/*
 * phononic_crystal.java
 */

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

/** Model exported on May 14 2026, 09:58 by COMSOL 6.4.0.420. */
public class phononic_crystal {

  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 Structural Mechanics > Solid Mechanics (solid).
//    Click Add.
//    Click Study.
//    In the Select Study tree, select General Studies > Eigenfrequency.
//    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("solid", "SolidMechanics", "geom1");

    model.study().create("std1");
    model.study("std1").create("eig", "Eigenfrequency");
    model.study("std1").feature("eig").set("storefact", false);
    model.study("std1").feature("eig").set("solnum", "auto");
    model.study("std1").feature("eig").set("notsolnum", "auto");
    model.study("std1").feature("eig").set("outputmap", new String[]{});
    model.study("std1").feature("eig").set("ngenAUX", "1");
    model.study("std1").feature("eig").set("goalngenAUX", "1");
    model.study("std1").feature("eig").set("ngenAUX", "1");
    model.study("std1").feature("eig").set("goalngenAUX", "1");

    model.component("comp1").common().create("mpf1", "ParticipationFactors");

//    In the Model Builder window, right-click Global Definitions and choose Geometry Parts > 2D Part.

    model.geom().create("part1", "Part", 2);

//    In the Geometry toolbar, click Square.

    model.geom("part1").create("sq1", "Square");

//    In the Settings window for Square, click to expand the Layers section.
//    In the table, enter the following settings:

    model.geom("part1").feature("sq1").setIndex("layer", 0.25, 0);

//    Select the Layers to the left checkbox.

    model.geom("part1").feature("sq1").set("layerleft", true);

//    Select the Layers to the right checkbox.

    model.geom("part1").feature("sq1").set("layerright", true);

//    Select the Layers on top checkbox.

    model.geom("part1").feature("sq1").set("layertop", true);

//    Click Build Selected.

    model.geom("part1").run("sq1");

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

    model.geom("part1").create("del1", "Delete");

//    In the Settings window for Delete Entities, locate the Entities or Objects to Delete section.
//    From the Geometric entity level list, select Domain.

    model.geom("part1").feature("del1").selection("input").init(2);

//    On the object sq1, select Domain 5.

    model.geom("part1").feature("del1").selection("input").set("sq1", 5);

//    In the Geometry toolbar, click Build All.

    model.geom("part1").run("del1");

//    In the Geometry toolbar, click Part Instance and choose Part 1.

    model.component("comp1").geom("geom1").create("pi1", "PartInstance");
    model.component("comp1").geom("geom1").feature("pi1").set("selkeepnoncontr", false);
    model.component("comp1").geom("geom1").feature("pi1").set("part", "part1");

//    In the Settings window for Part Instance, click Build All Objects.

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

//    In the Model Builder window, right-click Global Definitions > Materials and choose Blank Material.

    model.material().create("mat1", "Common", "");

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

    model.material("mat1").label("Aluminum");

//    Click to expand the Material Properties section.
//    In the Material properties tree, select Basic Properties > Density.
//    Click Add to Material.

    model.material("mat1").propertyGroup("def").set("density", "");

//    In the Material properties tree, select Basic Properties > Poisson's Ratio.
//    Click Add to Material.

    model.material("mat1").propertyGroup("def").set("poissonsratio", "");

//    In the Material properties tree, select Basic Properties > Young's Modulus.
//    Click Add to Material.

    model.material("mat1").propertyGroup("def").set("youngsmodulus", "");

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

    model.material("mat1").propertyGroup("def").set("density", new String[]{"2700[kg/m^3]"});
    model.material("mat1").propertyGroup("def").set("poissonsratio", new String[]{"0.3"});
    model.material("mat1").propertyGroup("def").set("youngsmodulus", new String[]{"69.9[GPa]"});

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

//    In the Model Builder window, right-click Component 1 (comp1) > Materials and choose More Materials > Material Link.

    model.component("comp1").material().create("matlnk1", "Link");

//    In the Settings window for Parameters, locate the Parameters section.
//    In the table, enter the following settings:

    model.param().set("P", "1");
    model.param().descr("P", "Sweep parameter");

//    In the Physics toolbar, click Boundaries and choose Periodic Condition.

    model.component("comp1").physics("solid").create("pc1", "PeriodicCondition", 1);

//    Select Boundaries 1, 3, 5, 22, 23, 24.

    model.component("comp1").physics("solid").feature("pc1").selection().set(1, 3, 5, 22, 23, 24);

//    In the Settings window for Periodic Condition, locate the Periodicity Settings section.
//    From the Type of periodicity list, select Floquet periodicity.

    model.component("comp1").physics("solid").feature("pc1").set("PeriodicType", "Floquet");

//    Specify the \[\mathbf{k}_{\textrm{F}}\] vector as

    model.component("comp1").physics("solid").feature("pc1").set("kFloquet", new String[]{"P*pi", "0", "0"});

//    Right-click Periodic Condition 1 and choose Duplicate.

    model.component("comp1").physics("solid").feature().duplicate("pc2", "pc1");

//    In the Settings window for Periodic Condition, locate the Boundary Selection section.
//    Click Clear Selection.

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

//    Select Boundaries 2, 7, 9, 14, 16, 21.

    model.component("comp1").physics("solid").feature("pc2").selection().set(2, 7, 9, 14, 16, 21);

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

    model.component("comp1").cpl().create("intop1", "Integration");
    model.component("comp1").cpl("intop1").set("axisym", true);

//    Click the Select All button in the Graphics toolbar.

    model.component("comp1").cpl("intop1").selection().set(1, 2, 3, 4, 5, 6, 7, 8);

//    In the Mesh toolbar, click Mapped.

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

//    In the Model Builder window, click Size.
//    In the Settings window for Size, locate the Element Size section.
//    From the Predefined list, select Coarse.

    model.component("comp1").mesh("mesh1").feature("size").set("hauto", 6);

//    In the Model Builder window, click Study 1.
//    In the Settings window for Study, type Infinite Crystal in the Label text field.

    model.study("std1").label("Infinite Crystal");

//    In the Model Builder window, under Infinite Crystal, click Step 1: Eigenfrequency.
//    In the Settings window for Eigenfrequency, click to expand the Study Extensions section.
//    Select the Auxiliary sweep checkbox.

    model.study("std1").feature("eig").set("useparam", true);

//    Click Add.

    model.study("std1").feature("eig").setIndex("pname", "P", 0);
    model.study("std1").feature("eig").setIndex("plistarr", "", 0);
    model.study("std1").feature("eig").setIndex("punit", "", 0);
    model.study("std1").feature("eig").setIndex("pname", "P", 0);
    model.study("std1").feature("eig").setIndex("plistarr", "", 0);
    model.study("std1").feature("eig").setIndex("punit", "", 0);

//    In the table, enter the following settings:

    model.study("std1").feature("eig").setIndex("plistarr", "range(0,0.02,1)", 0);

//    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", 6, 0);
    model.result("pg1").setIndex("looplevel", 51, 1);
    model.result("pg1").label("Mode Shape (solid)");
    model.result("pg1").set("showlegends", false);
    model.result("pg1").create("surf1", "Surface");
    model.result("pg1").feature("surf1").set("expr", new String[]{"solid.disp"});
    model.result("pg1").feature("surf1").set("threshold", "manual");
    model.result("pg1").feature("surf1").set("thresholdvalue", 0.2);
    model.result("pg1").feature("surf1").set("colortable", "Rainbow");
    model.result("pg1").feature("surf1").set("colortabletrans", "none");
    model.result("pg1").feature("surf1").set("colorscalemode", "linear");
    model.result("pg1").feature("surf1").set("colortable", "AuroraBorealis");
    model.result("pg1").feature("surf1").create("def", "Deform");
    model.result("pg1").feature("surf1").feature("def").set("expr", new String[]{"u", "v"});
    model.result("pg1").feature("surf1").feature("def").set("descr", "Displacement field");
    model.result().evaluationGroup().create("std1EvgFrq", "EvaluationGroup");
    model.result().evaluationGroup("std1EvgFrq").set("data", "dset1");
    model.result().evaluationGroup("std1EvgFrq").label("Eigenfrequencies (Infinite Crystal)");
    model.result().evaluationGroup("std1EvgFrq").create("gev1", "EvalGlobal");
    model.result().evaluationGroup("std1EvgFrq").feature("gev1").setIndex("expr", "2*pi*freq", 0);
    model.result().evaluationGroup("std1EvgFrq").feature("gev1").setIndex("unit", "rad/s", 0);
    model.result().evaluationGroup("std1EvgFrq").feature("gev1").setIndex("descr", "Angular frequency", 0);
    model.result().evaluationGroup("std1EvgFrq").feature("gev1").setIndex("expr", "imag(freq)/abs(freq)", 1);
    model.result().evaluationGroup("std1EvgFrq").feature("gev1").setIndex("unit", "1", 1);
    model.result().evaluationGroup("std1EvgFrq").feature("gev1").setIndex("descr", "Damping ratio", 1);
    model.result().evaluationGroup("std1EvgFrq").feature("gev1").setIndex("expr", "abs(freq)/imag(freq)/2", 2);
    model.result().evaluationGroup("std1EvgFrq").feature("gev1").setIndex("unit", "1", 2);
    model.result().evaluationGroup("std1EvgFrq").feature("gev1").setIndex("descr", "Quality factor", 2);
    model.result().evaluationGroup("std1EvgFrq").run();
    model.result().evaluationGroup().create("std1mpf1", "EvaluationGroup");
    model.result().evaluationGroup("std1mpf1").set("data", "dset1");
    model.result().evaluationGroup("std1mpf1").label("Participation Factors (Infinite Crystal)");
    model.result().evaluationGroup("std1mpf1").create("gev1", "EvalGlobal");
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.pfLnormX", 0);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "1", 0);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Participation factor, normalized, X-translation", 0);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.pfLnormY", 1);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "1", 1);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Participation factor, normalized, Y-translation", 1);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.pfLnormZ", 2);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "1", 2);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Participation factor, normalized, Z-translation", 2);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.pfRnormX", 3);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "1", 3);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Participation factor, normalized, X-rotation", 3);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.pfRnormY", 4);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "1", 4);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Participation factor, normalized, Y-rotation", 4);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.pfRnormZ", 5);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "1", 5);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Participation factor, normalized, Z-rotation", 5);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.mEffLX", 6);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "kg", 6);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Effective modal mass, X-translation", 6);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.mEffLY", 7);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "kg", 7);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Effective modal mass, Y-translation", 7);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.mEffLZ", 8);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "kg", 8);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Effective modal mass, Z-translation", 8);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.mEffRX", 9);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "kg*m^2", 9);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Effective modal mass, X-rotation", 9);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.mEffRY", 10);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "kg*m^2", 10);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Effective modal mass, Y-rotation", 10);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.mEffRZ", 11);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "kg*m^2", 11);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Effective modal mass, Z-rotation", 11);
    model.result().evaluationGroup("std1mpf1").run();
    model.result("pg1").run();

//    In the Model Builder window, expand the Results > Datasets node.
//    Right-click Results > Datasets and choose More 2D Datasets > Array 2D.

    model.result().dataset().create("arr1", "Array2D");

//    In the Settings window for Array 2D, locate the Array Size section.
//    In the X size text field, type 20.

    model.result().dataset("arr1").set("fullsize", new int[]{20, 1});

//    In the Y size text field, type 20.

    model.result().dataset("arr1").set("fullsize", new int[]{20, 20});

//    Click to expand the Advanced section.
//    Select the Floquet–Bloch periodicity checkbox.

    model.result().dataset("arr1").set("floquetper", true);

//    Find the Wave vector subsection.
//    In the X text field, type P*pi.

    model.result().dataset("arr1").set("wavevector", new String[]{"P*pi", "0"});
    model.result("pg1").run();

//    In the Model Builder window, expand the Results > Mode Shape (solid) node, then click Mode Shape (solid).
//    In the Settings window for 2D Plot Group, locate the Data section.
//    From the Dataset list, select Array 2D 1.

    model.result("pg1").set("data", "arr1");

//    From the Parameter value (P) list, select 0.1.

    model.result("pg1").set("looplevel", new int[]{6, 6});

//    From the Eigenfrequency (Hz) list, select 98.541.

    model.result("pg1").set("looplevel", new int[]{1, 6});

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

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

//    Find the Solution subsection.
//    Clear the Solution checkbox.

    model.result("pg1").set("solutionintitle", false);

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

    model.result("pg1").set("edges", false);
    model.result("pg1").run();

//    In the Model Builder window, right-click Surface 1 and choose Solution Array.

    model.result("pg1").feature("surf1").create("sol1", "SolutionArray");

//    In the Settings window for Solution Array, locate the Data section.
//    From the Parameter selection (P) list, select From list.

    model.result("pg1").feature("surf1").feature("sol1").setIndex("looplevelinput", "manual", 1);

//    In the Parameter values (P) list, select 0.1.

    model.result("pg1").feature("surf1").feature("sol1").setIndex("looplevel", new int[]{6}, 1);

//    select 0.1 in the Parameter values (P) list.
//    From the Eigenfrequency selection list, select Manual.

    model.result("pg1").feature("surf1").feature("sol1").setIndex("looplevelinput", "manualindices", 0);

//    In the Eigenfrequency indices (1-6) text field, type 1 2.

    model.result("pg1").feature("surf1").feature("sol1").setIndex("looplevelindices", "1 2", 0);

//    In the Mode Shape (solid) toolbar, click Plot.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Results toolbar, click 1D Plot Group.

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

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

    model.result("pg2").label("Dispersion Relation");

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

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

//    In the associated text field, type \kappa/\pi (1/m).

    model.result("pg2").set("xlabel", "\\kappa/\\pi (1/m)");

//    Select the y-axis label checkbox.

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

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

    model.result("pg2").set("ylabel", "f (kHz)");

//    Right-click Dispersion Relation and choose Global.

    model.result("pg2").create("glob1", "Global");
    model.result("pg2").feature("glob1").set("markerpos", "datapoints");
    model.result("pg2").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("pg2").feature("glob1").setIndex("expr", "solid.freq", 0);
    model.result("pg2").feature("glob1").setIndex("unit", "kHz", 0);

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

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

//    In the Expression text field, type P.

    model.result("pg2").feature("glob1").set("xdataexpr", "P");

//    In the Dispersion Relation toolbar, click Plot.

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

//    In the Model Builder window, click Dispersion Relation.
//    In the Settings window for 1D Plot Group, locate the Legend section.
//    Clear the Show legends checkbox.

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

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

    model.result("pg2").set("titletype", "label");
    model.result("pg2").run();

//    In the Model Builder window, click Global 1.
//    In the Settings window for Global, click to expand the Coloring and Style section.
//    Find the Line style subsection.
//    From the Line list, select None.

    model.result("pg2").feature("glob1").set("linestyle", "none");

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

    model.result("pg2").feature("glob1").set("linemarker", "asterisk");

//    From the Width list, select 2.

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

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

    model.result("pg2").feature("glob1").create("col1", "Color");
    model.result("pg2").run();

//    In the Settings window for Color Expression, locate the Expression section.
//    In the Expression text field, type intop1(real(u)^2)/intop1(real(solid.disp)^2).

    model.result("pg2").feature("glob1").feature("col1").set("expr", "intop1(real(u)^2)/intop1(real(solid.disp)^2)");

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

    model.result("pg2").feature("glob1").feature("col1").set("colortable", "WaveLight");

//    In the Dispersion Relation toolbar, click Plot.

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

//    In the Results toolbar, click Evaluation Group.

    model.result().evaluationGroup().create("eg1", "EvaluationGroup");

//    In the Settings window for Evaluation Group, type Long Wavelength Homogenized Properties in the Label text field.

    model.result().evaluationGroup("eg1").label("Long Wavelength Homogenized Properties");

//    Locate the Transformation section.
//    Select the Transpose checkbox.

    model.result().evaluationGroup("eg1").set("transpose", true);

//    Click to expand the Format section.
//    From the Include parameters list, select Off.

    model.result().evaluationGroup("eg1").set("includeparameters", false);

//    Right-click Long Wavelength Homogenized Properties and choose Global Evaluation.

    model.result().evaluationGroup("eg1").create("gev1", "EvalGlobal");

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

    model.result().evaluationGroup("eg1").feature("gev1").label("S Waves");

//    Locate the Data section.
//    From the Dataset list, select Infinite Crystal/Solution 1 (sol1).

    model.result().evaluationGroup("eg1").feature("gev1").set("data", "dset1");

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

    model.result().evaluationGroup("eg1").feature("gev1").setIndex("looplevelinput", "manual", 1);

//    In the Parameter values (P) list, select 0.02.

    model.result().evaluationGroup("eg1").feature("gev1").setIndex("looplevel", new int[]{2}, 1);

//    select 0.02 in the Parameter values (P) list.
//    From the Eigenfrequency selection list, select First.

    model.result().evaluationGroup("eg1").feature("gev1").setIndex("looplevelinput", "first", 0);

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

    model.result().evaluationGroup("eg1").feature("gev1").setIndex("expr", "2*pi*solid.freq/(P*pi/1[m])", 0);
    model.result().evaluationGroup("eg1").feature("gev1").setIndex("descr", "Wave Speed, S", 0);
    model.result().evaluationGroup("eg1").feature("gev1")
         .setIndex("expr", "(2*pi*solid.freq/(P*pi/1[m]))^2*2700[kg/m^2]*0.75", 1);
    model.result().evaluationGroup("eg1").feature("gev1").setIndex("descr", "Homogenized C66", 1);

//    Right-click S Waves and choose Duplicate.

    model.result().evaluationGroup("eg1").feature().duplicate("gev2", "gev1");

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

    model.result().evaluationGroup("eg1").feature("gev2").label("P Waves");

//    Locate the Data section.
//    From the Eigenfrequency selection list, select Manual.

    model.result().evaluationGroup("eg1").feature("gev2").setIndex("looplevelinput", "manualindices", 0);

//    In the Eigenfrequency indices (1-6) text field, type 2.

    model.result().evaluationGroup("eg1").feature("gev2").setIndex("looplevelindices", 2, 0);

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

    model.result().evaluationGroup("eg1").feature("gev2").setIndex("descr", "Wave Speed, P", 0);
    model.result().evaluationGroup("eg1").feature("gev2").setIndex("descr", "Homogenized C11", 1);
    model.result().evaluationGroup("eg1").feature("gev2").setIndex("expr", "2700[kg/m^3]*0.75", 2);
    model.result().evaluationGroup("eg1").feature("gev2").setIndex("descr", "Homogenized density", 2);

//    In the Long Wavelength Homogenized Properties toolbar, click Evaluate.

    model.result().evaluationGroup("eg1").run();

//    Right-click P Waves and choose 2D.

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

    model.component("comp2").geom().create("geom2", 2);

    model.component("comp2").mesh().create("mesh2");

//    In the Settings window for Component, type Unit Cell in the Label text field.

    model.component("comp1").label("Unit Cell");

//    In the Model Builder window, click Component 2 (comp2).
//    In the Settings window for Component, type Finite Crystal in the Label text field.

    model.component("comp2").label("Finite Crystal");

//    In the Geometry toolbar, click Part Instance and choose Part 1.

    model.component("comp2").geom("geom2").create("pi1", "PartInstance");
    model.component("comp2").geom("geom2").feature("pi1").set("selkeepnoncontr", false);
    model.component("comp2").geom("geom2").feature("pi1").set("part", "part1");

//    In the Settings window for Part Instance, click Build Selected.

    model.component("comp2").geom("geom2").run("pi1");

//    In the Physics toolbar, click Add Physics to open the Add Physics window.
//    In the tree, select Recently Used > Solid Mechanics (solid).
//    Click Add to Finite Crystal in the window toolbar.

    model.component("comp2").physics().create("solid2", "SolidMechanics", "geom2");

    model.component("comp2").geom("geom2").run();

//    In the Physics toolbar, click Add Physics to close the Add Physics window.
//    In the Model Builder window, right-click Finite Crystal (comp2) > Definitions and choose Variables.

    model.component("comp2").variable().create("var1");

//    In the Settings window for Variables, type Incident P Wave in the Label text field.

    model.component("comp2").variable("var1").label("Incident P Wave");

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

    model.component("comp2").variable("var1").set("Omega", "2*pi*freq");
    model.component("comp2").variable("var1").descr("Omega", "Angular frequency");
    model.component("comp2").variable("var1").set("kP", "Omega/solid2.cp");
    model.component("comp2").variable("var1").descr("kP", "P Wave wavenumber");
    model.component("comp2").variable("var1").set("uP", "exp(-1i*kP*x+1i*phase)[m]");
    model.component("comp2").variable("var1").descr("uP", "P Wave: u field");
    model.component("comp2").variable("var1").set("vP", "0[m]");
    model.component("comp2").variable("var1").descr("vP", "P Wave: v field");
    model.component("comp2").variable("var1").set("eps11P", "d(uP, x)");
    model.component("comp2").variable("var1").descr("eps11P", "Incident P wave: strain tensor, 11 component");
    model.component("comp2").variable("var1").set("eps22P", "d(vP, y)");
    model.component("comp2").variable("var1").descr("eps22P", "Incident P wave: strain tensor, 22 component");
    model.component("comp2").variable("var1").set("eps12P", "0.5*(d(uP,y)+d(vP,x))");
    model.component("comp2").variable("var1").descr("eps12P", "Incident P wave: strain tensor, 12 component");
    model.component("comp2").variable("var1")
         .set("s11P", "(solid2.lambLame+2*solid2.muLame)*eps11P+solid2.lambLame*eps22P");
    model.component("comp2").variable("var1").descr("s11P", "Incident P wave: stress tensor, 11 component");
    model.component("comp2").variable("var1")
         .set("s22P", "solid2.lambLame*eps11P+(solid2.lambLame+2*solid2.muLame)*eps22P");
    model.component("comp2").variable("var1").descr("s22P", "Incident P wave: stress tensor, 22 component");
    model.component("comp2").variable("var1").set("s12P", "2*solid2.muLame*eps12P");
    model.component("comp2").variable("var1").descr("s12P", "Incident P wave: stress tensor, 12 component");
    model.component("comp2").variable("var1").set("I1P", "0.5*real(-s11P*conj(1i*Omega*uP)-s12P*conj(1i*Omega*vP))");
    model.component("comp2").variable("var1").descr("I1P", "Incident P wave: mechanical energy flux, 1 component");
    model.component("comp2").variable("var1").set("I2P", "0.5*real(-s12P*conj(1i*Omega*uP)-s22P*conj(1i*Omega*vP))");
    model.component("comp2").variable("var1").descr("I2P", "Incident P wave: mechanical energy flux, 2 component");

//    In the Physics toolbar, click Boundaries and choose Periodic Condition.

    model.component("comp2").physics("solid2").create("pc1", "PeriodicCondition", 1);

//    Select Boundaries 2, 7, 9, 14, 16, 21.

    model.component("comp2").physics("solid2").feature("pc1").selection().set(2, 7, 9, 14, 16, 21);

//    In the Physics toolbar, click Boundaries and choose Boundary Load.

    model.component("comp2").physics("solid2").create("bndl1", "BoundaryLoad", 1);

//    Select Boundaries 10, 11, 13, 17.

    model.component("comp2").physics("solid2").feature("bndl1").selection().set(10, 11, 13, 17);

//    In the Settings window for Boundary Load, locate the Force section.
//    Specify the \[\mathbf{f}_{\mathrm{A}}\] vector as

    model.component("comp2").physics("solid2").feature("bndl1")
         .set("forceReferenceArea", new String[]{"-(s11P*solid2.nx+s12P*solid2.ny)", "-(s12P*solid2.nx+s22P*solid2.ny)", "0"});

//    In the Geometry toolbar, click Transforms and choose Array.

    model.component("comp2").geom("geom2").create("arr1", "Array");

//    In the Settings window for Array, locate the Size section.
//    In the x size text field, type 10.

    model.component("comp2").geom("geom2").feature("arr1").set("fullsize", new double[]{10, 1});

//    Locate the Displacement section.
//    In the x text field, type 1.

    model.component("comp2").geom("geom2").feature("arr1").set("displ", new double[]{1, 0});

//    Click the Select All button in the Graphics toolbar.

    model.component("comp2").geom("geom2").feature("arr1").selection("input").set("pi1");

//    Click Build Selected.

    model.component("comp2").geom("geom2").run("arr1");

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Geometry toolbar, click Rectangle.

    model.component("comp2").geom("geom2").create("r1", "Rectangle");

//    In the Settings window for Rectangle, locate the Size and Shape section.
//    In the Width text field, type 10.

    model.component("comp2").geom("geom2").feature("r1").set("size", new double[]{10, 1});

//    Locate the Position section.
//    In the x text field, type -10.

    model.component("comp2").geom("geom2").feature("r1").set("pos", new double[]{-10, 0});

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

    model.component("comp2").geom("geom2").feature("r1").setIndex("layer", 1, 0);

//    Select the Layers to the left checkbox.

    model.component("comp2").geom("geom2").feature("r1").set("layerleft", true);

//    Clear the Layers on bottom checkbox.

    model.component("comp2").geom("geom2").feature("r1").set("layerbottom", false);

//    Click Build Selected.

    model.component("comp2").geom("geom2").run("r1");

//    Click the Zoom Extents button in the Graphics toolbar.
//    Right-click Rectangle 1 (r1) and choose Duplicate.

    model.component("comp2").geom("geom2").feature().duplicate("r2", "r1");

//    In the Settings window for Rectangle, locate the Position section.
//    In the x text field, type 10.

    model.component("comp2").geom("geom2").feature("r2").set("pos", new double[]{10, 0});

//    Locate the Layers section.
//    Clear the Layers to the left checkbox.

    model.component("comp2").geom("geom2").feature("r2").set("layerleft", false);

//    Select the Layers to the right checkbox.

    model.component("comp2").geom("geom2").feature("r2").set("layerright", true);

//    Click Build Selected.

    model.component("comp2").geom("geom2").run("r2");

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Definitions toolbar, click Perfectly Matched Layer.

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

    model.component("comp2").geom("geom2").run();

//    Select Domains 1, 84.

    return model;
  }

  public static Model run2(Model model) {

    model.component("comp2").coordSystem("pml1").selection().set(1, 84);

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

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

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

    model.component("comp2").cpl("aveop1").selection().geom("geom2", 1);

//    Select Boundaries 7, 9, 11.

    model.component("comp2").cpl("aveop1").selection().set(7, 9, 11);

//    In the Label text field, type Scattered Intensity.

    model.component("comp2").cpl("aveop1").label("Scattered Intensity");

//    In the Model Builder window, right-click Finite Crystal (comp2) > Materials and choose More Materials > Material Link.

    model.component("comp2").material().create("matlnk2", "Link");

//    Select Boundaries 2, 3, 5, 6, 8, 13, 15, 20, 22, 27, 29, 34, 36, 41, 43, 48, 50, 55, 57, 62, 64, 69, 71, 76, 78, 83, 85, 90, 92, 97, 99, 104, 106, 111, 113, 118, 120, 125, 127, 132, 134, 139, 141, 146, 148, 153, 155, 160, 162, 167, 169, 174, 176, 181, 183, 188, 190, 195, 197, 202, 204, 209, 211, 216, 218, 221, 223, 224.

    model.component("comp2").physics("solid2").feature("pc1").selection()
         .set(2, 3, 5, 6, 8, 13, 15, 20, 22, 27, 29, 34, 36, 41, 43, 48, 50, 55, 57, 62, 64, 69, 71, 76, 78, 83, 85, 90, 92, 97, 99, 104, 106, 111, 113, 118, 120, 125, 127, 132, 134, 139, 141, 146, 148, 153, 155, 160, 162, 167, 169, 174, 176, 181, 183, 188, 190, 195, 197, 202, 204, 209, 211, 216, 218, 221, 223, 224);

//    In the Mesh toolbar, click Mapped.

    model.component("comp2").mesh("mesh2").create("map1", "Map");

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

    model.component("comp2").mesh("mesh2").feature("map1").selection().geom("geom2", 2);

//    Select Domains 1, 84.

    model.component("comp2").mesh("mesh2").feature("map1").selection().set(1, 84);

//    In the Mesh toolbar, click Free Triangular.

    model.component("comp2").mesh("mesh2").create("ftri1", "FreeTri");

//    In the Model Builder window, click Size.
//    In the Settings window for Size, locate the Element Size section.
//    From the Predefined list, select Extremely fine.

    model.component("comp2").mesh("mesh2").feature("size").set("hauto", 1);

//    Click to expand the Element Size Parameters section.
//    In the Maximum element size text field, type 0.1.

    model.component("comp2").mesh("mesh2").feature("size").set("hmax", 0.1);

//    Click Build All.

    model.component("comp2").mesh("mesh2").run();

//    In the Study toolbar, click Add Study to open the Add Study window.
//    Find the Studies subsection.
//    In the Select Study tree, select General Studies > Frequency Domain.
//    Click Add Study in the window toolbar.

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

//    In the Study toolbar, click Add Study to close the Add Study window.
//    In the Settings window for Eigenfrequency, locate the Physics and Variables Selection section.
//    Select the Modify model configuration for study step checkbox.

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

//    In the tree, select Finite Crystal (comp2) > Solid Mechanics 2 (solid2).
//    Click Disable in Model.

    model.study("std1").feature("eig").setSolveFor("/physics/solid2", false);
    model.study("std1").feature("eig").set("disabledphysics", new String[]{"solid2"});

//    In the Model Builder window, collapse the Infinite Crystal node.
//    In the Model Builder window, click Study 2.
//    In the Settings window for Study, type Finite Crystal: P Wave in the Label text field.

    model.study("std2").label("Finite Crystal: P Wave");

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

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

//    In the Model Builder window, under Finite Crystal: P Wave, click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Study Settings section.
//    In the Frequencies text field, type range(100, 5, 2500 ).

    model.study("std2").feature("freq").set("plist", "range(100, 5, 2500 )");

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

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

//    In the tree, select Unit Cell (comp1) > Solid Mechanics (solid).
//    Click Disable in Model.

    model.study("std2").feature("freq").setSolveFor("/physics/solid", false);
    model.study("std2").feature("freq").set("disabledphysics", new String[]{"solid"});

//    In the Study toolbar, click Compute.

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

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

//    In the Results toolbar, click More Datasets and choose Array 2D.

    model.result().dataset().create("arr2", "Array2D");

//    In the Settings window for Array 2D, locate the Array Size section.
//    In the Y size text field, type 5.

    model.result().dataset("arr2").set("fullsize", new int[]{1, 5});

//    Locate the Data section.
//    From the Dataset list, select Finite Crystal: P Wave/Solution 2 (sol2).

    model.result().dataset("arr2").set("data", "dset2");

//    In the Results toolbar, click Attributes and choose Selection.
//    In the Settings window for Selection, locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Domain.

    model.result().dataset("arr2").selection().geom("geom2", 2);

//    Click the Select All button in the Graphics toolbar.

    model.result().dataset("arr2").selection().geom("geom2", 2);
    model.result().dataset("arr2").selection()
         .set(1, 2, 3, 4, 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);

//    Select Domains 2, 3, 4, 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.

    model.result().dataset("arr2").selection().geom("geom2", 2);
    model.result().dataset("arr2").selection()
         .set(2, 3, 4, 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);

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

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

//    In the Settings window for 2D Plot Group, type P Wave Incident: P Wave Scattered in the Label text field.

    model.result("pg3").label("P Wave Incident: P Wave Scattered");

//    Locate the Data section.
//    From the Dataset list, select Array 2D 2.

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

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

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

//    In the Title text area, type \$ \nabla \cdot \mathbf{u}_\mathrm{tot} \$.

    model.result("pg3").set("title", "\\$ \\nabla \\cdot \\mathbf{u}_\\mathrm{tot} \\$");

//    In the Parameter indicator text field, type freq = eval(freq) Hz.

    model.result("pg3").set("paramindicator", "freq = eval(freq) Hz");

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

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

//    Right-click P Wave Incident: P Wave Scattered and choose Surface.

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

//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type d(u2+uP,x)+d(v2+vP,y).

    model.result("pg3").feature("surf1").set("expr", "d(u2+uP,x)+d(v2+vP,y)");

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

    model.result("pg3").feature("surf1").set("colortable", "WaveClassic");

//    From the Scale list, select Linear symmetric.

    model.result("pg3").feature("surf1").set("colorscalemode", "linearsymmetric");

//    In the P Wave Incident: P Wave Scattered toolbar, click Plot.

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

//    In the Model Builder window, right-click P Wave Incident: P Wave Scattered and choose Arrow Surface.

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

//    In the Settings window for Arrow Surface, locate the Expression section.
//    In the x-component text field, type u2+uP.

    model.result("pg3").feature("arws1").set("expr", new String[]{"u2+uP", "v2"});

//    In the y-component text field, type v2+vP.

    model.result("pg3").feature("arws1").set("expr", new String[]{"u2+uP", "v2+vP"});

//    Locate the Coloring and Style section.
//    From the Arrow length list, select Logarithmic.

    model.result("pg3").feature("arws1").set("arrowlength", "logarithmic");

//    From the Color list, select Black.

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

//    In the Model Builder window, click P Wave Incident: P Wave Scattered.
//    In the P Wave Incident: P Wave Scattered toolbar, click Plot.

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

//    Right-click P Wave Incident: P Wave Scattered and choose Duplicate.

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

//    In the Model Builder window, click P Wave Incident: P Wave Scattered 1.
//    In the Settings window for 2D Plot Group, type P Wave Incident: S Wave Scattered in the Label text field.

    model.result("pg4").label("P Wave Incident: S Wave Scattered");

//    Locate the Title section.
//    In the Title text area, type \$ \nabla \times \mathbf{u}_\mathrm{tot} \$.

    model.result("pg4").set("title", "\\$ \\nabla \\times \\mathbf{u}_\\mathrm{tot} \\$");
    model.result("pg4").run();

//    In the Model Builder window, click Surface 1.
//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type -d(u2+uP,y)+d(v2+vP,x).

    model.result("pg4").feature("surf1").set("expr", "-d(u2+uP,y)+d(v2+vP,x)");

//    In the P Wave Incident: S Wave Scattered toolbar, click Plot.

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

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

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

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

    model.result("pg5").label("Transmission Coefficient");

//    Locate the Data section.
//    From the Dataset list, select Finite Crystal: P Wave/Solution 2 (sol2).

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

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

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

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

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

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

    model.result("pg5").set("xlabel", "f (kHz)");

//    Select the y-axis label checkbox.

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

//    In the associated text field, type (1).

    model.result("pg5").set("ylabel", "(1)");

//    Right-click Transmission Coefficient and choose Global.

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

//    In the Settings window for Global, type P Wave in the Label text field.

    model.result("pg5").feature("glob1").label("P Wave");

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

    model.result("pg5").feature("glob1").setIndex("expr", "1-comp2.aveop1(solid2.IX*solid2.nx/I1P)", 0);
    model.result("pg5").feature("glob1").setIndex("descr", "Transmission Coefficient", 0);

//    Locate the x-Axis Data section.
//    From the Unit list, select kHz.

    model.result("pg5").feature("glob1").set("xdataparamunit", "kHz");

//    Locate the Coloring and Style section.
//    From the Width list, select 2.

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

//    Click to expand the Legends section.
//    Find the Include subsection.
//    Clear the Solution checkbox.

    model.result("pg5").feature("glob1").set("autosolution", false);

//    Clear the Description checkbox.

    model.result("pg5").feature("glob1").set("autodescr", false);

//    Select the Label checkbox.

    model.result("pg5").feature("glob1").set("autoplotlabel", true);

//    In the Transmission Coefficient toolbar, click Plot.

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

//    In the Model Builder window, collapse the Finite Crystal: P Wave node.
//    In the Study toolbar, click Add Study to open the Add Study window.
//    Find the Studies subsection.
//    In the Select Study tree, select General Studies > Frequency Domain.
//    Click Add Study in the window toolbar.

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

//    In the Study toolbar, click Add Study to close the Add Study window.
//    In the Settings window for Study, type Finite Crystal: S Wave in the Label text field.

    model.study("std3").label("Finite Crystal: S Wave");

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

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

//    In the Model Builder window, under Finite Crystal: S Wave, click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Study Settings section.
//    In the Frequencies text field, type range(100, 5, 2500).

    model.study("std3").feature("freq").set("plist", "range(100, 5, 2500)");

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

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

//    In the tree, select Unit Cell (comp1) > Solid Mechanics (solid).
//    Click Disable in Model.

    model.study("std3").feature("freq").setSolveFor("/physics/solid", false);
    model.study("std3").feature("freq").set("disabledphysics", new String[]{"solid"});

//    In the Model Builder window, right-click Finite Crystal (comp2) > Definitions and choose Variables.

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

//    In the Settings window for Variables, type Incident S Wave in the Label text field.

    model.component("comp2").variable("var2").label("Incident S Wave");

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

    model.component("comp2").variable("var2").set("kS", "Omega/solid2.cs");
    model.component("comp2").variable("var2").descr("kS", "S Wave wavenumber");
    model.component("comp2").variable("var2").set("uS", "0[m]");
    model.component("comp2").variable("var2").descr("uS", "S Wave: u field");
    model.component("comp2").variable("var2").set("vS", "exp(-1i*kS*x+1i*phase)[m]");
    model.component("comp2").variable("var2").descr("vS", "S Wave: v field");
    model.component("comp2").variable("var2").set("eps11S", "d(uS, x)");
    model.component("comp2").variable("var2").descr("eps11S", "Incident S wave: strain tensor, 11 component");
    model.component("comp2").variable("var2").set("eps22S", "d(vS, y)");
    model.component("comp2").variable("var2").descr("eps22S", "Incident S wave: strain tensor, 22 component");
    model.component("comp2").variable("var2").set("eps12S", "0.5*(d(uS,y)+d(vS,x))");
    model.component("comp2").variable("var2").descr("eps12S", "Incident S wave: strain tensor, 12 component");
    model.component("comp2").variable("var2")
         .set("s11S", "(solid2.lambLame+2*solid2.muLame)*eps11S+solid2.lambLame*eps22S");
    model.component("comp2").variable("var2").descr("s11S", "Incident S wave: stress tensor, 11 component");
    model.component("comp2").variable("var2")
         .set("s22S", "solid2.lambLame*eps11S+(solid2.lambLame+2*solid2.muLame)*eps22S");
    model.component("comp2").variable("var2").descr("s22S", "Incident S wave: stress tensor, 22 component");
    model.component("comp2").variable("var2").set("s12S", "2*solid2.muLame*eps12S");
    model.component("comp2").variable("var2").descr("s12S", "Incident S wave: stress tensor, 12 component");
    model.component("comp2").variable("var2").set("I1S", "0.5*real(-s11S*conj(1i*Omega*uS)-s12S*conj(1i*Omega*vS))");
    model.component("comp2").variable("var2").descr("I1S", "Incident S wave: mechanical energy flux, 1 component");
    model.component("comp2").variable("var2").set("I2S", "0.5*real(-s12S*conj(1i*Omega*uS)-s22S*conj(1i*Omega*vS))");
    model.component("comp2").variable("var2").descr("I2S", "Incident S wave: mechanical energy flux, 2 component");

//    In the Model Builder window, under Finite Crystal (comp2), click Solid Mechanics 2 (solid2).
//    In the Settings window for Solid Mechanics, click to expand the Typical Wave Speed for Perfectly Matched Layers section.
//    In the \[c_{\textrm{ref}}\] text field, type solid2.cs.

    model.component("comp2").physics("solid2").prop("cref").set("cref", "solid2.cs");

//    In the Model Builder window, under Finite Crystal (comp2) > Solid Mechanics 2 (solid2), click Boundary Load 1.
//    In the Settings window for Boundary Load, type Boundary Load: P Wave in the Label text field.

    model.component("comp2").physics("solid2").feature("bndl1").label("Boundary Load: P Wave");

//    Right-click Boundary Load: P Wave and choose Duplicate.

    model.component("comp2").physics("solid2").feature().duplicate("bndl2", "bndl1");

//    In the Settings window for Boundary Load, type Boundary Load: S Wave in the Label text field.

    model.component("comp2").physics("solid2").feature("bndl2").label("Boundary Load: S Wave");

//    Locate the Force section.
//    Specify the \[\mathbf{f}_{\mathrm{A}}\] vector as

    model.component("comp2").physics("solid2").feature("bndl2")
         .set("forceReferenceArea", new String[]{"-(s11S*solid2.nx+s12S*solid2.ny)", "-(s12S*solid2.nx+s22S*solid2.ny)", "0"});

//    In the Model Builder window, expand the Finite Crystal: P Wave node, then click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Physics and Variables Selection section.
//    In the tree, select Finite Crystal (comp2) > Solid Mechanics 2 (solid2) > Boundary Load: S Wave.
//    Click Disable.

    model.study("std2").feature("freq").set("disabledphysics", new String[]{"solid", "solid2/bndl2"});

//    In the Model Builder window, under Finite Crystal: S Wave, click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Physics and Variables Selection section.
//    In the tree, select Finite Crystal (comp2) > Solid Mechanics 2 (solid2) > Boundary Load: P Wave.
//    Click Disable.

    model.study("std3").feature("freq").set("disabledphysics", new String[]{"solid", "solid2/bndl1"});

//    In the Study toolbar, click Compute.

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

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

//    In the Model Builder window, right-click Results > Datasets > Array 2D 2 and choose Duplicate.

    model.result().dataset().duplicate("arr3", "arr2");

//    In the Settings window for Array 2D, locate the Data section.
//    From the Dataset list, select Finite Crystal: S Wave/Solution 3 (sol3).

    model.result().dataset("arr3").set("data", "dset3");
    model.result("pg3").run();

//    In the Model Builder window, right-click P Wave Incident: P Wave Scattered and choose Duplicate.

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

//    In the Settings window for 2D Plot Group, type S Wave Incident: P Wave Scattered in the Label text field.

    model.result("pg6").label("S Wave Incident: P Wave Scattered");

//    Locate the Data section.
//    From the Dataset list, select Array 2D 3.

    model.result("pg6").set("data", "arr3");

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

    model.result("pg6").setIndex("looplevel", 221, 0);
    model.result("pg6").run();

//    In the Model Builder window, expand the S Wave Incident: P Wave Scattered node, then click Surface 1.
//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type d(u2+uS,x)+d(v2+vS,y).

    model.result("pg6").feature("surf1").set("expr", "d(u2+uS,x)+d(v2+vS,y)");
    model.result("pg6").run();

//    In the Model Builder window, click Arrow Surface 1.
//    In the Settings window for Arrow Surface, locate the Expression section.
//    In the x-component text field, type u2+uS.

    model.result("pg6").feature("arws1").set("expr", new String[]{"u2+uS", "v2+vP"});

//    In the y-component text field, type v2+vS.

    model.result("pg6").feature("arws1").set("expr", new String[]{"u2+uS", "v2+vS"});

//    In the S Wave Incident: P Wave Scattered toolbar, click Plot.

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

//    In the Model Builder window, right-click P Wave Incident: S Wave Scattered and choose Duplicate.

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

//    In the Settings window for 2D Plot Group, type S Wave Incident: S Wave Scattered in the Label text field.

    model.result("pg7").label("S Wave Incident: S Wave Scattered");

//    Locate the Data section.
//    From the Dataset list, select Array 2D 3.

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

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

    model.result("pg7").setIndex("looplevel", 221, 0);
    model.result("pg7").run();

//    In the Model Builder window, expand the S Wave Incident: S Wave Scattered node, then click Surface 1.
//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type -d(u2+uS,y)+d(v2+vS,x).

    model.result("pg7").feature("surf1").set("expr", "-d(u2+uS,y)+d(v2+vS,x)");
    model.result("pg7").run();

//    In the Model Builder window, click Arrow Surface 1.
//    In the Settings window for Arrow Surface, locate the Expression section.
//    In the x-component text field, type u2+uS.

    model.result("pg7").feature("arws1").set("expr", new String[]{"u2+uS", "v2+vP"});

//    In the y-component text field, type v2+vS.

    model.result("pg7").feature("arws1").set("expr", new String[]{"u2+uS", "v2+vS"});

//    In the S Wave Incident: S Wave Scattered toolbar, click Plot.

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

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

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

//    In the Settings window for Global, type S Wave in the Label text field.

    model.result("pg5").feature("glob2").label("S Wave");

//    Locate the Data section.
//    From the Dataset list, select Finite Crystal: S Wave/Solution 3 (sol3).

    model.result("pg5").feature("glob2").set("data", "dset3");

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

    model.result("pg5").feature("glob2").setIndex("expr", "1-comp2.aveop1(solid2.IX*solid2.nx/I1S)", 0);

//    In the Transmission Coefficient toolbar, click Plot.

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

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

    model.title("Phononic Crystal");

    model
         .description("This model shows how to use the scattered-field formulation to compute the transmission coefficient for impinging P and S plane elastic waves onto a finite-size phononic crystal.\n\nThe transmission tends to zero in the frequency range corresponding to the P- and S-wave band gaps, as predicted by a preliminary study aimed at computing the dispersion relation.");

    return model;
  }

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

}
