/*
 * full_ear_hearing_aid.java
 */

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

/** Model exported on May 12 2026, 14:09 by COMSOL 6.4.0.418. */
public class full_ear_hearing_aid {

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

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

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

    model.component("comp1").geom().create("geom1", 3);
    model.component("comp1").geom("geom1").geomRep("comsol");

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

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

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

//    The model parameters are loaded from the file <c>full_ear_hearing_aid_parameters.txt</c>.
//    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 full_ear_hearing_aid_parameters.txt.
//    To import content from file, use:
//    model.param().loadFile("FILENAME");
    model.param().set("a_vent", "0.27[mm]", "Radius of the vents");
    model.param().set("a_port", "0.715[mm]", "Radius of speaker");
    model.param().set("V0rms", "100[mV]", "Driver voltage RMS");
    model.param().set("V0", "sqrt(2)*V0rms", "Driver voltage");
    model.param().set("h_max", "343[m/s]/fmax/12", "Maximum mesh element length");
    model.param().set("fmax", "20000[Hz]", "Maximum frequency");
    model.param().set("gain", "0", "Gain of hearing aid");

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

//    Locate the Advanced section.
//    From the Geometry representation list, select CAD kernel.

    model.component("comp1").geom("geom1").geomRep("cadps");

//    Select the Design Module Boolean operations checkbox.

    model.component("comp1").geom("geom1").designBooleans(true);

//    In the Geometry toolbar, click Insert Sequence and choose Insert Sequence.
//    Browse to the model's Application Library folder and double-click the file full_ear_hearing_aid_geom_sequence.mph.
//    In the Insert Sequence dialog, click OK.

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

//    In the Geometry toolbar, click Build All.

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

//    Hide boundaries to make it easier to visualize the model.
//    In the Model Builder window, expand the Component 1 (comp1) > Definitions node.
//    Right-click View 1 and choose Hide for Geometry.

    model.component("comp1").view("view1").hideObjects().create("hide1");

//    In the Settings window for Hide for Geometry, locate the Selection section.
//    From the Geometric entity level list, select Boundary.

    model.component("comp1").view("view1").hideObjects("hide1").init(2);

//    On the object cle1, select Boundaries 1, 2, 3, 141, 142.

    model.component("comp1").view("view1").hideObjects("hide1").set("cle1", 1, 2, 3, 141, 142);

//    In the Geometry toolbar, click Build All.

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

//    In the Model Builder window, under Component 1 (comp1), click Geometry 1.
//    In the Model Builder window, expand the Global Definitions > Geometry Parts node, then click Part 1.
//    In the Model Builder window, under Global Definitions > Geometry Parts, click Ear bud.
//    Load in data files for the ear drum impedance, the hearing aid lumped speaker parameters, microphone sensitivity, and experimental data.
//    In the Home toolbar, click Functions and choose Global > Interpolation.

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

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

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

//    In the Filename text field, type full_ear_hearing_aid_impedance.txt.

    model.func("int1").set("filename", "full_ear_hearing_aid_impedance.txt");

//    Locate the Data Column Settings section.
//    In the table, click to select the cell at row number 1 and column number 1.
//    In the Unit text field, type 1.

    model.func("int1").setIndex("argunit", "1", 0);

//    In the table, enter the following settings:

    model.func("int1").setEntry("columnType", "col2", "value");

//    In the Name text field, type absZ.

    model.func("int1").setEntry("funcnames", "col2", "absZ");

//    In the Unit text field, type kg/(m^2*s).

    model.func("int1").setIndex("fununit", "kg/(m^2*s)", 0);

//    In the table, click to select the cell at row number 3 and column number 1.
//    In the Name text field, type argZ.

    model.func("int1").setEntry("funcnames", "col3", "argZ");

//    In the Unit text field, type rad.

    model.func("int1").setIndex("fununit", "rad", 1);

//    Locate the Definition section.
//    Click Import.

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

//    Click Plot.
//    In the Home toolbar, click Functions and choose Global > Interpolation.

    model.func().create("int2", "Interpolation");

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

    model.func("int2").set("source", "file");

//    In the Filename text field, type full_ear_hearing_aid_abcd.dat.

    model.func("int2").set("filename", "full_ear_hearing_aid_abcd.dat");

//    Locate the Data Column Settings section.
//    In the table, enter the following settings:

    model.func("int2").setEntry("columnType", "col2", "value");
    model.func("int2").setEntry("columnType", "col3", "value");
    model.func("int2").setEntry("columnType", "col5", "value");
    model.func("int2").setEntry("columnType", "col6", "value");
    model.func("int2").setEntry("columnType", "col7", "value");
    model.func("int2").setEntry("columnType", "col8", "value");
    model.func("int2").setEntry("columnType", "col9", "value");

//    In the table, click to select the cell at row number 1 and column number 1.
//    In the Unit text field, type Hz.

    model.func("int2").setIndex("argunit", "Hz", 0);

//    In the table, click to select the cell at row number 2 and column number 1.
//    In the Name text field, type Ar.

    model.func("int2").setEntry("funcnames", "col2", "Ar");

//    In the table, click to select the cell at row number 3 and column number 1.
//    In the Name text field, type Ai.

    model.func("int2").setEntry("funcnames", "col3", "Ai");

//    In the table, click to select the cell at row number 4 and column number 1.
//    In the Name text field, type Br.

    model.func("int2").setEntry("funcnames", "col4", "Br");

//    In the table, click to select the cell at row number 5 and column number 1.
//    In the Name text field, type Bi.

    model.func("int2").setEntry("funcnames", "col5", "Bi");

//    In the table, click to select the cell at row number 6 and column number 1.
//    In the Name text field, type Cr.

    model.func("int2").setEntry("funcnames", "col6", "Cr");

//    In the table, click to select the cell at row number 7 and column number 1.
//    In the Name text field, type Ci.

    model.func("int2").setEntry("funcnames", "col7", "Ci");

//    In the table, click to select the cell at row number 8 and column number 1.
//    In the Name text field, type Dr.

    model.func("int2").setEntry("funcnames", "col8", "Dr");

//    In the table, click to select the cell at row number 9 and column number 1.
//    In the Name text field, type Di.

    model.func("int2").setEntry("funcnames", "col9", "Di");

//    Locate the Definition section.
//    Click Import.

    model.func("int2").importData();

//    Click Plot.
//    In the Home toolbar, click Functions and choose Global > Interpolation.

    model.func().create("int3", "Interpolation");

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

    model.func("int3").set("source", "file");

//    In the Filename text field, type full_ear_hearing_aid_measurements.txt.

    model.func("int3").set("filename", "full_ear_hearing_aid_measurements.txt");

//    Locate the Data Column Settings section.
//    In the table, enter the following settings:

    model.func("int3").setEntry("columnType", "col2", "value");
    model.func("int3").setEntry("columnType", "col3", "value");
    model.func("int3").setEntry("columnType", "col5", "value");
    model.func("int3").setEntry("columnType", "col6", "value");
    model.func("int3").setEntry("columnType", "col7", "value");
    model.func("int3").setEntry("columnType", "col8", "value");
    model.func("int3").setEntry("columnType", "col9", "value");

//    In the table, click to select the cell at row number 1 and column number 1.
//    In the Unit text field, type Hz.

    model.func("int3").setIndex("argunit", "Hz", 0);

//    In the table, click to select the cell at row number 2 and column number 1.
//    In the Name text field, type L1.

    model.func("int3").setEntry("funcnames", "col2", "L1");

//    In the Unit text field, type dB.

    model.func("int3").setIndex("fununit", "dB", 0);

//    In the table, click to select the cell at row number 3 and column number 1.
//    In the Name text field, type L2.

    model.func("int3").setEntry("funcnames", "col3", "L2");

//    In the Unit text field, type dB.

    model.func("int3").setIndex("fununit", "dB", 1);

//    In the table, click to select the cell at row number 4 and column number 1.
//    In the Name text field, type L3.

    model.func("int3").setEntry("funcnames", "col4", "L3");

//    In the Unit text field, type dB.

    model.func("int3").setIndex("fununit", "dB", 2);

//    In the table, click to select the cell at row number 5 and column number 1.
//    In the Name text field, type L4.

    model.func("int3").setEntry("funcnames", "col5", "L4");

//    In the Unit text field, type dB.

    model.func("int3").setIndex("fununit", "dB", 3);

//    In the table, click to select the cell at row number 6 and column number 1.
//    In the Name text field, type L5.

    model.func("int3").setEntry("funcnames", "col6", "L5");

//    In the Unit text field, type dB.

    model.func("int3").setIndex("fununit", "dB", 4);

//    In the table, click to select the cell at row number 7 and column number 1.
//    In the Name text field, type Lav.

    model.func("int3").setEntry("funcnames", "col7", "Lav");

//    In the Unit text field, type dB.

    model.func("int3").setIndex("fununit", "dB", 5);

//    In the table, click to select the cell at row number 8 and column number 1.
//    In the Name text field, type Lpsigma.

    model.func("int3").setEntry("funcnames", "col8", "Lpsigma");

//    In the Unit text field, type dB.

    model.func("int3").setIndex("fununit", "dB", 6);

//    In the table, click to select the cell at row number 9 and column number 1.
//    In the Name text field, type Lmsigma.

    model.func("int3").setEntry("funcnames", "col9", "Lmsigma");

//    In the Unit text field, type dB.

    model.func("int3").setIndex("fununit", "dB", 7);

//    Locate the Definition section.
//    Click Import.

    model.func("int3").importData();

//    Click Plot.
//    In the Home toolbar, click Functions and choose Global > Interpolation.

    model.func().create("int4", "Interpolation");

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

    model.func("int4").set("source", "file");

//    In the Filename text field, type full_ear_hearing_aid_microphonesensitivity.txt.

    model.func("int4").set("filename", "full_ear_hearing_aid_microphonesensitivity.txt");

//    Locate the Data Column Settings section.
//    In the table, click to select the cell at row number 1 and column number 1.
//    In the Unit text field, type Hz.

    model.func("int4").setIndex("argunit", "Hz", 0);

//    In the table, enter the following settings:

    model.func("int4").setEntry("columnType", "col2", "value");
    model.func("int4").setEntry("columnType", "col3", "value");
    model.func("int4").setEntry("columnType", "col4", "none");

//    In the table, click to select the cell at row number 2 and column number 1.
//    In the Name text field, type Tr.

    model.func("int4").setEntry("funcnames", "col2", "Tr");

//    In the Unit text field, type V/Pa.

    model.func("int4").setIndex("fununit", "V/Pa", 0);

//    In the table, click to select the cell at row number 3 and column number 1.
//    In the Name text field, type Ti.

    model.func("int4").setEntry("funcnames", "col3", "Ti");

//    In the Unit text field, type V/Pa.

    model.func("int4").setIndex("fununit", "V/Pa", 1);

//    Locate the Definition section.
//    Click Import.

    model.func("int4").importData();

//    Click Plot.
//    In the Definitions toolbar, click Nonlocal Couplings and choose Average.

    model.component("comp1").cpl().create("aveop1", "Average");
    model.component("comp1").cpl("aveop1").set("axisym", true);

    model.component("comp1").geom("geom1").feature().create("rmd1", "RemoveDetails");
    model.component("comp1").geom("geom1").feature("rmd1").set("detailsizetype", "absolute");
    model.component("comp1").geom("geom1").feature("rmd1").set("maxabssize", "0.028");
    model.component("comp1").geom("geom1").run("rmd1");

//    In the Geometry Cleanup dialog, click Clean Up Automatically to automatically clean up the geometry.
//    In the Model Builder window, under Component 1 (comp1) > Definitions, click Average 1 (aveop1).
//    In the Settings window for Average, type aveop_ed in the Operator name text field.

    model.component("comp1").cpl("aveop1").set("opname", "aveop_ed");

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

    model.component("comp1").cpl("aveop1").selection().geom("geom1", 2);

//    From the Selection list, select Ear Drum.

    model.component("comp1").cpl("aveop1").selection().named("geom1_sel4");

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

    model.component("comp1").cpl().create("aveop2", "Average");
    model.component("comp1").cpl("aveop2").set("axisym", true);

//    In the Settings window for Average, type aveop_mic in the Operator name text field.

    model.component("comp1").cpl("aveop2").set("opname", "aveop_mic");

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

    model.component("comp1").cpl("aveop2").selection().geom("geom1", 2);

//    From the Selection list, select Microphones.

    model.component("comp1").cpl("aveop2").selection().named("geom1_unisel1");

//    In the Home 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 Home toolbar, click Add Material to close the Add Material window.
//    In the Settings window for Pressure Acoustics, Frequency Domain, click to expand the Discretization section.
//    From the Element order list, select Linear.

    model.component("comp1").physics("acpr").prop("ShapeProperty").set("order_pressure", 1);

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

    model.component("comp1").physics("acpr").create("lport1", "LumpedPort", 2);

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

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

//    Locate the Connection Type section.
//    From the Two-port representation list, select Electroacoustic.

    model.component("comp1").physics("acpr").feature("lport1").set("TwoPortRepresentation", "Electroacoustic");

//    In the \[T_{11}\] text field, type Ar(freq)+i*Ai(freq).

    model.component("comp1").physics("acpr").feature("lport1").set("T11_ea_in", "Ar(freq)+i*Ai(freq)");

//    In the \[T_{12}\] text field, type Br(freq)+i*Bi(freq).

    model.component("comp1").physics("acpr").feature("lport1").set("T12_ea_in", "Br(freq)+i*Bi(freq)");

//    In the \[T_{21}\] text field, type Cr(freq)+i*Ci(freq).

    model.component("comp1").physics("acpr").feature("lport1").set("T21_ea_in", "Cr(freq)+i*Ci(freq)");

//    In the \[T_{22}\] text field, type Dr(freq)+i*Di(freq).

    model.component("comp1").physics("acpr").feature("lport1").set("T22_ea_in", "Dr(freq)+i*Di(freq)");

//    Locate the Source Settings section.
//    In the \[V_\textrm{in}\] text field, type V0+(Tr(freq)+i*Ti(freq))*aveop_mic(acpr.p_t)*gain.

    model.component("comp1").physics("acpr").feature("lport1")
         .set("V_in", "V0+(Tr(freq)+i*Ti(freq))*aveop_mic(acpr.p_t)*gain");

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

    model.component("comp1").physics("acpr").create("imp1", "Impedance", 2);

//    In the Settings window for Impedance, type Impedance - Ear Drum in the Label text field.

    model.component("comp1").physics("acpr").feature("imp1").label("Impedance - Ear Drum");

//    Locate the Boundary Selection section.
//    From the Selection list, select Ear Drum.

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

//    Locate the Impedance section.
//    In the \[Z_\textrm{n}\] text field, type absZ(log10(freq[1/Hz]))*exp(i*argZ(log10(freq[1/Hz]))).

    model.component("comp1").physics("acpr").feature("imp1")
         .set("Zn", "absZ(log10(freq[1/Hz]))*exp(i*argZ(log10(freq[1/Hz])))");

//    In the Physics toolbar, click Boundaries and choose Thermoviscous Boundary Layer Impedance.

    model.component("comp1").physics("acpr").create("tvb1", "ThermoviscousBoundaryLayerImpedance", 2);

//    In the Settings window for Thermoviscous Boundary Layer Impedance, locate the Boundary Selection section.
//    From the Selection list, select Ear Canal - TVBLI Boundaries.

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

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

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

//    Include the losses in the thin domains by the Narrow Region Acoustics feature.
//    In the Physics toolbar, click Domains and choose Narrow Region Acoustics.

    model.component("comp1").physics("acpr").create("nra1", "NarrowRegionAcousticsModel", 3);

//    In the Settings window for Narrow Region Acoustics, type Narrow Region Acoustics - Vent Holes in the Label text field.

    model.component("comp1").physics("acpr").feature("nra1").label("Narrow Region Acoustics - Vent Holes");

//    Locate the Domain Selection section.
//    From the Selection list, select Vent Holes.

    model.component("comp1").physics("acpr").feature("nra1").selection().named("geom1_sel8");

//    Locate the Duct Properties section.
//    From the Duct type list, select Circular duct.

    model.component("comp1").physics("acpr").feature("nra1").set("DuctType", "CircularDuct");

//    In the \[a\] text field, type a_vent.

    model.component("comp1").physics("acpr").feature("nra1").set("a", "a_vent");

//    In the Physics toolbar, click Domains and choose Narrow Region Acoustics.

    model.component("comp1").physics("acpr").create("nra2", "NarrowRegionAcousticsModel", 3);

//    In the Settings window for Narrow Region Acoustics, type Narrow Region Acoustics - Wax Guard Holes in the Label text field.

    model.component("comp1").physics("acpr").feature("nra2").label("Narrow Region Acoustics - Wax Guard Holes");

//    Locate the Domain Selection section.
//    From the Selection list, select Wax Guard Holes.

    model.component("comp1").physics("acpr").feature("nra2").selection().named("geom1_sel9");

//    Locate the Duct Properties section.
//    From the Duct type list, select Circular duct.

    model.component("comp1").physics("acpr").feature("nra2").set("DuctType", "CircularDuct");

//    In the \[a\] text field, type 0.5*0.4[mm].

    model.component("comp1").physics("acpr").feature("nra2").set("a", "0.5*0.4[mm]");

//    In the Physics toolbar, click Domains and choose Narrow Region Acoustics.

    model.component("comp1").physics("acpr").create("nra3", "NarrowRegionAcousticsModel", 3);

//    In the Settings window for Narrow Region Acoustics, locate the Domain Selection section.
//    From the Selection list, select Ear-Bud Domain.

    model.component("comp1").physics("acpr").feature("nra3").selection().named("geom1_sel10");

//    In the Label text field, type Wax Guard.

    model.component("comp1").physics("acpr").feature("nra3").label("Wax Guard");

//    Locate the Duct Properties section.
//    From the Duct type list, select Circular duct.

    model.component("comp1").physics("acpr").feature("nra3").set("DuctType", "CircularDuct");

//    In the \[a\] text field, type a_port.

    model.component("comp1").physics("acpr").feature("nra3").set("a", "a_port");

//    Perfectly Matched Boundary is used to mimic an infinite baffle.
//    In the Physics toolbar, click Boundaries and choose Perfectly Matched Boundary.

    model.component("comp1").physics("acpr").create("pmb1", "PerfectlyMatchedBoundary", 2);

//    Select Boundaries 1, 2, 3, 141, 142.

    model.component("comp1").physics("acpr").feature("pmb1").selection().set(1, 2, 3, 141, 142);

//    In the Mesh toolbar, click Free Tetrahedral.

    model.component("comp1").mesh("mesh1").create("ftet1", "FreeTet");

//    Right-click Free Tetrahedral 1 and choose Size.

    model.component("comp1").mesh("mesh1").feature("ftet1").create("size1", "Size");

//    Set a finer mesh size in the thin regions.

    return model;
  }

  public static Model run2(Model model) {
//    In the Settings window for Size, locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Domain.

    model.component("comp1").mesh("mesh1").feature("ftet1").feature("size1").selection().geom("geom1", 3);

//    Select Domains 4, 5, 7, 8, 9, 10, 11, 12, 13.

    model.component("comp1").mesh("mesh1").feature("ftet1").feature("size1").selection()
         .set(4, 5, 7, 8, 9, 10, 11, 12, 13);

//    Locate the Element Size section.
//    Click the Custom button.

    model.component("comp1").mesh("mesh1").feature("ftet1").feature("size1").set("custom", true);

//    Locate the Element Size Parameters section.
//    Select the Maximum element size checkbox.

    model.component("comp1").mesh("mesh1").feature("ftet1").feature("size1").set("hmaxactive", true);

//    In the associated text field, type a_vent/3.

    model.component("comp1").mesh("mesh1").feature("ftet1").feature("size1").set("hmax", "a_vent/3");

//    In the Model Builder window, right-click Free Tetrahedral 1 and choose Size.

    model.component("comp1").mesh("mesh1").feature("ftet1").create("size2", "Size");

//    In the Settings window for Size, locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Domain.

    model.component("comp1").mesh("mesh1").feature("ftet1").feature("size2").selection().geom("geom1", 3);

//    Select Domain 2.

    model.component("comp1").mesh("mesh1").feature("ftet1").feature("size2").selection().set(2);

//    Locate the Element Size section.
//    Click the Custom button.

    model.component("comp1").mesh("mesh1").feature("ftet1").feature("size2").set("custom", true);

//    Locate the Element Size Parameters section.
//    Select the Minimum element size checkbox.

    model.component("comp1").mesh("mesh1").feature("ftet1").feature("size2").set("hminactive", true);

//    In the associated text field, type a_vent/3.

    model.component("comp1").mesh("mesh1").feature("ftet1").feature("size2").set("hmin", "a_vent/3");

//    Select the Maximum element growth rate checkbox.

    model.component("comp1").mesh("mesh1").feature("ftet1").feature("size2").set("hgradactive", true);

//    In the associated text field, type 1.3.

    model.component("comp1").mesh("mesh1").feature("ftet1").feature("size2").set("hgrad", 1.3);

//    In the Model Builder window, under Component 1 (comp1) > Mesh 1, click Size.
//    In the Settings window for Size, click to expand the Element Size Parameters section.
//    Locate the Element Size section.
//    Click the Custom button.

    model.component("comp1").mesh("mesh1").feature("size").set("custom", true);

//    Locate the Element Size Parameters section.
//    In the Maximum element size text field, type h_max.

    model.component("comp1").mesh("mesh1").feature("size").set("hmax", "h_max");

//    In the Minimum element size text field, type h_max/2.

    model.component("comp1").mesh("mesh1").feature("size").set("hmin", "h_max/2");

//    Click Build All.

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

//    A finer step size is chosen for the higher frequencies. This is to resolve the resonance peaks appearing when the gain is nonzero.
//    In the Model Builder window, under Study 1, click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Study Settings section.
//    In the Frequencies text field, type {10^{range(log10(20),1/20,log10(950))} 10^{range(log10(1000),1/60,log10(20000))}}.

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

//    Click to expand the Results While Solving section.
//    From the Probes list, select None.

    model.study("std1").feature("freq").set("probesel", "none");

//    Show the default solver suggestions and enable an iterative solver suggestion.
//    In the Study toolbar, click Show Default Solver.

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

//    In the Model Builder window, expand the Solution 1 (sol1) node.
//    In the Model Builder window, expand the Study 1 > Solver Configurations > Solution 1 (sol1) > Stationary Solver 1 node.
//    Right-click Study 1 > Solver Configurations > Solution 1 (sol1) > Stationary Solver 1 > Suggested Iterative Solver (GMRES with GMG) (acpr) and choose Enable.

    model.sol("sol1").feature("s1").feature("i1").active(true);

//    In the Study toolbar, click Parametric Sweep.

    model.study("std1").create("param", "Parametric");

//    In the Settings window for Parametric Sweep, locate the Study Settings section.
//    Click Add.

    model.study("std1").feature("param").setIndex("pname", "a_vent", 0);
    model.study("std1").feature("param").setIndex("plistarr", "", 0);
    model.study("std1").feature("param").setIndex("punit", "m", 0);
    model.study("std1").feature("param").setIndex("pname", "a_vent", 0);
    model.study("std1").feature("param").setIndex("plistarr", "", 0);
    model.study("std1").feature("param").setIndex("punit", "m", 0);

//    In the table, enter the following settings:

    model.study("std1").feature("param").setIndex("pname", "gain", 0);
    model.study("std1").feature("param").setIndex("plistarr", "0, 500", 0);

//    In the Study toolbar, click Compute.

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

    model.sol().create("sol2");
    model.sol("sol2").study("std1");
    model.sol("sol2").label("Parametric Solutions 1");

    model.batch("p1").feature("so1").set("psol", "sol2");
    model.batch("p1").run("compute");

    model.result().create("pg1", "PlotGroup3D");
    model.result("pg1").set("data", "dset2");
    model.result("pg1").setIndex("looplevel", 113, 0);
    model.result("pg1").setIndex("looplevel", 2, 1);
    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", "dset2");
    model.result("pg2").setIndex("looplevel", 113, 0);
    model.result("pg2").setIndex("looplevel", 2, 1);
    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", "dset2");
    model.result("pg3").setIndex("looplevel", 113, 0);
    model.result("pg3").setIndex("looplevel", 2, 1);
    model.result("pg3").create("iso1", "Isosurface");
    model.result("pg3").feature("iso1").set("expr", new String[]{"acpr.p_t"});
    model.result("pg3").feature("iso1").set("number", "10");
    model.result("pg3").feature("iso1").set("colortable", "Wave");
    model.result("pg3").feature("iso1").set("colorscalemode", "linearsymmetric");
    model.result("pg3").set("showlegendsunit", true);
    model.result("pg3").label("Acoustic Pressure, Isosurfaces (acpr)");
    model.result("pg1").run();

//    Create a plot for the acoustic response on the ear drum including both the experimental measurements and the simulation results.
//    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, locate the Data section.
//    From the Dataset list, select Study 1/Parametric Solutions 1 (sol2).

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

//    From the Parameter selection (gain) list, select First.

    model.result("pg4").setIndex("looplevelinput", "first", 1);

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

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

//    In the Label text field, type Eardrum Response.

    model.result("pg4").label("Eardrum Response");

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

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

//    In the Eardrum Response 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 Boundary.

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

//    From the Selection list, select Ear Drum.

    model.result("pg4").feature("oct1").selection().named("geom1_sel4");

//    Locate the y-Axis Data section.
//    In the Amplitude reference text field, type acpr.pref_SPL*sqrt(2).

    model.result("pg4").feature("oct1").set("amplref", "acpr.pref_SPL*sqrt(2)");

//    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", "COMSOL Model", 0);

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

    model.result("pg4").feature("oct1").create("gmrk1", "GraphMarker");
    model.result("pg4").feature("oct1").feature("gmrk1").set("linewidth", "preference");
    model.result("pg4").run();

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

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

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

    model.result("pg4").feature("oct1").feature("gmrk1").set("intersectionx", "700 3000 8000");

//    Select the Show lines checkbox.

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

//    In the Model Builder window, right-click Eardrum Response and choose Global.

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

//    In the Settings window for Global, type Measurements (1) in the Label text field.

    model.result("pg4").feature("glob1").label("Measurements (1)");

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

    model.result("pg4").feature("glob1").setIndex("expr", "L1(freq)", 0);

//    Click to expand the Legends section.
//    From the Legends list, select Manual.

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

//    In the table, enter the following settings:

    model.result("pg4").feature("glob1").setIndex("legends", "Measurements (1-5)", 0);

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

    model.result("pg4").feature("glob1").set("linestyle", "dashed");

//    From the Color list, select Black.

    model.result("pg4").feature("glob1").set("linecolor", "black");

//    Right-click Measurements (1) and choose Duplicate.

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

//    In the Settings window for Global, type Measurements (2-5) in the Label text field.

    model.result("pg4").feature("glob2").label("Measurements (2-5)");

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

    model.result("pg4").feature("glob2").set("legend", false);

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

    model.result("pg4").feature("glob2").setIndex("expr", "L2(freq)", 0);
    model.result("pg4").feature("glob2").setIndex("expr", "L3(freq)", 1);
    model.result("pg4").feature("glob2").setIndex("expr", "L4(freq)", 2);
    model.result("pg4").feature("glob2").setIndex("expr", "L5(freq)", 3);

//    In the Eardrum Response toolbar, click Plot.

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

//    In the Model Builder window, right-click Measurements (1) and choose Duplicate.

    model.result("pg4").feature().duplicate("glob3", "glob1");
    model.result("pg4").run();

//    In the Settings window for Global, type Measurements (Average) in the Label text field.

    model.result("pg4").feature("glob3").label("Measurements (Average)");

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

    model.result("pg4").feature("glob3").setIndex("expr", "Lav(freq)", 0);

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

    model.result("pg4").feature("glob3").set("linestyle", "solid");

//    From the Color list, select Red.

    model.result("pg4").feature("glob3").set("linecolor", "red");

//    From the Width list, select 2.

    model.result("pg4").feature("glob3").set("linewidth", 2);

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

    model.result("pg4").feature("glob3").setIndex("legends", "Average", 0);

//    In the Eardrum Response toolbar, click Plot.

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

//    Right-click Measurements (Average) and choose Duplicate.

    model.result("pg4").feature().duplicate("glob4", "glob3");
    model.result("pg4").run();

//    In the Settings window for Global, type Measurements (+-sigma) in the Label text field.

    model.result("pg4").feature("glob4").label("Measurements (+-sigma)");

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

    model.result("pg4").feature("glob4").setIndex("expr", "Lmsigma(freq)", 0);
    model.result("pg4").feature("glob4").setIndex("expr", "Lpsigma(freq)", 1);

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

    model.result("pg4").feature("glob4").set("linestyle", "dashed");

//    From the Width list, select Default from preferences (1).

    model.result("pg4").feature("glob4").set("linewidth", "preference");

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

    model.result("pg4").feature("glob4").set("legend", false);

//    In the Eardrum Response toolbar, click Plot.

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

//    Create a plot for the acoustic feedback at the microphones. Plot both the amplitude and phase of the acoustic feedback.
//    In the Results toolbar, click 1D Plot Group.

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

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

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

//    Locate the Data section.
//    From the Dataset list, select Study 1/Parametric Solutions 1 (sol2).

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

//    From the Parameter selection (gain) list, select First.

    model.result("pg5").setIndex("looplevelinput", "first", 1);

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

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

//    In the Microphones toolbar, click More Plots and choose Octave Band.

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

//    In the Settings window for Octave Band, type Front Microphone in the Label text field.

    model.result("pg5").feature("oct1").label("Front Microphone");

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

    model.result("pg5").feature("oct1").selection().geom("geom1", 2);

//    From the Selection list, select Front Microphone.

    model.result("pg5").feature("oct1").selection().named("geom1_sel2");

//    Locate the y-Axis Data section.
//    In the Expression text field, type abs((Tr(freq)+i*Ti(freq))*acpr.p_t).

    model.result("pg5").feature("oct1").set("expr", "abs((Tr(freq)+i*Ti(freq))*acpr.p_t)");

//    From the Expression type list, select General (non-dB).

    model.result("pg5").feature("oct1").set("exprtype", "general");

//    In the Reference expression text field, type aveop_ed(abs(acpr.p_t)).

    model.result("pg5").feature("oct1").set("generalref", "aveop_ed(abs(acpr.p_t))");

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

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

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

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

//    From the Legends list, select Manual.

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

//    In the table, enter the following settings:

    model.result("pg5").feature("oct1").setIndex("legends", "Front Microphone", 0);

//    Right-click Front Microphone and choose Duplicate.

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

//    In the Settings window for Octave Band, type Back Microphone in the Label text field.

    model.result("pg5").feature("oct2").label("Back Microphone");

//    Locate the Selection section.
//    Select the Activate Selection toggle button.
//    From the Selection list, select Back Microphone.

    model.result("pg5").feature("oct2").selection().named("geom1_sel3");

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

    model.result("pg5").feature("oct2").setIndex("legends", "Back Microphone", 0);

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

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

//    Right-click Back Microphone and choose Point Graph.

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

//    In the Settings window for Point Graph, locate the Selection section.
//    From the Selection list, select Front Microphone Point.

    model.result("pg5").feature("ptgr1").selection().named("geom1_sel6");

//    Locate the y-Axis Data section.
//    In the Expression text field, type arg(acpr.p_t).

    model.result("pg5").feature("ptgr1").set("expr", "arg(acpr.p_t)");

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

    model.result("pg5").feature("ptgr1").set("linecolor", "cyclereset");

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

    model.result("pg5").feature("ptgr1").set("linestyle", "dashed");

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

    model.result("pg5").feature("ptgr1").set("legend", true);

//    From the Legends list, select Manual.

    model.result("pg5").feature("ptgr1").set("legendmethod", "manual");

//    In the table, enter the following settings:

    model.result("pg5").feature("ptgr1").setIndex("legends", "Front Microphone - Phase", 0);

//    Right-click Results > Microphones > Point Graph 1 and choose Duplicate.

    model.result("pg5").feature().duplicate("ptgr2", "ptgr1");
    model.result("pg5").run();

//    In the Settings window for Point Graph, locate the Selection section.
//    Select the Activate Selection toggle button.
//    From the Selection list, select Front Microphone Point.
//    Locate the Coloring and Style section.
//    From the Color list, select Cycle.

    model.result("pg5").feature("ptgr2").set("linecolor", "cycle");

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

    model.result("pg5").feature("ptgr2").setIndex("legends", "Back Microphone - Phase", 0);
    model.result("pg5").run();

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

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

//    In the table, enter the following settings:

    model.result("pg5").setIndex("plotonsecyaxis", true, 2, 1);
    model.result("pg5").setIndex("plotonsecyaxis", true, 3, 1);

//    Select the y-axis label checkbox.

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

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

    model.result("pg5").set("ylabel", "abs(V) (mV/Pa)");

//    Select the Secondary y-axis label checkbox.

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

//    In the associated text field, type arg(V) (rad).

    model.result("pg5").set("yseclabel", "arg(V) (rad)");

//    Select the x-axis label checkbox.

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

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

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

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

    model.result("pg5").set("titletype", "none");

//    In the Microphones toolbar, click Plot.

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

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

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

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

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

//    Click the Show Grid button in the Graphics toolbar.

    model.component("comp1").view("view1").set("showgrid", false);

//    Right-click Sound Pressure Level (acpr) and choose Duplicate.

    model.result().duplicate("pg6", "pg2");
    model.result("pg6").run();

//    In the Settings window for 3D Plot Group, type Sound Pressure Level Array in the Label text field.

    model.result("pg6").label("Sound Pressure Level Array");

//    Locate the Data section.
//    From the Parameter value (gain) list, select 0.

    model.result("pg6").setIndex("looplevel", 1, 1);

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

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

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

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

//    Click to expand the Plot Array section.
//    From the Array type list, select Square.

    model.result("pg6").set("plotarraytype", "square");
    model.result("pg6").run();

//    In the Model Builder window, expand the Sound Pressure Level Array node, then click Surface 1.
//    In the Settings window for Surface, locate the Data section.
//    From the Dataset list, select Study 1/Solution 1 (sol1).

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

//    Right-click Results > Sound Pressure Level Array > Surface 1 and choose Duplicate.

    model.result("pg6").feature().duplicate("surf2", "surf1");
    model.result("pg6").run();

//    In the Settings window for Surface, locate the Data section.
//    From the Parameter value (freq (Hz)) list, select 1995.3.

    model.result("pg6").feature("surf2").setIndex("looplevel", 53, 0);

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

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

//    Right-click Surface 2 and choose Duplicate.

    model.result("pg6").feature().duplicate("surf3", "surf2");
    model.result("pg6").run();

//    In the Settings window for Surface, locate the Data section.
//    From the Parameter value (freq (Hz)) list, select 200.

    model.result("pg6").feature("surf3").setIndex("looplevel", 21, 0);

//    Right-click Surface 3 and choose Duplicate.

    model.result("pg6").feature().duplicate("surf4", "surf3");
    model.result("pg6").run();

//    In the Settings window for Surface, locate the Data section.
//    From the Parameter value (freq (Hz)) list, select 20.

    model.result("pg6").feature("surf4").setIndex("looplevel", 1, 0);

//    Click the Show Axis Orientation button in the Graphics toolbar.

    model.component("comp1").view("view1").set("showaxisorientation", false);

//    In the Sound Pressure Level Array toolbar, click Plot.

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

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

    model.result("pg1").setIndex("looplevel", 1, 1);
    model.result("pg1").setIndex("looplevel", 62, 0);
    model.result("pg1").run();
    model.result("pg1").setIndex("looplevel", 90, 0);
    model.result("pg1").run();

//    In the Model Builder window, click Acoustic Pressure (acpr).
//    From the Parameter value (freq (Hz)) list, select 14678.

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

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

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

//    Create a plot of the acoustic response on the eardrum including effects of acoustic feedback.
//    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, locate the Data section.
//    From the Dataset list, select Study 1/Parametric Solutions 1 (sol2).

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

//    In the Label text field, type Acoustic Feedback - Constant Gain.

    model.result("pg7").label("Acoustic Feedback - Constant Gain");

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

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

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

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

//    In the Acoustic Feedback - Constant Gain toolbar, click More Plots and choose Octave Band.

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

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

    model.result("pg7").feature("oct1").selection().geom("geom1", 2);

//    From the Selection list, select Ear Drum.

    model.result("pg7").feature("oct1").selection().named("geom1_sel4");

//    Locate the y-Axis Data section.
//    In the Amplitude reference text field, type acpr.pref_SPL*sqrt(2).

    model.result("pg7").feature("oct1").set("amplref", "acpr.pref_SPL*sqrt(2)");

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

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

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

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

//    Locate the y-Axis Data section.
//    Select the Description checkbox.

    model.result("pg7").feature("oct1").set("descractive", true);

//    In the associated text field, type Acoustic Response.

    model.result("pg7").feature("oct1").set("descr", "Acoustic Response");

//    In the Acoustic Feedback - Constant Gain toolbar, click Plot.

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

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

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

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

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

//    Locate the Data section.
//    From the Dataset list, select Study 1/Parametric Solutions 1 (sol2).

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

//    From the Parameter value (gain) list, select 0.

    model.result("pg8").setIndex("looplevel", 1, 1);

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

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

//    Locate the Plot Settings section.
//    Clear the Plot dataset edges checkbox.

    model.result("pg8").set("edges", false);

//    Locate the Color Legend section.
//    Clear the Show legends checkbox.

    model.result("pg8").set("showlegends", false);

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

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

//    Right-click Thumbnail and choose Streamline.

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

//    In the Settings window for Streamline, type Intensity in the Label text field.

    model.result("pg8").feature("str1").label("Intensity");

//    Locate the Expression section.
//    In the X-component text field, type -acpr.Ix.

    model.result("pg8").feature("str1").set("expr", new String[]{"-acpr.Ix", "", ""});

//    In the Y-component text field, type -acpr.Iy.

    model.result("pg8").feature("str1").set("expr", new String[]{"-acpr.Ix", "-acpr.Iy", ""});

//    In the Z-component text field, type -acpr.Iz.

    model.result("pg8").feature("str1").setIndex("expr", "-acpr.Iz", 2);

//    Locate the Streamline Positioning section.
//    In the Number text field, type 30.

    model.result("pg8").feature("str1").set("selnumber", 30);

//    Select Boundary 3.

    model.result("pg8").feature("str1").selection().set(3);

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

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

//    Click to expand the Advanced section.
//    Clear the Allow backward time integration checkbox.

    model.result("pg8").feature("str1").set("back", false);

//    Right-click Intensity and choose Color Expression.

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

//    In the Settings window for Color Expression, locate the Expression section.
//    In the Expression text field, type acpr.I_mag.

    model.result("pg8").feature("str1").feature("col1").set("expr", "acpr.I_mag");

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

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

//    From the Scale list, select Logarithmic.

    model.result("pg8").feature("str1").feature("col1").set("colorscalemode", "logarithmic");

//    Click to expand the Range section.
//    Select the Manual color range checkbox.

    model.result("pg8").feature("str1").feature("col1").set("rangecoloractive", true);

//    In the Maximum text field, type 1e-5.

    model.result("pg8").feature("str1").feature("col1").set("rangecolormax", "1e-5");
    model.result("pg8").run();

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

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

//    In the Settings window for Surface, type Ear in the Label text field.

    model.result("pg8").feature("surf1").label("Ear");

//    Right-click Ear and choose Material Appearance.

    return model;
  }

  public static Model run3(Model model) {

    model.result("pg8").feature("surf1").create("mtrl1", "MaterialAppearance");

//    In the Settings window for Material Appearance, locate the Appearance section.
//    From the Appearance list, select Custom.

    model.result("pg8").feature("surf1").feature("mtrl1").set("appearance", "custom");

//    From the Color list, select Gray.

    model.result("pg8").feature("surf1").feature("mtrl1").set("color", "gray");
    model.result("pg8").run();

//    In the Model Builder window, right-click Ear and choose Selection.

    model.result("pg8").feature("surf1").create("sel1", "Selection");

//    In the Settings window for Selection, locate the Selection section.
//    Click Paste Selection.
//    In the Paste Selection dialog, type 5-9, 14, 129 in the Selection text field.
//    Click OK.

    model.result("pg8").feature("surf1").feature("sel1").selection().set(5, 6, 7, 8, 9, 14, 129);
    model.result("pg8").run();

//    Right-click Ear and choose Duplicate.

    model.result("pg8").feature().duplicate("surf2", "surf1");
    model.result("pg8").run();

//    In the Model Builder window, click Ear 1.
//    In the Settings window for Surface, type Wire in the Label text field.

    model.result("pg8").feature("surf2").label("Wire");
    model.result("pg8").run();

//    In the Model Builder window, click Material Appearance 1.
//    In the Settings window for Material Appearance, locate the Appearance section.
//    From the Color list, select White.

    model.result("pg8").feature("surf2").feature("mtrl1").set("color", "white");
    model.result("pg8").run();

//    In the Model Builder window, click Selection 1.
//    In the Settings window for Selection, locate the Selection section.
//    Click Clear Selection.

    model.result("pg8").feature("surf2").feature("sel1").selection().set();

//    Click Paste Selection.
//    In the Paste Selection dialog, type 44, 45, 135-140, 143, 144 in the Selection text field.
//    Click OK.

    model.result("pg8").feature("surf2").feature("sel1").selection()
         .set(44, 45, 135, 136, 137, 138, 139, 140, 143, 144);
    model.result("pg8").run();

//    In the Model Builder window, right-click Wire and choose Duplicate.

    model.result("pg8").feature().duplicate("surf3", "surf2");
    model.result("pg8").run();

//    In the Model Builder window, click Wire 1.
//    In the Settings window for Surface, type Hearing Aid (Copper) in the Label text field.

    model.result("pg8").feature("surf3").label("Hearing Aid (Copper)");
    model.result("pg8").run();

//    In the Model Builder window, click Material Appearance 1.
//    In the Settings window for Material Appearance, locate the Appearance section.
//    From the Material type list, select Copper (oxidized).

    model.result("pg8").feature("surf3").feature("mtrl1").set("family", "copperoxidized");
    model.result("pg8").run();

//    In the Model Builder window, click Selection 1.
//    In the Settings window for Selection, locate the Selection section.
//    Click Clear Selection.

    model.result("pg8").feature("surf3").feature("sel1").selection().set();

//    Click Paste Selection.
//    In the Paste Selection dialog, type 146, 148, 150, 151, 153-155, 157, 159, 160, 162, 163, 165-168, 170-176, 178, 179, 181-189, 191, 194, 195 in the Selection text field.
//    Click OK.

    model.result("pg8").feature("surf3").feature("sel1").selection()
         .set(146, 148, 150, 151, 153, 154, 155, 157, 159, 160, 162, 163, 165, 166, 167, 168, 170, 171, 172, 173, 174, 175, 176, 178, 179, 181, 182, 183, 184, 185, 186, 187, 188, 189, 191, 194, 195);
    model.result("pg8").run();

//    In the Model Builder window, right-click Hearing Aid (Copper) and choose Duplicate.

    model.result("pg8").feature().duplicate("surf4", "surf3");
    model.result("pg8").run();

//    In the Model Builder window, click Hearing Aid (Copper) 1.
//    In the Settings window for Surface, type Hearing Aid (Black) in the Label text field.

    model.result("pg8").feature("surf4").label("Hearing Aid (Black)");
    model.result("pg8").run();

//    In the Model Builder window, click Material Appearance 1.
//    In the Settings window for Material Appearance, locate the Appearance section.
//    From the Material type list, select Plastic.

    model.result("pg8").feature("surf4").feature("mtrl1").set("family", "plastic");

//    From the Color list, select Black.

    model.result("pg8").feature("surf4").feature("mtrl1").set("color", "black");
    model.result("pg8").run();

//    In the Model Builder window, click Selection 1.
//    In the Settings window for Selection, locate the Selection section.
//    Click Clear Selection.

    model.result("pg8").feature("surf4").feature("sel1").selection().set();

//    Click Paste Selection.
//    In the Paste Selection dialog, type 10-13, 15-43, 46-128, 130-134, 145, 147, 149, 152, 156, 158, 164, 177, 180, 190, 192, 193, 196 in the Selection text field.
//    Click OK.

    model.result("pg8").feature("surf4").feature("sel1").selection()
         .set(10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 130, 131, 132, 133, 134, 145, 147, 149, 152, 156, 158, 164, 177, 180, 190, 192, 193, 196);
    model.result("pg8").run();

//    In the Model Builder window, right-click Hearing Aid (Black) and choose Duplicate.

    model.result("pg8").feature().duplicate("surf5", "surf4");
    model.result("pg8").run();

//    In the Model Builder window, click Hearing Aid (Black) 1.
//    In the Settings window for Surface, type LED in the Label text field.

    model.result("pg8").feature("surf5").label("LED");
    model.result("pg8").run();

//    In the Model Builder window, click Material Appearance 1.
//    In the Settings window for Material Appearance, locate the Appearance section.
//    From the Color list, select Green.

    model.result("pg8").feature("surf5").feature("mtrl1").set("color", "green");
    model.result("pg8").run();

//    In the Model Builder window, click Selection 1.
//    In the Settings window for Selection, locate the Selection section.
//    Click Clear Selection.

    model.result("pg8").feature("surf5").feature("sel1").selection().set();

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

    model.result("pg8").feature("surf5").feature("sel1").selection().set(169);
    model.result("pg8").run();

    model.title("Full Ear Hearing Aid Response");

    model
         .description("This model demonstrates how to perform a hearing aid acoustic feedback response analysis, including both the in-ear hearing aid and the hearing aid cassette. The hearing aid modeled is a ReSound OMNIA\u2122 device from GN Hearing A/S. The hearing aid is tested on a combined pinna and ear canal and calculates the sound pressure level at the eardrum and compares with measurements. The model also simulates the acoustic field outside the ear and includes the acoustic feedback to the two microphones located on the hearing aid cassette.\n\nThe model uses the Pressure Acoustics, Frequency Domain interface and models the loudspeaker with a Lumped Port, while the damping is modeled by Narrow Region Acoustics and Thermoviscous Boundary Layer Impedance in the domains and boundaries where it is appropriate.");

    return model;
  }

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

}
