/*
 * baffled_piston_radiation.java
 */

import com.comsol.model.*;
import com.comsol.model.util.*;

/** Model exported on May 12 2026, 10:55 by COMSOL 6.4.0.418. */
public class baffled_piston_radiation {

  public static Model run() {
    Model model = ModelUtil.create("Model");

//    From the File menu, choose New.
//    In the New window, click Model Wizard.
//    In the Model Wizard window, click 2D Axisymmetric.
//    In the Select Physics tree, select Acoustics > Pressure Acoustics > Pressure Acoustics, Frequency Domain (acpr).
//    Click Add.
//    Click Study.
//    In the Select Study tree, select General Studies > Frequency Domain.
//    Click Done.

    model.component().create("comp1", true);

    model.component("comp1").geom().create("geom1", 2);
    model.component("comp1").geom("geom1").axisymmetric(true);

    model.component("comp1").mesh().create("mesh1");

    model.component("comp1").physics().create("acpr", "PressureAcoustics", "geom1");

    model.study().create("std1");
    model.study("std1").create("freq", "Frequency");

//    In the Model Builder window, under Global Definitions, click Parameters 1.
//    In the Settings window for Parameters, locate the Parameters section.
//    Click Load from File.
//    Browse to the model's Application Library folder and double-click the file baffled_piston_radiation_parameters.txt.
//    To import content from file, use:
//    model.param().loadFile("FILENAME");
    model.param().set("u0", "1[m/s]", "Piston velocity amplitude");
    model.param().set("a", "0.1[m]", "Piston radius");
    model.param().set("Rmodel", "0.2[m]", "Domain radius");
    model.param().set("f0", "20000[Hz]", "Maximum frequency");
    model.param().set("c0", "343[m/s]", "Speed of sound");
    model.param().set("lam0", "c0/f0", "Wavelength at f0");
    model.param().set("ka0", "2*pi*a/lam0", "k0*a");
    model.param().set("R0", "ka0*a/2", "Rayleigh distance at f0");
    model.param().set("Rfar", "20*Rmodel", "Far-field evaluation distance");
    model.param().set("Scale", "a/lam0", "Help variable");

//    In the Geometry toolbar, click Circle.

    model.component("comp1").geom("geom1").create("c1", "Circle");

//    In the Settings window for Circle, locate the Size and Shape section.
//    In the Radius text field, type Rmodel.

    model.component("comp1").geom("geom1").feature("c1").set("r", "Rmodel");

//    In the Sector angle text field, type 90.

    model.component("comp1").geom("geom1").feature("c1").set("angle", 90);

//    In the Geometry toolbar, click Point.

    model.component("comp1").geom("geom1").run("c1");
    model.component("comp1").geom("geom1").create("pt1", "Point");

//    In the Settings window for Point, locate the Point section.
//    In the r text field, type a.

    model.component("comp1").geom("geom1").feature("pt1").setIndex("p", "a", 0);

//    Click Build All Objects.

    model.component("comp1").geom("geom1").runPre("fin");

//    In the Definitions toolbar, click Local Variables.

    model.component("comp1").variable().create("var1");

    model.component("comp1").geom("geom1").run();

//    In the Settings window for Variables, type Variables: Analytical Pressure Field in the Label text field.

    model.component("comp1").variable("var1").label("Variables: Analytical Pressure Field");

//    Locate the Variables section.
//    Click Load from File.
//    Browse to the model's Application Library folder and double-click the file baffled_piston_radiation_variables1.txt.
//    To import content from file, use:
//    model.component("comp1").variable("var1").loadFile("FILENAME");
    model.component("comp1").variable("var1").set("k", "intop_pt(acpr.k)*1[1/rad]", "Wave number");
    model.component("comp1").variable("var1").set("ka", "k*a", "k*a");
    model.component("comp1").variable("var1")
         .set("p0", "intop_pt(acpr.rho*acpr.c*u0)", "Specific reference pressure");
    model.component("comp1").variable("var1")
         .set("p_axis", "p0*(exp(-i*k*z)-exp(-i*k*sqrt(z^2+a^2)))", "On-axis near-field pressure (analytical)");
    model.component("comp1").variable("var1").set("R0", "k*a^2/2", "Rayleigh length scale");
    model.component("comp1").variable("var1")
         .set("p_axis_ff", "p0*(exp(-i*k*z)-exp(-i*k*sqrt(z^2+a^2)))", "On-axis far-field pressure (analytical)");
    model.component("comp1").variable("var1")
         .set("P_ar", "(pi/2)*a^2*u0*p0*(1-2*besselj(1,2*acpr.k*a)/(2*acpr.k*a))", "Acoustic radiated power");
    model.component("comp1").variable("var1")
         .set("p_ana", "i*a*p0/dis*besselj(1,ka*sin(theta))/sin(theta)*exp(-i*ka/a*dis)", "Analytical far-field pressure (spatial)");
    model.component("comp1").variable("var1").set("dis", "sqrt(r^2+z^2)", "Distance from origin");
    model.component("comp1").variable("var1").set("theta", "atan2(r,z)", "Polar angle (from z-axis)");

//    In the Definitions toolbar, click Local Variables.

    model.component("comp1").variable().create("var2");

//    In the Settings window for Variables, type Variables: Surface Impedance and Power in the Label text field.

    model.component("comp1").variable("var2").label("Variables: Surface Impedance and Power");

//    Locate the Variables section.
//    Click Load from File.
//    Browse to the model's Application Library folder and double-click the file baffled_piston_radiation_variables2.txt.
//    To import content from file, use:
//    model.component("comp1").variable("var2").loadFile("FILENAME");
    model.component("comp1").variable("var2").set("Zp", "acpr.rho*acpr.c*(R1+i*X1)", "Piston surface impedance");
    model.component("comp1").variable("var2").set("R1", "1-2*besselj(1,2*ka)/(2*ka)", "Piston function R1");
    model.component("comp1").variable("var2").set("X1", "2*K1/(2*ka)", "Piston function X1");
    model.component("comp1").variable("var2")
         .set("K1", "2/pi-besselj(0,2*ka)+0.5*(-5+16/pi)*sin(2*ka)/(ka)+(12-36/pi)*(1-cos(2*ka))/(2*ka)^2", "Struve function (approximation)");
    model.component("comp1").variable("var2")
         .set("W_ana", "intop_pt(pi*a^2*(u0^2)/2*real(Zp))", "Radiated power (analytical)");
    model.component("comp1").variable("var2")
         .set("W", "intop_out(acpr.Iz*acpr.nz+acpr.Ir*acpr.nr)", "Radiated power");

//    In the Definitions toolbar, click Nonlocal Couplings and choose Integration.

    model.component("comp1").cpl().create("intop1", "Integration");
    model.component("comp1").cpl("intop1").set("axisym", true);

//    In the Settings window for Integration, type intop_pt in the Operator name text field.

    model.component("comp1").cpl("intop1").set("opname", "intop_pt");

//    Locate the Source Selection section.
//    From the Geometric entity level list, select Point.

    model.component("comp1").cpl("intop1").selection().geom("geom1", 0);

//    Click Paste Selection.
//    In the Paste Selection dialog, type 1 in the Selection text field.
//    Click OK.

    model.component("comp1").cpl("intop1").selection().set(1);

//    In the Settings window for Integration, locate the Advanced section.
//    Clear the Compute integral in revolved geometry checkbox.

    model.component("comp1").cpl("intop1").set("axisym", false);

//    In the Definitions toolbar, click Nonlocal Couplings and choose Integration.

    model.component("comp1").cpl().create("intop2", "Integration");
    model.component("comp1").cpl("intop2").set("axisym", true);

//    In the Settings window for Integration, type intop_out in the Operator name text field.

    model.component("comp1").cpl("intop2").set("opname", "intop_out");

//    Locate the Source Selection section.
//    From the Geometric entity level list, select Boundary.

    model.component("comp1").cpl("intop2").selection().geom("geom1", 1);

//    Click Paste Selection.
//    In the Paste Selection dialog, type 4 in the Selection text field.
//    Click OK.

    model.component("comp1").cpl("intop2").selection().set(4);

//    In the Materials toolbar, click Add Material to open the Add Material window.
//    In the tree, select Built-in > Air.
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat1", "Common");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("eta", "Piecewise");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("Cp", "Piecewise");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("rho", "Analytic");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("k", "Piecewise");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("cs", "Analytic");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("an1", "Analytic");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("an2", "Analytic");
    model.component("comp1").material("mat1").propertyGroup()
         .create("RefractiveIndex", "RefractiveIndex", "Refractive index");
    model.component("comp1").material("mat1").propertyGroup()
         .create("NonlinearModel", "NonlinearModel", "Nonlinear model");
    model.component("comp1").material("mat1").propertyGroup().create("idealGas", "idealGas", "Ideal gas");
    model.component("comp1").material("mat1").propertyGroup("idealGas").func().create("Cp", "Piecewise");
    model.component("comp1").material("mat1").label("Air");
    model.component("comp1").material("mat1").set("family", "air");
    model.component("comp1").material("mat1").propertyGroup("def").func("eta").set("arg", "T");
    model.component("comp1").material("mat1").propertyGroup("def").func("eta")
         .set("pieces", new String[][]{{"200.0", "1600.0", "-8.38278E-7+8.35717342E-8*T^1-7.69429583E-11*T^2+4.6437266E-14*T^3-1.06585607E-17*T^4"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("eta").set("argunit", "K");
    model.component("comp1").material("mat1").propertyGroup("def").func("eta").set("fununit", "Pa*s");
    model.component("comp1").material("mat1").propertyGroup("def").func("Cp").set("arg", "T");
    model.component("comp1").material("mat1").propertyGroup("def").func("Cp")
         .set("pieces", new String[][]{{"200.0", "1600.0", "1047.63657-0.372589265*T^1+9.45304214E-4*T^2-6.02409443E-7*T^3+1.2858961E-10*T^4"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("Cp").set("argunit", "K");
    model.component("comp1").material("mat1").propertyGroup("def").func("Cp").set("fununit", "J/(kg*K)");
    model.component("comp1").material("mat1").propertyGroup("def").func("rho")
         .set("expr", "pA*0.02897/R_const[K*mol/J]/T");
    model.component("comp1").material("mat1").propertyGroup("def").func("rho").set("args", new String[]{"pA", "T"});
    model.component("comp1").material("mat1").propertyGroup("def").func("rho").set("fununit", "kg/m^3");
    model.component("comp1").material("mat1").propertyGroup("def").func("rho")
         .set("argunit", new String[]{"Pa", "K"});
    model.component("comp1").material("mat1").propertyGroup("def").func("rho")
         .set("plotaxis", new String[]{"off", "on"});
    model.component("comp1").material("mat1").propertyGroup("def").func("rho")
         .set("plotfixedvalue", new String[]{"101325", "273.15"});
    model.component("comp1").material("mat1").propertyGroup("def").func("rho")
         .set("plotargs", new String[][]{{"pA", "101325", "101325"}, {"T", "273.15", "293.15"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("k").set("arg", "T");
    model.component("comp1").material("mat1").propertyGroup("def").func("k")
         .set("pieces", new String[][]{{"200.0", "1600.0", "-0.00227583562+1.15480022E-4*T^1-7.90252856E-8*T^2+4.11702505E-11*T^3-7.43864331E-15*T^4"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("k").set("argunit", "K");
    model.component("comp1").material("mat1").propertyGroup("def").func("k").set("fununit", "W/(m*K)");
    model.component("comp1").material("mat1").propertyGroup("def").func("cs")
         .set("expr", "sqrt(1.4*R_const[K*mol/J]/0.02897*T)");
    model.component("comp1").material("mat1").propertyGroup("def").func("cs").set("args", new String[]{"T"});
    model.component("comp1").material("mat1").propertyGroup("def").func("cs").set("fununit", "m/s");
    model.component("comp1").material("mat1").propertyGroup("def").func("cs").set("argunit", new String[]{"K"});
    model.component("comp1").material("mat1").propertyGroup("def").func("cs")
         .set("plotfixedvalue", new String[]{"273.15"});
    model.component("comp1").material("mat1").propertyGroup("def").func("cs")
         .set("plotargs", new String[][]{{"T", "273.15", "373.15"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("an1").set("funcname", "alpha_p");
    model.component("comp1").material("mat1").propertyGroup("def").func("an1")
         .set("expr", "-1/rho(pA,T)*d(rho(pA,T),T)");
    model.component("comp1").material("mat1").propertyGroup("def").func("an1").set("args", new String[]{"pA", "T"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an1").set("fununit", "1/K");
    model.component("comp1").material("mat1").propertyGroup("def").func("an1")
         .set("argunit", new String[]{"Pa", "K"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an1")
         .set("plotaxis", new String[]{"off", "on"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an1")
         .set("plotfixedvalue", new String[]{"101325", "273.15"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an1")
         .set("plotargs", new String[][]{{"pA", "101325", "101325"}, {"T", "273.15", "373.15"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("an2").set("funcname", "muB");
    model.component("comp1").material("mat1").propertyGroup("def").func("an2").set("expr", "0.6*eta(T)");
    model.component("comp1").material("mat1").propertyGroup("def").func("an2").set("args", new String[]{"T"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an2").set("fununit", "Pa*s");
    model.component("comp1").material("mat1").propertyGroup("def").func("an2").set("argunit", new String[]{"K"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an2")
         .set("plotfixedvalue", new String[]{"200"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an2")
         .set("plotargs", new String[][]{{"T", "200", "1600"}});
    model.component("comp1").material("mat1").propertyGroup("def").set("thermalexpansioncoefficient", "");
    model.component("comp1").material("mat1").propertyGroup("def").set("molarmass", "");
    model.component("comp1").material("mat1").propertyGroup("def").set("bulkviscosity", "");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("thermalexpansioncoefficient", new String[]{"alpha_p(pA,T)", "0", "0", "0", "alpha_p(pA,T)", "0", "0", "0", "alpha_p(pA,T)"});
    model.component("comp1").material("mat1").propertyGroup("def").set("molarmass", "0.02897[kg/mol]");
    model.component("comp1").material("mat1").propertyGroup("def").set("bulkviscosity", "muB(T)");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("relpermeability", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("relpermittivity", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat1").propertyGroup("def").set("dynamicviscosity", "eta(T)");
    model.component("comp1").material("mat1").propertyGroup("def").set("ratioofspecificheat", "1.4");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("electricconductivity", new String[]{"0[S/m]", "0", "0", "0", "0[S/m]", "0", "0", "0", "0[S/m]"});
    model.component("comp1").material("mat1").propertyGroup("def").set("heatcapacity", "Cp(T)");
    model.component("comp1").material("mat1").propertyGroup("def").set("density", "rho(pA,T)");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("thermalconductivity", new String[]{"k(T)", "0", "0", "0", "k(T)", "0", "0", "0", "k(T)"});
    model.component("comp1").material("mat1").propertyGroup("def").set("soundspeed", "cs(T)");
    model.component("comp1").material("mat1").propertyGroup("def").addInput("temperature");
    model.component("comp1").material("mat1").propertyGroup("def").addInput("pressure");
    model.component("comp1").material("mat1").propertyGroup("RefractiveIndex")
         .set("n", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat1").propertyGroup("NonlinearModel").set("BA", "def.gamma-1");
    model.component("comp1").material("mat1").propertyGroup("idealGas").func("Cp").label("Piecewise 2");
    model.component("comp1").material("mat1").propertyGroup("idealGas").func("Cp").set("arg", "T");
    model.component("comp1").material("mat1").propertyGroup("idealGas").func("Cp")
         .set("pieces", new String[][]{{"200.0", "1600.0", "1047.63657-0.372589265*T^1+9.45304214E-4*T^2-6.02409443E-7*T^3+1.2858961E-10*T^4"}});
    model.component("comp1").material("mat1").propertyGroup("idealGas").func("Cp").set("argunit", "K");
    model.component("comp1").material("mat1").propertyGroup("idealGas").func("Cp").set("fununit", "J/(kg*K)");
    model.component("comp1").material("mat1").propertyGroup("idealGas").set("Rs", "R_const/Mn");
    model.component("comp1").material("mat1").propertyGroup("idealGas").set("heatcapacity", "Cp(T)");
    model.component("comp1").material("mat1").propertyGroup("idealGas").set("ratioofspecificheat", "1.4");
    model.component("comp1").material("mat1").propertyGroup("idealGas").set("molarmass", "0.02897[kg/mol]");
    model.component("comp1").material("mat1").propertyGroup("idealGas").addInput("temperature");
    model.component("comp1").material("mat1").propertyGroup("idealGas").addInput("pressure");
    model.component("comp1").material("mat1").materialType("nonSolid");

//    In the Materials toolbar, click Add Material to close the Add Material window.
//    In the Settings window for Pressure Acoustics, locate the Pressure Acoustics Model section.
//    From the Fluid model list, select Atmosphere attenuation.

    model.component("comp1").physics("acpr").feature("fpam1").set("FluidModel", "AtmosphereAttenuation");

//    In the Physics toolbar, click Boundaries and choose Normal Velocity.

    model.component("comp1").physics("acpr").create("nvel1", "NormalVelocity", 1);

//    In the Settings window for Normal Velocity, locate the Boundary Selection section.
//    Click Paste Selection.
//    In the Paste Selection dialog, type 2 in the Selection text field.
//    Click OK.

    model.component("comp1").physics("acpr").feature("nvel1").selection().set(2);

//    In the Settings window for Normal Velocity, locate the Normal Velocity section.
//    In the \[v_n\] text field, type u0.

    model.component("comp1").physics("acpr").feature("nvel1").set("nvel", "u0");

//    In the Physics toolbar, click Boundaries and choose Spherical Wave Radiation.

    model.component("comp1").physics("acpr").create("swr1", "SphericalWaveRadiation", 1);

//    In the Settings window for Spherical Wave Radiation, locate the Boundary Selection section.
//    Click Paste Selection.
//    In the Paste Selection dialog, type 4 in the Selection text field.
//    Click OK.

    model.component("comp1").physics("acpr").feature("swr1").selection().set(4);

//    In the Physics toolbar, click Boundaries and choose Exterior Field Calculation.

    model.component("comp1").physics("acpr").create("efc1", "ExteriorFieldCalculation", 1);

//    In the Settings window for Exterior Field Calculation, locate the Boundary Selection section.
//    Click Paste Selection.
//    In the Paste Selection dialog, type 4 in the Selection text field.
//    Click OK.

    model.component("comp1").physics("acpr").feature("efc1").selection().set(4);

//    In the Settings window for Exterior Field Calculation, locate the Exterior Field Calculation section.
//    From the Condition in the z = z₀ plane list, select Symmetric/Infinite sound hard boundary.

    model.component("comp1").physics("acpr").feature("efc1").setIndex("SymmetryCondition2", 1, 0);

//    In the Model Builder window, click Study 1.
//    In the Settings window for Study, locate the Study Settings section.
//    Clear the Generate default plots checkbox.

    model.study("std1").setGenPlots(false);

//    In the Model Builder window, under Study 1, click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Study Settings section.
//    Click Range.
//    In the Range dialog, choose Logarithmic from the Entry method list.
//    In the Start text field, type 10.
//    In the Stop text field, type 20000.
//    In the Steps per decade text field, type 9.
//    Click Replace.

    model.study("std1").feature("freq").set("plist", "10^{range(log10(10),1/9,log10(20000))}");

//    In the Settings window for Frequency Domain, locate the Study Settings section.
//    From the Reuse solution from previous step list, select Yes.

    model.study("std1").feature("freq").set("preusesol", "yes");

//    In the Study toolbar, click Show Default Solver.

    model.study("std1").showAutoSequences("all");

//    In the Model Builder window, right-click Component 1 (comp1) > Mesh 1 and choose Build All.

    model.component("comp1").mesh("mesh1").run();

//    In the Study toolbar, click Compute.

    model.study("std1").createAutoSequences("all");

    model.sol("sol1").runAll();

//    In the Model Builder window, expand the Results node.
//    In the Model Builder window, expand the Results > Datasets node.
//    Right-click Results > Datasets and choose More 2D Datasets > Parametric Curve 2D.

    model.result().dataset().create("pc1", "ParCurve2D");

//    In the Settings window for Parametric Curve 2D, locate the Parameter section.
//    In the Maximum text field, type pi/2.

    model.result().dataset("pc1").set("parmax1", "pi/2");

//    Locate the Expressions section.
//    In the r text field, type 1.3*a*cos(s).

    model.result().dataset("pc1").set("exprx", "1.3*a*cos(s)");

//    In the z text field, type 1.3*a*sin(s).

    model.result().dataset("pc1").set("expry", "1.3*a*sin(s)");

//    In the Results toolbar, click More Datasets and choose Parametric Curve 2D.

    model.result().dataset().create("pc2", "ParCurve2D");

//    In the Settings window for Parametric Curve 2D, locate the Expressions section.
//    In the z text field, type 1.01*Rmodel*(1-s)+Rfar*s.

    model.result().dataset("pc2").set("expry", "1.01*Rmodel*(1-s)+Rfar*s");

//    Select the Only evaluate globally defined expressions checkbox.

    model.result().dataset("pc2").set("global", true);

//    In the Results toolbar, click More Datasets and choose Parametric Curve 2D.

    model.result().dataset().create("pc3", "ParCurve2D");

//    In the Settings window for Parametric Curve 2D, locate the Expressions section.
//    Select the Only evaluate globally defined expressions checkbox.

    model.result().dataset("pc3").set("global", true);

//    In the Results toolbar, click More Datasets and choose Revolution 2D.

    model.result().dataset().create("rev1", "Revolve2D");

//    In the Model Builder window, click Parametric Curve 2D 3.
//    In the Settings window for Parametric Curve 2D, locate the Expressions section.
//    In the z text field, type Rfar*s.

    model.result().dataset("pc3").set("expry", "Rfar*s");

//    In the Model Builder window, click Revolution 2D 1.
//    In the Settings window for Revolution 2D, click to expand the Revolution Layers section.
//    In the Start angle text field, type -50.

    model.result().dataset("rev1").set("startangle", -50);

//    In the Revolution angle text field, type 230.

    model.result().dataset("rev1").set("revangle", 230);

//    In the Results toolbar, click More Datasets and choose Grid > Grid 2D.

    model.result().dataset().create("grid1", "Grid2D");
    model.result().dataset("grid1").set("source", "data");

//    In the Settings window for Grid 2D, locate the Parameter Bounds section.
//    Find the First parameter subsection.
//    In the Name text field, type r.

    model.result().dataset("grid1").set("par1", "r");

//    In the Minimum text field, type -1.5*Rmodel.

    model.result().dataset("grid1").set("parmin1", "-1.5*Rmodel");

//    In the Maximum text field, type 1.5*Rmodel.

    model.result().dataset("grid1").set("parmax1", "1.5*Rmodel");

//    Find the Second parameter subsection.
//    In the Name text field, type z.

    model.result().dataset("grid1").set("par2", "z");

//    In the Maximum text field, type 3*Rmodel.

    model.result().dataset("grid1").set("parmax2", "3*Rmodel");

//    In the Results toolbar, click More Datasets and choose Mirror 2D.

    model.result().dataset().create("mir1", "Mirror2D");

//    In the Model Builder window, click Results.
//    In the Settings window for Results, locate the Save Data in the Model section.
//    From the Save plot data list, select On.
//    In the Results toolbar, click 2D Plot Group.

    model.result().create("pg1", "PlotGroup2D");
    model.result("pg1").run();

//    In the Settings window for 2D Plot Group, type Acoustic Pressure in the Label text field.

    model.result("pg1").label("Acoustic Pressure");

//    Locate the Data section.
//    From the Parameter value (freq (Hz)) list, select 10000.

    model.result("pg1").setIndex("looplevel", 28, 0);

//    Click to expand the Title section.
//    From the Title type list, select Label.

    model.result("pg1").set("titletype", "label");

//    Locate the Color Legend section.
//    Select the Show maximum and minimum values checkbox.

    model.result("pg1").set("showlegendsmaxmin", true);

//    Select the Show units checkbox.

    model.result("pg1").set("showlegendsunit", true);

//    In the Acoustic Pressure toolbar, click Surface.

    model.result("pg1").create("surf1", "Surface");
    model.result("pg1").feature("surf1").set("evaluationsettings", "parent");

//    In the Settings window for Surface, locate the Coloring and Style section.
//    From the Color table list, select Wave.
//    In the Acoustic Pressure toolbar, click Plot.

    model.result("pg1").run();

//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg2", "PlotGroup1D");
    model.result("pg2").run();

//    In the Settings window for 1D Plot Group, type On-Axis Acoustic Pressure in the Label text field.

    model.result("pg2").label("On-Axis Acoustic Pressure");

//    Locate the Data section.
//    From the Parameter selection (freq) list, select Last.

    model.result("pg2").setIndex("looplevelinput", "last", 0);

//    Click to expand the Title section.
//    From the Title type list, select Label.

    model.result("pg2").set("titletype", "label");

//    Locate the Plot Settings section.
//    Select the x-axis label checkbox.

    model.result("pg2").set("xlabelactive", true);

//    In the associated text field, type z/R0.

    model.result("pg2").set("xlabel", "z/R0");

//    Select the y-axis label checkbox.

    model.result("pg2").set("ylabelactive", true);

//    In the associated text field, type abs(p) (Pa).

    model.result("pg2").set("ylabel", "abs(p) (Pa)");

//    Locate the Axis section.
//    Select the x-axis log scale checkbox.

    model.result("pg2").set("xlog", true);

//    Locate the Legend section.
//    From the Position list, select Upper left.

    model.result("pg2").set("legendpos", "upperleft");

//    In the On-Axis Acoustic Pressure toolbar, click Line Graph.

    model.result("pg2").create("lngr1", "LineGraph");
    model.result("pg2").feature("lngr1").set("markerpos", "datapoints");
    model.result("pg2").feature("lngr1").set("linewidth", "preference");
    model.result("pg2").feature("lngr1").set("evaluationsettings", "parent");

//    In the Settings window for Line Graph, locate the Selection section.
//    Click Paste Selection.
//    In the Paste Selection dialog, type 1 in the Selection text field.
//    Click OK.

    model.result("pg2").feature("lngr1").selection().set(1);

//    In the Settings window for Line Graph, locate the y-Axis Data section.
//    In the Expression text field, type abs(p/p0).

    model.result("pg2").feature("lngr1").set("expr", "abs(p/p0)");

//    Locate the x-Axis Data section.
//    From the Parameter list, select Expression.

    model.result("pg2").feature("lngr1").set("xdata", "expr");

//    In the Expression text field, type z/R0.

    model.result("pg2").feature("lngr1").set("xdataexpr", "z/R0");

//    Click to expand the Coloring and Style section.
//    From the Color list, select Blue.

    model.result("pg2").feature("lngr1").set("linecolor", "blue");

//    From the Width list, select 2.

    model.result("pg2").feature("lngr1").set("linewidth", 2);

//    Click to expand the Legends section.
//    Select the Show legends checkbox.

    model.result("pg2").feature("lngr1").set("legend", true);

//    From the Legends list, select Manual.

    model.result("pg2").feature("lngr1").set("legendmethod", "manual");

//    In the table, enter the following settings:

    model.result("pg2").feature("lngr1").setIndex("legends", "COMSOL Model", 0);
    model.result("pg2").run();

//    In the Model Builder window, click On-Axis Acoustic Pressure.
//    In the On-Axis Acoustic Pressure toolbar, click Line Graph.

    model.result("pg2").create("lngr2", "LineGraph");
    model.result("pg2").feature("lngr2").set("markerpos", "datapoints");
    model.result("pg2").feature("lngr2").set("linewidth", "preference");
    model.result("pg2").feature("lngr2").set("evaluationsettings", "parent");

//    In the Settings window for Line Graph, locate the Selection section.
//    Click Paste Selection.
//    In the Paste Selection dialog, type 1 in the Selection text field.
//    Click OK.

    model.result("pg2").feature("lngr2").selection().set(1);

//    In the Settings window for Line Graph, locate the y-Axis Data section.
//    In the Expression text field, type abs(p_axis/p0).

    model.result("pg2").feature("lngr2").set("expr", "abs(p_axis/p0)");

//    Locate the x-Axis Data section.
//    From the Parameter list, select Expression.

    model.result("pg2").feature("lngr2").set("xdata", "expr");

//    In the Expression text field, type z/R0.

    model.result("pg2").feature("lngr2").set("xdataexpr", "z/R0");

//    Locate the Coloring and Style section.
//    Find the Line style subsection.
//    From the Line list, select None.

    model.result("pg2").feature("lngr2").set("linestyle", "none");

//    From the Color list, select Red.

    model.result("pg2").feature("lngr2").set("linecolor", "red");

//    From the Width list, select 2.

    model.result("pg2").feature("lngr2").set("linewidth", 2);

//    Find the Line markers subsection.
//    From the Marker list, select Point.

    model.result("pg2").feature("lngr2").set("linemarker", "point");

//    From the Positioning list, select Interpolated.

    model.result("pg2").feature("lngr2").set("markerpos", "interp");

//    In the Number text field, type 100.

    model.result("pg2").feature("lngr2").set("markers", 100);

//    Locate the Legends section.
//    Select the Show legends checkbox.

    model.result("pg2").feature("lngr2").set("legend", true);

//    From the Legends list, select Manual.

    model.result("pg2").feature("lngr2").set("legendmethod", "manual");

//    In the table, enter the following settings:

    model.result("pg2").feature("lngr2").setIndex("legends", "Full Analytical", 0);
    model.result("pg2").run();

//    In the Model Builder window, click On-Axis Acoustic Pressure.
//    In the On-Axis Acoustic Pressure toolbar, click Line Graph.

    model.result("pg2").create("lngr3", "LineGraph");
    model.result("pg2").feature("lngr3").set("markerpos", "datapoints");
    model.result("pg2").feature("lngr3").set("linewidth", "preference");
    model.result("pg2").feature("lngr3").set("evaluationsettings", "parent");

//    In the Settings window for Line Graph, locate the Data section.
//    From the Dataset list, select Parametric Curve 2D 2.

    model.result("pg2").feature("lngr3").set("data", "pc2");

//    From the Parameter selection (freq) list, select Last.

    model.result("pg2").feature("lngr3").setIndex("looplevelinput", "last", 0);

    return model;
  }

  public static Model run2(Model model) {

//    Locate the y-Axis Data section.
//    In the Expression text field, type abs(pext(0,z)/p0).

    model.result("pg2").feature("lngr3").set("expr", "abs(pext(0,z)/p0)");

//    Locate the x-Axis Data section.
//    From the Parameter list, select Expression.

    model.result("pg2").feature("lngr3").set("xdata", "expr");

//    In the Expression text field, type z/R0.

    model.result("pg2").feature("lngr3").set("xdataexpr", "z/R0");

//    Locate the Coloring and Style section.
//    From the Color list, select Blue.

    model.result("pg2").feature("lngr3").set("linecolor", "blue");

//    From the Width list, select 2.

    model.result("pg2").feature("lngr3").set("linewidth", 2);

//    Locate the Legends section.
//    From the Legends list, select Manual.

    model.result("pg2").feature("lngr3").set("legendmethod", "manual");

//    In the table, enter the following settings:

    model.result("pg2").feature("lngr3").setIndex("legends", "COMSOL FE Model", 0);
    model.result("pg2").run();

//    In the Model Builder window, click On-Axis Acoustic Pressure.
//    In the On-Axis Acoustic Pressure toolbar, click Line Graph.

    model.result("pg2").create("lngr4", "LineGraph");
    model.result("pg2").feature("lngr4").set("markerpos", "datapoints");
    model.result("pg2").feature("lngr4").set("linewidth", "preference");
    model.result("pg2").feature("lngr4").set("evaluationsettings", "parent");

//    In the Settings window for Line Graph, locate the Data section.
//    From the Dataset list, select Parametric Curve 2D 2.

    model.result("pg2").feature("lngr4").set("data", "pc2");

//    From the Parameter selection (freq) list, select Last.

    model.result("pg2").feature("lngr4").setIndex("looplevelinput", "last", 0);

//    Locate the y-Axis Data section.
//    In the Expression text field, type abs(p_axis_ff/p0).

    model.result("pg2").feature("lngr4").set("expr", "abs(p_axis_ff/p0)");

//    Locate the x-Axis Data section.
//    From the Parameter list, select Expression.

    model.result("pg2").feature("lngr4").set("xdata", "expr");

//    In the Expression text field, type z/R0.

    model.result("pg2").feature("lngr4").set("xdataexpr", "z/R0");

//    Locate the Coloring and Style section.
//    Find the Line style subsection.
//    From the Line list, select None.

    model.result("pg2").feature("lngr4").set("linestyle", "none");

//    From the Color list, select Red.

    model.result("pg2").feature("lngr4").set("linecolor", "red");

//    From the Width list, select 2.

    model.result("pg2").feature("lngr4").set("linewidth", 2);

//    Find the Line markers subsection.
//    From the Marker list, select Point.

    model.result("pg2").feature("lngr4").set("linemarker", "point");

//    From the Positioning list, select Interpolated.

    model.result("pg2").feature("lngr4").set("markerpos", "interp");

//    In the Number text field, type 20.

    model.result("pg2").feature("lngr4").set("markers", 20);
    model.result("pg2").run();

//    In the Model Builder window, click On-Axis Acoustic Pressure.
//    In the On-Axis Acoustic Pressure toolbar, click Line Graph.

    model.result("pg2").create("lngr5", "LineGraph");
    model.result("pg2").feature("lngr5").set("markerpos", "datapoints");
    model.result("pg2").feature("lngr5").set("linewidth", "preference");
    model.result("pg2").feature("lngr5").set("evaluationsettings", "parent");

//    In the Settings window for Line Graph, locate the Data section.
//    From the Dataset list, select Parametric Curve 2D 3.

    model.result("pg2").feature("lngr5").set("data", "pc3");

//    From the Parameter selection (freq) list, select Last.

    model.result("pg2").feature("lngr5").setIndex("looplevelinput", "last", 0);

//    Locate the y-Axis Data section.
//    In the Expression text field, type 2/sqrt(1+(2*z/R0)^2).

    model.result("pg2").feature("lngr5").set("expr", "2/sqrt(1+(2*z/R0)^2)");

//    Locate the x-Axis Data section.
//    From the Parameter list, select Expression.

    model.result("pg2").feature("lngr5").set("xdata", "expr");

//    In the Expression text field, type z/R0.

    model.result("pg2").feature("lngr5").set("xdataexpr", "z/R0");

//    Locate the Coloring and Style section.
//    Find the Line style subsection.
//    From the Line list, select Dashed.

    model.result("pg2").feature("lngr5").set("linestyle", "dashed");

//    From the Color list, select Green.

    model.result("pg2").feature("lngr5").set("linecolor", "green");

//    From the Width list, select 2.

    model.result("pg2").feature("lngr5").set("linewidth", 2);

//    Locate the Legends section.
//    Select the Show legends checkbox.

    model.result("pg2").feature("lngr5").set("legend", true);

//    From the Legends list, select Manual.

    model.result("pg2").feature("lngr5").set("legendmethod", "manual");

//    In the table, enter the following settings:

    model.result("pg2").feature("lngr5").setIndex("legends", "Asymptotes M and MM", 0);
    model.result("pg2").run();

//    In the Model Builder window, click On-Axis Acoustic Pressure.
//    In the On-Axis Acoustic Pressure toolbar, click Line Graph.

    model.result("pg2").create("lngr6", "LineGraph");
    model.result("pg2").feature("lngr6").set("markerpos", "datapoints");
    model.result("pg2").feature("lngr6").set("linewidth", "preference");
    model.result("pg2").feature("lngr6").set("evaluationsettings", "parent");

//    In the Settings window for Line Graph, locate the Data section.
//    From the Dataset list, select Parametric Curve 2D 3.

    model.result("pg2").feature("lngr6").set("data", "pc3");

//    From the Parameter selection (freq) list, select Last.

    model.result("pg2").feature("lngr6").setIndex("looplevelinput", "last", 0);

//    Locate the y-Axis Data section.
//    In the Expression text field, type 1/sqrt(1+(z/R0)^2).

    model.result("pg2").feature("lngr6").set("expr", "1/sqrt(1+(z/R0)^2)");

//    Locate the x-Axis Data section.
//    From the Parameter list, select Expression.

    model.result("pg2").feature("lngr6").set("xdata", "expr");

//    In the Expression text field, type z/R0.

    model.result("pg2").feature("lngr6").set("xdataexpr", "z/R0");

//    Locate the Coloring and Style section.
//    Find the Line style subsection.
//    From the Line list, select Dashed.

    model.result("pg2").feature("lngr6").set("linestyle", "dashed");

//    From the Color list, select Green.

    model.result("pg2").feature("lngr6").set("linecolor", "green");

//    From the Width list, select 2.

    model.result("pg2").feature("lngr6").set("linewidth", 2);
    model.result("pg2").run();

//    In the Model Builder window, click On-Axis Acoustic Pressure.
//    In the On-Axis Acoustic Pressure toolbar, click Line Graph.

    model.result("pg2").create("lngr7", "LineGraph");
    model.result("pg2").feature("lngr7").set("markerpos", "datapoints");
    model.result("pg2").feature("lngr7").set("linewidth", "preference");
    model.result("pg2").feature("lngr7").set("evaluationsettings", "parent");

//    In the Settings window for Line Graph, locate the Data section.
//    From the Dataset list, select Parametric Curve 2D 2.

    model.result("pg2").feature("lngr7").set("data", "pc2");

//    From the Parameter selection (freq) list, select Last.

    model.result("pg2").feature("lngr7").setIndex("looplevelinput", "last", 0);

//    Locate the y-Axis Data section.
//    In the Expression text field, type abs(i*R0/z*exp(-i*k*z)).

    model.result("pg2").feature("lngr7").set("expr", "abs(i*R0/z*exp(-i*k*z))");

//    Locate the x-Axis Data section.
//    From the Parameter list, select Expression.

    model.result("pg2").feature("lngr7").set("xdata", "expr");

//    In the Expression text field, type z/R0.

    model.result("pg2").feature("lngr7").set("xdataexpr", "z/R0");

//    Locate the Coloring and Style section.
//    Find the Line style subsection.
//    From the Line list, select Dashed.

    model.result("pg2").feature("lngr7").set("linestyle", "dashed");

//    From the Color list, select Black.

    model.result("pg2").feature("lngr7").set("linecolor", "black");

//    From the Width list, select 2.

    model.result("pg2").feature("lngr7").set("linewidth", 2);

//    Locate the Legends section.
//    Select the Show legends checkbox.

    model.result("pg2").feature("lngr7").set("legend", true);

//    From the Legends list, select Manual.

    model.result("pg2").feature("lngr7").set("legendmethod", "manual");

//    In the table, enter the following settings:

    model.result("pg2").feature("lngr7").setIndex("legends", "Far-field Limit", 0);

//    In the On-Axis Acoustic Pressure toolbar, click Plot.

    model.result("pg2").run();

//    The on-axis pressure should look like the one in the figure below.
//    In the Home toolbar, click Add Plot Group and choose Polar Plot Group.

    model.result().create("pg3", "PolarGroup");
    model.result("pg3").run();

//    In the Settings window for Polar Plot Group, type Near Field r=1.3a in the Label text field.

    model.result("pg3").label("Near Field r=1.3a");

//    Locate the Data section.
//    From the Dataset list, select Parametric Curve 2D 1.

    model.result("pg3").set("data", "pc1");

//    From the Parameter selection (freq) list, select From list.

    model.result("pg3").setIndex("looplevelinput", "manual", 0);

//    In the Parameter values (freq (Hz)) list, select 10000.

    model.result("pg3").setIndex("looplevel", new int[]{28}, 0);

//    select 10000 in the Parameter values (freq (Hz)) list.
//    Click to expand the Title section.
//    From the Title type list, select Manual.

    model.result("pg3").set("titletype", "manual");

//    In the Title text area, type Near-Field SPL at f=eval(freq) Hz.

    model.result("pg3").set("title", "Near-Field SPL at f=eval(freq) Hz");

//    Locate the Axis section.
//    Select the Symmetric angle range checkbox.

    model.result("pg3").set("symmetricangle", true);

//    From the Zero angle list, select Up.

    model.result("pg3").set("zeroangle", "up");

//    From the Rotation direction list, select Clockwise.

    model.result("pg3").set("rotdir", "cw");

//    In the Near Field r=1.3a toolbar, click Line Graph.

    model.result("pg3").create("lngr1", "LineGraph");
    model.result("pg3").feature("lngr1").set("markerpos", "datapoints");
    model.result("pg3").feature("lngr1").set("linewidth", "preference");
    model.result("pg3").feature("lngr1").set("evaluationsettings", "parent");

//    In the Settings window for Line Graph, locate the r-Axis Data section.
//    In the Expression text field, type acpr.Lp.

    model.result("pg3").feature("lngr1").set("expr", "acpr.Lp");

//    Locate the θ Angle Data section.
//    From the Parameter list, select Expression.

    model.result("pg3").feature("lngr1").set("xdata", "expr");

//    In the Expression text field, type theta.

    model.result("pg3").feature("lngr1").set("xdataexpr", "theta");

//    In the Unit field, type 1.

    model.result("pg3").feature("lngr1").set("xdataunit", "1");
    model.result("pg3").run();

//    In the Model Builder window, click Near Field r=1.3a.
//    In the Near Field r=1.3a toolbar, click Line Graph.

    model.result("pg3").create("lngr2", "LineGraph");
    model.result("pg3").feature("lngr2").set("markerpos", "datapoints");
    model.result("pg3").feature("lngr2").set("linewidth", "preference");
    model.result("pg3").feature("lngr2").set("evaluationsettings", "parent");

//    In the Settings window for Line Graph, locate the r-Axis Data section.
//    In the Expression text field, type acpr.Lp.

    model.result("pg3").feature("lngr2").set("expr", "acpr.Lp");

//    Locate the θ Angle Data section.
//    From the Parameter list, select Expression.

    model.result("pg3").feature("lngr2").set("xdata", "expr");

//    In the Expression text field, type -theta.

    model.result("pg3").feature("lngr2").set("xdataexpr", "-theta");

//    In the Unit field, type 1.

    model.result("pg3").feature("lngr2").set("xdataunit", "1");

//    Click to expand the Coloring and Style section.
//    From the Color list, select Blue.

    model.result("pg3").feature("lngr2").set("linecolor", "blue");

//    In the Near Field r=1.3a toolbar, click Plot.

    model.result("pg3").run();

//    In the Results toolbar, click Polar Plot Group.

    model.result().create("pg4", "PolarGroup");
    model.result("pg4").run();

//    In the Settings window for Polar Plot Group, type Far Field r=Rfar in the Label text field.

    model.result("pg4").label("Far Field r=Rfar");

//    Locate the Data section.
//    From the Parameter selection (freq) list, select From list.

    model.result("pg4").setIndex("looplevelinput", "manual", 0);

//    In the Parameter values (freq (Hz)) list, select 10000.

    model.result("pg4").setIndex("looplevel", new int[]{28}, 0);

//    select 10000 in the Parameter values (freq (Hz)) list.
//    Locate the Title section.
//    From the Title type list, select Manual.

    model.result("pg4").set("titletype", "manual");

//    In the Title text area, type Far-Field SPL at f=eval(freq) Hz.

    model.result("pg4").set("title", "Far-Field SPL at f=eval(freq) Hz");

//    Locate the Axis section.
//    Select the Symmetric angle range checkbox.

    model.result("pg4").set("symmetricangle", true);

//    From the Zero angle list, select Up.

    model.result("pg4").set("zeroangle", "up");

//    From the Rotation direction list, select Clockwise.

    model.result("pg4").set("rotdir", "cw");

//    In the Far Field r=Rfar toolbar, click More Plots and choose Radiation Pattern.

    model.result("pg4").create("rp1", "RadiationPattern");
    model.result("pg4").feature("rp1").set("markerpos", "datapoints");
    model.result("pg4").feature("rp1").set("linewidth", "preference");

//    In the Settings window for Radiation Pattern, locate the Evaluation section.
//    Find the Angles subsection.
//    In the Number of angles text field, type 180.

    model.result("pg4").feature("rp1").set("phidisc", 180);

//    From the Restriction list, select Manual.

    model.result("pg4").feature("rp1").set("anglerestr", "manual");

//    In the φ start text field, type -90.

    model.result("pg4").feature("rp1").set("phimin", -90);

//    In the φ range text field, type 180.

    model.result("pg4").feature("rp1").set("phirange", 180);

//    Find the Evaluation distance subsection.
//    In the Radius text field, type Rfar.

    model.result("pg4").feature("rp1").set("radius", "Rfar");

//    In the Far Field r=Rfar toolbar, click Plot.

    model.result("pg4").run();
    model.result("pg4").run();

//    In the Model Builder window, click Far Field r=Rfar.
//    In the Far Field r=Rfar toolbar, click More Plots and choose Radiation Pattern.

    model.result("pg4").create("rp2", "RadiationPattern");
    model.result("pg4").feature("rp2").set("markerpos", "datapoints");
    model.result("pg4").feature("rp2").set("linewidth", "preference");

//    In the Settings window for Radiation Pattern, locate the Expression section.
//    In the Expression text field, type 10*log10(0.5*p_ana*conj(p_ana)/(20e-6)^2).

    model.result("pg4").feature("rp2").set("expr", "10*log10(0.5*p_ana*conj(p_ana)/(20e-6)^2)");

//    Locate the Evaluation section.
//    Find the Angles subsection.
//    In the Number of angles text field, type 180.

    model.result("pg4").feature("rp2").set("phidisc", 180);

//    From the Restriction list, select Manual.

    model.result("pg4").feature("rp2").set("anglerestr", "manual");

//    In the φ start text field, type -90.

    model.result("pg4").feature("rp2").set("phimin", -90);

//    In the φ range text field, type 180.

    model.result("pg4").feature("rp2").set("phirange", 180);

//    Find the Evaluation distance subsection.
//    In the Radius text field, type Rfar.

    model.result("pg4").feature("rp2").set("radius", "Rfar");

//    Click to expand the Legends section.
//    Select the Show legends checkbox.

    model.result("pg4").feature("rp2").set("legend", true);

//    From the Legends list, select Manual.

    model.result("pg4").feature("rp2").set("legendmethod", "manual");

//    In the table, enter the following settings:

    model.result("pg4").feature("rp2").setIndex("legends", "Analytical (far-field)", 0);

//    Click to expand the Coloring and Style section.
//    Find the Line style subsection.
//    From the Line list, select None.

    model.result("pg4").feature("rp2").set("linestyle", "none");

//    Find the Line markers subsection.
//    From the Marker list, select Point.

    model.result("pg4").feature("rp2").set("linemarker", "point");

//    From the Positioning list, select Interpolated.

    model.result("pg4").feature("rp2").set("markerpos", "interp");

//    In the Number text field, type 180.

    model.result("pg4").feature("rp2").set("markers", 180);

//    In the Far Field r=Rfar toolbar, click Plot.

    model.result("pg4").run();

//    The far-field radiation pattern at <eqv>f</eqv>=10,000 Hz should look like the one in the figure below.
//    In the Results toolbar, click Polar Plot Group.

    model.result().create("pg5", "PolarGroup");
    model.result("pg5").run();

//    In the Settings window for Polar Plot Group, type Beamwidth Polar in the Label text field.

    model.result("pg5").label("Beamwidth Polar");

//    Locate the Axis section.
//    Select the Symmetric angle range checkbox.

    model.result("pg5").set("symmetricangle", true);

//    From the Zero angle list, select Up.

    model.result("pg5").set("zeroangle", "up");

//    From the Rotation direction list, select Clockwise.

    model.result("pg5").set("rotdir", "cw");

//    In the Beamwidth Polar toolbar, click More Plots and choose Radiation Pattern.

    model.result("pg5").create("rp1", "RadiationPattern");
    model.result("pg5").feature("rp1").set("markerpos", "datapoints");
    model.result("pg5").feature("rp1").set("linewidth", "preference");

//    In the Settings window for Radiation Pattern, locate the Evaluation section.
//    Find the Angles subsection.
//    In the Number of angles text field, type 90.

    model.result("pg5").feature("rp1").set("phidisc", 90);

//    From the Restriction list, select Manual.

    model.result("pg5").feature("rp1").set("anglerestr", "manual");

//    In the φ start text field, type -90.

    model.result("pg5").feature("rp1").set("phimin", -90);

//    In the φ range text field, type 180.

    model.result("pg5").feature("rp1").set("phirange", 180);

//    From the Compute beamwidth list, select On.

    model.result("pg5").feature("rp1").set("beamwidth", true);

//    In the Level down text field, type 3.

    model.result("pg5").feature("rp1").set("leveldown", 3);

//    Find the Evaluation distance subsection.
//    In the Radius text field, type Rfar.

    model.result("pg5").feature("rp1").set("radius", "Rfar");

//    In the Beamwidth Polar toolbar, click Plot.

    model.result("pg5").run();

//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg6", "PlotGroup1D");
    model.result("pg6").run();

//    In the Settings window for 1D Plot Group, type Beamwidth in the Label text field.

    model.result("pg6").label("Beamwidth");

//    Locate the Data section.
//    From the Dataset list, select None.

    model.result("pg6").set("data", "none");

//    Locate the Title section.
//    From the Title type list, select Label.

    model.result("pg6").set("titletype", "label");

//    Locate the Plot Settings section.
//    Select the x-axis label checkbox.

    model.result("pg6").set("xlabelactive", true);

//    In the associated text field, type f (Hz).

    model.result("pg6").set("xlabel", "f (Hz)");

//    Select the y-axis label checkbox.

    model.result("pg6").set("ylabelactive", true);

//    In the associated text field, type Beamwidth (deg).

    model.result("pg6").set("ylabel", "Beamwidth (deg)");

//    In the Beamwidth toolbar, click Table Graph.

    model.result("pg6").create("tblp1", "Table");
    model.result("pg6").feature("tblp1").set("markerpos", "datapoints");
    model.result("pg6").feature("tblp1").set("linewidth", "preference");

//    In the Settings window for Table Graph, click to expand the Legends section.
//    Select the Show legends checkbox.

    model.result("pg6").feature("tblp1").set("legend", true);

//    In the Beamwidth toolbar, click Global.

    model.result("pg6").create("glob1", "Global");
    model.result("pg6").feature("glob1").set("markerpos", "datapoints");
    model.result("pg6").feature("glob1").set("linewidth", "preference");

//    In the Settings window for Global, locate the Data section.
//    From the Dataset list, select Study 1/Solution 1 (sol1).

    model.result("pg6").feature("glob1").set("data", "dset1");

//    Locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg6").feature("glob1").setIndex("expr", "2*asin(1.616/ka)/pi*180", 0);
    model.result("pg6").feature("glob1").setIndex("unit", "rad", 0);
    model.result("pg6").feature("glob1").setIndex("descr", "Beamwidth (-3 dB), analytical", 0);
    model.result("pg6").feature("glob1").setIndex("expr", "2*asin(0.610*2*pi/ka)/pi*180", 1);
    model.result("pg6").feature("glob1").setIndex("unit", "rad", 1);
    model.result("pg6").feature("glob1").setIndex("descr", "Null-to-null beamwidth, analytical", 1);

//    Click to expand the Coloring and Style section.
//    Find the Line style subsection.
//    From the Line list, select None.

    model.result("pg6").feature("glob1").set("linestyle", "none");

//    Find the Line markers subsection.
//    From the Marker list, select Point.

    model.result("pg6").feature("glob1").set("linemarker", "point");

//    From the Positioning list, select Interpolated.

    model.result("pg6").feature("glob1").set("markerpos", "interp");

//    In the Number text field, type 50.

    model.result("pg6").feature("glob1").set("markers", 50);

//    In the Beamwidth toolbar, click Plot.

    model.result("pg6").run();

//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg7", "PlotGroup1D");
    model.result("pg7").run();

//    In the Settings window for 1D Plot Group, type Radiated Power in the Label text field.

    model.result("pg7").label("Radiated Power");

//    Locate the Title section.
//    From the Title type list, select Label.

    model.result("pg7").set("titletype", "label");

//    Locate the Plot Settings section.
//    Select the x-axis label checkbox.

    model.result("pg7").set("xlabelactive", true);

//    In the associated text field, type f (Hz).

    model.result("pg7").set("xlabel", "f (Hz)");

//    Select the y-axis label checkbox.

    model.result("pg7").set("ylabelactive", true);

//    In the associated text field, type Power (W).

    model.result("pg7").set("ylabel", "Power (W)");

//    Locate the Axis section.
//    Select the x-axis log scale checkbox.

    model.result("pg7").set("xlog", true);

//    Locate the Legend section.
//    From the Position list, select Upper left.

    model.result("pg7").set("legendpos", "upperleft");

//    In the Radiated Power toolbar, click Global.

    model.result("pg7").create("glob1", "Global");
    model.result("pg7").feature("glob1").set("markerpos", "datapoints");
    model.result("pg7").feature("glob1").set("linewidth", "preference");

//    In the Settings window for Global, locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg7").feature("glob1").setIndex("expr", "W", 0);
    model.result("pg7").feature("glob1").setIndex("unit", "W", 0);
    model.result("pg7").feature("glob1").setIndex("descr", "COMSOL Model", 0);

//    Locate the Coloring and Style section.
//    From the Width list, select 2.

    model.result("pg7").feature("glob1").set("linewidth", 2);

//    In the Radiated Power toolbar, click Global.

    model.result("pg7").create("glob2", "Global");
    model.result("pg7").feature("glob2").set("markerpos", "datapoints");
    model.result("pg7").feature("glob2").set("linewidth", "preference");

//    In the Settings window for Global, locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg7").feature("glob2").setIndex("expr", "W_ana", 0);
    model.result("pg7").feature("glob2").setIndex("unit", "W", 0);
    model.result("pg7").feature("glob2").setIndex("descr", "Radiated power (analytical)", 0);

//    Locate the Coloring and Style section.
//    Find the Line style subsection.
//    From the Line list, select None.

    model.result("pg7").feature("glob2").set("linestyle", "none");

//    From the Color list, select Red.

    model.result("pg7").feature("glob2").set("linecolor", "red");

//    From the Width list, select 2.

    model.result("pg7").feature("glob2").set("linewidth", 2);

//    Find the Line markers subsection.
//    From the Marker list, select Point.

    model.result("pg7").feature("glob2").set("linemarker", "point");

//    From the Positioning list, select Interpolated.

    model.result("pg7").feature("glob2").set("markerpos", "interp");

//    In the Number text field, type 50.

    model.result("pg7").feature("glob2").set("markers", 50);

//    In the Radiated Power toolbar, click Plot.

    model.result("pg7").run();

//    The total radiated power should look like the one in the figure below.
//    In the Results toolbar, click 2D Plot Group.

    model.result().create("pg8", "PlotGroup2D");
    model.result("pg8").run();

//    In the Settings window for 2D Plot Group, type Exterior Field in the Label text field.

    model.result("pg8").label("Exterior Field");

//    Locate the Data section.
//    From the Dataset list, select Grid 2D 1.

    model.result("pg8").set("data", "grid1");

//    From the Parameter value (freq (Hz)) list, select 5994.8.

    model.result("pg8").setIndex("looplevel", 26, 0);

//    Locate the Title section.
//    From the Title type list, select Label.

    model.result("pg8").set("titletype", "label");

//    Locate the Color Legend section.
//    Select the Show units checkbox.

    model.result("pg8").set("showlegendsunit", true);

//    In the Exterior Field toolbar, click Surface.

    model.result("pg8").create("surf1", "Surface");
    model.result("pg8").feature("surf1").set("evaluationsettings", "parent");

//    In the Settings window for Surface, locate the Data section.
//    From the Dataset list, select Mirror 2D 1.

    model.result("pg8").feature("surf1").set("data", "mir1");

//    From the Parameter value (freq (Hz)) list, select 5994.8.

    model.result("pg8").feature("surf1").setIndex("looplevel", 26, 0);

//    Locate the Coloring and Style section.
//    From the Color table list, select Wave.
//    In the Exterior Field toolbar, click Height Expression.

    model.result("pg8").feature("surf1").create("hght1", "Height");
    model.result("pg8").run();

//    In the Settings window for Height Expression, locate the Axis section.
//    Select the Scale factor checkbox.

    model.result("pg8").feature("surf1").feature("hght1").set("scaleactive", true);

//    In the associated text field, type 1.E-4.

    model.result("pg8").feature("surf1").feature("hght1").set("scale", "1.E-4");

//    In the Offset text field, type 0.15.

    model.result("pg8").feature("surf1").feature("hght1").set("offset", 0.15);
    model.result("pg8").run();

//    In the Model Builder window, under Results, click Exterior Field.
//    In the Exterior Field toolbar, click Surface.

    model.result("pg8").create("surf2", "Surface");
    model.result("pg8").feature("surf2").set("evaluationsettings", "parent");

//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type pext(r,z).

    model.result("pg8").feature("surf2").set("expr", "pext(r,z)");

//    Click to expand the Inherit Style section.
//    From the Plot list, select Surface 1.

    model.result("pg8").feature("surf2").set("inheritplot", "surf1");

//    In the Exterior Field toolbar, click Filter.

    model.result("pg8").feature("surf2").create("filt1", "Filter");
    model.result("pg8").run();

//    It is necessary to use a filter here for the computation of the Kirchhoff-Helmholtz integral (Exterior Field). The kernel is not numerically well defined near the source boundaries.
//    In the Settings window for Filter, locate the Element Selection section.
//    In the Logical expression for inclusion text field, type sqrt(z^2+r^2)>1.01*Rmodel.

    model.result("pg8").feature("surf2").feature("filt1").set("expr", "sqrt(z^2+r^2)>1.01*Rmodel");
    model.result("pg8").run();

//    In the Model Builder window, click Surface 2.
//    In the Exterior Field toolbar, click Height Expression.

    model.result("pg8").feature("surf2").create("hght1", "Height");
    model.result("pg8").run();

//    In the Settings window for Height Expression, locate the Axis section.
//    In the Offset text field, type 0.15.

    model.result("pg8").feature("surf2").feature("hght1").set("offset", 0.15);
    model.result("pg8").run();

//    In the Model Builder window, under Results, click Exterior Field.
//    In the Exterior Field toolbar, click Contour.

    model.result("pg8").create("con1", "Contour");
    model.result("pg8").feature("con1").set("evaluationsettings", "parent");

//    In the Settings window for Contour, locate the Data section.
//    From the Dataset list, select Mirror 2D 1.

    model.result("pg8").feature("con1").set("data", "mir1");

//    From the Parameter value (freq (Hz)) list, select 5994.8.

    model.result("pg8").feature("con1").setIndex("looplevel", 26, 0);

//    Locate the Coloring and Style section.
//    From the Color table list, select Wave.
//    Clear the Color legend checkbox.

    model.result("pg8").feature("con1").set("colorlegend", false);
    model.result("pg8").run();

//    In the Model Builder window, click Exterior Field.
//    In the Exterior Field toolbar, click Contour.

    model.result("pg8").create("con2", "Contour");
    model.result("pg8").feature("con2").set("evaluationsettings", "parent");

//    In the Settings window for Contour, locate the Expression section.
//    In the Expression text field, type pext(r,z).

    model.result("pg8").feature("con2").set("expr", "pext(r,z)");

//    Locate the Coloring and Style section.
//    Clear the Color legend checkbox.

    model.result("pg8").feature("con2").set("colorlegend", false);

//    Click to expand the Inherit Style section.
//    From the Plot list, select Contour 1.

    model.result("pg8").feature("con2").set("inheritplot", "con1");

//    In the Exterior Field toolbar, click Filter.

    model.result("pg8").feature("con2").create("filt1", "Filter");
    model.result("pg8").run();

//    In the Settings window for Filter, locate the Element Selection section.
//    In the Logical expression for inclusion text field, type sqrt(z^2+r^2)>1.01*Rmodel.

    model.result("pg8").feature("con2").feature("filt1").set("expr", "sqrt(z^2+r^2)>1.01*Rmodel");

//    In the Exterior Field toolbar, click Plot.

    model.result("pg8").run();

//    The exterior field should look like the one in the figure below.
//    In the Home toolbar, click Add Plot Group and choose 3D Plot Group.

    model.result().create("pg9", "PlotGroup3D");
    model.result("pg9").run();

//    In the Settings window for 3D Plot Group, type Thumbnail in the Label text field.

    model.result("pg9").label("Thumbnail");

//    Locate the Color Legend section.
//    Select the Show units checkbox.

    model.result("pg9").set("showlegendsunit", true);

//    In the Thumbnail toolbar, click Surface.

    model.result("pg9").create("surf1", "Surface");
    model.result("pg9").feature("surf1").set("evaluationsettings", "parent");

//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type acpr.Lp.

    model.result("pg9").feature("surf1").set("expr", "acpr.Lp");

//    Locate the Coloring and Style section.
//    From the Color table list, select Rainbow.

    return model;
  }

  public static Model run3(Model model) {

    model.result("pg9").feature("surf1").set("colortable", "Rainbow");

//    From the Scale list, select Linear.

    model.result("pg9").feature("surf1").set("colorscalemode", "linear");

//    In the Thumbnail toolbar, click Plot.

    model.result("pg9").run();

    model.title("Baffled Piston Radiation");

    model
         .description("An axisymmetric model of a rigid piston in an infinite baffle is used to exemplify the Exterior Field Calculation feature of the Acoustics Module. The radiation results provided by the COMSOL Multiphysics\u00ae software are compared to analytical results for the on-axis radiation pattern (as a function of distance), the spatial far-field response, and the total radiated power. The transition from near-field to far-field is smooth and continuous.");

    return model;
  }

  public static void main(String[] args) {
    Model model = run();
    model = run2(model);
    run3(model);
  }

}
