/*
 * absorptive_muffler.java
 */

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

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

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

//    The instructions take you through two versions of the model, first one with a completely hollow chamber with rigid walls, then one where the chamber is lined with glass wool.
//    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");

//    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 absorptive_muffler_parameters.txt.
//    To import content from file, use:
//    model.param().loadFile("FILENAME");
    model.param().set("fmax", "2800[Hz]", "Maximum study frequency");
    model.param().set("p_in", "1[Pa]", "Amplitude of incoming pressure wave");
    model.param().set("rho_ap", "12[kg/m^3]", "Apparent density of glass wool");
    model.param().set("d_av", "10[um]", "Mean fiber diameter");
    model.param().set("R_f", "3.18e-9[N*s/m^2]*(rho_ap/1[kg/m^3])^1.53/d_av^2", "Flow resistivity");
    model.param().set("T0", "20[degC]", "Ambient temperature");
    model.param().set("p0", "1[atm]", "Ambient pressure");

//    The parameters define the physical values of the system.
//    In the Model Builder window, under Component 1 (comp1), click Geometry 1.
//    In the Settings window for Geometry, locate the Units section.
//    From the Length unit list, select mm.

    model.component("comp1").geom("geom1").lengthUnit("mm");

//    To save some time, import the geometry sequence from a file. The instructions for setting up the geometry can be found in the Geometry Sequence Instructions section at the bottom of this document.
//    In the Geometry toolbar, click Insert Sequence and choose Insert Sequence.

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

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

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

//    Having imported the geometry, it can be easily modified as it is parameterized. Simply change the value of a dimension in the parameters list: this will update the geometry automatically. The imported geometry parameters are automatically added to the <l>Parameters 1</l> node.
//    Create selections for the inlet and outlet of the muffler.
//    In the Definitions toolbar, click Explicit.

    model.component("comp1").selection().create("sel1", "Explicit");

//    In the Settings window for Explicit, type Inlet in the Label text field.

    model.component("comp1").selection("sel1").label("Inlet");

//    Locate the Input Entities section.
//    From the Geometric entity level list, select Boundary.

    model.component("comp1").selection("sel1").geom(2);

//    Select Boundary 1.

    model.component("comp1").selection("sel1").set(1);

//    In the Definitions toolbar, click Explicit.

    model.component("comp1").selection().create("sel2", "Explicit");

//    In the Settings window for Explicit, type Outlet in the Label text field.

    model.component("comp1").selection("sel2").label("Outlet");

//    Locate the Input Entities section.
//    From the Geometric entity level list, select Boundary.

    model.component("comp1").selection("sel2").geom(2);

//    Select Boundary 28.

    model.component("comp1").selection("sel2").set(28);

//    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.
//    By default, the first material you add applies to all domains so you do not need to alter the geometric scope settings.
//    In the second version of this model, you will use a lining material in Domain 2. Add such a material with an empty selection.
//    In the Model Builder window, right-click Component 1 (comp1) > Materials and choose Blank Material.

    model.component("comp1").material().create("mat2", "Common");

//    In the Settings window for Material, type Absorptive Liner in the Label text field.

    model.component("comp1").material("mat2").label("Absorptive Liner");

//    In the Model Builder window, under Component 1 (comp1) > Pressure Acoustics, Frequency Domain (acpr), click Pressure Acoustics 1.
//    In the Settings window for Pressure Acoustics, locate the Model Input section.
//    In the \[T\] text field, type T0.

    model.component("comp1").physics("acpr").feature("fpam1").set("minput_temperature", "T0");

//    In the \[p_A\] text field, type p0.

    model.component("comp1").physics("acpr").feature("fpam1").set("minput_pressure", "p0");

//    Use the <l>Port</l> boundary condition to define the inlet and outlet. The port condition is superior to the classical radiation condition in waveguide configurations. This is particularly the case when nonplane modes start to propagate. This happens above the first cutoff frequency. For the present model, the cutoff frequency for the first nonplane mode (m = 1 and n = 0) is at 2514 Hz so this mode should be included. Note that the variable <c>acpr.port2.fc</c> gives the cutoff frequency of the mode (here for the mode defined on the <l>Port 2</l> condition).
//    Note that when including an azimuthal mode in a circular port, it is necessary to add both possible azimuthal angle dependencies (sine and cosine), each as a different <l>Port</l> condition. To get a complete basis for the modal expansion at the boundary, both the sine and cosine variants of the mode need to be included, as these modes are orthogonal.
//    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("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 p_in.

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

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

    model.component("comp1").physics("acpr").feature("port1").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("port1").feature("cpra1").selection().set();

//    Select Points 1, 4.

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

//    Select two points that define a reference axis for the azimuthal angle. The setting is in general necessary when higher-order azimuthal modes are used and/or necessary.
//    In the Model Builder window, right-click Component 1 (comp1) > Pressure Acoustics, Frequency Domain (acpr) > Port 1 and choose Duplicate.

    model.component("comp1").physics("acpr").feature().duplicate("port2", "port1");

//    In the Settings window for Port, locate the Port Mode Settings section.
//    In the \[m\] text field, type 1.

    model.component("comp1").physics("acpr").feature("port2").set("m_circ", 1);

//    Locate the Incident Mode Settings section.
//    From the Incident wave excitation at this port list, select Off.

    model.component("comp1").physics("acpr").feature("port2").set("PortExcitation", "off");

//    Right-click Port 2 and choose Duplicate.

    model.component("comp1").physics("acpr").feature().duplicate("port3", "port2");

//    In the Settings window for Port, locate the Port Mode Settings section.
//    From the Azimuthal angle dependency list, select Cosine.

    model.component("comp1").physics("acpr").feature("port3").set("AzimuthalDependency", "Cosine");

//    In the Model Builder window, under Component 1 (comp1) > Pressure Acoustics, Frequency Domain (acpr), Ctrl-click to select Port 1, Port 2, Port 3.
//    Right-click and choose Group.

    model.nodeGroup().create("grp1", "Physics", "acpr");
    model.nodeGroup("grp1").placeAfter("dcont1");
    model.nodeGroup("grp1").add("port1");
    model.nodeGroup("grp1").add("port2");
    model.nodeGroup("grp1").add("port3");

//    In the Settings window for Group, type Inlet Ports in the Label text field.

    model.nodeGroup("grp1").label("Inlet Ports");

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

    model.component("comp1").physics("acpr").create("port4", "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("port4").selection().named("sel2");

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

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

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

    model.component("comp1").physics("acpr").feature("port4").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("port4").feature("cpra1").selection().set();

//    Select two points at the outlet in the same way.
//    Select Points 37, 40.

    model.component("comp1").physics("acpr").feature("port4").feature("cpra1").selection().set(37, 40);

//    In the Model Builder window, right-click Component 1 (comp1) > Pressure Acoustics, Frequency Domain (acpr) > Port 4 and choose Duplicate.

    model.component("comp1").physics("acpr").feature().duplicate("port5", "port4");

//    In the Settings window for Port, locate the Port Mode Settings section.
//    In the \[m\] text field, type 1.

    model.component("comp1").physics("acpr").feature("port5").set("m_circ", 1);

//    Right-click Port 5 and choose Duplicate.

    model.component("comp1").physics("acpr").feature().duplicate("port6", "port5");

//    In the Settings window for Port, locate the Port Mode Settings section.
//    From the Azimuthal angle dependency list, select Cosine.

    model.component("comp1").physics("acpr").feature("port6").set("AzimuthalDependency", "Cosine");

//    In the Model Builder window, under Component 1 (comp1) > Pressure Acoustics, Frequency Domain (acpr), Ctrl-click to select Port 4, Port 5, Port 6.
//    Right-click and choose Group.

    model.nodeGroup().create("grp2", "Physics", "acpr");
    model.nodeGroup("grp2").placeAfter("dcont1");
    model.nodeGroup("grp2").add("port4");
    model.nodeGroup("grp2").add("port5");
    model.nodeGroup("grp2").add("port6");

//    In the Settings window for Group, type Outlet Ports in the Label text field.

    model.nodeGroup("grp2").label("Outlet Ports");

//    Now, add a poroacoustics model for the absorptive liner domain. You will deactivate this domain when configuring the first study step.
//    In the Physics toolbar, click Domains and choose Poroacoustics.

    model.component("comp1").physics("acpr").create("pom1", "PoroacousticsModel", 3);

//    Select Domain 2.

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

//    In the Settings window for Poroacoustics, locate the Model Input section.
//    In the \[T\] text field, type T0.

    model.component("comp1").physics("acpr").feature("pom1").set("minput_temperature", "T0");

//    Locate the Porous Matrix Properties section.
//    From the Porous elastic material list, select Absorptive Liner (mat2).

    model.component("comp1").physics("acpr").feature("pom1").set("SolidMaterial", "mat2");

//    The material data for the flow resistivity will now be picked up from the Absorptive Liner material. Enter the data in the material.
//    In the Model Builder window, under Component 1 (comp1) > Materials, click Absorptive Liner (mat2).
//    In the Settings window for Material, locate the Material Contents section.
//    In the table, enter the following settings:

    model.component("comp1").material("mat2").propertyGroup()
         .create("PoroacousticsModel", "PoroacousticsModel", "Poroacoustics_model");
    model.component("comp1").material("mat2").propertyGroup("PoroacousticsModel").set("Rf", new String[]{"R_f"});

//    Proceed and generate the mesh using the <l>Physics-controlled mesh</l> functionality. 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 the default <l>Automatic</l> option, which gives 5 elements per wavelength.
//    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 Maximum mesh element size control parameter list, select Frequency.

    model.component("comp1").physics("acpr").prop("MeshControl").set("SizeControlParameter", "Frequency");

//    In the \[f_\textrm{max}\] text field, type fmax.

    model.component("comp1").physics("acpr").prop("MeshControl").set("PhysicsControlledMeshMaximumFrequency", "fmax");

//    Click Build All.

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

//    In the Model Builder window, click Study 1.
//    In the Settings window for Study, type Study 1 - No Liner in the Label text field.

    model.study("std1").label("Study 1 - No Liner");

//    In the Model Builder window, under Study 1 - No Liner, click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Study Settings section.
//    In the Frequencies text field, type range(50,25,fmax).

    model.study("std1").feature("freq").set("plist", "range(50,25,fmax)");

//    Locate the Physics and Variables Selection section.
//    Select the Modify model configuration for study step checkbox.

    model.study("std1").feature("freq").set("useadvanceddisable", true);

//    In the tree, select Component 1 (comp1) > Pressure Acoustics, Frequency Domain (acpr) > Poroacoustics 1.
//    Right-click and choose Disable.

    model.study("std1").feature("freq").set("disabledphysics", new String[]{"acpr/pom1"});

//    In the Study 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", 111, 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", 111, 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", 111, 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();

//    The first one of the default plots shows the pressure distribution on the walls of the muffler at the highest frequency, 2800 Hz.
//    The two other default plot groups show the sound pressure level on the wall surface and the pressure inside the muffler as isosurfaces.

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

//    In the Model Builder window, click Acoustic Pressure, Isosurfaces (acpr).
//    Proceed to plot the transmission loss of the muffler system. Use the Octave Band plot, which makes it possible to plot any transfer function both as band plots and as continuous curves (sweeps).
//    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, Continuous in the Label text field.

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

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

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

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

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

//    In the associated text field, type Power, incoming wave (dB, rel. outgoing wave).

    model.result("pg4").set("ylabel", "Power, incoming wave (dB, rel. outgoing wave)");

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

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

//    In the Transmission Loss, Continuous 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");

//    Start by locating and inspecting the postprocessing variables available for the port boundary conditions. Add the variable for the power of the incident mode at Port 1. Then modify the expression manually to get the ratio to the power of the outgoing wave at Port 2. This will give the transmission loss.
//    Click Replace Expression in the upper-right corner of the y-Axis Data section.
//    From the menu, choose Component 1 (comp1) > Pressure Acoustics, Frequency Domain > Ports > Port 1 > acpr.port1.P_in - Power of incident mode - W.

    model.result("pg4").feature("oct1").set("expr", "acpr.port1.P_in");
    model.result("pg4").feature("oct1").set("descr", "Power of incident mode");

//    Locate the y-Axis Data section.
//    In the Expression text field, type acpr.port1.P_in/(acpr.port4.P_out+acpr.port5.P_out+acpr.port6.P_out).

    model.result("pg4").feature("oct1")
         .set("expr", "acpr.port1.P_in/(acpr.port4.P_out+acpr.port5.P_out+acpr.port6.P_out)");

//    From the Expression type list, select Transfer function.

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

//    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", "No liner", 0);

//    In the Transmission Loss, Continuous toolbar, click Plot.

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

//    Proceed to solve the model including a layer of absorptive glass wool on the muffler line. Continue working from where you left off with the model developed thus far and add a second study to keep your existing results intact.
//    In the Home toolbar, click Add Study to open the Add Study window.
//    Find the Studies subsection.
//    In the Select Study tree, select General Studies > Frequency Domain.
//    Click Add Study in the window toolbar.

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

//    In the Home toolbar, click Add Study to close the Add Study window.
//    In the Settings window for Study, type Study 2 - Absorptive Liner in the Label text field.

    model.study("std2").label("Study 2 - Absorptive Liner");

//    Locate the Study Settings section.
//    Clear the Generate default plots checkbox.

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

//    In the Model Builder window, under Study 2 - Absorptive Liner, click Step 1: Frequency Domain.

    return model;
  }

  public static Model run2(Model model) {
//    In the Settings window for Frequency Domain, locate the Study Settings section.
//    In the Frequencies text field, type range(50,25,fmax).

    model.study("std2").feature("freq").set("plist", "range(50,25,fmax)");

//    In the Study toolbar, click Compute.

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

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

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

//    You chose not to have new default plots generated. Once the solution process is finished, you can use the existing plot groups and just switch the dataset to see how the damping material affects the solution.
//    In the Model Builder window, under Results, click Acoustic Pressure, Isosurfaces (acpr).
//    In the Settings window for 3D Plot Group, locate the Data section.
//    From the Dataset list, select Study 2 - Absorptive Liner/Solution 2 (sol2).

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

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

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

//    At 2800 Hz, the pressure in the chamber is much lower than before.
//    Proceed to study how the transmission loss has changed with the addition of the lining. First do a bit of formatting and then duplicate the first plot and select the new dataset.

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

//    In the Model Builder window, right-click Results > Transmission Loss, Continuous > Octave Band 1 and choose Duplicate.

    model.result("pg4").feature().duplicate("oct2", "oct1");
    model.result("pg4").run();

//    In the Settings window for Octave Band, locate the Data section.
//    From the Dataset list, select Study 2 - Absorptive Liner/Solution 2 (sol2).

    model.result("pg4").feature("oct2").set("data", "dset2");

//    Locate the Legends section.
//    In the table, enter the following settings:

    model.result("pg4").feature("oct2").setIndex("legends", "Absorptive liner", 0);

//    In the Transmission Loss, Continuous toolbar, click Plot.

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

//    Duplicate the Transmission Loss plot and change the format to 1/3 octave bands.

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

//    In the Model Builder window, right-click Transmission Loss, Continuous and choose Duplicate.

    model.result().duplicate("pg5", "pg4");
    model.result("pg5").run();

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

    model.result("pg5").label("Transmission Loss, 1/3 Octave Bands");
    model.result("pg5").run();

//    In the Model Builder window, expand the Transmission Loss, 1/3 Octave Bands node, then click Octave Band 1.
//    In the Settings window for Octave Band, locate the Plot section.
//    From the Quantity list, select Band average power spectral density.

    model.result("pg5").feature("oct1").set("quantity", "bandaveragepsd");

//    From the Band type list, select 1/3 octave.

    model.result("pg5").feature("oct1").set("bandtype", "octave3");
    model.result("pg5").run();

//    In the Model Builder window, click Octave Band 2.
//    In the Settings window for Octave Band, locate the Plot section.
//    From the Quantity list, select Band average power spectral density.

    model.result("pg5").feature("oct2").set("quantity", "bandaveragepsd");

//    From the Band type list, select 1/3 octave.

    model.result("pg5").feature("oct2").set("bandtype", "octave3");

//    Click to expand the Coloring and Style section.
//    From the Type list, select Outline.

    model.result("pg5").feature("oct2").set("type", "outline");

//    From the Width list, select 2.

    model.result("pg5").feature("oct2").set("linewidth", 2);

//    In the Transmission Loss, 1/3 Octave Bands toolbar, click Plot.

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

//    Now, create a plot that represents the energy flux through the muffler system. Use streamlines that follow the intensity vector. You can change between solutions and frequencies to study and visualize the sound-absorbing properties of the muffler.
//    In the Results toolbar, click 3D Plot Group.

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

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

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

//    Right-click Intensity and choose Streamline.

    model.result("pg6").create("str1", "Streamline");
    model.result("pg6").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("pg6").feature("str1").set("expr", new String[]{"acpr.Ix", "acpr.Iy", "acpr.Iz"});
    model.result("pg6").feature("str1").set("descr", "Intensity");

//    Select Boundary 1.

    model.result("pg6").feature("str1").selection().set(1);

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

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

//    In the Tube radius expression text field, type 2.

    model.result("pg6").feature("str1").set("radiusexpr", "2");

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

    model.result("pg6").feature("str1").create("col1", "Color");
    model.result("pg6").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("pg6").feature("str1").feature("col1").set("expr", "acpr.I_mag");
    model.result("pg6").feature("str1").feature("col1").set("descr", "Intensity magnitude");

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

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

//    From the Scale list, select Linear.

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

//    In the Intensity 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 Normalized Power Balance in the Label text field.

    model.result("pg7").label("Normalized Power Balance");

//    Locate the Data section.
//    From the Dataset list, select Study 2 - Absorptive Liner/Solution 2 (sol2).

    model.result("pg7").set("data", "dset2");

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

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

//    Locate the Legend section.
//    From the Layout list, select Outside graph axis area.

    model.result("pg7").set("legendlayout", "outside");

//    From the Position list, select Bottom.

    model.result("pg7").set("legendposoutside", "bottom");

//    In the Number of rows text field, type 4.

    model.result("pg7").set("legendrowcount", 4);

//    Click the y-Axis Log Scale button in the Graphics toolbar.

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

//    Locate the Axis section.
//    Select the Manual axis limits checkbox.

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

//    In the x minimum text field, type 10.

    model.result("pg7").set("xmin", 10);

//    In the x maximum text field, type 2850.

    model.result("pg7").set("xmax", 2850);

//    In the y minimum text field, type 9e-5.

    model.result("pg7").set("ymin", "9e-5");

//    In the y maximum text field, type 1.1.

    model.result("pg7").set("ymax", 1.1);

//    Right-click Normalized Power Balance and choose 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", "acpr.port1.P_out/acpr.port1.P_in", 0);
    model.result("pg7").feature("glob1").setIndex("unit", 1, 0);
    model.result("pg7").feature("glob1").setIndex("descr", "Reflected Power - Plane mode", 0);
    model.result("pg7").feature("glob1").setIndex("expr", "acpr.port3.P_out/acpr.port1.P_in", 1);
    model.result("pg7").feature("glob1").setIndex("unit", 1, 1);
    model.result("pg7").feature("glob1").setIndex("descr", "Reflected Power - Second azimuthal mode", 1);
    model.result("pg7").feature("glob1").setIndex("expr", "acpr.port4.P_out/acpr.port1.P_in", 2);
    model.result("pg7").feature("glob1").setIndex("unit", 1, 2);
    model.result("pg7").feature("glob1").setIndex("descr", "Transmitted Power - Plane mode", 2);
    model.result("pg7").feature("glob1").setIndex("expr", "acpr.port6.P_out/acpr.port1.P_in", 3);
    model.result("pg7").feature("glob1").setIndex("unit", 1, 3);
    model.result("pg7").feature("glob1").setIndex("descr", "Transmitted Power - Second azimuthal mode", 3);

//    Click to expand the Legends section.
//    Find the Prefix and suffix subsection.
//    In the Suffix text field, type - Absorptive Liner.

    model.result("pg7").feature("glob1").set("legendsuffix", " - Absorptive Liner");

//    In the Normalized Power Balance toolbar, click Plot.

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

    model.title("Absorptive Muffler");

    model
         .description("This example describes the pressure wave propagation in a muffler for an internal combustion engine. This example shows how to analyze both inductive and resistive damping in a muffler as well as the use of port boundary conditions.");

    return model;
  }

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

}
