/*
 * microstrip_patch_antenna_array.java
 */

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

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

  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");

//    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("f0", "1.68[GHz]");
    model.param().descr("f0", "Current frequency in sweep");
    model.param().set("lda0", "c_const/f0");
    model.param().descr("lda0", "Wavelength, air");
    model.param().set("h_max", "0.2*lda0");
    model.param().descr("h_max", "Maximum mesh element size, air");

//    Here, <c>c_const</c> is a predefined COMSOL constant for the speed of light in vacuum.
//    First, import the microstrip patch antenna array design.
//    In the Geometry toolbar, click Import.

    model.component("comp1").geom("geom1").create("imp1", "Import");

//    In the Settings window for Import, locate the Source section.
//    Click Browse.
//    Browse to the model's Application Library folder and double-click the file microstrip_patch_antenna_array.mphbin.

    model.component("comp1").geom("geom1").feature("imp1").set("filename", "microstrip_patch_antenna_array.mphbin");

//    Click Import.

    model.component("comp1").geom("geom1").feature("imp1").importData();

//    Choose wireframe rendering to get a better view of the interior parts.
//    Click the Wireframe Rendering button in the Graphics toolbar.

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

//    Add a sphere for the perfectly matched layers. Use a layer definition to create shell-type sphere structure.
//    In the Geometry toolbar, click Sphere.

    model.component("comp1").geom("geom1").create("sph1", "Sphere");

//    In the Settings window for Sphere, type PML in the Label text field.

    model.component("comp1").geom("geom1").feature("sph1").label("PML");

//    Locate the Size section.
//    In the Radius text field, type 0.275.

    model.component("comp1").geom("geom1").feature("sph1").set("r", 0.275);

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

    model.component("comp1").geom("geom1").feature("sph1").setIndex("layername", "Layer 1", 0);
    model.component("comp1").geom("geom1").feature("sph1").setIndex("layer", 0.04, 0);

//    Click Build All Objects.

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

//    Disable the analysis of the geometry as the remaining small geometric details are needed.
//    In the Model Builder window, click Geometry 1.
//    In the Settings window for Geometry, locate the Cleanup section.
//    Clear the Automatic detection of small details checkbox.
//    Create a set of selections for use when setting up the physics. First, create a selection for the patch antennas.
//    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 Patch in the Label text field.

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

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

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

//    Select Boundaries 22, 23, 27, 28, 48, 49, 52, 53.

    model.component("comp1").selection("sel1").set(22, 23, 27, 28, 48, 49, 52, 53);

//    Add selections for the feed network, slot, ground, and substrate.
//    In the Definitions toolbar, click Explicit.

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

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

    model.component("comp1").selection("sel2").label("Feed network");

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

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

//    Select Boundary 26.

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

//    In the Definitions toolbar, click Explicit.

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

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

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

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

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

//    Select Boundaries 24, 25, 29, 30, 50, 51, 54, 55.

    model.component("comp1").selection("sel3").set(24, 25, 29, 30, 50, 51, 54, 55);

//    In the Definitions toolbar, click Explicit.

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

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

    model.component("comp1").selection("sel4").label("Ground");

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

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

//    Select Boundary 18.

    model.component("comp1").selection("sel4").set(18);

//    In the Definitions toolbar, click Explicit.

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

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

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

//    Select Domains 6, 7.

    model.component("comp1").selection("sel5").set(6, 7);

//    Zoom out to get a view of the entire structure.
//    Click the Zoom Out button in the Graphics toolbar.
//    In the Definitions toolbar, click Perfectly Matched Layer.

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

//    Select Domains 1, 2, 3, 4, 8, 9, 10, 11.

    model.component("comp1").coordSystem("pml1").selection().set(1, 2, 3, 4, 8, 9, 10, 11);

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

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

//    To get a better view, suppress some of the domains. Furthermore, by assigning the resulting settings to a View node, you can easily return to the same view later by clicking the <l>Go to View 2</l> button in the <l>Graphics</l> toolbar.
//    In the Model Builder window, right-click Component 1 (comp1) > Definitions and choose View.

    model.component("comp1").view().create("view2", "geom1");

//    Click the Wireframe Rendering button in the Graphics toolbar.

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

//    In the Model Builder window, right-click View 2 and choose Hide for Physics.

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

//    Select Domains 2, 4, 9, 11.

    model.component("comp1").view("view2").hideEntities("hide1").set(2, 4, 9, 11);

//    In the Model Builder window, right-click View 2 and choose Hide for Physics.

    model.component("comp1").view("view2").hideEntities().create("hide2");

//    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("view2").hideEntities("hide2").geom("geom1", 2);

//    Select Boundaries 10, 12, 38, 45.

    model.component("comp1").view("view2").hideEntities("hide2").set(10, 12, 38, 45);

//    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 Patch.

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

//    In the Physics toolbar, click Boundaries and choose Perfect Electric Conductor.

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

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

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

//    In the Physics toolbar, click Boundaries and choose Perfect Electric Conductor.

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

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

    model.component("comp1").physics("emw").feature("pec4").selection().named("sel4");

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

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

//    Click the Zoom In button in the Graphics toolbar.
//    , a couple of times to see the port boundary clearly.
//    Select Boundary 31.

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

//    For the first port, wave excitation is <l>on</l> by default.
//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Physics toolbar, click Domains and choose Far-Field Domain.

    model.component("comp1").physics("emw").create("ffd1", "FarFieldDomain", 3);

//    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>r = 3.38.
//    In the Model Builder window, right-click Component 1 (comp1) > 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("sel5");

//    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"});

//    Choose the maximum mesh size in the air domain smaller than 0.2 wavelengths using the parameter h_max that you defined earlier. Scale the mesh size inside the substrate by the inverse of the square root of the relative dielectric constant of the substrate.
//    In the Model Builder window, right-click Component 1 (comp1) > Mesh 1 and choose Size.

    model.component("comp1").mesh("mesh1").create("size1", "Size");

//    In the Settings window for Size, locate the Element Size section.
//    Click the Custom button.

    model.component("comp1").mesh("mesh1").feature("size1").set("custom", true);

//    Locate the Element Size Parameters section.
//    Select the Maximum element size checkbox.

    model.component("comp1").mesh("mesh1").feature("size1").set("hmaxactive", true);

//    In the associated text field, type h_max.

    model.component("comp1").mesh("mesh1").feature("size1").set("hmax", "h_max");

//    Select the Maximum element growth rate checkbox.

    model.component("comp1").mesh("mesh1").feature("size1").set("hgradactive", true);

//    In the associated text field, type 2.5.

    model.component("comp1").mesh("mesh1").feature("size1").set("hgrad", 2.5);

//    Due to the thin substrate, use a smaller value for the maximum mesh size than that initially suggested.
//    In the Model Builder window, right-click Mesh 1 and choose Size.

    model.component("comp1").mesh("mesh1").create("size2", "Size");

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

    model.component("comp1").mesh("mesh1").feature("size2").selection().geom("geom1", 3);

//    From the Selection list, select Substrate.

    model.component("comp1").mesh("mesh1").feature("size2").selection().named("sel5");

//    Locate the Element Size section.
//    Click the Custom button.

    model.component("comp1").mesh("mesh1").feature("size2").set("custom", true);

//    Locate the Element Size Parameters section.
//    Select the Maximum element size checkbox.

    model.component("comp1").mesh("mesh1").feature("size2").set("hmaxactive", true);

//    In the associated text field, type h_max/sqrt(3.38)/2.

    model.component("comp1").mesh("mesh1").feature("size2").set("hmax", "h_max/sqrt(3.38)/2");

//    To resolve the small parts properly, refine the mesh further in each selection of the model.
//    Right-click Mesh 1 and choose Size.

    model.component("comp1").mesh("mesh1").create("size3", "Size");

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

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

//    From the Selection list, select Feed network.

    model.component("comp1").mesh("mesh1").feature("size3").selection().named("sel2");

//    Locate the Element Size section.
//    Click the Custom button.

    model.component("comp1").mesh("mesh1").feature("size3").set("custom", true);

//    Locate the Element Size Parameters section.
//    Select the Maximum element size checkbox.

    model.component("comp1").mesh("mesh1").feature("size3").set("hmaxactive", true);

//    In the associated text field, type 1.8[mm].

    model.component("comp1").mesh("mesh1").feature("size3").set("hmax", "1.8[mm]");

//    Select the Minimum element size checkbox.

    model.component("comp1").mesh("mesh1").feature("size3").set("hminactive", true);

//    In the associated text field, type 0.5[mm].

    model.component("comp1").mesh("mesh1").feature("size3").set("hmin", "0.5[mm]");

//    Right-click Mesh 1 and choose Size.

    model.component("comp1").mesh("mesh1").create("size4", "Size");

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

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

//    From the Selection list, select Slot.

    model.component("comp1").mesh("mesh1").feature("size4").selection().named("sel3");

//    Locate the Element Size section.
//    Click the Custom button.

    model.component("comp1").mesh("mesh1").feature("size4").set("custom", true);

//    Locate the Element Size Parameters section.
//    Select the Maximum element size checkbox.

    model.component("comp1").mesh("mesh1").feature("size4").set("hmaxactive", true);

//    In the associated text field, type 2[mm].

    model.component("comp1").mesh("mesh1").feature("size4").set("hmax", "2[mm]");

//    Right-click Mesh 1 and choose Size.

    model.component("comp1").mesh("mesh1").create("size5", "Size");

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

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

//    From the Selection list, select Patch.

    model.component("comp1").mesh("mesh1").feature("size5").selection().named("sel1");

//    Locate the Element Size section.
//    Click the Custom button.

    model.component("comp1").mesh("mesh1").feature("size5").set("custom", true);

//    Locate the Element Size Parameters section.
//    Select the Maximum element size checkbox.

    model.component("comp1").mesh("mesh1").feature("size5").set("hmaxactive", true);

//    In the associated text field, type 2[mm].

    model.component("comp1").mesh("mesh1").feature("size5").set("hmax", "2[mm]");

//    Right-click Mesh 1 and choose Size.

    model.component("comp1").mesh("mesh1").create("size6", "Size");

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

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

//    From the Selection list, select Ground.

    model.component("comp1").mesh("mesh1").feature("size6").selection().named("sel4");

//    Locate the Element Size section.
//    Click the Custom button.

    model.component("comp1").mesh("mesh1").feature("size6").set("custom", true);

//    Locate the Element Size Parameters section.
//    Select the Maximum element size checkbox.

    model.component("comp1").mesh("mesh1").feature("size6").set("hmaxactive", true);

//    In the associated text field, type 4[mm].

    model.component("comp1").mesh("mesh1").feature("size6").set("hmax", "4[mm]");

//    In the Mesh toolbar, click Free Tetrahedral.

    model.component("comp1").mesh("mesh1").create("ftet1", "FreeTet");

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

    model.component("comp1").mesh("mesh1").feature("ftet1").selection().geom("geom1", 3);

//    Select Domains 5, 6, 7.

    model.component("comp1").mesh("mesh1").feature("ftet1").selection().set(5, 6, 7);

//    Use a swept mesh for the PMLs.
//    In the Mesh toolbar, click Swept.

    model.component("comp1").mesh("mesh1").create("swe1", "Sweep");

//    Right-click Swept 1 and choose Distribution.

    model.component("comp1").mesh("mesh1").feature("swe1").create("dis1", "Distribution");

//    Right-click Mesh 1 and choose Build All.

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

//    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.
//    In the Frequencies text field, type f0.

    model.study("std1").feature("freq").set("plist", "f0");

//    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", 1, 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("pg2").selection().geom("geom1", 3);
    model.result("pg2").selection().set(5, 6, 7);
    model.result("pg2").set("applyselectiontodatasetedges", true);
    model.result("pg2").run();
    model.result().evaluationGroup().create("eg1", "EvaluationGroup");
    model.result().evaluationGroup("eg1").set("data", "dset1");
    model.result().evaluationGroup("eg1").label("S-Parameter (emw)");
    model.result().evaluationGroup("eg1").set("data", "dset1");
    model.result().evaluationGroup("eg1").create("gev1", "EvalGlobal");
    model.result().evaluationGroup("eg1").feature("gev1").label("S-Parameter (emw)");
    model.result().evaluationGroup("eg1").feature("gev1").set("expr", new String[]{"emw.S11dB"});
    model.result().table().create("tbl2", "Table");
    model.result().evaluationGroup("eg1").feature("gev1").set("table", "tbl2");
    model.result().evaluationGroup("eg1").run();
    model.result().create("pg3", "PlotGroup3D");
    model.result("pg3").set("data", "dset1");
    model.result("pg3").label("Electric Field, Logarithmic (emw)");
    model.result("pg3").selection().geom("geom1", 3);
    model.result("pg3").selection().set(5, 6, 7);
    model.result("pg3").set("applyselectiontodatasetedges", true);

    model.component("comp1").measure().selection().geom(2);
    model.component("comp1").measure().selection().set(18, 22, 23, 26, 27, 28, 48, 49, 52, 53);
    model.component("comp1").measure().selection().geom(2);
    model.component("comp1").measure().selection().set(5, 6, 7, 8, 35, 36, 41, 46);

    model.result("pg3").create("surf1", "Surface");
    model.result("pg3").feature("surf1").set("expr", "emw.normE");
    model.result("pg3").feature("surf1").create("sel1", "Selection");
    model.result("pg3").feature("surf1").feature("sel1").selection().set(18, 22, 23, 26, 27, 28, 48, 49, 52, 53);
    model.result("pg3").feature("surf1").set("colortable", "Dipole");
    model.result("pg3").feature("surf1").set("colorscalemode", "logarithmic");

    return model;
  }

  public static Model run2(Model model) {
    model.result("pg3").feature("surf1").create("mtrl1", "MaterialAppearance");
    model.result("pg3").feature("surf1").feature("mtrl1").set("appearance", "custom");
    model.result("pg3").feature("surf1").feature("mtrl1").set("family", "chrome");
    model.result("pg3").feature("surf1").set("expr", "1");
    model.result("pg3").create("mslc1", "Multislice");
    model.result("pg3").feature("mslc1").set("expr", "emw.normE");
    model.result("pg3").feature("mslc1").create("sel1", "Selection");
    model.result("pg3").feature("mslc1").feature("sel1").selection().set(5);
    model.result("pg3").feature("mslc1").set("colortable", "Prism");
    model.result("pg3").feature("mslc1").set("colorscalemode", "logarithmic");
    model.result("pg3").feature("mslc1").set("colortabletype", "discrete");
    model.result("pg3").feature("mslc1").set("bandcount", 20);
    model.result("pg3").feature("mslc1").create("tran1", "Transparency");
    model.result("pg3").feature("mslc1").feature("tran1").set("transparency", 0.5);
    model.result("pg3").feature("mslc1").set("znumber", "0");
    model.result("pg3").create("surf2", "Surface");
    model.result("pg3").feature("surf2").set("expr", "emw.normE");
    model.result("pg3").feature("surf2").create("sel1", "Selection");
    model.result("pg3").feature("surf2").feature("sel1").selection()
         .set(13, 14, 15, 16, 17, 19, 20, 21, 24, 25, 29, 30, 31, 50, 51, 54, 55, 56, 57);
    model.result("pg3").feature("surf2").set("colortable", "Dipole");
    model.result("pg3").feature("surf2").set("colorscalemode", "logarithmic");
    model.result("pg3").feature("surf2").create("tran1", "Transparency");
    model.result("pg3").feature("surf2").feature("tran1").set("transparency", 0.7);

    model.component("comp1").view().create("view3", "geom1");
    model.component("comp1").view("view3").camera().set("position", new double[]{-0.47, -0.63, 0.47});
    model.component("comp1").view("view3").set("environmentmap", "Indoor");
    model.component("comp1").view("view3").camera().set("zoomanglefull", 62.074999999999996);

    model.result("pg3").set("view", "view3");
    model.result().create("pg4", "PolarGroup");
    model.result("pg4").label("2D Far Field (emw)");
    model.result("pg4").set("data", "dset1");
    model.result("pg4").create("rp1", "RadiationPattern");
    model.result("pg4").feature("rp1").set("legend", "on");
    model.result("pg4").feature("rp1").set("phidisc", "180");
    model.result("pg4").feature("rp1").set("expr", new String[]{"emw.normEfar"});
    model.result("pg4").feature("rp1").create("exp1", "Export");
    model.result().create("pg5", "PlotGroup3D");
    model.result("pg5").label("3D Far Field, Gain (emw)");
    model.result("pg5").set("data", "dset1");
    model.result("pg5").set("view", "new");
    model.result("pg5").set("edges", "off");
    model.result("pg5").set("showlegendsmaxmin", true);
    model.result("pg5").create("rp1", "RadiationPattern");
    model.result("pg5").feature("rp1").set("expr", new String[]{"emw.rGaindBEfar"});
    model.result("pg5").feature("rp1").set("colorexpr", new String[]{"emw.normEfar"});
    model.result("pg5").feature("rp1").set("useradiusascolor", true);
    model.result("pg5").feature("rp1").set("directivityexpr", new String[]{"emw.normEfar^2"});
    model.result("pg5").feature("rp1").set("thetadisc", "45");
    model.result("pg5").feature("rp1").set("phidisc", "90");
    model.result("pg5").feature("rp1").set("directivity", "on");
    model.result("pg5").feature("rp1").set("colortable", "RainbowLight");
    model.result("pg5").feature("rp1").create("exp1", "Export");
    model.result("pg5").feature("rp1").feature("exp1").setIndex("expr", "comp1.emw.theta", 0);
    model.result("pg5").feature("rp1").feature("exp1").setIndex("expr", "comp1.emw.phi", 1);
    model.result("pg4").feature("rp1").feature("exp1").setIndex("expr", "comp1.emw.theta", 0);
    model.result("pg4").feature("rp1").feature("exp1").setIndex("expr", "comp1.emw.phi", 1);
    model.result("pg2").set("applyselectiontodatasetedges", true);
    model.result("pg2").run();

//    Begin the results analysis by reviewing the plot showing the distribution of the electric field norm.

    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 Expression section.
//    In the Expression text field, type 20*log10(emw.normE).

    model.result("pg2").feature("mslc1").set("expr", "20*log10(emw.normE)");

//    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 1.524[mm].

    model.result("pg2").feature("mslc1").set("zcoord", "1.524[mm]");

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

    model.result("pg2").feature("mslc1").set("colortable", "HeatCameraLight");

//    Right-click Multislice 1 and choose Selection.

    model.result("pg2").feature("mslc1").create("sel1", "Selection");

//    Select Domain 7.

    model.result("pg2").feature("mslc1").feature("sel1").selection().set(7);

//    Click the Zoom to Selection button in the Graphics toolbar.

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

//    Right-click Multislice 1 and choose Deformation.

    model.result("pg2").feature("mslc1").create("def1", "Deform");
    model.result("pg2").run();

//    In the Settings window for Deformation, locate the Expression section.
//    In the X-component text field, type 0.

    model.result("pg2").feature("mslc1").feature("def1").set("expr", new String[]{"0", "", ""});

//    In the Y-component text field, type 0.

    model.result("pg2").feature("mslc1").feature("def1").set("expr", new String[]{"0", "0", ""});

//    In the Z-component text field, type 20*log10(emw.normE).

    model.result("pg2").feature("mslc1").feature("def1").set("expr", new String[]{"0", "0", "20*log10(emw.normE)"});

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

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

//    Strong electric fields are observed on the radiating edges.

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

//    In the Model Builder window, under Results, click Electric Field, Logarithmic (emw).
//    Adjust the polar plot settings to visualize the far-field pattern on the E-plane.

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

//    In the Model Builder window, expand the Results > 2D Far Field (emw) node, then click Radiation Pattern 1.
//    In the Settings window for Radiation Pattern, locate the Evaluation section.
//    Find the Normal vector subsection.
//    In the x text field, type 1.

    model.result("pg4").feature("rp1").set("normal", new int[]{1, 0, 1});

//    In the z text field, type 0.

    model.result("pg4").feature("rp1").set("normal", new int[]{1, 0, 0});

//    Find the Reference direction subsection.
//    In the x text field, type 0.

    model.result("pg4").feature("rp1").set("refdir", new int[]{0, 0, 0});

//    In the y text field, type 1.

    model.result("pg4").feature("rp1").set("refdir", new int[]{0, 1, 0});

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

    model.result("pg4").feature("rp1").set("legendmethod", "manual");

//    In the table, enter the following settings:

    model.result("pg4").feature("rp1").setIndex("legends", "E-plane", 0);

//    In the 2D Far Field (emw) toolbar, click Plot.

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

//    The E-plane in this model is located on the \[yz\]-plane where \[\phi\] is measured counterclockwise from the \[y\]-axis.
//    Add the H-plane polar plot.
//    Right-click Results > 2D Far Field (emw) > Radiation Pattern 1 and choose Duplicate.

    model.result("pg4").feature().duplicate("rp2", "rp1");
    model.result("pg4").run();

//    In the Settings window for Radiation Pattern, locate the Evaluation section.
//    Find the Reference direction subsection.
//    In the x text field, type 1.

    model.result("pg4").feature("rp2").set("refdir", new int[]{1, 1, 0});

//    In the y text field, type 0.

    model.result("pg4").feature("rp2").set("refdir", new int[]{1, 0, 0});

//    Find the Normal vector subsection.
//    In the x text field, type 0.

    model.result("pg4").feature("rp2").set("normal", new int[]{0, 0, 0});

//    In the y text field, type -1.

    model.result("pg4").feature("rp2").set("normal", new int[]{0, -1, 0});

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

    model.result("pg4").feature("rp2").setIndex("legends", "H-plane", 0);

//    In the 2D Far Field (emw) toolbar, click Plot.

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

//    The H-plane is located on the \[xz\]-plane where \[\phi\] is measured counterclockwise from the \[x\]-axis.

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

//    In the Model Builder window, expand the 3D Far Field, Gain (emw) node, then click Radiation Pattern 1.
//    In the Settings window for Radiation Pattern, locate the Evaluation section.
//    Find the Angles subsection.
//    In the Number of elevation angles text field, type 90.

    model.result("pg5").feature("rp1").set("thetadisc", 90);

//    In the Number of azimuth angles text field, type 90.
//    Locate the Coloring and Style section.
//    From the Color table list, select DiscoLight.

    model.result("pg5").feature("rp1").set("colortable", "DiscoLight");

//    In the 3D Far Field, Gain (emw) toolbar, click Plot.

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

//    Finish by inspecting the input matching characteristic of the antenna array.

    model.title("Feasibility Study of Microstrip Patch Antenna Array Design");

    model
         .description("An antenna array is a group of radiating elements. By controlling the phase and magnitude of the input signal assigned to each antenna element and the number of array elements, the radiation pattern can be steered in a desired direction with a preferred level of gain. In this example, a 4-by-2 array of patch antennas is fed from a single feed point, with all elements fed at equal phase and magnitude.");

    return model;
  }

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

}
