/*
 * waveguide_adapter.java
 */

import com.comsol.model.*;
import com.comsol.model.util.*;

/** Model exported on May 15 2026, 11:20 by COMSOL 6.4.0.421. */
public class waveguide_adapter {

  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 Empty Study.
//    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");

//    In the Study toolbar, click More Study Steps and choose Other > Boundary Mode Analysis.

    model.study("std1").create("bma", "BoundaryModeAnalysis");

//    Define the study frequency ahead of performing any frequency-dependent operation such as building mesh. The physics-controlled mesh uses the specified frequency value.
//    In the Settings window for Boundary Mode Analysis, locate the Study Settings section.
//    In the Mode analysis frequency text field, type 7[GHz].

    model.study("std1").feature("bma").set("modeFreq", "7[GHz]");

//    The exact value of this frequency is not important. What matters is that it should be above the cutoff frequency for the fundamental mode, but below that for the next mode. This setting ensures that the boundary mode analysis finds the fundamental mode.
//    Add another boundary mode analysis, for the second port.
//    In the Study toolbar, click More Study Steps and choose Other > Boundary Mode Analysis.

    model.study("std1").create("bma2", "BoundaryModeAnalysis");

//    In the Settings window for Boundary Mode Analysis, locate the Study Settings section.
//    In the Port name text field, type 2.

    model.study("std1").feature("bma2").set("PortName", "2");

//    In the Mode analysis frequency text field, type 7[GHz].

    model.study("std1").feature("bma2").set("modeFreq", "7[GHz]");

//    Finally, add the 3D equation for the propagating wave in the waveguide.
//    In the Study toolbar, click Frequency Domain.

    model.study("std1").create("freq", "Frequency");

//    In the Settings window for Frequency Domain, locate the Study Settings section.
//    In the Frequencies text field, type range(6.6[GHz],3.4[GHz]/49,10[GHz]).

    model.study("std1").feature("freq").set("plist", "range(6.6[GHz],3.4[GHz]/49,10[GHz])");

//    Proceed to import the geometry.
//    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 waveguide_adapter.mphbin.

    model.component("comp1").geom("geom1").feature("imp1").set("filename", "waveguide_adapter.mphbin");

//    Click Import.

    model.component("comp1").geom("geom1").feature("imp1").importData();
    model.component("comp1").geom("geom1").run();

//    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.
//    By default, the first material you add applies on all domains so you need not alter any settings.
//    In the Physics toolbar, click Boundaries and choose Port.

    model.component("comp1").physics("emw").create("port1", "Port", 2);

//    In the Settings window for Port, locate the Port Properties section.
//    From the Type of port list, select Numeric.

    model.component("comp1").physics("emw").feature("port1").set("PortType", "Numeric");

//    For the first port, wave excitation is <l>on</l> by default.
//    Select Boundary 13.

    model.component("comp1").physics("emw").feature("port1").selection().set(13);

//    The wave enters the adapter through the port with a rectangular cross section.
//    In the Physics toolbar, click Boundaries and choose Port.

    model.component("comp1").physics("emw").create("port2", "Port", 2);

//    In the Settings window for Port, locate the Port Properties section.
//    From the Type of port list, select Numeric.

    model.component("comp1").physics("emw").feature("port2").set("PortType", "Numeric");

//    Select Boundary 6.

    model.component("comp1").physics("emw").feature("port2").selection().set(6);

//    This is the exit port, the one with an elliptical cross section.
//    In the Model Builder window, under Component 1 (comp1), click Mesh 1.
//    In the Settings window for Mesh, locate the Physics-Controlled Mesh section.
//    From the Element size list, select Coarse.

    model.component("comp1").mesh("mesh1").autoMeshSize(6);

//    Click Build All.

    model.component("comp1").mesh("mesh1").run();

//    Now set up the study to find the boundary modes and use them when computing the field distribution over a range of frequencies.
//    In the Model Builder window, under Study 1, click Step 1: Boundary Mode Analysis.
//    In the Settings window for Boundary Mode Analysis, locate the Study Settings section.
//    In the Search for modes around shift text field, type 50.

    model.study("std1").feature("bma").set("shift", "50");

//    This value should be in the vicinity of the value that you expect the fundamental mode to have. If you do not know this in advance, you can experiment with some different values or estimate one from analytical formulas valid for cross sections resembling yours.
//    From the Transform list, select Out-of-plane wave number.

    model.study("std1").feature("bma").set("transform", "outofplanewavenumber");

//    In the Model Builder window, click Step 2: Boundary Mode Analysis 2.
//    In the Settings window for Boundary Mode Analysis, locate the Study Settings section.
//    In the Search for modes around shift text field, type 50.

    model.study("std1").feature("bma2").set("shift", "50");

//    From the Transform list, select Out-of-plane wave number.

    model.study("std1").feature("bma2").set("transform", "outofplanewavenumber");

//    In the Study toolbar, click Compute.

    model.study("std1").createAutoSequences("all");

    model.component("comp1").probe("emw_port1_probe").genResult("none");

    model.sol("sol1").runAll();

    model.result().create("pg2", "PlotGroup3D");
    model.result("pg2").set("data", "dset1");
    model.result("pg2").setIndex("looplevel", 50, 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"});
    model.result("pg3").feature("glob1").set("descr", new String[]{"S11", "S21"});
    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)");
    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);
    model.result("pg5").set("applyselectiontodatasetedges", true);

    model.component("comp1").measure().selection().geom(2);
    model.component("comp1").measure().selection()
         .set(1, 2, 4, 5, 7, 8, 9, 10, 11, 12, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28);
    model.component("comp1").measure().selection().geom(2);
    model.component("comp1").measure().selection()
         .set(1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28);

    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, 4, 5, 7, 8, 9, 10, 11, 12, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28);
    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.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(3, 14);
    model.result("pg5").feature("surf2").set("colortable", "Dipole");
    model.result("pg5").feature("surf2").set("colorscalemode", "logarithmic");
    model.result("pg5").feature("surf2").create("tran1", "Transparency");
    model.result("pg5").feature("surf2").feature("tran1").set("transparency", 0.3);
    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(6, 13);
    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.7);

    model.component("comp1").view().create("view2", "geom1");
    model.component("comp1").view("view2").camera().set("position", new double[]{-0.17, -0.23, 0.2});
    model.component("comp1").view("view2").set("environmentmap", "Indoor");
    model.component("comp1").view("view2").camera().set("zoomanglefull", 59.074999999999996);

    model.result("pg5").set("view", "view2");
    model.result().create("pg6", "PlotGroup3D");
    model.result("pg6").label("Electric Mode Field, Port 1 (emw)");
    model.result("pg6").set("showlegendsmaxmin", true);
    model.result("pg6").set("data", "dset1");
    model.result("pg6").create("surf1", "Surface");
    model.result("pg6").feature("surf1").set("expr", "root.comp1.emw.normEbm_1");
    model.result("pg6").feature("surf1").set("colortable", "RainbowLight");
    model.result("pg6").create("ann1", "Annotation");
    model.result("pg6").feature("ann1").set("posxexpr", "emw.aveport1(x)");
    model.result("pg6").feature("ann1").set("posyexpr", "emw.aveport1(y)");
    model.result("pg6").feature("ann1").set("poszexpr", "emw.aveport1(z)");
    model.result("pg6").feature("ann1").set("backgroundcolor", "fromtheme");
    model.result("pg6").feature("ann1").set("text", "Effective mode index: eval(comp1.emw.neff_1)");
    model.result().create("pg7", "PlotGroup3D");
    model.result("pg7").label("Electric Mode Field, Port 2 (emw)");
    model.result("pg7").set("showlegendsmaxmin", true);
    model.result("pg7").set("data", "dset1");
    model.result("pg7").create("surf1", "Surface");
    model.result("pg7").feature("surf1").set("expr", "root.comp1.emw.normEbm_2");
    model.result("pg7").feature("surf1").set("colortable", "RainbowLight");
    model.result("pg7").create("ann1", "Annotation");
    model.result("pg7").feature("ann1").set("posxexpr", "emw.aveport2(x)");
    model.result("pg7").feature("ann1").set("posyexpr", "emw.aveport2(y)");
    model.result("pg7").feature("ann1").set("poszexpr", "emw.aveport2(z)");
    model.result("pg7").feature("ann1").set("backgroundcolor", "fromtheme");
    model.result("pg7").feature("ann1").set("text", "Effective mode index: eval(comp1.emw.neff_2)");
    model.result("pg2").run();

//    Click the Zoom Extents button in the Graphics toolbar.
//    The default plot shows the norm of the electric field on slices through the waveguide; you can simplify and improve this plot.
//    Delete the Multislice plot.

    model.result("pg2").run();

//    In the Model Builder window, expand the Electric Field (emw) node.
//    Right-click Multislice 1 and choose Delete.

    model.result("pg2").feature().remove("mslc1");
    model.result("pg2").run();

//    Right-click Electric Field (emw) and choose Slice.

    model.result("pg2").create("slc1", "Slice");
    model.result("pg2").feature("slc1").set("evaluationsettings", "parent");

//    In the Settings window for Slice, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Electromagnetic Waves, Frequency Domain > Electric > Electric field - V/m > emw.Ex - Electric field, x-component.

    model.result("pg2").feature("slc1").set("expr", "emw.Ex");
    model.result("pg2").feature("slc1").set("descr", "Electric field, x-component");

//    Locate the Coloring and Style section.
//    From the Color table list, select WaveLight.

    model.result("pg2").feature("slc1").set("colortable", "WaveLight");

//    Locate the Plane Data section.
//    In the Planes text field, type 1.

    model.result("pg2").feature("slc1").set("quickxnumber", 1);

//    In the Electric Field (emw) toolbar, click Plot.

    model.result("pg2").run();

//    Proceed by checking the plot of the S-parameters as functions of the frequency.

    model.result("pg3").run();
    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).

    model.result("pg6").set("applyselectiontodatasetedges", false);
    model.result("pg6").run();

//    In the Model Builder window, click Electric Mode Field, Port 1 (emw).

    model.result("pg7").run();

//    In the Model Builder window, click Electric Mode Field, Port 2 (emw).

    model.title("Waveguide Adapter");

    model
         .description("This is a model of an adapter for microwave propagation in the transition between a rectangular and an elliptical waveguide. The scattering S-parameters are calculated for frequencies in the single mode range.");

    return model;
  }

  public static void main(String[] args) {
    run();
  }

}
