/*
 * loudspeaker_driver_transient.java
 */

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

/** Model exported on May 15 2026, 10:09 by COMSOL 6.4.0.421. */
public class loudspeaker_driver_transient {

  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 AC/DC > Electromagnetic Fields > Magnetic Fields (mf).
//    Click Add.
//    In the Select Physics tree, select Acoustics > Pressure Acoustics > Pressure Acoustics, Transient (actd).
//    Click Add.
//    In the Select Physics tree, select Acoustics > Elastic Waves > Solid Mechanics (Elastic Waves) (solid).
//    Click Add.
//    In the Select Physics tree, select Acoustics > Thermoviscous Acoustics > Thermoviscous Acoustics, Transient (tatd).
//    Click Add.
//    Click Study.
//    The <l>Model Wizard</l> lets you select the first of the study steps you plan to use in the model. Select a stationary study used to solve for the initial condition; the static (DC) magnetic fields.
//    In the Select Study tree, select Preset Studies for Some Physics Interfaces > Stationary.
//    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("mf", "InductionCurrents", "geom1");
    model.component("comp1").physics().create("actd", "TransientPressureAcoustics", "geom1");
    model.component("comp1").physics().create("solid", "SolidMechanics", "geom1");
    model.component("comp1").physics().create("tatd", "ThermoacousticsSinglePhysicsTransient", "geom1");

    model.study().create("std1");
    model.study("std1").create("stat", "Stationary");

//    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 loudspeaker_driver_transient_parameters.txt.
//    To import content from file, use:
//    model.param().loadFile("FILENAME");
    model.param().set("N0", "100", "Number of turns in coil");
    model.param().set("V0", "10[V]", "Peak driving voltage");
    model.param().set("c0", "343[m/s]", "Speed of sound in air");
    model.param().set("f0", "70[Hz]", "Driving frequency");
    model.param().set("omega0", "2*pi*f0", "Driving angular frequency");
    model.param().set("T0", "1/f0", "Driving signal period");
    model.param().set("T_end", "4*T0", "End time for simulation");
    model.param().set("f_d", "40[Hz]", "Frequency at which stiffness damping factor is given");
    model.param().set("omega_d", "2*pi*f_d", "Angular frequency at which stiffness damping factor is given");
    model.param().set("E_com", "2[GPa]", "Young's modulus (composite)");
    model.param().set("nu_com", "0.42", "Poisson's ratio (composite)");
    model.param().set("eta_s_com", "0.04", "Isotropic loss factor (composite)");
    model.param().set("K_com", "E_com/(3*(1-2*nu_com))", "Bulk modulus (composite)");
    model.param().set("G_com", "E_com/(2*(1+nu_com))", "Shear modulus (composite)");
    model.param().set("E_gf", "70[GPa]", "Young's modulus (glass fiber)");
    model.param().set("nu_gf", "0.33", "Poisson's ratio (glass fiber)");
    model.param().set("eta_s_gf", "0.04", "Isotropic loss factor (glass fiber)");
    model.param().set("K_gf", "E_gf/(3*(1-2*nu_gf))", "Bulk modulus (glass fiber)");
    model.param().set("G_gf", "E_gf/(2*(1+nu_gf))", "Shear modulus (glass fiber)");
    model.param().set("mu0", "mu0_const", "Vacuum permeability");
    model.param().set("Nhar", "3", "Number of harmonics to resolve");

//    When working with your own modeling project of an acoustic driver, you will typically either draw the geometry in COMSOL Multiphysics, or import a CAD file of the driver itself and add the surrounding air and PML domains. Here, the entire geometry is imported as a sequence from the geometry file. The instructions to the geometry are found in the appendix at the end of this document.
//    In the Geometry toolbar, click Insert Sequence and choose Insert Sequence.

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

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

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    Add a <l>Ramp</l> function in order to model the transient regime of the input voltage before it reaches the steady state.
//    In the Home toolbar, click Functions and choose Global > Ramp.

    model.func().create("rm1", "Ramp");

//    In the Settings window for Ramp, locate the Parameters section.
//    In the Location text field, type 0.1*T0.

    model.func("rm1").set("location", "0.1*T0");

//    In the Slope text field, type 1/T0.

    model.func("rm1").set("slope", "1/T0");

//    Select the Cutoff checkbox.

    model.func("rm1").set("cutoffactive", true);

//    Click to expand the Smoothing section.
//    Select the Size of transition zone at start checkbox.

    model.func("rm1").set("smoothzonelocactive", true);

//    In the associated text field, type 0.2*T0.

    model.func("rm1").set("smoothzoneloc", "0.2*T0");

//    Select the Size of transition zone at cutoff checkbox.

    model.func("rm1").set("smoothzonecutoffactive", true);

//    In the associated text field, type 0.2*T0.

    model.func("rm1").set("smoothzonecutoff", "0.2*T0");

//    Create selections for the coil and the domains where you will specify the physics and also a selection for the boundary adjacent to the Solid Mechanics domains. Here, the selections are pasted to the text field to simplify the modeling. Normally, they are selected in the geometry window.
//    In the Definitions toolbar, click Explicit.

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

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

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

//    Locate the Input Entities section.
//    Click Paste Selection.
//    In the Paste Selection dialog, type 15 in the Selection text field.
//    Click OK.

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

//    In the Definitions toolbar, click Explicit.

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

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

    model.component("comp1").selection("sel2").label("Solid Mechanics");

//    Locate the Input Entities section.
//    Click Paste Selection.
//    In the Paste Selection dialog, type 4, 9-17, 20 in the Selection text field.
//    Click OK.

    model.component("comp1").selection("sel2").set(4, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20);

//    In the Definitions toolbar, click Explicit.

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

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

    model.component("comp1").selection("sel3").label("Magnetic Fields");

//    Locate the Input Entities section.
//    Click Paste Selection.
//    In the Paste Selection dialog, type 2, 3, 8-13, 15, 16, 18, 19 in the Selection text field.
//    Click OK.

    model.component("comp1").selection("sel3").set(2, 3, 8, 9, 10, 11, 12, 13, 15, 16, 18, 19);

//    In the Definitions toolbar, click Explicit.

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

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

    model.component("comp1").selection("sel4").label("Pressure Acoustic");

//    Locate the Input Entities section.
//    Click Paste Selection.
//    In the Paste Selection dialog, type 1, 2, 6, 7 in the Selection text field.
//    Click OK.

    model.component("comp1").selection("sel4").set(1, 2, 6, 7);

//    In the Definitions toolbar, click Explicit.

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

//    In the Settings window for Explicit, type Thermoviscous Acoustic and Moving Mesh in the Label text field.

    model.component("comp1").selection("sel5").label("Thermoviscous Acoustic and Moving Mesh");

//    Locate the Input Entities section.
//    Click Paste Selection.
//    In the Paste Selection dialog, type 3, 5 in the Selection text field.
//    Click OK.

    model.component("comp1").selection("sel5").set(3, 5);

//    In the Definitions toolbar, click Adjacent.

    model.component("comp1").selection().create("adj1", "Adjacent");

//    In the Settings window for Adjacent, type Solid Mechanics Exterior Boundaries in the Label text field.

    model.component("comp1").selection("adj1").label("Solid Mechanics Exterior Boundaries");

//    Locate the Input Entities section.
//    Under Input selections, click Add.
//    In the Add dialog, select Solid Mechanics in the Input selections list.
//    Click OK.

    model.component("comp1").selection("adj1").set("input", new String[]{"sel2"});

//    Define an <l>Average</l> operator over the coil domain.
//    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);

//    In the Settings window for Average, locate the Source Selection section.
//    From the Selection list, select Coil.

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

//    Locate the Advanced section.
//    Clear the Compute integral in revolved geometry checkbox.

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

//    While the material properties used in this model are partly made up, they resemble those used in a real driver. The diaphragm and dust cap both consist of a HexaCone\[\textregistered\]-like material; a light and very stiff composite. The apex has properties representative of glass fiber materials. The spider, acting as a spring, is made of a phenolic cloth with a much lower stiffness. The material used in the coil is taken to be lighter than copper, as the wire is insulated and does not completely fill the coil domain. The surround, finally, is a light resistive foam.
//    Except for air and soft Iron, the materials you will use all come from a material library created especially for this model (to be loaded from the file <c>loudspeaker_driver_materials.mph</c>). You may notice that some of the materials will report missing properties. For example, the composite does not include any electromagnetic properties. This is fine, as you will not model the magnetic fields in the domains where the composite is used.
//    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");

//    First, add air which will be present everywhere in your geometry. Next, switch to using nonlinear Iron in the pole piece and top plate.
//    In the tree, select AC/DC > Soft Iron (With Losses).
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat2", "Common");
    model.component("comp1").material("mat2").propertyGroup().create("BHCurve", "BHCurve", "B-H Curve");
    model.component("comp1").material("mat2").propertyGroup("BHCurve").func().create("BH", "Interpolation");
    model.component("comp1").material("mat2").propertyGroup()
         .create("EffectiveBHCurve", "EffectiveBHCurve", "Effective B-H Curve");
    model.component("comp1").material("mat2").propertyGroup("EffectiveBHCurve").func()
         .create("BHeff", "Interpolation");
    model.component("comp1").material("mat2").label("Soft Iron (With Losses)");
    model.component("comp1").material("mat2").set("family", "iron");
    model.component("comp1").material("mat2").propertyGroup("def")
         .set("electricconductivity", new String[]{"1.12e7[S/m]", "0", "0", "0", "1.12e7[S/m]", "0", "0", "0", "1.12e7[S/m]"});
    model.component("comp1").material("mat2").propertyGroup("def")
         .set("relpermittivity", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat2").propertyGroup("BHCurve").label("B-H Curve");
    model.component("comp1").material("mat2").propertyGroup("BHCurve").func("BH").label("Interpolation 1");
    model.component("comp1").material("mat2").propertyGroup("BHCurve").func("BH")
         .set("table", new String[][]{{"0", "0"}, 
         {"663.146", "1"}, 
         {"1067.5", "1.1"}, 
         {"1705.23", "1.2"}, 
         {"2463.11", "1.3"}, 
         {"3841.67", "1.4"}, 
         {"5425.74", "1.5"}, 
         {"7957.75", "1.6"}, 
         {"12298.3", "1.7"}, 
         {"20462.8", "1.8"}, 
         {"32169.6", "1.9"}, 
         {"61213.4", "2"}, 
         {"111408", "2.1"}, 
         {"188487.757", "2.2"}, 
         {"267930.364", "2.3"}, 
         {"347507.836", "2.4"}});
    model.component("comp1").material("mat2").propertyGroup("BHCurve").func("BH").set("extrap", "linear");
    model.component("comp1").material("mat2").propertyGroup("BHCurve").func("BH").set("fununit", new String[]{"T"});
    model.component("comp1").material("mat2").propertyGroup("BHCurve").func("BH").set("argunit", new String[]{"A/m"});
    model.component("comp1").material("mat2").propertyGroup("BHCurve").func("BH").set("plotleftextrap", false);
    model.component("comp1").material("mat2").propertyGroup("BHCurve").func("BH").set("defineinv", true);
    model.component("comp1").material("mat2").propertyGroup("BHCurve").func("BH").set("defineprimfun", true);
    model.component("comp1").material("mat2").propertyGroup("BHCurve").set("normB", "BH(normHin)");
    model.component("comp1").material("mat2").propertyGroup("BHCurve").set("normH", "BH_inv(normBin)");
    model.component("comp1").material("mat2").propertyGroup("BHCurve").set("Wpm", "BH_prim(normHin)");
    model.component("comp1").material("mat2").propertyGroup("BHCurve").descr("normHin", "Magnetic field norm");
    model.component("comp1").material("mat2").propertyGroup("BHCurve").descr("normBin", "Magnetic flux density norm");
    model.component("comp1").material("mat2").propertyGroup("BHCurve").addInput("magneticfield");
    model.component("comp1").material("mat2").propertyGroup("BHCurve").addInput("magneticfluxdensity");
    model.component("comp1").material("mat2").propertyGroup("EffectiveBHCurve").label("Effective B-H Curve");
    model.component("comp1").material("mat2").propertyGroup("EffectiveBHCurve").func("BHeff")
         .label("Interpolation 1");
    model.component("comp1").material("mat2").propertyGroup("EffectiveBHCurve").func("BHeff")
         .set("table", new String[][]{{"0", "0"}, 
         {"663.146", "1.000000051691021"}, 
         {"1067.5", "1.4936495124126294"}, 
         {"1705.23", "1.9415328461315795"}, 
         {"2463.11", "2.257765669366018"}, 
         {"3841.67", "2.609980642431287"}, 
         {"5425.74", "2.8664452090837504"}, 
         {"7957.75", "3.1441438097176118"}, 
         {"12298.3", "3.448538051654125"}, 
         {"20462.8", "3.7816711973679054"}, 
         {"32169.6", "4.058345590113038"}, 
         {"61213.4", "4.420646552950275"}, 
         {"111408", "4.721274089545955"}, 
         {"188487.757", "4.972148140718701"}, 
         {"267930.364", "5.145510860855953"}, 
         {"347507.836", "5.245510861426532"}});
    model.component("comp1").material("mat2").propertyGroup("EffectiveBHCurve").func("BHeff").set("extrap", "linear");
    model.component("comp1").material("mat2").propertyGroup("EffectiveBHCurve").func("BHeff")
         .set("fununit", new String[]{"T"});
    model.component("comp1").material("mat2").propertyGroup("EffectiveBHCurve").func("BHeff")
         .set("argunit", new String[]{"A/m"});
    model.component("comp1").material("mat2").propertyGroup("EffectiveBHCurve").func("BHeff")
         .set("plotleftextrap", false);
    model.component("comp1").material("mat2").propertyGroup("EffectiveBHCurve").func("BHeff").set("defineinv", true);
    model.component("comp1").material("mat2").propertyGroup("EffectiveBHCurve").func("BHeff")
         .set("defineprimfun", true);
    model.component("comp1").material("mat2").propertyGroup("EffectiveBHCurve").set("normBeff", "BHeff(normHeffin)");
    model.component("comp1").material("mat2").propertyGroup("EffectiveBHCurve")
         .set("normHeff", "BHeff_inv(normBeffin)");
    model.component("comp1").material("mat2").propertyGroup("EffectiveBHCurve")
         .set("Wpmeff", "BHeff_prim(normHeffin)");
    model.component("comp1").material("mat2").propertyGroup("EffectiveBHCurve")
         .descr("normHeffin", "Effective magnetic field norm");
    model.component("comp1").material("mat2").propertyGroup("EffectiveBHCurve")
         .descr("normBeffin", "Effective magnetic flux density norm");
    model.component("comp1").material("mat2").propertyGroup("EffectiveBHCurve").addInput("magneticfield");
    model.component("comp1").material("mat2").propertyGroup("EffectiveBHCurve").addInput("magneticfluxdensity");

//    Select Domains 8, 18.

    model.component("comp1").material("mat2").selection().set(8, 18);

//    In the ribbon, on the <l>Materials</l> tab click <l>Browse Materials</l>.
//    The <l>Import Material Library</l> functionality is activated by clicking the small icon at the lower-right, below the Material Browser tree.
//    In the Material Browser window, click Import Material Library.
//    Browse to the model's Application Library folder and double-click the file loudspeaker_driver_materials.mph.
//    Click Done.
//    In the tree, select loudspeaker driver materials > Composite.
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat3", "Common");
    model.component("comp1").material("mat3").label("Composite");
    model.component("comp1").material("mat3").propertyGroup("def").set("youngsmodulus", "2[GPa]");
    model.component("comp1").material("mat3").propertyGroup("def").set("poissonsratio", "0.42");
    model.component("comp1").material("mat3").propertyGroup("def").set("density", "1200[kg/m^3]");
    model.component("comp1").material("mat3").propertyGroup("def").set("lossfactor", "0.04");

//    Select Domains 4, 17.

    model.component("comp1").material("mat3").selection().set(4, 17);

//    In the tree, select loudspeaker driver materials > Cloth.
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat4", "Common");
    model.component("comp1").material("mat4").label("Cloth");
    model.component("comp1").material("mat4").propertyGroup("def")
         .set("electricconductivity", new String[]{"0", "0", "0", "0", "0", "0", "0", "0", "0"});
    model.component("comp1").material("mat4").propertyGroup("def")
         .set("relpermittivity", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat4").propertyGroup("def")
         .set("relpermeability", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat4").propertyGroup("def").set("youngsmodulus", "0.58[GPa]");
    model.component("comp1").material("mat4").propertyGroup("def").set("poissonsratio", "0.3");
    model.component("comp1").material("mat4").propertyGroup("def").set("density", "650[kg/m^3]");

//    Select Domain 16.

    model.component("comp1").material("mat4").selection().set(16);

//    In the tree, select loudspeaker driver materials > Foam.
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat5", "Common");
    model.component("comp1").material("mat5").label("Foam");
    model.component("comp1").material("mat5").propertyGroup("def").set("youngsmodulus", "5[MPa]");
    model.component("comp1").material("mat5").propertyGroup("def").set("poissonsratio", "0.4");
    model.component("comp1").material("mat5").propertyGroup("def").set("density", "67[kg/m^3]");

//    Select Domain 20.

    model.component("comp1").material("mat5").selection().set(20);

//    In the tree, select loudspeaker driver materials > Coil.
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat6", "Common");
    model.component("comp1").material("mat6").label("Coil");
    model.component("comp1").material("mat6").propertyGroup("def").set("lossfactor", "0.05");
    model.component("comp1").material("mat6").propertyGroup("def")
         .set("relpermittivity", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat6").propertyGroup("def")
         .set("relpermeability", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat6").propertyGroup("def").set("youngsmodulus", "110[GPa]");
    model.component("comp1").material("mat6").propertyGroup("def").set("poissonsratio", "0.35");
    model.component("comp1").material("mat6").propertyGroup("def").set("density", "4500[kg/m^3]");

//    Select Domain 15.

    model.component("comp1").material("mat6").selection().set(15);

//    In the tree, select loudspeaker driver materials > Glass Fiber.
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat7", "Common");
    model.component("comp1").material("mat7").label("Glass Fiber");
    model.component("comp1").material("mat7").propertyGroup("def")
         .set("electricconductivity", new String[]{"0", "0", "0", "0", "0", "0", "0", "0", "0"});
    model.component("comp1").material("mat7").propertyGroup("def")
         .set("relpermittivity", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat7").propertyGroup("def")
         .set("relpermeability", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat7").propertyGroup("def").set("youngsmodulus", "70[GPa]");
    model.component("comp1").material("mat7").propertyGroup("def").set("poissonsratio", "0.33");
    model.component("comp1").material("mat7").propertyGroup("def").set("density", "2000[kg/m^3]");

    return model;
  }

  public static Model run2(Model model) {
    model.component("comp1").material("mat7").propertyGroup("def").set("lossfactor", "0.04");

//    Select Domains 9, 10, 11, 12, 13, 14.

    model.component("comp1").material("mat7").selection().set(9, 10, 11, 12, 13, 14);

//    In the tree, select loudspeaker driver materials > Generic Ferrite.
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat8", "Common");
    model.component("comp1").material("mat8").propertyGroup()
         .create("RemanentFluxDensity", "RemanentFluxDensity", "Remanent flux density");
    model.component("comp1").material("mat8").label("Generic Ferrite");
    model.component("comp1").material("mat8").propertyGroup("def").set("lossfactor", "0.01");
    model.component("comp1").material("mat8").propertyGroup("def")
         .set("electricconductivity", new String[]{"0", "0", "0", "0", "0", "0", "0", "0", "0"});
    model.component("comp1").material("mat8").propertyGroup("def")
         .set("relpermittivity", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat8").propertyGroup("def").set("poissonsratio", "0.3");
    model.component("comp1").material("mat8").propertyGroup("def").set("youngsmodulus", "200[GPa]");
    model.component("comp1").material("mat8").propertyGroup("def").set("density", "5000[kg/m^3]");
    model.component("comp1").material("mat8").propertyGroup("RemanentFluxDensity")
         .set("murec", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat8").propertyGroup("RemanentFluxDensity").set("normBr", "0.4[T]");

//    In the Materials toolbar, click Add Material to close the Add Material window.
//    Select Domain 19.

    model.component("comp1").material("mat8").selection().set(19);

//    Now it is time to set up the physics interfaces. Specify the selection where the Magnetic Fields equation needs to be solved, that is the magnetic motor domain and its surroundings. In the other domains, the magnetic field is assumed to be negligible.
//    In the Model Builder window, under Component 1 (comp1), click Magnetic Fields (mf).
//    In the Settings window for Magnetic Fields, locate the Domain Selection section.
//    From the Selection list, select Magnetic Fields.

    model.component("comp1").physics("mf").selection().named("sel3");

//    Add an instance of the <l>Ampère's Law in Solids</l> domain feature in all Magnetic Fields domains, where the material is different from air.
//    In the Physics toolbar, click Domains and choose Ampère's Law in Solids.

    model.component("comp1").physics("mf").create("als1", "AmperesLawSolid", 2);

//    In the Settings window for Ampère's Law in Solids, type Ampère's Law in Solids - Generic Ferrite in the Label text field.

    model.component("comp1").physics("mf").feature("als1").label("Amp\u00e8re's Law in Solids - Generic Ferrite");

//    Select Domain 19.

    model.component("comp1").physics("mf").feature("als1").selection().set(19);

//    Locate the Constitutive Relation B-H section.
//    From the Magnetization model list, select Remanent flux density.

    model.component("comp1").physics("mf").feature("als1").set("ConstitutiveRelationBH", "RemanentFluxDensity");

//    Specify the \[\mathbf{e}\] vector as

    model.component("comp1").physics("mf").feature("als1").set("e_crel_BH_RemanentFluxDensity", new int[]{0, 0, 1});

//    In the Physics toolbar, click Domains and choose Ampère's Law in Solids.

    model.component("comp1").physics("mf").create("als2", "AmperesLawSolid", 2);

//    In the Settings window for Ampère's Law in Solids, type Ampère's Law in Solids - Soft Iron in the Label text field.

    model.component("comp1").physics("mf").feature("als2").label("Amp\u00e8re's Law in Solids - Soft Iron");

//    Select Domains 8, 18.

    model.component("comp1").physics("mf").feature("als2").selection().set(8, 18);

//    Locate the Constitutive Relation B-H section.
//    From the Magnetization model list, select B-H curve.

    model.component("comp1").physics("mf").feature("als2").set("ConstitutiveRelationBH", "BHCurve");

//    The BH curve is provided by the soft iron material.
//    In the Physics toolbar, click Domains and choose Ampère's Law in Solids.

    model.component("comp1").physics("mf").create("als3", "AmperesLawSolid", 2);

//    In the Settings window for Ampère's Law in Solids, locate the Domain Selection section.
//    From the Selection list, select Solid Mechanics.

    model.component("comp1").physics("mf").feature("als3").selection().named("sel2");

//    In the Label text field, type Ampère's Law in Solids - Nonconductive Solids.

    model.component("comp1").physics("mf").feature("als3")
         .label("Amp\u00e8re's Law in Solids - Nonconductive Solids");

//    In the Physics toolbar, click Domains and choose Domain Coil.

    model.component("comp1").physics("mf").create("coil1", "Coil", 2);

//    In the Settings window for Domain Coil, locate the Domain Selection section.
//    From the Selection list, select Coil.

    model.component("comp1").physics("mf").feature("coil1").selection().named("sel1");

//    Locate the Material Type section.
//    From the Material type list, select Solid.

    model.component("comp1").physics("mf").feature("coil1").setIndex("materialType", "solid", 0);

//    Locate the Coil section.
//    From the Conductor model list, select Homogenized multiturn.

    model.component("comp1").physics("mf").feature("coil1").set("ConductorModel", "Multi");

//    From the Coil excitation list, select Voltage.

    model.component("comp1").physics("mf").feature("coil1").set("CoilExcitation", "Voltage");

//    In the \[V_{\textrm{coil}}\] text field, type V0*sin(2*pi*f0*t)*rm1(t).

    model.component("comp1").physics("mf").feature("coil1").set("VCoil", "V0*sin(2*pi*f0*t)*rm1(t)");

//    The harmonic voltage is multiplied by the previously defined ramp function to add the smooth build-up time to the signal.
//    Locate the Homogenized Conductor section.
//    In the \[N\] text field, type N0.

    model.component("comp1").physics("mf").feature("coil1").set("N", "N0");

//    From the Coil wire cross-section area list, select User defined.

    model.component("comp1").physics("mf").feature("coil1").set("AreaFrom", "UserDefined");

//    Find the High-frequency effective loss subsection.
//    Clear the Include harmonic loss checkbox.

    model.component("comp1").physics("mf").feature("coil1").set("HarmonicLoss", false);

//    In the \[a\] text field, type 2.4e-8[m^2].

    model.component("comp1").physics("mf").feature("coil1").set("coilWindArea", "2.4e-8[m^2]");

//    The area of the coil domain is \[4 \cdot 10^{-6} \] m<sup>2</sup>. The number of turns <c>N0 = 100</c> makes the total cross-sectional area covered by the wires equal to \[2.4 \cdot 10^{-6} \] m<sup>2</sup>, which will give the fill factor of 60%.
//    In the Model Builder window, under Component 1 (comp1), click Pressure Acoustics, Transient (actd).
//    In the Settings window for Pressure Acoustics, Transient, locate the Domain Selection section.
//    From the Selection list, select Pressure Acoustic.

    model.component("comp1").physics("actd").selection().named("sel4");

//    Modify the <l>Transient Solver Settings</l> according to the frequency of the input signal. This setting will adjust the time-dependent solver settings.
//    Locate the <l>Transient Solver Settings</l> section. In the <l>Maximum frequency to resolve</l> field enter <c>Nhar*f0</c>. It will give the maximal time step for the Transient Solver.

    model.component("comp1").physics("actd").prop("TransientSettings").set("fmax", "Nhar*f0");

//    In the Model Builder window, under Component 1 (comp1), click Solid Mechanics (solid).
//    In the Settings window for Solid Mechanics, locate the Domain Selection section.
//    From the Selection list, select Solid Mechanics.

    model.component("comp1").physics("solid").selection().named("sel2");

//    With the above selection, you leave out the magnet, pole piece, and top plate. You will consider these domains as perfectly rigid by using the default sound hard wall condition on their surfaces.
//    Add damping to some of the solid materials.
//    In the Model Builder window, under Component 1 (comp1) > Solid Mechanics (solid), click Linear Elastic Material 1.
//    In the Physics toolbar, click Attributes and choose Damping.

    model.component("comp1").physics("solid").feature("lemm1").create("dmp1", "Damping", 2);

//    In the Settings window for Damping, locate the Damping Settings section.
//    In the \[\beta_{\textrm{d}K}\] text field, type 0.14/omega_d.

    model.component("comp1").physics("solid").feature("lemm1").feature("dmp1").set("beta_dK", "0.14/omega_d");

//    Locate the Domain Selection section.
//    Click Clear Selection.

    model.component("comp1").physics("solid").feature("lemm1").feature("dmp1").selection().set();

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

    model.component("comp1").physics("solid").feature("lemm1").feature("dmp1").selection().set(16);

//    In the Model Builder window, click Linear Elastic Material 1.
//    In the Physics toolbar, click Attributes and choose Damping.

    model.component("comp1").physics("solid").feature("lemm1").create("dmp2", "Damping", 2);

//    In the Settings window for Damping, locate the Damping Settings section.
//    In the \[\beta_{\textrm{d}K}\] text field, type 0.46/omega_d.

    model.component("comp1").physics("solid").feature("lemm1").feature("dmp2").set("beta_dK", "0.46/omega_d");

//    Locate the Domain Selection section.
//    Click Clear Selection.

    model.component("comp1").physics("solid").feature("lemm1").feature("dmp2").selection().set();

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

    model.component("comp1").physics("solid").feature("lemm1").feature("dmp2").selection().set(20);

//    In the Model Builder window, click Linear Elastic Material 1.
//    In the Physics toolbar, click Attributes and choose Damping.

    model.component("comp1").physics("solid").feature("lemm1").create("dmp3", "Damping", 2);

//    In the Settings window for Damping, locate the Damping Settings section.
//    From the Damping type list, select Viscous damping.

    model.component("comp1").physics("solid").feature("lemm1").feature("dmp3").set("DampingType", "ViscousDamping");

//    In the \[\eta_{\textrm{b}}\] text field, type eta_s_gf*K_gf/omega0.

    model.component("comp1").physics("solid").feature("lemm1").feature("dmp3").set("etab", "eta_s_gf*K_gf/omega0");

//    In the \[\eta_{\textrm{v}}\] text field, type eta_s_gf*G_gf/omega0.

    model.component("comp1").physics("solid").feature("lemm1").feature("dmp3").set("etav", "eta_s_gf*G_gf/omega0");

//    Locate the Domain Selection section.
//    Click Clear Selection.

    model.component("comp1").physics("solid").feature("lemm1").feature("dmp3").selection().set();

//    Click Paste Selection.
//    In the Paste Selection dialog, type 9-14 in the Selection text field.
//    Click OK.

    model.component("comp1").physics("solid").feature("lemm1").feature("dmp3").selection().set(9, 10, 11, 12, 13, 14);

//    In the Model Builder window, click Linear Elastic Material 1.
//    In the Physics toolbar, click Attributes and choose Damping.

    model.component("comp1").physics("solid").feature("lemm1").create("dmp4", "Damping", 2);

//    In the Settings window for Damping, locate the Damping Settings section.
//    From the Damping type list, select Viscous damping.

    model.component("comp1").physics("solid").feature("lemm1").feature("dmp4").set("DampingType", "ViscousDamping");

//    In the \[\eta_{\textrm{b}}\] text field, type eta_s_com*K_com/omega0.

    model.component("comp1").physics("solid").feature("lemm1").feature("dmp4").set("etab", "eta_s_com*K_com/omega0");

//    In the \[\eta_{\textrm{v}}\] text field, type eta_s_com*G_com/omega0.

    model.component("comp1").physics("solid").feature("lemm1").feature("dmp4").set("etav", "eta_s_com*G_com/omega0");

//    Locate the Domain Selection section.
//    Click Clear Selection.

    model.component("comp1").physics("solid").feature("lemm1").feature("dmp4").selection().set();

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

    model.component("comp1").physics("solid").feature("lemm1").feature("dmp4").selection().set(4, 17);

//    The spider and the surround are attached to the case.
//    In the Physics toolbar, click Boundaries and choose Fixed Constraint.

    model.component("comp1").physics("solid").create("fix1", "Fixed", 1);

//    In the Settings window for Fixed Constraint, locate the Boundary Selection section.
//    Click Paste Selection.
//    In the Paste Selection dialog, type 72 76 in the Selection text field.
//    Click OK.

    model.component("comp1").physics("solid").feature("fix1").selection().set(72, 76);

//    Now proceed and set up the transient Thermoviscous Acoustics physics. It will be active in the Moving Mesh domain. For this large domain the Adiabatic formulation is ideal.
//    In the Model Builder window, under Component 1 (comp1), click Thermoviscous Acoustics, Transient (tatd).
//    In the Settings window for Thermoviscous Acoustics, Transient, locate the Domain Selection section.
//    From the Selection list, select Thermoviscous Acoustic and Moving Mesh.

    model.component("comp1").physics("tatd").selection().named("sel5");

//    Locate the Transient Solver and Mesh Settings section.
//    In the \[f_\textrm{max}\] text field, type Nhar*f0.

    model.component("comp1").physics("tatd").prop("TransientSettings").set("fmax", "Nhar*f0");

//    Locate the Thermoviscous Acoustics Equation Settings section.
//    Select the Adiabatic formulation checkbox.

    model.component("comp1").physics("tatd").prop("EquationSettings").set("AdiabaticFormulation", true);

//    In the Model Builder window, under Component 1 (comp1) > Thermoviscous Acoustics, Transient (tatd), click Wall 1.
//    In the Settings window for Wall, locate the Mechanical section.
//    From the Mechanical condition list, select Slip (perfect).

    model.component("comp1").physics("tatd").feature("wall1").set("MechanicalCondition", "Slip");

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

    model.component("comp1").physics("tatd").create("wall2", "Wall", 1);

//    Select Boundaries 16, 43, 89, 90, 91, 92.

    model.component("comp1").physics("tatd").feature("wall2").selection().set(16, 43, 89, 90, 91, 92);

//    Now, look into the multiphysics coupling under the <l>Multiphysics</l> node.
//    Now, the <l>Magnetomechanics</l> multiphysics feature is added to handle Lorentz force on the coil.
//    In the Physics toolbar, click Multiphysics Couplings and choose Domain > Magnetomechanics, Solid.

    model.component("comp1").multiphysics().create("mmcpl1", "Magnetomechanics", 2);

//    In the Settings window for Magnetomechanics, Solid, locate the Domain Selection section.
//    From the Selection list, select Coil.

    model.component("comp1").multiphysics("mmcpl1").selection().named("sel1");

//    Locate the Lorentz Coupling section.
//    Select the Only use Lorentz force checkbox.

    model.component("comp1").multiphysics("mmcpl1").set("OnlyLorentz", true);

//    In the Physics toolbar, click Multiphysics Couplings and choose Boundary > Acoustic–Thermoviscous Acoustic Boundary.

    model.component("comp1").multiphysics().create("atb1", "AcousticThermoacousticBoundary", 1);

//    In the Settings window for Acoustic–Thermoviscous Acoustic Boundary, locate the Boundary Selection section.
//    From the Selection list, select All boundaries.

    model.component("comp1").multiphysics("atb1").selection().all();

//    In the Physics toolbar, click Multiphysics Couplings and choose Boundary > Thermoviscous Acoustic–Structure Boundary.

    model.component("comp1").multiphysics().create("tsb1", "ThermoacousticStructureBoundary", 1);

//    In the Settings window for Thermoviscous Acoustic–Structure Boundary, locate the Boundary Selection section.
//    From the Selection list, select All boundaries.

    model.component("comp1").multiphysics("tsb1").selection().all();

//    First select all the boundaries (giving all applicable), then go to <l>Manual</l> and de-select the two boundaries on the Coil (19 and 42). Here we want to model the viscous losses and will add a No Slip.
//    From the Selection list, select Manual.

    model.component("comp1").multiphysics("tsb1").selection()
         .set(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 43, 44, 45, 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);

//    Locate the Mechanical section.
//    From the Mechanical condition list, select Slip (perfect).

    model.component("comp1").multiphysics("tsb1").set("MechanicalCondition", "PerfectSlip");

//    In the Physics toolbar, click Multiphysics Couplings and choose Boundary > Thermoviscous Acoustic–Structure Boundary.

    model.component("comp1").multiphysics().create("tsb2", "ThermoacousticStructureBoundary", 1);

//    Select Boundaries 19, 42.

    model.component("comp1").multiphysics("tsb2").selection().set(19, 42);

//    Add a <l>Perfectly Matched Layer</l> to truncate the computational domain without introducing spurious reflections of the acoustic waves from the outer boundary.
//    In the Definitions toolbar, click Perfectly Matched Layer.

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

//    Select Domains 1, 7.

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

//    In the Settings window for Perfectly Matched Layer, locate the Scaling section.
//    In the PML scaling curvature parameter text field, type 3.

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

//    The <l>Solid Mechanics</l> domains will move and deform due to the motion of the voice coil caused by the Lorenz force. To account for the deformed configuration of the system during the calculation, add the <l>Moving Mesh</l> feature and specify the <l>Deforming Domain</l> above and below the moving parts. The movement of the mesh is automatically taken from the <l>Solid Mechanics</l> interface. The <l>Moving Mesh</l> is not compatible with the second order formulation of <l>Pressure Acoustics, Transient</l>. <l>Thermoviscous Acoustics, Transient</l> is used on the moving domains, this also allows to include the viscous damping in the magnetic air gap. On the axis-of-symmetry add the <l>Symmetry/Roller</l> conditions, as the mesh needs to slide where it is in contact with the moving dust cap. Not adding this condition will force the moving mesh to be fixed on the axis.
//    In the Physics toolbar, click Moving Mesh and choose Free Deformation.

    model.component("comp1").common().create("free1", "DeformingDomain");
    model.component("comp1").common("free1").selection().all();

//    In the Settings window for Deforming Domain, locate the Domain Selection section.
//    From the Selection list, select Thermoviscous Acoustic and Moving Mesh.

    model.component("comp1").common("free1").selection().named("sel5");

//    Locate the Smoothing section.
//    From the Mesh smoothing type list, select Laplace.

    model.component("comp1").common("free1").set("smoothingType", "laplace");

//    In the Moving Mesh toolbar, click Symmetry/Roller.

    model.component("comp1").common().create("sym1", "Symmetry");

//    Select Boundaries 3, 6.

    model.component("comp1").common("sym1").selection().set(3, 6);

//    In the model <c>Acoustics_Module/Electroacoustic_Transducers/loudspeaker_driver</c>, it was important to have a finer mesh along the iron surfaces next to the voice coil. The mesh refinement took the skin depth into account, which resolved the eddy currents in the pole and the top plate at higher frequencies.
//    Here, the frequency of the driving voltage is <c>f0 = 70</c> Hz. This gives the skin depth of approximately 0.5 mm, which is comparable to the width of the voice coil. Therefore, the mesh refinement it is not necessary in this case.
//    For the acoustic-structure interaction, the air domain and the thin moving structures also need to be well resolved. 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>. The <l>Extra fine</l> setting gives a maximum element size of 6 mm which is by orders of magnitude smaller than 6 elements per wavelength (80 cm here) slowing down the analysis without adding any relevant information. That is why the model uses a user defined mesh with a very fine mesh around the voice coil and a coarser mesh in the rest of the model. For the structural components, the model uses a <l>Mapped</l> mesh with 2 elements through the thickness. The PML is also preferably meshed with mapped elements; use 8 elements for the default polynomial scaling.
//    In the Mesh toolbar, click Free Triangular.

    model.component("comp1").mesh("mesh1").create("ftri1", "FreeTri");

//    In the Model Builder window, click Size.
//    In the Settings window for Size, 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 15[mm].

    model.component("comp1").mesh("mesh1").feature("size").set("hmax", "15[mm]");

//    In the Minimum element size text field, type 0.10[mm].

    model.component("comp1").mesh("mesh1").feature("size").set("hmin", "0.10[mm]");

//    In the Curvature factor text field, type 0.25.

    model.component("comp1").mesh("mesh1").feature("size").set("hcurve", 0.25);

//    Click Build Selected.

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

//    In the Mesh toolbar, click Mapped.

    model.component("comp1").mesh("mesh1").create("map1", "Map");

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

    model.component("comp1").mesh("mesh1").feature("map1").selection().geom("geom1", 2);

//    Select Domains 4, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20.

    model.component("comp1").mesh("mesh1").feature("map1").selection().set(4, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20);

//    Click to expand the Reduce Element Skewness section.
//    Select the Adjust edge mesh checkbox.

    model.component("comp1").mesh("mesh1").feature("map1").set("adjustedgdistr", true);

//    Right-click Mapped 1 and choose Distribution.

    model.component("comp1").mesh("mesh1").feature("map1").create("dis1", "Distribution");

//    Select Boundaries 20, 32, 35, 39.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis1").selection().set(20, 32, 35, 39);

//    In the Settings window for Distribution, locate the Distribution section.
//    In the Number of elements text field, type 2.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis1").set("numelem", 2);

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

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

//    In the Settings window for Size, locate the Geometric Entity Selection section.
//    Click Clear Selection.

    model.component("comp1").mesh("mesh1").feature("map1").feature("size1").selection().set();

//    Select Domains 10, 15.

    model.component("comp1").mesh("mesh1").feature("map1").feature("size1").selection().set(10, 15);

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

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

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

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

//    In the associated text field, type 0.15[mm].

    model.component("comp1").mesh("mesh1").feature("map1").feature("size1").set("hmax", "0.15[mm]");

//    Right-click Mapped 1 and choose Size.

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

//    In the Settings window for Size, locate the Geometric Entity Selection section.
//    Click Clear Selection.

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

//    Select Domains 13, 16.

    model.component("comp1").mesh("mesh1").feature("map1").feature("size2").selection().set(13, 16);

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

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

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

    model.component("comp1").mesh("mesh1").feature("map1").feature("size2").set("hmaxactive", true);

//    In the associated text field, type 0.7[mm].

    model.component("comp1").mesh("mesh1").feature("map1").feature("size2").set("hmax", "0.7[mm]");

//    Right-click Mapped 1 and choose Size.

    model.component("comp1").mesh("mesh1").feature("map1").create("size3", "Size");

//    In the Settings window for Size, locate the Geometric Entity Selection section.
//    Click Clear Selection.

    model.component("comp1").mesh("mesh1").feature("map1").feature("size3").selection().set();

//    Select Domains 4, 17, 20.

    model.component("comp1").mesh("mesh1").feature("map1").feature("size3").selection().set(4, 17, 20);

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

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

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

    model.component("comp1").mesh("mesh1").feature("map1").feature("size3").set("hmaxactive", true);

//    In the associated text field, type 1.0[mm].

    model.component("comp1").mesh("mesh1").feature("map1").feature("size3").set("hmax", "1.0[mm]");

//    Right-click Mapped 1 and choose Distribution.

    model.component("comp1").mesh("mesh1").feature("map1").create("dis2", "Distribution");

//    Select Boundary 21.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis2").selection().set(21);

//    In the Settings window for Distribution, locate the Distribution section.
//    From the Distribution type list, select Predefined.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis2").set("type", "predefined");

//    In the Number of elements text field, type 20.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis2").set("elemcount", 20);

//    In the Element ratio text field, type 3.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis2").set("elemratio", 3);

//    Right-click Mapped 1 and choose Distribution.

    model.component("comp1").mesh("mesh1").feature("map1").create("dis3", "Distribution");

//    Select Boundary 17.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis3").selection().set(17);

//    In the Settings window for Distribution, locate the Distribution section.
//    From the Distribution type list, select Predefined.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis3").set("type", "predefined");

//    In the Number of elements text field, type 10.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis3").set("elemcount", 10);

//    In the Element ratio text field, type 3.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis3").set("elemratio", 3);

//    Select the Reverse direction checkbox.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis3").set("reverse", true);

//    In the Model Builder window, under Component 1 (comp1) > Mesh 1, click Free Triangular 1.
//    In the Settings window for Free Triangular, locate the Domain Selection section.
//    From the Geometric entity level list, select Domain.

    model.component("comp1").mesh("mesh1").feature("ftri1").selection().geom("geom1", 2);

//    Select Domains 2, 3, 5, 6, 8, 18, 19.

    model.component("comp1").mesh("mesh1").feature("ftri1").selection().set(2, 3, 5, 6, 8, 18, 19);

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

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

//    In the Settings window for Size, locate the Geometric Entity Selection section.
//    Click Clear Selection.

    model.component("comp1").mesh("mesh1").feature("ftri1").feature("size1").selection().set();

//    Select Domains 8, 18, 19.

    model.component("comp1").mesh("mesh1").feature("ftri1").feature("size1").selection().set(8, 18, 19);

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

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

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

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

//    In the associated text field, type 3[mm].

    model.component("comp1").mesh("mesh1").feature("ftri1").feature("size1").set("hmax", "3[mm]");

//    Select the Minimum element size checkbox.

    model.component("comp1").mesh("mesh1").feature("ftri1").feature("size1").set("hminactive", true);

//    In the associated text field, type 0.5[mm].

    model.component("comp1").mesh("mesh1").feature("ftri1").feature("size1").set("hmin", "0.5[mm]");

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

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

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

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

//    Select Boundary 12.

    model.component("comp1").mesh("mesh1").feature("ftri1").feature("size2").selection().set(12);

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

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

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

    model.component("comp1").mesh("mesh1").feature("ftri1").feature("size2").set("hmaxactive", true);

//    In the associated text field, type 1[mm].

    model.component("comp1").mesh("mesh1").feature("ftri1").feature("size2").set("hmax", "1[mm]");

//    Click Build All.

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

//    In the Mesh toolbar, click Mapped.

    model.component("comp1").mesh("mesh1").create("map2", "Map");

//    In the Settings window for Mapped, locate the Reduce Element Skewness section.
//    Select the Adjust edge mesh checkbox.

    model.component("comp1").mesh("mesh1").feature("map2").set("adjustedgdistr", true);

//    Right-click Mapped 2 and choose Distribution.

    model.component("comp1").mesh("mesh1").feature("map2").create("dis1", "Distribution");

//    Select Boundaries 80, 81.

    model.component("comp1").mesh("mesh1").feature("map2").feature("dis1").selection().set(80, 81);

//    In the Settings window for Distribution, locate the Distribution section.
//    In the Number of elements text field, type 8.

    model.component("comp1").mesh("mesh1").feature("map2").feature("dis1").set("numelem", 8);

//    Click Build All.

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

    return model;
  }

  public static Model run3(Model model) {

//    It is time to set up the study that will include the interaction between all physics interfaces present in the model. In the <l>Stationary</l> study step, clear all of the physics interfaces except for the Magnetic Fields.

    model.study("std1").feature("stat").setSolveFor("/physics/solid", false);

//    In the Model Builder window, under Study 1, click Step 1: Stationary.
//    In the Settings window for Stationary, locate the Physics and Variables Selection section.

    model.study("std1").feature("stat").setSolveFor("/frame/spatial1", false);

//    In the Solve for column of the table, under Component 1 (comp1), clear the checkboxes for Solid Mechanics (solid), Moving Mesh.
//    Add a Time Dependent study step which will account for the acoustics-structure interaction and the moving mesh.
//    In the Study toolbar, click Time Dependent.

    model.study("std1").create("time", "Transient");

//    Assume that the transient process reaches the steady state by the time <c>3*T0</c>. Split the time interval into two intervals: form <c>0</c> to <c>3*T0</c> and from <c>3*T0</c> to <c>T_end</c>. In the first one, use a coarser time stepping for the solution storage; in the second one, use a finer time stepping.
//    In the Settings window for Time Dependent, locate the Study Settings section.
//    In the Output times text field, type {range(0, T0/5, 14*T0/5) range(3*T0, T0/50, T_end)}.

    model.study("std1").feature("time").set("tlist", "{range(0, T0/5, 14*T0/5) range(3*T0, T0/50, T_end)}");

//    Click to expand the Study Extensions section.
//    Select the Automatic remeshing checkbox.

    model.study("std1").feature("time").set("autoremesh", true);

//    The <l>Automatic Remeshing</l> option assures that the distortion of the mesh elements will not exceed a certain threshold. As soon as the threshold is reached, the domain will be remeshed.
//    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) > Dependent Variables 2 node, then click Spatial Mesh Displacement (comp1.spatial.disp).
//    In the Settings window for Field, locate the Scaling section.
//    In the Scale text field, type 1e-4.

    model.sol("sol1").feature("v2").feature("comp1_spatial_disp").set("scaleval", "1e-4");

//    Change the Time Stepping Method to <l>BDF</l>, because it is more robust for detecting events necessary when Automatic Remeshing is used in the model.
//    In the Model Builder window, under Study 1 > Solver Configurations > Solution 1 (sol1), click Time-Dependent Solver 1.
//    In the Settings window for Time-Dependent Solver, locate the General section.
//    From the Times to store list, select Output times by interpolation.

    model.sol("sol1").feature("t1").set("tout", "tlist");

//    Click to expand the Time Stepping section.
//    From the Method list, select BDF.

    model.sol("sol1").feature("t1").set("timemethod", "bdf");

//    From the Steps taken by solver list, select Manual.

    model.sol("sol1").feature("t1").set("tstepsbdf", "manual");

//    In the Initial step fraction text field, type 0.5.

    model.sol("sol1").feature("t1").set("initialstepfractionbdf-2", 0.5);

//    In the Initial step growth rate text field, type 1.4.

    model.sol("sol1").feature("t1").set("initialstepgrowthratebdf-2", 1.4);

//    Right-click Study 1 > Solver Configurations > Solution 1 (sol1) > Time-Dependent Solver 1 and choose Fully Coupled.

    model.sol("sol1").feature("t1").create("fc1", "FullyCoupled");

//    In the Model Builder window, expand the Study 1 > Solver Configurations > Solution 1 (sol1) > Time-Dependent Solver 1 node, then click Fully Coupled 1.
//    In the Settings window for Fully Coupled, click to expand the Method and Termination section.
//    From the Nonlinear method list, select Automatic (Newton).

    model.sol("sol1").feature("t1").feature("fc1").set("dtech", "auto");

//    In the Maximum number of iterations text field, type 10.

    model.sol("sol1").feature("t1").feature("fc1").set("maxiter", 10);

//    In the Model Builder window, under Study 1 > Solver Configurations > Solution 1 (sol1) > Time-Dependent Solver 1, click Direct.
//    In the Settings window for Direct, locate the General section.
//    From the Solver list, select PARDISO.

    model.sol("sol1").feature("t1").feature("dDef").set("linsolver", "pardiso");

//    In the Model Builder window, under Study 1 > Solver Configurations > Solution 1 (sol1) > Time-Dependent Solver 1, click Automatic Remeshing.
//    In the Settings window for Automatic Remeshing, locate the Condition for Remeshing section.
//    From the Condition type list, select Distortion.

    model.sol("sol1").feature("t1").feature("arDef").set("stopcondtype", "maxDistortion");

//    In the Stop when distortion exceeds text field, type 2.5.

    model.sol("sol1").feature("t1").feature("arDef").set("maxdistval", "2.5");

//    Locate the Remesh section.
//    Clear the Store solution when new meshes are created checkbox.

    model.sol("sol1").feature("t1").feature("arDef").set("storesolmesh", false);

//    In the Model Builder window, click Study 1.
//    In the Settings window for Study, type Study 1 - Time Dependent Analysis in the Label text field.

    model.study("std1").label("Study 1 - Time Dependent Analysis");

//    In the Study toolbar, click Compute.

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

    model.sol().create("sol3");
    model.sol("sol3").label("Remeshed Solution 1");
    model.sol("sol3").study("std1");
    model.sol("sol1").feature("t1").feature("arDef").set("tadapsol", "sol3");
    model.sol("sol1").runAll();

    model.result().create("pg1", "PlotGroup2D");
    model.result("pg1").label("Magnetic Flux Density (mf)");
    model.result("pg1").set("data", "dset3");
    model.result("pg1").set("frametype", "spatial");
    model.result("pg1").set("showlegendsmaxmin", true);
    model.result("pg1").feature().create("surf1", "Surface");
    model.result("pg1").feature("surf1").set("solutionparams", "parent");
    model.result("pg1").feature("surf1").set("colortable", "Prism");
    model.result("pg1").feature("surf1").set("colortabletrans", "nonlinear");
    model.result("pg1").feature("surf1").set("colorcalibration", -0.8);
    model.result("pg1").feature("surf1").set("evaluationsettings", "parent");
    model.result("pg1").feature("surf1").set("data", "parent");
    model.result("pg1").feature().create("str1", "Streamline");
    model.result("pg1").feature("str1").set("solutionparams", "parent");
    model.result("pg1").feature("str1").set("titletype", "none");
    model.result("pg1").feature("str1").set("posmethod", "uniform");
    model.result("pg1").feature("str1").set("udensity", 2);
    model.result("pg1").feature("str1").set("color", "custom");
    model.result("pg1").feature("str1")
         .set("customcolor", new double[]{0.3764705955982208, 0.3764705955982208, 0.3764705955982208});
    model.result("pg1").feature("str1").set("evaluationsettings", "parent");
    model.result("pg1").feature("str1").set("maxlen", 0.4);
    model.result("pg1").feature("str1").set("maxtime", Double.POSITIVE_INFINITY);
    model.result("pg1").feature("str1").set("inheritcolor", false);
    model.result("pg1").feature("str1").set("maxtime", Double.POSITIVE_INFINITY);
    model.result("pg1").feature("str1").set("data", "parent");
    model.result("pg1").feature("str1").selection().geom("geom1", 1);
    model.result("pg1").feature("str1").selection()
         .set(2, 3, 4, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 30, 31, 32, 33, 34, 35, 36, 37, 38, 40, 42, 43, 44, 45, 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, 74, 75, 78, 83, 84, 89, 90, 91, 92, 94, 95, 96);
    model.result("pg1").feature("str1").set("inheritplot", "surf1");
    model.result("pg1").feature("str1").feature().create("filt1", "Filter");
    model.result("pg1").feature("str1").feature("filt1").set("expr", "!isScalingSystemDomain");
    model.result("pg1").feature().create("con1", "Contour");
    model.result("pg1").feature("con1").set("solutionparams", "parent");
    model.result("pg1").feature("con1").set("expr", "mf.Psi");
    model.result("pg1").feature("con1").set("titletype", "none");
    model.result("pg1").feature("con1").set("number", 10);
    model.result("pg1").feature("con1").set("levelrounding", false);
    model.result("pg1").feature("con1").set("coloring", "uniform");
    model.result("pg1").feature("con1").set("colorlegend", false);
    model.result("pg1").feature("con1").set("color", "custom");
    model.result("pg1").feature("con1")
         .set("customcolor", new double[]{0.3764705955982208, 0.3764705955982208, 0.3764705955982208});
    model.result("pg1").feature("con1").set("evaluationsettings", "parent");
    model.result("pg1").feature("con1").set("inheritcolor", false);
    model.result("pg1").feature("con1").set("data", "parent");
    model.result("pg1").feature("con1").set("inheritplot", "surf1");
    model.result("pg1").feature("con1").feature().create("filt1", "Filter");
    model.result("pg1").feature("con1").feature("filt1").set("expr", "!isScalingSystemDomain");
    model.result().dataset().create("rev1", "Revolve2D");
    model.result().dataset("rev1").set("data", "none");
    model.result().dataset("rev1").set("startangle", -90);
    model.result().dataset("rev1").set("revangle", 225);
    model.result().dataset("rev1").set("data", "dset3");
    model.result().create("pg2", "PlotGroup3D");
    model.result("pg2").label("Magnetic Flux Density, Revolved Geometry (mf)");
    model.result("pg2").set("frametype", "spatial");
    model.result("pg2").set("showlegendsmaxmin", true);
    model.result("pg2").feature().create("vol1", "Volume");
    model.result("pg2").feature("vol1").set("solutionparams", "parent");
    model.result("pg2").feature("vol1").set("colortable", "Prism");
    model.result("pg2").feature("vol1").set("colortabletrans", "nonlinear");
    model.result("pg2").feature("vol1").set("colorcalibration", -0.8);
    model.result("pg2").feature("vol1").set("evaluationsettings", "parent");
    model.result("pg2").feature("vol1").set("data", "parent");
    model.result("pg2").feature().create("con1", "Contour");
    model.result("pg2").feature("con1").set("solutionparams", "parent");
    model.result("pg2").feature("con1").set("expr", "mf.Psi");
    model.result("pg2").feature("con1").set("titletype", "none");
    model.result("pg2").feature("con1").set("number", 10);
    model.result("pg2").feature("con1").set("levelrounding", false);
    model.result("pg2").feature("con1").set("coloring", "uniform");
    model.result("pg2").feature("con1").set("colorlegend", false);
    model.result("pg2").feature("con1").set("color", "custom");
    model.result("pg2").feature("con1")
         .set("customcolor", new double[]{0.3764705955982208, 0.3764705955982208, 0.3764705955982208});
    model.result("pg2").feature("con1").set("evaluationsettings", "parent");
    model.result("pg2").feature("con1").set("inheritcolor", false);
    model.result("pg2").feature("con1").set("data", "parent");
    model.result("pg2").feature("con1").set("inheritplot", "vol1");
    model.result("pg2").feature("con1").feature().create("filt1", "Filter");
    model.result("pg2").feature("con1").feature("filt1").set("expr", "!isScalingSystemDomain");
    model.result().create("pg3", "PlotGroup2D");
    model.result("pg3").set("data", "dset3");
    model.result("pg3").create("surf1", "Surface");
    model.result("pg3").feature("surf1").set("expr", new String[]{"actd.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 (actd)");
    model.result().create("pg4", "PlotGroup3D");
    model.result("pg4").set("data", "rev1");
    model.result("pg4").create("surf1", "Surface");
    model.result("pg4").feature("surf1").set("expr", new String[]{"actd.p_t"});
    model.result("pg4").feature("surf1").set("colortable", "Wave");
    model.result("pg4").feature("surf1").set("colorscalemode", "linearsymmetric");
    model.result("pg4").set("showlegendsunit", true);
    model.result("pg4").label("Acoustic Pressure, 3D (actd)");
    model.result().create("pg5", "PlotGroup2D");
    model.result("pg5").set("data", "dset3");
    model.result("pg5").label("Stress (solid)");
    model.result("pg5").set("frametype", "spatial");
    model.result("pg5").create("surf1", "Surface");
    model.result("pg5").feature("surf1").set("expr", new String[]{"solid.misesGp"});
    model.result("pg5").feature("surf1").set("threshold", "manual");
    model.result("pg5").feature("surf1").set("thresholdvalue", 0.2);
    model.result("pg5").feature("surf1").set("colortable", "Rainbow");
    model.result("pg5").feature("surf1").set("colortabletrans", "none");
    model.result("pg5").feature("surf1").set("colorscalemode", "linear");
    model.result("pg5").feature("surf1").set("resolution", "normal");
    model.result("pg5").feature("surf1").set("refine", 2);
    model.result("pg5").feature("surf1").set("colortable", "Prism");
    model.result().dataset().create("dset3solidrev", "Revolve2D");
    model.result().dataset("dset3solidrev").set("data", "dset3");
    model.result().dataset("dset3solidrev").set("revangle", 225);
    model.result().dataset("dset3solidrev").set("startangle", -90);
    model.result().create("pg6", "PlotGroup3D");
    model.result("pg6").set("data", "dset3solidrev");
    model.result("pg6").label("Stress, 3D (solid)");
    model.result("pg6").set("frametype", "spatial");
    model.result("pg6").create("surf1", "Surface");
    model.result("pg6").feature("surf1").set("expr", new String[]{"solid.misesGp"});
    model.result("pg6").feature("surf1").set("threshold", "manual");
    model.result("pg6").feature("surf1").set("thresholdvalue", 0.2);
    model.result("pg6").feature("surf1").set("colortable", "Rainbow");
    model.result("pg6").feature("surf1").set("colortabletrans", "none");
    model.result("pg6").feature("surf1").set("colorscalemode", "linear");
    model.result("pg6").feature("surf1").set("colortable", "Prism");
    model.result().create("pg7", "PlotGroup2D");
    model.result("pg7").label("Acoustic Pressure (tatd)");
    model.result("pg7").set("data", "dset3");
    model.result("pg7").set("showlegendsunit", true);
    model.result("pg7").feature().create("surf1", "Surface");
    model.result("pg7").feature("surf1").label("Surface");
    model.result("pg7").feature("surf1").set("expr", "tatd.p_t");
    model.result("pg7").feature("surf1").set("colortable", "Wave");
    model.result("pg7").feature("surf1").set("colorscalemode", "linearsymmetric");
    model.result("pg7").feature("surf1").set("smooth", "internal");
    model.result("pg7").feature("surf1").set("data", "parent");
    model.result().create("pg8", "PlotGroup2D");
    model.result("pg8").label("Acoustic Velocity (tatd)");
    model.result("pg8").set("data", "dset3");
    model.result("pg8").set("showlegendsunit", true);
    model.result("pg8").feature().create("surf1", "Surface");
    model.result("pg8").feature("surf1").label("Surface");
    model.result("pg8").feature("surf1").set("expr", "tatd.v_inst");
    model.result("pg8").feature("surf1").set("smooth", "internal");
    model.result("pg8").feature("surf1").set("data", "parent");
    model.result().dataset().create("rev2", "Revolve2D");
    model.result().dataset("rev2").label("Revolution 2D 3");
    model.result().dataset("rev2").set("data", "none");
    model.result().dataset("rev2").set("startangle", -90);
    model.result().dataset("rev2").set("revangle", 225);
    model.result().dataset("rev2").set("data", "dset3");
    model.result().dataset("rev2").selection().geom("geom1", 2);
    model.result().dataset("rev2").selection().set(3, 5);
    model.result().create("pg9", "PlotGroup3D");
    model.result("pg9").label("Temperature Variation (tatd)");
    model.result("pg9").set("data", "rev2");
    model.result("pg9").set("showlegendsunit", true);
    model.result("pg9").feature().create("surf1", "Surface");
    model.result("pg9").feature("surf1").label("Surface");
    model.result("pg9").feature("surf1").set("expr", "tatd.T_t");
    model.result("pg9").feature("surf1").set("colortable", "ThermalWave");
    model.result("pg9").feature("surf1").set("colorscalemode", "linearsymmetric");
    model.result("pg9").feature("surf1").set("smooth", "internal");
    model.result("pg9").feature("surf1").set("data", "parent");
    model.result().create("pg10", "PlotGroup2D");
    model.result("pg10").set("data", "dset3");
    model.result("pg10").label("Moving Mesh");
    model.result("pg10").create("mesh1", "Mesh");
    model.result("pg10").feature("mesh1").set("meshdomain", "surface");
    model.result("pg10").feature("mesh1").set("colortable", "TrafficFlow");
    model.result("pg10").feature("mesh1").set("colortabletrans", "nonlinear");
    model.result("pg10").feature("mesh1").set("nonlinearcolortablerev", true);
    model.result("pg10").feature("mesh1").create("sel1", "MeshSelection");
    model.result("pg10").feature("mesh1").feature("sel1").selection()
         .set(3, 4, 5, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20);
    model.result("pg10").feature("mesh1").set("qualmeasure", "custom");
    model.result("pg10").feature("mesh1").set("qualexpr", "comp1.spatial.relVol");
    model.result("pg10").feature("mesh1").set("colorrangeunitinterval", false);
    model.result("pg1").run();

//    Plot the magnetic field in the voice coil air gap. It is clearly seen that the voice coil has moved down from its initial position. Use the <l>Zoom Box</l> to zoom in on the magnetic gap.
//    In the Settings window for 2D Plot Group, click to expand the Title section.
//    From the Title type list, select Manual.

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

//    In the Title text area, type Magnetic Flux Density Norm.

    model.result("pg1").set("title", "Magnetic Flux Density Norm");

//    In the Parameter indicator text field, type t = eval(t) s.

    model.result("pg1").set("paramindicator", "t = eval(t) s");

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

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

//    Locate the Plot Settings section.
//    From the View list, select New view.

    model.result("pg1").set("view", "new");

//    In the Magnetic Flux Density (mf) toolbar, click Plot.

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

//    In the Model Builder window, expand the Magnetic Flux Density (mf) node.
//    In the Model Builder window, under Results > Magnetic Flux Density (mf), Ctrl-click to select Streamline 1, Contour 1.
//    Right-click and choose Disable.

    model.result("pg1").feature("str1").active(false);
    model.result("pg1").feature("con1").active(false);
    model.result("pg1").run();

//    In the Model Builder window, right-click Magnetic Flux Density (mf) and choose Streamline.

    model.result("pg1").create("str2", "Streamline");
    model.result("pg1").feature("str2").set("evaluationsettings", "parent");

//    In the Settings window for Streamline, locate the Selection section.
//    Click Paste Selection.
//    In the Paste Selection dialog, type 43 in the Selection text field.
//    Click OK.

    model.result("pg1").feature("str2").selection().set(43);

//    In the Settings window for Streamline, locate the Coloring and Style section.
//    Find the Point style subsection.
//    From the Color list, select Gray.

    model.result("pg1").feature("str2").set("color", "gray");

//    In the Magnetic Flux Density (mf) toolbar, click Plot.

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

//    In the Model Builder window, under Results, click Acoustic Pressure (actd).
//    In the Settings window for 2D Plot Group, locate the Title section.
//    From the Title type list, select Manual.

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

//    In the Title text area, type Acoustic pressure, Time = eval(t) s.

    model.result("pg3").set("title", "Acoustic pressure, Time = eval(t) s");

//    Clear the Parameter indicator text field.

    model.result("pg3").set("paramindicator", "");

//    From the Number format list, select Automatic.

    model.result("pg3").set("titlenumberformat", "auto");

//    Locate the Plot Settings section.
//    From the Frame list, select Spatial (r, phi, z).

    model.result("pg3").set("frametype", "spatial");
    model.result("pg3").run();

//    In the Model Builder window, expand the Acoustic Pressure (actd) node, then click Surface 1.
//    In the Settings window for Surface, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Multiphysics > atb1.p_t - Total acoustic pressure - Pa.

    model.result("pg3").feature("surf1").set("expr", "atb1.p_t");
    model.result("pg3").feature("surf1").set("descr", "Total acoustic pressure");

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

    model.result("pg3").feature("surf1").set("rangecoloractive", true);

//    In the Minimum text field, type -150.

    model.result("pg3").feature("surf1").set("rangecolormin", -150);

//    In the Maximum text field, type 150.

    model.result("pg3").feature("surf1").set("rangecolormax", 150);

//    Right-click Surface 1 and choose Selection.

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

//    Select Domains 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.

    model.result("pg3").feature("surf1").feature("sel1").selection()
         .set(2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);

//    Select all domains except the PML region where the solution is unphysical. Simply select all domains (you can use Ctrl+A) and then deselect the two PML domains (domains 1 and 6).
//    In the Acoustic Pressure (actd) toolbar, click Plot.

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

//    Plot the acoustic pressure at the listening point over the time interval <c>[3*T0, T_end]</c>.

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

//    In the Model Builder window, under Results, click Acoustic Velocity (tatd).
//    In the Settings window for 2D Plot Group, locate the Plot Settings section.
//    From the Frame list, select Spatial (r, phi, z).

    model.result("pg8").set("frametype", "spatial");

//    In the Acoustic Velocity (tatd) toolbar, click Plot.

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

//    Look at the plot of the acoustic velocity, notice the no-slip behavior in the magnetic air gap.
//    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 Pressure at Listening Point in the Label text field.

    model.result("pg11").label("Pressure at Listening Point");

//    Locate the Data section.
//    From the Dataset list, select Study 1 - Time Dependent Analysis/Remeshed Solution 1 (sol3).

    model.result("pg11").set("data", "dset3");

//    From the Time selection list, select Interpolated.

    model.result("pg11").setIndex("looplevelinput", "interp", 0);

//    In the Times (s) text field, type range(3*T0, T0/50, T_end).

    model.result("pg11").setIndex("interp", "range(3*T0, T0/50, T_end)", 0);

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

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

//    Right-click Pressure at Listening Point and choose Point Graph.

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

//    Select Point 7.

    model.result("pg11").feature("ptgr1").selection().set(7);

//    In the Settings window for Point Graph, locate the y-Axis Data section.
//    In the Expression text field, type p.

    model.result("pg11").feature("ptgr1").set("expr", "p");

//    In the Pressure at Listening Point toolbar, click Plot.

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

//    It is seen that the shape of the signal slightly differs from a perfectly sinusoidal one. That is, its THD is different from 0. The instruction below will help you to do the frequency spectrum analysis of the signal and calculate its THD.
//    In the Results toolbar, click Point Evaluation.

    model.result().numerical().create("pev1", "EvalPoint");

//    In the Settings window for Point Evaluation, type Pressure at Point in the Label text field.

    model.result().numerical("pev1").label("Pressure at Point");

//    Locate the Data section.
//    From the Dataset list, select Study 1 - Time Dependent Analysis/Remeshed Solution 1 (sol3).

    model.result().numerical("pev1").set("data", "dset3");

//    From the Time selection list, select Interpolated.

    model.result().numerical("pev1").setIndex("looplevelinput", "interp", 0);

//    In the Times (s) text field, type range(3*T0, T0/50, T_end).

    model.result().numerical("pev1").setIndex("interp", "range(3*T0, T0/50, T_end)", 0);

//    Select Point 7.

    model.result().numerical("pev1").selection().set(7);

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

    model.result().numerical("pev1").setIndex("expr", "p", 0);
    model.result().numerical("pev1").setIndex("unit", "Pa", 0);
    model.result().numerical("pev1").setIndex("descr", "Pressure", 0);

//    Click ^ next to Evaluate then choose New Table.

    model.result().table().create("tbl1", "Table");
    model.result().table("tbl1").comments("Pressure at Point");
    model.result().numerical("pev1").set("table", "tbl1");
    model.result().numerical("pev1").setResult();

//    In the Model Builder window, expand the Results > Tables node, then click Table 1.
//    In the Settings window for Table, type Pressure at Point in the Label text field.

    model.result().table("tbl1").label("Pressure at Point");

//    Make an Interpolation and a Periodic Extension of the pressure at the listening point.
//    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 Result table.

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

//    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 s.

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

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

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

//    In the Unit text field, type Pa.

    model.func("int1").setIndex("fununit", "Pa", 0);

//    Locate the Interpolation and Extrapolation section.
//    From the Interpolation list, select Cubic spline.

    model.func("int1").set("interp", "cubicspline");

//    From the Extrapolation list, select Nearest function.

    model.func("int1").set("extrap", "interior");

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

    model.func().create("an1", "Analytic");

//    In the Settings window for Analytic, type p_periodic in the Function name text field.

    model.func("an1").set("funcname", "p_periodic");

//    Locate the Definition section.
//    In the Expression text field, type p_point(t).

    model.func("an1").set("expr", "p_point(t)");

//    In the Arguments text field, type t.

    model.func("an1").set("args", "t");

//    Click to expand the Periodic Extension section.
//    Select the Make periodic checkbox.

    model.func("an1").set("periodic", true);

//    In the Lower limit text field, type 3*T0.

    model.func("an1").set("periodiclower", "3*T0");

//    In the Upper limit text field, type 4*T0.

    model.func("an1").set("periodicupper", "4*T0");

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

    model.func("an1").setIndex("argunit", "s", 0);

//    In the Function text field, type Pa.

    model.func("an1").set("fununit", "Pa");

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

    model.func("an1").setIndex("plotargs", "4*T0", 0, 2);

//    Click Plot.
//    Now, set up the components necessary to analyze the frequency spectrum and the THD of the acoustic pressure in steady state.
//    In the Model Builder window, right-click the root node and choose Add Component > 0D.

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

//    In the Home toolbar, click Add Physics to open the Add Physics window.
//    In the tree, select Mathematics > ODE and DAE Interfaces > Global ODEs and DAEs (ge).
//    Find the Physics interfaces in study subsection.
//    In the table, enter the following settings:
//    Click Add to Component 2 in the window toolbar.

    model.component("comp2").physics().create("ge", "GlobalEquations");

    model.study("std1").feature("stat").setSolveFor("/physics/ge", false);
    model.study("std1").feature("time").setSolveFor("/physics/ge", false);

    model.component("comp2").physics("ge").prop("EquationForm").set("form", "Automatic");

//    In the Home toolbar, click Add Physics to close the Add Physics window.
//    In the Settings window for Global Equations, locate the Global Equations section.
//    In the table, enter the following settings:

    model.component("comp2").physics("ge").feature("ge1").setIndex("name", "P", 0, 0);
    model.component("comp2").physics("ge").feature("ge1").setIndex("equation", "P - p_periodic(t)", 0, 0);

//    Locate the Units section.
//    Click Select Dependent Variable Quantity.
//    In the Physical Quantity dialog, type id:pressure in the text field.
//    In the tree, select General > Pressure (Pa).
//    Click OK.

    model.component("comp2").physics("ge").feature("ge1").set("DependentVariableQuantity", "pressure");

//    In the Settings window for Global Equations, locate the Units section.
//    Click Select Source Term Quantity.
//    In the Physical Quantity dialog, type id:pressure in the text field.
//    In the tree, select General > Pressure (Pa).
//    Click OK.

    model.component("comp2").physics("ge").feature("ge1").set("SourceTermQuantity", "pressure");

//    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 > Time Dependent.
//    Click Add Study in the window toolbar.

    model.study().create("std2");
    model.study("std2").create("time", "Transient");

//    In the Home toolbar, click Add Study to close the Add Study window.
//    The Interpolation and the Periodic Extension performed earlier make it possible to increase the time interval and refine the time stepping for a more accurate frequency spectrum calculation.
//    In the Settings window for Time Dependent, locate the Study Settings section.
//    In the Output times text field, type range(0, T0/200, 10*T0).

    model.study("std2").feature("time").set("tlist", "range(0, T0/200, 10*T0)");
    model.study("std2").feature("time").setSolveFor("/modelNode/comp1", false);

//    Locate the Physics and Variables Selection section.
//    In the Solve for column of the table, clear the checkbox for Component 1 (comp1).
//    In the Study toolbar, click More Study Steps and choose Frequency Domain > Time to Frequency FFT.

    model.study("std2").create("tffft", "TimeToFreqFFT");

//    In the Settings window for Time to Frequency FFT, locate the Study Settings section.

    return model;
  }

  public static Model run4(Model model) {
//    In the End time text field, type 10*T0.

    model.study("std2").feature("tffft").set("fftendtime", "10*T0");

//    In the Maximum output frequency text field, type 10*f0.

    model.study("std2").feature("tffft").set("fftmaxfreq", "10*f0");
    model.study("std2").feature("tffft").setSolveFor("/modelNode/comp1", false);

//    Locate the Physics and Variables Selection section.
//    In the Solve for column of the table, clear the checkbox for Component 1 (comp1).
//    In the Model Builder window, click Study 2.
//    In the Settings window for Study, type Study 2 - Periodic Signal Extraction and FFT in the Label text field.

    model.study("std2").label("Study 2 - Periodic Signal Extraction and FFT");

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

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

//    Generate the default solver and then modify the <l>Time Stepping</l> to get minimal numerical damping. Manual time-stepping is used with a time step that resolves the wave nature of the problem.
//    In the Study toolbar, click Show Default Solver.

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

//    In the Model Builder window, expand the Solution 4 (sol4) node, then click Time-Dependent Solver 1.
//    In the Settings window for Time-Dependent Solver, click to expand the Time Stepping section.
//    From the Method list, select Generalized alpha.

    model.sol("sol4").feature("t1").set("timemethod", "genalpha");

//    From the Steps taken by solver list, select Manual.

    model.sol("sol4").feature("t1").set("tstepsgenalpha", "manual");

//    In the Time step text field, type 1/(6*f0)/60.

    model.sol("sol4").feature("t1").set("timestepgenalpha", "1/(6*f0)/60");

//    In the Study toolbar, click Compute.

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

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

//    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 SPL at Listening Point, FFT in the Label text field.

    model.result("pg12").label("SPL at Listening Point, FFT");

//    Locate the Data section.
//    From the Dataset list, select Study 2 - Periodic Signal Extraction and FFT/Solution 4 (4) (sol4).

    model.result("pg12").set("data", "dset4");

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

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

//     and select all but the first four frequency parameters.

    model.result("pg12")
         .setIndex("looplevel", new int[]{5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 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, 44, 45, 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}, 0);

//    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 Frequency (Hz).

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

//    Select the y-axis label checkbox.

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

//    In the associated text field, type Sound Pressure Level (dB).

    model.result("pg12").set("ylabel", "Sound Pressure Level (dB)");

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

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

//    Right-click SPL at Listening Point, FFT and choose More Plots > Octave Band.

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

//    Locate the y-Axis Data section.
//    In the Expression text field, type comp2.P.

    model.result("pg12").feature("oct1").set("expr", "comp2.P");

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

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

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

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

//    Select the Show legends checkbox.

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

//    In the table, enter the following settings:

    model.result("pg12").feature("oct1").setIndex("legends", "Continuous PSD", 0);
    model.result("pg12").run();

//    In the Model Builder window, click SPL at Listening Point, FFT.
//    In the SPL at Listening Point, FFT toolbar, click More Plots and choose Octave Band.

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

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

    model.result("pg12").feature("oct2").selection().geom("geom1");

//    Locate the y-Axis Data section.
//    In the Expression text field, type comp2.P.

    model.result("pg12").feature("oct2").set("expr", "comp2.P");

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

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

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

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

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

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

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

    model.result("pg12").feature("oct2").set("legendmethod", "manual");

//    Select the Show legends checkbox.

    model.result("pg12").feature("oct2").set("legend", true);

//    In the table, enter the following settings:

    model.result("pg12").feature("oct2").setIndex("legends", "1/3 octave bands (PSD)", 0);
    model.result("pg12").run();

//    In the Model Builder window, right-click Results > SPL at Listening Point, FFT > Octave Band 1 and choose Duplicate.

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

//    In the Settings window for Octave Band, locate the Data section.
//    From the Dataset list, select Study 2 - Periodic Signal Extraction and FFT/Solution 4 (4) (sol4).

    model.result("pg12").feature("oct3").set("data", "dset4");

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

    model.result("pg12").feature("oct3").setIndex("looplevelinput", "manualindices", 0);

//    In the Parameter indices (1-101) text field, type range(11, 10, 101).

    model.result("pg12").feature("oct3").setIndex("looplevelindices", "range(11, 10, 101)", 0);

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

    model.result("pg12").feature("oct3").set("linestyle", "none");

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

    model.result("pg12").feature("oct3").set("linemarker", "circle");

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

    model.result("pg12").feature("oct3").set("legend", false);

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

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

//    In the Settings window for Graph Marker, locate the Display section.
//    From the Scope list, select Local.

    model.result("pg12").feature("oct3").feature("gmrk1").set("scope", "local");

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

    model.result("pg12").feature("oct3").feature("gmrk1").set("precision", 4);

//    Select the Include unit checkbox.

    model.result("pg12").feature("oct3").feature("gmrk1").set("includeunit", true);

//    In the SPL at Listening Point, FFT toolbar, click Plot.

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

//    For the THD calculation, pick up the pressure at the frequencies that are multiples of <c>f0</c>.
//    In the Results toolbar, click Global Evaluation.

    model.result().numerical().create("gev1", "EvalGlobal");

//    In the Settings window for Global Evaluation, type THD Evaluation in the Label text field.

    model.result().numerical("gev1").label("THD Evaluation");

//    Locate the Data section.
//    From the Dataset list, select Study 2 - Periodic Signal Extraction and FFT/Solution 4 (4) (sol4).

    model.result().numerical("gev1").set("data", "dset4");

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

    model.result().numerical("gev1").setIndex("looplevelinput", "first", 0);

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

    model.result().numerical("gev1")
         .setIndex("expr", "sqrt(sum(with(11 + 10*k, abs(comp2.P)^2), k, 1, 9))/with(11, abs(comp2.P))", 0);
    model.result().numerical("gev1").setIndex("unit", 1, 0);
    model.result().numerical("gev1").setIndex("descr", "THD", 0);

//    Click Evaluate.

    model.result().table().create("tbl2", "Table");
    model.result().table("tbl2").comments("THD Evaluation");
    model.result().numerical("gev1").set("table", "tbl2");
    model.result().numerical("gev1").setResult();

//    Next, calculate the coil power and the dynamic BL force factor.
//    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 Coil Power in the Label text field.

    model.result("pg13").label("Coil Power");

//    Locate the Data section.
//    From the Dataset list, select Study 1 - Time Dependent Analysis/Remeshed Solution 1 (sol3).

    model.result("pg13").set("data", "dset3");

//    From the Time selection list, select Interpolated.

    model.result("pg13").setIndex("looplevelinput", "interp", 0);

//    In the Times (s) text field, type range(3*T0, T0/50, T_end).

    model.result("pg13").setIndex("interp", "range(3*T0, T0/50, T_end)", 0);

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

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

//    Right-click Coil Power and choose Global.

    model.result("pg13").create("glob1", "Global");
    model.result("pg13").feature("glob1").set("markerpos", "datapoints");
    model.result("pg13").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) > Magnetic Fields > Coil parameters > mf.PCoil_1 - Coil power - W.

    model.result("pg13").feature("glob1").set("expr", new String[]{"mf.PCoil_1"});
    model.result("pg13").feature("glob1").set("descr", new String[]{"Coil power"});
    model.result("pg13").feature("glob1").set("unit", new String[]{"W"});

//    In the Coil Power toolbar, click Plot.

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

//    This expression corresponds to the <eqv>z</eqv>-coordinate of the voice coil center relative to its position at the time <eqv>t = 0</eqv>.
//    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 Dynamic BL Force Factor in the Label text field.

    model.result("pg14").label("Dynamic BL Force Factor");

//    Locate the Data section.
//    From the Dataset list, select Study 1 - Time Dependent Analysis/Remeshed Solution 1 (sol3).

    model.result("pg14").set("data", "dset3");

//    From the Time selection list, select Interpolated.

    model.result("pg14").setIndex("looplevelinput", "interp", 0);

//    In the Times (s) text field, type range(3*T0, T0/50, T_end).

    model.result("pg14").setIndex("interp", "range(3*T0, T0/50, T_end)", 0);

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

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

//    In the Title text area, type Dynamic BL Force Factor vs. Relative Position of the Voice Coil.

    model.result("pg14").set("title", "Dynamic BL Force Factor vs. Relative Position of the Voice Coil");

//    Right-click Dynamic BL Force Factor 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", "aveop1(-mf.Br*N0*2*pi*r)", 0);
    model.result("pg14").feature("glob1").setIndex("unit", "T*m", 0);
    model.result("pg14").feature("glob1").setIndex("descr", "Dynamic Bl force factor", 0);

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

    model.result("pg14").feature("glob1").set("xdata", "expr");

//    In the Expression text field, type aveop1(z - Z).

    model.result("pg14").feature("glob1").set("xdataexpr", "aveop1(z - Z)");

//    Select the Description checkbox.

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

//    In the associated text field, type Relative position of the coil.

    model.result("pg14").feature("glob1").set("xdatadescr", "Relative position of the coil");

//    In the Dynamic BL Force Factor toolbar, click Plot.

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

    model.title("Loudspeaker Driver \u2014 Transient Analysis");

    model
         .description("This model presents a full transient analysis of a loudspeaker driver, which allows the modeling of nonlinear effects. It extends the linear frequency-domain analysis done in the Loudspeaker Driver tutorial model.\n\nThe analysis accounts for nonlinear behavior of the soft iron in the magnetic system, geometric nonlinearities in the structures, and nonlinear effects due to the topology change when the voice coil is moving in and out of the magnetic gap. The model uses the moving mesh feature and automatic remeshing to capture the topology changes and the movement of the voice coil.\n\nThe output includes the total harmonic distortion (THD) and the dynamic BL curve. The model also describes how to calculate the intermodulation distortion (IMD).\n\nThe model requires the Acoustics Module and the AC/DC Module.");

    return model;
  }

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

}
