/*
 * acoustic_cloaking.java
 */

import com.comsol.model.*;
import com.comsol.model.util.*;

/** Model exported on May 15 2026, 10:29 by COMSOL 6.4.0.421. */
public class acoustic_cloaking {

  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.
//    In the Select Physics tree, select Acoustics > Pressure Acoustics > Pressure Acoustics, Frequency Domain (acpr).
//    Click Add.
//    Click Study.
//    In the Select Study tree, select General Studies > Frequency Domain.
//    Click Done.

    model.component().create("comp1", true);

    model.component("comp1").geom().create("geom1", 2);

    model.component("comp1").mesh().create("mesh1");

    model.component("comp1").physics().create("acpr", "PressureAcoustics", "geom1");

    model.study().create("std1");
    model.study("std1").create("freq", "Frequency");

//    The geometry of this model is simple but a bit repetitive to create, due to the large number of circles involved. You will therefore import a geometry sequence from a file. The instructions for building the geometry can be found in the appendix at the end of this document.
//    In the Geometry toolbar, click Insert Sequence and choose Insert Sequence.

    model.component("comp1").geom("geom1").insertFile("acoustic_cloaking_geom_sequence.mph", "geom1");

//    Browse to the model's Application Library folder and double-click the file acoustic_cloaking_geom_sequence.mph.
//    In the Geometry toolbar, click Build All.

    model.component("comp1").geom("geom1").run("boxsel10");

//    Click the Zoom Extents button in the Graphics toolbar.
//    The file you have just imported contains a few parameters that are used to generate the geometry. Now proceed to add some additional parameters that will be used in the analysis.
//    In the Model Builder window, under Global Definitions, click Parameters 1.
//    In the Settings window for Parameters, locate the Parameters section.
//    In the table, enter the following settings:

    model.param().set("rhob", "1.25[kg/m^3]");
    model.param().descr("rhob", "Density, background material");
    model.param().set("cb", "343[m/s]");
    model.param().descr("cb", "Speed of sound, background material");
    model.param().set("f0", "300[Hz]");
    model.param().descr("f0", "Frequency of the analysis");
    model.param().set("lam0", "cb/f0");
    model.param().descr("lam0", "Wavelength");

//    The material properties in the cloaking involve dependencies on the inner and outer radius, the local distance from the center, and the properties of the surrounding background fluid. It is convenient to define these expressions as variables.
//    In the Definitions toolbar, click Coordinate Systems and choose Cylindrical System.

    model.component("comp1").coordSystem().create("sys2", "Cylindrical");

//    In the Settings window for Cylindrical System, locate the Settings section.
//    Find the Origin subsection.
//    In the table, enter the following settings:

    model.component("comp1").coordSystem("sys2").setIndex("origin", "x1", 0);
    model.component("comp1").coordSystem("sys2").setIndex("origin", "y1", 1);

//    In the Model Builder window, right-click Definitions and choose Variables.

    model.component("comp1").variable().create("var1");

//    In the Settings window for Variables, type Radial Coordinate: Homogenized Cloak in the Label text field.

    model.component("comp1").variable("var1").label("Radial Coordinate: Homogenized Cloak");

//    Locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Domain.

    model.component("comp1").variable("var1").selection().geom("geom1", 2);

//    From the Selection list, select Selection: Homogenized Cloak.

    model.component("comp1").variable("var1").selection().named("geom1_sel3");

//    Locate the Variables section.
//    In the table, enter the following settings:

    model.component("comp1").variable("var1").set("r", "sys2.r");
    model.component("comp1").variable("var1").descr("r", "Radial coordinate");

//    Right-click Definitions and choose Variables.

    model.component("comp1").variable().create("var2");

//    In the Settings window for Variables, type Radial Coordinate: 50 Layer Cloak in the Label text field.

    model.component("comp1").variable("var2").label("Radial Coordinate: 50 Layer Cloak");

//    Locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Domain.

    model.component("comp1").variable("var2").selection().geom("geom1", 2);

//    From the Selection list, select Selection: 50 Layer Cloak.

    model.component("comp1").variable("var2").selection().named("geom1_boxsel1");

//    Locate the Variables section.
//    In the table, enter the following settings:

    model.component("comp1").variable("var2").set("r", "sqrt((x-x3)^2+(y-y3)^2)", "Radial coordinate");

//    Right-click Definitions and choose Variables.

    model.component("comp1").variable().create("var3");

//    In the Settings window for Variables, type Radial Coordinate: 20 Layer Cloak in the Label text field.

    model.component("comp1").variable("var3").label("Radial Coordinate: 20 Layer Cloak");

//    Locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Domain.

    model.component("comp1").variable("var3").selection().geom("geom1", 2);

//    From the Selection list, select Selection: 20 Layer Cloak.

    model.component("comp1").variable("var3").selection().named("geom1_boxsel2");

//    Locate the Variables section.
//    In the table, enter the following settings:

    model.component("comp1").variable("var3").set("r", "sqrt((x-x4)^2+(y-y4)^2)", "Radial coordinate");

//    In the Definitions toolbar, click Local Variables.

    model.component("comp1").variable().create("var4");

//    In the Settings window for Variables, type Variables: Acoustic Cloak Data in the Label text field.

    model.component("comp1").variable("var4").label("Variables: Acoustic Cloak Data");

//    Locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Domain.

    model.component("comp1").variable("var4").selection().geom("geom1", 2);

//    From the Selection list, select Selection: Acoustic Cloak.

    model.component("comp1").variable("var4").selection().named("geom1_unisel1");

//    Locate the Variables section.
//    In the table, enter the following settings:

    model.component("comp1").variable("var4").set("rho1", "rhob*(r+sqrt(2*r*R1-R1^2))/(r-R1)");
    model.component("comp1").variable("var4").descr("rho1", "Density, Material 1");
    model.component("comp1").variable("var4").set("c1", "cb*(R2-R1)/R2*r/(r-R1)");
    model.component("comp1").variable("var4").descr("c1", "Speed of sound, Material 1");
    model.component("comp1").variable("var4").set("rho2", "rhob^2/rho1");
    model.component("comp1").variable("var4").descr("rho2", "Density, Material 2");
    model.component("comp1").variable("var4").set("c2", "c1");
    model.component("comp1").variable("var4").descr("c2", "Speed of sound, Material 2");
    model.component("comp1").variable("var4").set("K1", "rho1*c1^2");
    model.component("comp1").variable("var4").descr("K1", "Bulk modulus, Material 1");
    model.component("comp1").variable("var4").set("K2", "rho2*c2^2");
    model.component("comp1").variable("var4").descr("K2", "Bulk modulus, Material 2");
    model.component("comp1").variable("var4").set("K", "2*K1*K2/(K1+K2)");
    model.component("comp1").variable("var4").descr("K", "Effective bulk modulus");
    model.component("comp1").variable("var4").set("rho_tangential", "2*rho1*rho2/(rho1+rho2)");
    model.component("comp1").variable("var4").descr("rho_tangential", "Density along layers");
    model.component("comp1").variable("var4").set("rho_normal", "(rho1+rho2)/2");
    model.component("comp1").variable("var4").descr("rho_normal", "Density perpendicular to the layers");

//    Now, proceed to add the materials. Material 1 and Material 2 are the two materials with varying properties that will be used in the layers to create an acoustic cloak. The homogenized material is an anisotropic material which properties also vary with thickness and are equivalent to a model with a large number of layers.
//    In the Model Builder window, right-click Component 1 (comp1) > Materials and choose Blank Material.

    model.component("comp1").material().create("mat1", "Common");

//    In the Settings window for Material, type Air in the Label text field.

    model.component("comp1").material("mat1").label("Air");

//    Locate the Material Contents section.
//    In the table, enter the following settings:

    model.component("comp1").material("mat1").propertyGroup("def").set("density", new String[]{"rhob"});
    model.component("comp1").material("mat1").propertyGroup("def").set("soundspeed", new String[]{"cb"});

//    Right-click Materials and choose Blank Material.

    model.component("comp1").material().create("mat2", "Common");

//    In the Settings window for Material, type Material 1 in the Label text field.

    model.component("comp1").material("mat2").label("Material 1");

//    Locate the Geometric Entity Selection section.
//    From the Selection list, select Selection: Material 1.

    model.component("comp1").material("mat2").selection().named("geom1_sel1");

//    Locate the Material Contents section.
//    In the table, enter the following settings:

    model.component("comp1").material("mat2").propertyGroup("def").set("density", new String[]{"rho1"});
    model.component("comp1").material("mat2").propertyGroup("def").set("soundspeed", new String[]{"c1"});

//    Right-click Materials and choose Blank Material.

    model.component("comp1").material().create("mat3", "Common");

//    In the Settings window for Material, type Material 2 in the Label text field.

    model.component("comp1").material("mat3").label("Material 2");

//    Locate the Geometric Entity Selection section.
//    From the Selection list, select Selection: Material 2.

    model.component("comp1").material("mat3").selection().named("geom1_sel2");

//    Locate the Material Contents section.
//    In the table, enter the following settings:

    model.component("comp1").material("mat3").propertyGroup("def").set("density", new String[]{"rho2"});
    model.component("comp1").material("mat3").propertyGroup("def").set("soundspeed", new String[]{"c2"});

//    Right-click Materials and choose Blank Material.

    model.component("comp1").material().create("mat4", "Common");

//    In the Settings window for Material, type Homogenized Material in the Label text field.

    model.component("comp1").material("mat4").label("Homogenized Material");

//    Locate the Geometric Entity Selection section.
//    From the Selection list, select Selection: Homogenized Cloak.

    model.component("comp1").material("mat4").selection().named("geom1_sel3");

//    Click to expand the Material Properties section.
//    In the Material properties tree, select Acoustics > Anisotropic Acoustics Model > Effective bulk modulus (K_eff).
//    Click Add to Material.

    model.component("comp1").material("mat4").propertyGroup()
         .create("AnisotropicAcousticsModel", "AnisotropicAcousticsModel", "Anisotropic_acoustics_model");

//    In the Material properties tree, select Acoustics > Anisotropic Acoustics Model > Effective density (rho_eff).
//    Locate the Material Contents section.
//    In the table, enter the following settings:

    model.component("comp1").material("mat4").propertyGroup("AnisotropicAcousticsModel")
         .set("rho_eff", new String[]{"rho_normal", "rho_tangential", "rho_tangential"});
    model.component("comp1").material("mat4").propertyGroup("AnisotropicAcousticsModel")
         .set("K_eff", new String[]{"K"});

//    The homogenized material has a diagonal density matrix with terms that change value with the radius. The bulk modulus also varies with the radius.
//    In the Model Builder window, right-click Component 1 (comp1) > Pressure Acoustics, Frequency Domain (acpr) and choose Node Group.

    model.nodeGroup().create("grp1", "Physics", "acpr");

//    In the Settings window for Group, type Homogenized Model in the Label text field.

    model.nodeGroup("grp1").label("Homogenized Model");

//    The outer boundaries need a radiation condition to make sure that no waves are reflected at this interface.
//    In the Physics toolbar, click Boundaries and choose Cylindrical Wave Radiation.

    model.component("comp1").physics("acpr").create("cwr1", "CylindricalWaveRadiation", 1);

    model.nodeGroup("grp1").add("cwr1");

//    Select Boundary 154.

    model.component("comp1").physics("acpr").feature("cwr1").selection().set(154);

//    In the Settings window for Cylindrical Wave Radiation, locate the Cylindrical Wave Radiation section.
//    Specify the \[\mathbf{r}_0\] vector as

    model.component("comp1").physics("acpr").feature("cwr1").set("r0", new String[]{"x1", "y1", "0"});

//    Now, proceed to add a <l>Background Pressure Field</l> for each of the geometries. The field is a plane wave propagating in the <l>x</l> direction. The phase of this field is updated on each of the domains to make sure that the incident acoustic field is the same in all the domains.
//    In the Physics toolbar, click Domains and choose Background Pressure Field.

    model.component("comp1").physics("acpr").create("bpf1", "BackgroundPressureField", 2);

    model.nodeGroup("grp1").add("bpf1");

//    In the Settings window for Background Pressure Field, locate the Domain Selection section.
//    From the Selection list, select Selection: Homogenized Cloak Domain.

    model.component("comp1").physics("acpr").feature("bpf1").selection().named("geom1_boxsel7");

//    Locate the Background Pressure Field section.
//    In the \[p_0\] text field, type 1.

    model.component("comp1").physics("acpr").feature("bpf1").set("pamp", 1);

//    From the \[c\] list, select From material.

    model.component("comp1").physics("acpr").feature("bpf1").set("c_mat", "from_mat");

//    From the Material list, select Air (mat1).

    model.component("comp1").physics("acpr").feature("bpf1").set("PressureFieldMaterial", "mat1");

//    In the \[\phi\] text field, type acpr.bpf1.k*x1.

    model.component("comp1").physics("acpr").feature("bpf1").set("phi", "acpr.bpf1.k*x1");

//    In the Physics toolbar, click Boundaries and choose Symmetry.

    model.component("comp1").physics("acpr").create("sym1", "Symmetry", 1);

    model.nodeGroup("grp1").add("sym1");

//    In the Settings window for Symmetry, locate the Boundary Selection section.
//    From the Selection list, select Selection: Symmetry Boundaries, Homogenized Cloak.

    model.component("comp1").physics("acpr").feature("sym1").selection().named("geom1_boxsel3");

//    In the Physics toolbar, click Domains and choose Anisotropic Acoustics.

    model.component("comp1").physics("acpr").create("aam1", "AnisotropicAcousticsModel", 2);

    model.nodeGroup("grp1").add("aam1");

//    Select Domain 4.

    model.component("comp1").physics("acpr").feature("aam1").selection().set(4);

//    In the Settings window for Anisotropic Acoustics, locate the Coordinate System Selection section.
//    From the Coordinate system list, select Cylindrical System 2 (sys2).

    model.component("comp1").physics("acpr").feature("aam1").set("coordinateSystem", "sys2");

//    In the Model Builder window, right-click Pressure Acoustics, Frequency Domain (acpr) and choose Node Group.

    model.nodeGroup().create("grp2", "Physics", "acpr");

//    In the Settings window for Group, type No Cloak Model in the Label text field.

    model.nodeGroup("grp2").label("No Cloak Model");

//    In the Physics toolbar, click Boundaries and choose Cylindrical Wave Radiation.

    model.component("comp1").physics("acpr").create("cwr2", "CylindricalWaveRadiation", 1);

    model.nodeGroup("grp2").add("cwr2");

//    Select Boundary 209.

    model.component("comp1").physics("acpr").feature("cwr2").selection().set(209);

//    In the Settings window for Cylindrical Wave Radiation, locate the Cylindrical Wave Radiation section.
//    Specify the \[\mathbf{r}_0\] vector as

    model.component("comp1").physics("acpr").feature("cwr2").set("r0", new String[]{"x2", "y2", "0"});

//    In the Physics toolbar, click Domains and choose Background Pressure Field.

    model.component("comp1").physics("acpr").create("bpf2", "BackgroundPressureField", 2);

    model.nodeGroup("grp2").add("bpf2");

//    In the Settings window for Background Pressure Field, locate the Domain Selection section.
//    From the Selection list, select Selection: No Cloak Domain.

    model.component("comp1").physics("acpr").feature("bpf2").selection().named("geom1_boxsel8");

//    Locate the Background Pressure Field section.
//    In the \[p_0\] text field, type 1.

    model.component("comp1").physics("acpr").feature("bpf2").set("pamp", 1);

//    From the \[c\] list, select From material.

    model.component("comp1").physics("acpr").feature("bpf2").set("c_mat", "from_mat");

//    In the \[\phi\] text field, type acpr.bpf2.k*x2.

    model.component("comp1").physics("acpr").feature("bpf2").set("phi", "acpr.bpf2.k*x2");

//    In the Physics toolbar, click Boundaries and choose Symmetry.

    model.component("comp1").physics("acpr").create("sym2", "Symmetry", 1);

    model.nodeGroup("grp2").add("sym2");

//    In the Settings window for Symmetry, locate the Boundary Selection section.
//    From the Selection list, select Selection: Symmetry Boundaries, No Cloak.

    model.component("comp1").physics("acpr").feature("sym2").selection().named("geom1_boxsel4");

//    Right-click Pressure Acoustics, Frequency Domain (acpr) and choose Node Group.

    model.nodeGroup().create("grp3", "Physics", "acpr");

//    In the Settings window for Group, type 50 Layer Cloak Model in the Label text field.

    model.nodeGroup("grp3").label("50 Layer Cloak Model");

//    In the Physics toolbar, click Boundaries and choose Cylindrical Wave Radiation.

    model.component("comp1").physics("acpr").create("cwr3", "CylindricalWaveRadiation", 1);

    model.nodeGroup("grp3").add("cwr3");

//    Select Boundary 153.

    model.component("comp1").physics("acpr").feature("cwr3").selection().set(153);

//    In the Settings window for Cylindrical Wave Radiation, locate the Cylindrical Wave Radiation section.
//    Specify the \[\mathbf{r}_0\] vector as

    model.component("comp1").physics("acpr").feature("cwr3").set("r0", new String[]{"x3", "y3", "0"});

//    In the Physics toolbar, click Domains and choose Background Pressure Field.

    model.component("comp1").physics("acpr").create("bpf3", "BackgroundPressureField", 2);

    model.nodeGroup("grp3").add("bpf3");

//    In the Settings window for Background Pressure Field, locate the Domain Selection section.
//    From the Selection list, select Selection: 50 Layer Cloak Domain.

    model.component("comp1").physics("acpr").feature("bpf3").selection().named("geom1_boxsel9");

//    Locate the Background Pressure Field section.
//    In the \[p_0\] text field, type 1.

    model.component("comp1").physics("acpr").feature("bpf3").set("pamp", 1);

//    From the \[c\] list, select From material.

    model.component("comp1").physics("acpr").feature("bpf3").set("c_mat", "from_mat");

//    In the \[\phi\] text field, type acpr.bpf3.k*x3.

    model.component("comp1").physics("acpr").feature("bpf3").set("phi", "acpr.bpf3.k*x3");

//    In the Physics toolbar, click Boundaries and choose Symmetry.

    model.component("comp1").physics("acpr").create("sym3", "Symmetry", 1);

    model.nodeGroup("grp3").add("sym3");

//    In the Settings window for Symmetry, locate the Boundary Selection section.
//    From the Selection list, select Selection: Symmetry Boundaries, 50 Layer Cloak.

    model.component("comp1").physics("acpr").feature("sym3").selection().named("geom1_boxsel5");

//    Right-click Pressure Acoustics, Frequency Domain (acpr) and choose Node Group.

    model.nodeGroup().create("grp4", "Physics", "acpr");

//    In the Settings window for Group, type 20 Layer Cloak Model in the Label text field.

    model.nodeGroup("grp4").label("20 Layer Cloak Model");

//    In the Physics toolbar, click Boundaries and choose Cylindrical Wave Radiation.

    model.component("comp1").physics("acpr").create("cwr4", "CylindricalWaveRadiation", 1);

    model.nodeGroup("grp4").add("cwr4");

//    Select Boundary 208.

    model.component("comp1").physics("acpr").feature("cwr4").selection().set(208);

//    In the Settings window for Cylindrical Wave Radiation, locate the Cylindrical Wave Radiation section.
//    Specify the \[\mathbf{r}_0\] vector as

    model.component("comp1").physics("acpr").feature("cwr4").set("r0", new String[]{"x4", "y4", "0"});

//    In the Physics toolbar, click Domains and choose Background Pressure Field.

    model.component("comp1").physics("acpr").create("bpf4", "BackgroundPressureField", 2);

    model.nodeGroup("grp4").add("bpf4");

//    In the Settings window for Background Pressure Field, locate the Domain Selection section.
//    From the Selection list, select Selection: 20 Layer Cloak Domain.

    model.component("comp1").physics("acpr").feature("bpf4").selection().named("geom1_boxsel10");

//    Locate the Background Pressure Field section.
//    In the \[p_0\] text field, type 1.

    model.component("comp1").physics("acpr").feature("bpf4").set("pamp", 1);

//    From the \[c\] list, select From material.

    model.component("comp1").physics("acpr").feature("bpf4").set("c_mat", "from_mat");

//    In the \[\phi\] text field, type acpr.bpf4.k*x4.

    model.component("comp1").physics("acpr").feature("bpf4").set("phi", "acpr.bpf4.k*x4");

//    In the Physics toolbar, click Boundaries and choose Symmetry.

    model.component("comp1").physics("acpr").create("sym4", "Symmetry", 1);

    model.nodeGroup("grp4").add("sym4");

//    In the Settings window for Symmetry, locate the Boundary Selection section.
//    From the Selection list, select Selection: Symmetry Boundaries, 20 Layer Cloak.

    model.component("comp1").physics("acpr").feature("sym4").selection().named("geom1_boxsel6");

//    In this model, the mesh is set up manually. Proceed by directly adding the desired mesh component.
//    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 lam0/6.

    model.component("comp1").mesh("mesh1").feature("size").set("hmax", "lam0/6");

//    In general, five to six 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>. This model uses six elements per wavelength.
//    Click Build Selected.

    model.component("comp1").mesh("mesh1").run("size");

//    Add a mapped mesh in the acoustic cloak domains. As the domains have properties that change with the radius, it is a good idea to keep a structured mesh with elements along the varying direction.
//    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);

//    From the Selection list, select Selection: Acoustic Cloak.

    model.component("comp1").mesh("mesh1").feature("map1").selection().named("geom1_unisel1");

//    Since the variation of properties is more pronounced toward the inner center of the acoustic cloak, add a skewed distribution to make sure that the mesh is sufficiently fine throughout the domain.
//    Right-click Mapped 1 and choose Distribution.

    model.component("comp1").mesh("mesh1").feature("map1").create("dis1", "Distribution");

//    Select Boundary 4.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis1").selection().set(4);

//    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("dis1").set("type", "predefined");

//    In the Number of elements text field, type 20.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis1").set("elemcount", 20);

//    In the Element ratio text field, type 4.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis1").set("elemratio", 4);

//    The same distribution should be applied to the other edge of the domain, but with the reverse direction.
//    In the Model Builder window, right-click Mapped 1 and choose Distribution.

    model.component("comp1").mesh("mesh1").feature("map1").create("dis2", "Distribution");

//    Select Boundary 55.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis2").selection().set(55);

//    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 4.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis2").set("elemratio", 4);

//    Select the Reverse direction checkbox.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis2").set("reverse", true);

//    Right-click Mapped 1 and choose Distribution.

    model.component("comp1").mesh("mesh1").feature("map1").create("dis3", "Distribution");

//    Select Boundary 156.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis3").selection().set(156);

//    In the Settings window for Distribution, locate the Distribution section.
//    In the Number of elements text field, type 40.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis3").set("numelem", 40);

//    In the Model Builder window, right-click Mesh 1 and choose Build All.

    model.component("comp1").mesh("mesh1").run();

//    The mesh should look like this.
//    In the Model Builder window, under Study 1, click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Study Settings section.
//    In the Frequencies text field, type f0.

    model.study("std1").feature("freq").set("plist", "f0");

//    In the Study toolbar, click Compute.

    model.study("std1").createAutoSequences("all");

    model.sol("sol1").runAll();

    model.result().create("pg1", "PlotGroup2D");
    model.result("pg1").set("data", "dset1");
    model.result("pg1").setIndex("looplevel", 1, 0);
    model.result("pg1").create("surf1", "Surface");
    model.result("pg1").feature("surf1").set("expr", new String[]{"acpr.p_t"});
    model.result("pg1").feature("surf1").set("colortable", "Wave");
    model.result("pg1").feature("surf1").set("colorscalemode", "linearsymmetric");
    model.result("pg1").set("showlegendsunit", true);
    model.result("pg1").label("Acoustic Pressure (acpr)");
    model.result().create("pg2", "PlotGroup2D");
    model.result("pg2").set("data", "dset1");
    model.result("pg2").setIndex("looplevel", 1, 0);
    model.result("pg2").create("surf1", "Surface");
    model.result("pg2").feature("surf1").set("expr", new String[]{"acpr.Lp_t"});
    model.result("pg2").feature("surf1").set("colortable", "Rainbow");
    model.result("pg2").feature("surf1").set("colorscalemode", "linear");
    model.result("pg2").set("showlegendsunit", true);
    model.result("pg2").label("Sound Pressure Level (acpr)");
    model.result("pg1").run();

//    The following steps will update the default plots to include a cleaner view of the model with annotations of the different cloaks.
//    In the Settings window for 2D Plot Group, type Total Acoustic Pressure (acpr) in the Label text field.

    model.result("pg1").label("Total Acoustic Pressure (acpr)");

//    Locate the Plot Settings section.
//    Clear the Plot dataset edges checkbox.

    model.result("pg1").set("edges", false);

//    Right-click Total Acoustic Pressure (acpr) and choose Line.

    model.result("pg1").create("line1", "Line");
    model.result("pg1").feature("line1").set("evaluationsettings", "parent");

//    In the Settings window for Line, locate the Expression section.
//    In the Expression text field, type 0.

    model.result("pg1").feature("line1").set("expr", "0");

//    Click to expand the Title section.
//    From the Title type list, select None.

    model.result("pg1").feature("line1").set("titletype", "none");

//    Locate the Coloring and Style section.
//    From the Coloring list, select Uniform.

    model.result("pg1").feature("line1").set("coloring", "uniform");

//    From the Color list, select Black.

    model.result("pg1").feature("line1").set("color", "black");

//    Right-click Line 1 and choose Selection.

    model.result("pg1").feature("line1").create("sel1", "Selection");

//    Select Boundaries 1, 2, 105, 106, 107, 108, 151, 152, 153, 154, 155, 156, 208, 209, 210, 211.

    model.result("pg1").feature("line1").feature("sel1").selection()
         .set(1, 2, 105, 106, 107, 108, 151, 152, 153, 154, 155, 156, 208, 209, 210, 211);

//    In the Total Acoustic Pressure (acpr) toolbar, click Plot.

    model.result("pg1").run();
    model.result("pg1").run();

//    In the Model Builder window, under Results, click Total Acoustic Pressure (acpr).
//    In the Total Acoustic Pressure (acpr) toolbar, click More Plots and choose Table Annotation.

    model.result("pg1").create("tlan1", "TableAnnotation");

//    In the Settings window for Table Annotation, locate the Data section.
//    From the Source list, select Local table.

    model.result("pg1").feature("tlan1").set("source", "localtable");

//    In the table, enter the following settings:

    model.result("pg1").feature("tlan1").setIndex("localtablematrix", "x1", 0, 0);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", "y1+4.3[m]", 0, 1);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", "Homogenized cloak", 0, 2);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", "x2", 1, 0);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", "y2+4.3[m]", 1, 1);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", "No cloak", 1, 2);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", "x3", 2, 0);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", "y3+4.3[m]", 2, 1);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", "50 Layer cloak", 2, 2);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", "x4", 3, 0);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", "y4+4.3[m]", 3, 1);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", "20 Layer cloak", 3, 2);

//    Locate the Coloring and Style section.
//    Clear the Show point checkbox.

    model.result("pg1").feature("tlan1").set("showpoint", false);

//    From the Anchor point list, select Center.

    model.result("pg1").feature("tlan1").set("anchorpoint", "center");

//    In the Total Acoustic Pressure (acpr) toolbar, click Plot.

    return model;
  }

  public static Model run2(Model model) {

    model.result("pg1").run();

//    Click the Zoom Extents button in the Graphics toolbar.

    model.result("pg1").run();

//    In the Model Builder window, click Total Acoustic Pressure (acpr).
//    In the Total Acoustic Pressure (acpr) toolbar, click Plot.

    model.result("pg1").run();
    model.result("pg2").run();

//    In the Model Builder window, right-click Sound Pressure Level (acpr) and choose Delete.

    model.result().remove("pg2");

//    Remove the default Sound Pressure Level plot and duplicate the Total Acoustic Pressure plot created previously. Doing this, you make sure that the annotations will be carried over to the new plots.

    model.result("pg1").run();

//    In the Model Builder window, right-click Total Acoustic Pressure (acpr) and choose Duplicate.

    model.result().duplicate("pg2", "pg1");
    model.result("pg2").run();

//    In the Settings window for 2D Plot Group, type Total Sound Pressure Level (acpr) in the Label text field.

    model.result("pg2").label("Total Sound Pressure Level (acpr)");
    model.result("pg2").run();

//    In the Model Builder window, expand the Total Sound Pressure Level (acpr) node, then click Surface 1.
//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type acpr.Lp_t.

    model.result("pg2").feature("surf1").set("expr", "acpr.Lp_t");

//    Locate the Coloring and Style section.
//    From the Color table list, select Rainbow.

    model.result("pg2").feature("surf1").set("colortable", "Rainbow");

//    From the Scale list, select Linear.

    model.result("pg2").feature("surf1").set("colorscalemode", "linear");

//    In the Total Sound Pressure Level (acpr) toolbar, click Plot.

    model.result("pg2").run();
    model.result("pg2").run();

//    In the Model Builder window, right-click Total Sound Pressure Level (acpr) and choose Duplicate.

    model.result().duplicate("pg3", "pg2");
    model.result("pg3").run();

//    In the Settings window for 2D Plot Group, type Scattered Sound Pressure Level (acpr) in the Label text field.

    model.result("pg3").label("Scattered Sound Pressure Level (acpr)");
    model.result("pg3").run();

//    In the Model Builder window, expand the Scattered Sound Pressure Level (acpr) node, then click Surface 1.
//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type acpr.Lp_s.

    model.result("pg3").feature("surf1").set("expr", "acpr.Lp_s");

//    Right-click Surface 1 and choose Selection.

    model.result("pg3").feature("surf1").create("sel1", "Selection");

//    Select Domains 1, 2, 54, 55.

    model.result("pg3").feature("surf1").feature("sel1").selection().set(1, 2, 54, 55);

//    In the Scattered Sound Pressure Level (acpr) toolbar, click Plot.

    model.result("pg3").run();

//    In the Results toolbar, click 2D Plot Group.

    model.result().create("pg4", "PlotGroup2D");
    model.result("pg4").run();

//    In the Settings window for 2D Plot Group, type Effective Speed of Sound in Principal Directions in the Label text field.

    model.result("pg4").label("Effective Speed of Sound in Principal Directions");

//    Click to expand the Selection section.
//    From the Geometric entity level list, select Domain.

    model.result("pg4").selection().geom("geom1", 2);

//    Select Domain 4.

    model.result("pg4").selection().geom("geom1", 2);
    model.result("pg4").selection().set(4);

//    Locate the Plot Settings section.
//    From the View list, select New view.

    model.result("pg4").set("view", "new");

//     to create a dedicated view for this plot.
//    Locate the Selection section.
//    Select the Apply to dataset edges checkbox.

    model.result("pg4").set("applyselectiontodatasetedges", true);

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Effective Speed of Sound in Principal Directions toolbar, click Plot.

    model.result("pg4").run();

//    Click to expand the Title section.
//    From the Title type list, select Label.

    model.result("pg4").set("titletype", "label");

//    In the Effective Speed of Sound in Principal Directions toolbar, click More Plots and choose Principal Stress Surface.

    model.result("pg4").create("pris1", "PrincipalSurface");

//    In the Settings window for Principal Stress Surface, locate the Principal Components section.
//    Find the Principal values subsection.
//    In row Value, set Second to 0.

    model.result("pg4").feature("pris1").setIndex("princvalstressexpr", 0, 0, 1);

//    In row Value, set Third to 0.5.

    model.result("pg4").feature("pris1").setIndex("princvalstressexpr", 0.5, 0, 2);

//    Find the Principal directions subsection.
//    In row X, set First to acpr.c_eff1x+acpr.c_eff2x.

    model.result("pg4").feature("pris1").setIndex("princdirstressexpr", "acpr.c_eff1x+acpr.c_eff2x", 0, 0);

//    In row Y, set First to acpr.c_eff1y+acpr.c_eff2y.

    model.result("pg4").feature("pris1").setIndex("princdirstressexpr", "acpr.c_eff1y+acpr.c_eff2y", 1, 0);

//    In row Y, set Second to 0.

    model.result("pg4").feature("pris1").setIndex("princdirstressexpr", 0, 1, 1);

//    In row X, set Third to acpr.c_eff3x.

    model.result("pg4").feature("pris1").setIndex("princdirstressexpr", "acpr.c_eff3x", 0, 2);

//    In row Y, set Third to acpr.c_eff3y.

    model.result("pg4").feature("pris1").setIndex("princdirstressexpr", "acpr.c_eff3y", 1, 2);

//    In row Z, set Third to 0.

    model.result("pg4").feature("pris1").setIndex("princdirstressexpr", 0, 2, 2);

//    The first and second effective speeds of sound are identical in magnitude, but one of them is perpendicular to the plane. Both terms are added to the first direction so that the arrows are consistent.
//    In the Effective Speed of Sound in Principal Directions toolbar, click Plot.

    model.result("pg4").run();

//    The plot should look like this.
//    In the Home toolbar, click Add Plot Group and choose 1D Plot Group.

    model.result().create("pg5", "PlotGroup1D");
    model.result("pg5").run();

//    In the Settings window for 1D Plot Group, type Total Acoustic Pressure Along Cloak Boundary in the Label text field.

    model.result("pg5").label("Total Acoustic Pressure Along Cloak Boundary");

//    Click to expand the Title section.
//    From the Title type list, select Label.

    model.result("pg5").set("titletype", "label");

//    Locate the Plot Settings section.
//    Select the y-axis label checkbox.

    model.result("pg5").set("ylabelactive", true);

//    In the associated text field, type Pressure (Pa).

    model.result("pg5").set("ylabel", "Pressure (Pa)");

//    Right-click Total Acoustic Pressure Along Cloak Boundary and choose Line Graph.

    model.result("pg5").create("lngr1", "LineGraph");
    model.result("pg5").feature("lngr1").set("markerpos", "datapoints");
    model.result("pg5").feature("lngr1").set("linewidth", "preference");
    model.result("pg5").feature("lngr1").set("evaluationsettings", "parent");

//    Select Boundary 156.

    model.result("pg5").feature("lngr1").selection().set(156);

//    In the Settings window for Line Graph, locate the y-Axis Data section.
//    In the Expression text field, type acpr.p_b.

    model.result("pg5").feature("lngr1").set("expr", "acpr.p_b");

//    Click to expand the Title section.
//    From the Title type list, select None.

    model.result("pg5").feature("lngr1").set("titletype", "none");

//    Click to expand the Legends section.
//    Select the Show legends checkbox.

    model.result("pg5").feature("lngr1").set("legend", true);

//    From the Legends list, select Manual.

    model.result("pg5").feature("lngr1").set("legendmethod", "manual");

//    In the table, enter the following settings:

    model.result("pg5").feature("lngr1").setIndex("legends", "Background pressure field", 0);

//    Click to expand the Coloring and Style section.
//    Find the Line markers subsection.
//    From the Marker list, select Circle.

    model.result("pg5").feature("lngr1").set("linemarker", "circle");

//    From the Positioning list, select Interpolated.

    model.result("pg5").feature("lngr1").set("markerpos", "interp");

//    In the Number text field, type 100.

    model.result("pg5").feature("lngr1").set("markers", 100);

//    In the Total Acoustic Pressure Along Cloak Boundary toolbar, click Plot.

    model.result("pg5").run();

//    Right-click Line Graph 1 and choose Duplicate.

    model.result("pg5").feature().duplicate("lngr2", "lngr1");
    model.result("pg5").run();

//    In the Settings window for Line Graph, locate the y-Axis Data section.
//    In the Expression text field, type acpr.p_t.

    model.result("pg5").feature("lngr2").set("expr", "acpr.p_t");

//    Locate the Coloring and Style section.
//    Find the Line markers subsection.
//    From the Marker list, select None.

    model.result("pg5").feature("lngr2").set("linemarker", "none");

//    Locate the Legends section.
//    In the table, enter the following settings:

    model.result("pg5").feature("lngr2").setIndex("legends", "Homogenized cloak model", 0);

//    Right-click Line Graph 2 and choose Duplicate.

    model.result("pg5").feature().duplicate("lngr3", "lngr2");
    model.result("pg5").run();

//    In the Settings window for Line Graph, locate the Selection section.
//    Click Clear Selection.

    model.result("pg5").feature("lngr3").selection().set();

//    Select Boundary 155.

    model.result("pg5").feature("lngr3").selection().set(155);

//    Locate the Legends section.
//    In the table, enter the following settings:

    model.result("pg5").feature("lngr3").setIndex("legends", "50 layer cloak model", 0);

//    Right-click Line Graph 3 and choose Duplicate.

    model.result("pg5").feature().duplicate("lngr4", "lngr3");
    model.result("pg5").run();

//    In the Settings window for Line Graph, locate the Selection section.
//    Click Clear Selection.

    model.result("pg5").feature("lngr4").selection().set();

//    Select Boundary 210.

    model.result("pg5").feature("lngr4").selection().set(210);

//    Locate the Legends section.
//    In the table, enter the following settings:

    model.result("pg5").feature("lngr4").setIndex("legends", "20 layer cloak model", 0);

//    In the Total Acoustic Pressure Along Cloak Boundary toolbar, click Plot.

    model.result("pg5").run();

//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg6", "PlotGroup1D");
    model.result("pg6").run();

//    In the Settings window for 1D Plot Group, type Speed of Sound in Homogenized Material in the Label text field.

    model.result("pg6").label("Speed of Sound in Homogenized Material");

//    Locate the Title section.
//    From the Title type list, select Label.

    model.result("pg6").set("titletype", "label");

//    Locate the Plot Settings section.
//    Select the y-axis label checkbox.

    model.result("pg6").set("ylabelactive", true);

//    In the associated text field, type Speed of sound (m/s).

    model.result("pg6").set("ylabel", "Speed of sound (m/s)");

//    Right-click Speed of Sound in Homogenized Material and choose Line Graph.

    model.result("pg6").create("lngr1", "LineGraph");
    model.result("pg6").feature("lngr1").set("markerpos", "datapoints");
    model.result("pg6").feature("lngr1").set("linewidth", "preference");
    model.result("pg6").feature("lngr1").set("evaluationsettings", "parent");

//    Select Boundary 55.

    model.result("pg6").feature("lngr1").selection().set(55);

//    In the Settings window for Line Graph, locate the y-Axis Data section.
//    In the Expression text field, type acpr.c_eff1.

    model.result("pg6").feature("lngr1").set("expr", "acpr.c_eff1");

//    Locate the x-Axis Data section.
//    From the Parameter list, select Expression.

    model.result("pg6").feature("lngr1").set("xdata", "expr");

//    In the Expression text field, type x.

    model.result("pg6").feature("lngr1").set("xdataexpr", "x");

//    Locate the Legends section.
//    Select the Show legends checkbox.

    model.result("pg6").feature("lngr1").set("legend", true);

//    Find the Include subsection.
//    Clear the Solution checkbox.

    model.result("pg6").feature("lngr1").set("autosolution", false);

//    Select the Description checkbox.

    model.result("pg6").feature("lngr1").set("autodescr", true);

//    Right-click Line Graph 1 and choose Duplicate.

    model.result("pg6").feature().duplicate("lngr2", "lngr1");
    model.result("pg6").run();

//    In the Settings window for Line Graph, locate the y-Axis Data section.
//    In the Expression text field, type acpr.c_eff3.

    model.result("pg6").feature("lngr2").set("expr", "acpr.c_eff3");

//    Click the y-Axis Log Scale button in the Graphics toolbar.

    model.result("pg6").set("ylog", true);

//    In the Speed of Sound in Homogenized Material toolbar, click Plot.

    model.result("pg6").run();
    model.result("pg1").set("applyselectiontodatasetedges", false);
    model.result("pg1").run();

    model.title("Acoustic Cloaking");

    model
         .description("This example demonstrates how to use a background field in a sound scattering problem. The application is an acoustic invisibility cloak made of a metamaterial. Two different types of metamaterials are used, one using an anisotropic acoustic material with varying properties and one using two layered materials with varying properties. Thanks to its space-dependent material properties and layered structure, both types of metamaterials are almost transparent to an incident plane pressure wave.");

    return model;
  }

  public static void main(String[] args) {
    Model model = run();
    run2(model);
  }

}
