/*
 * lumped_loudspeaker_driver.java
 */

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

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

  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.
//    In the Select Physics tree, select AC/DC > Electrical Circuit (cir).
//    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.component("comp1").physics().create("cir", "Circuit", "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 lumped_loudspeaker_driver_parameters.txt.
//    To import content from file, use:
//    model.param().loadFile("FILENAME");
    model.param().set("fmax", "10[kHz]", "Maximal study frequency");
    model.param().set("c0", "343[m/s]", "Speed of sound in air");
    model.param().set("rho0", "1.2[kg/m^3]", "Density of air");
    model.param().set("M_MD", "33.4[g]", "Moving mass (voice coil and diaphragm)");
    model.param().set("C_MS", "1.18e-3[m/N]", "Suspension compliance");
    model.param().set("R_MS", "1.85[N*s/m]", "Suspension mechanical losses");
    model.param().set("BL", "11.4[T*m]", "Force factor, flux density (B) times coil length (L)");
    model.param().set("R_E", "7[ohm]", "Voice coil resistance");
    model.param().set("L_e", "6.89[mH]", "Voice coil inductance (constant)");
    model.param().set("n_e", "0.7", "Voice coil loss factor");
    model.param().set("V0", "sqrt(2)[V]", "Driving voltage (peak)");
    model.param().set("V0rms", "V0/sqrt(2)", "Driving voltage (rms)");
    model.param().set("R_g", "0[ohm]", "Driver output resistance");
    model.param().set("a", "12[cm]", "Piston radius of driver (equivalent)");
    model.param().set("S_D", "a^2*pi", "Driver equivalent area");
    model.param().set("M_MS", "M_MD+2*S_D^2*8*rho0/(3*pi^2*a)", "Moving mass (including acoustic load)");
    model.param().set("Fs", "1/(2*pi*sqrt(C_MS*M_MS))", "Fundamental resonant frequency");
    model.param().set("Q_ES", "2*pi*Fs*M_MS*R_E/BL^2", "Electrical Q factor at Fs");
    model.param().set("Q_MS", "2*pi*Fs*M_MS/R_MS", "Mechanical Q factor at Fs");
    model.param().set("Q_TS", "Q_MS*Q_ES/(Q_MS+Q_ES)", "Total Q factor of driver at Fs");
    model.param().set("V_AS", "rho0*c0^2*S_D^2*C_MS", "Equivalent volume compliance");
    model.param().set("eta0", "4*pi^2/c0^3*Fs^3*V_AS/Q_ES", "Reference efficiency of driver");
    model.param().set("Rair", "20[cm]", "Air domain radius");
    model.param().set("Rpml", "6[cm]", "PML layer thickness");

//    Build the simple 2D axisymmetric geometry of the speaker driver by drawing some circles and lines.
//    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 1[cm].

    model.component("comp1").geom("geom1").feature("c1").set("r", "1[cm]");

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

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

//    Locate the Position section.
//    In the r text field, type a.

    model.component("comp1").geom("geom1").feature("c1").set("pos", new String[]{"a", "0"});

//    In the Geometry toolbar, click Circle.

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

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

    model.component("comp1").geom("geom1").feature("c2").set("r", "Rair+Rpml");

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

    model.component("comp1").geom("geom1").feature("c2").set("angle", 180);

//    Locate the Rotation Angle section.
//    In the Rotation text field, type -90.

    model.component("comp1").geom("geom1").feature("c2").set("rot", -90);

//    Click to expand the Layers section.
//    In the table, enter the following settings:

    model.component("comp1").geom("geom1").feature("c2").setIndex("layername", "Layer 1", 0);
    model.component("comp1").geom("geom1").feature("c2").setIndex("layer", "Rpml", 0);

//    In the Geometry toolbar, click Polygon.

    model.component("comp1").geom("geom1").run("c2");
    model.component("comp1").geom("geom1").create("pol1", "Polygon");
    model.component("comp1").geom("geom1").feature("pol1").set("source", "table");

//    In the Settings window for Polygon, locate the Object Type section.
//    From the Type list, select Open curve.

    model.component("comp1").geom("geom1").feature("pol1").set("type", "open");

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

    model.component("comp1").geom("geom1").feature("pol1").setIndex("table", "3[cm]", 0, 0);
    model.component("comp1").geom("geom1").feature("pol1").setIndex("table", "-4[cm]", 0, 1);
    model.component("comp1").geom("geom1").feature("pol1").setIndex("table", "a-1[cm]", 1, 0);
    model.component("comp1").geom("geom1").feature("pol1").setIndex("table", 0, 1, 1);

//    In the Geometry toolbar, click Polygon.

    model.component("comp1").geom("geom1").run("pol1");
    model.component("comp1").geom("geom1").create("pol2", "Polygon");
    model.component("comp1").geom("geom1").feature("pol2").set("source", "table");

//    In the Settings window for Polygon, locate the Object Type section.
//    From the Type list, select Open curve.

    model.component("comp1").geom("geom1").feature("pol2").set("type", "open");

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

    model.component("comp1").geom("geom1").feature("pol2").setIndex("table", "a+1[cm]", 0, 0);
    model.component("comp1").geom("geom1").feature("pol2").setIndex("table", 0, 0, 1);
    model.component("comp1").geom("geom1").feature("pol2").setIndex("table", "Rair", 1, 0);
    model.component("comp1").geom("geom1").feature("pol2").setIndex("table", 0, 1, 1);

//    Click Build All Objects.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Geometry toolbar, click More Primitives and choose Quadratic Bézier.

    model.component("comp1").geom("geom1").create("qb1", "QuadraticBezier");

//    In the Settings window for Quadratic Bézier, locate the Control Points section.
//    In row 2, set r to 1.8[cm].

    model.component("comp1").geom("geom1").feature("qb1").setIndex("p", "1.8[cm]", 0, 1);

//    In row 3, set r to 3[cm].

    model.component("comp1").geom("geom1").feature("qb1").setIndex("p", "3[cm]", 0, 2);

//    In row 1, set z to -3[cm].

    model.component("comp1").geom("geom1").feature("qb1").setIndex("p", "-3[cm]", 1, 0);

//    In row 2, set z to -3.1[cm].

    model.component("comp1").geom("geom1").feature("qb1").setIndex("p", "-3.1[cm]", 1, 1);

//    In row 3, set z to -4[cm].

    model.component("comp1").geom("geom1").feature("qb1").setIndex("p", "-4[cm]", 1, 2);

//    Locate the Weights section.
//    In the 2 text field, type 1.5.

    model.component("comp1").geom("geom1").feature("qb1").set("w", new double[]{1, 1.5, 1});

//    Click Build All Objects.

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

//    In the Model Builder window, right-click Geometry 1 and choose Delete Entities.

    model.component("comp1").geom("geom1").create("del1", "Delete");

//    On the object c1, select Boundaries 3, 4.

    model.component("comp1").geom("geom1").feature("del1").selection("input").set("c1", 3, 4);

//    In the Settings window for Delete Entities, click Build Selected.

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

//    In the Geometry toolbar, click Polygon.

    model.component("comp1").geom("geom1").create("pol3", "Polygon");
    model.component("comp1").geom("geom1").feature("pol3").set("source", "table");

//    In the Settings window for Polygon, locate the Object Type section.
//    From the Type list, select Open curve.

    model.component("comp1").geom("geom1").feature("pol3").set("type", "open");

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

    model.component("comp1").geom("geom1").feature("pol3").setIndex("table", 0.15, 0, 0);
    model.component("comp1").geom("geom1").feature("pol3").setIndex("table", 0, 0, 1);
    model.component("comp1").geom("geom1").feature("pol3").setIndex("table", 0.15, 1, 0);
    model.component("comp1").geom("geom1").feature("pol3").setIndex("table", -0.1, 1, 1);
    model.component("comp1").geom("geom1").feature("pol3").setIndex("table", 0, 2, 0);
    model.component("comp1").geom("geom1").feature("pol3").setIndex("table", -0.1, 2, 1);

//    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 Model variables in the Label text field.

    model.component("comp1").variable("var1").label("Model variables");

//    Locate the Variables section.
//    Click Load from File.
//    Browse to the model's Application Library folder and double-click the file lumped_loudspeaker_driver_variables_1.txt.
//    To import content from file, use:
//    model.component("comp1").variable("var1").loadFile("FILENAME");
    model.component("comp1").variable("var1")
         .set("L_E", "(L_e/(sin(n_e*pi/2)))*(acpr.omega[s/rad])^(n_e-1)", "Voice coil inductance (frequency dependent)");
    model.component("comp1").variable("var1")
         .set("Rp_E", "(L_e/(cos(n_e*pi/2)))*(acpr.omega[s/rad])^(n_e)[ohm/H]", "Resistance (losses in magnetic system)");
    model.component("comp1").variable("var1").set("u_D", "acpr.ilsb1.v_ax", "Diaphragm velocity (COMSOL)");
    model.component("comp1").variable("var1").set("F_D", "acpr.ilsb1.F_ax", "Axial pressure force (COMSOL)");
    model.component("comp1").variable("var1").set("P_AR", "acpr.ilsb1.P_front", "Radiated power (COMSOL)");
    model.component("comp1").variable("var1").set("P_E", "0.5*realdot(V0,cir.R1.i)", "Electric input power (rms)");
    model.component("comp1").variable("var1").set("eta", "P_AR/P_E", "Driver efficiency");

//    In the Definitions toolbar, click Local Variables.

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

//    In the Settings window for Variables, type Analytical approximations in the Label text field.

    model.component("comp1").variable("var2").label("Analytical approximations");

//    Locate the Variables section.
//    Click Load from File.
//    Browse to the model's Application Library folder and double-click the file lumped_loudspeaker_driver_variables_2.txt.
//    To import content from file, use:
//    model.component("comp1").variable("var2").loadFile("FILENAME");
    model.component("comp1").variable("var2").set("omega_s", "2*pi*Fs", "Fundamental resonance frequency");
    model.component("comp1").variable("var2").set("R_AE", "BL^2/(S_D^2*R_E)", "Norton equivalent");
    model.component("comp1").variable("var2").set("R_AT", "R_AE+R_MS/(S_D^2)", "Total acoustical resistance");
    model.component("comp1").variable("var2")
         .set("Qlf_D", "S_D*V0/BL*R_AE/R_AT*((1/Q_TS)*(acpr.iomega/omega_s))/((acpr.iomega/omega_s)^2+(1/Q_TS)*(acpr.iomega/omega_s)+1)", "Volume velocity transfer function (low freq. approx)");
    model.component("comp1").variable("var2")
         .set("omega_u1", "M_MS*R_E/(M_MD*L_E)", "Transition frequency (low to high approximation)");
    model.component("comp1").variable("var2")
         .set("Qhf_D", "Qlf_D/(1+acpr.iomega/omega_u1)", "Volume velocity transfer function (high freq. approximation)");
    model.component("comp1").variable("var2")
         .set("prms", "rho0*acpr.omega*sqrt(0.5*u_D*conj(u_D))*S_D/(2*pi*1[m])", "RMS pressure at 1[m] (piston)");
    model.component("comp1").variable("var2")
         .set("P_AR_ana", "pi/2*a^2*abs(u_D)^2*rho0*c0*(1-2*besselj(1,2*k0*a)/(2*k0*a))", "Radiated power (piston)");
    model.component("comp1").variable("var2").set("k0", "acpr.omega/c0", "Free space wave number");

//    In the Definitions toolbar, click Explicit.

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

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

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

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

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

//    Select Boundaries 8, 15, 18.

    model.component("comp1").selection("sel1").set(8, 15, 18);

//    In the Definitions toolbar, click Explicit.

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

//    In the Settings window for Explicit, type Baffle (interior wall) in the Label text field.

    model.component("comp1").selection("sel2").label("Baffle (interior wall)");

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

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

//    Select Boundaries 9, 11, 12, 19.

    model.component("comp1").selection("sel2").set(9, 11, 12, 19);

//    In the Definitions toolbar, click Explicit.

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

//    In the Settings window for Explicit, type Back Volume (interior wall) in the Label text field.

    model.component("comp1").selection("sel3").label("Back Volume (interior wall)");

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

    model.component("comp1").selection("sel3").geom(1);

//    Select Boundaries 4, 10.

    model.component("comp1").selection("sel3").set(4, 10);

//    In the Definitions toolbar, click Perfectly Matched Layer.

    model.component("comp1").coordSystem().create("pml1", "PML");

//    Select Domains 1, 5.

    model.component("comp1").coordSystem("pml1").selection().set(1, 5);

//    In the Settings window for Perfectly Matched Layer, locate the Scaling section.
//    From the Coordinate stretching type list, select Rational.

    model.component("comp1").coordSystem("pml1").set("stretchingType", "rational");

//    In the PML scaling factor text field, type 0.5.

    model.component("comp1").coordSystem("pml1").set("PMLfactor", "0.5");

//    In the PML scaling curvature parameter text field, type 5.

    model.component("comp1").coordSystem("pml1").set("PMLgamma", "5");

//    A good way to investigate the performance of the PML is to make a sensitivity analysis on some parameter (for example the total radiated acoustic power) with respect to changes in the PML parameters. This model does not include such a sensitivity analysis.
//    In general, increasing the curvature factor effectively shifts the resolving power of the PML toward the physical domain, which is necessary in this case since the evanescent components decay in only a fraction of a wavelength. However, if you increase it too much, you may lose resolution in the other end, that is, of the free space wavelength. Assuming that the PMLs work properly for high frequencies and curvature parameter 1, you can in principle do a convergence study increasing a constant curvature parameter until the low-frequency result converges (for 10 Hz) while making sure that the high-frequency result (for 10 kHz) is not affected. It turns out that a value of 5 yields good results in this model. A scaling factor of 0.5 further improves the results, but only by a small amount. Decreasing the scaling factor corresponds to compressing the PML layer (shortening it), which in turn effectively increases the mesh resolution.
//    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.
//    Now, set up the physics and the boundary conditions for the model. Use the interior conditions at the diaphragm and on the infinite baffle. This condition will allow for a discontinuous pressure field.
//    In the Physics toolbar, click Boundaries and choose Interior Sound Hard Boundary (Wall).

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

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

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

//    In the Physics toolbar, click Boundaries and choose Interior Lumped Speaker Boundary.

    model.component("comp1").physics("acpr").create("ilsb1", "InteriorLumpedSpeakerBoundary", 1);

//    In the Settings window for Interior Lumped Speaker Boundary, locate the Boundary Selection section.
//    From the Selection list, select Speaker.

    model.component("comp1").physics("acpr").feature("ilsb1").selection().named("sel1");

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

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

//    Select Boundary 16.

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

//    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);

//    Note that you have applied the exterior-field calculation condition only to the front of the speaker. In reality, the exterior-field condition should be applied to boundaries surrounding all sources and scatterers. This is of course not possible with an infinite baffle. However, in this specific case, a trick can be used, namely employing the fact that symmetry (in z = 0) is equal to a sound-hard wall in pressure acoustics (as indicated in the UI). So, in the infinite baffle configuration, the exterior-field condition can still be used.
//    In the Physics toolbar, click Boundaries and choose Interior Sound Hard Boundary (Wall).

    model.component("comp1").physics("acpr").create("ishb2", "InteriorSoundHard", 1);

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

    model.component("comp1").physics("acpr").feature("ishb2").selection().named("sel3");

//    This interior wall condition will be deactivated in the first study when modeling the open configuration. In the second study the interior wall is active and the speaker operates with a closed back-volume.
//    In the Electrical Circuit toolbar, click Voltage Source.

    model.component("comp1").physics("cir").create("V1", "VoltageSource", -1);

//    In the Settings window for Voltage Source, locate the Node Connections section.
//    In the table, enter the following settings:

    model.component("comp1").physics("cir").feature("V1").setIndex("Connections", 1, 0, 0);
    model.component("comp1").physics("cir").feature("V1").setIndex("Connections", 0, 1, 0);

//    Locate the Device Parameters section.
//    In the \[v_{\textrm{src}}\] text field, type V0.

    model.component("comp1").physics("cir").feature("V1").set("value", "V0");

//    In the Electrical Circuit toolbar, click Resistor.

    model.component("comp1").physics("cir").create("R1", "Resistor", -1);

//    In the Settings window for Resistor, locate the Node Connections section.
//    In the table, enter the following settings:

    model.component("comp1").physics("cir").feature("R1").setIndex("Connections", 1, 0, 0);
    model.component("comp1").physics("cir").feature("R1").setIndex("Connections", 2, 1, 0);

//    Locate the Device Parameters section.
//    In the \[R\] text field, type R_g.

    model.component("comp1").physics("cir").feature("R1").set("R", "R_g");

//    In the Electrical Circuit toolbar, click Resistor.

    model.component("comp1").physics("cir").create("R2", "Resistor", -1);

//    In the Settings window for Resistor, locate the Node Connections section.
//    In the table, enter the following settings:

    model.component("comp1").physics("cir").feature("R2").setIndex("Connections", 2, 0, 0);
    model.component("comp1").physics("cir").feature("R2").setIndex("Connections", 3, 1, 0);

//    Locate the Device Parameters section.
//    In the \[R\] text field, type R_E.

    model.component("comp1").physics("cir").feature("R2").set("R", "R_E");

//    In the Electrical Circuit toolbar, click Inductor.

    model.component("comp1").physics("cir").create("L1", "Inductor", -1);

//    In the Settings window for Inductor, locate the Node Connections section.
//    In the table, enter the following settings:

    model.component("comp1").physics("cir").feature("L1").setIndex("Connections", 3, 0, 0);
    model.component("comp1").physics("cir").feature("L1").setIndex("Connections", 4, 1, 0);

//    Locate the Device Parameters section.
//    In the \[L\] text field, type L_E.

    model.component("comp1").physics("cir").feature("L1").set("L", "L_E");

//    In the Electrical Circuit toolbar, click Resistor.

    model.component("comp1").physics("cir").create("R3", "Resistor", -1);

//    In the Settings window for Resistor, locate the Node Connections section.

    return model;
  }

  public static Model run2(Model model) {
//    In the table, enter the following settings:

    model.component("comp1").physics("cir").feature("R3").setIndex("Connections", 3, 0, 0);
    model.component("comp1").physics("cir").feature("R3").setIndex("Connections", 4, 1, 0);

//    Locate the Device Parameters section.
//    In the \[R\] text field, type Rp_E.

    model.component("comp1").physics("cir").feature("R3").set("R", "Rp_E");

//    In the Electrical Circuit toolbar, click Current-Controlled Voltage Source.

    model.component("comp1").physics("cir").create("H1", "CurrentVoltageSource", -1);

//    In the Settings window for Current-Controlled Voltage Source, locate the Node Connections section.
//    In the table, enter the following settings:

    model.component("comp1").physics("cir").feature("H1").setIndex("Connections", 4, 0, 0);
    model.component("comp1").physics("cir").feature("H1").setIndex("Connections", 0, 1, 0);

//    Locate the Current Measurement section.
//    In the Gain text field, type BL[m/Wb*ohm].

    model.component("comp1").physics("cir").feature("H1").set("gain", "BL[m/Wb*ohm]");

//    Remember to select the measured current when the mechanical circuit components have been set up.
//    In the Electrical Circuit toolbar, click Current-Controlled Voltage Source.

    model.component("comp1").physics("cir").create("H2", "CurrentVoltageSource", -1);

//    In the Settings window for Current-Controlled Voltage Source, locate the Node Connections section.
//    In the table, enter the following settings:

    model.component("comp1").physics("cir").feature("H2").setIndex("Connections", 6, 0, 0);
    model.component("comp1").physics("cir").feature("H2").setIndex("Connections", 0, 1, 0);

//    Locate the Current Measurement section.
//    In the Gain text field, type BL[m/Wb*ohm].

    model.component("comp1").physics("cir").feature("H2").set("gain", "BL[m/Wb*ohm]");

//    From the Measure current for device list, select Resistor 2 (R2).

    model.component("comp1").physics("cir").feature("H2").set("gainDevice", "R2");

//    In the Electrical Circuit toolbar, click Inductor.

    model.component("comp1").physics("cir").create("L2", "Inductor", -1);

//    In the Settings window for Inductor, locate the Node Connections section.
//    In the table, enter the following settings:

    model.component("comp1").physics("cir").feature("L2").setIndex("Connections", 6, 0, 0);
    model.component("comp1").physics("cir").feature("L2").setIndex("Connections", 7, 1, 0);

//    Locate the Device Parameters section.
//    In the \[L\] text field, type M_MD[H/kg].

    model.component("comp1").physics("cir").feature("L2").set("L", "M_MD[H/kg]");

//    In the Model Builder window, click Current-Controlled Voltage Source 1 (H1).
//    In the Settings window for Current-Controlled Voltage Source, locate the Current Measurement section.
//    From the Measure current for device list, select Inductor 2 (L2).

    model.component("comp1").physics("cir").feature("H1").set("gainDevice", "L2");

//    In the Electrical Circuit toolbar, click Resistor.

    model.component("comp1").physics("cir").create("R4", "Resistor", -1);

//    In the Settings window for Resistor, locate the Node Connections section.
//    In the table, enter the following settings:

    model.component("comp1").physics("cir").feature("R4").setIndex("Connections", 7, 0, 0);
    model.component("comp1").physics("cir").feature("R4").setIndex("Connections", 8, 1, 0);

//    Locate the Device Parameters section.
//    In the \[R\] text field, type R_MS[ohm/kg*s].

    model.component("comp1").physics("cir").feature("R4").set("R", "R_MS[ohm/kg*s]");

//    In the Electrical Circuit toolbar, click Capacitor.

    model.component("comp1").physics("cir").create("C1", "Capacitor", -1);

//    In the Settings window for Capacitor, locate the Node Connections section.
//    In the table, enter the following settings:

    model.component("comp1").physics("cir").feature("C1").setIndex("Connections", 8, 0, 0);
    model.component("comp1").physics("cir").feature("C1").setIndex("Connections", 9, 1, 0);

//    Locate the Device Parameters section.
//    In the \[C\] text field, type C_MS[F*N/m].

    model.component("comp1").physics("cir").feature("C1").set("C", "C_MS[F*N/m]");

//    In the Electrical Circuit toolbar, click External I vs. U.

    model.component("comp1").physics("cir").create("IvsU1", "ModelDeviceIV", -1);

//    In the Settings window for External I vs. U, locate the Node Connections section.
//    In the table, enter the following settings:

    model.component("comp1").physics("cir").feature("IvsU1").setIndex("Connections", 9, 0, 0);
    model.component("comp1").physics("cir").feature("IvsU1").setIndex("Connections", 0, 1, 0);

//    Locate the External Device section.
//    From the \[V\] list, select Voltage from lumped speaker boundary (acpr/ilsb1).

    model.component("comp1").physics("cir").feature("IvsU1").set("V_src", "root.comp1.acpr.ilsb1.V_cir");

//    The lumped electromechanical model defined by the electrical circuit is now fully coupled with the <l>Interior Lumped Speaker Boundary</l> feature in the finite element domain.
//    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 the default <l>Automatic</l> option, that 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 Physics-Controlled Mesh section.
//    In the table, enter the following settings:

    model.component("comp1").mesh("mesh1").contribute("physics/cir", false);

//    Now, proceed to the study and set the frequencies, before building the mesh and solving.
//    In the Model Builder window, click Study 1.
//    In the Settings window for Study, type Study 1 - Open Back-Volume in the Label text field.

    model.study("std1").label("Study 1 - Open Back-Volume");

//    In the Model Builder window, under Study 1 - Open Back-Volume, click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Study Settings section.
//    Click Range.
//    In the Range dialog, choose ISO preferred frequencies from the Entry method list.
//    In the Start frequency text field, type 10.
//    In the Stop frequency text field, type 10000.
//    From the Interval list, select 1/24 octave.
//    Click Replace.

    model.study("std1").feature("freq")
         .set("plist", "{10, 10.3, 10.6, 10.9, 11.2, 11.5, 11.8, 12.2, 12.5, 12.8, 13.2, 13.6, 14, 14.5, 15, 15.5, 16, 16.5, 17, 17.5, 18, 18.5, 19, 19.5, 20, 20.6, 21.2, 21.8, 22.4, 23, 23.6, 24.3, 25, 25.8, 26.5, 27.2, 28, 29, 30, 30.7, 31.5, 32.5, 33.5, 34.5, 35.5, 36.5, 37.5, 38.7, 40, 41.2, 42.5, 43.7, 45, 46.2, 47.5, 48.7, 50, 51.5, 53, 54.5, 56, 58, 60, 61.5, 63, 65, 67, 69, 71, 73, 75, 77.5, 80, 82.5, 85, 87.5, 90, 92.5, 95, 97.5, 100, 103, 106, 109, 112, 115, 118, 122, 125, 128, 132, 136, 140, 145, 150, 155, 160, 165, 170, 175, 180, 185, 190, 195, 200, 206, 212, 218, 224, 230, 236, 243, 250, 258, 265, 272, 280, 290, 300, 307, 315, 325, 335, 345, 355, 365, 375, 387, 400, 412, 425, 437, 450, 462, 475, 487, 500, 515, 530, 545, 560, 580, 600, 615, 630, 650, 670, 690, 710, 730, 750, 775, 800, 825, 850, 875, 900, 925, 950, 975, 1e3, 1.03e3, 1.06e3, 1.09e3, 1.12e3, 1.15e3, 1.18e3, 1.22e3, 1.25e3, 1.28e3, 1.32e3, 1.36e3, 1.4e3, 1.45e3, 1.5e3, 1.55e3, 1.6e3, 1.65e3, 1.7e3, 1.75e3, 1.8e3, 1.85e3, 1.9e3, 1.95e3, 2e3, 2.06e3, 2.12e3, 2.18e3, 2.24e3, 2.3e3, 2.36e3, 2.43e3, 2.5e3, 2.58e3, 2.65e3, 2.72e3, 2.8e3, 2.9e3, 3e3, 3.07e3, 3.15e3, 3.25e3, 3.35e3, 3.45e3, 3.55e3, 3.65e3, 3.75e3, 3.87e3, 4e3, 4.12e3, 4.25e3, 4.37e3, 4.5e3, 4.62e3, 4.75e3, 4.87e3, 5e3, 5.15e3, 5.3e3, 5.45e3, 5.6e3, 5.8e3, 6e3, 6.15e3, 6.3e3, 6.5e3, 6.7e3, 6.9e3, 7.1e3, 7.3e3, 7.5e3, 7.75e3, 8e3, 8.25e3, 8.5e3, 8.75e3, 9e3, 9.25e3, 9.5e3, 9.75e3, 1e4}");

//    Disable the interior wall that defines the closed back-volume for this first study where you use the open configuration.
//    In the Settings window for Frequency Domain, 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) > Interior Sound Hard Boundary (Wall) 2.
//    Click Disable.

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

//    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();

    model.result().create("pg1", "PlotGroup2D");
    model.result("pg1").set("data", "dset1");
    model.result("pg1").setIndex("looplevel", 241, 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", "PlotGroup2D");
    model.result("pg2").set("data", "dset1");
    model.result("pg2").setIndex("looplevel", 241, 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().dataset().create("rev1", "Revolve2D");
    model.result().dataset("rev1").set("data", "dset1");
    model.result().dataset("rev1").set("revangle", 225);
    model.result().dataset("rev1").set("startangle", -90);
    model.result().create("pg3", "PlotGroup3D");
    model.result("pg3").set("data", "rev1");
    model.result("pg3").setIndex("looplevel", 241, 0);
    model.result("pg3").create("surf1", "Surface");
    model.result("pg3").feature("surf1").set("expr", new String[]{"acpr.p_t"});
    model.result("pg3").feature("surf1").set("colortable", "Wave");
    model.result("pg3").feature("surf1").set("colorscalemode", "linearsymmetric");
    model.result("pg3").set("showlegendsunit", true);
    model.result("pg3").label("Acoustic Pressure, 3D (acpr)");
    model.result().create("pg4", "PlotGroup3D");
    model.result("pg4").set("data", "rev1");
    model.result("pg4").setIndex("looplevel", 241, 0);
    model.result("pg4").create("surf1", "Surface");
    model.result("pg4").feature("surf1").set("expr", new String[]{"acpr.Lp_t"});
    model.result("pg4").feature("surf1").set("colortable", "Rainbow");
    model.result("pg4").feature("surf1").set("colorscalemode", "linear");
    model.result("pg4").set("showlegendsunit", true);
    model.result("pg4").label("Sound Pressure Level, 3D (acpr)");
    model.result().create("pg5", "PolarGroup");
    model.result("pg5").set("data", "dset1");
    model.result("pg5").create("rp1", "RadiationPattern");
    model.result("pg5").feature("rp1").set("expr", new String[]{"acpr.efc1.Lp_pext"});
    model.result("pg5").feature("rp1").set("legend", true);
    model.result("pg5").feature("rp1").set("phidisc", 180);
    model.result("pg5").label("Exterior-Field Sound Pressure Level (acpr)");
    model.result("pg5").setIndex("looplevelinput", "last", 0);
    model.result().create("pg6", "PolarGroup");
    model.result("pg6").set("data", "dset1");
    model.result("pg6").create("rp1", "RadiationPattern");
    model.result("pg6").feature("rp1").set("expr", new String[]{"acpr.efc1.pext"});
    model.result("pg6").feature("rp1").set("legend", true);
    model.result("pg6").feature("rp1").set("phidisc", 180);
    model.result("pg6").label("Exterior-Field Pressure (acpr)");
    model.result("pg6").setIndex("looplevelinput", "last", 0);
    model.result("pg5").set("symmetricangle", true);
    model.result("pg5").set("zeroangle", "up");
    model.result("pg5").set("rotdir", "cw");
    model.result("pg6").set("symmetricangle", true);
    model.result("pg6").set("zeroangle", "up");
    model.result("pg6").set("rotdir", "cw");
    model.result("pg1").run();

//    First, look at the default plots. Investigate the 2D <l>Sound Pressure Level (acpr)</l> plot to verify the performance of the perfectly matched layer (PML). After doing this you can disable plotting in the PML region, which is unphysical. Secondly, look at the default exterior-field plots and make a few changes, before setting up a range of plots to investigate the loudspeaker driver performance.

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

//    Look at the sound pressure level (SPL) plots at the frequencies of 10 kHz, 1 kHz, and 10 Hz. Note that the SPL decreases nearly 100 dB over the width of the thickness of the PML. This means that the outgoing waves are extremely damped.
//    In the Model Builder window, click Sound Pressure Level (acpr).
//    In the Settings window for 2D Plot Group, locate the Data section.
//    From the Parameter value (freq (Hz)) list, select 1000.

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

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

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

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

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

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

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

//    In the Model Builder window, expand the Results > Datasets node, then click Study 1 - Open Back-Volume/Solution 1 (sol1).
//    In the Results toolbar, click Attributes and choose Selection.
//    In the Settings window for Selection, locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Domain.

    model.result().dataset("dset1").selection().geom("geom1", 2);

//    Select Domains 2, 3, 4.

    model.result().dataset("dset1").selection().geom("geom1", 2);
    model.result().dataset("dset1").selection().set(2, 3, 4);
    model.result("pg1").run();

//    In the Model Builder window, under Results, click Acoustic Pressure (acpr).
//    In the Settings window for 2D Plot Group, locate the Data section.
//    From the Parameter value (freq (Hz)) list, select 1000.

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

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

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    From the Parameter value (freq (Hz)) list, select 5000.

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

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

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

//    In the Model Builder window, click Acoustic Pressure, 3D (acpr).

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

//    In the Model Builder window, click Sound Pressure Level, 3D (acpr).

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

//    In the Model Builder window, expand the Exterior-Field Sound Pressure Level (acpr) node, then click Radiation Pattern 1.
//    In the Settings window for Radiation Pattern, locate the Evaluation section.
//    Find the Angles subsection.
//    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);

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

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

//    In the Model Builder window, expand the Exterior-Field Pressure (acpr) node, then click Radiation Pattern 1.
//    In the Settings window for Radiation Pattern, locate the Evaluation section.
//    Find the Angles subsection.
//    From the Restriction list, select Manual.

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

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

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

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

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

//    In the Exterior-Field Pressure (acpr) toolbar, click Plot.

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

//    The plots are the following:
//    Membrane Velocity
//    Acoustic Radiated Power
//    Electric Input Power
//    Efficiency
//    Force on Speaker Cone
//    Voice-Coil Impedance
//    Sensitivity
//    Phase
//    On-axis Exterior-Field Pressure
//    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 Diaphragm Velocity in the Label text field.

    model.result("pg7").label("Diaphragm Velocity");

//    Click to expand 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 Velocity amplitude (m/s).

    model.result("pg7").set("ylabel", "Velocity amplitude (m/s)");

//    Right-click Diaphragm Velocity 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", "abs(u_D)", 0);
    model.result("pg7").feature("glob1").setIndex("unit", "m/s", 0);
    model.result("pg7").feature("glob1").setIndex("descr", "COMSOL", 0);
    model.result("pg7").feature("glob1").setIndex("expr", "abs(Qlf_D/S_D)", 1);
    model.result("pg7").feature("glob1").setIndex("unit", "m/s", 1);
    model.result("pg7").feature("glob1").setIndex("descr", "Low frequency approximation", 1);
    model.result("pg7").feature("glob1").setIndex("expr", "abs(Qhf_D/S_D)", 2);
    model.result("pg7").feature("glob1").setIndex("unit", "m/s", 2);
    model.result("pg7").feature("glob1").setIndex("descr", "High frequency approximation", 2);

//    In the Diaphragm Velocity toolbar, click Plot.

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

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

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

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

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

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

    model.result("pg8").label("Acoustic Radiated Power");

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

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

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

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

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

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

//    Select the y-axis label checkbox.

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

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

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

//    Locate the Legend section.
//    From the Position list, select Lower middle.

    model.result("pg8").set("legendpos", "lowermiddle");

//    Right-click Acoustic Radiated Power and choose Global.

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

//    In the Settings window for Global, click Add Expression in the upper-right corner of the y-Axis Data section.
//    From the menu, choose Component 1 (comp1) > Definitions > Variables > P_AR - Radiated power (COMSOL) - W.

    model.result("pg8").feature("glob1").set("expr", new String[]{"P_AR"});
    model.result("pg8").feature("glob1").set("descr", new String[]{"Radiated power (COMSOL)"});

//    Click Add Expression in the upper-right corner of the y-Axis Data section.
//    From the menu, choose Component 1 (comp1) > Definitions > Variables > P_AR_ana - Radiated power (piston) - W.

    model.result("pg8").feature("glob1").set("expr", new String[]{"P_AR", "P_AR_ana"});
    model.result("pg8").feature("glob1")
         .set("descr", new String[]{"Radiated power (COMSOL)", "Radiated power (piston)"});

//    In the Acoustic Radiated Power toolbar, click Plot.

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

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

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

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

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

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

    model.result("pg9").label("Electric Input Power");

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

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

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

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

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

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

//    Select the y-axis label checkbox.

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

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

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

//    Locate the Legend section.
//    From the Position list, select Lower right.

    model.result("pg9").set("legendpos", "lowerright");

//    Right-click Electric Input Power and choose Global.

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

//    In the Settings window for Global, click Replace Expression in the upper-right corner of the y-Axis Data section.
//    From the menu, choose Component 1 (comp1) > Definitions > Variables > P_E - Electric input power (rms) - W.

    model.result("pg9").feature("glob1").set("expr", new String[]{"P_E"});
    model.result("pg9").feature("glob1").set("descr", new String[]{"Electric input power (rms)"});
    model.result("pg9").feature("glob1").set("unit", new String[]{"W"});

//    In the Electric Input Power toolbar, click Plot.

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

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

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

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

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

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

    model.result("pg10").label("Driver Efficiency");

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

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

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

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

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

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

//    Select the y-axis label checkbox.

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

//    In the associated text field, type Efficiency (%).

    model.result("pg10").set("ylabel", "Efficiency (%)");

//    Locate the Legend section.
//    From the Position list, select Lower middle.

    model.result("pg10").set("legendpos", "lowermiddle");

//    Right-click Driver Efficiency and choose Global.

    model.result("pg10").create("glob1", "Global");
    model.result("pg10").feature("glob1").set("markerpos", "datapoints");
    model.result("pg10").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("pg10").feature("glob1").setIndex("expr", "eta*100", 0);
    model.result("pg10").feature("glob1").setIndex("unit", 1, 0);
    model.result("pg10").feature("glob1").setIndex("descr", "Driver efficiency (COMSOL)", 0);
    model.result("pg10").feature("glob1").setIndex("expr", "eta0*100", 1);
    model.result("pg10").feature("glob1").setIndex("unit", "", 1);
    model.result("pg10").feature("glob1").setIndex("descr", "Reference efficiency (piston)", 1);

//    In the Driver Efficiency toolbar, click Plot.

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

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

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

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

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

//    In the Settings window for 1D Plot Group, type Force on Speaker Cone in the Label text field.

    model.result("pg11").label("Force on Speaker Cone");

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

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

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

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

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

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

//    Select the y-axis label checkbox.

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

//    In the associated text field, type Pressure force (N).

    model.result("pg11").set("ylabel", "Pressure force (N)");

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

    model.result("pg11").set("legendpos", "lowerleft");

//    Right-click Force on Speaker Cone and choose Global.

    model.result("pg11").create("glob1", "Global");
    model.result("pg11").feature("glob1").set("markerpos", "datapoints");
    model.result("pg11").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("pg11").feature("glob1").setIndex("expr", "sqrt(0.5*F_D*conj(F_D))", 0);
    model.result("pg11").feature("glob1").setIndex("unit", "N", 0);
    model.result("pg11").feature("glob1").setIndex("descr", "Pressure force (rms) (COMSOL)", 0);

//    In the Force on Speaker Cone toolbar, click Plot.

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

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

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

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

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

//    In the Settings window for 1D Plot Group, type Voice-Coil Impedance in the Label text field.

    model.result("pg12").label("Voice-Coil Impedance");

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

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

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

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

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

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

//    Select the y-axis label checkbox.

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

//    In the associated text field, type Impedance (ohm).

    model.result("pg12").set("ylabel", "Impedance (ohm)");

//    Right-click Voice-Coil Impedance and choose Global.

    model.result("pg12").create("glob1", "Global");
    model.result("pg12").feature("glob1").set("markerpos", "datapoints");
    model.result("pg12").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("pg12").feature("glob1").setIndex("expr", "abs(V0/cir.R1.i)", 0);
    model.result("pg12").feature("glob1").setIndex("unit", "ohm", 0);
    model.result("pg12").feature("glob1").setIndex("descr", "|Z|", 0);
    model.result("pg12").feature("glob1").setIndex("expr", "real(V0/cir.R1.i)", 1);
    model.result("pg12").feature("glob1").setIndex("unit", "ohm", 1);
    model.result("pg12").feature("glob1").setIndex("descr", "Re(Z)", 1);
    model.result("pg12").feature("glob1").setIndex("expr", "imag(V0/cir.R1.i)", 2);
    model.result("pg12").feature("glob1").setIndex("unit", "ohm", 2);
    model.result("pg12").feature("glob1").setIndex("descr", "Im(Z)", 2);

//    In the Voice-Coil Impedance toolbar, click Plot.

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

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

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

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

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

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

    model.result("pg13").label("Sensitivity at 1 m");

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

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

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

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

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

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

//    Select the y-axis label checkbox.

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

//    In the associated text field, type Level (dB SPL rel. 1 V).

    model.result("pg13").set("ylabel", "Level (dB SPL rel. 1 V)");

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

    model.result("pg13").set("legendpos", "lowerleft");

//    In the Sensitivity at 1 m toolbar, click More Plots and choose Octave Band.

    model.result("pg13").create("oct1", "OctaveBand");
    model.result("pg13").feature("oct1").set("quantity", "bandpower");
    model.result("pg13").feature("oct1").set("markerpos", "datapoints");
    model.result("pg13").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("pg13").feature("oct1").selection().geom("geom1");

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

    model.result("pg13").feature("oct1").set("expr", "pext(0,1)");

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

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

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

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

//    From the Legends list, select Manual.

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

//    In the table, enter the following settings:

    model.result("pg13").feature("oct1").setIndex("legends", "Sound pressure level (COMSOL)", 0);

//    Right-click Octave Band 1 and choose Graph Marker.

    model.result("pg13").feature("oct1").create("gmrk1", "GraphMarker");

    return model;
  }

  public static Model run3(Model model) {
    model.result("pg13").feature("oct1").feature("gmrk1").set("linewidth", "preference");
    model.result("pg13").run();

//    In the Settings window for Graph Marker, locate the Display section.
//    From the Display mode list, select Line intersection.

    model.result("pg13").feature("oct1").feature("gmrk1").set("displaymode", "intersection");

//    In the x-coordinates text field, type 700.

    model.result("pg13").feature("oct1").feature("gmrk1").set("intersectionx", 700);

//    Select the Show lines checkbox.

    model.result("pg13").feature("oct1").feature("gmrk1").set("showlines", true);

//    Locate the Text Format section.
//    In the Precision text field, type 3.

    model.result("pg13").feature("oct1").feature("gmrk1").set("precision", 3);

//    Select the Include unit checkbox.

    model.result("pg13").feature("oct1").feature("gmrk1").set("includeunit", true);

//    Click to expand the Coloring and Style section.
//    From the Anchor point list, select Middle right.

    model.result("pg13").feature("oct1").feature("gmrk1").set("anchorpoint", "middleright");

//    In the Sensitivity at 1 m toolbar, click Plot.

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

//    In the Model Builder window, right-click Results > Sensitivity at 1 m > Octave Band 1 and choose Duplicate.

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

//    In the Settings window for Octave Band, locate the y-Axis Data section.
//    In the Expression text field, type sqrt(2)*prms.

    model.result("pg13").feature("oct2").set("expr", "sqrt(2)*prms");

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

    model.result("pg13").feature("oct2").setIndex("legends", "Sound pressure level (piston)", 0);
    model.result("pg13").run();

//    In the Model Builder window, expand the Octave Band 2 node, then click Graph Marker 1.
//    In the Settings window for Graph Marker, locate the Coloring and Style section.
//    From the Anchor point list, select Upper left.

    model.result("pg13").feature("oct2").feature("gmrk1").set("anchorpoint", "upperleft");

//    In the Sensitivity at 1 m toolbar, click Plot.

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

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

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

//    In the Settings window for 1D Plot Group, type Phase Relative to a Plane Wave in the Label text field.

    model.result("pg14").label("Phase Relative to a Plane Wave");

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

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

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

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

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

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

//    Select the y-axis label checkbox.

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

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

    model.result("pg14").set("ylabel", "Phase (deg)");

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

    model.result("pg14").set("legendpos", "lowerleft");

//    Right-click Phase Relative to a Plane Wave and choose Global.

    model.result("pg14").create("glob1", "Global");
    model.result("pg14").feature("glob1").set("markerpos", "datapoints");
    model.result("pg14").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("pg14").feature("glob1")
         .setIndex("expr", "arg(subst(acpr.efc1.pext,r,0,z,1[m])/(exp(-i*k0*1[m])*1[Pa]))", 0);
    model.result("pg14").feature("glob1").setIndex("unit", "deg", 0);
    model.result("pg14").feature("glob1").setIndex("descr", "Phase (COMSOL)", 0);

//    Select the Unwrap phase checkbox.

    model.result("pg14").feature("glob1").set("unwrapphase", true);

//    In the Phase Relative to a Plane Wave toolbar, click Plot.

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

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

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

//    Set up a parametric curve used to evaluate the exterior-field outside of the computational mesh.
//    In the Results toolbar, click More Datasets and choose Parametric Curve 2D.

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

//    In the Settings window for Parametric Curve 2D, locate the Expressions section.
//    In the z text field, type s*5[m]+(1-s)*Rair.

    model.result().dataset("pc1").set("expry", "s*5[m]+(1-s)*Rair");

//    Select the Only evaluate globally defined expressions checkbox.

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

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

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

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

    model.result("pg15").label("On-axis Pressure");

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

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

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

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

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

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

//    In the associated text field, type z (m).

    model.result("pg15").set("xlabel", "z (m)");

//    Select the y-axis label checkbox.

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

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

    model.result("pg15").set("ylabel", "Pressure (Pa)");

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

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

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

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

//    select 1000 in the Parameter values (freq (Hz)) list.
//    Right-click On-axis Pressure and choose Line Graph.

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

//    In the Settings window for Line Graph, locate the y-Axis Data section.
//    In the Expression text field, type pext(r,z).

    model.result("pg15").feature("lngr1").set("expr", "pext(r,z)");

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

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

//    In the Expression text field, type z.

    model.result("pg15").feature("lngr1").set("xdataexpr", "z");

//    Click to expand the Quality section.
//    From the Evaluation settings list, select Manual.

    model.result("pg15").feature("lngr1").set("evaluationsettings", "manual");

//    From the Resolution list, select Extra fine.

    model.result("pg15").feature("lngr1").set("resolution", "extrafine");

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

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

//    From the Legends list, select Manual.

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

//    In the table, enter the following settings:

    model.result("pg15").feature("lngr1").setIndex("legends", "COMSOL", 0);

//    Right-click Line Graph 1 and choose Duplicate.

    model.result("pg15").feature().duplicate("lngr2", "lngr1");
    model.result("pg15").run();

//    In the Settings window for Line Graph, locate the y-Axis Data section.
//    In the Expression text field, type acpr.iomega*rho0*u_D*S_D*exp(-i*k0*z)/(2*pi*z).

    model.result("pg15").feature("lngr2").set("expr", "acpr.iomega*rho0*u_D*S_D*exp(-i*k0*z)/(2*pi*z)");

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

    model.result("pg15").feature("lngr2").setIndex("legends", "Piston", 0);

//    In the On-axis Pressure toolbar, click Plot.

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

//    Create a 2D intensity plot that includes the magnitude of the intensity vector <c>acpr.I_rms</c> as well as an arrow surface (vector field plot) of the intensity vector, with the components (<c>acpr.Ir</c>,<c>acpr.Iz</c>).
//    In the Results toolbar, click 2D Plot Group.

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

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

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

//    Right-click Intensity and choose Surface.

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

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

    model.result("pg16").feature("surf1").set("expr", "acpr.I_rms");
    model.result("pg16").run();

//    In the Model Builder window, right-click Intensity and choose Arrow Surface.

    model.result("pg16").create("arws1", "ArrowSurface");
    model.result("pg16").feature("arws1").set("evaluationsettings", "parent");

//    In the Settings window for Arrow Surface, 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.Ir,acpr.Iz - Intensity.

    model.result("pg16").feature("arws1").set("expr", new String[]{"acpr.Ir", "acpr.Iz"});
    model.result("pg16").feature("arws1").set("descr", "Intensity");

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

    model.result("pg16").feature("arws1").set("color", "black");
    model.result("pg16").run();

//    Right-click Intensity and choose Arrow Line.

    model.result("pg16").create("arwl1", "ArrowLine");
    model.result("pg16").feature("arwl1").set("evaluationsettings", "parent");

//    In the Settings window for Arrow Line, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Pressure Acoustics, Frequency Domain > Geometry > acpr.nr,acpr.nz - Normal vector.

    model.result("pg16").feature("arwl1").set("expr", new String[]{"acpr.nr", "acpr.nz"});
    model.result("pg16").feature("arwl1").set("descr", "Normal vector");

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

    model.result("pg16").feature("arwl1").set("color", "gray");

//    In the Intensity toolbar, click Plot.

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

//    Click the Zoom Extents button in the Graphics toolbar.

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

//    In the Model Builder window, click Intensity.
//    In the Settings window for 2D Plot Group, locate the Data section.
//    From the Parameter value (freq (Hz)) list, select 5000.

    model.result("pg16").setIndex("looplevel", 217, 0);

//    In the Intensity toolbar, click Plot.

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

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

    model.result("pg16").setIndex("looplevel", 161, 0);

//    In the Intensity toolbar, click Plot.

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

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

    model.result("pg16").setIndex("looplevel", 81, 0);

//    In the Intensity toolbar, click Plot.

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

//    Next create the directivity plot of the speaker.
//    In the Results toolbar, click 1D Plot Group.

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

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

    model.result("pg17").label("Directivity");

//    In the Directivity toolbar, click More Plots and choose Directivity.

    model.result("pg17").create("dir1", "Directivity");
    model.result("pg17").feature("dir1").set("linewidth", "preference");

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

    model.result("pg17").feature("dir1").set("phidisc", 180);

//    From the Restriction list, select Manual.

    model.result("pg17").feature("dir1").set("anglerestr", "manual");

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

    model.result("pg17").feature("dir1").set("phimin", -90);

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

    model.result("pg17").feature("dir1").set("phirange", 180);

//    Click to expand the Coloring and Style section.
//    From the Layout list, select Frequency on y-axis.

    model.result("pg17").feature("dir1").set("layout", "frequencyy");

//    In the Directivity toolbar, click Plot.

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

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

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

//    Create an additional plot that shows the sensitivity and the phase in one plot using two <eqv>y</eqv>-axes.

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

//    In the Model Builder window, right-click Results > Phase Relative to a Plane Wave > Global 1 and choose Copy.

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

//    In the Model Builder window, right-click Sensitivity at 1 m and choose Duplicate.

    model.result().duplicate("pg18", "pg13");
    model.result("pg18").run();

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

    model.result("pg18").label("Sensitivity and Phase");
    model.result("pg18").run();

//    In the Model Builder window, expand the Sensitivity and Phase node.

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

//    In the Model Builder window, expand the Octave Band 1 node.
//    Right-click Graph Marker 1 and choose Delete.

    model.result("pg18").feature("oct1").feature().remove("gmrk1");
    model.result("pg18").run();
    model.result("pg18").run();

//    In the Model Builder window, right-click Octave Band 2 and choose Delete.

    model.result("pg18").feature().remove("oct2");
    model.result("pg18").run();

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

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

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

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

//    In the Model Builder window, right-click Sensitivity and Phase and choose Paste Global.

    model.result("pg18").feature().copy("glob1", "pg14/glob1");
    model.result("pg18").run();

//    In the Settings window for Global, click to expand the Coloring and Style section.
//    From the Width list, select 2.

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

//    From the Color list, select Red.

    model.result("pg18").feature("glob1").set("linecolor", "red");
    model.result("pg18").run();

//    In the Model Builder window, click Sensitivity and Phase.
//    In the Settings window for 1D Plot Group, locate the Plot Settings section.
//    Select the Two y-axes checkbox.

    model.result("pg18").set("twoyaxes", true);

//    In the table, enter the following settings:

    model.result("pg18").setIndex("plotonsecyaxis", true, 1, 1);

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

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

//    In the y minimum text field, type 40.

    model.result("pg18").set("ymin", 40);

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

    model.result("pg18").set("ymax", 90);

//    In the Secondary y minimum text field, type -180.

    model.result("pg18").set("yminsec", -180);

//    In the Secondary y maximum text field, type 180.

    model.result("pg18").set("ymaxsec", 180);

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

    model.result("pg18").set("yseclabelactive", true);

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

    model.result("pg18").set("yseclabel", "Phase (deg)");

//    In the Sensitivity and Phase toolbar, click Plot.

    model.result("pg18").run();
    model.result("pg3").run();
    model.result("pg3").setIndex("looplevel", 217, 0);
    model.result("pg3").run();

//    It is time to solve the model with the closed back-volume configuration. After solving add a few extra graphs to the existing plots to see how the system response has changed. The closed back-volume acts as a spring and thus modifies the mechanical compliance of the system. The effect is, for example, seen in the electric impedance plot by moving the resonance up in frequency.
//    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 Frequency Domain, locate the Study Settings section.
//    Click Range.
//    In the Range dialog, choose ISO preferred frequencies from the Entry method list.
//    In the Start frequency text field, type 10.
//    In the Stop frequency text field, type 10000.
//    From the Interval list, select 1/24 octave.
//    Click Replace.

    model.study("std2").feature("freq")
         .set("plist", "{10, 10.3, 10.6, 10.9, 11.2, 11.5, 11.8, 12.2, 12.5, 12.8, 13.2, 13.6, 14, 14.5, 15, 15.5, 16, 16.5, 17, 17.5, 18, 18.5, 19, 19.5, 20, 20.6, 21.2, 21.8, 22.4, 23, 23.6, 24.3, 25, 25.8, 26.5, 27.2, 28, 29, 30, 30.7, 31.5, 32.5, 33.5, 34.5, 35.5, 36.5, 37.5, 38.7, 40, 41.2, 42.5, 43.7, 45, 46.2, 47.5, 48.7, 50, 51.5, 53, 54.5, 56, 58, 60, 61.5, 63, 65, 67, 69, 71, 73, 75, 77.5, 80, 82.5, 85, 87.5, 90, 92.5, 95, 97.5, 100, 103, 106, 109, 112, 115, 118, 122, 125, 128, 132, 136, 140, 145, 150, 155, 160, 165, 170, 175, 180, 185, 190, 195, 200, 206, 212, 218, 224, 230, 236, 243, 250, 258, 265, 272, 280, 290, 300, 307, 315, 325, 335, 345, 355, 365, 375, 387, 400, 412, 425, 437, 450, 462, 475, 487, 500, 515, 530, 545, 560, 580, 600, 615, 630, 650, 670, 690, 710, 730, 750, 775, 800, 825, 850, 875, 900, 925, 950, 975, 1e3, 1.03e3, 1.06e3, 1.09e3, 1.12e3, 1.15e3, 1.18e3, 1.22e3, 1.25e3, 1.28e3, 1.32e3, 1.36e3, 1.4e3, 1.45e3, 1.5e3, 1.55e3, 1.6e3, 1.65e3, 1.7e3, 1.75e3, 1.8e3, 1.85e3, 1.9e3, 1.95e3, 2e3, 2.06e3, 2.12e3, 2.18e3, 2.24e3, 2.3e3, 2.36e3, 2.43e3, 2.5e3, 2.58e3, 2.65e3, 2.72e3, 2.8e3, 2.9e3, 3e3, 3.07e3, 3.15e3, 3.25e3, 3.35e3, 3.45e3, 3.55e3, 3.65e3, 3.75e3, 3.87e3, 4e3, 4.12e3, 4.25e3, 4.37e3, 4.5e3, 4.62e3, 4.75e3, 4.87e3, 5e3, 5.15e3, 5.3e3, 5.45e3, 5.6e3, 5.8e3, 6e3, 6.15e3, 6.3e3, 6.5e3, 6.7e3, 6.9e3, 7.1e3, 7.3e3, 7.5e3, 7.75e3, 8e3, 8.25e3, 8.5e3, 8.75e3, 9e3, 9.25e3, 9.5e3, 9.75e3, 1e4}");

//    In the Model Builder window, click Study 2.
//    In the Settings window for Study, type Study 2 - Closed Back-Volume in the Label text field.

    model.study("std2").label("Study 2 - Closed Back-Volume");

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

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

//    In the Study toolbar, click Compute.

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

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

//    Finally, modify two of the existing plots to understand the effect of a closed-back volume. To see the results of the closed configuration, in any of the plots, simply change the <l>Dataset</l> to the one from study 2.

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

//    In the Model Builder window, under Results > Voice-Coil Impedance, click Global 1.
//    In the Settings window for Global, locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg12").feature("glob1").setIndex("unit", "ohm", 0);
    model.result("pg12").feature("glob1").setIndex("descr", "|Z| (open back-volume)", 0);

//    Right-click Results > Voice-Coil Impedance > Global 1 and choose Duplicate.

    model.result("pg12").feature().duplicate("glob2", "glob1");
    model.result("pg12").run();

//    In the Settings window for Global, locate the Data section.
//    From the Dataset list, select Study 2 - Closed Back-Volume/Solution 2 (sol2).

    model.result("pg12").feature("glob2").set("data", "dset2");

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

    model.result("pg12").feature("glob2").setIndex("unit", "ohm", 0);
    model.result("pg12").feature("glob2").setIndex("descr", "|Z| (closed back-volume)", 0);

//    Locate the Coloring and Style section.
//    From the Color list, select Cycle (reset).

    model.result("pg12").feature("glob2").set("linecolor", "cyclereset");

//    Find the Line style subsection.
//    From the Line list, select Dashed.

    model.result("pg12").feature("glob2").set("linestyle", "dashed");

//    In the Voice-Coil Impedance toolbar, click Plot.

    model.result("pg12").run();
    model.result("pg13").run();

//    In the Model Builder window, under Results > Sensitivity at 1 m, click Octave Band 1.
//    In the Settings window for Octave Band, locate the Legends section.
//    In the table, enter the following settings:

    model.result("pg13").feature("oct1").setIndex("legends", "Sound pressure level (COMSOL) (open back-volume)", 0);

//    Right-click Results > Sensitivity at 1 m > Octave Band 1 and choose Duplicate.

    model.result("pg13").feature().duplicate("oct3", "oct1");
    model.result("pg13").run();

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

    model.result("pg13").feature("oct3").set("data", "dset2");

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

    model.result("pg13").feature("oct3").setIndex("legends", "Sound pressure level (COMSOL) (closed back-volume)", 0);
    model.result("pg13").run();

//    In the Model Builder window, expand the Octave Band 3 node, then click Graph Marker 1.
//    In the Settings window for Graph Marker, locate the Coloring and Style section.
//    From the Anchor point list, select Lower left.

    model.result("pg13").feature("oct3").feature("gmrk1").set("anchorpoint", "lowerleft");

//    In the Sensitivity at 1 m toolbar, click Plot.

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

    model.title("Lumped Loudspeaker Driver");

    model
         .description("This is a model of a moving-coil loudspeaker where a lumped parameter analogy represents the behavior of the electrical and mechanical speaker components. The Thiele\u2013Small parameters (small-signal parameters) serve as input to the lumped model, which is represented by an Electrical Circuit interface. The lumped model is coupled to a 2D axisymmetric Pressure Acoustics model describing the surrounding air domain. The output from the model includes, among many things, the speaker sensitivity, the impedance, and the radiated acoustic power. The results are compared with an analytical solution based on the flat piston approximation.");

    return model;
  }

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

}
