/*
 * perforated_muffler.java
 */

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

/** Model exported on May 12 2026, 12:50 by COMSOL 6.4.0.418. */
public class perforated_muffler {

  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 3D.
//    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", 3);
    model.component("comp1").geom("geom1").geomRep("comsol");

    model.component("comp1").mesh().create("mesh1");
    model.component("comp1").mesh("mesh1").contribute("geom/detail", true);

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

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

//    A horizontal symmetry plane through the muffler means that it is sufficient to model only half of the geometry. Here, the entire geometry is imported as a sequence from the geometry file. The instructions to the geometry can be found in the appendix at the end of this document.
//    In the Geometry toolbar, click Insert Sequence and choose Insert Sequence.

    model.component("comp1").geom("geom1").insertFile("perforated_muffler_geom_sequence.mph", "geom1");

//    Browse to the model's Application Library folder and double-click the file perforated_muffler_geom_sequence.mph.
//    In the Geometry toolbar, click Build All.

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

//    You should now see the upper half of a muffler in the drawing area.
//    Enter the parameters needed for the model or load them from the file perforated_muffler_parameters.txt.
//    In the Model Builder window, under Global Definitions, click Parameters 1.
//    In the Settings window for Parameters, locate the Parameters section.
//    In the table, enter the following settings:

    model.param().set("p0", "1[Pa]");
    model.param().descr("p0", "Inlet pressure");
    model.param().set("t_w", "1.5[mm]");
    model.param().descr("t_w", "Wall thickness");
    model.param().set("d_h", "5[mm]");
    model.param().descr("d_h", "Hole diameter");
    model.param().set("sigma_p", "0.22");
    model.param().descr("sigma_p", "Porosity, pipe perforates");
    model.param().set("sigma_bi", "0.46");
    model.param().descr("sigma_bi", "Porosity, baffles on inlet side");
    model.param().set("sigma_bo", "0.3");
    model.param().descr("sigma_bo", "Porosity, baffles on outlet side");

//    Define the following interpolation function (measurement data) and variable definitions so that you can compute the transmission loss and compare it with experimental data.
//    In the Definitions toolbar, click Interpolation.

    model.component("comp1").func().create("int1", "Interpolation");

//    In the Settings window for Interpolation, locate the Definition section.
//    From the Data source list, select File.

    model.component("comp1").func("int1").set("source", "file");

//    Click Browse.
//    Browse to the model's Application Library folder and double-click the file perforated_muffler_exp_data.txt.

    model.component("comp1").func("int1").set("filename", "perforated_muffler_exp_data.txt");

//    Click Import.

    model.component("comp1").func("int1").importData();

//    In the Function name text field, type TL_exp.

    model.component("comp1").func("int1").set("funcname", "TL_exp");

//    The walls of the muffler are considered perfectly rigid and will not use any material properties. The only material you need to select is air.
//    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.
//    With all selections, variables, and material settings completed, it is time to set up the physics.
//    All boundaries that are exterior to the geometry are by default assigned the Sound Hard boundary condition. Start by applying the Interior Sound Hard condition to the interior rigid walls.
//    In the Physics toolbar, click Boundaries and choose Interior Sound Hard Boundary (Wall).

    model.component("comp1").physics("acpr").create("ishb1", "InteriorSoundHard", 2);

//    In the Settings window for Interior Sound Hard Boundary (Wall), locate the Boundary Selection section.
//    From the Selection list, select Interior Hard Walls.

    model.component("comp1").physics("acpr").feature("ishb1").selection().named("geom1_difsel1");

//    You need four Interior Perforated Plate conditions, one for each different set of parameters. The Thin plate (default) model type is appropriate here since the value <eqv>kt<sub>p</sub> </eqv> is much less than <eqv>1</eqv>.
//    In the Physics toolbar, click Boundaries and choose Interior Perforated Plate.

    model.component("comp1").physics("acpr").create("ipp1", "InteriorPerforatedPlate", 2);

//    In the Settings window for Interior Perforated Plate, locate the Boundary Selection section.
//    From the Selection list, select Pipe Perforates.

    model.component("comp1").physics("acpr").feature("ipp1").selection().named("geom1_sel3");

//    Locate the Interior Perforated Plate section.
//    In the \[\sigma\] text field, type sigma_p.

    model.component("comp1").physics("acpr").feature("ipp1").set("porArea", "sigma_p");

//    In the \[t_{\textrm{p}}\] text field, type t_w.

    model.component("comp1").physics("acpr").feature("ipp1").set("tp", "t_w");

//    In the \[d_\textrm{h}\] text field, type d_h.

    model.component("comp1").physics("acpr").feature("ipp1").set("dh", "d_h");

//    Locate the Fluid Properties section.
//    From the Fluid material list, select Air (mat1).

    model.component("comp1").physics("acpr").feature("ipp1").set("FluidMaterial", "mat1");

//    In the Physics toolbar, click Boundaries and choose Interior Perforated Plate.

    model.component("comp1").physics("acpr").create("ipp2", "InteriorPerforatedPlate", 2);

//    In the Settings window for Interior Perforated Plate, locate the Boundary Selection section.
//    From the Selection list, select Pipe Perforate with Sleeve.

    model.component("comp1").physics("acpr").feature("ipp2").selection().named("geom1_sel4");

//    Locate the Interior Perforated Plate section.
//    In the \[\sigma\] text field, type sigma_p.

    model.component("comp1").physics("acpr").feature("ipp2").set("porArea", "sigma_p");

//    In the \[t_{\textrm{p}}\] text field, type t_w.

    model.component("comp1").physics("acpr").feature("ipp2").set("tp", "t_w");

//    In the \[d_\textrm{h}\] text field, type d_h.

    model.component("comp1").physics("acpr").feature("ipp2").set("dh", "d_h");

//    Locate the Fluid Properties section.
//    From the Fluid material list, select Air (mat1).

    model.component("comp1").physics("acpr").feature("ipp2").set("FluidMaterial", "mat1");

//    Locate the Interior Perforated Plate section.
//    Select the User-defined contribution checkbox.

    model.component("comp1").physics("acpr").feature("ipp2").set("IncludeUserDefinedTerms", true);

//    In the \[\theta^{\textrm{(user)}}\] text field, type 1.

    model.component("comp1").physics("acpr").feature("ipp2").set("theta", 1);

//    The user-defined resistance represents the impedance contribution from the metallic sleeve outside the pipe.
//    In the Physics toolbar, click Boundaries and choose Interior Perforated Plate.

    model.component("comp1").physics("acpr").create("ipp3", "InteriorPerforatedPlate", 2);

//    In the Settings window for Interior Perforated Plate, locate the Boundary Selection section.
//    From the Selection list, select Inlet Baffle Perforates.

    model.component("comp1").physics("acpr").feature("ipp3").selection().named("geom1_sel5");

//    Locate the Interior Perforated Plate section.
//    In the \[\sigma\] text field, type sigma_bi.

    model.component("comp1").physics("acpr").feature("ipp3").set("porArea", "sigma_bi");

//    In the \[t_{\textrm{p}}\] text field, type t_w.

    model.component("comp1").physics("acpr").feature("ipp3").set("tp", "t_w");

//    In the \[d_\textrm{h}\] text field, type d_h.

    model.component("comp1").physics("acpr").feature("ipp3").set("dh", "d_h");

//    Locate the Fluid Properties section.
//    From the Fluid material list, select Air (mat1).

    model.component("comp1").physics("acpr").feature("ipp3").set("FluidMaterial", "mat1");

//    In the Physics toolbar, click Boundaries and choose Interior Perforated Plate.

    model.component("comp1").physics("acpr").create("ipp4", "InteriorPerforatedPlate", 2);

//    In the Settings window for Interior Perforated Plate, locate the Boundary Selection section.
//    From the Selection list, select Outlet Baffle Perforates.

    model.component("comp1").physics("acpr").feature("ipp4").selection().named("geom1_sel6");

//    Locate the Interior Perforated Plate section.
//    In the \[\sigma\] text field, type sigma_bo.

    model.component("comp1").physics("acpr").feature("ipp4").set("porArea", "sigma_bo");

//    In the \[t_{\textrm{p}}\] text field, type t_w.

    model.component("comp1").physics("acpr").feature("ipp4").set("tp", "t_w");

//    In the \[d_\textrm{h}\] text field, type d_h.

    model.component("comp1").physics("acpr").feature("ipp4").set("dh", "d_h");

//    Locate the Fluid Properties section.
//    From the Fluid material list, select Air (mat1).

    model.component("comp1").physics("acpr").feature("ipp4").set("FluidMaterial", "mat1");

//    Use the Port boundary conditions at the inlet and outlet. Note that the first port at the inlet has an incident field excitation. Both ports capture ingoing and outgoing plane-wave modes. If the frequency range is extended above the cutoff frequency of the first nonplane mode, then add more ports at the inlet and outlet to capture these. The cutoff frequency of a port can be evaluated in postprocessing.
//    In the Physics toolbar, click Boundaries and choose Port.

    model.component("comp1").physics("acpr").create("port1", "Port", 2);

//    In the Settings window for Port, locate the Boundary Selection section.
//    From the Selection list, select Inlet.

    model.component("comp1").physics("acpr").feature("port1").selection().named("geom1_sel1");

//    Locate the Port Properties section.
//    From the Type of port list, select Circular.

    model.component("comp1").physics("acpr").feature("port1").set("PortType", "Circular");

//    Locate the Incident Mode Settings section.
//    In the \[A_\textrm{p}^\textrm{in}\] text field, type p0.

    model.component("comp1").physics("acpr").feature("port1").set("pamp", "p0");

//    In the Physics toolbar, click Attributes and choose Port Reference Axis.

    model.component("comp1").physics("acpr").feature("port1").create("cpra1", "CircularPortReferenceAxis", 0);

//    Select two points at the inlet boundary to define the reference for the azimuthal angle. This becomes important if higher-order modes are included in the model. Note that because of the symmetry only certain symmetric modes should be selected.
//    In the Settings window for Port Reference Axis, locate the Point Selection section.
//    Click Clear Selection.

    model.component("comp1").physics("acpr").feature("port1").feature("cpra1").selection().set();

//    Select Points 5, 8.

    model.component("comp1").physics("acpr").feature("port1").feature("cpra1").selection().set(5, 8);

//    In the Physics toolbar, click Boundaries and choose Port.

    model.component("comp1").physics("acpr").create("port2", "Port", 2);

//    In the Settings window for Port, locate the Boundary Selection section.
//    From the Selection list, select Outlet.

    model.component("comp1").physics("acpr").feature("port2").selection().named("geom1_sel2");

//    Locate the Port Properties section.
//    From the Type of port list, select Circular.

    model.component("comp1").physics("acpr").feature("port2").set("PortType", "Circular");

//    In the Physics toolbar, click Attributes and choose Port Reference Axis.

    model.component("comp1").physics("acpr").feature("port2").create("cpra1", "CircularPortReferenceAxis", 0);

//    In the Settings window for Port Reference Axis, locate the Point Selection section.
//    Click Clear Selection.

    model.component("comp1").physics("acpr").feature("port2").feature("cpra1").selection().set();

//    Select Points 1, 4.

    model.component("comp1").physics("acpr").feature("port2").feature("cpra1").selection().set(1, 4);

//    In the Physics toolbar, click Boundaries and choose Symmetry.

    model.component("comp1").physics("acpr").create("sym1", "Symmetry", 2);

//    In the Settings window for Symmetry, locate the Boundary Selection section.
//    From the Selection list, select Symmetry.

    model.component("comp1").physics("acpr").feature("sym1").selection().named("geom1_boxsel1");

//    Mesh
//    Proceed and generate the mesh using the <l>Physics-controlled mesh</l> functionality. The frequency controlling the maximum element size is per default taken <l>From study</l>. Set the desired <l>Frequencies</l> in the study step. In general, 5 to 6 second-order elements per wavelength are needed to resolve the waves. For more details, see <em>Meshing (Resolving the Waves)</em> in the <em>Acoustics Module User's Guide</em>. In this model, use 8 elements per wavelength; the default <l>Automatic</l> is to have 5.
//    Select to solve for the frequency range from 20 Hz to 600 Hz, in steps of 5 Hz.
//    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.
//    In the Frequencies text field, type range(20,5,600).

    model.study("std1").feature("freq").set("plist", "range(20,5,600)");

//    In the Model Builder window, under Component 1 (comp1), click Mesh 1.
//    In the Settings window for Mesh, locate the Pressure Acoustics, Frequency Domain (acpr) section.
//    From the Number of mesh elements per wavelength list, select User defined.

    model.component("comp1").physics("acpr").prop("MeshControl").set("ElementsPerWavelength", "UserDefined");

//    In the text field, type 8.

    model.component("comp1").physics("acpr").prop("MeshControl").set("nperlambda", 8);

//    Click Build All.

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

//    In the Home toolbar, click Compute.

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

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

    model.result().create("pg1", "PlotGroup3D");
    model.result("pg1").set("data", "dset1");
    model.result("pg1").setIndex("looplevel", 117, 0);
    model.result("pg1").create("surf1", "Surface");
    model.result("pg1").feature("surf1").set("expr", new String[]{"acpr.p_t"});
    model.result("pg1").feature("surf1").set("colortable", "Wave");
    model.result("pg1").feature("surf1").set("colorscalemode", "linearsymmetric");
    model.result("pg1").set("showlegendsunit", true);
    model.result("pg1").label("Acoustic Pressure (acpr)");
    model.result().create("pg2", "PlotGroup3D");
    model.result("pg2").set("data", "dset1");
    model.result("pg2").setIndex("looplevel", 117, 0);
    model.result("pg2").create("surf1", "Surface");
    model.result("pg2").feature("surf1").set("expr", new String[]{"acpr.Lp_t"});
    model.result("pg2").feature("surf1").set("colortable", "Rainbow");
    model.result("pg2").feature("surf1").set("colorscalemode", "linear");
    model.result("pg2").set("showlegendsunit", true);
    model.result("pg2").label("Sound Pressure Level (acpr)");
    model.result().create("pg3", "PlotGroup3D");
    model.result("pg3").set("data", "dset1");
    model.result("pg3").setIndex("looplevel", 117, 0);
    model.result("pg3").create("iso1", "Isosurface");
    model.result("pg3").feature("iso1").set("expr", new String[]{"acpr.p_t"});
    model.result("pg3").feature("iso1").set("number", "10");
    model.result("pg3").feature("iso1").set("colortable", "Wave");
    model.result("pg3").feature("iso1").set("colorscalemode", "linearsymmetric");
    model.result("pg3").set("showlegendsunit", true);
    model.result("pg3").label("Acoustic Pressure, Isosurfaces (acpr)");
    model.result("pg1").run();

//    Create a Mirror 3D dataset in order to visualize the solution on the full geometry.
//    In the Results toolbar, click More Datasets and choose Mirror 3D.

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

//    In the Settings window for Mirror 3D, locate the Plane Data section.
//    From the Plane list, select XY-planes.

    model.result().dataset("mir1").set("quickplane", "xy");
    model.result("pg1").run();

//    In the Model Builder window, under Results, click Acoustic Pressure (acpr).
//    In the Settings window for 3D Plot Group, locate the Data section.
//    From the Dataset list, select Mirror 3D 1.

    model.result("pg1").set("data", "mir1");

//    In the Acoustic Pressure (acpr) toolbar, click Plot.

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

//    The plot shows the pressure distribution on the surface of the muffler. Follow the instructions to see the sound pressure level on a slice inside it.

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

//    In the Model Builder window, expand the Results > Sound Pressure Level (acpr) node.
//    Right-click Surface 1 and choose Disable.

    model.result("pg2").feature("surf1").active(false);
    model.result("pg2").run();

//    In the Model Builder window, click Sound Pressure Level (acpr).
//    In the Settings window for 3D Plot Group, locate the Data section.
//    From the Dataset list, select Mirror 3D 1.

    model.result("pg2").set("data", "mir1");

//    In the Sound Pressure Level (acpr) toolbar, click More Plots and choose Multislice.

    model.result("pg2").create("mslc1", "Multislice");
    model.result("pg2").feature("mslc1").set("evaluationsettings", "parent");

//    In the Settings window for Multislice, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Pressure Acoustics, Frequency Domain > Pressure and sound pressure level > acpr.Lp_t - Total sound pressure level - dB.

    model.result("pg2").feature("mslc1").set("expr", "acpr.Lp_t");
    model.result("pg2").feature("mslc1").set("descr", "Total sound pressure level");

//    Locate the Multiplane Data section.
//    Find the x-planes subsection.
//    In the Planes text field, type 5.

    model.result("pg2").feature("mslc1").set("xnumber", "5");

//    Find the y-planes subsection.
//    In the Planes text field, type 0.

    model.result("pg2").feature("mslc1").set("ynumber", "0");

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

    model.result("pg2").feature("mslc1").set("colortable", "Rainbow");

//    From the Scale list, select Linear.

    model.result("pg2").feature("mslc1").set("colorscalemode", "linear");

//    In the Sound Pressure Level (acpr) toolbar, click Plot.

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

//    In the Model Builder window, click Sound Pressure Level (acpr).
//    In the Settings window for 3D Plot Group, locate the Data section.
//    From the Parameter value (freq (Hz)) list, select 530.

    model.result("pg2").setIndex("looplevel", 103, 0);

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

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

//    Locate the Color Legend section.
//    From the Position list, select Bottom.

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

//    In the Sound Pressure Level (acpr) toolbar, click Plot.

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

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

    model.result("pg2").setIndex("looplevel", 108, 0);

//    In the Sound Pressure Level (acpr) toolbar, click Plot.

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

//    In the Model Builder window, click Acoustic Pressure, Isosurfaces (acpr).
//    In the Settings window for 3D Plot Group, locate the Data section.
//    From the Dataset list, select Mirror 3D 1.

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

//    In the Acoustic Pressure, Isosurfaces (acpr) toolbar, click Plot.

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

//    The last default plot, depicting pressure isosurfaces should look like the figure below.
//    In the Results toolbar, click 1D Plot Group.

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

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

    model.result("pg4").label("Transmission Loss");

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

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

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

    model.result("pg4").set("xlabel", "Frequency (Hz)");

//    Select the y-axis label checkbox.

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

//    In the associated text field, type Transmission loss (dB).

    model.result("pg4").set("ylabel", "Transmission loss (dB)");

//    In the Model Builder window, click Transmission Loss.
//    In the Transmission Loss toolbar, click More Plots and choose Octave Band.

    model.result("pg4").create("oct1", "OctaveBand");
    model.result("pg4").feature("oct1").set("quantity", "bandpower");
    model.result("pg4").feature("oct1").set("markerpos", "datapoints");
    model.result("pg4").feature("oct1").set("linewidth", "preference");

//    In the Settings window for Octave Band, locate the Selection section.
//    From the Geometric entity level list, select Global.

    model.result("pg4").feature("oct1").selection().geom("geom1");

//    Locate the y-Axis Data section.
//    From the Expression type list, select Power.

    model.result("pg4").feature("oct1").set("exprtype", "power");

//    In the Expression text field, type acpr.port1.P_in.

    model.result("pg4").feature("oct1").set("expr", "acpr.port1.P_in");

    return model;
  }

  public static Model run2(Model model) {

//    In the Power reference text field, type acpr.port2.P_out.

    model.result("pg4").feature("oct1").set("powerref", "acpr.port2.P_out");

//    Locate the Plot section.
//    From the Quantity list, select Continuous power spectral density.

    model.result("pg4").feature("oct1").set("quantity", "continuous");

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

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

//    From the Legends list, select Manual.

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

//    In the table, enter the following settings:

    model.result("pg4").feature("oct1").setIndex("legends", "Computed", 0);

//    Right-click Octave Band 1 and choose Global.

    model.result("pg4").create("glob1", "Global");
    model.result("pg4").feature("glob1").set("markerpos", "datapoints");
    model.result("pg4").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("pg4").feature("glob1").setIndex("expr", "TL_exp(freq)", 0);
    model.result("pg4").feature("glob1").setIndex("unit", "", 0);
    model.result("pg4").feature("glob1").setIndex("descr", "Transmission loss", 0);

//    Click to expand the Coloring and Style section.
//    Find the Line markers subsection.
//    From the Marker list, select None.
//    Click to expand the Legends section.
//    From the Legends list, select Manual.

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

//    In the table, enter the following settings:

    model.result("pg4").feature("glob1").setIndex("legends", "Measured", 0);
    model.result("pg4").run();

//    In the Model Builder window, click Transmission Loss.
//    In the Settings window for 1D Plot Group, locate the Axis section.
//    Clear the x-axis log scale checkbox.

    model.result("pg4").set("xlog", false);

//    In the Transmission Loss toolbar, click Plot.

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

//    Finally, create a streamline plot of the acoustic intensity vector (SI unit: \[\textrm{W}/\textrm{m}}^{\textrm{2}}\]) in order to visualize the direction of propagation of the acoustic energy in the muffler system.
//    In the Results toolbar, click 3D Plot Group.

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

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

    model.result("pg5").label("Intensity");

//    Locate the Data section.
//    From the Dataset list, select Mirror 3D 1.

    model.result("pg5").set("data", "mir1");

//    Right-click Intensity and choose Streamline.

    model.result("pg5").create("str1", "Streamline");
    model.result("pg5").feature("str1").set("evaluationsettings", "parent");

//    In the Settings window for Streamline, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Pressure Acoustics, Frequency Domain > Intensity > acpr.Ix,acpr.Iy,acpr.Iz - Intensity.

    model.result("pg5").feature("str1").set("expr", new String[]{"acpr.Ix", "acpr.Iy", "acpr.Iz"});
    model.result("pg5").feature("str1").set("descr", "Intensity");

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

    model.result("pg5").feature("str1").set("linetype", "tube");

//    Right-click Streamline 1 and choose Color Expression.

    model.result("pg5").feature("str1").create("col1", "Color");
    model.result("pg5").run();

//    In the Settings window for Color Expression, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Pressure Acoustics, Frequency Domain > Intensity > acpr.I_mag - Intensity magnitude - W/m².

    model.result("pg5").feature("str1").feature("col1").set("expr", "acpr.I_mag");
    model.result("pg5").feature("str1").feature("col1").set("descr", "Intensity magnitude");

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

    model.result("pg5").feature("str1").feature("col1").set("colortable", "Rainbow");

//    From the Scale list, select Linear.

    model.result("pg5").feature("str1").feature("col1").set("colorscalemode", "linear");

//    In the Intensity toolbar, click Plot.

    model.result("pg5").run();
    model.result("pg2").run();
    model.result("pg2").setIndex("looplevel", 106, 0);

    model.title("Muffler with Perforates");

    model
         .description("The acoustics of a car muffler with perforated baffles and pipes is analyzed for a range of frequencies. The simulation results for the transmission loss are shown to agree well with experimental data.");

    return model;
  }

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

}
