/*
 * scattered_field_elastic_waves.java
 */

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

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

  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 > 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("solid", "SolidMechanics", "geom1");

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

//    In the Model Builder window, under Global Definitions, click Parameters 1.
//    In the Settings window for Parameters, type Material Parameters in the Label text field.

    model.param().label("Material Parameters");

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

    model.param().set("rho", "1[kg/m^3]");
    model.param().descr("rho", "Density of background material");
    model.param().set("muLame", "1[Pa]");
    model.param().descr("muLame", "Shear modulus of background material");
    model.param().set("lambLame", "2.3[Pa]");
    model.param().descr("lambLame", "First Lam\u00e9 parameter of background material");
    model.param().set("rho_o", "2[kg/m^3]");
    model.param().descr("rho_o", "Density of elastic obstacle");
    model.param().set("muLame_o", "1.1[Pa]");
    model.param().descr("muLame_o", "Shear modulus of elastic obstacle");
    model.param().set("lambLame_o", "2.5[Pa]");
    model.param().descr("lambLame_o", "First Lam\u00e9 parameter elastic obstacle");

//    In the Home toolbar, click Parameters and choose Add > Parameters.

    model.param().create("par2");

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

    model.param("par2").label("P Wave Parameters");

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

    model.param("par2").set("cP", "sqrt((lambLame+2*muLame)/rho)");
    model.param("par2").descr("cP", "Speed of P waves");
    model.param("par2").set("wlengthP", "1[m]");
    model.param("par2").descr("wlengthP", "Wavelength");
    model.param("par2").set("kP", "2*pi[rad]/wlengthP");
    model.param("par2").descr("kP", "Wave number");
    model.param("par2").set("omega", "kP*cP");
    model.param("par2").descr("omega", "Angular frequency");

//    In the Home toolbar, click Parameters and choose Add > Parameters.

    model.param().create("par3");

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

    model.param("par3").label("S Wave Parameters");

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

    model.param("par3").set("cS", "sqrt(muLame/rho)");
    model.param("par3").descr("cS", "Speed of S waves");
    model.param("par3").set("kS", "omega/cS");
    model.param("par3").descr("kS", "Wave number");
    model.param("par3").set("wlengthS", "2*pi/kS");
    model.param("par3").descr("wlengthS", "Wavelength");

//    In the Home toolbar, click Parameters and choose Add > Parameters.

    model.param().create("par4");

//    In the Settings window for Parameters, type Geometrical Parameters in the Label text field.

    model.param("par4").label("Geometrical Parameters");

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

    model.param("par4").set("R", "5[m]");
    model.param("par4").descr("R", "Radius of computational domain");
    model.param("par4").set("r_o", "1[m]");
    model.param("par4").descr("r_o", "Radius of inclusion");
    model.param("par4").set("r_layer", "1[m]");
    model.param("par4").descr("r_layer", "Thickness of PML");

//    In the Geometry toolbar, click Circle.

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

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

    model.component("comp1").geom("geom1").feature("c1").set("r", "R");

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

    model.component("comp1").geom("geom1").feature("c1").setIndex("layer", "r_layer", 0);
    model.component("comp1").geom("geom1").feature("c1").setIndex("layer", "R-r_layer-r_o", 1);

//    Click Build Selected.

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

//    Add more copies of the computational domain in order to solve for cavity inclusion, infinitely rigid obstacle, and elastic inclusion at the same time.
//    In the Geometry toolbar, click Transforms and choose Array.

    model.component("comp1").geom("geom1").create("arr1", "Array");

//    Select the object c1.

    model.component("comp1").geom("geom1").feature("arr1").selection("input").set("c1");

//    In the Settings window for Array, locate the Size section.
//    From the Array type list, select Linear.

    model.component("comp1").geom("geom1").feature("arr1").set("type", "linear");

//    In the Size text field, type 3.

    model.component("comp1").geom("geom1").feature("arr1").set("linearsize", 3);

//    Locate the Displacement section.
//    In the x text field, type 2*(R+r_o).

    model.component("comp1").geom("geom1").feature("arr1").set("displ", new String[]{"2*(R+r_o)", "0"});

//    Click Build Selected.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Model Builder window, right-click Geometry 1 and choose Delete Entities.

    model.component("comp1").geom("geom1").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.component("comp1").geom("geom1").feature("del1").selection("input").init(2);

//    On the object arr1(1), select Domain 9.

    model.component("comp1").geom("geom1").feature("del1").selection("input").set("arr1(1)", 9);
    model.component("comp1").geom("geom1").feature("del1").selection("input").set("arr1(2)", 9);

//    On the object arr1(2), select Domain 9.
//    Click Build All Objects.

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

//    In the Model Builder window, expand the Component 1 (comp1) > Definitions node.
//    Right-click Definitions and choose Perfectly Matched Layer.

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

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

//    Select Domains 1, 2, 5, 8.

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

//    In the Settings window for Perfectly Matched Layer, locate the Geometry section.
//    From the Type list, select Cylindrical.

    model.component("comp1").coordSystem("pml1").set("ScalingType", "Cylindrical");

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

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

//    Select Domains 9, 10, 13, 16.

    model.component("comp1").coordSystem("pml2").selection().set(9, 10, 13, 16);

//    In the Settings window for Perfectly Matched Layer, locate the Geometry section.
//    From the Type list, select Cylindrical.

    model.component("comp1").coordSystem("pml2").set("ScalingType", "Cylindrical");

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

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

//    Select Domains 17, 18, 21, 24.

    model.component("comp1").coordSystem("pml3").selection().set(17, 18, 21, 24);

//    In the Settings window for Perfectly Matched Layer, locate the Geometry section.
//    From the Type list, select Cylindrical.

    model.component("comp1").coordSystem("pml3").set("ScalingType", "Cylindrical");

//    First, set up the simulation for an incident P wave.
//    In the Model Builder window, right-click Component 1 (comp1) > Definitions and choose Variables.

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

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

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

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

    model.component("comp1").variable("var1").set("uP", "exp(-1i*kP*x-1i*pi/2+1i*phase)[m]");
    model.component("comp1").variable("var1").descr("uP", "Incident wave: u field");
    model.component("comp1").variable("var1").set("vP", "0[m]");
    model.component("comp1").variable("var1").descr("vP", "Incident wave: v field");
    model.component("comp1").variable("var1").set("eps11P", "d(uP,x)");
    model.component("comp1").variable("var1").descr("eps11P", "Incident wave: strain tensor, 11 component");
    model.component("comp1").variable("var1").set("eps22P", "d(vP,y)");
    model.component("comp1").variable("var1").descr("eps22P", "Incident wave: strain tensor, 22 component");
    model.component("comp1").variable("var1").set("eps12P", "0.5*(d(uP,y)+d(vP,x))");
    model.component("comp1").variable("var1").descr("eps12P", "Incident wave: strain tensor, 12 component");
    model.component("comp1").variable("var1").set("s11P", "(lambLame+2*muLame)*eps11P+lambLame*eps22P");
    model.component("comp1").variable("var1").descr("s11P", "Incident wave: stress tensor, 11 component");
    model.component("comp1").variable("var1").set("s22P", "lambLame*eps11P+(lambLame+2*muLame)*eps22P");
    model.component("comp1").variable("var1").descr("s22P", "Incident wave: stress tensor, 22 component");
    model.component("comp1").variable("var1").set("s12P", "2*muLame*eps12P");
    model.component("comp1").variable("var1").descr("s12P", "Incident wave: stress tensor, 12 component");

//    The internal variable <l>phase</l> is used to synchronize the incident field with the solved scattered field in plots and animations over the dynamic data extension.
//    In the Model Builder window, under Component 1 (comp1) > Solid Mechanics (solid), click Linear Elastic Material 1.
//    In the Settings window for Linear Elastic Material, type Background Material in the Label text field.

    model.component("comp1").physics("solid").feature("lemm1").label("Background Material");

//    Locate the Linear Elastic Material section.
//    From the Specify list, select Pressure-wave and shear-wave speeds.

    model.component("comp1").physics("solid").feature("lemm1").set("IsotropicOption", "CpCs");

//    From the \[c_{\textrm{p}}\] list, select User defined.

    model.component("comp1").physics("solid").feature("lemm1").set("cp_mat", "userdef");

//    In the associated text field, type cP.

    model.component("comp1").physics("solid").feature("lemm1").set("cp", "cP");

//    From the \[c_{\textrm{s}}\] list, select User defined.

    model.component("comp1").physics("solid").feature("lemm1").set("cs_mat", "userdef");

//    In the associated text field, type cS.

    model.component("comp1").physics("solid").feature("lemm1").set("cs", "cS");

//    From the \[\rho\] list, select User defined.

    model.component("comp1").physics("solid").feature("lemm1").set("rho_mat", "userdef");

//    In the associated text field, type rho.

    model.component("comp1").physics("solid").feature("lemm1").set("rho", "rho");

//    Add the boundary condition for a cavity inclusion.
//    In the Physics toolbar, click Boundaries and choose Boundary Load.

    model.component("comp1").physics("solid").create("bndl1", "BoundaryLoad", 1);

//    In the Settings window for Boundary Load, type Cavity Inclusion, P Wave in the Label text field.

    model.component("comp1").physics("solid").feature("bndl1").label("Cavity Inclusion, P Wave");

//    Select Boundaries 29, 30, 33, 34.

    model.component("comp1").physics("solid").feature("bndl1").selection().set(29, 30, 33, 34);

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

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

//    Now add the boundary condition for an infinitely rigid inclusion.
//    In the Physics toolbar, click Boundaries and choose Prescribed Displacement.

    model.component("comp1").physics("solid").create("disp1", "Displacement1", 1);

//    In the Settings window for Prescribed Displacement, type Infinitely Rigid Inclusion, P Wave in the Label text field.

    model.component("comp1").physics("solid").feature("disp1").label("Infinitely Rigid Inclusion, P Wave");

//    Select Boundaries 41, 42, 45, 46.

    model.component("comp1").physics("solid").feature("disp1").selection().set(41, 42, 45, 46);

//    Locate the Prescribed Displacement section.
//    From the Displacement in x direction list, select Prescribed.

    model.component("comp1").physics("solid").feature("disp1").setIndex("Direction", "prescribed", 0);

//    In the \[u_{\, 0 \, x}\] text field, type -uP.

    model.component("comp1").physics("solid").feature("disp1").setIndex("U0", "-uP", 0);

//    From the Displacement in y direction list, select Prescribed.

    model.component("comp1").physics("solid").feature("disp1").setIndex("Direction", "prescribed", 1);

//    In the \[u_{\, 0 \, y}\] text field, type -vP.

    model.component("comp1").physics("solid").feature("disp1").setIndex("U0", "-vP", 1);

//    Finally, set up the domain equation for the elastic inclusion.
//    In the Physics toolbar, click Domains and choose Linear Elastic Material.

    model.component("comp1").physics("solid").create("lemm2", "LinearElasticModel", 2);

//    In the Settings window for Linear Elastic Material, type Elastic Inclusion, P Wave in the Label text field.

    model.component("comp1").physics("solid").feature("lemm2").label("Elastic Inclusion, P Wave");

//    Select Domain 25.

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

//    Locate the Linear Elastic Material section.
//    From the Specify list, select Lamé parameters.

    model.component("comp1").physics("solid").feature("lemm2").set("IsotropicOption", "Lame");

//    From the \[\lambda\] list, select User defined.

    model.component("comp1").physics("solid").feature("lemm2").set("lambLame_mat", "userdef");

//    In the associated text field, type lambLame_o.

    model.component("comp1").physics("solid").feature("lemm2").set("lambLame", "lambLame_o");

//    From the \[\mu\] list, select User defined.

    model.component("comp1").physics("solid").feature("lemm2").set("muLame_mat", "userdef");

//    In the associated text field, type muLame_o.

    model.component("comp1").physics("solid").feature("lemm2").set("muLame", "muLame_o");

//    From the \[\rho\] list, select User defined.

    model.component("comp1").physics("solid").feature("lemm2").set("rho_mat", "userdef");

//    In the associated text field, type rho_o.

    model.component("comp1").physics("solid").feature("lemm2").set("rho", "rho_o");

//    Add the initial stress and strain computed from the background field.
//    In the Physics toolbar, click Attributes and choose Initial Stress and Strain.

    model.component("comp1").physics("solid").feature("lemm2").create("iss1", "InitialStressandStrain", 2);

//    In the Settings window for Initial Stress and Strain, locate the Initial Stress and Strain section.
//    Specify the \[\textrm{S}_{0}\] matrix as

    model.component("comp1").physics("solid").feature("lemm2").feature("iss1")
         .set("Sil", new String[]{"-s11P", "-s12P", "0", "-s12P", "-s22P", "0", "0", "0", "0"});
    model.component("comp1").physics("solid").feature("lemm2").feature("iss1")
         .set("eil", new String[]{"-eps11P", "0", "0", "0", "0", "0", "0", "0", "0"});

//    Specify the \[\epsilon_{0}\] matrix as

    model.component("comp1").physics("solid").feature("lemm2").feature("iss1")
         .set("eil", new String[]{"-eps11P", "-eps12P", "0", "-eps12P", "-eps22P", "0", "0", "0", "0"});

//    Add also the body force.
//    In the Physics toolbar, click Domains and choose Body Load.

    model.component("comp1").physics("solid").create("bl1", "BodyLoad", 2);

//    In the Settings window for Body Load, type Body Load (Elastic Inclusion), P Wave in the Label text field.

    model.component("comp1").physics("solid").feature("bl1").label("Body Load (Elastic Inclusion), P Wave");

//    Select Domain 25.

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

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

    model.component("comp1").physics("solid").feature("bl1")
         .set("forceReferenceVolume", new String[]{"(rho-rho_o)*(-omega^2)*uP", "(rho-rho_o)*(-omega^2)*vP", "0"});

//    In the Mesh toolbar, click Mapped.

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

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

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

//    Select Domains 1, 2, 5, 8, 9, 10, 13, 16, 17, 18, 21, 24.

    model.component("comp1").mesh("mesh1").feature("map1").selection().set(1, 2, 5, 8, 9, 10, 13, 16, 17, 18, 21, 24);

//    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 wlengthS/6.

    model.component("comp1").mesh("mesh1").feature("size").set("hmax", "wlengthS/6");

//    In the Minimum element size text field, type wlengthS/8.

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

//    Click Build All.

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

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

    model.study("std1").label("P Wave");

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

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

//    In the Model Builder window, under 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 omega/2/pi[rad].

    model.study("std1").feature("freq").set("plist", "omega/2/pi[rad]");

//    In the Model Builder window, expand the Results node.
//    Right-click P Wave and choose Compute.

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

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

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

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

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

    model.result("pg1").label("Scattered u Field");

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

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

//    In the Title text area, type Displacement Field, X-component.

    model.result("pg1").set("title", "Displacement Field, X-component");

//    Clear the Parameter indicator text field.

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

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

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

//    Right-click Scattered u Field and choose Surface.

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

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

    model.result("pg1").feature("surf1").set("expr", "u");

//    Locate the Coloring and Style section.
//    From the Scale list, select Linear symmetric.

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

//    Right-click Surface 1 and choose Selection.

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

//    Select Domains 3, 4, 6, 7, 11, 12, 14, 15, 19, 20, 22, 23, 25.

    model.result("pg1").feature("surf1").feature("sel1").selection()
         .set(3, 4, 6, 7, 11, 12, 14, 15, 19, 20, 22, 23, 25);
    model.result("pg1").run();

//    In the Model Builder window, under Results, click Scattered u Field.
//    In the Scattered u Field 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", 0, 0, 0);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", 5, 0, 1);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", "Cavity", 0, 2);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", 12, 1, 0);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", 5, 1, 1);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", "Rigid", 1, 2);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", 24, 2, 0);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", 5, 2, 1);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", "Elastic", 2, 2);

//    In the Scattered u Field toolbar, click Plot.

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

//    Locate the Coloring and Style section.
//    From the Anchor point list, select Center.

    model.result("pg1").feature("tlan1").set("anchorpoint", "center");

//    Clear the Show point checkbox.

    model.result("pg1").feature("tlan1").set("showpoint", false);
    model.result("pg1").run();

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Model Builder window, collapse the Surface 1 node.
//    In the Model Builder window, collapse the Results > Scattered u Field node.

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

//    In the Model Builder window, right-click Scattered u Field and choose Duplicate.

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

//    In the Model Builder window, click Scattered u Field 1.
//    In the Settings window for 2D Plot Group, type Scattered v Field in the Label text field.

    model.result("pg2").label("Scattered v Field");

//    Locate the Title section.
//    In the Title text area, type Displacement Field, Y-component.

    model.result("pg2").set("title", "Displacement Field, Y-component");
    model.result("pg2").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 v.

    model.result("pg2").feature("surf1").set("expr", "v");

//    In the Scattered v Field toolbar, click Plot.

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

//    In the Model Builder window, collapse the Results > Scattered v Field node.

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

//    In the Model Builder window, right-click Scattered v Field and choose Duplicate.

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

//    In the Model Builder window, click Scattered v Field 1.
//    In the Settings window for 2D Plot Group, type Scattered Displacement Field Magnitude in the Label text field.

    model.result("pg3").label("Scattered Displacement Field Magnitude");

//    Locate the Title section.
//    In the Title text area, type Displacement Magnitude.

    model.result("pg3").set("title", "Displacement Magnitude");
    model.result("pg3").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 solid.disp.

    model.result("pg3").feature("surf1").set("expr", "solid.disp");

//    In the Scattered Displacement Field Magnitude toolbar, click Plot.

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

//    Locate the Coloring and Style section.
//    From the Scale list, select Linear.

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

//    From the Color table list, select SpectrumLight.

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

//    In the Model Builder window, right-click Scattered Displacement Field Magnitude and choose Duplicate.

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

//    In the Model Builder window, collapse the Results > Scattered Displacement Field Magnitude node.
//    Apply the divergence to the displacement field to highlight P waves only.
//    In the Model Builder window, under Results, click Scattered Displacement Field Magnitude 1.
//    In the Settings window for 2D Plot Group, type Scattered P Wave in the Label text field.

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

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

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

//    In the Model Builder window, expand the Scattered P Wave node, then click Surface 1.
//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type d(u,x)+d(v,y).

    model.result("pg4").feature("surf1").set("expr", "d(u,x)+d(v,y)");

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

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

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

    model.result("pg4").feature("surf1").set("colortable", "Wave");

//    From the Scale list, select Linear symmetric.

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

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

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

//    Apply the curl to the displacement field to highlight S waves only.

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

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

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

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

    model.result("pg5").label("Scattered S Wave");

//    In the Model Builder window, collapse the Results > Scattered P Wave node.

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

//    In the Model Builder window, expand the Results > Scattered S Wave node, then click Surface 1.
//    In the Settings window for Surface, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Solid Mechanics > Displacement > Curl of displacement (material and geometry frames) > solid.curlUZ - Curl of displacement, Z-component.

    model.result("pg5").feature("surf1").set("expr", "solid.curlUZ");
    model.result("pg5").feature("surf1").set("descr", "Curl of displacement, Z-component");

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

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

//    In the Model Builder window, collapse the Results > Scattered S Wave node.

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

//    In the Model Builder window, right-click Scattered Displacement Field Magnitude and choose Duplicate.

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

//    Add the incident field to the scattered to obtain the total displacement.
//    In the Settings window for 2D Plot Group, type Total Displacement Field Magnitude in the Label text field.

    model.result("pg6").label("Total Displacement Field Magnitude");

//    Locate the Title section.
//    In the Title text area, type Total Displacement Magnitude.

    model.result("pg6").set("title", "Total Displacement Magnitude");
    model.result("pg6").run();

//    In the Model Builder window, expand the Total Displacement Field Magnitude node, then click Surface 1.
//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type sqrt((real(u+uP))^2+(real(v+vP))^2).

    model.result("pg6").feature("surf1").set("expr", "sqrt((real(u+uP))^2+(real(v+vP))^2)");

//    In the Total Displacement Field Magnitude toolbar, click Plot.

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

//    In the Model Builder window, collapse the Results > Total Displacement Field Magnitude node.

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

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

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

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

    model.result("pg7").label("Total P Wave");
    model.result("pg7").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(u+uP,x)+d(v+vP,y).

    model.result("pg7").feature("surf1").set("expr", "d(u+uP,x)+d(v+vP,y)");

//    In the Model Builder window, collapse the Results > Total P Wave node.

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

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

    model.result().duplicate("pg8", "pg5");
    model.result("pg8").run();

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

    model.result("pg8").label("Total S Wave");
    model.result("pg8").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(v+vP,x)-d(u+uP,y).

    model.result("pg8").feature("surf1").set("expr", "d(v+vP,x)-d(u+uP,y)");

//    In the Total S Wave toolbar, click Plot.

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

//    Now analyze the case of impinging S wave.
//    In the Model Builder window, right-click Incident P Wave and choose Duplicate.

    model.component("comp1").variable().duplicate("var2", "var1");

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

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

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

    model.component("comp1").variable("var2").rename("uP", "uS");
    model.component("comp1").variable("var2").set("uS", "0[m]");
    model.component("comp1").variable("var2").rename("vP", "vS");
    model.component("comp1").variable("var2").set("vS", "exp(-1i*kS*x-1i*pi/2+1i*phase)[m]");
    model.component("comp1").variable("var2").rename("eps11P", "eps11S");
    model.component("comp1").variable("var2").set("eps11S", "d(uS,x)");
    model.component("comp1").variable("var2").rename("eps22P", "eps22S");
    model.component("comp1").variable("var2").set("eps22S", "d(vS,y)");
    model.component("comp1").variable("var2").rename("eps12P", "eps12S");
    model.component("comp1").variable("var2").set("eps12S", "0.5*(d(uS,y)+d(vS,x))");
    model.component("comp1").variable("var2").rename("s11P", "s11S");
    model.component("comp1").variable("var2").set("s11S", "(lambLame+2*muLame)*eps11S+lambLame*eps22S");
    model.component("comp1").variable("var2").rename("s22P", "s22S");
    model.component("comp1").variable("var2").set("s22S", "lambLame*eps11S+(lambLame+2*muLame)*eps22S");
    model.component("comp1").variable("var2").rename("s12P", "s12S");
    model.component("comp1").variable("var2").set("s12S", "2*muLame*eps12S");

    return model;
  }

  public static Model run2(Model model) {

//    In the Model Builder window, under Component 1 (comp1) > Solid Mechanics (solid), Ctrl-click to select Cavity Inclusion, P Wave, Infinitely Rigid Inclusion, P Wave, Elastic Inclusion, P Wave, Body Load (Elastic Inclusion), P Wave.
//    Right-click and choose Group.

    model.nodeGroup().create("grp1", "Physics", "solid");
    model.nodeGroup("grp1").placeAfter("dgcnt1");
    model.nodeGroup("grp1").add("bndl1");
    model.nodeGroup("grp1").add("disp1");
    model.nodeGroup("grp1").add("lemm2");
    model.nodeGroup("grp1").add("bl1");

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

    model.nodeGroup("grp1").label("P Wave");

//    Right-click P Wave and choose Duplicate.

    model.nodeGroup().duplicate("grp2", "grp1");

//    In the Model Builder window, collapse the Component 1 (comp1) > Solid Mechanics (solid) > P Wave node.
//    In the Model Builder window, under Component 1 (comp1) > Solid Mechanics (solid), click P Wave 1.
//    In the Settings window for Group, type S Wave in the Label text field.

    model.nodeGroup("grp2").label("S Wave");

//    In the Model Builder window, expand the S Wave node, then click Cavity Inclusion, P Wave 1.
//    In the Settings window for Boundary Load, type Cavity Inclusion, S Wave in the Label text field.

    model.component("comp1").physics("solid").feature("bndl2").label("Cavity Inclusion, S Wave");

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

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

//    In the Model Builder window, under Component 1 (comp1) > Solid Mechanics (solid) > S Wave, click Infinitely Rigid Inclusion, P Wave 1.
//    In the Settings window for Prescribed Displacement, type Infinitely Rigid Inclusion, S Wave in the Label text field.

    model.component("comp1").physics("solid").feature("disp2").label("Infinitely Rigid Inclusion, S Wave");

//    Locate the Prescribed Displacement section.
//    In the \[u_{\, 0 \, x}\] text field, type -uS.

    model.component("comp1").physics("solid").feature("disp2").setIndex("U0", "-uS", 0);

//    In the \[u_{\, 0 \, y}\] text field, type -vS.

    model.component("comp1").physics("solid").feature("disp2").setIndex("U0", "-vS", 1);

//    In the Model Builder window, expand the Component 1 (comp1) > Solid Mechanics (solid) > S Wave > Elastic Inclusion, P Wave 1 node, then click Elastic Inclusion, P Wave 1.
//    In the Settings window for Linear Elastic Material, type Elastic Inclusion, S Wave in the Label text field.

    model.component("comp1").physics("solid").feature("lemm3").label("Elastic Inclusion, S Wave");

//    In the Model Builder window, under Component 1 (comp1) > Solid Mechanics (solid) > S Wave > Elastic Inclusion, S Wave, click Initial Stress and Strain 1.
//    In the Settings window for Initial Stress and Strain, type Initial Stress and Strain in the Label text field.

    model.component("comp1").physics("solid").feature("lemm3").feature("iss1").label("Initial Stress and Strain");

//    Locate the Initial Stress and Strain section.
//    Specify the \[\textrm{S}_{0}\] matrix as

    model.component("comp1").physics("solid").feature("lemm3").feature("iss1")
         .set("Sil", new String[]{"-s11S", "-s12S", "0", "-s12S", "-s22S", "0", "0", "0", "0"});
    model.component("comp1").physics("solid").feature("lemm3").feature("iss1")
         .set("eil", new String[]{"-eps11S", "-eps12P", "0", "-eps12P", "-eps22P", "0", "0", "0", "0"});

//    Specify the \[\epsilon_{0}\] matrix as

    model.component("comp1").physics("solid").feature("lemm3").feature("iss1")
         .set("eil", new String[]{"-eps11S", "-eps12S", "0", "-eps12S", "-eps22S", "0", "0", "0", "0"});

//    In the Model Builder window, under Component 1 (comp1) > Solid Mechanics (solid) > S Wave, click Body Load (Elastic Inclusion), P Wave 1.
//    In the Settings window for Body Load, type Body Load (Elastic Inclusion), S Wave in the Label text field.

    model.component("comp1").physics("solid").feature("bl2").label("Body Load (Elastic Inclusion), S Wave");

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

    model.component("comp1").physics("solid").feature("bl2")
         .set("forceReferenceVolume", new String[]{"(rho-rho_o)*(-omega^2)*uS", "(rho-rho_o)*(-omega^2)*vS", "0"});

//    In the Model Builder window, collapse the Component 1 (comp1) > Solid Mechanics (solid) > S Wave > Elastic Inclusion, S Wave node.
//    In the Model Builder window, collapse the Component 1 (comp1) > Solid Mechanics (solid) > S Wave node.
//    Modify the previous study to include only the desired boundary conditions for future reruns.
//    In the Model Builder window, under P Wave, click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Physics and Variables Selection section.
//    Select the Modify model configuration for study step checkbox.

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

//    In the tree, select Component 1 (comp1) > Solid Mechanics (solid) > S Wave.
//    Click Disable.

    model.study("std1").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl2", "solid/lemm3", "solid/disp2", "solid/bndl2"});

//    In the Model Builder window, collapse the 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("std2");
    model.study("std2").create("freq", "Frequency");

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

    model.study("std2").label("S Wave");

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

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

//    In the Model Builder window, under 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 omega/2/pi[rad].

    model.study("std2").feature("freq").set("plist", "omega/2/pi[rad]");

//    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 Component 1 (comp1) > Solid Mechanics (solid) > P Wave.
//    Click Disable.

    model.study("std2").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl1", "solid/lemm2", "solid/disp1", "solid/bndl1"});

//    In the Study toolbar, click Compute.

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

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

//    In the Study toolbar, click Add Study to close the Add Study window.
//    Add the results for the incident S wave near those obtained for the P wave.

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

//    In the Model Builder window, under Results, click Scattered u Field.
//    In the Settings window for 2D Plot Group, click to expand the Plot Array section.
//    From the Array type list, select Linear.

    model.result("pg1").set("plotarraytype", "linear");

//    From the Array axis list, select y.

    model.result("pg1").set("arrayaxis", "y");
    model.result("pg1").run();

//    In the Model Builder window, expand the Scattered u Field node, then click Surface 1.
//    In the Settings window for Surface, type Incident P Wave in the Label text field.

    model.result("pg1").feature("surf1").label("Incident P Wave");

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

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

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

    model.result("pg1").feature("surf2").label("Incident S Wave");

//    Locate the Data section.
//    From the Dataset list, select S Wave/Solution 2 (sol2).

    model.result("pg1").feature("surf2").set("data", "dset2");

//    In the Scattered u Field toolbar, click Plot.

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

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

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

//    In the Model Builder window, click Table Annotation 1.
//    In the Settings window for Table Annotation, locate the Data section.
//    In the table, enter the following settings:

    model.result("pg1").feature("tlan1").setIndex("localtablematrix", 0, 3, 0);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", 15.5, 3, 1);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", "Cavity", 3, 2);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", 12, 4, 0);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", 15.5, 4, 1);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", "Rigid", 4, 2);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", 24, 5, 0);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", 15.5, 5, 1);
    model.result("pg1").feature("tlan1").setIndex("localtablematrix", "Elastic", 5, 2);
    model.result("pg1").run();

//    In the Model Builder window, click Scattered u Field.
//    In the Scattered u Field toolbar, click More Plots and choose Table Annotation.

    model.result("pg1").create("tlan2", "TableAnnotation");

//    In the Settings window for Table Annotation, locate the Data section.
//    From the Source list, select Local table.

    model.result("pg1").feature("tlan2").set("source", "localtable");

//    In the table, enter the following settings:

    model.result("pg1").feature("tlan2").setIndex("localtablematrix", -9, 0, 0);
    model.result("pg1").feature("tlan2").setIndex("localtablematrix", 0, 0, 1);
    model.result("pg1").feature("tlan2").setIndex("localtablematrix", "P Wave", 0, 2);
    model.result("pg1").feature("tlan2").setIndex("localtablematrix", -9, 1, 0);
    model.result("pg1").feature("tlan2").setIndex("localtablematrix", 10.5, 1, 1);
    model.result("pg1").feature("tlan2").setIndex("localtablematrix", "S Wave", 1, 2);

//    Locate the Coloring and Style section.
//    From the Anchor point list, select Middle left.

    model.result("pg1").feature("tlan2").set("anchorpoint", "middleleft");

//    Clear the Show point checkbox.

    model.result("pg1").feature("tlan2").set("showpoint", false);

//    In the Scattered u Field toolbar, click Plot.

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

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

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

//    In the Model Builder window, click Incident P Wave.
//    In the Settings window for Surface, click to expand the Range section.
//    Select the Manual color range checkbox.

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

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

    model.result("pg1").feature("surf1").set("rangecolormin", -1.5);

//    In the Maximum text field, type 1.5.

    model.result("pg1").feature("surf1").set("rangecolormax", 1.5);
    model.result("pg1").run();

//    In the Model Builder window, click Incident S Wave.
//    In the Settings window for Surface, click to expand the Inherit Style section.
//    From the Plot list, select Incident P Wave.

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

//    In the Scattered u Field toolbar, click Plot.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Model Builder window, click Scattered u Field.
//    In the Settings window for 2D Plot Group, locate the Plot Settings section.
//    From the View list, select New view.

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

//    In the Scattered u Field toolbar, click Plot.

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

//    In the Model Builder window, click Scattered v Field.
//    In the Settings window for 2D Plot Group, locate the Plot Array section.
//    From the Array type list, select Linear.

    model.result("pg2").set("plotarraytype", "linear");

//    From the Array axis list, select y.

    model.result("pg2").set("arrayaxis", "y");
    model.result("pg2").run();

//    In the Model Builder window, expand the Scattered v Field node, then click Surface 1.
//    In the Settings window for Surface, type Incident P Wave in the Label text field.

    model.result("pg2").feature("surf1").label("Incident P Wave");

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

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

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

    model.result("pg2").feature("surf2").label("Incident S Wave");

//    Locate the Data section.
//    From the Dataset list, select S Wave/Solution 2 (sol2).

    model.result("pg2").feature("surf2").set("data", "dset2");
    model.result("pg2").run();

//    In the Model Builder window, click Incident P Wave.
//    In the Settings window for Surface, locate the Range section.
//    Select the Manual color range checkbox.

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

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

    model.result("pg2").feature("surf1").set("rangecolormin", -1.5);

//    In the Maximum text field, type 1.5.

    model.result("pg2").feature("surf1").set("rangecolormax", 1.5);
    model.result("pg2").run();

//    In the Model Builder window, click Incident S Wave.
//    In the Settings window for Surface, locate the Inherit Style section.
//    From the Plot list, select Incident P Wave.

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

//    In the Model Builder window, click Table Annotation 1.
//    In the Settings window for Table Annotation, locate the Data section.
//    In the table, enter the following settings:

    model.result("pg2").feature("tlan1").setIndex("localtablematrix", 0, 3, 0);
    model.result("pg2").feature("tlan1").setIndex("localtablematrix", 15.5, 3, 1);
    model.result("pg2").feature("tlan1").setIndex("localtablematrix", "Cavity", 3, 2);
    model.result("pg2").feature("tlan1").setIndex("localtablematrix", 12, 4, 0);
    model.result("pg2").feature("tlan1").setIndex("localtablematrix", 15.5, 4, 1);
    model.result("pg2").feature("tlan1").setIndex("localtablematrix", "Rigid", 4, 2);
    model.result("pg2").feature("tlan1").setIndex("localtablematrix", 24, 5, 0);
    model.result("pg2").feature("tlan1").setIndex("localtablematrix", 15.5, 5, 1);
    model.result("pg2").feature("tlan1").setIndex("localtablematrix", "Elastic", 5, 2);
    model.result("pg2").run();

//    In the Model Builder window, click Scattered v Field.
//    In the Scattered v Field toolbar, click More Plots and choose Table Annotation.

    model.result("pg2").create("tlan2", "TableAnnotation");

//    In the Settings window for Table Annotation, locate the Data section.
//    From the Source list, select Local table.

    model.result("pg2").feature("tlan2").set("source", "localtable");

//    In the table, enter the following settings:

    model.result("pg2").feature("tlan2").setIndex("localtablematrix", -9, 0, 0);
    model.result("pg2").feature("tlan2").setIndex("localtablematrix", 0, 0, 1);
    model.result("pg2").feature("tlan2").setIndex("localtablematrix", "P Wave", 0, 2);
    model.result("pg2").feature("tlan2").setIndex("localtablematrix", -9, 1, 0);
    model.result("pg2").feature("tlan2").setIndex("localtablematrix", 10.5, 1, 1);
    model.result("pg2").feature("tlan2").setIndex("localtablematrix", "S Wave", 1, 2);

//    Locate the Coloring and Style section.
//    From the Anchor point list, select Middle left.

    model.result("pg2").feature("tlan2").set("anchorpoint", "middleleft");

//    Clear the Show point checkbox.

    model.result("pg2").feature("tlan2").set("showpoint", false);

//    In the Scattered v Field toolbar, click Plot.

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

//    In the Model Builder window, click Scattered v Field.
//    Click Plot.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Settings window for 2D Plot Group, locate the Plot Settings section.
//    From the View list, select View 2D 2.

    model.result("pg2").set("view", "view2");
    model.result("pg3").run();

//    In the Model Builder window, click Scattered Displacement Field Magnitude.
//    In the Settings window for 2D Plot Group, locate the Plot Array section.
//    From the Array type list, select Linear.

    model.result("pg3").set("plotarraytype", "linear");

//    From the Array axis list, select y.

    model.result("pg3").set("arrayaxis", "y");
    model.result("pg3").run();

//    In the Model Builder window, expand the Scattered Displacement Field Magnitude node, then click Surface 1.
//    In the Settings window for Surface, type Incident P Wave in the Label text field.

    model.result("pg3").feature("surf1").label("Incident P Wave");

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

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

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

    model.result("pg3").feature("surf2").label("Incident S Wave");

//    Locate the Data section.
//    From the Dataset list, select S Wave/Solution 2 (sol2).

    model.result("pg3").feature("surf2").set("data", "dset2");
    model.result("pg3").run();

//    In the Model Builder window, click Incident P Wave.
//    In the Settings window for Surface, locate the Range section.
//    Select the Manual color range checkbox.

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

//    In the Minimum text field, type 0.

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

//    In the Maximum text field, type 2.5.

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

//    In the Model Builder window, click Incident S Wave.
//    In the Settings window for Surface, click to collapse the Inherit Style section.
//    Click to expand the Inherit Style section.
//    From the Plot list, select Incident P Wave.

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

//    In the Model Builder window, click Table Annotation 1.
//    In the Settings window for Table Annotation, locate the Data section.
//    In the table, enter the following settings:

    model.result("pg3").feature("tlan1").setIndex("localtablematrix", 0, 3, 0);
    model.result("pg3").feature("tlan1").setIndex("localtablematrix", 15.5, 3, 1);
    model.result("pg3").feature("tlan1").setIndex("localtablematrix", "Cavity", 3, 2);
    model.result("pg3").feature("tlan1").setIndex("localtablematrix", 12, 4, 0);
    model.result("pg3").feature("tlan1").setIndex("localtablematrix", 15.5, 4, 1);
    model.result("pg3").feature("tlan1").setIndex("localtablematrix", "Rigid", 4, 2);
    model.result("pg3").feature("tlan1").setIndex("localtablematrix", 24, 5, 0);
    model.result("pg3").feature("tlan1").setIndex("localtablematrix", 15.5, 5, 1);
    model.result("pg3").feature("tlan1").setIndex("localtablematrix", "Elastic", 5, 2);
    model.result("pg3").run();

//    In the Model Builder window, click Scattered Displacement Field Magnitude.
//    In the Scattered Displacement Field Magnitude toolbar, click More Plots and choose Table Annotation.

    model.result("pg3").create("tlan2", "TableAnnotation");

//    In the Settings window for Table Annotation, locate the Data section.
//    From the Source list, select Local table.

    model.result("pg3").feature("tlan2").set("source", "localtable");

//    In the table, enter the following settings:

    model.result("pg3").feature("tlan2").setIndex("localtablematrix", -9, 0, 0);
    model.result("pg3").feature("tlan2").setIndex("localtablematrix", 0, 0, 1);
    model.result("pg3").feature("tlan2").setIndex("localtablematrix", "P Wave", 0, 2);
    model.result("pg3").feature("tlan2").setIndex("localtablematrix", -9, 1, 0);
    model.result("pg3").feature("tlan2").setIndex("localtablematrix", 10.5, 1, 1);
    model.result("pg3").feature("tlan2").setIndex("localtablematrix", "S Wave", 1, 2);

//    Locate the Coloring and Style section.
//    From the Anchor point list, select Middle left.

    model.result("pg3").feature("tlan2").set("anchorpoint", "middleleft");

//    Clear the Show point checkbox.

    model.result("pg3").feature("tlan2").set("showpoint", false);

//    In the Scattered Displacement Field Magnitude toolbar, click Plot.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Model Builder window, click Scattered Displacement Field Magnitude.
//    In the Settings window for 2D Plot Group, locate the Plot Settings section.
//    From the View list, select View 2D 2.

    model.result("pg3").set("view", "view2");
    model.result("pg4").run();

//    In the Model Builder window, expand the Results > Scattered P Wave node, then click Scattered P Wave.
//    In the Settings window for 2D Plot Group, locate the Plot Array section.
//    From the Array type list, select Linear.

    model.result("pg4").set("plotarraytype", "linear");

//    From the Array axis list, select y.

    model.result("pg4").set("arrayaxis", "y");
    model.result("pg4").run();

//    In the Model Builder window, under Results > Scattered P Wave, click Surface 1.
//    In the Settings window for Surface, type Incident P Wave in the Label text field.

    model.result("pg4").feature("surf1").label("Incident P Wave");

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

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

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

    model.result("pg4").feature("surf2").label("Incident S Wave");

//    Locate the Data section.
//    From the Dataset list, select S Wave/Solution 2 (sol2).

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

//    In the Model Builder window, click Table Annotation 1.
//    In the Settings window for Table Annotation, locate the Data section.
//    In the table, enter the following settings:

    model.result("pg4").feature("tlan1").setIndex("localtablematrix", 0, 3, 0);
    model.result("pg4").feature("tlan1").setIndex("localtablematrix", 15.5, 3, 1);
    model.result("pg4").feature("tlan1").setIndex("localtablematrix", "Cavity", 3, 2);
    model.result("pg4").feature("tlan1").setIndex("localtablematrix", 12, 4, 0);
    model.result("pg4").feature("tlan1").setIndex("localtablematrix", 15.5, 4, 1);
    model.result("pg4").feature("tlan1").setIndex("localtablematrix", "Rigid", 4, 2);
    model.result("pg4").feature("tlan1").setIndex("localtablematrix", 24, 5, 0);
    model.result("pg4").feature("tlan1").setIndex("localtablematrix", 15.5, 5, 1);
    model.result("pg4").feature("tlan1").setIndex("localtablematrix", "Elastic", 5, 2);
    model.result("pg4").run();

//    In the Model Builder window, click Scattered P Wave.
//    In the Scattered P Wave toolbar, click More Plots and choose Table Annotation.

    model.result("pg4").create("tlan2", "TableAnnotation");

//    In the Settings window for Table Annotation, locate the Data section.
//    From the Source list, select Local table.

    model.result("pg4").feature("tlan2").set("source", "localtable");

//    In the table, enter the following settings:

    model.result("pg4").feature("tlan2").setIndex("localtablematrix", -9, 0, 0);
    model.result("pg4").feature("tlan2").setIndex("localtablematrix", 0, 0, 1);
    model.result("pg4").feature("tlan2").setIndex("localtablematrix", "P Wave", 0, 2);
    model.result("pg4").feature("tlan2").setIndex("localtablematrix", -9, 1, 0);
    model.result("pg4").feature("tlan2").setIndex("localtablematrix", 10.5, 1, 1);
    model.result("pg4").feature("tlan2").setIndex("localtablematrix", "S Wave", 1, 2);

//    Locate the Coloring and Style section.
//    From the Anchor point list, select Middle left.

    model.result("pg4").feature("tlan2").set("anchorpoint", "middleleft");

//    Clear the Show point checkbox.

    model.result("pg4").feature("tlan2").set("showpoint", false);

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

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Model Builder window, click Scattered P Wave.
//    In the Settings window for 2D Plot Group, locate the Plot Settings section.
//    From the View list, select View 2D 2.

    model.result("pg4").set("view", "view2");
    model.result("pg5").run();

//    In the Model Builder window, click Scattered S Wave.
//    In the Settings window for 2D Plot Group, locate the Plot Array section.
//    From the Array type list, select Linear.

    model.result("pg5").set("plotarraytype", "linear");

//    From the Array axis list, select y.

    model.result("pg5").set("arrayaxis", "y");
    model.result("pg5").run();

//    In the Model Builder window, expand the Scattered S Wave node, then click Surface 1.
//    In the Settings window for Surface, type Incident P Wave in the Label text field.

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

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

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

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

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

//    Locate the Data section.
//    From the Dataset list, select S Wave/Solution 2 (sol2).

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

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

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

//    In the Model Builder window, click Table Annotation 1.
//    In the Settings window for Table Annotation, locate the Data section.
//    In the table, enter the following settings:

    model.result("pg5").feature("tlan1").setIndex("localtablematrix", 0, 3, 0);
    model.result("pg5").feature("tlan1").setIndex("localtablematrix", 15.5, 3, 1);
    model.result("pg5").feature("tlan1").setIndex("localtablematrix", "Cavity", 3, 2);
    model.result("pg5").feature("tlan1").setIndex("localtablematrix", 12, 4, 0);
    model.result("pg5").feature("tlan1").setIndex("localtablematrix", 15.5, 4, 1);
    model.result("pg5").feature("tlan1").setIndex("localtablematrix", "Rigid", 4, 2);
    model.result("pg5").feature("tlan1").setIndex("localtablematrix", 24, 5, 0);
    model.result("pg5").feature("tlan1").setIndex("localtablematrix", 15.5, 5, 1);
    model.result("pg5").feature("tlan1").setIndex("localtablematrix", "Elastic", 5, 2);
    model.result("pg5").run();

//    In the Model Builder window, click Scattered S Wave.
//    In the Scattered S Wave toolbar, click More Plots and choose Table Annotation.

    model.result("pg5").create("tlan2", "TableAnnotation");

//    In the Settings window for Table Annotation, locate the Data section.
//    From the Source list, select Local table.

    model.result("pg5").feature("tlan2").set("source", "localtable");

//    In the table, enter the following settings:

    model.result("pg5").feature("tlan2").setIndex("localtablematrix", -9, 0, 0);
    model.result("pg5").feature("tlan2").setIndex("localtablematrix", 0, 0, 1);
    model.result("pg5").feature("tlan2").setIndex("localtablematrix", "P Wave", 0, 2);
    model.result("pg5").feature("tlan2").setIndex("localtablematrix", -9, 1, 0);
    model.result("pg5").feature("tlan2").setIndex("localtablematrix", 10.5, 1, 1);
    model.result("pg5").feature("tlan2").setIndex("localtablematrix", "S Wave", 1, 2);

//    Locate the Coloring and Style section.
//    From the Anchor point list, select Middle left.

    model.result("pg5").feature("tlan2").set("anchorpoint", "middleleft");

//    Clear the Show point checkbox.

    model.result("pg5").feature("tlan2").set("showpoint", false);

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

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Model Builder window, click Scattered S Wave.
//    In the Settings window for 2D Plot Group, locate the Plot Settings section.
//    From the View list, select View 2D 2.

    model.result("pg5").set("view", "view2");
    model.result("pg6").run();

//    In the Model Builder window, expand the Results > Total Displacement Field Magnitude node, then click Total Displacement Field Magnitude.
//    In the Settings window for 2D Plot Group, locate the Plot Array section.
//    From the Array type list, select Linear.

    model.result("pg6").set("plotarraytype", "linear");

//    From the Array axis list, select y.

    model.result("pg6").set("arrayaxis", "y");
    model.result("pg6").run();

//    In the Model Builder window, under Results > Total Displacement Field Magnitude, click Surface 1.
//    In the Settings window for Surface, type Incident P Wave in the Label text field.

    model.result("pg6").feature("surf1").label("Incident P Wave");

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

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

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

    model.result("pg6").feature("surf2").label("Incident S Wave");

//    Locate the Data section.
//    From the Dataset list, select S Wave/Solution 2 (sol2).

    model.result("pg6").feature("surf2").set("data", "dset2");

//    Locate the Expression section.
//    In the Expression text field, type sqrt((real(u+uS))^2+(real(v+vS))^2).

    model.result("pg6").feature("surf2").set("expr", "sqrt((real(u+uS))^2+(real(v+vS))^2)");
    model.result("pg6").run();

//    In the Model Builder window, click Table Annotation 1.
//    In the Settings window for Table Annotation, locate the Data section.
//    In the table, enter the following settings:

    model.result("pg6").feature("tlan1").setIndex("localtablematrix", 0, 3, 0);
    model.result("pg6").feature("tlan1").setIndex("localtablematrix", 15.5, 3, 1);
    model.result("pg6").feature("tlan1").setIndex("localtablematrix", "Cavity", 3, 2);
    model.result("pg6").feature("tlan1").setIndex("localtablematrix", 12, 4, 0);
    model.result("pg6").feature("tlan1").setIndex("localtablematrix", 15.5, 4, 1);
    model.result("pg6").feature("tlan1").setIndex("localtablematrix", "Rigid", 4, 2);
    model.result("pg6").feature("tlan1").setIndex("localtablematrix", 24, 5, 0);
    model.result("pg6").feature("tlan1").setIndex("localtablematrix", 15.5, 5, 1);
    model.result("pg6").feature("tlan1").setIndex("localtablematrix", "Elastic", 5, 2);
    model.result("pg6").run();

//    In the Model Builder window, click Total Displacement Field Magnitude.
//    In the Total Displacement Field Magnitude toolbar, click More Plots and choose Table Annotation.

    model.result("pg6").create("tlan2", "TableAnnotation");

//    In the Settings window for Table Annotation, locate the Data section.
//    From the Source list, select Local table.

    model.result("pg6").feature("tlan2").set("source", "localtable");

//    In the table, enter the following settings:

    model.result("pg6").feature("tlan2").setIndex("localtablematrix", -9, 0, 0);
    model.result("pg6").feature("tlan2").setIndex("localtablematrix", 0, 0, 1);
    model.result("pg6").feature("tlan2").setIndex("localtablematrix", "P Wave", 0, 2);
    model.result("pg6").feature("tlan2").setIndex("localtablematrix", -9, 1, 0);

    return model;
  }

  public static Model run3(Model model) {
    model.result("pg6").feature("tlan2").setIndex("localtablematrix", 10.5, 1, 1);
    model.result("pg6").feature("tlan2").setIndex("localtablematrix", "S Wave", 1, 2);

//    Locate the Coloring and Style section.
//    From the Anchor point list, select Middle left.

    model.result("pg6").feature("tlan2").set("anchorpoint", "middleleft");

//    Clear the Show point checkbox.

    model.result("pg6").feature("tlan2").set("showpoint", false);

//    In the Total Displacement Field Magnitude toolbar, click Plot.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Model Builder window, click Total Displacement Field Magnitude.
//    In the Settings window for 2D Plot Group, locate the Plot Settings section.
//    From the View list, select View 2D 2.

    model.result("pg6").set("view", "view2");
    model.result("pg7").run();

//    In the Model Builder window, expand the Results > Total P Wave node, then click Total P Wave.
//    In the Settings window for 2D Plot Group, locate the Plot Array section.
//    From the Array type list, select Linear.

    model.result("pg7").set("plotarraytype", "linear");

//    From the Array axis list, select y.

    model.result("pg7").set("arrayaxis", "y");
    model.result("pg7").run();

//    In the Model Builder window, under Results > Total P Wave, click Surface 1.
//    In the Settings window for Surface, type Incident P Wave in the Label text field.

    model.result("pg7").feature("surf1").label("Incident P Wave");

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

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

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

    model.result("pg7").feature("surf2").label("Incident S Wave");

//    Locate the Data section.
//    From the Dataset list, select S Wave/Solution 2 (sol2).

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

//    Locate the Expression section.
//    In the Expression text field, type d(u+uS,x)+d(v+vS,y).

    model.result("pg7").feature("surf2").set("expr", "d(u+uS,x)+d(v+vS,y)");

//    In the Total P Wave toolbar, click Plot.

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

//    In the Model Builder window, click Table Annotation 1.
//    In the Settings window for Table Annotation, locate the Data section.
//    In the table, enter the following settings:

    model.result("pg7").feature("tlan1").setIndex("localtablematrix", 0, 3, 0);
    model.result("pg7").feature("tlan1").setIndex("localtablematrix", 15.5, 3, 1);
    model.result("pg7").feature("tlan1").setIndex("localtablematrix", "Cavity", 3, 2);
    model.result("pg7").feature("tlan1").setIndex("localtablematrix", 12, 4, 0);
    model.result("pg7").feature("tlan1").setIndex("localtablematrix", 15.5, 4, 1);
    model.result("pg7").feature("tlan1").setIndex("localtablematrix", "Rigid", 4, 2);
    model.result("pg7").feature("tlan1").setIndex("localtablematrix", 24, 5, 0);
    model.result("pg7").feature("tlan1").setIndex("localtablematrix", 15.5, 5, 1);
    model.result("pg7").feature("tlan1").setIndex("localtablematrix", "Elastic", 5, 2);
    model.result("pg7").run();

//    In the Model Builder window, click Total P Wave.
//    In the Total P Wave toolbar, click More Plots and choose Table Annotation.

    model.result("pg7").create("tlan2", "TableAnnotation");

//    In the Settings window for Table Annotation, locate the Data section.
//    From the Source list, select Local table.

    model.result("pg7").feature("tlan2").set("source", "localtable");

//    In the table, enter the following settings:

    model.result("pg7").feature("tlan2").setIndex("localtablematrix", -9, 0, 0);
    model.result("pg7").feature("tlan2").setIndex("localtablematrix", 0, 0, 1);
    model.result("pg7").feature("tlan2").setIndex("localtablematrix", "P Wave", 0, 2);
    model.result("pg7").feature("tlan2").setIndex("localtablematrix", -9, 1, 0);
    model.result("pg7").feature("tlan2").setIndex("localtablematrix", 10.5, 1, 1);
    model.result("pg7").feature("tlan2").setIndex("localtablematrix", "S Wave", 1, 2);

//    Locate the Coloring and Style section.
//    From the Anchor point list, select Middle left.

    model.result("pg7").feature("tlan2").set("anchorpoint", "middleleft");

//    Clear the Show point checkbox.

    model.result("pg7").feature("tlan2").set("showpoint", false);

//    In the Total P Wave toolbar, click Plot.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Model Builder window, click Total P Wave.
//    In the Settings window for 2D Plot Group, locate the Plot Settings section.
//    From the View list, select View 2D 2.

    model.result("pg7").set("view", "view2");
    model.result("pg8").run();

//    In the Model Builder window, click Total S Wave.
//    In the Settings window for 2D Plot Group, locate the Plot Array section.
//    From the Array type list, select Linear.

    model.result("pg8").set("plotarraytype", "linear");

//    From the Array axis list, select y.

    model.result("pg8").set("arrayaxis", "y");
    model.result("pg8").run();

//    In the Model Builder window, under Results > Total S Wave, click Surface 1.
//    In the Settings window for Surface, type Incident P Wave in the Label text field.

    model.result("pg8").feature("surf1").label("Incident P Wave");

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

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

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

    model.result("pg8").feature("surf2").label("Incident S Wave");

//    Locate the Data section.
//    From the Dataset list, select S Wave/Solution 2 (sol2).

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

//    Locate the Expression section.
//    In the Expression text field, type d(v+vS,x)-d(u+uS,y).

    model.result("pg8").feature("surf2").set("expr", "d(v+vS,x)-d(u+uS,y)");
    model.result("pg8").run();

//    In the Model Builder window, click Table Annotation 1.
//    In the Settings window for Table Annotation, locate the Data section.
//    In the table, enter the following settings:

    model.result("pg8").feature("tlan1").setIndex("localtablematrix", 0, 3, 0);
    model.result("pg8").feature("tlan1").setIndex("localtablematrix", 15.5, 3, 1);
    model.result("pg8").feature("tlan1").setIndex("localtablematrix", "Cavity", 3, 2);
    model.result("pg8").feature("tlan1").setIndex("localtablematrix", 12, 4, 0);
    model.result("pg8").feature("tlan1").setIndex("localtablematrix", 15.5, 4, 1);
    model.result("pg8").feature("tlan1").setIndex("localtablematrix", "Rigid", 4, 2);
    model.result("pg8").feature("tlan1").setIndex("localtablematrix", 24, 5, 0);
    model.result("pg8").feature("tlan1").setIndex("localtablematrix", 15.5, 5, 1);
    model.result("pg8").feature("tlan1").setIndex("localtablematrix", "Elastic", 5, 2);
    model.result("pg8").run();

//    In the Model Builder window, click Total S Wave.
//    In the Total S Wave toolbar, click More Plots and choose Table Annotation.

    model.result("pg8").create("tlan2", "TableAnnotation");

//    In the Settings window for Table Annotation, locate the Data section.
//    From the Source list, select Local table.

    model.result("pg8").feature("tlan2").set("source", "localtable");

//    In the table, enter the following settings:

    model.result("pg8").feature("tlan2").setIndex("localtablematrix", -9, 0, 0);
    model.result("pg8").feature("tlan2").setIndex("localtablematrix", 0, 0, 1);
    model.result("pg8").feature("tlan2").setIndex("localtablematrix", "P Wave", 0, 2);
    model.result("pg8").feature("tlan2").setIndex("localtablematrix", -9, 1, 0);
    model.result("pg8").feature("tlan2").setIndex("localtablematrix", 10.5, 1, 1);
    model.result("pg8").feature("tlan2").setIndex("localtablematrix", "S Wave", 1, 2);

//    Locate the Coloring and Style section.
//    From the Anchor point list, select Middle left.

    model.result("pg8").feature("tlan2").set("anchorpoint", "middleleft");

//    Clear the Show point checkbox.

    model.result("pg8").feature("tlan2").set("showpoint", false);

//    In the Total S Wave toolbar, click Plot.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Model Builder window, click Total S Wave.
//    In the Settings window for 2D Plot Group, locate the Plot Settings section.
//    From the View list, select View 2D 2.

    model.result("pg8").set("view", "view2");

//    In the Model Builder window, collapse the Total S Wave node.
//    In the Model Builder window, collapse the Results > Total P Wave node.
//    In the Model Builder window, collapse the Results > Total Displacement Field Magnitude node.
//    In the Model Builder window, collapse the Results > Scattered S Wave node.
//    In the Model Builder window, collapse the Results > Scattered P Wave node.
//    In the Model Builder window, collapse the Results > Scattered Displacement Field Magnitude node.
//    In the Model Builder window, collapse the Results > Scattered v Field node.
//    In the Model Builder window, collapse the Results > Scattered u Field node.

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

//    In the Model Builder window, under Results, Ctrl-click to select Scattered u Field, Scattered v Field, Scattered Displacement Field Magnitude, Scattered P Wave, Scattered S Wave, Total Displacement Field Magnitude, Total P Wave, Total S Wave.
//    Right-click and choose Group.

    model.nodeGroup().create("grp3", "Results");
    model.nodeGroup("grp3").set("type", "plotgroup");
    model.nodeGroup("grp3").add("plotgroup", "pg1");
    model.nodeGroup("grp3").add("plotgroup", "pg2");
    model.nodeGroup("grp3").add("plotgroup", "pg3");
    model.nodeGroup("grp3").add("plotgroup", "pg4");
    model.nodeGroup("grp3").add("plotgroup", "pg5");
    model.nodeGroup("grp3").add("plotgroup", "pg6");
    model.nodeGroup("grp3").add("plotgroup", "pg7");
    model.nodeGroup("grp3").add("plotgroup", "pg8");

//    In the Settings window for Group, type Plane Wave in the Label text field.

    model.nodeGroup("grp3").label("Plane Wave");

//    Add a point where to apply the point source.
//    In the Geometry toolbar, click Point.

    model.component("comp1").geom("geom1").create("pt1", "Point");

//    In the Settings window for Point, locate the Point section.
//    In the x text field, type -((R-r_layer-r_o)/2+r_o)*cos(pi/4).

    model.component("comp1").geom("geom1").feature("pt1").setIndex("p", "-((R-r_layer-r_o)/2+r_o)*cos(pi/4)", 0);

//    In the y text field, type ((R-r_layer-r_o)/2+r_o)*sin(pi/4).

    model.component("comp1").geom("geom1").feature("pt1").setIndex("p", "((R-r_layer-r_o)/2+r_o)*sin(pi/4)", 1);

//    Click Build Selected.

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

//    Drag and drop below Circle 1 (c1).

    model.component("comp1").geom("geom1").feature().move("pt1", 1);

//    Click Build Selected.

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

//    In the Model Builder window, click Array 1 (arr1).
//    Click the Select All button in the Graphics toolbar.

    model.component("comp1").geom("geom1").feature("arr1").selection("input").set("c1", "pt1");

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

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

//    In the Physics toolbar, click Points and choose Point Load.

    model.component("comp1").physics("solid").create("pl1", "PointLoad", 0);

//    Select Point 29.

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

//    In the Settings window for Point Load, locate the Force section.
//    Specify the \[\mathbf{F}_{\mathrm{P}}\] vector as

    model.component("comp1").physics("solid").feature("pl1").set("forcePoint", new int[]{1, 0, 0});

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

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

//    In the Home toolbar, click Add Study to close the Add Study window.
//    In the Settings window for Study, locate the Study Settings section.
//    Clear the Generate default plots checkbox.

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

//    In the Label text field, type Point Source Incident Field.

    model.study("std3").label("Point Source Incident Field");

//    In the Model Builder window, expand the 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 Component 1 (comp1) > Solid Mechanics (solid) > Point Load 1.
//    Click Disable.

    model.study("std1").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl2", "solid/lemm3", "solid/disp2", "solid/bndl2", "solid/pl1"});

//    In the Model Builder window, collapse the P Wave node.
//    In the Model Builder window, under S Wave, click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Physics and Variables Selection section.
//    Click Disable.

    model.study("std2").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl1", "solid/lemm2", "solid/disp1", "solid/bndl1", "solid/pl1"});

//    In the Model Builder window, collapse the S Wave node.
//    In the Model Builder window, under Point Source Incident Field, click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Study Settings section.
//    In the Frequencies text field, type omega/2/pi[rad].

    model.study("std3").feature("freq").set("plist", "omega/2/pi[rad]");

//    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 Component 1 (comp1) > Solid Mechanics (solid) > P Wave.
//    Click Disable.

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

//    In the tree, select Component 1 (comp1) > Solid Mechanics (solid) > S Wave.
//    Click Disable.

    model.study("std3").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl1", "solid/lemm2", "solid/disp1", "solid/bndl1", "solid/bl2", "solid/lemm3", "solid/disp2", "solid/bndl2"});

//    In the Study toolbar, click Compute.

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

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

//    Plot the field generated by the point source, that will be used as incident field.
//    In the Results toolbar, click 2D Plot Group.

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

//    In the Settings window for 2D Plot Group, type Point Source Background Fields in the Label text field.

    model.result("pg9").label("Point Source Background Fields");

//    Locate the Data section.
//    From the Dataset list, select Point Source Incident Field/Solution 3 (sol3).

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

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

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

//    Locate the Plot Array section.
//    From the Array type list, select Linear.

    model.result("pg9").set("plotarraytype", "linear");

//    Right-click Point Source Background Fields and choose Surface.

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

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

    model.result("pg9").feature("surf1").label("Displacement Magnitude");

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

    model.result("pg9").feature("surf1").set("colortable", "SpectrumLight");

//    Right-click Displacement Magnitude and choose Selection.

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

//    Select Domains 19, 20, 22, 23, 25.

    model.result("pg9").feature("surf1").feature("sel1").selection().set(19, 20, 22, 23, 25);

//    In the Point Source Background Fields toolbar, click Plot.

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

//    In the Model Builder window, click Displacement Magnitude.
//    In the Settings window for Surface, locate the Range section.
//    Select the Manual color range checkbox.

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

//    In the Minimum text field, type 0.

    model.result("pg9").feature("surf1").set("rangecolormin", 0);

//    In the Maximum text field, type 0.15.

    model.result("pg9").feature("surf1").set("rangecolormax", 0.15);

//    In the Point Source Background Fields toolbar, click Plot.

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

//    Right-click Displacement Magnitude and choose Duplicate.

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

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

    model.result("pg9").feature("surf2").label("P Wave");

//    Locate the Expression section.
//    In the Expression text field, type d(u,x)+d(v,y).

    model.result("pg9").feature("surf2").set("expr", "d(u,x)+d(v,y)");

//    Locate the Range section.
//    Clear the Manual color range checkbox.

    model.result("pg9").feature("surf2").set("rangecoloractive", false);

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

    model.result("pg9").feature("surf2").set("colortable", "Wave");

//    Locate the Range section.
//    Select the Manual color range checkbox.

    model.result("pg9").feature("surf2").set("rangecoloractive", true);

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

    model.result("pg9").feature("surf2").set("rangecolormin", -0.8);

//    In the Maximum text field, type 0.8.

    model.result("pg9").feature("surf2").set("rangecolormax", 0.8);

//    In the Point Source Background Fields toolbar, click Plot.

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

//    Right-click P Wave and choose Duplicate.

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

//    In the Model Builder window, expand the Results > Point Source Background Fields > P Wave node, then click Results > Point Source Background Fields > P Wave 1.
//    In the Settings window for Surface, type S Wave in the Label text field.

    model.result("pg9").feature("surf3").label("S Wave");

//    Locate the Expression section.
//    In the Expression text field, type d(v,x)-d(u,y).

    model.result("pg9").feature("surf3").set("expr", "d(v,x)-d(u,y)");

//    In the Point Source Background Fields toolbar, click Plot.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    Locate the Range section.
//    In the Minimum text field, type -4.

    model.result("pg9").feature("surf3").set("rangecolormin", -4);

//    In the Maximum text field, type 4.

    model.result("pg9").feature("surf3").set("rangecolormax", 4);

//    In the Point Source Background Fields toolbar, click Plot.

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

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

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

//    In the Model Builder window, click Point Source Background Fields.
//    In the Point Source Background Fields toolbar, click More Plots and choose Table Annotation.

    model.result("pg9").create("tlan1", "TableAnnotation");

//    In the Settings window for Table Annotation, locate the Data section.
//    From the Source list, select Local table.

    model.result("pg9").feature("tlan1").set("source", "localtable");

//    In the table, enter the following settings:

    model.result("pg9").feature("tlan1").setIndex("localtablematrix", 24, 0, 0);
    model.result("pg9").feature("tlan1").setIndex("localtablematrix", 5, 0, 1);
    model.result("pg9").feature("tlan1").setIndex("localtablematrix", "Displacement", 0, 2);
    model.result("pg9").feature("tlan1").setIndex("localtablematrix", 34.4, 1, 0);
    model.result("pg9").feature("tlan1").setIndex("localtablematrix", 5, 1, 1);
    model.result("pg9").feature("tlan1").setIndex("localtablematrix", "P Wave", 1, 2);
    model.result("pg9").feature("tlan1").setIndex("localtablematrix", 44.6, 2, 0);
    model.result("pg9").feature("tlan1").setIndex("localtablematrix", 5, 2, 1);
    model.result("pg9").feature("tlan1").setIndex("localtablematrix", "S Wave", 2, 2);

//    Locate the Coloring and Style section.
//    Clear the Show point checkbox.

    model.result("pg9").feature("tlan1").set("showpoint", false);

//    From the Anchor point list, select Center.

    model.result("pg9").feature("tlan1").set("anchorpoint", "center");

//    In the Point Source Background Fields toolbar, click Plot.

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

//    In the Model Builder window, click Point Source Background Fields.
//    In the Settings window for 2D Plot Group, locate the Title section.
//    From the Title type list, select Manual.

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

//    In the Title text area, type Point Source Background Fields.

    model.result("pg9").set("title", "Point Source Background Fields");

//    Clear the Parameter indicator text field.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Model Builder window, right-click Results > Views and choose View 2D.

    model.view().create("view3", 2);

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

//    In the Settings window for 2D Plot Group, locate the Plot Settings section.
//    From the View list, select View 2D 3.

    model.result("pg9").set("view", "view3");

//    In the Model Builder window, collapse the Results > Point Source Background Fields > P Wave node.
//    In the Model Builder window, collapse the Results > Point Source Background Fields > Displacement Magnitude node.
//    In the Model Builder window, collapse the Results > Point Source Background Fields node.
//    Set the results of the previous study to be the new incident field.
//    In the Model Builder window, right-click Incident S Wave and choose Duplicate.

    model.component("comp1").variable().duplicate("var3", "var2");

//    In the Settings window for Variables, type Point Source in the Label text field.

    model.component("comp1").variable("var3").label("Point Source");

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

    model.component("comp1").variable("var3").rename("uS", "uPS");
    model.component("comp1").variable("var3").set("uPS", "withsol('sol3',u)*exp(1i*phase)");
    model.component("comp1").variable("var3").rename("vS", "vPS");
    model.component("comp1").variable("var3").set("vPS", "withsol('sol3',v)*exp(1i*phase)");
    model.component("comp1").variable("var3").rename("eps11S", "eps11PS");
    model.component("comp1").variable("var3").set("eps11PS", "withsol('sol3',solid.el11)*exp(1i*phase)");
    model.component("comp1").variable("var3").rename("eps22S", "eps22PS");
    model.component("comp1").variable("var3").set("eps22PS", "withsol('sol3',solid.el22)*exp(1i*phase)");
    model.component("comp1").variable("var3").rename("eps12S", "eps12PS");
    model.component("comp1").variable("var3").set("eps12PS", "withsol('sol3',solid.el12)*exp(1i*phase)");
    model.component("comp1").variable("var3").rename("s11S", "s11PS");
    model.component("comp1").variable("var3").set("s11PS", "withsol('sol3',solid.sl11)*exp(1i*phase)");
    model.component("comp1").variable("var3").rename("s22S", "s22PS");
    model.component("comp1").variable("var3").set("s22PS", "withsol('sol3',solid.sl22)*exp(1i*phase)");
    model.component("comp1").variable("var3").rename("s12S", "s12PS");
    model.component("comp1").variable("var3").set("s12PS", "withsol('sol3',solid.sl12)*exp(1i*phase)");

//    Note that the point source background field is only defined on the third computational domain. Add two <l>General Extrusion</l> operators in order to make the point source background field available also for the other two computational domains.
//    In the Definitions toolbar, click Nonlocal Couplings and choose General Extrusion.

    model.component("comp1").cpl().create("genext1", "GeneralExtrusion");

//    Select Domains 17, 18, 19, 20, 21, 22, 23, 24, 25.

    model.component("comp1").cpl("genext1").selection().set(17, 18, 19, 20, 21, 22, 23, 24, 25);

//    In the Settings window for General Extrusion, locate the Destination Map section.
//    In the x-expression text field, type x+24.

    model.component("comp1").cpl("genext1").set("dstmap", new String[]{"x+24", "y"});

//    Right-click General Extrusion 1 (genext1) and choose Duplicate.

    model.component("comp1").cpl().duplicate("genext2", "genext1");

//    In the Settings window for General Extrusion, locate the Destination Map section.
//    In the x-expression text field, type x+12.

    model.component("comp1").cpl("genext2").set("dstmap", new String[]{"x+12", "y"});

//    In the Model Builder window, expand the Component 1 (comp1) > Solid Mechanics (solid) > P Wave > Cavity Inclusion, P Wave node.
//    Right-click S Wave and choose Duplicate.

    model.nodeGroup().duplicate("grp4", "grp2");

//    In the Settings window for Group, type Point Source in the Label text field.

    model.nodeGroup("grp4").label("Point Source");

//    In the Model Builder window, expand the Point Source node, then click Cavity Inclusion, S Wave 1.
//    In the Settings window for Boundary Load, type Cavity Inclusion, Point Source in the Label text field.

    model.component("comp1").physics("solid").feature("bndl3").label("Cavity Inclusion, Point Source");

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

    model.component("comp1").physics("solid").feature("bndl3")
         .set("forceReferenceArea", new String[]{"-(genext1(s11PS)*solid.nx+genext1(s12PS)*solid.ny)", "-(genext1(s12PS)*solid.nx+genext1(s22PS)*solid.ny)", "0"});

//    In the Model Builder window, under Component 1 (comp1) > Solid Mechanics (solid) > Point Source, click Infinitely Rigid Inclusion, S Wave 1.
//    In the Settings window for Prescribed Displacement, type Infinitely Rigid Inclusion, Point Source in the Label text field.

    model.component("comp1").physics("solid").feature("disp3").label("Infinitely Rigid Inclusion, Point Source");

//    Locate the Prescribed Displacement section.
//    In the \[u_{\, 0 \, x}\] text field, type -genext2(uPS).

    model.component("comp1").physics("solid").feature("disp3").setIndex("U0", "-genext2(uPS)", 0);

//    In the \[u_{\, 0 \, y}\] text field, type -genext2(vPS).

    model.component("comp1").physics("solid").feature("disp3").setIndex("U0", "-genext2(vPS)", 1);

//    In the Model Builder window, expand the Component 1 (comp1) > Solid Mechanics (solid) > Point Source > Elastic Inclusion, S Wave 1 node, then click Elastic Inclusion, S Wave 1.
//    In the Settings window for Linear Elastic Material, type Elastic Inclusion, Point Source in the Label text field.

    model.component("comp1").physics("solid").feature("lemm4").label("Elastic Inclusion, Point Source");

//    In the Model Builder window, click Initial Stress and Strain.
//    In the Settings window for Initial Stress and Strain, locate the Initial Stress and Strain section.
//    Specify the \[\textrm{S}_{0}\] matrix as

    model.component("comp1").physics("solid").feature("lemm4").feature("iss1")
         .set("Sil", new String[]{"-s11PS", "-s12PS", "0", "-s12PS", "-s22PS", "0", "0", "0", "0"});
    model.component("comp1").physics("solid").feature("lemm4").feature("iss1")
         .set("eil", new String[]{"-eps11PS", "-eps12S", "0", "-eps12S", "-eps22S", "0", "0", "0", "0"});

//    Specify the \[\epsilon_{0}\] matrix as

    model.component("comp1").physics("solid").feature("lemm4").feature("iss1")
         .set("eil", new String[]{"-eps11PS", "-eps12PS", "0", "-eps12PS", "-eps22PS", "0", "0", "0", "0"});

//    In the Model Builder window, under Component 1 (comp1) > Solid Mechanics (solid) > Point Source, click Body Load (Elastic Inclusion), S Wave 1.
//    In the Settings window for Body Load, type Body load (Elastic Inclusion), Point Source in the Label text field.

    model.component("comp1").physics("solid").feature("bl3").label("Body load (Elastic Inclusion), Point Source");

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

    model.component("comp1").physics("solid").feature("bl3")
         .set("forceReferenceVolume", new String[]{"(rho-rho_o)*(-omega^2)*uPS", "(rho-rho_o)*(-omega^2)*vPS", "0"});

//    In the Model Builder window, collapse the Component 1 (comp1) > Solid Mechanics (solid) > Point Source > Elastic Inclusion, Point Source node.
//    In the Model Builder window, collapse the Component 1 (comp1) > Solid Mechanics (solid) > Point Source node.
//    In the Home toolbar, click Add Study to open the Add Study window.
//    Find the Studies subsection.
//    In the Select Study tree, select General Studies > Frequency Domain.
//    Click Add Study in the window toolbar.

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

//    In the Home toolbar, click Add Study to close the Add Study window.
//    In the Settings window for Study, type Point Source Scattered Field in the Label text field.

    model.study("std4").label("Point Source Scattered Field");

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

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

//    In the Model Builder window, expand the 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 Component 1 (comp1) > Solid Mechanics (solid) > Point Source.
//    Click Disable.

    model.study("std1").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl2", "solid/lemm3", "solid/disp2", "solid/bndl2", "solid/pl1", "solid/bl3", "solid/lemm4", "solid/disp3", "solid/bndl3"});

//    In the Model Builder window, expand the S 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 Component 1 (comp1) > Solid Mechanics (solid) > Point Source.
//    Click Disable.

    model.study("std2").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl1", "solid/lemm2", "solid/disp1", "solid/bndl1", "solid/pl1", "solid/bl3", "solid/lemm4", "solid/disp3", "solid/bndl3"});

//    In the Model Builder window, under Point Source Incident Field, click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Physics and Variables Selection section.
//    In the tree, select Component 1 (comp1) > Solid Mechanics (solid) > Point Source.
//    Click Disable.

    model.study("std3").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl1", "solid/lemm2", "solid/disp1", "solid/bndl1", "solid/bl2", "solid/lemm3", "solid/disp2", "solid/bndl2", "solid/bl3", "solid/lemm4", 
         "solid/disp3", "solid/bndl3"});

//    In the Model Builder window, under Point Source Scattered Field, click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Study Settings section.
//    In the Frequencies text field, type omega/2/pi[rad].

    model.study("std4").feature("freq").set("plist", "omega/2/pi[rad]");

    return model;
  }

  public static Model run4(Model model) {

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

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

//    In the tree, select Component 1 (comp1) > Solid Mechanics (solid) > P Wave.
//    Click Disable.

    model.study("std4").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl1", "solid/lemm2", "solid/disp1", "solid/bndl1"});

//    In the tree, select Component 1 (comp1) > Solid Mechanics (solid) > S Wave.
//    Click Disable.

    model.study("std4").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl1", "solid/lemm2", "solid/disp1", "solid/bndl1", "solid/bl2", "solid/lemm3", "solid/disp2", "solid/bndl2"});

//    In the tree, select Component 1 (comp1) > Solid Mechanics (solid) > Point Load 1.
//    Click Disable.

    model.study("std4").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl1", "solid/lemm2", "solid/disp1", "solid/bndl1", "solid/bl2", "solid/lemm3", "solid/disp2", "solid/bndl2", "solid/pl1"});

//    In the Study toolbar, click Compute.

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

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

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

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

//    In the Settings window for 2D Plot Group, type Point Source Scattered Displacement Field Magnitude in the Label text field.

    model.result("pg10").label("Point Source Scattered Displacement Field Magnitude");

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

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

//    In the Title text area, type Displacement Magnitude.

    model.result("pg10").set("title", "Displacement Magnitude");

//    Clear the Parameter indicator text field.

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

//    Locate the Data section.
//    From the Dataset list, select Point Source Scattered Field/Solution 4 (sol4).

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

//    Right-click Point Source Scattered Displacement Field Magnitude and choose Surface.

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

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

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

//    Select Domains 3, 4, 6, 7, 11, 12, 14, 15, 19, 20, 22, 23, 25.

    model.result("pg10").feature("surf1").feature("sel1").selection()
         .set(3, 4, 6, 7, 11, 12, 14, 15, 19, 20, 22, 23, 25);
    model.result("pg10").run();

//    In the Model Builder window, click Surface 1.
//    In the Settings window for Surface, locate the Coloring and Style section.
//    From the Color table list, select SpectrumLight.

    model.result("pg10").feature("surf1").set("colortable", "SpectrumLight");
    model.result("pg10").run();

//    In the Model Builder window, click Point Source Scattered Displacement Field Magnitude.
//    In the Settings window for 2D Plot Group, locate the Plot Settings section.
//    Clear the Plot dataset edges checkbox.

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

//    In the Point Source Scattered Displacement Field Magnitude toolbar, click More Plots and choose Table Annotation.

    model.result("pg10").create("tlan1", "TableAnnotation");

//    In the Settings window for Table Annotation, locate the Data section.
//    From the Source list, select Local table.

    model.result("pg10").feature("tlan1").set("source", "localtable");

//    In the table, enter the following settings:

    model.result("pg10").feature("tlan1").setIndex("localtablematrix", 0, 0, 0);
    model.result("pg10").feature("tlan1").setIndex("localtablematrix", 5, 0, 1);
    model.result("pg10").feature("tlan1").setIndex("localtablematrix", "Cavity", 0, 2);
    model.result("pg10").feature("tlan1").setIndex("localtablematrix", 12, 1, 0);
    model.result("pg10").feature("tlan1").setIndex("localtablematrix", 5, 1, 1);
    model.result("pg10").feature("tlan1").setIndex("localtablematrix", "Rigid", 1, 2);
    model.result("pg10").feature("tlan1").setIndex("localtablematrix", 24, 2, 0);
    model.result("pg10").feature("tlan1").setIndex("localtablematrix", 5, 2, 1);
    model.result("pg10").feature("tlan1").setIndex("localtablematrix", "Elastic", 2, 2);

//    Locate the Coloring and Style section.
//    Clear the Show point checkbox.

    model.result("pg10").feature("tlan1").set("showpoint", false);

//    From the Anchor point list, select Center.

    model.result("pg10").feature("tlan1").set("anchorpoint", "center");

//    In the Model Builder window, right-click Results > Views and choose View 2D.

    model.view().create("view4", 2);

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

//    In the Settings window for 2D Plot Group, locate the Plot Settings section.
//    From the View list, select View 2D 4.

    model.result("pg10").set("view", "view4");

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Model Builder window, collapse the Results > Point Source Scattered Displacement Field Magnitude > Surface 1 node.
//    Right-click Results > Point Source Scattered Displacement Field Magnitude and choose Duplicate.

    model.result().duplicate("pg11", "pg10");
    model.result("pg11").run();

//    In the Model Builder window, collapse the Results > Point Source Scattered Displacement Field Magnitude node.
//    In the Model Builder window, under Results, click Point Source Scattered Displacement Field Magnitude 1.
//    In the Settings window for 2D Plot Group, type Point Source Total Displacement Field Magnitude in the Label text field.

    model.result("pg11").label("Point Source Total Displacement Field Magnitude");

//    In the Model Builder window, expand the Point Source Total Displacement Field Magnitude node.

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

//    In the Model Builder window, expand the Results > Point Source Total Displacement Field Magnitude > Surface 1 node, then click Surface 1.
//    In the Settings window for Surface, type Scattered Field Formulation in the Label text field.

    model.result("pg11").feature("surf1").label("Scattered Field Formulation");

//    Locate the Expression section.
//    In the Expression text field, type if(x>20,sqrt((real(u+uPS))^2+(real(v+vPS))^2),if(x<5,sqrt((real(u+genext1(uPS)))^2+(real(v+genext1(vPS)))^2),sqrt((real(u+genext2(uPS)))^2+(real(v+genext2(vPS)))^2))).

    model.result("pg11").feature("surf1")
         .set("expr", "if(x>20,sqrt((real(u+uPS))^2+(real(v+vPS))^2),if(x<5,sqrt((real(u+genext1(uPS)))^2+(real(v+genext1(vPS)))^2),sqrt((real(u+genext2(uPS)))^2+(real(v+genext2(vPS)))^2)))");

//    Locate the Range section.
//    Select the Manual color range checkbox.

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

//    In the Minimum text field, type 0.

    model.result("pg11").feature("surf1").set("rangecolormin", 0);

//    In the Maximum text field, type 0.15.

    model.result("pg11").feature("surf1").set("rangecolormax", 0.15);

//    In the Point Source Total Displacement Field Magnitude toolbar, click Plot.

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

//    In the Model Builder window, collapse the Results > Point Source Total Displacement Field Magnitude node.

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

//    In the Model Builder window, click Point Source Total Displacement Field Magnitude.
//    In the Settings window for 2D Plot Group, locate the Title section.
//    In the Title text area, type Total Displacement Field Magnitude.

    model.result("pg11").set("title", "Total Displacement Field Magnitude");

//    Compute the total field without using the scattered field formulation, that is, adopting the actual boundary conditions and field equation for the total field.
//    In the Model Builder window, under Component 1 (comp1) > Solid Mechanics (solid), click Point Load 1.
//    Select Points 3, 16, 29.

    model.component("comp1").physics("solid").feature("pl1").selection().set(3, 16, 29);

//    In the Physics toolbar, click Boundaries and choose Fixed Constraint.

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

//    Select Boundaries 41, 42, 45, 46.

    model.component("comp1").physics("solid").feature("fix1").selection().set(41, 42, 45, 46);

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

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

//    In the Settings window for Study, type Point Source Total Field (NO Scattered Field Formulation) in the Label text field.

    model.study("std5").label("Point Source Total Field (NO Scattered Field Formulation)");

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

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

//    In the Model Builder window, under P Wave, click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Physics and Variables Selection section.
//    In the tree, select Component 1 (comp1) > Solid Mechanics (solid) > Fixed Constraint 1.
//    Click Disable.

    model.study("std1").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl2", "solid/lemm3", "solid/disp2", "solid/bndl2", "solid/pl1", "solid/bl3", "solid/lemm4", "solid/disp3", "solid/bndl3", "solid/fix1"});

//    In the Model Builder window, under 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 Component 1 (comp1) > Solid Mechanics (solid) > Fixed Constraint 1.
//    Click Disable.

    model.study("std2").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl1", "solid/lemm2", "solid/disp1", "solid/bndl1", "solid/pl1", "solid/bl3", "solid/lemm4", "solid/disp3", "solid/bndl3", "solid/fix1"});

//    In the Model Builder window, under Point Source Incident Field, click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Physics and Variables Selection section.
//    In the tree, select Component 1 (comp1) > Solid Mechanics (solid) > Fixed Constraint 1.
//    Click Disable.

    model.study("std3").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl1", "solid/lemm2", "solid/disp1", "solid/bndl1", "solid/bl2", "solid/lemm3", "solid/disp2", "solid/bndl2", "solid/bl3", "solid/lemm4", 
         "solid/disp3", "solid/bndl3", "solid/fix1"});

//    In the Model Builder window, under Point Source Scattered Field, click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Physics and Variables Selection section.
//    Click Disable.

    model.study("std4").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl1", "solid/lemm2", "solid/disp1", "solid/bndl1", "solid/bl2", "solid/lemm3", "solid/disp2", "solid/bndl2", "solid/pl1", "solid/fix1"});

//    In the Model Builder window, under Point Source Total Field (NO Scattered Field Formulation), click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Study Settings section.
//    In the Frequencies text field, type omega/2/pi[rad].

    model.study("std5").feature("freq").set("plist", "omega/2/pi[rad]");

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

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

//    In the tree, select Component 1 (comp1) > Solid Mechanics (solid) > P Wave.
//    Click Disable.

    model.study("std5").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl1", "solid/lemm2", "solid/disp1", "solid/bndl1"});

//    In the tree, select Component 1 (comp1) > Solid Mechanics (solid) > S Wave.
//    Click Disable.

    model.study("std5").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl1", "solid/lemm2", "solid/disp1", "solid/bndl1", "solid/bl2", "solid/lemm3", "solid/disp2", "solid/bndl2"});

//    In the tree, select Component 1 (comp1) > Solid Mechanics (solid) > Point Source > Cavity Inclusion, Point Source.
//    Click Disable.

    model.study("std5").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl1", "solid/lemm2", "solid/disp1", "solid/bndl1", "solid/bl2", "solid/lemm3", "solid/disp2", "solid/bndl2", "solid/bndl3"});

//    In the tree, select Component 1 (comp1) > Solid Mechanics (solid) > Point Source > Infinitely Rigid Inclusion, Point Source.
//    Click Disable.

    model.study("std5").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl1", "solid/lemm2", "solid/disp1", "solid/bndl1", "solid/bl2", "solid/lemm3", "solid/disp2", "solid/bndl2", "solid/bndl3", "solid/disp3"});

//    In the tree, select Component 1 (comp1) > Solid Mechanics (solid) > Point Source > Elastic Inclusion, Point Source > Initial Stress and Strain.
//    Click Disable.

    model.study("std5").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl1", "solid/lemm2", "solid/disp1", "solid/bndl1", "solid/bl2", "solid/lemm3", "solid/disp2", "solid/bndl2", "solid/bndl3", "solid/disp3", 
         "solid/lemm4/iss1"});

//    In the tree, select Component 1 (comp1) > Solid Mechanics (solid) > Point Source > Body load (Elastic Inclusion), Point Source.
//    Click Disable.

    model.study("std5").feature("freq")
         .set("disabledphysics", new String[]{"solid/bl1", "solid/lemm2", "solid/disp1", "solid/bndl1", "solid/bl2", "solid/lemm3", "solid/disp2", "solid/bndl2", "solid/bndl3", "solid/disp3", 
         "solid/lemm4/iss1", "solid/bl3"});

//    In the Study toolbar, click Compute.

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

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

//    In the Study toolbar, click Add Study to close the Add Study window.
//    In the Model Builder window, collapse the Point Source Total Field (NO Scattered Field Formulation) node.
//    Plot the results obtained next to those obtained with the scattered field formulation for comparison.

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

//    In the Model Builder window, under Results, click Point Source Total Displacement Field Magnitude.
//    In the Settings window for 2D Plot Group, locate the Plot Array section.
//    From the Array type list, select Linear.

    model.result("pg11").set("plotarraytype", "linear");

//    From the Array axis list, select y.

    model.result("pg11").set("arrayaxis", "y");
    model.result("pg11").run();

//    In the Model Builder window, expand the Point Source Total Displacement Field Magnitude node.
//    Right-click Scattered Field Formulation and choose Duplicate.

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

//    In the Settings window for Surface, locate the Data section.
//    From the Dataset list, select Point Source Total Field (NO Scattered Field Formulation)/Solution 5 (sol5).

    model.result("pg11").feature("surf2").set("data", "dset5");

//    Locate the Expression section.
//    In the Expression text field, type solid.disp.

    model.result("pg11").feature("surf2").set("expr", "solid.disp");

//    In the Point Source Total Displacement Field Magnitude toolbar, click Plot.

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

//    Locate the Inherit Style section.
//    From the Plot list, select Scattered Field Formulation.

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

//    In the Label text field, type NO Scattered Field Formulation.

    model.result("pg11").feature("surf2").label("NO Scattered Field Formulation");
    model.result("pg11").run();

//    In the Model Builder window, click Table Annotation 1.
//    In the Settings window for Table Annotation, locate the Data section.
//    In the table, enter the following settings:

    model.result("pg11").feature("tlan1").setIndex("localtablematrix", 0, 3, 0);
    model.result("pg11").feature("tlan1").setIndex("localtablematrix", 15.5, 3, 1);
    model.result("pg11").feature("tlan1").setIndex("localtablematrix", "Cavity", 3, 2);
    model.result("pg11").feature("tlan1").setIndex("localtablematrix", 12, 4, 0);
    model.result("pg11").feature("tlan1").setIndex("localtablematrix", 15.5, 4, 1);
    model.result("pg11").feature("tlan1").setIndex("localtablematrix", "Rigid", 4, 2);
    model.result("pg11").feature("tlan1").setIndex("localtablematrix", 24, 5, 0);
    model.result("pg11").feature("tlan1").setIndex("localtablematrix", 15.5, 5, 1);
    model.result("pg11").feature("tlan1").setIndex("localtablematrix", "Elastic", 5, 2);
    model.result("pg11").run();

//    In the Model Builder window, click Point Source Total Displacement Field Magnitude.
//    In the Point Source Total Displacement Field Magnitude toolbar, click More Plots and choose Table Annotation.

    model.result("pg11").create("tlan2", "TableAnnotation");

//    In the Settings window for Table Annotation, locate the Data section.
//    From the Source list, select Local table.

    model.result("pg11").feature("tlan2").set("source", "localtable");

//    In the table, enter the following settings:

    model.result("pg11").feature("tlan2").setIndex("localtablematrix", -9, 0, 0);
    model.result("pg11").feature("tlan2").setIndex("localtablematrix", 0, 0, 1);
    model.result("pg11").feature("tlan2").setIndex("localtablematrix", "SFF", 0, 2);
    model.result("pg11").feature("tlan2").setIndex("localtablematrix", -9, 1, 0);
    model.result("pg11").feature("tlan2").setIndex("localtablematrix", 10.5, 1, 1);
    model.result("pg11").feature("tlan2").setIndex("localtablematrix", "NO SFF", 1, 2);

//    Locate the Coloring and Style section.
//    From the Anchor point list, select Middle left.

    model.result("pg11").feature("tlan2").set("anchorpoint", "middleleft");

//    Clear the Show point checkbox.

    model.result("pg11").feature("tlan2").set("showpoint", false);

//    In the Point Source Total Displacement Field Magnitude toolbar, click Plot.

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

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

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

//    In the Model Builder window, click Point Source Total Displacement Field Magnitude.
//    In the Settings window for 2D Plot Group, locate the Plot Settings section.
//    From the View list, select New view.

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

//    In the Point Source Total Displacement Field Magnitude toolbar, click Plot.

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

//    Right-click Point Source Total Displacement Field Magnitude and choose Duplicate.

    model.result().duplicate("pg12", "pg11");
    model.result("pg12").run();

//    In the Model Builder window, click Point Source Total Displacement Field Magnitude 1.
//    In the Settings window for 2D Plot Group, type Point Source Total P Wave in the Label text field.

    model.result("pg12").label("Point Source Total P Wave");
    model.result("pg12").run();

//    In the Model Builder window, click Scattered Field Formulation.
//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type if(x>20,d(u+uPS,x)+d(v+vPS,y),if(x<5,d(u+genext1(uPS),x)+d(v+genext1(vPS),y),d(u+genext2(uPS),x)+d(v+genext2(vPS),y))).

    model.result("pg12").feature("surf1")
         .set("expr", "if(x>20,d(u+uPS,x)+d(v+vPS,y),if(x<5,d(u+genext1(uPS),x)+d(v+genext1(vPS),y),d(u+genext2(uPS),x)+d(v+genext2(vPS),y)))");

//    In the Point Source Total P Wave toolbar, click Plot.

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

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

    model.result("pg12").feature("surf1").set("colortable", "Wave");

//    Locate the Range section.
//    In the Minimum text field, type -0.5.

    model.result("pg12").feature("surf1").set("rangecolormin", -0.5);

//    In the Maximum text field, type 0.5.

    model.result("pg12").feature("surf1").set("rangecolormax", 0.5);

//    In the Point Source Total P Wave toolbar, click Plot.

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

//    In the Model Builder window, click NO Scattered Field Formulation.
//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type d(u,x)+d(v,y).

    model.result("pg12").feature("surf2").set("expr", "d(u,x)+d(v,y)");

//    In the Point Source Total P Wave toolbar, click Plot.

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

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

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

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

    model.result("pg13").label("Point Source Total S Wave");
    model.result("pg13").run();

//    In the Model Builder window, click Scattered Field Formulation.
//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type if(x>20,-d(u+uPS,y)+d(v+vPS,x),if(x<5,-d(u+genext1(uPS),y)+d(v+genext1(vPS),x),-d(u+genext2(uPS),y)+d(v+genext2(vPS),x))).

    model.result("pg13").feature("surf1")
         .set("expr", "if(x>20,-d(u+uPS,y)+d(v+vPS,x),if(x<5,-d(u+genext1(uPS),y)+d(v+genext1(vPS),x),-d(u+genext2(uPS),y)+d(v+genext2(vPS),x)))");

//    Locate the Range section.
//    In the Minimum text field, type -1.

    model.result("pg13").feature("surf1").set("rangecolormin", -1);

//    In the Maximum text field, type 1.

    model.result("pg13").feature("surf1").set("rangecolormax", 1);

//    In the Point Source Total S Wave toolbar, click Plot.

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

//    In the Model Builder window, click NO Scattered Field Formulation.
//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type -d(u,y)+d(v,x).

    model.result("pg13").feature("surf2").set("expr", "-d(u,y)+d(v,x)");

//    In the Point Source Total S Wave toolbar, click Plot.

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

    model.nodeGroup().create("grp5", "Results");
    model.nodeGroup("grp5").set("type", "plotgroup");
    model.nodeGroup().move("grp5", 3);
    model.nodeGroup("grp5").add("plotgroup", "pg9");
    model.nodeGroup("grp5").add("plotgroup", "pg10");
    model.nodeGroup("grp5").add("plotgroup", "pg11");
    model.nodeGroup("grp5").add("plotgroup", "pg12");
    model.nodeGroup("grp5").add("plotgroup", "pg13");
    model.nodeGroup("grp5").label("Point Source");

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

    model.title("Scattered-Field Formulation for Elastic Waves");

    model
         .description("This model showcases how to solve for the scattered field when knowing the incident field for three different types of scatterer, that is, an infinitely rigid one, a cavity, and an elastic inclusion. This formulation can be useful when the scatterer is in the far-field of the source, such that the probing wave resembles a plane wave. In this case, including the source would require an unnecessarily huge computational domain to be meshed. Both P and S plane waves are thus used as incident fields in the model. Moreover, the model shows how to compute numerically the field emitted by a point source, and then use such solution as the known incident field for a subsequent study where the scattering problem is solved.");

    return model;
  }

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

}
