/*
 * yagi_uda_antenna.java
 */

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

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

  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", "2.45[GHz]");
    model.param().descr("f0", "Operating frequency");
    model.param().set("lda0", "c_const/f0");
    model.param().descr("lda0", "Operating wavelength");
    model.param().set("arm_length", "0.43*lda0/2");
    model.param().descr("arm_length", "Dipole antenna arm length");
    model.param().set("r_antenna", "arm_length/20");
    model.param().descr("r_antenna", "Dipole antenna radius");
    model.param().set("gap_size", "arm_length/100");
    model.param().descr("gap_size", "Gap between arms");
    model.param().set("lr", "0.48*lda0");
    model.param().descr("lr", "Reflector length");
    model.param().set("dr", "0.2*lda0");
    model.param().descr("dr", "Distance between feeder and reflector");
    model.param().set("ld", "0.35*lda0");
    model.param().descr("ld", "Director length");
    model.param().set("d", "0.2*lda0");
    model.param().descr("d", "Distance between director");

//    Build a feeder element along with the boundaries for lumped port excitation.
//    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_antenna.

    model.component("comp1").geom("geom1").feature("cyl1").set("r", "r_antenna");

//    In the Height text field, type 2*arm_length+gap_size.

    model.component("comp1").geom("geom1").feature("cyl1").set("h", "2*arm_length+gap_size");

//    Locate the Position section.
//    In the z text field, type -(arm_length+gap_size/2).

    model.component("comp1").geom("geom1").feature("cyl1")
         .set("pos", new String[]{"0", "0", "-(arm_length+gap_size/2)"});

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

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

//    Clear the Layers on side checkbox.

    model.component("comp1").geom("geom1").feature("cyl1").set("layerside", false);

//    Select the Layers on bottom checkbox.

    model.component("comp1").geom("geom1").feature("cyl1").set("layerbottom", true);

//    Select the Layers on top checkbox.

    model.component("comp1").geom("geom1").feature("cyl1").set("layertop", true);

//    Build a reflector element.
//    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 r_antenna*1.2.

    model.component("comp1").geom("geom1").feature("cyl2").set("r", "r_antenna*1.2");

//    In the Height text field, type lr.

    model.component("comp1").geom("geom1").feature("cyl2").set("h", "lr");

//    Locate the Position section.
//    In the x text field, type -dr.

    model.component("comp1").geom("geom1").feature("cyl2").set("pos", new String[]{"-dr", "0", "0"});

//    In the z text field, type -lr/2.

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

//    Build a director and an array of directors.
//    In the Geometry toolbar, click Cylinder.

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

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

    model.component("comp1").geom("geom1").feature("cyl3").set("r", "r_antenna");

//    In the Height text field, type ld.

    model.component("comp1").geom("geom1").feature("cyl3").set("h", "ld");

//    Locate the Position section.
//    In the x text field, type d.

    model.component("comp1").geom("geom1").feature("cyl3").set("pos", new String[]{"d", "0", "0"});

//    In the z text field, type -ld/2.

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

//    Click Build Selected.

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

//    In the Geometry toolbar, click Transforms and choose Array.

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

//    Select the object cyl3.

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

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

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

//    In the Size text field, type 4.

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

//    Locate the Displacement section.
//    In the x text field, type d.

    model.component("comp1").geom("geom1").feature("arr1").set("displ", new String[]{"d", "0", "0"});

//    Click Build Selected.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    Build a mechanical supporting structure which holds the feeder, reflector, and directors together.
//    In the Geometry toolbar, click Block.

    model.component("comp1").geom("geom1").create("blk1", "Block");

//    In the Settings window for Block, locate the Size and Shape section.
//    In the Width text field, type 4*d+1*dr+3*r_antenna.

    model.component("comp1").geom("geom1").feature("blk1")
         .set("size", new String[]{"4*d+1*dr+3*r_antenna", "1", "1"});

//    In the Depth text field, type r_antenna*3.

    model.component("comp1").geom("geom1").feature("blk1").setIndex("size", "r_antenna*3", 1);

//    In the Height text field, type r_antenna*2.

    model.component("comp1").geom("geom1").feature("blk1").setIndex("size", "r_antenna*2", 2);

//    Locate the Position section.
//    In the x text field, type -dr-1.5*r_antenna.

    model.component("comp1").geom("geom1").feature("blk1").set("pos", new String[]{"-dr-1.5*r_antenna", "0", "0"});

//    In the y text field, type -1.5*r_antenna.

    model.component("comp1").geom("geom1").feature("blk1").setIndex("pos", "-1.5*r_antenna", 1);

//    In the z text field, type -r_antenna.

    model.component("comp1").geom("geom1").feature("blk1").setIndex("pos", "-r_antenna", 2);

//    Click Build Selected.

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

//    In the Geometry toolbar, click Transforms and choose Move.

    model.component("comp1").geom("geom1").create("mov1", "Move");

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

    model.component("comp1").geom("geom1").feature("mov1").selection("input").set("arr1", "blk1", "cyl1", "cyl2");

//    In the Settings window for Move, locate the Displacement section.
//    In the x text field, type -(5*d+1*dr+3*r_antenna)/4.

    model.component("comp1").geom("geom1").feature("mov1").set("displx", "-(5*d+1*dr+3*r_antenna)/4");

//    Click Build Selected.

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

//    Build a surrounding air space along with domains for Perfectly matched layer (PML) that mimics the anechoic chamber.
//    In the Geometry toolbar, click Sphere.

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

//    In the Settings window for Sphere, locate the Size section.
//    In the Radius text field, type lda0.

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

//    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.5*arm_length", 0);

//    Click Build Selected.

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

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

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    The volumetric region enclosed by antenna elements can be omitted for simplifying the physics setup.
//    In the Geometry toolbar, click Booleans and Partitions and choose Difference.

    model.component("comp1").geom("geom1").create("dif1", "Difference");

//    Select the objects mov1(5), sph1.

    model.component("comp1").geom("geom1").feature("dif1").selection("input").set("mov1(5)", "sph1");

//    In the Settings window for Difference, locate the Difference section.
//    Select the Activate Selection toggle button for Objects to subtract.
//    Select the objects mov1(1), mov1(2), mov1(3), mov1(4), mov1(6), mov1(7).

    model.component("comp1").geom("geom1").feature("dif1").selection("input2")
         .set("mov1(1)", "mov1(2)", "mov1(3)", "mov1(4)", "mov1(6)", "mov1(7)");

//    Click Build All Objects.

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

//    In the Home 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");

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

//    In the Home toolbar, click Add Material to close the Add Material window.
//    In the Materials toolbar, click Blank Material.

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

//    Select Domain 6.

    model.component("comp1").material("mat2").selection().set(6);

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

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

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

    model.component("comp1").material("mat2").propertyGroup("def").set("relpermittivity", new String[]{"2.1"});
    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 Definitions toolbar, click Perfectly Matched Layer.

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

//    PML acts as absorbing layer for EM wave. The far-field quantities are calculated at air-PML boundary interfaces.
//    Select Domains 1, 2, 3, 4, 7, 8, 9, 10.

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

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

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

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

//    Select Boundaries 37, 38, 46, 51.

    model.component("comp1").physics("emw").feature("lport1").selection().set(37, 38, 46, 51);

//    These boundaries are located at the middle of the feeder element.
//    In the Settings window for Lumped Port, locate the Boundary Selection section.
//    Click Create Selection.
//    In the Create Selection dialog, type Lumped port in the Selection name text field.
//    Click OK.

    model.component("comp1").selection().create("sel1", "Explicit");
    model.component("comp1").selection("sel1").geom(2);
    model.component("comp1").selection("sel1").label("Lumped port");
    model.component("comp1").selection("sel1").set(37, 38, 46, 51);

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

//    In the Settings window for Lumped Port, locate the Lumped Port Properties section.
//    From the Type of lumped port list, select User defined.

    model.component("comp1").physics("emw").feature("lport1").set("PortType", "UserDefined");

    model.component("comp1").view("view1").set("showDirections", false);

//    In the \[h_\textrm{port}\] text field, type gap_size.

    model.component("comp1").physics("emw").feature("lport1").set("hPort", "gap_size");

//    In the \[w_\textrm{port}\] text field, type r_antenna*pi*2.

    model.component("comp1").physics("emw").feature("lport1").set("wPort", "r_antenna*pi*2");

//    Specify the \[\mathbf{a}_\textrm{h}\] vector as

    model.component("comp1").physics("emw").feature("lport1").set("ahPort", new int[]{0, 0, 1});

//    In the Physics toolbar, click Domains and choose Far-Field Domain.

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

//    In the Model Builder window, under Component 1 (comp1), click Mesh 1.
//    In the Settings window for Mesh, locate the Electromagnetic Waves, Frequency Domain (emw) section.
//    Select the Add far-field boundary layers checkbox.

    model.component("comp1").physics("emw").prop("MeshControl").set("AddFarFieldBoundaryLayers", true);

//    The <l>Add far-field boundary layers</l> option adds very thin layers to the <l>Far-Field Calculation</l> boundaries to improve the accuracy of far-field computations.
//    Click Build All.

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

//    <l>Hide for Physics</l> allows us to visualize the mesh and the rest of the results for internal geometric entities.
//    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 6, 10, 69, 72, 74.

    model.component("comp1").view("view1").hideEntities("hide1").set(6, 10, 69, 72, 74);

//    In the Model Builder window, under Component 1 (comp1), click Mesh 1.
//    Also inspect the boundary layer mesh adjacent to the <l>Far-Field Calculation</l> boundaries by plotting the mesh in a separate plot.
//    In the Mesh toolbar, click Plot.

    model.result().dataset().create("mesh1", "Mesh");
    model.result().dataset("mesh1").set("mesh", "mesh1");
    model.result().create("pg1", "PlotGroup3D");
    model.result("pg1").label("Mesh Plot 1");
    model.result("pg1").set("data", "mesh1");
    model.result("pg1").set("inherithide", true);
    model.result("pg1").set("showlegendsmaxmin", true);
    model.result("pg1").create("mesh1", "Mesh");
    model.result("pg1").feature("mesh1").set("colortable", "TrafficFlow");
    model.result("pg1").feature("mesh1").set("colortabletrans", "nonlinear");
    model.result("pg1").feature("mesh1").set("nonlinearcolortablerev", true);
    model.result("pg1").feature("mesh1").set("meshdomain", "volume");
    model.result("pg1").run();
    model.result("pg1").feature("mesh1").set("colortable", "TrafficFlow");
    model.result("pg1").feature("mesh1").set("colortabletrans", "nonlinear");
    model.result("pg1").feature("mesh1").set("nonlinearcolortablerev", true);

//    In the Settings window for Mesh, locate the Coloring and Style section.
//    From the Quality measure list, select Volume versus circumradius.

    model.result("pg1").feature("mesh1").set("qualmeasure", "volcircum");

//    Right-click Mesh 1 and choose Filter.

    model.result("pg1").feature("mesh1").create("filt1", "Filter");
    model.result("pg1").run();

//    Click the Go to Default View button in the Graphics toolbar.
//    In the Settings window for Filter, locate the Element Selection section.
//    In the Logical expression for inclusion text field, type x>0.

    model.result("pg1").feature("mesh1").feature("filt1").set("expr", "x>0");

//    In the Mesh Plot 1 toolbar, click Plot.

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

//    First, run a frequency domain study to analyze the far-field radiation of the antenna.
//    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 2.45.

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

//    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("pg3", "PlotGroup3D");
    model.result("pg3").set("data", "dset1");
    model.result("pg3").setIndex("looplevel", 1, 0);
    model.result("pg3").create("mslc1", "Multislice");
    model.result("pg3").feature("mslc1").set("expr", new String[]{"emw.normE"});
    model.result("pg3").set("showlegendsmaxmin", true);
    model.result("pg3").feature("mslc1").set("colortable", "RainbowLight");
    model.result("pg3").label("Electric Field (emw)");
    model.result("pg3").selection().geom("geom1", 3);
    model.result("pg3").selection().set(5, 6);
    model.result("pg3").set("applyselectiontodatasetedges", true);
    model.result("pg3").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("pg4", "PlotGroup3D");
    model.result("pg4").set("data", "dset1");
    model.result("pg4").label("Electric Field, Logarithmic (emw)");
    model.result("pg4").selection().geom("geom1", 3);
    model.result("pg4").selection().set(5, 6);
    model.result("pg4").set("applyselectiontodatasetedges", true);

    model.component("comp1").measure().selection().geom(2);
    model.component("comp1").measure().selection()
         .set(18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 39, 40, 41, 42, 43, 44, 45, 47, 48, 49, 50, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125);
    model.component("comp1").measure().selection().geom(2);
    model.component("comp1").measure().selection()
         .set(5, 6, 7, 8, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 71, 72, 77, 82, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125);

    model.result("pg4").create("surf1", "Surface");
    model.result("pg4").feature("surf1").set("expr", "emw.normE");
    model.result("pg4").feature("surf1").create("sel1", "Selection");
    model.result("pg4").feature("surf1").feature("sel1").selection()
         .set(18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 39, 40, 41, 42, 43, 44, 45, 47, 48, 49, 50, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125);
    model.result("pg4").feature("surf1").set("colortable", "Dipole");
    model.result("pg4").feature("surf1").set("colorscalemode", "logarithmic");
    model.result("pg4").feature("surf1").create("mtrl1", "MaterialAppearance");
    model.result("pg4").feature("surf1").feature("mtrl1").set("appearance", "custom");
    model.result("pg4").feature("surf1").feature("mtrl1").set("family", "aluminumpolished");
    model.result("pg4").feature("surf1").set("expr", "1");
    model.result("pg4").create("mslc1", "Multislice");
    model.result("pg4").feature("mslc1").set("expr", "emw.normE");
    model.result("pg4").feature("mslc1").create("sel1", "Selection");
    model.result("pg4").feature("mslc1").feature("sel1").selection().set(5);
    model.result("pg4").feature("mslc1").set("colortable", "Prism");
    model.result("pg4").feature("mslc1").set("colorscalemode", "logarithmic");
    model.result("pg4").feature("mslc1").set("colortabletype", "discrete");

    return model;
  }

  public static Model run2(Model model) {
    model.result("pg4").feature("mslc1").set("bandcount", 20);
    model.result("pg4").feature("mslc1").create("tran1", "Transparency");
    model.result("pg4").feature("mslc1").feature("tran1").set("transparency", 0.5);
    model.result("pg4").feature("mslc1").set("znumber", "0");
    model.result("pg4").create("surf2", "Surface");
    model.result("pg4").feature("surf2").set("expr", "emw.normE");
    model.result("pg4").feature("surf2").create("sel1", "Selection");
    model.result("pg4").feature("surf2").feature("sel1").selection().set(13, 14, 15, 16, 17, 126);
    model.result("pg4").feature("surf2").set("colortable", "Dipole");
    model.result("pg4").feature("surf2").set("colorscalemode", "logarithmic");
    model.result("pg4").feature("surf2").create("tran1", "Transparency");
    model.result("pg4").feature("surf2").feature("tran1").set("transparency", 0.3);
    model.result("pg4").create("surf3", "Surface");
    model.result("pg4").feature("surf3").set("expr", "emw.normE");
    model.result("pg4").feature("surf3").create("sel1", "Selection");
    model.result("pg4").feature("surf3").feature("sel1").selection().set(37, 38, 46, 51);
    model.result("pg4").feature("surf3").set("colortable", "Dipole");
    model.result("pg4").feature("surf3").set("colorscalemode", "logarithmic");
    model.result("pg4").feature("surf3").create("tran1", "Transparency");
    model.result("pg4").feature("surf3").feature("tran1").set("transparency", 0.7);

    model.component("comp1").view().create("view2", "geom1");
    model.component("comp1").view("view2").camera().set("position", new double[]{-0.5, -0.66, 0.5});
    model.component("comp1").view("view2").set("environmentmap", "Indoor");
    model.component("comp1").view("view2").camera().set("zoomanglefull", 48.525);

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

//    In the Results toolbar, click Global Evaluation.

    model.result().numerical().create("gev2", "EvalGlobal");

//    In the Settings window for Global Evaluation, type Global Evaluation, TRP in the Label text field.

    model.result().numerical("gev2").label("Global Evaluation, TRP");

//    Click Replace Expression in the upper-right corner of the Expressions section.
//    From the menu, choose Component 1 (comp1) > Electromagnetic Waves, Frequency Domain > Far field > emw.TRPdB - Total radiated power, dB - dB.

    model.result().numerical("gev2").set("expr", new String[]{"emw.TRPdB"});
    model.result().numerical("gev2").set("descr", new String[]{"Total radiated power, dB"});
    model.result().numerical("gev2").set("unit", new String[]{"dB"});

//    Click Evaluate.

    model.result().table().create("tbl3", "Table");
    model.result().table("tbl3").comments("Global Evaluation, TRP");
    model.result().numerical("gev2").set("table", "tbl3");
    model.result().numerical("gev2").setResult();
    model.result("pg3").run();
    model.result("pg3").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("pg3").feature("mslc1").set("xnumber", "0");

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

    model.result("pg3").feature("mslc1").set("znumber", "0");

//    Click to expand the Range section.
//    Select the Manual color range checkbox.

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

//    In the Minimum text field, type 0.

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

//    In the Maximum text field, type 500.

    model.result("pg3").feature("mslc1").set("rangecolormax", 500);

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

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

//    Click the Go to XZ View button in the Graphics toolbar.

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

//    In the Model Builder window, under Results, click Electric Field, Logarithmic (emw).

    model.result("pg5").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, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Electromagnetic Waves, Frequency Domain > Far field > emw.rGaindBEfar - Realized far-field gain, dBi - dB.

    model.result("pg5").feature("rp1").set("expr", "emw.rGaindBEfar");
    model.result("pg5").feature("rp1").set("descr", "Realized far-field gain, dBi");

//    Locate the Evaluation section.
//    Click Preview Evaluation Plane.
//    Click to expand the Legends section.
//    From the Legends list, select Manual.

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

//    In the table, enter the following settings:

    model.result("pg5").feature("rp1").setIndex("legends", "H-plane", 0);

//    Right-click Results > 2D Far Field (emw) > Radiation Pattern 1 and choose Duplicate.

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

//    In the Settings window for Radiation Pattern, locate the Evaluation section.
//    Find the Normal vector subsection.
//    In the y text field, type -1.

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

//    In the z text field, type 0.

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

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

    model.result("pg5").feature("rp2").setIndex("legends", "E-plane", 0);

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

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

//    In the Model Builder window, click 2D Far Field (emw).
//    In the Settings window for Polar Plot Group, locate the Axis section.
//    Select the Manual axis limits checkbox.

    model.result("pg5").set("axislimits", true);

//    In the r maximum text field, type 15.

    model.result("pg5").set("rmax", 15);

//    In the r minimum text field, type -25.

    model.result("pg5").set("rmin", -25);

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

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

//    In the Model Builder window, expand the Results > 3D Far Field, Gain (emw) node, then click Radiation Pattern 1.
//    In the Settings window for Radiation Pattern, locate the Expression section.
//    Select the Threshold checkbox.

    model.result("pg6").feature("rp1").set("thresholdactive", true);

//    In the associated text field, type -20.

    model.result("pg6").feature("rp1").set("threshold", -20);

//    Locate the Evaluation section.
//    Find the Angles subsection.
//    In the Number of elevation angles text field, type 90.

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

//    In the Number of azimuth angles text field, type 90.
//    In the 3D Far Field, Gain (emw) toolbar, click Plot.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    Next, perform an adaptive frequency sweep to observe S-parameter responses for a wide band with a fine frequency step.
//    In the Home toolbar, click Add Study to open the Add Study window.
//    Find the Studies subsection.
//    In the Select Study tree, select Preset Studies for Selected Physics Interfaces > Adaptive Frequency Sweep.
//    Click Add Study in the window toolbar.

    model.study().create("std2");
    model.study("std2").create("frawe", "FrequencyAdaptive");
    model.study("std2").feature("frawe").set("plotgrouparr", new String[]{"Default"});
    model.study("std2").feature("frawe").set("solnum", "auto");
    model.study("std2").feature("frawe").set("notsolnum", "auto");
    model.study("std2").feature("frawe").set("outputmap", new String[]{});

//    In the Home toolbar, click Add Study to close the Add Study window.
//    In the Settings window for Adaptive Frequency Sweep, locate the Study Settings section.
//    Click Range.
//    In the Range dialog, type 2.3[GHz] in the Start text field.
//    In the Stop text field, type 2.6[GHz].
//    Click Replace.

    model.study("std2").feature("frawe").set("plist", "range(2.3[GHz],5[MHz],2.6[GHz])");

//    In the Settings window for Adaptive Frequency Sweep, click to expand the Store in Output section.
//    In the table, enter the following settings:

    model.study("std2").feature("frawe").setEntry("outputmap", "emw", "selection");

//    Click to select the first row in the table.
//    Under Selections, click Add.
//    In the Add dialog, select Lumped port (Boundary) in the Selections list.
//    Store in Output for the selected lumped port boundaries reduces the size of the model file.
//    Click OK.

    model.study("std2").feature("frawe").setEntry("outputselectionmap", "emw", "sel1");

//    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.component("comp1").probe("emw_lport1_probe").genResult("none");

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

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

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

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

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

//    In the Settings window for Global, locate the Data section.
//    From the Dataset list, select Probe Solution 2 (sol2).

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

//    Click Replace Expression in the upper-right corner of the y-Axis Data section.
//    From the menu, choose Component 1 (comp1) > Electromagnetic Waves, Frequency Domain > Ports > emw.S11dB - S11 - dB.

    model.result("pg7").feature("glob1").set("expr", new String[]{"emw.S11dB"});
    model.result("pg7").feature("glob1").set("descr", new String[]{"S11"});
    model.result("pg7").feature("glob1").set("unit", new String[]{"dB"});

//    Click to expand the Coloring and Style section.
//    Find the Line markers subsection.
//    From the Marker list, select Asterisk.

    model.result("pg7").feature("glob1").set("linemarker", "asterisk");

//    From the Positioning list, select Interpolated.

    model.result("pg7").feature("glob1").set("markerpos", "interp");

//    In the Number text field, type 30.

    model.result("pg7").feature("glob1").set("markers", 30);

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

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

    model.title("Wi-Fi Booster Yagi\u2013Uda Antenna");

    model
         .description("The Yagi\u2013Uda antenna is designed for a specific Wi-Fi band and can reduce eavesdropping by directing signals with the help of directors. This antenna consists of one uniformly spaced reflector and four directors. Simulated results show a maximum 10\u00a0dBi gain and a front-to-back ratio of 14\u00a0dB.");

    return model;
  }

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

}
