/*
 * rat_race_coupler.java
 */

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

/** Model exported on May 13 2026, 09:33 by COMSOL 6.4.0.419. */
public class rat_race_coupler {

  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 Radio Frequency > Electromagnetic Waves, Frequency Domain (emw).
//    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", 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("emw", "ElectromagneticWaves", "geom1");

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

//    Define the study frequency ahead of performing any frequency-dependent operation such as building mesh. The physics-controlled mesh uses the highest frequency value in the specified range.
//    In the Model Builder window, under Study 1, click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Study Settings section.
//    Click Range.
//    In the Range dialog, type 1[GHz] in the Start text field.
//    In the Stop text field, type 5[GHz].
//    In the Step text field, type 100[MHz].
//    Click Replace.

    model.study("std1").feature("freq").set("plist", "range(1[GHz],100[MHz],5[GHz])");

//    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 rat_race_coupler_parameters.txt.
//    To import content from file, use:
//    model.param().loadFile("FILENAME");
    model.param().set("d_subs", "60[mil]", "Substrate thickness");
    model.param().set("r_subs", "25[mm]", "Radius, substrate");
    model.param().set("w_line", "3.2[mm]", "Width, feed line");
    model.param().set("l_line", "10[mm]", "Length, feed line");
    model.param().set("w_ring", "1.4[mm]", "Width, ring");
    model.param().set("r_ring", "14.7[mm]", "Radius, ring");
    model.param().set("r_resonator", "45[mm]", "Height, dielectric resonator");
    model.param().set("x1", "w_line*2", "Substrate size parameter 1");
    model.param().set("y1", "r_subs", "Substrate size parameter 2");

//    Here, <c>mil</c> refers to the unit milliinch.
//    Click the Wireframe Rendering button in the Graphics toolbar.

    model.component("comp1").view("view1").set("renderwireframe", true);

//    First, create two cylinders for the metallic housing.
//    In the Geometry toolbar, click Cylinder.

    model.component("comp1").geom("geom1").create("cyl1", "Cylinder");

//    In the Settings window for Cylinder, locate the Size and Shape section.
//    In the Radius text field, type r_subs*1.1.

    model.component("comp1").geom("geom1").feature("cyl1").set("r", "r_subs*1.1");

//    In the Height text field, type d_subs*5.

    model.component("comp1").geom("geom1").feature("cyl1").set("h", "d_subs*5");

//    In the Geometry toolbar, click Cylinder.

    model.component("comp1").geom("geom1").run("cyl1");
    model.component("comp1").geom("geom1").create("cyl2", "Cylinder");

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

    model.component("comp1").geom("geom1").feature("cyl2").set("r", 0.005);

//    In the Height text field, type d_subs*5.

    model.component("comp1").geom("geom1").feature("cyl2").set("h", "d_subs*5");

//    Add a work plane for the coupler layout.
//    In the Geometry toolbar, click Work Plane.

    model.component("comp1").geom("geom1").run("cyl2");
    model.component("comp1").geom("geom1").create("wp1", "WorkPlane");
    model.component("comp1").geom("geom1").feature("wp1").set("unite", true);

//    Create two circles and subtract one from another for the ring strip.
//    In the Settings window for Work Plane, click Go to Plane Geometry.
//    In the Model Builder window, click Plane Geometry.
//    In the Work Plane toolbar, click Circle.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Settings window for Circle, locate the Size and Shape section.
//    In the Radius text field, type r_ring-w_ring/2.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("c1").set("r", "r_ring-w_ring/2");

//    In the Work Plane toolbar, click Circle.

    model.component("comp1").geom("geom1").feature("wp1").geom().run("c1");
    model.component("comp1").geom("geom1").feature("wp1").geom().create("c2", "Circle");

//    In the Settings window for Circle, locate the Size and Shape section.
//    In the Radius text field, type r_ring+w_ring/2.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("c2").set("r", "r_ring+w_ring/2");

//    In the Work Plane toolbar, click Booleans and Partitions and choose Difference.

    model.component("comp1").geom("geom1").feature("wp1").geom().run("c2");
    model.component("comp1").geom("geom1").feature("wp1").geom().create("dif1", "Difference");

//    Select the object c2.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("dif1").selection("input").set("c2");

//    In the Settings window for Difference, locate the Difference section.
//    Select the Activate Selection toggle button for Objects to subtract.
//    Select the object c1.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("dif1").selection("input2").set("c1");

//    Add a rectangle for the feed line and generate the four feed lines by rotating the rectangle. Use the rotation angle range to create multiple objects.
//    In the Work Plane toolbar, click Rectangle.

    model.component("comp1").geom("geom1").feature("wp1").geom().run("dif1");
    model.component("comp1").geom("geom1").feature("wp1").geom().create("r1", "Rectangle");

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

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("r1")
         .set("size", new String[]{"w_line", "1"});

//    In the Height text field, type l_line.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("r1")
         .set("size", new String[]{"w_line", "l_line"});

//    Locate the Position section.
//    In the xw text field, type -w_line/2.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("r1")
         .set("pos", new String[]{"-w_line/2", "0"});

//    In the yw text field, type r_subs-l_line.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("r1")
         .set("pos", new String[]{"-w_line/2", "r_subs-l_line"});

//    In the Work Plane toolbar, click Transforms and choose Rotate.

    model.component("comp1").geom("geom1").feature("wp1").geom().run("r1");
    model.component("comp1").geom("geom1").feature("wp1").geom().create("rot1", "Rotate");

//    Select the object r1.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("rot1").selection("input").set("r1");

//    In the Settings window for Rotate, locate the Rotation section.
//    Click Range.
//    In the Range dialog, type 0 in the Start text field.
//    In the Stop text field, type 180.
//    In the Step text field, type 60.
//    Click Replace.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("rot1").set("rot", "range(0,60,180)");

//    Create a union of all 2D objects on the work plane to remove the unnecessary interior boundaries.
//    In the Work Plane toolbar, click Booleans and Partitions and choose Union.

    model.component("comp1").geom("geom1").feature("wp1").geom().run("rot1");
    model.component("comp1").geom("geom1").feature("wp1").geom().create("uni1", "Union");

//    Click in the Graphics window and then press Ctrl+A to select all objects.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("uni1").selection("input")
         .set("dif1", "rot1");

//    In the Settings window for Union, locate the Union section.
//    Clear the Keep interior boundaries checkbox.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("uni1").set("intbnd", false);

//    Click Build Selected.

    model.component("comp1").geom("geom1").feature("wp1").geom().run("uni1");

//    Add a polygon for the substrate. This polygon covers only about 1/6 of the substrate area.
//    In the Work Plane toolbar, click Polygon.

    model.component("comp1").geom("geom1").feature("wp1").geom().create("pol1", "Polygon");
    model.component("comp1").geom("geom1").feature("wp1").geom().feature("pol1").set("source", "table");

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Settings window for Polygon, locate the Coordinates section.
//    In the table, enter the following settings:

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("pol1").setIndex("table", 0, 0, 0);
    model.component("comp1").geom("geom1").feature("wp1").geom().feature("pol1").setIndex("table", 0, 0, 1);
    model.component("comp1").geom("geom1").feature("wp1").geom().feature("pol1").setIndex("table", "x1", 1, 0);
    model.component("comp1").geom("geom1").feature("wp1").geom().feature("pol1").setIndex("table", "y1", 1, 1);
    model.component("comp1").geom("geom1").feature("wp1").geom().feature("pol1").setIndex("table", "-x1", 2, 0);
    model.component("comp1").geom("geom1").feature("wp1").geom().feature("pol1").setIndex("table", "y1", 2, 1);
    model.component("comp1").geom("geom1").feature("wp1").geom().feature("pol1")
         .setIndex("table", "-y1*sin(pi/3)+x1*cos(pi/3)", 3, 0);
    model.component("comp1").geom("geom1").feature("wp1").geom().feature("pol1")
         .setIndex("table", "y1*cos(pi/3)+x1*sin(pi/3)", 3, 1);
    model.component("comp1").geom("geom1").feature("wp1").geom().feature("pol1")
         .setIndex("table", "-y1*sin(pi/3)-x1*cos(pi/3)", 4, 0);
    model.component("comp1").geom("geom1").feature("wp1").geom().feature("pol1")
         .setIndex("table", "y1*cos(pi/3)-x1*sin(pi/3)", 4, 1);

//    Click Build Selected.

    model.component("comp1").geom("geom1").feature("wp1").geom().run("pol1");

//    Complete the substrate layout by rotating the polygon.
//    In the Work Plane toolbar, click Transforms and choose Rotate.

    model.component("comp1").geom("geom1").feature("wp1").geom().create("rot2", "Rotate");

//    Select the object pol1.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("rot2").selection("input").set("pol1");

//    In the Settings window for Rotate, locate the Rotation section.
//    Click Range.
//    In the Range dialog, type 0 in the Start text field.
//    In the Stop text field, type 300.
//    In the Step text field, type 60.
//    Click Replace.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("rot2").set("rot", "range(0,60,300)");

//    Create a union of the polygon pieces to remove the unnecessary interior boundaries.
//    In the Work Plane toolbar, click Booleans and Partitions and choose Union.

    model.component("comp1").geom("geom1").feature("wp1").geom().run("rot2");
    model.component("comp1").geom("geom1").feature("wp1").geom().create("uni2", "Union");

//    Select the objects rot2(1), rot2(2), rot2(3), rot2(4), rot2(5), rot2(6).

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("uni2").selection("input").set("rot2");

//    In the Settings window for Union, locate the Union section.
//    Clear the Keep interior boundaries checkbox.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("uni2").set("intbnd", false);

//    Click Build Selected.

    model.component("comp1").geom("geom1").feature("wp1").geom().run("uni2");

//    This is the rat race coupler layout on the \[xy\]-plane.
//    Turn the coupler layout into a 3D structure by extruding the layout.
//    In the Model Builder window, right-click Component 1 (comp1) > Geometry 1 > Work Plane 1 (wp1) and choose Extrude.

    model.component("comp1").geom("geom1").run("wp1");
    model.component("comp1").geom("geom1").feature().create("ext1", "Extrude");
    model.component("comp1").geom("geom1").feature("ext1").set("workplane", "wp1");
    model.component("comp1").geom("geom1").feature("ext1").selection("input").set("wp1");

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

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

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

    model.component("comp1").geom("geom1").feature("ext1").setIndex("distance", "d_subs", 0);

//    Click Build All Objects.

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

//    Create a set of selections for use while setting up the physics. First, create a selection for the substrate.
//    In the Definitions toolbar, click Explicit.

    model.component("comp1").selection().create("sel1", "Explicit");

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

//    In the Settings window for Explicit, type Substrate in the Label text field.

    model.component("comp1").selection("sel1").label("Substrate");

//    Select Domains 2, 3, 4, 5, 6, 9.

    model.component("comp1").selection("sel1").set(2, 3, 4, 5, 6, 9);

//    Next, add a selection for the microstrip line.
//    In the Definitions toolbar, click Explicit.

    model.component("comp1").selection().create("sel2", "Explicit");

//    In the Settings window for Explicit, type Microstrip line in the Label text field.

    model.component("comp1").selection("sel2").label("Microstrip line");

//    Locate the Input Entities section.
//    From the Geometric entity level list, select Boundary.

    model.component("comp1").selection("sel2").geom(2);

//    Select Boundary 13.

    model.component("comp1").selection("sel2").set(13);

//    Add a selection for the cylindrical post in the cavity. This domain is not a part of the modeling domain.
//    In the Definitions toolbar, click Explicit.

    model.component("comp1").selection().create("sel3", "Explicit");

//    In the Settings window for Explicit, type Post in the Label text field.

    model.component("comp1").selection("sel3").label("Post");

//    Select Domains 7, 8.

    model.component("comp1").selection("sel3").set(7, 8);

//    Add a selection for the modeling domain. This is the complement of the cylindrical post domain.
//    In the Definitions toolbar, click Complement.

    model.component("comp1").selection().create("com1", "Complement");

//    In the Settings window for Complement, type Model space in the Label text field.

    model.component("comp1").selection("com1").label("Model space");

//    Locate the Input Entities section.
//    Under Selections to invert, click Add.
//    In the Add dialog, select Post in the Selections to invert list.
//    Click OK.

    model.component("comp1").selection("com1").set("input", new String[]{"sel3"});

//    Hide some boundaries to get a better view of the interior parts when setting up the physics and reviewing the mesh.
//    In the Model Builder window, right-click View 1 and choose Hide for Physics.

    model.component("comp1").view("view1").hideEntities().create("hide1");

//    In the Settings window for Hide for Physics, locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Boundary.

    model.component("comp1").view("view1").hideEntities("hide1").geom("geom1", 2);

//    Select Boundaries 1, 2, 4.

    model.component("comp1").view("view1").hideEntities("hide1").set(1, 2, 4);

//    Now set up the physics.
//    In the Model Builder window, under Component 1 (comp1), click Electromagnetic Waves, Frequency Domain (emw).
//    In the Settings window for Electromagnetic Waves, Frequency Domain, locate the Domain Selection section.
//    From the Selection list, select Model space.

    model.component("comp1").physics("emw").selection().named("com1");

//    The default boundary condition is Perfect electric conductor, which applies to all exterior boundaries. Assign Perfect electric conductor on the interior boundary on the microstrip lines.
//    In the Physics toolbar, click Boundaries and choose Perfect Electric Conductor.

    model.component("comp1").physics("emw").create("pec2", "PerfectElectricConductor", 2);

//    In the Settings window for Perfect Electric Conductor, locate the Boundary Selection section.
//    From the Selection list, select Microstrip line.

    model.component("comp1").physics("emw").feature("pec2").selection().named("sel2");

//    In the Physics toolbar, click Boundaries and choose Lumped Port.

    model.component("comp1").physics("emw").create("lport1", "LumpedPort", 2);

//    Select Boundary 14.

    model.component("comp1").physics("emw").feature("lport1").selection().set(14);

//    For the first port, wave excitation is <l>on</l> by default.
//    In the Physics toolbar, click Boundaries and choose Lumped Port.

    model.component("comp1").physics("emw").create("lport2", "LumpedPort", 2);

//    Select Boundary 46.

    model.component("comp1").physics("emw").feature("lport2").selection().set(46);

//    In the Physics toolbar, click Boundaries and choose Lumped Port.

    model.component("comp1").physics("emw").create("lport3", "LumpedPort", 2);

//    Select Boundary 10.

    model.component("comp1").physics("emw").feature("lport3").selection().set(10);

//    In the Physics toolbar, click Boundaries and choose Lumped Port.

    model.component("comp1").physics("emw").create("lport4", "LumpedPort", 2);

//    Select Boundary 44.

    model.component("comp1").physics("emw").feature("lport4").selection().set(44);

//    Next, assign material properties to the model. Begin by specifying air for all domains.
//    In the Materials toolbar, click Add Material to open the Add Material window.
//    In the tree, select Built-in > Air.
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat1", "Common");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("eta", "Piecewise");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("Cp", "Piecewise");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("rho", "Analytic");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("k", "Piecewise");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("cs", "Analytic");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("an1", "Analytic");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("an2", "Analytic");
    model.component("comp1").material("mat1").propertyGroup()
         .create("RefractiveIndex", "RefractiveIndex", "Refractive index");
    model.component("comp1").material("mat1").propertyGroup()
         .create("NonlinearModel", "NonlinearModel", "Nonlinear model");
    model.component("comp1").material("mat1").propertyGroup().create("idealGas", "idealGas", "Ideal gas");
    model.component("comp1").material("mat1").propertyGroup("idealGas").func().create("Cp", "Piecewise");
    model.component("comp1").material("mat1").label("Air");
    model.component("comp1").material("mat1").set("family", "air");
    model.component("comp1").material("mat1").propertyGroup("def").func("eta").set("arg", "T");
    model.component("comp1").material("mat1").propertyGroup("def").func("eta")
         .set("pieces", new String[][]{{"200.0", "1600.0", "-8.38278E-7+8.35717342E-8*T^1-7.69429583E-11*T^2+4.6437266E-14*T^3-1.06585607E-17*T^4"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("eta").set("argunit", "K");
    model.component("comp1").material("mat1").propertyGroup("def").func("eta").set("fununit", "Pa*s");
    model.component("comp1").material("mat1").propertyGroup("def").func("Cp").set("arg", "T");
    model.component("comp1").material("mat1").propertyGroup("def").func("Cp")
         .set("pieces", new String[][]{{"200.0", "1600.0", "1047.63657-0.372589265*T^1+9.45304214E-4*T^2-6.02409443E-7*T^3+1.2858961E-10*T^4"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("Cp").set("argunit", "K");
    model.component("comp1").material("mat1").propertyGroup("def").func("Cp").set("fununit", "J/(kg*K)");
    model.component("comp1").material("mat1").propertyGroup("def").func("rho")
         .set("expr", "pA*0.02897/R_const[K*mol/J]/T");
    model.component("comp1").material("mat1").propertyGroup("def").func("rho").set("args", new String[]{"pA", "T"});
    model.component("comp1").material("mat1").propertyGroup("def").func("rho").set("fununit", "kg/m^3");
    model.component("comp1").material("mat1").propertyGroup("def").func("rho")
         .set("argunit", new String[]{"Pa", "K"});
    model.component("comp1").material("mat1").propertyGroup("def").func("rho")
         .set("plotaxis", new String[]{"off", "on"});
    model.component("comp1").material("mat1").propertyGroup("def").func("rho")
         .set("plotfixedvalue", new String[]{"101325", "273.15"});
    model.component("comp1").material("mat1").propertyGroup("def").func("rho")
         .set("plotargs", new String[][]{{"pA", "101325", "101325"}, {"T", "273.15", "293.15"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("k").set("arg", "T");
    model.component("comp1").material("mat1").propertyGroup("def").func("k")
         .set("pieces", new String[][]{{"200.0", "1600.0", "-0.00227583562+1.15480022E-4*T^1-7.90252856E-8*T^2+4.11702505E-11*T^3-7.43864331E-15*T^4"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("k").set("argunit", "K");
    model.component("comp1").material("mat1").propertyGroup("def").func("k").set("fununit", "W/(m*K)");
    model.component("comp1").material("mat1").propertyGroup("def").func("cs")
         .set("expr", "sqrt(1.4*R_const[K*mol/J]/0.02897*T)");
    model.component("comp1").material("mat1").propertyGroup("def").func("cs").set("args", new String[]{"T"});
    model.component("comp1").material("mat1").propertyGroup("def").func("cs").set("fununit", "m/s");
    model.component("comp1").material("mat1").propertyGroup("def").func("cs").set("argunit", new String[]{"K"});
    model.component("comp1").material("mat1").propertyGroup("def").func("cs")
         .set("plotfixedvalue", new String[]{"273.15"});
    model.component("comp1").material("mat1").propertyGroup("def").func("cs")
         .set("plotargs", new String[][]{{"T", "273.15", "373.15"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("an1").set("funcname", "alpha_p");
    model.component("comp1").material("mat1").propertyGroup("def").func("an1")
         .set("expr", "-1/rho(pA,T)*d(rho(pA,T),T)");
    model.component("comp1").material("mat1").propertyGroup("def").func("an1").set("args", new String[]{"pA", "T"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an1").set("fununit", "1/K");
    model.component("comp1").material("mat1").propertyGroup("def").func("an1")
         .set("argunit", new String[]{"Pa", "K"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an1")
         .set("plotaxis", new String[]{"off", "on"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an1")
         .set("plotfixedvalue", new String[]{"101325", "273.15"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an1")
         .set("plotargs", new String[][]{{"pA", "101325", "101325"}, {"T", "273.15", "373.15"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("an2").set("funcname", "muB");
    model.component("comp1").material("mat1").propertyGroup("def").func("an2").set("expr", "0.6*eta(T)");
    model.component("comp1").material("mat1").propertyGroup("def").func("an2").set("args", new String[]{"T"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an2").set("fununit", "Pa*s");
    model.component("comp1").material("mat1").propertyGroup("def").func("an2").set("argunit", new String[]{"K"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an2")
         .set("plotfixedvalue", new String[]{"200"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an2")
         .set("plotargs", new String[][]{{"T", "200", "1600"}});
    model.component("comp1").material("mat1").propertyGroup("def").set("thermalexpansioncoefficient", "");
    model.component("comp1").material("mat1").propertyGroup("def").set("molarmass", "");
    model.component("comp1").material("mat1").propertyGroup("def").set("bulkviscosity", "");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("thermalexpansioncoefficient", new String[]{"alpha_p(pA,T)", "0", "0", "0", "alpha_p(pA,T)", "0", "0", "0", "alpha_p(pA,T)"});
    model.component("comp1").material("mat1").propertyGroup("def").set("molarmass", "0.02897[kg/mol]");
    model.component("comp1").material("mat1").propertyGroup("def").set("bulkviscosity", "muB(T)");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("relpermeability", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("relpermittivity", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat1").propertyGroup("def").set("dynamicviscosity", "eta(T)");
    model.component("comp1").material("mat1").propertyGroup("def").set("ratioofspecificheat", "1.4");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("electricconductivity", new String[]{"0[S/m]", "0", "0", "0", "0[S/m]", "0", "0", "0", "0[S/m]"});
    model.component("comp1").material("mat1").propertyGroup("def").set("heatcapacity", "Cp(T)");
    model.component("comp1").material("mat1").propertyGroup("def").set("density", "rho(pA,T)");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("thermalconductivity", new String[]{"k(T)", "0", "0", "0", "k(T)", "0", "0", "0", "k(T)"});
    model.component("comp1").material("mat1").propertyGroup("def").set("soundspeed", "cs(T)");
    model.component("comp1").material("mat1").propertyGroup("def").addInput("temperature");
    model.component("comp1").material("mat1").propertyGroup("def").addInput("pressure");
    model.component("comp1").material("mat1").propertyGroup("RefractiveIndex")
         .set("n", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat1").propertyGroup("NonlinearModel").set("BA", "def.gamma-1");
    model.component("comp1").material("mat1").propertyGroup("idealGas").func("Cp").label("Piecewise 2");
    model.component("comp1").material("mat1").propertyGroup("idealGas").func("Cp").set("arg", "T");
    model.component("comp1").material("mat1").propertyGroup("idealGas").func("Cp")
         .set("pieces", new String[][]{{"200.0", "1600.0", "1047.63657-0.372589265*T^1+9.45304214E-4*T^2-6.02409443E-7*T^3+1.2858961E-10*T^4"}});
    model.component("comp1").material("mat1").propertyGroup("idealGas").func("Cp").set("argunit", "K");
    model.component("comp1").material("mat1").propertyGroup("idealGas").func("Cp").set("fununit", "J/(kg*K)");
    model.component("comp1").material("mat1").propertyGroup("idealGas").set("Rs", "R_const/Mn");
    model.component("comp1").material("mat1").propertyGroup("idealGas").set("heatcapacity", "Cp(T)");
    model.component("comp1").material("mat1").propertyGroup("idealGas").set("ratioofspecificheat", "1.4");
    model.component("comp1").material("mat1").propertyGroup("idealGas").set("molarmass", "0.02897[kg/mol]");
    model.component("comp1").material("mat1").propertyGroup("idealGas").addInput("temperature");
    model.component("comp1").material("mat1").propertyGroup("idealGas").addInput("pressure");
    model.component("comp1").material("mat1").materialType("nonSolid");

//    In the Materials toolbar, click Add Material to close the Add Material window.
//    Override the substrate with the dielectric material of <symbol>e</symbol><sub>r</sub> = 3.38.
//    In the Model Builder window, right-click Materials and choose Blank Material.

    model.component("comp1").material().create("mat2", "Common");

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

    model.component("comp1").material("mat2").label("Substrate");

//    Locate the Geometric Entity Selection section.
//    From the Selection list, select Substrate.

    model.component("comp1").material("mat2").selection().named("sel1");

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

    model.component("comp1").material("mat2").propertyGroup("def").set("relpermittivity", new String[]{"3.38"});
    model.component("comp1").material("mat2").propertyGroup("def").set("relpermeability", new String[]{"1"});
    model.component("comp1").material("mat2").propertyGroup("def").set("electricconductivity", new String[]{"0"});

//    In the Model Builder window, right-click Component 1 (comp1) > Mesh 1 and choose Build All.

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

//    In the Study toolbar, click Compute.

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

    model.component("comp1").probe("emw_lport1_probe").genResult("none");

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

    model.result().create("pg2", "PlotGroup3D");
    model.result("pg2").set("data", "dset1");
    model.result("pg2").setIndex("looplevel", 41, 0);
    model.result("pg2").create("mslc1", "Multislice");
    model.result("pg2").feature("mslc1").set("expr", new String[]{"emw.normE"});
    model.result("pg2").set("showlegendsmaxmin", true);
    model.result("pg2").feature("mslc1").set("colortable", "RainbowLight");
    model.result("pg2").label("Electric Field (emw)");
    model.result().create("pg3", "PlotGroup1D");
    model.result("pg3").set("data", "dset1");
    model.result("pg3").create("glob1", "Global");
    model.result("pg3").feature("glob1").set("unit", new String[]{"", "", "", ""});
    model.result("pg3").feature("glob1")
         .set("expr", new String[]{"emw.S11dB", "emw.S21dB", "emw.S31dB", "emw.S41dB"});
    model.result("pg3").feature("glob1").set("descr", new String[]{"S11", "S21", "S31", "S41"});
    model.result("pg3").label("S-Parameter (emw)");
    model.result("pg3").feature("glob1").set("titletype", "none");
    model.result("pg3").feature("glob1").set("xdata", "expr");
    model.result("pg3").set("ylabelactive", true);
    model.result("pg3").set("ylabel", "S-parameter (dB)");
    model.result("pg3").feature("glob1").set("xdataexpr", "freq");
    model.result("pg3").feature("glob1").set("xdataunit", "GHz");
    model.result("pg3").feature("glob1").set("markerpos", "datapoints");
    model.result("pg3").feature("glob1").set("xdatasolnumtype", "all");
    model.result().create("pg4", "SmithGroup");
    model.result("pg4").set("data", "dset1");
    model.result("pg4").create("rgr1", "ReflectionGraph");
    model.result("pg4").feature("rgr1").set("unit", new String[]{""});
    model.result("pg4").feature("rgr1").set("expr", new String[]{"emw.S11"});
    model.result("pg4").feature("rgr1").set("descr", new String[]{"S11"});
    model.result("pg4").label("Smith Plot (emw)");
    model.result("pg4").feature("rgr1").set("titletype", "manual");
    model.result("pg4").feature("rgr1").set("title", "Reflection Graph: S-parameter, Color: Frequency (GHz)");

    return model;
  }

  public static Model run2(Model model) {
    model.result("pg4").feature("rgr1").set("linemarker", "point");
    model.result("pg4").feature("rgr1").set("markerpos", "datapoints");
    model.result("pg4").feature("rgr1").create("col1", "Color");
    model.result("pg4").feature("rgr1").feature("col1").set("expr", "emw.freq/1e9");
    model.result("pg4").feature("rgr1").feature("col1").set("colortable", "Spectrum");
    model.result().create("pg5", "PlotGroup3D");
    model.result("pg5").set("data", "dset1");
    model.result("pg5").label("Electric Field, Logarithmic (emw)");
    model.result("pg5").selection().geom("geom1", 3);
    model.result("pg5").selection().set(1, 2, 3, 4, 5, 6, 9);
    model.result("pg5").set("applyselectiontodatasetedges", true);

    model.component("comp1").measure().selection().geom(2);
    model.component("comp1").measure().selection()
         .set(1, 2, 3, 4, 7, 12, 18, 22, 30, 36, 37, 39, 40, 47, 49, 50, 51, 52, 54, 57);
    model.component("comp1").measure().selection().geom(2);
    model.component("comp1").measure().selection()
         .set(1, 2, 3, 4, 7, 12, 18, 22, 30, 36, 37, 39, 40, 47, 49, 50, 51, 52, 54, 57);

    model.result("pg5").create("surf1", "Surface");
    model.result("pg5").feature("surf1").set("expr", "emw.normE");
    model.result("pg5").feature("surf1").create("sel1", "Selection");
    model.result("pg5").feature("surf1").feature("sel1").selection()
         .set(1, 2, 3, 4, 7, 12, 18, 22, 30, 36, 37, 39, 40, 47, 49, 50, 51, 52, 54, 57);
    model.result("pg5").feature("surf1").set("colortable", "Dipole");
    model.result("pg5").feature("surf1").set("colorscalemode", "logarithmic");
    model.result("pg5").feature("surf1").create("tran1", "Transparency");
    model.result("pg5").feature("surf1").feature("tran1").set("transparency", 0.85);
    model.result("pg5").feature("surf1").create("mtrl1", "MaterialAppearance");
    model.result("pg5").feature("surf1").feature("mtrl1").set("appearance", "custom");
    model.result("pg5").feature("surf1").feature("mtrl1").set("family", "aluminumpolished");
    model.result("pg5").feature("surf1").set("expr", "1");

    model.component("comp1").measure().selection().geom(2);
    model.component("comp1").measure().selection().set(13);
    model.component("comp1").measure().selection().geom(2);
    model.component("comp1").measure().selection()
         .set(1, 2, 3, 4, 7, 12, 18, 22, 30, 36, 37, 39, 40, 47, 49, 50, 51, 52, 54, 57);

    model.result("pg5").create("surf2", "Surface");
    model.result("pg5").feature("surf2").set("expr", "emw.normE");
    model.result("pg5").feature("surf2").create("sel1", "Selection");
    model.result("pg5").feature("surf2").feature("sel1").selection().set(13);
    model.result("pg5").feature("surf2").set("colortable", "Dipole");
    model.result("pg5").feature("surf2").set("colorscalemode", "logarithmic");
    model.result("pg5").feature("surf2").create("mtrl1", "MaterialAppearance");
    model.result("pg5").feature("surf2").feature("mtrl1").set("appearance", "custom");
    model.result("pg5").feature("surf2").feature("mtrl1").set("family", "chrome");
    model.result("pg5").feature("surf2").set("expr", "1");
    model.result("pg5").create("surf3", "Surface");
    model.result("pg5").feature("surf3").set("expr", "emw.normE");
    model.result("pg5").feature("surf3").create("sel1", "Selection");
    model.result("pg5").feature("surf3").feature("sel1").selection()
         .set(5, 6, 8, 9, 10, 11, 14, 15, 16, 17, 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, 31, 32, 33, 34, 35, 43, 44, 45, 46, 48, 53, 55, 56, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67);
    model.result("pg5").feature("surf3").set("colortable", "Dipole");
    model.result("pg5").feature("surf3").set("colorscalemode", "logarithmic");
    model.result("pg5").feature("surf3").create("tran1", "Transparency");
    model.result("pg5").feature("surf3").feature("tran1").set("transparency", 0.3);

    model.component("comp1").view("view2").camera().set("position", new double[]{-3, -4, 3});
    model.component("comp1").view("view2").camera().set("up", new double[]{0, 0, 1});
    model.component("comp1").view().create("view3", "geom1");
    model.component("comp1").view("view3").camera().set("position", new double[]{-0.09, -0.12, 0.09});
    model.component("comp1").view("view3").set("environmentmap", "Indoor");
    model.component("comp1").view("view3").camera().set("zoomanglefull", 31.575000000000003);

    model.result("pg5").set("view", "view3");
    model.result("pg2").run();

//    Begin the results analysis and visualization by modifying the first default plot to show the E-field norm on the bottom of the substrate at 3 GHz.
//    In the Settings window for 3D Plot Group, locate the Data section.
//    From the Parameter value (freq (GHz)) list, select 3.

    model.result("pg2").setIndex("looplevel", 21, 0);
    model.result("pg2").run();

//    In the Model Builder window, expand the Electric Field (emw) node, then click Multislice 1.
//    In the Settings window for Multislice, locate the Multiplane Data section.
//    Find the X-planes subsection.
//    In the Planes text field, type 0.

    model.result("pg2").feature("mslc1").set("xnumber", "0");

//    Find the Y-planes subsection.
//    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 Coordinates.

    model.result("pg2").feature("mslc1").set("multiplanezmethod", "coord");

//    In the Coordinates text field, type 0.

    model.result("pg2").feature("mslc1").set("zcoord", 0);

//    In the Electric Field (emw) toolbar, click Plot.

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

//    The input power is evenly split between the two output ports.

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

//    In the Model Builder window, under Results, click S-Parameter (emw).
//    In the Settings window for 1D Plot Group, locate the Legend section.
//    From the Position list, select Lower right.

    model.result("pg3").set("legendpos", "lowerright");

//    Next, change some port settings to run the device as a power combiner and see the performance at the sum and difference ports.

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

//    In the Model Builder window, click Smith Plot (emw).

    model.result("pg5").set("applyselectiontodatasetedges", true);
    model.result("pg5").run();

//    In the Model Builder window, click Electric Field, Logarithmic (emw).
//    In the Model Builder window, under Component 1 (comp1) > Electromagnetic Waves, Frequency Domain (emw), click Lumped Port 1.
//    In the Settings window for Lumped Port, locate the Lumped Port Properties section.
//    From the Wave excitation at this port list, select Off.

    model.component("comp1").physics("emw").feature("lport1").set("PortExcitation", "off");

//    In the Model Builder window, click Lumped Port 2.
//    In the Settings window for Lumped Port, locate the Lumped Port Properties section.
//    From the Wave excitation at this port list, select On.

    model.component("comp1").physics("emw").feature("lport2").set("PortExcitation", "on");

//    In the Model Builder window, click Lumped Port 3.
//    In the Settings window for Lumped Port, locate the Lumped Port Properties section.
//    From the Wave excitation at this port list, select On.

    model.component("comp1").physics("emw").feature("lport3").set("PortExcitation", "on");

//    Add a new study for the coupler (power divider) case in order to keep the result from the previous computation.
//    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("std2");
    model.study("std2").create("freq", "Frequency");
    model.study("std2").feature("freq").set("plotgrouparr", new String[]{"Default"});
    model.study("std2").feature("freq").set("solnum", "auto");
    model.study("std2").feature("freq").set("notsolnum", "auto");
    model.study("std2").feature("freq").set("outputmap", new String[]{});
    model.study("std2").feature("freq").set("ngenAUX", "1");
    model.study("std2").feature("freq").set("goalngenAUX", "1");
    model.study("std2").feature("freq").set("ngenAUX", "1");
    model.study("std2").feature("freq").set("goalngenAUX", "1");

//    In the Home toolbar, click Add Study to close the Add Study window.
//    In the Settings window for Frequency Domain, locate the Study Settings section.
//    Click Range.
//    In the Range dialog, type 1[GHz] in the Start text field.
//    In the Stop text field, type 5[GHz].
//    In the Step text field, type 100[MHz].
//    Click Replace.

    model.study("std2").feature("freq").set("plist", "range(1[GHz],100[MHz],5[GHz])");

//    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("sol2").runAll();

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

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

//    In the Settings window for 1D Plot Group, locate the Data section.
//    From the Dataset list, select Study 2/Solution 2 (sol2).

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

//    Locate the Legend section.
//    From the Position list, select Lower right.

    model.result("pg6").set("legendpos", "lowerright");

//    Right-click 1D Plot Group 6 and choose Global.

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

//    In the Settings window for Global, locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg6").feature("glob1").setIndex("expr", "20*log10(emw.Vport_1)", 0);
    model.result("pg6").feature("glob1").setIndex("unit", "", 0);
    model.result("pg6").feature("glob1").setIndex("descr", "Voltage at port 1 in dB scale", 0);
    model.result("pg6").feature("glob1").setIndex("expr", "20*log10(emw.Vport_2)", 1);
    model.result("pg6").feature("glob1").setIndex("unit", "", 1);
    model.result("pg6").feature("glob1").setIndex("descr", "Voltage at port 2 in dB scale", 1);
    model.result("pg6").feature("glob1").setIndex("expr", "20*log10(emw.Vport_3)", 2);
    model.result("pg6").feature("glob1").setIndex("unit", "", 2);
    model.result("pg6").feature("glob1").setIndex("descr", "Voltage at port 3 in dB scale", 2);
    model.result("pg6").feature("glob1").setIndex("expr", "20*log10(emw.Vport_4)", 3);
    model.result("pg6").feature("glob1").setIndex("unit", "", 3);
    model.result("pg6").feature("glob1").setIndex("descr", "Voltage at port 4 in dB scale", 3);

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

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

//    Lossy microstrip lines with multiple layers can be addressed using a <l>Layered Transition Boundary Condition</l>. Change the lumped port settings back as in the first study, and prepare materials in multiple layers.
//    In the Model Builder window, under Component 1 (comp1) > Electromagnetic Waves, Frequency Domain (emw), click Lumped Port 1.
//    In the Settings window for Lumped Port, locate the Lumped Port Properties section.
//    From the Wave excitation at this port list, select On.

    model.component("comp1").physics("emw").feature("lport1").set("PortExcitation", "on");

//    In the Model Builder window, click Lumped Port 2.
//    In the Settings window for Lumped Port, locate the Lumped Port Properties section.
//    From the Wave excitation at this port list, select Off.

    model.component("comp1").physics("emw").feature("lport2").set("PortExcitation", "off");

//    In the Model Builder window, click Lumped Port 3.
//    In the Settings window for Lumped Port, locate the Lumped Port Properties section.
//    From the Wave excitation at this port list, select Off.

    model.component("comp1").physics("emw").feature("lport3").set("PortExcitation", "off");

//    In the Model Builder window, right-click Perfect Electric Conductor 2 and choose Disable.

    model.component("comp1").physics("emw").feature("pec2").active(false);

//    In the Materials toolbar, click Add Material to open the Add Material window.
//    In the tree, select Built-in > Aluminum 6063-T83.
//    Click Add to Global Materials in the window toolbar.

    model.material().create("mat3", "Common", "");
    model.material("mat3").propertyGroup().create("Enu", "Enu", "Young's modulus and Poisson's ratio");
    model.material("mat3").label("Aluminum 6063-T83");
    model.material("mat3").set("family", "aluminum");
    model.material("mat3").propertyGroup("def")
         .set("relpermeability", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.material("mat3").propertyGroup("def")
         .set("electricconductivity", new String[]{"3.030e7[S/m]", "0", "0", "0", "3.030e7[S/m]", "0", "0", "0", "3.030e7[S/m]"});
    model.material("mat3").propertyGroup("def")
         .set("thermalexpansioncoefficient", new String[]{"23.4e-6[1/K]", "0", "0", "0", "23.4e-6[1/K]", "0", "0", "0", "23.4e-6[1/K]"});
    model.material("mat3").propertyGroup("def").set("heatcapacity", "900[J/(kg*K)]");
    model.material("mat3").propertyGroup("def")
         .set("relpermittivity", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.material("mat3").propertyGroup("def").set("density", "2700[kg/m^3]");
    model.material("mat3").propertyGroup("def")
         .set("thermalconductivity", new String[]{"201[W/(m*K)]", "0", "0", "0", "201[W/(m*K)]", "0", "0", "0", "201[W/(m*K)]"});
    model.material("mat3").propertyGroup("Enu").set("E", "69[GPa]");
    model.material("mat3").propertyGroup("Enu").set("nu", "0.33");

//    In the tree, select Built-in > Copper.
//    Click Add to Global Materials in the window toolbar.

    model.material().create("mat4", "Common", "");
    model.material("mat4").propertyGroup().create("Enu", "Enu", "Young's modulus and Poisson's ratio");
    model.material("mat4").propertyGroup().create("linzRes", "linzRes", "Linearized resistivity");
    model.material("mat4").label("Copper");
    model.material("mat4").set("family", "copper");
    model.material("mat4").propertyGroup("def")
         .set("relpermeability", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.material("mat4").propertyGroup("def")
         .set("electricconductivity", new String[]{"5.998e7[S/m]", "0", "0", "0", "5.998e7[S/m]", "0", "0", "0", "5.998e7[S/m]"});
    model.material("mat4").propertyGroup("def")
         .set("thermalexpansioncoefficient", new String[]{"17e-6[1/K]", "0", "0", "0", "17e-6[1/K]", "0", "0", "0", "17e-6[1/K]"});
    model.material("mat4").propertyGroup("def").set("heatcapacity", "385[J/(kg*K)]");
    model.material("mat4").propertyGroup("def")
         .set("relpermittivity", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.material("mat4").propertyGroup("def").set("density", "8960[kg/m^3]");
    model.material("mat4").propertyGroup("def")
         .set("thermalconductivity", new String[]{"400[W/(m*K)]", "0", "0", "0", "400[W/(m*K)]", "0", "0", "0", "400[W/(m*K)]"});
    model.material("mat4").propertyGroup("Enu").set("E", "110[GPa]");
    model.material("mat4").propertyGroup("Enu").set("nu", "0.35");
    model.material("mat4").propertyGroup("linzRes").set("rho0", "1.72e-8[ohm*m]");
    model.material("mat4").propertyGroup("linzRes").set("alpha", "0.0039[1/K]");
    model.material("mat4").propertyGroup("linzRes").set("Tref", "298[K]");
    model.material("mat4").propertyGroup("linzRes").addInput("temperature");

//    In the Materials toolbar, click Add Material to close the Add Material window.
//    In the Model Builder window, right-click Global Definitions > Materials and choose Layered Material.

    model.material().create("lmat1", "LayeredMaterial", "");

//    In the Settings window for Layered Material, locate the Layer Definition section.
//    In the table, enter the following settings:

    model.material("lmat1").setIndex("thickness", "20[um]", 0);
    model.material("lmat1").setIndex("tag", "lmat1_1", 0);

//    Click Add.

    model.material("lmat1").setIndex("layername", "Layer 2", 1);
    model.material("lmat1").setIndex("link", "mat3", 1);
    model.material("lmat1").setIndex("rotation", "0.0", 1);
    model.material("lmat1").setIndex("rotationValue", "\u2013", 1);
    model.material("lmat1").setIndex("thickness", "20[um]", 1);
    model.material("lmat1").setIndex("meshPoints", 2, 1);
    model.material("lmat1").setIndex("tag", "lmat1_2", 1);
    model.material("lmat1").setIndex("layername", "Layer 2", 1);
    model.material("lmat1").setIndex("link", "mat3", 1);
    model.material("lmat1").setIndex("rotation", "0.0", 1);
    model.material("lmat1").setIndex("rotationValue", "\u2013", 1);
    model.material("lmat1").setIndex("thickness", "20[um]", 1);
    model.material("lmat1").setIndex("meshPoints", 2, 1);
    model.material("lmat1").setIndex("tag", "lmat1_2", 1);

//    In the table, enter the following settings:

    model.material("lmat1").setIndex("link", "mat4", 1);
    model.material("lmat1").setIndex("thickness", "20[um]", 1);
    model.material("lmat1").setIndex("tag", "lmat1_2", 1);

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

    model.component("comp1").material().create("llmat1", "LayeredMaterialLink");

//    Select Boundary 13.

    model.component("comp1").material("llmat1").selection().set(13);

//    In the Physics toolbar, click Boundaries and choose Layered Transition Boundary Condition.

    model.component("comp1").physics("emw").create("ltbc1", "LayeredTransitionBoundaryCondition", 2);

//    Select Boundary 13.

    model.component("comp1").physics("emw").feature("ltbc1").selection().set(13);

//    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");
    model.study("std3").feature("freq").set("plotgrouparr", new String[]{"Default"});
    model.study("std3").feature("freq").set("solnum", "auto");
    model.study("std3").feature("freq").set("notsolnum", "auto");
    model.study("std3").feature("freq").set("outputmap", new String[]{});
    model.study("std3").feature("freq").set("ngenAUX", "1");
    model.study("std3").feature("freq").set("goalngenAUX", "1");
    model.study("std3").feature("freq").set("ngenAUX", "1");
    model.study("std3").feature("freq").set("goalngenAUX", "1");

//    In the Home toolbar, click Add Study to close the Add Study window.
//    In the Settings window for Frequency Domain, locate the Study Settings section.
//    In the Frequencies text field, type range(1[GHz],100[MHz],5[GHz]).

    model.study("std3").feature("freq").set("plist", "range(1[GHz],100[MHz],5[GHz])");

//    In the Study toolbar, click Compute.

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

    model.component("comp1").probe("emw_lport1_probe").genResult("none");

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

    model.result().create("pg8", "PlotGroup3D");
    model.result("pg8").set("data", "dset3");
    model.result("pg8").setIndex("looplevel", 41, 0);
    model.result("pg8").create("mslc1", "Multislice");
    model.result("pg8").feature("mslc1").set("expr", new String[]{"emw.normE"});
    model.result("pg8").set("showlegendsmaxmin", true);
    model.result("pg8").feature("mslc1").set("colortable", "RainbowLight");
    model.result("pg8").label("Electric Field (emw) 1");
    model.result().create("pg9", "PlotGroup1D");
    model.result("pg9").set("data", "dset3");
    model.result("pg9").create("glob1", "Global");
    model.result("pg9").feature("glob1").set("unit", new String[]{"", "", "", ""});
    model.result("pg9").feature("glob1")
         .set("expr", new String[]{"emw.S11dB", "emw.S21dB", "emw.S31dB", "emw.S41dB"});
    model.result("pg9").feature("glob1").set("descr", new String[]{"S11", "S21", "S31", "S41"});
    model.result("pg9").label("S-Parameter (emw) 1");
    model.result("pg9").feature("glob1").set("titletype", "none");
    model.result("pg9").feature("glob1").set("xdata", "expr");
    model.result("pg9").set("ylabelactive", true);
    model.result("pg9").set("ylabel", "S-parameter (dB)");
    model.result("pg9").feature("glob1").set("xdataexpr", "freq");
    model.result("pg9").feature("glob1").set("xdataunit", "GHz");
    model.result("pg9").feature("glob1").set("markerpos", "datapoints");
    model.result("pg9").feature("glob1").set("xdatasolnumtype", "all");
    model.result().create("pg10", "SmithGroup");
    model.result("pg10").set("data", "dset3");
    model.result("pg10").create("rgr1", "ReflectionGraph");
    model.result("pg10").feature("rgr1").set("unit", new String[]{""});
    model.result("pg10").feature("rgr1").set("expr", new String[]{"emw.S11"});
    model.result("pg10").feature("rgr1").set("descr", new String[]{"S11"});
    model.result("pg10").label("Smith Plot (emw) 1");
    model.result("pg10").feature("rgr1").set("titletype", "manual");
    model.result("pg10").feature("rgr1").set("title", "Reflection Graph: S-parameter, Color: Frequency (GHz)");
    model.result("pg10").feature("rgr1").set("linemarker", "point");
    model.result("pg10").feature("rgr1").set("markerpos", "datapoints");
    model.result("pg10").feature("rgr1").create("col1", "Color");
    model.result("pg10").feature("rgr1").feature("col1").set("expr", "emw.freq/1e9");
    model.result("pg10").feature("rgr1").feature("col1").set("colortable", "Spectrum");
    model.result().create("pg11", "PlotGroup3D");
    model.result("pg11").set("data", "dset3");
    model.result("pg11").label("Electric Field, Logarithmic (emw) 1");
    model.result("pg11").selection().geom("geom1", 3);
    model.result("pg11").selection().set(1, 2, 3, 4, 5, 6, 9);
    model.result("pg11").set("applyselectiontodatasetedges", true);

    model.component("comp1").measure().selection().geom(2);
    model.component("comp1").measure().selection()
         .set(1, 2, 3, 4, 7, 12, 18, 22, 30, 36, 37, 39, 40, 47, 49, 50, 51, 52, 54, 57);
    model.component("comp1").measure().selection().geom(2);
    model.component("comp1").measure().selection()
         .set(1, 2, 3, 4, 7, 12, 18, 22, 30, 36, 37, 39, 40, 47, 49, 50, 51, 52, 54, 57);

    model.result("pg11").create("surf1", "Surface");
    model.result("pg11").feature("surf1").set("expr", "emw.normE");
    model.result("pg11").feature("surf1").create("sel1", "Selection");
    model.result("pg11").feature("surf1").feature("sel1").selection()
         .set(1, 2, 3, 4, 7, 12, 18, 22, 30, 36, 37, 39, 40, 47, 49, 50, 51, 52, 54, 57);
    model.result("pg11").feature("surf1").set("colortable", "Dipole");
    model.result("pg11").feature("surf1").set("colorscalemode", "logarithmic");
    model.result("pg11").feature("surf1").create("tran1", "Transparency");
    model.result("pg11").feature("surf1").feature("tran1").set("transparency", 0.85);
    model.result("pg11").feature("surf1").create("mtrl1", "MaterialAppearance");
    model.result("pg11").feature("surf1").feature("mtrl1").set("appearance", "custom");
    model.result("pg11").feature("surf1").feature("mtrl1").set("family", "aluminumpolished");
    model.result("pg11").feature("surf1").set("expr", "1");
    model.result("pg11").create("surf2", "Surface");
    model.result("pg11").feature("surf2").set("expr", "emw.normE");
    model.result("pg11").feature("surf2").create("sel1", "Selection");
    model.result("pg11").feature("surf2").feature("sel1").selection()
         .set(5, 6, 8, 9, 10, 11, 13, 14, 15, 16, 17, 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, 31, 32, 33, 34, 35, 43, 44, 45, 46, 48, 53, 55, 56, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67);
    model.result("pg11").feature("surf2").set("colortable", "Dipole");
    model.result("pg11").feature("surf2").set("colorscalemode", "logarithmic");
    model.result("pg11").feature("surf2").create("tran1", "Transparency");
    model.result("pg11").feature("surf2").feature("tran1").set("transparency", 0.3);

    model.component("comp1").view().create("view5", "geom1");
    model.component("comp1").view("view5").camera().set("position", new double[]{-0.09, -0.12, 0.09});
    model.component("comp1").view("view5").set("environmentmap", "Indoor");
    model.component("comp1").view("view5").camera().set("zoomanglefull", 31.575000000000003);

    model.result("pg11").set("view", "view5");
    model.result("pg8").set("applyselectiontodatasetedges", false);
    model.result("pg8").run();
    model.result("pg8").run();

//    In the Model Builder window, expand the Electric Field (emw) 1 node, then click Multislice 1.
//    In the Settings window for Multislice, locate the Multiplane Data section.
//    Find the X-planes subsection.
//    In the Planes text field, type 0.

    model.result("pg8").feature("mslc1").set("xnumber", "0");

//    Find the Y-planes subsection.
//    In the Planes text field, type 0.

    model.result("pg8").feature("mslc1").set("ynumber", "0");

//    Find the Z-planes subsection.
//    From the Entry method list, select Coordinates.

    model.result("pg8").feature("mslc1").set("multiplanezmethod", "coord");

//    In the Coordinates text field, type 0.

    model.result("pg8").feature("mslc1").set("zcoord", 0);

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

    model.result("pg8").feature("mslc1").set("colortable", "ThermalWaveDark");
    model.result("pg9").run();

//    In the Model Builder window, under Results, click S-Parameter (emw) 1.

    model.title("Rat-Race Coupler");

    model
         .description("A 180-degree Ring Hybrid (Rat-Race Coupler) is a four-port network with 180-degree phase difference between two ports. The objective of this example is to compute the S-parameters and to observe the matching, isolation, and coupling around the operating frequency.");

    return model;
  }

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

}
