/*
 * saw_gas_sensor.java
 */

import com.comsol.model.*;
import com.comsol.model.util.*;

/** Model exported on May 15 2026, 14:13 by COMSOL 6.4.0.421. */
public class saw_gas_sensor {

  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 > Electromagnetics–Structure Interaction > Piezoelectricity > Piezoelectricity, Solid.
//    Click Add.
//    Click Study.
//    In the Select Study tree, select Preset Studies for Selected Multiphysics > Eigenfrequency.
//    Click Done.

    model.component().create("comp1", true);

    model.component("comp1").geom().create("geom1", 2);

    model.component("comp1").mesh().create("mesh1");

    model.component("comp1").physics().create("solid", "SolidMechanics", "geom1");
    model.component("comp1").physics("solid").create("pzm1", "PiezoelectricMaterialModel");
    model.component("comp1").physics("solid").feature("pzm1").selection().all();
    model.component("comp1").physics().create("es", "Electrostatics", "geom1");
    model.component("comp1").physics("es").create("ccnp1", "ChargeConservationPiezo");
    model.component("comp1").physics("es").feature("ccnp1").selection().all();

    model.component("comp1").multiphysics().create("pze1", "PiezoelectricEffect", 2);
    model.component("comp1").multiphysics("pze1").set("Solid_physics", "solid");
    model.component("comp1").multiphysics("pze1").set("Electrostatics_physics", "es");

    model.study().create("std1");
    model.study("std1").create("eig", "Eigenfrequency");
    model.study("std1").feature("eig").set("shift", "1[Hz]");
    model.study("std1").feature("eig").set("chkeigregion", true);
    model.study("std1").feature("eig").set("storefact", false);
    model.study("std1").feature("eig").set("linpsolnum", "auto");
    model.study("std1").feature("eig").set("solnum", "auto");
    model.study("std1").feature("eig").set("notsolnum", "auto");
    model.study("std1").feature("eig").set("outputmap", new String[]{});
    model.study("std1").feature("eig").set("ngenAUX", "1");
    model.study("std1").feature("eig").set("goalngenAUX", "1");
    model.study("std1").feature("eig").set("ngenAUX", "1");
    model.study("std1").feature("eig").set("goalngenAUX", "1");

    model.component("comp1").common().create("mpf1", "ParticipationFactors");

//    For quicker modeling, load the parameters from a file.
//    In the Model Builder window, under Global Definitions, click Parameters 1.
//    In the Settings window for Parameters, locate the Parameters section.
//    Click Load from File.
//    Browse to the model's Application Library folder and double-click the file saw_gas_sensor_parameters.txt.
//    To import content from file, use:
//    model.param().loadFile("FILENAME");
    model.param().set("p", "1[atm]", "Air pressure");
    model.param().set("T", "25[degC]", "Air temperature");
    model.param().set("c0", "100", "DCM Concentration in ppm");
    model.param().set("c_DCM_air", "1e-6*c0*p/(R_const*T)", "DCM concentration in air");
    model.param().set("M_DCM", "84.93[g/mol]", "Molar mass of DCM");
    model.param().set("K", "10^1.4821", "PIB/air partition constant for DCM");
    model.param().set("rho_DCM_PIB", "K*M_DCM*c_DCM_air", "Mass concentration of DCM in PIB");
    model.param().set("rho_PIB", "0.918[g/cm^3]", "Density of PIB");
    model.param().set("E_PIB", "10[GPa]", "Young's modulus of PIB");
    model.param().set("nu_PIB", "0.48", "Poisson's ratio of PIB");
    model.param().set("eps_PIB", "2.2", "Relative permittivity of PIB");
    model.param().set("switch", "0", "Switch for adding DCM density");
    model.param().set("vR", "3488[m/s]", "Rayleigh wave velocity");
    model.param().set("width", "4[um]", "Width of unit cell");
    model.param().set("f0", "vR/width", "Estimated SAW frequency");
    model.param().set("t_PIB", "0.5[um]", "PIB thickness");

//    In the Model Builder window, under Component 1 (comp1), click Geometry 1.
//    In the Settings window for Geometry, locate the Units section.
//    From the Length unit list, select µm.

    model.component("comp1").geom("geom1").lengthUnit("\u00b5m");

//    In the Geometry toolbar, click Rectangle.

    model.component("comp1").geom("geom1").create("r1", "Rectangle");

//    In the Settings window for Rectangle, locate the Size and Shape section.
//    In the Width text field, type width.

    model.component("comp1").geom("geom1").feature("r1").set("size", new String[]{"width", "1"});

//    In the Height text field, type 3*width+t_PIB.

    model.component("comp1").geom("geom1").feature("r1").set("size", new String[]{"width", "3*width+t_PIB"});

//    Locate the Position section.
//    In the y text field, type -3*width.

    model.component("comp1").geom("geom1").feature("r1").set("pos", new String[]{"0", "-3*width"});

//    Click to expand the Layers section.
//    In the table, enter the following settings:

    model.component("comp1").geom("geom1").feature("r1").setIndex("layer", "t_PIB", 0);

//    Select the Layers on top checkbox.

    model.component("comp1").geom("geom1").feature("r1").set("layertop", true);

//    Clear the Layers on bottom checkbox.

    model.component("comp1").geom("geom1").feature("r1").set("layerbottom", false);

//    Click Build Selected.

    model.component("comp1").geom("geom1").run("r1");

//    In the Geometry toolbar, click Rectangle.

    model.component("comp1").geom("geom1").create("r2", "Rectangle");

//    In the Settings window for Rectangle, locate the Size and Shape section.
//    In the Width text field, type width/4.

    model.component("comp1").geom("geom1").feature("r2").set("size", new String[]{"width/4", "1"});

//    In the Height text field, type 0.4*t_PIB.

    model.component("comp1").geom("geom1").feature("r2").set("size", new String[]{"width/4", "0.4*t_PIB"});

//    Locate the Position section.
//    In the x text field, type width/8.

    model.component("comp1").geom("geom1").feature("r2").set("pos", new String[]{"width/8", "0"});

//    Click Build Selected.

    model.component("comp1").geom("geom1").run("r2");

//    In the Geometry toolbar, click Transforms and choose Copy.

    model.component("comp1").geom("geom1").create("copy1", "Copy");

//    Select the object r2.

    model.component("comp1").geom("geom1").feature("copy1").selection("input").set("r2");

//    In the Settings window for Copy, locate the Displacement section.
//    In the x text field, type width/2.

    model.component("comp1").geom("geom1").feature("copy1").set("displx", "width/2");

//    Click Build All Objects.

    model.component("comp1").geom("geom1").runPre("fin");

//    Before creating materials, define the domains where each physics apply.

    model.component("comp1").geom("geom1").run();

//    In the Model Builder window, under Component 1 (comp1) > Solid Mechanics (solid), click Piezoelectric Material 1.
//    In the Settings window for Piezoelectric Material, locate the Domain Selection section.
//    Click Clear Selection.

    model.component("comp1").physics("solid").feature("pzm1").selection().set();

//    Select Domain 1.

    model.component("comp1").physics("solid").feature("pzm1").selection().set(1);

//    The electrical equations are not solved in the aluminum electrodes because they are assumed to be perfect conductors compared to LiNbO3 and PIB, and hence we consider them to be equipotential regions.
//    In the Model Builder window, under Component 1 (comp1), click Electrostatics (es).
//    Select Domains 1, 2.

    model.component("comp1").physics("es").selection().set(1, 2);

//    In the Model Builder window, under Component 1 (comp1) > Electrostatics (es), click Charge Conservation, Piezoelectric 1.
//    Select Domain 1.

    model.component("comp1").physics("es").feature("ccnp1").selection().set(1);

//    In the Physics toolbar, click Domains and choose Charge Conservation in Fluids.

    model.component("comp1").physics("es").create("ccnf1", "ChargeConservationFluid", 2);

//    Select Domain 2.

    model.component("comp1").physics("es").feature("ccnf1").selection().set(2);

//    In the Model Builder window, right-click Component 1 (comp1) > Materials and choose Blank Material.

    model.component("comp1").material().create("mat1", "Common");

//    In the Settings window for Material, type LiNbO3 in the Label text field.

    model.component("comp1").material("mat1").label("LiNbO3");

//    Locate the Geometric Entity Selection section.
//    Click Clear Selection.

    model.component("comp1").material("mat1").selection().set();

//    Select Domain 1.

    model.component("comp1").material("mat1").selection().set(1);

//    Locate the Material Contents section.
//    In the table, enter the following settings:

    model.component("comp1").material("mat1").propertyGroup()
         .create("StressCharge", "StressCharge", "Stress-charge_form");
    model.component("comp1").material("mat1").propertyGroup("StressCharge")
         .set("cE", new String[]{"242.4[GPa]", "75.2[GPa]", "203[GPa]", "75.2[GPa]", "57.3[GPa]", "203[GPa]", "0", "0", "0", "75.2[GPa]", 
         "0", "8.5[GPa]", "-8.5[GPa]", "0", "59.5[GPa]", "0", "0", "0", "8.5[GPa]", "0", 
         "59.5[GPa]"});
    model.component("comp1").material("mat1").propertyGroup("StressCharge")
         .set("eES", new String[]{"1.33", "0", "0", "0.23", "0", "-2.5", "0.23", "0", "2.5", "0", 
         "-2.5", "0", "0", "0", "3.7", "0", "3.7", "0"});
    model.component("comp1").material("mat1").propertyGroup("StressCharge")
         .set("epsilonrS", new String[]{"28.7", "85.2", "85.2"});
    model.component("comp1").material("mat1").propertyGroup("def").set("density", new String[]{"4647"});

//    Alternately, you can click the <l>Edit</l> button below the <l>Output properties</l> table and use the matrix inputs to enter <c>cE</c>, <c>e</c>, and <c>epsilonrS</c> according to the material data shown under the <l>Model Definition</l> section.
//    Right-click Materials and choose Blank Material.

    model.component("comp1").material().create("mat2", "Common");

//    In the Settings window for Material, type PIB in the Label text field.

    model.component("comp1").material("mat2").label("PIB");

//    Select Domain 2.

    model.component("comp1").material("mat2").selection().set(2);

//    Locate the Material Contents section.
//    In the table, enter the following settings:

    model.component("comp1").material("mat2").propertyGroup()
         .create("Enu", "Enu", "Young's_modulus_and_Poisson's_ratio");
    model.component("comp1").material("mat2").propertyGroup("Enu").set("E", new String[]{"E_PIB"});
    model.component("comp1").material("mat2").propertyGroup("Enu").set("nu", new String[]{"nu_PIB"});
    model.component("comp1").material("mat2").propertyGroup("def")
         .set("density", new String[]{"rho_PIB+switch*rho_DCM_PIB"});
    model.component("comp1").material("mat2").propertyGroup("def").set("relpermittivity", new String[]{"eps_PIB"});

//    In the Materials toolbar, click Add Material to open the Add Material window.
//    In the tree, select Built-in > Aluminum.
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat3", "Common");
    model.component("comp1").material("mat3").propertyGroup()
         .create("Enu", "Enu", "Young's modulus and Poisson's ratio");
    model.component("comp1").material("mat3").propertyGroup().create("Murnaghan", "Murnaghan", "Murnaghan");
    model.component("comp1").material("mat3").label("Aluminum");
    model.component("comp1").material("mat3").set("family", "aluminum");
    model.component("comp1").material("mat3").propertyGroup("def")
         .set("relpermeability", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat3").propertyGroup("def").set("heatcapacity", "900[J/(kg*K)]");
    model.component("comp1").material("mat3").propertyGroup("def")
         .set("thermalconductivity", new String[]{"238[W/(m*K)]", "0", "0", "0", "238[W/(m*K)]", "0", "0", "0", "238[W/(m*K)]"});
    model.component("comp1").material("mat3").propertyGroup("def")
         .set("electricconductivity", new String[]{"3.774e7[S/m]", "0", "0", "0", "3.774e7[S/m]", "0", "0", "0", "3.774e7[S/m]"});
    model.component("comp1").material("mat3").propertyGroup("def")
         .set("relpermittivity", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat3").propertyGroup("def")
         .set("thermalexpansioncoefficient", new String[]{"23e-6[1/K]", "0", "0", "0", "23e-6[1/K]", "0", "0", "0", "23e-6[1/K]"});
    model.component("comp1").material("mat3").propertyGroup("def").set("density", "2700[kg/m^3]");
    model.component("comp1").material("mat3").propertyGroup("Enu").set("E", "70[GPa]");
    model.component("comp1").material("mat3").propertyGroup("Enu").set("nu", "0.33");
    model.component("comp1").material("mat3").propertyGroup("Murnaghan").set("l", "-250[GPa]");
    model.component("comp1").material("mat3").propertyGroup("Murnaghan").set("m", "-330[GPa]");
    model.component("comp1").material("mat3").propertyGroup("Murnaghan").set("n", "-350[GPa]");

//    In the Materials toolbar, click Add Material to close the Add Material window.
//    Select Domains 3, 4.

    model.component("comp1").material("mat3").selection().set(3, 4);

//    In the Physics toolbar, click Boundaries and choose Fixed Constraint.

    model.component("comp1").physics("solid").create("fix1", "Fixed", 1);

//    Select Boundary 2.

    model.component("comp1").physics("solid").feature("fix1").selection().set(2);

//    In the Physics toolbar, click Boundaries and choose Periodic Condition.

    model.component("comp1").physics("solid").create("pc1", "PeriodicCondition", 1);

//    Select Boundaries 1, 3, 16, 17.

    model.component("comp1").physics("solid").feature("pc1").selection().set(1, 3, 16, 17);

//    This defines periodic condition for the <l>Solid Mechanics</l> physics. By default, the periodicity type is set to <l>Continuity</l> for all dependent variables.
//    Ground the left electrode by applying boundary condition on its edges.
//    In the Physics toolbar, click Boundaries and choose Ground.

    model.component("comp1").physics("es").create("gnd1", "Ground", 1);

//    Select Boundaries 6, 7, 8, 9.

    model.component("comp1").physics("es").feature("gnd1").selection().set(6, 7, 8, 9);

//    Apply a <l>Floating Potential</l> on the edges of the right electrode.
//    In the Physics toolbar, click Boundaries and choose Floating Potential.

    model.component("comp1").physics("es").create("fp1", "FloatingPotential", 1);

//    Select Boundaries 11, 12, 13, 14.

    model.component("comp1").physics("es").feature("fp1").selection().set(11, 12, 13, 14);

//    Define periodic boundary condition for the <l>Electrostatics</l> physics.
//    In the Physics toolbar, click Boundaries and choose Periodic Condition.

    model.component("comp1").physics("es").create("pc1", "PeriodicCondition", 1);

//    Select Boundaries 1, 3, 16, 17.

    model.component("comp1").physics("es").feature("pc1").selection().set(1, 3, 16, 17);

//    In the Mesh toolbar, click More Generators and choose Edge.

    model.component("comp1").mesh("mesh1").create("edg1", "Edge");

//    Select Boundaries 1, 3.

    model.component("comp1").mesh("mesh1").feature("edg1").selection().set(1, 3);

//    Right-click Edge 1 and choose Distribution.

    model.component("comp1").mesh("mesh1").feature("edg1").create("dis1", "Distribution");

//    Select Boundary 3.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("dis1").selection().set(3);

//    In the Settings window for Distribution, locate the Distribution section.
//    In the Number of elements text field, type 4.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("dis1").set("numelem", 4);

//    Define an increasing mesh size along the thickness of the piezoelectric substrate.
//    In the Model Builder window, right-click Edge 1 and choose Distribution.

    model.component("comp1").mesh("mesh1").feature("edg1").create("dis2", "Distribution");

//    Select Boundary 1.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("dis2").selection().set(1);

//    In the Settings window for Distribution, locate the Distribution section.
//    From the Distribution type list, select Predefined.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("dis2").set("type", "predefined");

//    In the Number of elements text field, type 25.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("dis2").set("elemcount", 25);

//    In the Element ratio text field, type 25.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("dis2").set("elemratio", 25);

//    Select the Reverse direction checkbox.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("dis2").set("reverse", true);

//    Click Build Selected.

    model.component("comp1").mesh("mesh1").run("edg1");

//    In the Model Builder window, right-click Mesh 1 and choose Copying Operations > Copy Edge.

    model.component("comp1").mesh("mesh1").create("cpe1", "CopyEdge");
    model.component("comp1").mesh("mesh1").feature("cpe1").selection("source").geom(1);
    model.component("comp1").mesh("mesh1").feature("cpe1").selection("destination").geom(1);

//    Select Boundaries 1, 3.

    model.component("comp1").mesh("mesh1").feature("cpe1").selection("source").set(1, 3);

//    In the Settings window for Copy Edge, locate the Destination Boundaries section.
//    Select the Activate Selection toggle button.
//    Select Boundaries 16, 17.

    model.component("comp1").mesh("mesh1").feature("cpe1").selection("destination").set(16, 17);

//    In the Mesh toolbar, click Free Quad.

    model.component("comp1").mesh("mesh1").create("fq1", "FreeQuad");

//    In the Settings window for Free Quad, locate the Domain Selection section.
//    From the Geometric entity level list, select Domain.

    model.component("comp1").mesh("mesh1").feature("fq1").selection().geom("geom1", 2);

//    Select Domains 2, 3, 4.

    model.component("comp1").mesh("mesh1").feature("fq1").selection().set(2, 3, 4);

//    Right-click Free Quad 1 and choose Size.

    model.component("comp1").mesh("mesh1").feature("fq1").create("size1", "Size");

//    In the Settings window for Size, locate the Element Size section.
//    Click the Custom button.

    model.component("comp1").mesh("mesh1").feature("fq1").feature("size1").set("custom", true);

//    Locate the Element Size Parameters section.
//    Select the Maximum element size checkbox.

    model.component("comp1").mesh("mesh1").feature("fq1").feature("size1").set("hmaxactive", true);

//    In the associated text field, type t_PIB/4.

    model.component("comp1").mesh("mesh1").feature("fq1").feature("size1").set("hmax", "t_PIB/4");

//    In the Mesh toolbar, click Mapped.

    model.component("comp1").mesh("mesh1").create("map1", "Map");

//    In the Settings window for Mapped, click Build All.

    model.component("comp1").mesh("mesh1").run();

//    Set up a <l>Parametric Sweep</l> to solve the model with and without the adsorbed species on the sensor. The parameter switch is used to solve the model once without adding the density of DCM and once with the added density of adsorbed DCM in PIB.
//    In the Study toolbar, click Parametric Sweep.

    model.study("std1").create("param", "Parametric");

//    In the Settings window for Parametric Sweep, locate the Study Settings section.
//    Click Add.

    model.study("std1").feature("param").setIndex("pname", "p", 0);
    model.study("std1").feature("param").setIndex("plistarr", "", 0);
    model.study("std1").feature("param").setIndex("punit", "Pa", 0);
    model.study("std1").feature("param").setIndex("pname", "p", 0);
    model.study("std1").feature("param").setIndex("plistarr", "", 0);
    model.study("std1").feature("param").setIndex("punit", "Pa", 0);

//    In the table, enter the following settings:

    model.study("std1").feature("param").setIndex("pname", "switch", 0);
    model.study("std1").feature("param").setIndex("plistarr", "0 1", 0);

//    Search for eigenfrequencies near the estimated resonance frequency.
//    In the Model Builder window, click Step 1: Eigenfrequency.
//    In the Settings window for Eigenfrequency, locate the Study Settings section.
//    In the Search for eigenfrequencies around shift text field, type f0.

    model.study("std1").feature("eig").set("shift", "f0");

//    In the Study toolbar, click Compute.

    model.study("std1").createAutoSequences("all");

    model.sol().create("sol2");
    model.sol("sol2").study("std1");
    model.sol("sol2").label("Parametric Solutions 1");

    model.batch("p1").feature("so1").set("psol", "sol2");
    model.batch("p1").run("compute");

    model.result().create("pg1", "PlotGroup2D");
    model.result("pg1").set("data", "dset2");
    model.result("pg1").setIndex("looplevel", 1, 0);
    model.result("pg1").setIndex("looplevel", 2, 1);
    model.result("pg1").label("Mode Shape (solid)");
    model.result("pg1").set("showlegends", false);
    model.result("pg1").create("surf1", "Surface");
    model.result("pg1").feature("surf1").set("expr", new String[]{"solid.disp"});
    model.result("pg1").feature("surf1").set("threshold", "manual");
    model.result("pg1").feature("surf1").set("thresholdvalue", 0.2);
    model.result("pg1").feature("surf1").set("colortable", "Rainbow");
    model.result("pg1").feature("surf1").set("colortabletrans", "none");
    model.result("pg1").feature("surf1").set("colorscalemode", "linear");
    model.result("pg1").feature("surf1").set("colortable", "AuroraBorealis");
    model.result("pg1").feature("surf1").create("def", "Deform");
    model.result("pg1").feature("surf1").feature("def").set("expr", new String[]{"u", "v"});
    model.result("pg1").feature("surf1").feature("def").set("descr", "Displacement field");
    model.result().evaluationGroup().create("std1EvgFrq", "EvaluationGroup");
    model.result().evaluationGroup("std1EvgFrq").set("data", "dset2");
    model.result().evaluationGroup("std1EvgFrq").label("Eigenfrequencies (Study 1)");
    model.result().evaluationGroup("std1EvgFrq").create("gev1", "EvalGlobal");
    model.result().evaluationGroup("std1EvgFrq").feature("gev1").setIndex("expr", "2*pi*freq", 0);
    model.result().evaluationGroup("std1EvgFrq").feature("gev1").setIndex("unit", "rad/s", 0);
    model.result().evaluationGroup("std1EvgFrq").feature("gev1").setIndex("descr", "Angular frequency", 0);
    model.result().evaluationGroup("std1EvgFrq").feature("gev1").setIndex("expr", "imag(freq)/abs(freq)", 1);
    model.result().evaluationGroup("std1EvgFrq").feature("gev1").setIndex("unit", "1", 1);
    model.result().evaluationGroup("std1EvgFrq").feature("gev1").setIndex("descr", "Damping ratio", 1);
    model.result().evaluationGroup("std1EvgFrq").feature("gev1").setIndex("expr", "abs(freq)/imag(freq)/2", 2);
    model.result().evaluationGroup("std1EvgFrq").feature("gev1").setIndex("unit", "1", 2);
    model.result().evaluationGroup("std1EvgFrq").feature("gev1").setIndex("descr", "Quality factor", 2);
    model.result().evaluationGroup("std1EvgFrq").run();
    model.result().create("pg2", "PlotGroup2D");
    model.result("pg2").label("Electric Potential (es)");
    model.result("pg2").set("data", "dset2");
    model.result("pg2").setIndex("looplevel", 1, 0);
    model.result("pg2").setIndex("looplevel", 2, 1);
    model.result("pg2").set("frametype", "spatial");
    model.result("pg2").set("showlegendsmaxmin", true);
    model.result("pg2").feature().create("surf1", "Surface");
    model.result("pg2").feature("surf1").set("solutionparams", "parent");
    model.result("pg2").feature("surf1").set("expr", "V");
    model.result("pg2").feature("surf1").set("colortable", "Dipole");
    model.result("pg2").feature("surf1").set("evaluationsettings", "parent");
    model.result("pg2").feature("surf1").set("data", "parent");
    model.result("pg2").feature().create("str1", "Streamline");
    model.result("pg2").feature("str1").set("solutionparams", "parent");
    model.result("pg2").feature("str1").set("expr", new String[]{"es.Ex", "es.Ey"});
    model.result("pg2").feature("str1").set("titletype", "none");
    model.result("pg2").feature("str1").set("posmethod", "uniform");
    model.result("pg2").feature("str1").set("udensity", 6.5);
    model.result("pg2").feature("str1").set("color", "custom");
    model.result("pg2").feature("str1")
         .set("customcolor", new double[]{0.3764705955982208, 0.3764705955982208, 0.3764705955982208});
    model.result("pg2").feature("str1").set("evaluationsettings", "parent");
    model.result("pg2").feature("str1").set("maxlen", 0.4);
    model.result("pg2").feature("str1").set("maxtime", Double.POSITIVE_INFINITY);
    model.result("pg2").feature("str1").set("inheritcolor", false);
    model.result("pg2").feature("str1").set("maxtime", Double.POSITIVE_INFINITY);
    model.result("pg2").feature("str1").set("data", "parent");
    model.result("pg2").feature("str1").selection().geom("geom1", 1);
    model.result("pg2").feature("str1").selection().set(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17);
    model.result("pg2").feature("str1").set("inheritplot", "surf1");
    model.result("pg2").feature("str1").feature().create("filt1", "Filter");
    model.result("pg2").feature("str1").feature("filt1").set("expr", "!isScalingSystemDomain");
    model.result().create("pg3", "PlotGroup2D");
    model.result("pg3").label("Electric Field (es)");
    model.result("pg3").set("data", "dset2");
    model.result("pg3").setIndex("looplevel", 1, 0);
    model.result("pg3").setIndex("looplevel", 2, 1);
    model.result("pg3").set("frametype", "spatial");
    model.result("pg3").set("showlegendsmaxmin", true);
    model.result("pg3").feature().create("surf1", "Surface");
    model.result("pg3").feature("surf1").set("solutionparams", "parent");
    model.result("pg3").feature("surf1").set("expr", "es.normE");
    model.result("pg3").feature("surf1").set("colortable", "Prism");
    model.result("pg3").feature("surf1").set("colortabletrans", "nonlinear");
    model.result("pg3").feature("surf1").set("colorcalibration", -0.8);
    model.result("pg3").feature("surf1").set("evaluationsettings", "parent");
    model.result("pg3").feature("surf1").set("data", "parent");
    model.result("pg3").feature().create("str1", "Streamline");
    model.result("pg3").feature("str1").set("solutionparams", "parent");
    model.result("pg3").feature("str1").set("expr", new String[]{"es.Ex", "es.Ey"});
    model.result("pg3").feature("str1").set("titletype", "none");
    model.result("pg3").feature("str1").set("posmethod", "uniform");
    model.result("pg3").feature("str1").set("udensity", 6.5);
    model.result("pg3").feature("str1").set("color", "custom");
    model.result("pg3").feature("str1")
         .set("customcolor", new double[]{0.3764705955982208, 0.3764705955982208, 0.3764705955982208});
    model.result("pg3").feature("str1").set("evaluationsettings", "parent");
    model.result("pg3").feature("str1").set("maxlen", 0.4);
    model.result("pg3").feature("str1").set("maxtime", Double.POSITIVE_INFINITY);
    model.result("pg3").feature("str1").set("inheritcolor", false);
    model.result("pg3").feature("str1").set("maxtime", Double.POSITIVE_INFINITY);
    model.result("pg3").feature("str1").set("data", "parent");
    model.result("pg3").feature("str1").selection().geom("geom1", 1);
    model.result("pg3").feature("str1").selection().set(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17);
    model.result("pg3").feature("str1").set("inheritplot", "surf1");
    model.result("pg3").feature("str1").feature().create("filt1", "Filter");
    model.result("pg3").feature("str1").feature("filt1").set("expr", "!isScalingSystemDomain");
    model.result().evaluationGroup().create("std1mpf1", "EvaluationGroup");
    model.result().evaluationGroup("std1mpf1").set("data", "dset2");
    model.result().evaluationGroup("std1mpf1").label("Participation Factors (Study 1)");
    model.result().evaluationGroup("std1mpf1").create("gev1", "EvalGlobal");
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.pfLnormX", 0);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "1", 0);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Participation factor, normalized, X-translation", 0);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.pfLnormY", 1);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "1", 1);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Participation factor, normalized, Y-translation", 1);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.pfLnormZ", 2);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "1", 2);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Participation factor, normalized, Z-translation", 2);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.pfRnormX", 3);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "1", 3);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Participation factor, normalized, X-rotation", 3);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.pfRnormY", 4);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "1", 4);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Participation factor, normalized, Y-rotation", 4);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.pfRnormZ", 5);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "1", 5);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Participation factor, normalized, Z-rotation", 5);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.mEffLX", 6);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "kg", 6);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Effective modal mass, X-translation", 6);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.mEffLY", 7);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "kg", 7);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Effective modal mass, Y-translation", 7);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.mEffLZ", 8);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "kg", 8);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Effective modal mass, Z-translation", 8);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.mEffRX", 9);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "kg*m^2", 9);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Effective modal mass, X-rotation", 9);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.mEffRY", 10);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "kg*m^2", 10);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Effective modal mass, Y-rotation", 10);

    return model;
  }

  public static Model run2(Model model) {
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("expr", "mpf1.mEffRZ", 11);
    model.result().evaluationGroup("std1mpf1").feature("gev1").setIndex("unit", "kg*m^2", 11);
    model.result().evaluationGroup("std1mpf1").feature("gev1")
         .setIndex("descr", "Effective modal mass, Z-rotation", 11);
    model.result().evaluationGroup("std1mpf1").run();
    model.result("pg1").run();

//    The default plot shows the anti-resonance SAW mode near 850 MHz. Adjust the deformed shape plot to see the effect of the wave localization near the surface.
//    In the Settings window for 2D Plot Group, locate the Data section.
//    From the Parameter value (switch) list, select 0.

    model.result("pg1").set("looplevel", new int[]{1, 1});

//    In the Model Builder window, expand the Mode Shape (solid) node.

    model.result("pg1").run();

//    In the Model Builder window, expand the Results > Mode Shape (solid) > Surface 1 node, then click Deformation.
//    In the Settings window for Deformation, locate the Scale section.
//    Select the Scale factor checkbox.

    model.result("pg1").feature("surf1").feature("def").set("scaleactive", true);

//    In the associated text field, type 5e13.

    model.result("pg1").feature("surf1").feature("def").set("scale", "5e13");

//    In the Mode Shape (solid) toolbar, click Plot.

    model.result("pg1").run();

//    Click the Zoom Extents button in the Graphics toolbar.
//    Plot the second mode shape near 855 MHz, which is the resonance SAW mode.
//    In the Mode Shape (solid) toolbar, click Plot.

    model.result("pg1").run();
    model.result("pg1").run();

//    In the Model Builder window, under Results, click Mode Shape (solid).
//    In the Settings window for 2D Plot Group, locate the Data section.
//    From the Eigenfrequency (Hz) list, select 8.5548E8.

    model.result("pg1").set("looplevel", new int[]{2, 1});

//    In the Mode Shape (solid) toolbar, click Plot.

    model.result("pg1").run();

//    Click the Zoom Extents button in the Graphics toolbar.
//    To visualize the electric potential distribution for the eigenmodes, follow these steps.

    model.result("pg2").run();

//    In the Model Builder window, expand the Results > Electric Potential (es) node, then click Surface 1.
//    In the Settings window for Surface, locate the Coloring and Style section.
//    From the Color table list, select WaveLight.

    model.result("pg2").feature("surf1").set("colortable", "WaveLight");

//    Right-click Surface 1 and choose Height Expression.

    model.result("pg2").feature("surf1").create("hght1", "Height");
    model.result("pg2").run();
    model.result("pg2").run();

//    In the Model Builder window, right-click Results > Electric Potential (es) > Streamline 1 and choose Disable.

    model.result("pg2").feature("str1").active(false);
    model.result("pg2").run();

//    In the Model Builder window, click Electric Potential (es).
//    In the Settings window for 2D Plot Group, locate the Color Legend section.
//    Clear the Show legends checkbox.

    model.result("pg2").set("showlegends", false);

//    Locate the Data section.
//    From the Parameter value (switch) list, select 0.

    model.result("pg2").set("looplevel", new int[]{1, 1});

//    In the Electric Potential (es) toolbar, click Plot.

    model.result("pg2").run();

//    Click the Zoom Extents button in the Graphics toolbar.
//    From the Eigenfrequency (Hz) list, select 8.5548E8.

    model.result("pg2").set("looplevel", new int[]{2, 1});

//    In the Electric Potential (es) toolbar, click Plot.

    model.result("pg2").run();

//    Click the Zoom Extents button in the Graphics toolbar.
//    To see all computed eigenfrequencies as a table, follow these steps.
//    In the Results toolbar, click Global Evaluation.

    model.result().numerical().create("gev1", "EvalGlobal");

//    In the Settings window for Global Evaluation, locate the Data section.
//    From the Dataset list, select Study 1/Parametric Solutions 1 (sol2).

    model.result().numerical("gev1").set("data", "dset2");

//    From the Table columns list, select Outer solutions.

    model.result().numerical("gev1").set("tablecols", "outer");

//    Click Replace Expression in the upper-right corner of the Expressions section.
//    From the menu, choose Solver > freq - Frequency - Hz.

    model.result().numerical("gev1").set("expr", new String[]{"freq"});
    model.result().numerical("gev1").set("descr", new String[]{"Frequency"});
    model.result().numerical("gev1").set("unit", new String[]{"Hz"});

//    Click ^ next to Evaluate then choose New Table.

    model.result().table().create("tbl1", "Table");
    model.result().table("tbl1").comments("Global Evaluation 1");
    model.result().numerical("gev1").set("table", "tbl1");
    model.result().numerical("gev1").setResult();

//    Click Full Precision in the window toolbar.
//    The first 6 digits of the eigenfrequency are the same. Subtracting the new value from the previous value shows that the eigenfrequency with gas exposure is lower by approximately 200 Hz.

    model.title("Surface Acoustic Wave Gas Sensor");

    model
         .description("This model analyzes the eigenfrequencies of a surface acoustic wave (SAW) gas sensor. In particular, the model studies how the additional mass load from an adsorbed gas lowers the resonance frequency.");

    return model;
  }

  public static void main(String[] args) {
    Model model = run();
    run2(model);
  }

}
