/*
 * thickness_shear_quartz_oscillator.java
 */

import com.comsol.model.*;
import com.comsol.model.util.*;

/** Model exported on May 11 2026, 08:00 by COMSOL 6.4.0.417. */
public class thickness_shear_quartz_oscillator {

  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 3D.
//    In the Select Physics tree, select Structural Mechanics > Electromagnetics–Structure Interaction > Piezoelectricity > Piezoelectricity, Solid.
//    Click Add.
//    We will select the <l>Adaptive Frequency Sweep</l> study step later.
//    Click Done.

    model.component().create("comp1", true);

    model.component("comp1").geom().create("geom1", 3);
    model.component("comp1").geom("geom1").geomRep("comsol");

    model.component("comp1").mesh().create("mesh1");
    model.component("comp1").mesh("mesh1").contribute("geom/detail", true);

    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", 3);
    model.component("comp1").multiphysics("pze1").set("Solid_physics", "solid");
    model.component("comp1").multiphysics("pze1").set("Electrostatics_physics", "es");

//    Add parameters for the model geometry and series capacitance.
//    In the Model Builder window, under Global Definitions, click Parameters 1.
//    In the Settings window for Parameters, locate the Parameters section.
//    In the table, enter the following settings:

    model.param().set("Cs", "1[pF]");
    model.param().descr("Cs", "Series capacitance");
    model.param().set("R0", "835[um]");
    model.param().descr("R0", "Oscillator radius");
    model.param().set("H0", "334[um]");
    model.param().descr("H0", "Oscillator thickness");

//    Instead of building the geometry from scratch, import a prebuilt mesh. This showcases a less-known functionality of COMSOL Multiphysics to create and solve a model from imported mesh without needing any geometry object to be created.
//    To keep the computational time and RAM requirements as low as possible, we use a coarse mesh. For this kind of high-Q systems, a much finer mesh is required for the resonant structure to be truly converged.

    model.component("comp1").geom("geom1").run();

//    In the Mesh toolbar, click Import.

    model.component("comp1").mesh("mesh1").create("imp1", "Import");

//    In the Settings window for Import, locate the Import section.
//    Click Browse.
//    Browse to the model's Application Library folder and double-click the file thickness_shear_quartz_oscillator_mesh.mphbin.

    model.component("comp1").mesh("mesh1").feature("imp1")
         .set("filename", "thickness_shear_quartz_oscillator_mesh.mphbin");

//    Click Import.

    model.component("comp1").mesh("mesh1").feature("imp1").importData();

//    Create an operator to evaluate quantities on a point for the <l>Adaptive Frequency Sweep</l> study step.
//    In the Definitions toolbar, click Nonlocal Couplings and choose Integration.

    model.component("comp1").cpl().create("intop1", "Integration");

    model.component("comp1").mesh("mesh1").run();

    model.component("comp1").cpl("intop1").set("axisym", true);

//    In the Settings window for Integration, locate the Source Selection section.
//    From the Geometric entity level list, select Point.

    model.component("comp1").cpl("intop1").selection().geom("geom1", 0);

//    Select Point 8.

    model.component("comp1").cpl("intop1").selection().set(8);

//    The <l>Adaptive Frequency Sweep</l> study step will generate a high resolution frequency sweep. To avoid large file size, create an "explicit selection" to store solution data only on the external surfaces of the modeling domain.
//    In the Definitions toolbar, click Explicit.

    model.component("comp1").selection().create("sel1", "Explicit");

//    In the Settings window for Explicit, type All surfaces in the Label text field.

    model.component("comp1").selection("sel1").label("All surfaces");

//    Locate the Input Entities section.
//    From the Geometric entity level list, select Boundary.

    model.component("comp1").selection("sel1").geom(2);

//    Select the All boundaries checkbox.

    model.component("comp1").selection("sel1").all();

//    Set up a rotated system appropriate for AT cut Quartz.
//    In the Definitions toolbar, click Coordinate Systems and choose Rotated System.

    model.component("comp1").coordSystem().create("sys2", "Rotated");

//    In the Settings window for Rotated System, locate the Rotation section.
//    Find the Euler angles subsection.
//    In the β text field, type 125.25[deg].

    model.component("comp1").coordSystem("sys2").set("angle", new String[]{"0", "125.25[deg]", "0"});

//    In the Materials toolbar, click Add Material to open the Add Material window.
//    In the tree, select Piezoelectric > Quartz LH (1978 IEEE).
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat1", "Common");
    model.component("comp1").material("mat1").propertyGroup()
         .create("StrainCharge", "StrainCharge", "Strain-charge form");
    model.component("comp1").material("mat1").propertyGroup()
         .create("StressCharge", "StressCharge", "Stress-charge form");
    model.component("comp1").material("mat1").label("Quartz LH (1978 IEEE)");
    model.component("comp1").material("mat1").set("family", "custom");
    model.component("comp1").material("mat1").set("diffuse", "custom");
    model.component("comp1").material("mat1").set("ambient", "custom");
    model.component("comp1").material("mat1").set("noise", true);
    model.component("comp1").material("mat1").set("fresnel", 0.99);
    model.component("comp1").material("mat1").set("roughness", 0.02);
    model.component("comp1").material("mat1").set("diffusewrap", 0);
    model.component("comp1").material("mat1").set("reflectance", 0);
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("relpermittivity", new String[]{"4.428", "0", "0", "0", "4.428", "0", "0", "0", "4.634"});
    model.component("comp1").material("mat1").propertyGroup("def").set("density", "2651[kg/m^3]");
    model.component("comp1").material("mat1").propertyGroup("StrainCharge").label("Strain-charge form");
    model.component("comp1").material("mat1").propertyGroup("StrainCharge")
         .set("sE", new String[]{"1.277e-011[1/Pa]", "-1.79e-012[1/Pa]", "-1.22e-012[1/Pa]", "-4.5e-012[1/Pa]", "0[1/Pa]", "0[1/Pa]", "-1.79e-012[1/Pa]", "1.277e-011[1/Pa]", "-1.22e-012[1/Pa]", "4.5e-012[1/Pa]", 
         "0[1/Pa]", "0[1/Pa]", "-1.22e-012[1/Pa]", "-1.22e-012[1/Pa]", "9.6e-012[1/Pa]", "0[1/Pa]", "0[1/Pa]", "0[1/Pa]", "-4.5e-012[1/Pa]", "4.5e-012[1/Pa]", 
         "0[1/Pa]", "2.00e-011[1/Pa]", "0[1/Pa]", "0[1/Pa]", "0[1/Pa]", "0[1/Pa]", "0[1/Pa]", "0[1/Pa]", "2.00e-011[1/Pa]", "-9e-012[1/Pa]", 
         "0[1/Pa]", "0[1/Pa]", "0[1/Pa]", "0[1/Pa]", "-9e-012[1/Pa]", "2.912e-011[1/Pa]"});
    model.component("comp1").material("mat1").propertyGroup("StrainCharge")
         .set("dET", new String[]{"-2.307e-012[C/N]", "0[C/N]", "0[C/N]", "2.307e-012[C/N]", "0[C/N]", "0[C/N]", "0[C/N]", "0[C/N]", "0[C/N]", "7.25e-013[C/N]", 
         "0[C/N]", "0[C/N]", "0[C/N]", "-7.25e-013[C/N]", "0[C/N]", "0[C/N]", "4.6e-012[C/N]", "0[C/N]"});
    model.component("comp1").material("mat1").propertyGroup("StrainCharge")
         .set("epsilonrT", new String[]{"4.514", "0", "0", "0", "4.514", "0", "0", "0", "4.634"});
    model.component("comp1").material("mat1").propertyGroup("StressCharge").label("Stress-charge form");
    model.component("comp1").material("mat1").propertyGroup("StressCharge")
         .set("cE", new String[]{"8.67362e+010[Pa]", "6.98527e+009[Pa]", "1.19104e+010[Pa]", "1.79081e+010[Pa]", "0[Pa]", "0[Pa]", "6.98527e+009[Pa]", "8.67362e+010[Pa]", "1.19104e+010[Pa]", "-1.79081e+010[Pa]", 
         "0[Pa]", "0[Pa]", "1.19104e+010[Pa]", "1.19104e+010[Pa]", "1.07194e+011[Pa]", "0[Pa]", "0[Pa]", "0[Pa]", "1.79081e+010[Pa]", "-1.79081e+010[Pa]", 
         "0[Pa]", "5.79428e+010[Pa]", "0[Pa]", "0[Pa]", "0[Pa]", "0[Pa]", "0[Pa]", "0[Pa]", "5.79492e+010[Pa]", "1.79224e+010[Pa]", 
         "0[Pa]", "0[Pa]", "0[Pa]", "0[Pa]", "1.79224e+010[Pa]", "3.99073e+010[Pa]"});
    model.component("comp1").material("mat1").propertyGroup("StressCharge")
         .set("eES", new String[]{"-0.1710[C/m^2]", "0[C/m^2]", "0[C/m^2]", "0.1710[C/m^2]", "0[C/m^2]", "0[C/m^2]", "0[C/m^2]", "0[C/m^2]", "0[C/m^2]", "-0.0406[C/m^2]", 
         "0[C/m^2]", "0[C/m^2]", "0[C/m^2]", "0.0406[C/m^2]", "0[C/m^2]", "0[C/m^2]", "0.1710[C/m^2]", "0[C/m^2]"});
    model.component("comp1").material("mat1").propertyGroup("StressCharge")
         .set("epsilonrS", new String[]{"4.428", "0", "0", "0", "4.428", "0", "0", "0", "4.634"});

//    In the Materials toolbar, click Add Material to close the Add Material window.
//    Use the rotated system to define the orientation of the crystal.
//    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 Coordinate System Selection section.
//    From the Coordinate system list, select Rotated System 2 (sys2).

    model.component("comp1").physics("solid").feature("pzm1").set("coordinateSystem", "sys2");

//    Add damping to the model.
//    In the Physics toolbar, click Attributes and choose Mechanical Damping.

    model.component("comp1").physics("solid").feature("pzm1").create("mdmp1", "MechanicalDamping", 3);

//    In the Settings window for Mechanical Damping, locate the Damping Settings section.
//    From the Damping type list, select Isotropic loss factor.

    model.component("comp1").physics("solid").feature("pzm1").feature("mdmp1")
         .set("DampingType", "IsotropicLossFactor");

//    From the \[\eta_{\textrm{s}}\] list, select User defined.

    model.component("comp1").physics("solid").feature("pzm1").feature("mdmp1").set("eta_s_mat", "userdef");

//    In the associated text field, type 1e-3.

    model.component("comp1").physics("solid").feature("pzm1").feature("mdmp1").set("eta_s", "1e-3");

//    Add electrical boundary conditions to the model. First add a <l>Boundary Terminal</l> feature that connects the electrode to an external circuit.
//    In the Model Builder window, under Component 1 (comp1), click Electrostatics (es).
//    In the Physics toolbar, click Boundaries and choose Boundary Terminal.

    model.component("comp1").physics("es").create("term1", "Terminal", 2);

//    Select Boundary 4.

    model.component("comp1").physics("es").feature("term1").selection().set(4);

//    In the Settings window for Boundary Terminal, locate the Terminal section.
//    From the Terminal type list, select Circuit.

    model.component("comp1").physics("es").feature("term1").set("TerminalType", "Circuit");

//    Override the preceding boundary condition with a constant potential boundary condition to compute the response of the device without a series capacitance. This node will be disabled in the study when the circuit is included in the model.
//    In the Physics toolbar, click Boundaries and choose Boundary Terminal.

    model.component("comp1").physics("es").create("term2", "Terminal", 2);

//    In the Settings window for Boundary Terminal, locate the Terminal section.
//    In the Terminal name text field, type 1.

    model.component("comp1").physics("es").feature("term2").set("TerminalName", "1");

//    Select Boundary 4.

    model.component("comp1").physics("es").feature("term2").selection().set(4);

//    From the Terminal type list, select Voltage.

    model.component("comp1").physics("es").feature("term2").set("TerminalType", "Voltage");

//    In the \[V_\textrm{0}\] text field, type 10.

    model.component("comp1").physics("es").feature("term2").set("V0", 10);

//    In the Physics toolbar, click Boundaries and choose Ground.

    model.component("comp1").physics("es").create("gnd1", "Ground", 2);

//    Select Boundary 3.

    model.component("comp1").physics("es").feature("gnd1").selection().set(3);

//    In the second study in this model, the effect of a series capacitor on the device response will be investigated. Add an <l>Electrical Circuit</l> interface to model the capacitor.
//    In the Home toolbar, click Add Physics to open the Add Physics window.
//    In the tree, select AC/DC > Electrical Circuit (cir).
//    Click Add to Component 1 in the window toolbar.

    model.component("comp1").physics().create("cir", "Circuit", "geom1");

//    In the Home toolbar, click Add Physics to close the Add Physics window.
//    Features in the <l>Electrical Circuit</l> interface are connected by specifying connecting node numbers for each port of the device.
//    A ground node is automatically added to the circuit, with the default node number of 0.
//    Next add a voltage source between the ground node and a (newly created) node with number 2.
//    In the Electrical Circuit toolbar, click Voltage Source.

    model.component("comp1").physics("cir").create("V1", "VoltageSource", -1);

//    In the Settings window for Voltage Source, locate the Node Connections section.
//    In the table, enter the following settings:

    model.component("comp1").physics("cir").feature("V1").setIndex("Connections", 2, 0, 0);
    model.component("comp1").physics("cir").feature("V1").setIndex("Connections", 0, 1, 0);

//    Locate the Device Parameters section.
//    From the Source type list, select AC-source.

    model.component("comp1").physics("cir").feature("V1").set("sourceType", "AC");

//    In the \[v_{\textrm{src}}\] text field, type 10.

    model.component("comp1").physics("cir").feature("V1").set("value", 10);

//    Add a capacitor between the voltage source output (node 2) and a new node, 1.
//    In the Electrical Circuit toolbar, click Capacitor.

    model.component("comp1").physics("cir").create("C1", "Capacitor", -1);

//    In the Settings window for Capacitor, locate the Node Connections section.
//    In the table, enter the following settings:

    model.component("comp1").physics("cir").feature("C1").setIndex("Connections", 2, 0, 0);
    model.component("comp1").physics("cir").feature("C1").setIndex("Connections", 1, 1, 0);

//    Locate the Device Parameters section.
//    In the \[C\] text field, type Cs.

    model.component("comp1").physics("cir").feature("C1").set("C", "Cs");

//    Connect node 1 to the <l>Terminal</l> feature in the model using the <l>External I-Terminal</l> feature.
//    In the Electrical Circuit toolbar, click External I-Terminal.

    model.component("comp1").physics("cir").create("termI1", "ModelTerminalIV", -1);

//    Couple the electric potential from the <l>Terminal</l> in the electrostatics interface back into the model.
//    In the Settings window for External I-Terminal, locate the Node Connections section.
//    In the Node name text field, type 1.

    model.component("comp1").physics("cir").feature("termI1").set("Connections", 1);

//    Locate the External Terminal section.
//    From the \[V\] list, select Terminal voltage (es).

    model.component("comp1").physics("cir").feature("termI1").set("V_src", "root.comp1.es.V0_1");

//    In the Model Builder window, under Component 1 (comp1), click Mesh 1.
//    The mesh used here is somewhat coarse for this kind of high-Q systems. The reason is mainly to keep the computational time and RAM requirements as low as possible. Interested users are encouraged to solve the problem for finer mesh settings.
//    Set up and solve an <l>Adaptive Frequency Sweep</l> study, which is optimized for resolving narrow resonant peaks without excessive computation.
//    In the Home toolbar, click Add Study to open the Add Study window.
//    Find the Studies subsection.
//    In the Select Study tree, select Empty Study.
//    Click Add Study in the window toolbar.

    model.study().create("std1");

//    In the Home toolbar, click Add Study to close the Add Study window.
//    In the Study toolbar, click More Study Steps and choose Frequency Domain > Adaptive Frequency Sweep.

    model.study("std1").create("frawe", "FrequencyAdaptive");

//    In the Settings window for Adaptive Frequency Sweep, locate the Study Settings section.
//    In the Frequencies text field, type range(5.095[MHz],0.2[kHz],5.13[MHz]).

    model.study("std1").feature("frawe").set("plist", "range(5.095[MHz],0.2[kHz],5.13[MHz])");

//    From the AWE expression type list, select User controlled.

    model.study("std1").feature("frawe").set("awefunctype", "usercontrolled");

//    In the table, enter the following settings:

    model.study("std1").feature("frawe").setIndex("awefunc", "comp1.intop1(abs(comp1.u)/1e-9[m])", 0);

//    In the first study, disable the electrical circuit.

    model.study("std1").feature("frawe").setSolveFor("/physics/cir", false);

//    Locate the Physics and Variables Selection section.
//    In the Solve for column of the table, under Component 1 (comp1), clear the checkbox for Electrical Circuit (cir).
//    In the Study toolbar, click Compute.

    model.study("std1").createAutoSequences("all");

    model.sol("sol1").runAll();

    model.result().create("pg1", "PlotGroup3D");
    model.result("pg1").set("data", "dset1");
    model.result("pg1").setIndex("looplevel", 176, 0);
    model.result("pg1").label("Stress (solid)");
    model.result("pg1").set("frametype", "spatial");
    model.result("pg1").create("vol1", "Volume");
    model.result("pg1").feature("vol1").set("expr", new String[]{"solid.misesGp"});
    model.result("pg1").feature("vol1").set("threshold", "manual");
    model.result("pg1").feature("vol1").set("thresholdvalue", 0.2);
    model.result("pg1").feature("vol1").set("colortable", "Rainbow");
    model.result("pg1").feature("vol1").set("colortabletrans", "none");
    model.result("pg1").feature("vol1").set("colorscalemode", "linear");
    model.result("pg1").feature("vol1").set("resolution", "custom");
    model.result("pg1").feature("vol1").set("refine", 2);
    model.result("pg1").feature("vol1").set("colortable", "Prism");
    model.result("pg1").feature("vol1").create("def", "Deform");
    model.result("pg1").feature("vol1").feature("def").set("expr", new String[]{"u", "v", "w"});
    model.result("pg1").feature("vol1").feature("def").set("descr", "Displacement field");
    model.result().create("pg2", "PlotGroup3D");
    model.result("pg2").label("Electric Potential (es)");
    model.result("pg2").set("frametype", "spatial");
    model.result("pg2").set("showlegendsmaxmin", true);
    model.result("pg2").feature().create("mslc1", "Multislice");
    model.result("pg2").feature("mslc1").set("solutionparams", "parent");
    model.result("pg2").feature("mslc1").set("expr", "V");
    model.result("pg2").feature("mslc1").set("multiplanexmethod", "coord");
    model.result("pg2").feature("mslc1").set("xcoord", "es.CPx");
    model.result("pg2").feature("mslc1").set("multiplaneymethod", "coord");
    model.result("pg2").feature("mslc1").set("ycoord", "es.CPy");
    model.result("pg2").feature("mslc1").set("multiplanezmethod", "coord");
    model.result("pg2").feature("mslc1").set("zcoord", "es.CPz");
    model.result("pg2").feature("mslc1").set("colortable", "Dipole");
    model.result("pg2").feature("mslc1").set("evaluationsettings", "parent");
    model.result("pg2").feature("mslc1").set("data", "parent");
    model.result("pg2").feature().create("strmsl1", "StreamlineMultislice");
    model.result("pg2").feature("strmsl1").set("solutionparams", "parent");
    model.result("pg2").feature("strmsl1").set("expr", new String[]{"es.Ex", "es.Ey", "es.Ez"});
    model.result("pg2").feature("strmsl1").set("multiplanexmethod", "coord");
    model.result("pg2").feature("strmsl1").set("xcoord", "es.CPx");
    model.result("pg2").feature("strmsl1").set("multiplaneymethod", "coord");
    model.result("pg2").feature("strmsl1").set("ycoord", "es.CPy");
    model.result("pg2").feature("strmsl1").set("multiplanezmethod", "coord");
    model.result("pg2").feature("strmsl1").set("zcoord", "es.CPz");
    model.result("pg2").feature("strmsl1").set("titletype", "none");
    model.result("pg2").feature("strmsl1").set("posmethod", "uniform");
    model.result("pg2").feature("strmsl1").set("udensity", 8);
    model.result("pg2").feature("strmsl1").set("color", "black");
    model.result("pg2").feature("strmsl1").set("evaluationsettings", "parent");
    model.result("pg2").feature("strmsl1").set("maxlen", 0.4);
    model.result("pg2").feature("strmsl1").set("maxtime", Double.POSITIVE_INFINITY);
    model.result("pg2").feature("strmsl1").set("inheritcolor", false);
    model.result("pg2").feature("strmsl1").set("maxtime", Double.POSITIVE_INFINITY);
    model.result("pg2").feature("strmsl1").set("data", "parent");
    model.result("pg2").feature("strmsl1").set("inheritplot", "mslc1");
    model.result("pg2").feature("strmsl1").feature().create("tran1", "Transparency");
    model.result("pg2").feature("strmsl1").feature("tran1").set("transparency", 0.9);
    model.result("pg2").feature("strmsl1").feature().create("filt1", "Filter");
    model.result("pg2").feature("strmsl1").feature("filt1").set("expr", "!isScalingSystemDomain");
    model.result().create("pg3", "PlotGroup3D");
    model.result("pg3").label("Electric Field (es)");
    model.result("pg3").set("frametype", "spatial");
    model.result("pg3").set("showlegendsmaxmin", true);
    model.result("pg3").feature().create("mslc1", "Multislice");
    model.result("pg3").feature("mslc1").set("solutionparams", "parent");
    model.result("pg3").feature("mslc1").set("expr", "es.normE");
    model.result("pg3").feature("mslc1").set("multiplanexmethod", "coord");
    model.result("pg3").feature("mslc1").set("xcoord", "es.CPx");
    model.result("pg3").feature("mslc1").set("multiplaneymethod", "coord");
    model.result("pg3").feature("mslc1").set("ycoord", "es.CPy");
    model.result("pg3").feature("mslc1").set("multiplanezmethod", "coord");
    model.result("pg3").feature("mslc1").set("zcoord", "es.CPz");
    model.result("pg3").feature("mslc1").set("colortable", "Prism");
    model.result("pg3").feature("mslc1").set("colortabletrans", "nonlinear");
    model.result("pg3").feature("mslc1").set("colorcalibration", -0.8);
    model.result("pg3").feature("mslc1").set("evaluationsettings", "parent");
    model.result("pg3").feature("mslc1").set("data", "parent");
    model.result("pg3").feature().create("strmsl1", "StreamlineMultislice");
    model.result("pg3").feature("strmsl1").set("solutionparams", "parent");
    model.result("pg3").feature("strmsl1").set("expr", new String[]{"es.Ex", "es.Ey", "es.Ez"});
    model.result("pg3").feature("strmsl1").set("multiplanexmethod", "coord");
    model.result("pg3").feature("strmsl1").set("xcoord", "es.CPx");
    model.result("pg3").feature("strmsl1").set("multiplaneymethod", "coord");
    model.result("pg3").feature("strmsl1").set("ycoord", "es.CPy");
    model.result("pg3").feature("strmsl1").set("multiplanezmethod", "coord");
    model.result("pg3").feature("strmsl1").set("zcoord", "es.CPz");
    model.result("pg3").feature("strmsl1").set("titletype", "none");
    model.result("pg3").feature("strmsl1").set("posmethod", "uniform");
    model.result("pg3").feature("strmsl1").set("udensity", 8);
    model.result("pg3").feature("strmsl1").set("color", "black");
    model.result("pg3").feature("strmsl1").set("evaluationsettings", "parent");
    model.result("pg3").feature("strmsl1").set("maxlen", 0.4);
    model.result("pg3").feature("strmsl1").set("maxtime", Double.POSITIVE_INFINITY);
    model.result("pg3").feature("strmsl1").set("inheritcolor", false);
    model.result("pg3").feature("strmsl1").set("maxtime", Double.POSITIVE_INFINITY);
    model.result("pg3").feature("strmsl1").set("data", "parent");
    model.result("pg3").feature("strmsl1").set("inheritplot", "mslc1");
    model.result("pg3").feature("strmsl1").feature().create("tran1", "Transparency");
    model.result("pg3").feature("strmsl1").feature("tran1").set("transparency", 0.9);
    model.result("pg3").feature("strmsl1").feature().create("filt1", "Filter");
    model.result("pg3").feature("strmsl1").feature("filt1").set("expr", "!isScalingSystemDomain");
    model.result().create("pg4", "PlotGroup1D");
    model.result("pg4").set("data", "dset1");
    model.result("pg4").create("glob1", "Global");
    model.result("pg4").feature("glob1").set("unit", new String[]{""});
    model.result("pg4").feature("glob1").set("expr", new String[]{"solid.Wh_tot"});
    model.result("pg4").feature("glob1").set("descr", new String[]{"Total stored energy"});
    model.result("pg4").label("Total Stored Energy (pze1)");
    model.result("pg1").run();

//    Instead of the stress plot, visualize the mode shape of the device at resonance.

    model.result("pg1").run();

//    In the Model Builder window, under Results, click Stress (solid).
//    In the Settings window for 3D Plot Group, type Displacement in the Label text field.

    model.result("pg1").label("Displacement");

//    Locate the Data section.
//    From the Parameter value (freq (Hz)) list, select 5.112E6.

    model.result("pg1").setIndex("looplevel", 86, 0);
    model.result("pg1").run();

//    In the Model Builder window, expand the Displacement node, then click Volume 1.
//    In the Settings window for Volume, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Solid Mechanics > Displacement > solid.disp - Displacement magnitude - m.

    model.result("pg1").feature("vol1").set("expr", "solid.disp");
    model.result("pg1").feature("vol1").set("descr", "Displacement magnitude");

//    Locate the Expression section.
//    From the Unit list, select nm.

    model.result("pg1").feature("vol1").set("unit", "nm");

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Displacement toolbar, click Plot.

    model.result("pg1").run();

//    The second default plot shows the electric potential within the device. For a better view, plot 5 slices in \[xy\] planes.

    model.result("pg2").run();

//    In the Model Builder window, under Results, click Electric Potential (es).
//    In the Settings window for 3D Plot Group, locate the Data section.
//    From the Parameter value (freq (Hz)) list, select 5.112E6.

    model.result("pg2").setIndex("looplevel", 86, 0);
    model.result("pg2").run();

//    In the Model Builder window, expand the Electric Potential (es) node, then click Multislice 1.
//    In the Settings window for Multislice, locate the Multiplane Data section.
//    Find the x-planes subsection.
//    From the Entry method list, select Number of planes.

    model.result("pg2").feature("mslc1").set("multiplanexmethod", "number");

//    In the Planes text field, type 5.

    model.result("pg2").feature("mslc1").set("xnumber", "5");

//    Find the y-planes subsection.
//    From the Entry method list, select Number of planes.

    model.result("pg2").feature("mslc1").set("multiplaneymethod", "number");

//    In the Planes text field, type 0.

    model.result("pg2").feature("mslc1").set("ynumber", "0");

//    Find the z-planes subsection.
//    From the Entry method list, select Number of planes.

    model.result("pg2").feature("mslc1").set("multiplanezmethod", "number");

//    In the Planes text field, type 0.

    model.result("pg2").feature("mslc1").set("znumber", "0");
    model.result("pg2").run();

//    In the Model Builder window, click Streamline Multislice 1.
//    In the Settings window for Streamline Multislice, locate the Multiplane Data section.
//    Find the x-planes subsection.
//    From the Entry method list, select Number of planes.

    model.result("pg2").feature("strmsl1").set("multiplanexmethod", "number");

//    In the Planes text field, type 5.

    model.result("pg2").feature("strmsl1").set("xnumber", "5");

//    Find the y-planes subsection.
//    From the Entry method list, select Number of planes.

    model.result("pg2").feature("strmsl1").set("multiplaneymethod", "number");

//    In the Planes text field, type 0.

    model.result("pg2").feature("strmsl1").set("ynumber", "0");

//    Find the z-planes subsection.
//    From the Entry method list, select Number of planes.

    model.result("pg2").feature("strmsl1").set("multiplanezmethod", "number");

//    In the Planes text field, type 0.

    model.result("pg2").feature("strmsl1").set("znumber", "0");

//    In the Electric Potential (es) toolbar, click Plot.

    model.result("pg2").run();

//    Add a plot to show the mechanical response of the device.
//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg5", "PlotGroup1D");
    model.result("pg5").run();

//    In the Settings window for 1D Plot Group, type Mechanical Response in the Label text field.

    model.result("pg5").label("Mechanical Response");

//    Right-click Mechanical Response and choose Point Graph.

    model.result("pg5").create("ptgr1", "PointGraph");
    model.result("pg5").feature("ptgr1").set("markerpos", "datapoints");
    model.result("pg5").feature("ptgr1").set("linewidth", "preference");

//    Select Point 8.

    model.result("pg5").feature("ptgr1").selection().set(8);

//    In the Settings window for Point Graph, locate the y-Axis Data section.
//    In the Expression text field, type abs(u).

    model.result("pg5").feature("ptgr1").set("expr", "abs(u)");

//    From the Unit list, select nm.

    model.result("pg5").feature("ptgr1").set("unit", "nm");

//    Locate the x-Axis Data section.
//    From the Unit list, select MHz.

    model.result("pg5").feature("ptgr1").set("xdataparamunit", "MHz");

//    In the Mechanical Response toolbar, click Plot.

    model.result("pg5").run();

//    Now set up a study to compute the frequency response of the device with different capacitors added in series.
//    In the Home toolbar, click Add Study to open the Add Study window.
//    Find the Studies subsection.
//    In the Select Study tree, select Empty Study.
//    Click Add Study in the window toolbar.

    model.study().create("std2");

//    In the Home toolbar, click Add Study to close the Add Study window.
//    In the Study toolbar, click More Study Steps and choose Frequency Domain > Adaptive Frequency Sweep.

    model.study("std2").create("frawe", "FrequencyAdaptive");

//    In the Settings window for Adaptive Frequency Sweep, locate the Study Settings section.
//    In the Frequencies text field, type range(5.095[MHz],0.2[kHz],5.13[MHz]).

    model.study("std2").feature("frawe").set("plist", "range(5.095[MHz],0.2[kHz],5.13[MHz])");

//    From the AWE expression type list, select User controlled.

    model.study("std2").feature("frawe").set("awefunctype", "usercontrolled");

//    In the table, enter the following settings:

    model.study("std2").feature("frawe").setIndex("awefunc", "comp1.intop1(abs(comp1.u)/1e-9[m])", 0);

//    Locate the Physics and Variables Selection section.
//    Select the Modify model configuration for study step checkbox.

    model.study("std2").feature("frawe").set("useadvanceddisable", true);

//    In the tree, select Component 1 (comp1) > Electrostatics (es) > Boundary Terminal 2.
//    Click Disable.

    model.study("std2").feature("frawe").set("disabledphysics", new String[]{"es/term2"});

    return model;
  }

  public static Model run2(Model model) {

//    To reduce file size, only store solution data on the external surfaces.
//    Click to expand the Store in Output section.
//    In the table, enter the following settings:

    model.study("std2").feature("frawe").setEntry("outputmap", "solid", "selection");

//    Under Selections, click Add.
//    In the Add dialog, select All surfaces (Boundary) in the Selections list.
//    Click OK.

    model.study("std2").feature("frawe").setEntry("outputselectionmap", "solid", "sel1");

//    In the Settings window for Adaptive Frequency Sweep, locate the Store in Output section.
//    In the table, enter the following settings:

    model.study("std2").feature("frawe").setEntry("outputmap", "es", "selection");

//    Under Selections, click Add.
//    In the Add dialog, select All surfaces (Boundary) in the Selections list.
//    Click OK.

    model.study("std2").feature("frawe").setEntry("outputselectionmap", "es", "sel1");

//    In the Study toolbar, click Parametric Sweep.

    model.study("std2").create("param", "Parametric");

//    In the Settings window for Parametric Sweep, locate the Study Settings section.
//    Click Add.

    model.study("std2").feature("param").setIndex("pname", "Cs", 0);
    model.study("std2").feature("param").setIndex("plistarr", "", 0);
    model.study("std2").feature("param").setIndex("punit", "F", 0);
    model.study("std2").feature("param").setIndex("pname", "Cs", 0);
    model.study("std2").feature("param").setIndex("plistarr", "", 0);
    model.study("std2").feature("param").setIndex("punit", "F", 0);

//    In the table, enter the following settings:

    model.study("std2").feature("param").setIndex("plistarr", "0.1 0.4 1", 0);
    model.study("std2").feature("param").setIndex("punit", "pF", 0);

//    In the Model Builder window, click Study 2.
//    In the Settings window for Study, locate the Study Settings section.
//    Clear the Generate default plots checkbox.

    model.study("std2").setGenPlots(false);

//    In the Study toolbar, click Compute.

    model.study("std2").createAutoSequences("all");

    model.sol().create("sol3");
    model.sol("sol3").study("std2");
    model.sol("sol3").label("Parametric Solutions 1");

    model.batch("p1").feature("so1").set("psol", "sol3");
    model.batch("p1").run("compute");

//    Replot the mechanical response with the additional series capacitance.

    model.result("pg5").run();

//    In the Model Builder window, right-click Mechanical Response and choose Duplicate.

    model.result().duplicate("pg6", "pg5");
    model.result("pg6").run();

//    In the Settings window for 1D Plot Group, type Mechanical response, Parametric in the Label text field.

    model.result("pg6").label("Mechanical response, Parametric");

//    Locate the Data section.
//    From the Dataset list, select Study 2/Parametric Solutions 1 (sol3).

    model.result("pg6").set("data", "dset3");

//    Locate the Legend section.
//    From the Position list, select Upper left.

    model.result("pg6").set("legendpos", "upperleft");
    model.result("pg6").run();

//    In the Model Builder window, expand the Mechanical response, Parametric node, then click Point Graph 1.
//    In the Settings window for Point Graph, click to expand the Legends section.
//    Select the Show legends checkbox.

    model.result("pg6").feature("ptgr1").set("legend", true);

//    In the Mechanical response, Parametric toolbar, click Plot.

    model.result("pg6").run();

//    Note how the mechanical resonant frequency is 'pulled' by the series capacitance.

    model.title("Thickness Shear Mode Quartz Oscillator");

    model
         .description("A quartz oscillator, operated in the thickness shear mode, is simulated. The example shows how to set up the coordinate system correctly for AT cut quartz and to model the response of a device driven at resonance. The resonant frequency of the oscillator is altered by the changing the capacitance of a shunt capacitor.");

    return model;
  }

  public static void main(String[] args) {
    Model model = run();
    run2(model);
  }

}
