/*
 * spp_otto_kretschmann.java
 */

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

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

  public static Model run() {
    Model model = ModelUtil.create("Model");

//    From the File menu, choose New.
//    In the New window, click Model Wizard.
//    Use two physics interfaces to simulate the Otto and Kretschmann configurations independently, and another physics interface to calculate the angle phase matching.
//    In the Model Wizard window, click 2D.
//    In the Select Physics tree, select Optics > Wave Optics > Electromagnetic Waves, Frequency Domain (ewfd).
//    Click Add.
//    Click Add.
//    , to add the second physics interface.
//    Click Add.
//    , to add the third physics interface.
//    Click Study.
//    In the Select Study tree, select Preset Studies for Selected Physics Interfaces > Wavelength Domain.
//    Click Done.

    model.component().create("comp1", true);

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

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

    model.component("comp1").physics().create("ewfd", "ElectromagneticWavesFrequencyDomain", "geom1");
    model.component("comp1").physics().create("ewfd2", "ElectromagneticWavesFrequencyDomain", "geom1");
    model.component("comp1").physics().create("ewfd3", "ElectromagneticWavesFrequencyDomain", "geom1");

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

//    In the Model Builder window, under Component 1 (comp1), click Geometry 1.
//    In the Settings window for Geometry, locate the Units section.
//    From the Length unit list, select µm.

    model.component("comp1").geom("geom1").lengthUnit("\u00b5m");

//    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("L", "1[um]");
    model.param().descr("L", "Simulation domain length");
    model.param().set("H", "3[um]");
    model.param().descr("H", "Simulation domain height");
    model.param().set("lda0", "500[nm]");
    model.param().descr("lda0", "Wavelength");
    model.param().set("angle", "0[deg]");
    model.param().descr("angle", "Incident angle");
    model.param().set("n_prism", "1.4");
    model.param().descr("n_prism", "Refractive index, prism");

//    The geometry is simple, consisting of three rectangular geometries side by side, representing the (i) Otto and (ii) Kretschmann configurations, and (iii) to calculate the angle phase matching.
//    First, build the geometry of the Otto configuration.
//    In the Geometry toolbar, click Rectangle.

    model.component("comp1").geom("geom1").create("r1", "Rectangle");

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

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

//    In the Height text field, type H.

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

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

    model.component("comp1").geom("geom1").feature("r1").setIndex("layer", "H/2", 0);
    model.component("comp1").geom("geom1").feature("r1").setIndex("layer", "lda0", 1);

//    Click Build Selected.

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

//    Next, build the geometry of the Kretschmann configuration.
//    Right-click Rectangle 1 (r1) and choose Duplicate.

    model.component("comp1").geom("geom1").feature().duplicate("r2", "r1");

//    In the Settings window for Rectangle, locate the Position section.
//    In the x text field, type 1.25*L.

    model.component("comp1").geom("geom1").feature("r2").set("pos", new String[]{"1.25*L", "0"});

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

    model.component("comp1").geom("geom1").feature("r2").setIndex("layer", "lda0/10", 1);

//    Click Build Selected.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    Now, build the geometry to calculate the angle phase matching.
//    In the Geometry toolbar, click Rectangle.

    model.component("comp1").geom("geom1").create("r3", "Rectangle");

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

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

//    In the Height text field, type H.

    model.component("comp1").geom("geom1").feature("r3").set("size", new String[]{"L", "H"});

//    Locate the Position section.
//    In the x text field, type 2.5*L.

    model.component("comp1").geom("geom1").feature("r3").set("pos", new String[]{"2.5*L", "0"});

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

    model.component("comp1").geom("geom1").feature("r3").setIndex("layer", "H/2", 0);

//    Click Build All Objects.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    Pick silver from the Optical material library.

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

//    In the Materials toolbar, click Add Material to open the Add Material window.
//    In the tree, select Optical > Inorganic Materials > Ag - Silver > Experimental data: bulk, thick film > Ag (Silver) (Johnson and Christy 1972: n,k 0.188-1.94 um).
//    Right-click and choose Add to Component 1 (comp1).

    model.component("comp1").material().create("mat1", "Common");
    model.component("comp1").material("mat1").propertyGroup()
         .create("RefractiveIndex", "RefractiveIndex", "Refractive index");
    model.component("comp1").material("mat1").propertyGroup("RefractiveIndex").func().create("int1", "Interpolation");
    model.component("comp1").material("mat1").propertyGroup("RefractiveIndex").func().create("int2", "Interpolation");
    model.component("comp1").material("mat1").label("Ag (Silver) (Johnson and Christy 1972: n,k 0.188-1.94 um)");
    model.component("comp1").material("mat1").propertyGroup("RefractiveIndex").func("int1").set("funcname", "nr");
    model.component("comp1").material("mat1").propertyGroup("RefractiveIndex").func("int1")
         .set("table", new String[][]{{"0.1879", "1.07"}, 
         {"0.1916", "1.10"}, 
         {"0.1953", "1.12"}, 
         {"0.1993", "1.14"}, 
         {"0.2033", "1.15"}, 
         {"0.2073", "1.18"}, 
         {"0.2119", "1.20"}, 
         {"0.2164", "1.22"}, 
         {"0.2214", "1.25"}, 
         {"0.2262", "1.26"}, 
         {"0.2313", "1.28"}, 
         {"0.2371", "1.28"}, 
         {"0.2426", "1.30"}, 
         {"0.2490", "1.31"}, 
         {"0.2551", "1.33"}, 
         {"0.2616", "1.35"}, 
         {"0.2689", "1.38"}, 
         {"0.2761", "1.41"}, 
         {"0.2844", "1.41"}, 
         {"0.2924", "1.39"}, 
         {"0.3009", "1.34"}, 
         {"0.3107", "1.13"}, 
         {"0.3204", "0.81"}, 
         {"0.3315", "0.17"}, 
         {"0.3425", "0.14"}, 
         {"0.3542", "0.10"}, 
         {"0.3679", "0.07"}, 
         {"0.3815", "0.05"}, 
         {"0.3974", "0.05"}, 
         {"0.4133", "0.05"}, 
         {"0.4305", "0.04"}, 
         {"0.4509", "0.04"}, 
         {"0.4714", "0.05"}, 
         {"0.4959", "0.05"}, 
         {"0.5209", "0.05"}, 
         {"0.5486", "0.06"}, 
         {"0.5821", "0.05"}, 
         {"0.6168", "0.06"}, 
         {"0.6595", "0.05"}, 
         {"0.7045", "0.04"}, 
         {"0.7560", "0.03"}, 
         {"0.8211", "0.04"}, 
         {"0.8920", "0.04"}, 
         {"0.9840", "0.04"}, 
         {"1.0880", "0.04"}, 
         {"1.2160", "0.09"}, 
         {"1.3930", "0.13"}, 
         {"1.6100", "0.15"}, 
         {"1.9370", "0.24"}});
    model.component("comp1").material("mat1").propertyGroup("RefractiveIndex").func("int1")
         .set("fununit", new String[]{"1"});
    model.component("comp1").material("mat1").propertyGroup("RefractiveIndex").func("int1")
         .set("argunit", new String[]{"um"});
    model.component("comp1").material("mat1").propertyGroup("RefractiveIndex").func("int2").set("funcname", "ni");
    model.component("comp1").material("mat1").propertyGroup("RefractiveIndex").func("int2")
         .set("table", new String[][]{{"0.1879", "1.212"}, 
         {"0.1916", "1.232"}, 
         {"0.1953", "1.255"}, 
         {"0.1993", "1.277"}, 
         {"0.2033", "1.296"}, 
         {"0.2073", "1.312"}, 
         {"0.2119", "1.325"}, 
         {"0.2164", "1.336"}, 
         {"0.2214", "1.342"}, 
         {"0.2262", "1.344"}, 
         {"0.2313", "1.357"}, 
         {"0.2371", "1.367"}, 
         {"0.2426", "1.378"}, 
         {"0.2490", "1.389"}, 
         {"0.2551", "1.393"}, 
         {"0.2616", "1.387"}, 
         {"0.2689", "1.372"}, 
         {"0.2761", "1.331"}, 
         {"0.2844", "1.264"}, 
         {"0.2924", "1.161"}, 
         {"0.3009", "0.964"}, 
         {"0.3107", "0.616"}, 
         {"0.3204", "0.392"}, 
         {"0.3315", "0.829"}, 
         {"0.3425", "1.142"}, 
         {"0.3542", "1.419"}, 
         {"0.3679", "1.657"}, 
         {"0.3815", "1.864"}, 
         {"0.3974", "2.070"}, 
         {"0.4133", "2.275"}, 
         {"0.4305", "2.462"}, 
         {"0.4509", "2.657"}, 
         {"0.4714", "2.869"}, 
         {"0.4959", "3.093"}, 
         {"0.5209", "3.324"}, 
         {"0.5486", "3.586"}, 
         {"0.5821", "3.858"}, 
         {"0.6168", "4.152"}, 
         {"0.6595", "4.483"}, 
         {"0.7045", "4.838"}, 
         {"0.7560", "5.242"}, 
         {"0.8211", "5.727"}, 
         {"0.8920", "6.312"}, 
         {"0.9840", "6.992"}, 
         {"1.0880", "7.795"}, 
         {"1.2160", "8.828"}, 
         {"1.3930", "10.10"}, 
         {"1.6100", "11.85"}, 
         {"1.9370", "14.08"}});
    model.component("comp1").material("mat1").propertyGroup("RefractiveIndex").func("int2")
         .set("fununit", new String[]{"1"});
    model.component("comp1").material("mat1").propertyGroup("RefractiveIndex").func("int2")
         .set("argunit", new String[]{"um"});
    model.component("comp1").material("mat1").propertyGroup("RefractiveIndex")
         .set("n", new String[]{"nr(c_const/freq)", "0", "0", "0", "nr(c_const/freq)", "0", "0", "0", "nr(c_const/freq)"});
    model.component("comp1").material("mat1").propertyGroup("RefractiveIndex")
         .set("ki", new String[]{"ni(c_const/freq)", "0", "0", "0", "ni(c_const/freq)", "0", "0", "0", "ni(c_const/freq)"});
    model.component("comp1").material("mat1").propertyGroup("RefractiveIndex").addInput("frequency");

//    In the tree, select Built-in > Air.
//    Right-click and choose Add to Component 1 (comp1).

    model.component("comp1").material().create("mat2", "Common");
    model.component("comp1").material("mat2").propertyGroup("def").func().create("eta", "Piecewise");
    model.component("comp1").material("mat2").propertyGroup("def").func().create("Cp", "Piecewise");
    model.component("comp1").material("mat2").propertyGroup("def").func().create("rho", "Analytic");
    model.component("comp1").material("mat2").propertyGroup("def").func().create("k", "Piecewise");
    model.component("comp1").material("mat2").propertyGroup("def").func().create("cs", "Analytic");
    model.component("comp1").material("mat2").propertyGroup("def").func().create("an1", "Analytic");
    model.component("comp1").material("mat2").propertyGroup("def").func().create("an2", "Analytic");
    model.component("comp1").material("mat2").propertyGroup()
         .create("RefractiveIndex", "RefractiveIndex", "Refractive index");
    model.component("comp1").material("mat2").propertyGroup()
         .create("NonlinearModel", "NonlinearModel", "Nonlinear model");
    model.component("comp1").material("mat2").propertyGroup().create("idealGas", "idealGas", "Ideal gas");
    model.component("comp1").material("mat2").propertyGroup("idealGas").func().create("Cp", "Piecewise");
    model.component("comp1").material("mat2").label("Air");
    model.component("comp1").material("mat2").set("family", "air");
    model.component("comp1").material("mat2").propertyGroup("def").func("eta").set("arg", "T");
    model.component("comp1").material("mat2").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("mat2").propertyGroup("def").func("eta").set("argunit", "K");
    model.component("comp1").material("mat2").propertyGroup("def").func("eta").set("fununit", "Pa*s");
    model.component("comp1").material("mat2").propertyGroup("def").func("Cp").set("arg", "T");
    model.component("comp1").material("mat2").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("mat2").propertyGroup("def").func("Cp").set("argunit", "K");
    model.component("comp1").material("mat2").propertyGroup("def").func("Cp").set("fununit", "J/(kg*K)");
    model.component("comp1").material("mat2").propertyGroup("def").func("rho")
         .set("expr", "pA*0.02897/R_const[K*mol/J]/T");
    model.component("comp1").material("mat2").propertyGroup("def").func("rho").set("args", new String[]{"pA", "T"});
    model.component("comp1").material("mat2").propertyGroup("def").func("rho").set("fununit", "kg/m^3");
    model.component("comp1").material("mat2").propertyGroup("def").func("rho")
         .set("argunit", new String[]{"Pa", "K"});
    model.component("comp1").material("mat2").propertyGroup("def").func("rho")
         .set("plotaxis", new String[]{"off", "on"});
    model.component("comp1").material("mat2").propertyGroup("def").func("rho")
         .set("plotfixedvalue", new String[]{"101325", "273.15"});
    model.component("comp1").material("mat2").propertyGroup("def").func("rho")
         .set("plotargs", new String[][]{{"pA", "101325", "101325"}, {"T", "273.15", "293.15"}});
    model.component("comp1").material("mat2").propertyGroup("def").func("k").set("arg", "T");
    model.component("comp1").material("mat2").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("mat2").propertyGroup("def").func("k").set("argunit", "K");
    model.component("comp1").material("mat2").propertyGroup("def").func("k").set("fununit", "W/(m*K)");
    model.component("comp1").material("mat2").propertyGroup("def").func("cs")
         .set("expr", "sqrt(1.4*R_const[K*mol/J]/0.02897*T)");
    model.component("comp1").material("mat2").propertyGroup("def").func("cs").set("args", new String[]{"T"});
    model.component("comp1").material("mat2").propertyGroup("def").func("cs").set("fununit", "m/s");
    model.component("comp1").material("mat2").propertyGroup("def").func("cs").set("argunit", new String[]{"K"});
    model.component("comp1").material("mat2").propertyGroup("def").func("cs")
         .set("plotfixedvalue", new String[]{"273.15"});
    model.component("comp1").material("mat2").propertyGroup("def").func("cs")
         .set("plotargs", new String[][]{{"T", "273.15", "373.15"}});
    model.component("comp1").material("mat2").propertyGroup("def").func("an1").set("funcname", "alpha_p");
    model.component("comp1").material("mat2").propertyGroup("def").func("an1")
         .set("expr", "-1/rho(pA,T)*d(rho(pA,T),T)");
    model.component("comp1").material("mat2").propertyGroup("def").func("an1").set("args", new String[]{"pA", "T"});
    model.component("comp1").material("mat2").propertyGroup("def").func("an1").set("fununit", "1/K");
    model.component("comp1").material("mat2").propertyGroup("def").func("an1")
         .set("argunit", new String[]{"Pa", "K"});
    model.component("comp1").material("mat2").propertyGroup("def").func("an1")
         .set("plotaxis", new String[]{"off", "on"});
    model.component("comp1").material("mat2").propertyGroup("def").func("an1")
         .set("plotfixedvalue", new String[]{"101325", "273.15"});
    model.component("comp1").material("mat2").propertyGroup("def").func("an1")
         .set("plotargs", new String[][]{{"pA", "101325", "101325"}, {"T", "273.15", "373.15"}});
    model.component("comp1").material("mat2").propertyGroup("def").func("an2").set("funcname", "muB");
    model.component("comp1").material("mat2").propertyGroup("def").func("an2").set("expr", "0.6*eta(T)");
    model.component("comp1").material("mat2").propertyGroup("def").func("an2").set("args", new String[]{"T"});
    model.component("comp1").material("mat2").propertyGroup("def").func("an2").set("fununit", "Pa*s");
    model.component("comp1").material("mat2").propertyGroup("def").func("an2").set("argunit", new String[]{"K"});
    model.component("comp1").material("mat2").propertyGroup("def").func("an2")
         .set("plotfixedvalue", new String[]{"200"});
    model.component("comp1").material("mat2").propertyGroup("def").func("an2")
         .set("plotargs", new String[][]{{"T", "200", "1600"}});
    model.component("comp1").material("mat2").propertyGroup("def").set("thermalexpansioncoefficient", "");
    model.component("comp1").material("mat2").propertyGroup("def").set("molarmass", "");
    model.component("comp1").material("mat2").propertyGroup("def").set("bulkviscosity", "");
    model.component("comp1").material("mat2").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("mat2").propertyGroup("def").set("molarmass", "0.02897[kg/mol]");
    model.component("comp1").material("mat2").propertyGroup("def").set("bulkviscosity", "muB(T)");
    model.component("comp1").material("mat2").propertyGroup("def")
         .set("relpermeability", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat2").propertyGroup("def")
         .set("relpermittivity", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat2").propertyGroup("def").set("dynamicviscosity", "eta(T)");
    model.component("comp1").material("mat2").propertyGroup("def").set("ratioofspecificheat", "1.4");
    model.component("comp1").material("mat2").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("mat2").propertyGroup("def").set("heatcapacity", "Cp(T)");
    model.component("comp1").material("mat2").propertyGroup("def").set("density", "rho(pA,T)");
    model.component("comp1").material("mat2").propertyGroup("def")
         .set("thermalconductivity", new String[]{"k(T)", "0", "0", "0", "k(T)", "0", "0", "0", "k(T)"});
    model.component("comp1").material("mat2").propertyGroup("def").set("soundspeed", "cs(T)");
    model.component("comp1").material("mat2").propertyGroup("def").addInput("temperature");
    model.component("comp1").material("mat2").propertyGroup("def").addInput("pressure");
    model.component("comp1").material("mat2").propertyGroup("RefractiveIndex")
         .set("n", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat2").propertyGroup("NonlinearModel").set("BA", "def.gamma-1");
    model.component("comp1").material("mat2").propertyGroup("idealGas").func("Cp").label("Piecewise 2");
    model.component("comp1").material("mat2").propertyGroup("idealGas").func("Cp").set("arg", "T");
    model.component("comp1").material("mat2").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("mat2").propertyGroup("idealGas").func("Cp").set("argunit", "K");
    model.component("comp1").material("mat2").propertyGroup("idealGas").func("Cp").set("fununit", "J/(kg*K)");
    model.component("comp1").material("mat2").propertyGroup("idealGas").set("Rs", "R_const/Mn");
    model.component("comp1").material("mat2").propertyGroup("idealGas").set("heatcapacity", "Cp(T)");
    model.component("comp1").material("mat2").propertyGroup("idealGas").set("ratioofspecificheat", "1.4");
    model.component("comp1").material("mat2").propertyGroup("idealGas").set("molarmass", "0.02897[kg/mol]");
    model.component("comp1").material("mat2").propertyGroup("idealGas").addInput("temperature");
    model.component("comp1").material("mat2").propertyGroup("idealGas").addInput("pressure");
    model.component("comp1").material("mat2").materialType("nonSolid");

//    In the Materials toolbar, click Add Material to close the Add Material window.
//    In the Model Builder window, under Component 1 (comp1) > Materials, click Air (mat2).
//    Select Domains 2, 4, 8.

    model.component("comp1").material("mat2").selection().set(2, 4, 8);

//    In the Model Builder window, right-click Materials and choose Blank Material.

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

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

    model.component("comp1").material("mat3").label("Prism");

//    Select Domains 3, 6.

    model.component("comp1").material("mat3").selection().set(3, 6);

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

    model.component("comp1").material("mat3").propertyGroup()
         .create("RefractiveIndex", "RefractiveIndex", "Refractive_index");
    model.component("comp1").material("mat3").propertyGroup("RefractiveIndex").set("n", new String[]{"n_prism"});

//    This physics interface is used to simulate the Otto configuration.
//    In the Model Builder window, under Component 1 (comp1), click Electromagnetic Waves, Frequency Domain (ewfd).
//    In the Settings window for Electromagnetic Waves, Frequency Domain, locate the Domain Selection section.
//    Click Clear Selection.

    model.component("comp1").physics("ewfd").selection().set();

//    Select Domains 1, 2, 3.

    model.component("comp1").physics("ewfd").selection().set(1, 2, 3);

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

    model.component("comp1").physics("ewfd").create("port1", "Port", 1);

//    Select Boundary 7.

    model.component("comp1").physics("ewfd").feature("port1").selection().set(7);

//    In the Settings window for Port, locate the Port Properties section.
//    From the Type of port list, select Periodic.

    model.component("comp1").physics("ewfd").feature("port1").set("PortType", "Periodic");

//    Locate the Port Mode Settings section.
//    From the Input quantity list, select Magnetic field.

    model.component("comp1").physics("ewfd").feature("port1").set("InputType", "H");

//    Specify the \[\mathbf{H}_{0}\] vector as

    model.component("comp1").physics("ewfd").feature("port1").set("Hampl", new int[]{0, 0, 1});

//    In the \[\alpha\] text field, type angle.

    model.component("comp1").physics("ewfd").feature("port1").set("alpha_inc", "angle");

//    Right-click Port 1 and choose Duplicate.

    model.component("comp1").physics("ewfd").feature().duplicate("port2", "port1");

//    In the Settings window for Port, locate the Boundary Selection section.
//    Click Clear Selection.

    model.component("comp1").physics("ewfd").feature("port2").selection().set();

//    Select Boundary 2.

    model.component("comp1").physics("ewfd").feature("port2").selection().set(2);

//    Locate the Port Properties section.
//    From the Wave excitation at this port list, select Off.

    model.component("comp1").physics("ewfd").feature("port2").set("PortExcitation", "off");

//    In the Physics toolbar, click Boundaries and choose Periodic Condition.

    model.component("comp1").physics("ewfd").create("pc1", "PeriodicCondition", 1);

//    Select Boundaries 1, 3, 5, 8, 9, 10.

    model.component("comp1").physics("ewfd").feature("pc1").selection().set(1, 3, 5, 8, 9, 10);

//    In the Settings window for Periodic Condition, locate the Periodicity Settings section.
//    From the Type of periodicity list, select Floquet periodicity.

    model.component("comp1").physics("ewfd").feature("pc1").set("PeriodicType", "Floquet");

//    From the k-vector for Floquet periodicity list, select From periodic port.

    model.component("comp1").physics("ewfd").feature("pc1").set("Floquet_source", "FromPeriodicPort");

//    This physics interface is used to simulate the Kretschmann configuration.
//    In the Model Builder window, under Component 1 (comp1), click Electromagnetic Waves, Frequency Domain 2 (ewfd2).
//    In the Settings window for Electromagnetic Waves, Frequency Domain, locate the Domain Selection section.
//    Click Clear Selection.

    model.component("comp1").physics("ewfd2").selection().set();

//    Select Domains 4, 5, 6.

    model.component("comp1").physics("ewfd2").selection().set(4, 5, 6);

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

    model.component("comp1").physics("ewfd2").create("port1", "Port", 1);

//    Select Boundary 17.

    model.component("comp1").physics("ewfd2").feature("port1").selection().set(17);

//    In the Settings window for Port, locate the Port Properties section.
//    From the Type of port list, select Periodic.

    model.component("comp1").physics("ewfd2").feature("port1").set("PortType", "Periodic");

//    Locate the Port Mode Settings section.
//    From the Input quantity list, select Magnetic field.

    model.component("comp1").physics("ewfd2").feature("port1").set("InputType", "H");

//    Specify the \[\mathbf{H}_{0}\] vector as

    model.component("comp1").physics("ewfd2").feature("port1").set("Hampl", new int[]{0, 0, 1});

//    In the \[\alpha\] text field, type angle.

    model.component("comp1").physics("ewfd2").feature("port1").set("alpha_inc", "angle");

//    Right-click Port 1 and choose Duplicate.

    model.component("comp1").physics("ewfd2").feature().duplicate("port2", "port1");

//    In the Settings window for Port, locate the Boundary Selection section.
//    Click Clear Selection.

    model.component("comp1").physics("ewfd2").feature("port2").selection().set();

//    Select Boundary 12.

    model.component("comp1").physics("ewfd2").feature("port2").selection().set(12);

//    Locate the Port Properties section.
//    From the Wave excitation at this port list, select Off.

    model.component("comp1").physics("ewfd2").feature("port2").set("PortExcitation", "off");

//    In the Physics toolbar, click Boundaries and choose Periodic Condition.

    model.component("comp1").physics("ewfd2").create("pc1", "PeriodicCondition", 1);

//    Select Boundaries 11, 13, 15, 18, 19, 20.

    model.component("comp1").physics("ewfd2").feature("pc1").selection().set(11, 13, 15, 18, 19, 20);

//    In the Settings window for Periodic Condition, locate the Periodicity Settings section.
//    From the Type of periodicity list, select Floquet periodicity.

    model.component("comp1").physics("ewfd2").feature("pc1").set("PeriodicType", "Floquet");

//    From the k-vector for Floquet periodicity list, select From periodic port.

    model.component("comp1").physics("ewfd2").feature("pc1").set("Floquet_source", "FromPeriodicPort");

//    This physics interface is used to calculate the angle phase matching.
//    In the Model Builder window, under Component 1 (comp1), click Electromagnetic Waves, Frequency Domain 3 (ewfd3).
//    In the Settings window for Electromagnetic Waves, Frequency Domain, locate the Domain Selection section.
//    Click Clear Selection.

    model.component("comp1").physics("ewfd3").selection().set();

//    Select Domains 7, 8.

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

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

    model.component("comp1").physics("ewfd3").create("port1", "Port", 1);

//    Select Boundaries 21, 23.

    model.component("comp1").physics("ewfd3").feature("port1").selection().set(21, 23);

//    In the Settings window for Port, locate the Port Properties section.
//    From the Type of port list, select Numeric.

    model.component("comp1").physics("ewfd3").feature("port1").set("PortType", "Numeric");

//    Right-click Port 1 and choose Duplicate.

    model.component("comp1").physics("ewfd3").feature().duplicate("port2", "port1");

//    In the Settings window for Port, locate the Boundary Selection section.
//    Click Clear Selection.

    model.component("comp1").physics("ewfd3").feature("port2").selection().set();

//    Select Boundaries 26, 27.

    model.component("comp1").physics("ewfd3").feature("port2").selection().set(26, 27);

//    Locate the Port Properties section.
//    From the Wave excitation at this port list, select Off.

    model.component("comp1").physics("ewfd3").feature("port2").set("PortExcitation", "off");

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

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

//    In the Settings window for Mesh, locate the Electromagnetic Waves, Frequency Domain (ewfd) section.
//    Select the Resolve wave in lossy media checkbox.

    model.component("comp1").physics("ewfd").prop("MeshControl").set("ResolveWaveInLossyMedia", true);

//    Locate the Electromagnetic Waves, Frequency Domain 2 (ewfd2) section.
//    Select the Resolve wave in lossy media checkbox.

    model.component("comp1").physics("ewfd2").prop("MeshControl").set("ResolveWaveInLossyMedia", true);

//    Locate the Electromagnetic Waves, Frequency Domain 3 (ewfd3) section.
//    Select the Resolve wave in lossy media checkbox.

    model.component("comp1").physics("ewfd3").prop("MeshControl").set("ResolveWaveInLossyMedia", true);

//    It applies a finer mesh to the lossy media and metal domains to properly resolve the electromagnetic waves.
//    Click Build All.

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

//    In the Model Builder window, click Study 1.
//    In the Settings window for Study, type Study, Otto in the Label text field.

    model.study("std1").label("Study, Otto");

//    In the Model Builder window, under Study, Otto, click Step 1: Wavelength Domain.
//    In the Settings window for Wavelength Domain, locate the Study Settings section.
//    In the Wavelengths text field, type lda0.

    model.study("std1").feature("wave").set("plist", "lda0");
    model.study("std1").feature("wave").setSolveFor("/physics/ewfd2", false);

//    Locate the Physics and Variables Selection section.

    model.study("std1").feature("wave").setSolveFor("/physics/ewfd3", false);

//    In the Solve for column of the table, under Component 1 (comp1), clear the checkboxes for Electromagnetic Waves, Frequency Domain 2 (ewfd2), Electromagnetic Waves, Frequency Domain 3 (ewfd3).
//    . This study simulates the Otto configuration only.
//    Click to expand the Study Extensions section.
//    Select the Auxiliary sweep checkbox.

    model.study("std1").feature("wave").set("useparam", true);

//    Click Add.

    model.study("std1").feature("wave").setIndex("pname_aux", "L", 0);
    model.study("std1").feature("wave").setIndex("plistarr_aux", "", 0);
    model.study("std1").feature("wave").setIndex("punit_aux", "m", 0);
    model.study("std1").feature("wave").setIndex("pname_aux", "L", 0);
    model.study("std1").feature("wave").setIndex("plistarr_aux", "", 0);
    model.study("std1").feature("wave").setIndex("punit_aux", "m", 0);

//    In the table, enter the following settings:

    model.study("std1").feature("wave").setIndex("pname_aux", "angle", 0);

//    In the table, click to select the cell at row number 1 and column number 2.
//    Click Range.

    return model;
  }

  public static Model run2(Model model) {
//    In the Range dialog, type 45 in the Start text field.
//    In the Step text field, type 0.05.
//    In the Stop text field, type 55.
//    Click Add.

    model.study("std1").feature("wave").setIndex("plistarr_aux", "range(45,0.05,55)", 0);

//    In the Settings window for Wavelength Domain, locate the Study Extensions section.
//    In the table, enter the following settings:

    model.study("std1").feature("wave").setIndex("punit_aux", "deg", 0);

//    Add a study to simulate the Kretschmann configuration.
//    In the Study 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 > Wavelength Domain.
//    Right-click and choose Add Study.

    model.study().create("std2");
    model.study("std2").create("wave", "Wavelength");
    model.study("std2").feature("wave").set("ftplistmethod", "manual");
    model.study("std2").feature("wave").set("solnum", "auto");
    model.study("std2").feature("wave").set("notsolnum", "auto");
    model.study("std2").feature("wave").set("outputmap", new String[]{});
    model.study("std2").feature("wave").set("ngenAUX", "1");
    model.study("std2").feature("wave").set("goalngenAUX", "1");
    model.study("std2").feature("wave").set("ngenAUX", "1");
    model.study("std2").feature("wave").set("goalngenAUX", "1");

//    In the Study toolbar, click Add Study to close the Add Study window.
//    In the Settings window for Study, type Study, Kretschmann in the Label text field.

    model.study("std2").label("Study, Kretschmann");

//    In the Model Builder window, under Study, Kretschmann, click Step 1: Wavelength Domain.
//    In the Settings window for Wavelength Domain, locate the Study Settings section.
//    In the Wavelengths text field, type lda0.

    model.study("std2").feature("wave").set("plist", "lda0");
    model.study("std2").feature("wave").setSolveFor("/physics/ewfd", false);

//    Locate the Physics and Variables Selection section.

    model.study("std2").feature("wave").setSolveFor("/physics/ewfd3", false);

//    In the Solve for column of the table, under Component 1 (comp1), clear the checkboxes for Electromagnetic Waves, Frequency Domain (ewfd), Electromagnetic Waves, Frequency Domain 3 (ewfd3).
//    Locate the Study Extensions section.
//    Select the Auxiliary sweep checkbox.

    model.study("std2").feature("wave").set("useparam", true);

//    Click Add.

    model.study("std2").feature("wave").setIndex("pname_aux", "L", 0);
    model.study("std2").feature("wave").setIndex("plistarr_aux", "", 0);
    model.study("std2").feature("wave").setIndex("punit_aux", "m", 0);
    model.study("std2").feature("wave").setIndex("pname_aux", "L", 0);
    model.study("std2").feature("wave").setIndex("plistarr_aux", "", 0);
    model.study("std2").feature("wave").setIndex("punit_aux", "m", 0);

//    In the table, enter the following settings:

    model.study("std2").feature("wave").setIndex("pname_aux", "angle", 0);

//    In the table, click to select the cell at row number 1 and column number 2.
//    Click Range.
//    In the Range dialog, type 45 in the Start text field.
//    In the Step text field, type 0.05.
//    In the Stop text field, type 55.
//    Click Add.

    model.study("std2").feature("wave").setIndex("plistarr_aux", "range(45,0.05,55)", 0);

//    In the Settings window for Wavelength Domain, locate the Study Extensions section.
//    In the table, enter the following settings:

    model.study("std2").feature("wave").setIndex("punit_aux", "deg", 0);

//    Now, add another study to calculate the angle phase matching.
//    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 > Wavelength Domain.
//    Right-click and choose Add Study.

    model.study().create("std3");
    model.study("std3").create("wave", "Wavelength");
    model.study("std3").feature("wave").set("ftplistmethod", "manual");
    model.study("std3").feature("wave").set("solnum", "auto");
    model.study("std3").feature("wave").set("notsolnum", "auto");
    model.study("std3").feature("wave").set("outputmap", new String[]{});
    model.study("std3").feature("wave").set("ngenAUX", "1");
    model.study("std3").feature("wave").set("goalngenAUX", "1");
    model.study("std3").feature("wave").set("ngenAUX", "1");
    model.study("std3").feature("wave").set("goalngenAUX", "1");

//    In the Home toolbar, click Add Study to close the Add Study window.
//    In the Settings window for Study, type Study, Angle Phase Matching in the Label text field.

    model.study("std3").label("Study, Angle Phase Matching");

//    In the Model Builder window, under Study, Angle Phase Matching, click Step 1: Wavelength Domain.
//    In the Settings window for Wavelength Domain, locate the Study Settings section.
//    In the Wavelengths text field, type lda0.

    model.study("std3").feature("wave").set("plist", "lda0");
    model.study("std3").feature("wave").setSolveFor("/physics/ewfd", false);

//    Locate the Physics and Variables Selection section.

    model.study("std3").feature("wave").setSolveFor("/physics/ewfd2", false);

//    In the Study toolbar, click More Study Steps and choose Other > Boundary Mode Analysis.

    model.study("std3").create("bma", "BoundaryModeAnalysis");

//    In the Settings window for Boundary Mode Analysis, locate the Study Settings section.
//    In the Mode analysis frequency text field, type c_const/lda0.

    model.study("std3").feature("bma").set("modeFreq", "c_const/lda0");

//    In the Search for modes around shift text field, type 5.

    model.study("std3").feature("bma").set("shift", "5");
    model.study("std3").feature("bma").setSolveFor("/physics/ewfd", false);

//    Locate the Physics and Variables Selection section.

    model.study("std3").feature("bma").setSolveFor("/physics/ewfd2", false);

//    In the Solve for column of the table, under Component 1 (comp1), clear the checkboxes for Electromagnetic Waves, Frequency Domain (ewfd), Electromagnetic Waves, Frequency Domain 2 (ewfd2).
//    Right-click Step 2: Boundary Mode Analysis and choose Duplicate.

    model.study("std3").feature().duplicate("bma1", "bma");

//    In the Settings window for Boundary Mode Analysis, locate the Study Settings section.
//    In the Port name text field, type 2.

    model.study("std3").feature("bma1").set("PortName", "2");

//    In the Model Builder window, under Study, Angle Phase Matching, Ctrl-click to select Step 2: Boundary Mode Analysis, Step 3: Boundary Mode Analysis 1.
//    Drag and drop above Step 3: Wavelength Domain.

    model.study("std3").feature().move("bma", 0);
    model.study("std3").feature().move("bma1", 1);

//    In the Study toolbar, click Parametric Sweep.

    model.study("std3").create("param", "Parametric");

//    In the Settings window for Parametric Sweep, locate the Study Settings section.
//    Click Add.

    model.study("std3").feature("param").setIndex("pname", "L", 0);
    model.study("std3").feature("param").setIndex("plistarr", "", 0);
    model.study("std3").feature("param").setIndex("punit", "m", 0);
    model.study("std3").feature("param").setIndex("pname", "L", 0);
    model.study("std3").feature("param").setIndex("plistarr", "", 0);
    model.study("std3").feature("param").setIndex("punit", "m", 0);

//    In the table, enter the following settings:

    model.study("std3").feature("param").setIndex("pname", "lda0", 0);
    model.study("std3").feature("param").setIndex("plistarr", "range(330,15,375) range(400,25,675)", 0);
    model.study("std3").feature("param").setIndex("punit", "nm", 0);

//    First, simulate the Otto configuration.
//    In the Study toolbar, click Compute.

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

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

    model.result().create("pg1", "PlotGroup2D");
    model.result("pg1").set("data", "dset1");
    model.result("pg1").setIndex("looplevel", 201, 0);
    model.result("pg1").setIndex("looplevel", 1, 1);
    model.result("pg1").create("surf1", "Surface");
    model.result("pg1").feature("surf1").set("expr", "ewfd.normE");
    model.result("pg1").feature("surf1").set("descr", "Electric field norm");
    model.result("pg1").set("showlegendsmaxmin", true);
    model.result("pg1").feature("surf1").set("colortable", "RainbowLight");
    model.result("pg1").label("Electric Field (ewfd)");
    model.result().create("pg2", "PlotGroup1D");
    model.result("pg2").set("data", "dset1");
    model.result("pg2").create("glob1", "Global");
    model.result("pg2").feature("glob1").set("unit", new String[]{"", "", "", ""});
    model.result("pg2").feature("glob1")
         .set("expr", new String[]{"ewfd.Rorder_0", "ewfd.Torder_0", "ewfd.RTtotal", "ewfd.Atotal"});
    model.result("pg2").feature("glob1")
         .set("descr", new String[]{"Reflectance, order 0", "Transmittance, order 0", "Total reflectance and transmittance", "Absorptance"});
    model.result("pg2").label("Reflectance, Transmittance, and Absorptance (ewfd)");
    model.result("pg2").feature("glob1").set("titletype", "none");
    model.result("pg2").feature("glob1").set("xdata", "expr");
    model.result("pg2").set("ylabelactive", true);
    model.result("pg2").set("ylabel", "Reflectance, transmittance, and absorptance (1)");
    model.result("pg2").feature("glob1").set("xdataexpr", "angle");
    model.result("pg2").feature("glob1").set("xdataunit", "deg");
    model.result("pg2").feature("glob1").set("markerpos", "datapoints");
    model.result("pg2").feature("glob1").set("xdatasolnumtype", "all");
    model.result().create("pg3", "PlotGroup1D");
    model.result("pg3").label("Polarization Plot (ewfd)");
    model.result("pg3").set("data", "dset1");
    model.result("pg3").set("titletype", "manual");
    model.result("pg3").set("title", "Polarization states, Color: Phase (Radians)");
    model.result("pg3").setIndex("looplevelinput", "manual", 0);
    model.result("pg3").setIndex("looplevelinput", "manual", 1);
    model.result("pg3").setIndex("looplevel", "1", 0);
    model.result("pg3").setIndex("looplevel", "1", 1);
    model.result("pg3").create("plz1", "Polarization");
    model.result("pg3").feature("plz1").set("normalization", "allorders");
    model.result("pg3").feature("plz1").set("linestyle", "dotted");
    model.result("pg3").feature("plz1").set("linewidth", 2);
    model.result("pg3").feature("plz1").set("display", "2");
    model.result("pg3").feature("plz1").create("col1", "Color");
    model.result("pg3").feature("plz1").feature("col1").set("colortable", "Cyclic");
    model.result("pg3").feature("plz1").feature("col1").set("colorlegend", true);
    model.result("pg3").feature("plz1").set("legend", true);
    model.result("pg3").feature("plz1").set("legendmethod", "manual");
    model.result("pg3").feature("plz1").setIndex("legends", "Input field", 0);
    model.result("pg3").create("plz2", "Polarization");
    model.result("pg3").feature("plz2").set("normalization", "allorders");
    model.result("pg3").feature("plz2").set("linestyle", "solid");
    model.result("pg3").feature("plz2").set("linewidth", 2);
    model.result("pg3").feature("plz2").set("display", "1");
    model.result("pg3").feature("plz2").create("col1", "Color");
    model.result("pg3").feature("plz2").feature("col1").set("colortable", "Cyclic");
    model.result("pg3").feature("plz2").feature("col1").set("colorlegend", false);
    model.result("pg3").feature("plz2").set("legend", true);
    model.result("pg3").feature("plz2").set("legendmethod", "manual");
    model.result("pg3").feature("plz2").setIndex("legends", "Reflection", 0);
    model.result("pg3").create("plz3", "Polarization");
    model.result("pg3").feature("plz3").set("normalization", "allorders");
    model.result("pg3").feature("plz3").set("linestyle", "dashed");
    model.result("pg3").feature("plz3").set("linewidth", 2);
    model.result("pg3").feature("plz3").set("display", "0");
    model.result("pg3").feature("plz3").create("col1", "Color");
    model.result("pg3").feature("plz3").feature("col1").set("colortable", "Cyclic");
    model.result("pg3").feature("plz3").feature("col1").set("colorlegend", false);
    model.result("pg3").feature("plz3").set("legend", true);
    model.result("pg3").feature("plz3").set("legendmethod", "manual");
    model.result("pg3").feature("plz3").setIndex("legends", "Transmission", 0);
    model.result("pg3").create("lnsg1", "LineSegments");
    model.result("pg3").feature("lnsg1").label("Propagation Limit, Reflection Side");
    model.result("pg3").feature("lnsg1")
         .set("xexpr", new String[]{"ewfd.orderMinR", "ewfd.orderMaxR", "ewfd.orderMaxR", "ewfd.orderMinR", "ewfd.orderMinR"});
    model.result("pg3").feature("lnsg1").set("yexpr", new String[]{"-0.54", "-0.54", "0.54", "0.54", "-0.54"});
    model.result("pg3").feature("lnsg1").set("legend", true);
    model.result("pg3").feature("lnsg1").set("legendmethod", "manual");
    model.result("pg3").feature("lnsg1").setIndex("legends", "Propagation limit, reflection side", 0);
    model.result("pg3").feature("lnsg1").active(false);
    model.result("pg3").create("lnsg2", "LineSegments");
    model.result("pg3").feature("lnsg2").label("Propagation Limit, Transmission Side");
    model.result("pg3").feature("lnsg2")
         .set("xexpr", new String[]{"ewfd.orderMinT", "ewfd.orderMaxT", "ewfd.orderMaxT", "ewfd.orderMinT", "ewfd.orderMinT"});
    model.result("pg3").feature("lnsg2").set("yexpr", new String[]{"-0.55", "-0.55", "0.55", "0.55", "-0.55"});
    model.result("pg3").feature("lnsg2").set("legend", true);
    model.result("pg3").feature("lnsg2").set("legendmethod", "manual");
    model.result("pg3").feature("lnsg2").setIndex("legends", "Propagation limit, transmission side", 0);
    model.result("pg3").feature("lnsg2").active(false);
    model.result("pg1").run();

//    In the Model Builder window, expand the Results > Datasets node, then click Study, Otto/Solution 1 (sol1).
//    In the Results toolbar, click Attributes and choose Selection.
//    In the Settings window for Selection, locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Domain.

    model.result().dataset("dset1").selection().geom("geom1", 2);

//    Select Domains 1, 2, 3.

    model.result().dataset("dset1").selection().geom("geom1", 2);
    model.result().dataset("dset1").selection().set(1, 2, 3);
    model.result("pg1").run();

//    In the Model Builder window, under Results, click Electric Field (ewfd).
//    In the Settings window for 2D Plot Group, locate the Data section.
//    From the Parameter value (angle (deg)) list, select 49.

    model.result("pg1").setIndex("looplevel", 81, 0);

//    . At this angle maximum absorption occurs, as will be shown in the next figure.

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

//    In the Model Builder window, expand the Electric Field (ewfd) node, then click Surface 1.
//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type ewfd.Ey.

    model.result("pg1").feature("surf1").set("expr", "ewfd.Ey");

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

    model.result("pg1").feature("surf1").set("colortable", "Wave");

//    From the Scale list, select Linear symmetric.

    model.result("pg1").feature("surf1").set("colorscalemode", "linearsymmetric");
    model.result("pg1").run();

//    In the Model Builder window, under Results, click Electric Field (ewfd).
//    In the Settings window for 2D Plot Group, type Electric Field, Otto (ewfd) in the Label text field.

    model.result("pg1").label("Electric Field, Otto (ewfd)");

//    Right-click Electric Field, Otto (ewfd) and choose Arrow Line.

    model.result("pg1").create("arwl1", "ArrowLine");
    model.result("pg1").feature("arwl1").set("evaluationsettings", "parent");

//    Plot the incident wave vector at the excitation port.
//    In the Settings window for Arrow Line, locate the Expression section.
//    In the X-component text field, type ewfd.kIncx_1.

    model.result("pg1").feature("arwl1").set("expr", new String[]{"ewfd.kIncx_1", "ewfd.Hy"});

//    In the Y-component text field, type ewfd.kIncy_1.

    model.result("pg1").feature("arwl1").setIndex("expr", "ewfd.kIncy_1", 1);

//    Locate the Arrow Positioning section.
//    In the Number of arrows text field, type 20.

    model.result("pg1").feature("arwl1").set("arrowcount", 20);

//    Locate the Coloring and Style section.
//    Select the Scale factor checkbox.

    model.result("pg1").feature("arwl1").set("scaleactive", true);

//    In the associated text field, type 8E-9.

    model.result("pg1").feature("arwl1").set("scale", "8E-9");

//    Right-click Arrow Line 1 and choose Selection.

    model.result("pg1").feature("arwl1").create("sel1", "Selection");

//    Select Boundary 7.

    model.result("pg1").feature("arwl1").feature("sel1").selection().set(7);
    model.result("pg1").run();

//    In the Model Builder window, right-click Electric Field, Otto (ewfd) and choose Arrow Surface.

    model.result("pg1").create("arws1", "ArrowSurface");
    model.result("pg1").feature("arws1").set("evaluationsettings", "parent");

//    Plot the electric field polarization.
//    In the Settings window for Arrow Surface, locate the Expression section.
//    In the X-component text field, type ewfd.Ex.

    model.result("pg1").feature("arws1").set("expr", new String[]{"ewfd.Ex", "ewfd.Hy"});

//    In the Y-component text field, type ewfd.Ey.

    model.result("pg1").feature("arws1").set("expr", new String[]{"ewfd.Ex", "ewfd.Ey"});

//    Locate the Arrow Positioning section.
//    Find the X grid points subsection.
//    In the Points text field, type 40.

    model.result("pg1").feature("arws1").set("xnumber", 40);

//    Find the Y grid points subsection.
//    In the Points text field, type 40.

    model.result("pg1").feature("arws1").set("ynumber", 40);

//    Locate the Coloring and Style section.
//    Select the Scale factor checkbox.

    model.result("pg1").feature("arws1").set("scaleactive", true);

//    In the associated text field, type 3E-7.

    model.result("pg1").feature("arws1").set("scale", "3E-7");

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

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

//    From the Color list, select Black.

    model.result("pg1").feature("arws1").set("color", "black");

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

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

//    Click the Zoom Extents button in the Graphics toolbar.

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

//    In the Model Builder window, under Results, click Reflectance, Transmittance, and Absorptance (ewfd).
//    In the Settings window for 1D Plot Group, type Reflectance, Transmittance, and SPP Coupling, Otto (ewfd) in the Label text field.

    model.result("pg2").label("Reflectance, Transmittance, and SPP Coupling, Otto (ewfd)");

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

    model.result("pg2").set("legendpos", "middleright");
    model.result("pg2").run();

//    In the Model Builder window, expand the Reflectance, Transmittance, and SPP Coupling, Otto (ewfd) node, then click Global 1.
//    In the Settings window for Global, locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg2").feature("glob1").setIndex("descr", "SPP coupling", 3);

//    In the Reflectance, Transmittance, and SPP Coupling, Otto (ewfd) toolbar, click Plot.

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

//    Visualize the polarization plot.

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

//    In the Model Builder window, under Results, click Polarization Plot (ewfd).
//    In the Settings window for 1D Plot Group, type Polarization Plot, Otto (ewfd) in the Label text field.

    model.result("pg3").label("Polarization Plot, Otto (ewfd)");

//    Locate the Data section.
//    In the Parameter values (angle (deg)) list, select 49.

    model.result("pg3").setIndex("looplevel", new int[]{81}, 0);

//    select 49 in the Parameter values (angle (deg)) list.
//    In the Polarization Plot, Otto (ewfd) toolbar, click Plot.

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

//    Now, simulate the Kretschmann configuration.
//    In the Study toolbar, click Compute.

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

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

    model.result().create("pg4", "PlotGroup2D");
    model.result("pg4").set("data", "dset2");
    model.result("pg4").setIndex("looplevel", 201, 0);
    model.result("pg4").setIndex("looplevel", 1, 1);
    model.result("pg4").create("surf1", "Surface");
    model.result("pg4").feature("surf1").set("expr", "ewfd2.normE");
    model.result("pg4").feature("surf1").set("descr", "Electric field norm");
    model.result("pg4").set("showlegendsmaxmin", true);
    model.result("pg4").feature("surf1").set("colortable", "RainbowLight");
    model.result("pg4").label("Electric Field (ewfd2)");
    model.result().create("pg5", "PlotGroup1D");
    model.result("pg5").set("data", "dset2");
    model.result("pg5").create("glob1", "Global");
    model.result("pg5").feature("glob1").set("unit", new String[]{"", "", "", ""});
    model.result("pg5").feature("glob1")
         .set("expr", new String[]{"ewfd2.Rorder_0", "ewfd2.Torder_0", "ewfd2.RTtotal", "ewfd2.Atotal"});
    model.result("pg5").feature("glob1")
         .set("descr", new String[]{"Reflectance, order 0", "Transmittance, order 0", "Total reflectance and transmittance", "Absorptance"});
    model.result("pg5").label("Reflectance, Transmittance, and Absorptance (ewfd2)");
    model.result("pg5").feature("glob1").set("titletype", "none");
    model.result("pg5").feature("glob1").set("xdata", "expr");
    model.result("pg5").set("ylabelactive", true);
    model.result("pg5").set("ylabel", "Reflectance, transmittance, and absorptance (1)");
    model.result("pg5").feature("glob1").set("xdataexpr", "angle");
    model.result("pg5").feature("glob1").set("xdataunit", "deg");
    model.result("pg5").feature("glob1").set("markerpos", "datapoints");
    model.result("pg5").feature("glob1").set("xdatasolnumtype", "all");
    model.result().create("pg6", "PlotGroup1D");
    model.result("pg6").label("Polarization Plot (ewfd2)");
    model.result("pg6").set("data", "dset2");
    model.result("pg6").set("titletype", "manual");
    model.result("pg6").set("title", "Polarization states, Color: Phase (Radians)");
    model.result("pg6").setIndex("looplevelinput", "manual", 0);
    model.result("pg6").setIndex("looplevelinput", "manual", 1);
    model.result("pg6").setIndex("looplevel", "1", 0);
    model.result("pg6").setIndex("looplevel", "1", 1);
    model.result("pg6").create("plz1", "Polarization");
    model.result("pg6").feature("plz1").set("normalization", "allorders");
    model.result("pg6").feature("plz1").set("linestyle", "dotted");
    model.result("pg6").feature("plz1").set("linewidth", 2);
    model.result("pg6").feature("plz1").set("display", "5");
    model.result("pg6").feature("plz1").create("col1", "Color");
    model.result("pg6").feature("plz1").feature("col1").set("colortable", "Cyclic");
    model.result("pg6").feature("plz1").feature("col1").set("colorlegend", true);
    model.result("pg6").feature("plz1").set("legend", true);
    model.result("pg6").feature("plz1").set("legendmethod", "manual");
    model.result("pg6").feature("plz1").setIndex("legends", "Input field", 0);
    model.result("pg6").create("plz2", "Polarization");
    model.result("pg6").feature("plz2").set("normalization", "allorders");
    model.result("pg6").feature("plz2").set("linestyle", "solid");
    model.result("pg6").feature("plz2").set("linewidth", 2);
    model.result("pg6").feature("plz2").set("display", "4");
    model.result("pg6").feature("plz2").create("col1", "Color");
    model.result("pg6").feature("plz2").feature("col1").set("colortable", "Cyclic");
    model.result("pg6").feature("plz2").feature("col1").set("colorlegend", false);
    model.result("pg6").feature("plz2").set("legend", true);
    model.result("pg6").feature("plz2").set("legendmethod", "manual");
    model.result("pg6").feature("plz2").setIndex("legends", "Reflection", 0);
    model.result("pg6").create("plz3", "Polarization");
    model.result("pg6").feature("plz3").set("normalization", "allorders");
    model.result("pg6").feature("plz3").set("linestyle", "dashed");
    model.result("pg6").feature("plz3").set("linewidth", 2);
    model.result("pg6").feature("plz3").set("display", "3");
    model.result("pg6").feature("plz3").create("col1", "Color");
    model.result("pg6").feature("plz3").feature("col1").set("colortable", "Cyclic");
    model.result("pg6").feature("plz3").feature("col1").set("colorlegend", false);
    model.result("pg6").feature("plz3").set("legend", true);
    model.result("pg6").feature("plz3").set("legendmethod", "manual");
    model.result("pg6").feature("plz3").setIndex("legends", "Transmission", 0);
    model.result("pg6").create("lnsg1", "LineSegments");
    model.result("pg6").feature("lnsg1").label("Propagation Limit, Reflection Side");
    model.result("pg6").feature("lnsg1")
         .set("xexpr", new String[]{"ewfd2.orderMinR", "ewfd2.orderMaxR", "ewfd2.orderMaxR", "ewfd2.orderMinR", "ewfd2.orderMinR"});
    model.result("pg6").feature("lnsg1").set("yexpr", new String[]{"-0.54", "-0.54", "0.54", "0.54", "-0.54"});
    model.result("pg6").feature("lnsg1").set("legend", true);
    model.result("pg6").feature("lnsg1").set("legendmethod", "manual");
    model.result("pg6").feature("lnsg1").setIndex("legends", "Propagation limit, reflection side", 0);
    model.result("pg6").feature("lnsg1").active(false);
    model.result("pg6").create("lnsg2", "LineSegments");
    model.result("pg6").feature("lnsg2").label("Propagation Limit, Transmission Side");
    model.result("pg6").feature("lnsg2")
         .set("xexpr", new String[]{"ewfd2.orderMinT", "ewfd2.orderMaxT", "ewfd2.orderMaxT", "ewfd2.orderMinT", "ewfd2.orderMinT"});
    model.result("pg6").feature("lnsg2").set("yexpr", new String[]{"-0.55", "-0.55", "0.55", "0.55", "-0.55"});
    model.result("pg6").feature("lnsg2").set("legend", true);
    model.result("pg6").feature("lnsg2").set("legendmethod", "manual");
    model.result("pg6").feature("lnsg2").setIndex("legends", "Propagation limit, transmission side", 0);
    model.result("pg6").feature("lnsg2").active(false);
    model.result("pg4").run();

//    In the Model Builder window, under Results > Datasets, click Study, Kretschmann/Solution 2 (sol2).
//    In the Results toolbar, click Attributes and choose Selection.
//    In the Settings window for Selection, locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Domain.

    model.result().dataset("dset2").selection().geom("geom1", 2);

//    Select Domains 4, 5, 6.

    model.result().dataset("dset2").selection().geom("geom1", 2);
    model.result().dataset("dset2").selection().set(4, 5, 6);
    model.result("pg4").run();

//    In the Model Builder window, under Results, click Electric Field (ewfd2).
//    In the Settings window for 2D Plot Group, type Electric Field, Kretschmann (ewfd2) in the Label text field.

    model.result("pg4").label("Electric Field, Kretschmann (ewfd2)");

//    Locate the Data section.
//    From the Parameter value (angle (deg)) list, select 49.

    model.result("pg4").setIndex("looplevel", 81, 0);
    model.result("pg4").run();

//    In the Model Builder window, expand the Electric Field, Kretschmann (ewfd2) node, then click Surface 1.
//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type ewfd2.Ey.

    model.result("pg4").feature("surf1").set("expr", "ewfd2.Ey");

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

    model.result("pg4").feature("surf1").set("colortable", "Wave");

//    From the Scale list, select Linear symmetric.

    model.result("pg4").feature("surf1").set("colorscalemode", "linearsymmetric");
    model.result("pg4").run();

//    In the Model Builder window, right-click Electric Field, Kretschmann (ewfd2) and choose Arrow Line.

    model.result("pg4").create("arwl1", "ArrowLine");
    model.result("pg4").feature("arwl1").set("evaluationsettings", "parent");

//    In the Settings window for Arrow Line, locate the Expression section.
//    In the X-component text field, type ewfd2.kIncx_1.

    model.result("pg4").feature("arwl1").set("expr", new String[]{"ewfd2.kIncx_1", "ewfd.Hy"});

//    In the Y-component text field, type ewfd2.kIncy_1.

    model.result("pg4").feature("arwl1").setIndex("expr", "ewfd2.kIncy_1", 1);

//    Locate the Arrow Positioning section.
//    In the Number of arrows text field, type 20.

    model.result("pg4").feature("arwl1").set("arrowcount", 20);

//    Locate the Coloring and Style section.
//    Select the Scale factor checkbox.

    model.result("pg4").feature("arwl1").set("scaleactive", true);

//    In the associated text field, type 8E-9.

    model.result("pg4").feature("arwl1").set("scale", "8E-9");

//    Right-click Arrow Line 1 and choose Selection.

    model.result("pg4").feature("arwl1").create("sel1", "Selection");

//    Select Boundary 17.

    model.result("pg4").feature("arwl1").feature("sel1").selection().set(17);
    model.result("pg4").run();

//    In the Model Builder window, right-click Electric Field, Kretschmann (ewfd2) and choose Arrow Surface.

    model.result("pg4").create("arws1", "ArrowSurface");
    model.result("pg4").feature("arws1").set("evaluationsettings", "parent");

//    In the Settings window for Arrow Surface, locate the Expression section.
//    In the X-component text field, type ewfd2.Ex.

    model.result("pg4").feature("arws1").set("expr", new String[]{"ewfd2.Ex", "ewfd.Hy"});

//    In the Y-component text field, type ewfd2.Ey.

    model.result("pg4").feature("arws1").set("expr", new String[]{"ewfd2.Ex", "ewfd2.Ey"});

//    Locate the Arrow Positioning section.
//    Find the X grid points subsection.
//    In the Points text field, type 40.

    model.result("pg4").feature("arws1").set("xnumber", 40);

//    Find the Y grid points subsection.
//    In the Points text field, type 40.

    model.result("pg4").feature("arws1").set("ynumber", 40);

//    Locate the Coloring and Style section.
//    Select the Scale factor checkbox.

    model.result("pg4").feature("arws1").set("scaleactive", true);

//    In the associated text field, type 3E-7.

    model.result("pg4").feature("arws1").set("scale", "3E-7");

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

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

//    From the Color list, select Black.

    model.result("pg4").feature("arws1").set("color", "black");

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

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

//    Click the Zoom Extents button in the Graphics toolbar.

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

//    In the Model Builder window, under Results, click Reflectance, Transmittance, and Absorptance (ewfd2).
//    In the Settings window for 1D Plot Group, type Reflectance, Transmittance, and SPP Coupling, Kretschmann (ewfd2) in the Label text field.

    model.result("pg5").label("Reflectance, Transmittance, and SPP Coupling, Kretschmann (ewfd2)");

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

    model.result("pg5").set("legendpos", "middleright");
    model.result("pg5").run();

//    In the Model Builder window, expand the Reflectance, Transmittance, and SPP Coupling, Kretschmann (ewfd2) node, then click Global 1.
//    In the Settings window for Global, locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg5").feature("glob1").setIndex("descr", "SPP coupling", 3);

    return model;
  }

  public static Model run3(Model model) {

//    In the Reflectance, Transmittance, and SPP Coupling, Kretschmann (ewfd2) toolbar, click Plot.

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

//    Visualize the polarization plot.

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

//    In the Model Builder window, under Results, click Polarization Plot (ewfd2).
//    In the Settings window for 1D Plot Group, type Polarization Plot, Kretschmann (ewfd2) in the Label text field.

    model.result("pg6").label("Polarization Plot, Kretschmann (ewfd2)");

//    Locate the Data section.
//    In the Parameter values (angle (deg)) list, select 49.

    model.result("pg6").setIndex("looplevel", new int[]{81}, 0);

//    select 49 in the Parameter values (angle (deg)) list.
//    In the Polarization Plot, Kretschmann (ewfd2) toolbar, click Plot.

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

//    Now, create a plot of the instantaneous electric field norm for the Otto and the Kretschmann configurations.
//    In the Results toolbar, click 2D Plot Group.

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

//    In the Settings window for 2D Plot Group, type Instantaneous Electric Field Norm in the Label text field.

    model.result("pg7").label("Instantaneous Electric Field Norm");

//    Locate the Data section.
//    From the Parameter value (angle (deg)) list, select 49.

    model.result("pg7").setIndex("looplevel", 81, 0);

//    Right-click Instantaneous Electric Field Norm and choose Surface.

    model.result("pg7").create("surf1", "Surface");
    model.result("pg7").feature("surf1").set("evaluationsettings", "parent");

//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type ewfd.normEi.

    model.result("pg7").feature("surf1").set("expr", "ewfd.normEi");

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

    model.result("pg7").feature("surf1").set("colortable", "GrayBody");
    model.result("pg7").run();

//    In the Model Builder window, right-click Instantaneous Electric Field Norm and choose Arrow Surface.

    model.result("pg7").create("arws1", "ArrowSurface");
    model.result("pg7").feature("arws1").set("evaluationsettings", "parent");

//    In the Settings window for Arrow Surface, locate the Expression section.
//    In the X-component text field, type ewfd.Ex.

    model.result("pg7").feature("arws1").set("expr", new String[]{"ewfd.Ex", "ewfd.Hy"});

//    In the Y-component text field, type ewfd.Ey.

    model.result("pg7").feature("arws1").set("expr", new String[]{"ewfd.Ex", "ewfd.Ey"});

//    Locate the Arrow Positioning section.
//    Find the X grid points subsection.
//    In the Points text field, type 30.

    model.result("pg7").feature("arws1").set("xnumber", 30);

//    Find the Y grid points subsection.
//    In the Points text field, type 30.

    model.result("pg7").feature("arws1").set("ynumber", 30);

//    Locate the Coloring and Style section.
//    Select the Scale factor checkbox.

    model.result("pg7").feature("arws1").set("scaleactive", true);

//    In the associated text field, type 5E-7.

    model.result("pg7").feature("arws1").set("scale", "5E-7");

//    From the Color list, select White.

    model.result("pg7").feature("arws1").set("color", "white");
    model.result("pg7").run();

//    In the Model Builder window, right-click Results > Instantaneous Electric Field Norm > Surface 1 and choose Duplicate.

    model.result("pg7").feature().duplicate("surf2", "surf1");
    model.result("pg7").run();

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

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

//    From the Parameter value (angle (deg)) list, select 49.

    model.result("pg7").feature("surf2").setIndex("looplevel", 81, 0);

//    Locate the Expression section.
//    In the Expression text field, type ewfd2.normEi.

    model.result("pg7").feature("surf2").set("expr", "ewfd2.normEi");

//    Click to expand the Inherit Style section.
//    From the Plot list, select Surface 1.

    model.result("pg7").feature("surf2").set("inheritplot", "surf1");
    model.result("pg7").run();

//    In the Model Builder window, right-click Results > Instantaneous Electric Field Norm > Arrow Surface 1 and choose Duplicate.

    model.result("pg7").feature().duplicate("arws2", "arws1");
    model.result("pg7").run();

//    In the Settings window for Arrow Surface, locate the Data section.
//    From the Dataset list, select Study, Kretschmann/Solution 2 (sol2).

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

//    From the Parameter value (angle (deg)) list, select 49.

    model.result("pg7").feature("arws2").setIndex("looplevel", 81, 0);

//    Locate the Expression section.
//    In the X-component text field, type ewfd2.Ex.

    model.result("pg7").feature("arws2").set("expr", new String[]{"ewfd2.Ex", "ewfd.Ey"});

//    In the Y-component text field, type ewfd2.Ey.

    model.result("pg7").feature("arws2").set("expr", new String[]{"ewfd2.Ex", "ewfd2.Ey"});

//    In the Instantaneous Electric Field Norm toolbar, click Plot.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    Now, simulate to calculate the angle phase matching.
//    In the Study toolbar, click Compute.

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

    model.sol().create("sol6");
    model.sol("sol6").study("std3");
    model.sol("sol6").label("Parametric Solutions 1");

    model.batch("p1").feature("so1").set("psol", "sol6");
    model.batch("p1").run("compute");

    model.result().create("pg8", "PlotGroup2D");
    model.result("pg8").set("data", "dset6");
    model.result("pg8").setIndex("looplevel", 1, 0);
    model.result("pg8").setIndex("looplevel", 16, 1);
    model.result("pg8").create("surf1", "Surface");
    model.result("pg8").feature("surf1").set("expr", "ewfd3.normE");
    model.result("pg8").feature("surf1").set("descr", "Electric field norm");
    model.result("pg8").set("showlegendsmaxmin", true);
    model.result("pg8").feature("surf1").set("colortable", "RainbowLight");
    model.result("pg8").label("Electric Field (ewfd3)");
    model.result().create("pg9", "PlotGroup1D");
    model.result("pg9").set("data", "dset6");
    model.result("pg9").create("glob1", "Global");
    model.result("pg9").feature("glob1").set("unit", new String[]{"", "", "", ""});
    model.result("pg9").feature("glob1")
         .set("expr", new String[]{"ewfd3.Rport_1", "ewfd3.Tport_2", "ewfd3.RTtotal", "ewfd3.Atotal"});
    model.result("pg9").feature("glob1")
         .set("descr", new String[]{"Reflectance, port 1", "Transmittance, port 2", "Total reflectance and transmittance", "Absorptance"});
    model.result("pg9").label("Reflectance, Transmittance, and Absorptance (ewfd3)");
    model.result("pg9").feature("glob1").set("titletype", "none");
    model.result("pg9").feature("glob1").set("xdata", "expr");
    model.result("pg9").set("ylabelactive", true);
    model.result("pg9").set("ylabel", "Reflectance, transmittance, and absorptance (1)");
    model.result("pg9").feature("glob1").set("xdataexpr", "lda0");
    model.result("pg9").feature("glob1").set("xdataunit", "nm");
    model.result("pg9").feature("glob1").set("markerpos", "datapoints");
    model.result("pg9").feature("glob1").set("xdatasolnumtype", "all");
    model.result().create("pg10", "PlotGroup2D");
    model.result("pg10").label("Electric Mode Field, Port 1 (ewfd3)");
    model.result("pg10").set("showlegendsmaxmin", true);
    model.result("pg10").set("data", "dset6");
    model.result("pg10").create("line1", "Line");
    model.result("pg10").feature("line1").set("expr", "root.comp1.ewfd3.normEbm_1");
    model.result("pg10").feature("line1").set("colortable", "RainbowLight");
    model.result("pg10").feature("line1").set("linetype", "tube");
    model.result("pg10").feature("line1").create("hght1", "Height");
    model.result().create("pg11", "PlotGroup2D");
    model.result("pg11").label("Electric Mode Field, Port 2 (ewfd3)");
    model.result("pg11").set("showlegendsmaxmin", true);
    model.result("pg11").set("data", "dset6");
    model.result("pg11").create("line1", "Line");
    model.result("pg11").feature("line1").set("expr", "root.comp1.ewfd3.normEbm_2");
    model.result("pg11").feature("line1").set("colortable", "RainbowLight");
    model.result("pg11").feature("line1").set("linetype", "tube");
    model.result("pg11").feature("line1").create("hght1", "Height");
    model.result("pg8").run();

//    In the Model Builder window, under Results > Datasets, click Study, Angle Phase Matching/Parametric Solutions 1 (sol6).
//    In the Results toolbar, click Attributes and choose Selection.
//    In the Settings window for Selection, locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Domain.

    model.result().dataset("dset6").selection().geom("geom1", 2);

//    Select Domains 7, 8.

    model.result().dataset("dset6").selection().geom("geom1", 2);
    model.result().dataset("dset6").selection().set(7, 8);

//    Create a plot of the electric field to visualize the surface plasmon polariton wave.

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

//    In the Model Builder window, under Results, click Electric Field (ewfd3).
//    In the Settings window for 2D Plot Group, locate the Data section.
//    From the Parameter value (lda0 (nm)) list, select 500.

    model.result("pg8").set("looplevel", new int[]{1, 9});
    model.result("pg8").run();

//    In the Model Builder window, expand the Electric Field (ewfd3) node, then click Surface 1.
//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type ewfd3.Ey.

    model.result("pg8").feature("surf1").set("expr", "ewfd3.Ey");

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

    model.result("pg8").feature("surf1").set("colortable", "Wave");

//    From the Scale list, select Linear symmetric.

    model.result("pg8").feature("surf1").set("colorscalemode", "linearsymmetric");

//    Now, add the electric field polarization.

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

//    In the Model Builder window, right-click Electric Field (ewfd3) and choose Arrow Surface.

    model.result("pg8").create("arws1", "ArrowSurface");
    model.result("pg8").feature("arws1").set("evaluationsettings", "parent");

//    In the Settings window for Arrow Surface, locate the Expression section.
//    In the X-component text field, type ewfd3.Ex.

    model.result("pg8").feature("arws1").set("expr", new String[]{"ewfd3.Ex", "ewfd.Hy"});

//    In the Y-component text field, type ewfd3.Ey.

    model.result("pg8").feature("arws1").set("expr", new String[]{"ewfd3.Ex", "ewfd3.Ey"});

//    Locate the Arrow Positioning section.
//    Find the X grid points subsection.
//    In the Points text field, type 40.

    model.result("pg8").feature("arws1").set("xnumber", 40);

//    Find the Y grid points subsection.
//    In the Points text field, type 40.

    model.result("pg8").feature("arws1").set("ynumber", 40);

//    Locate the Coloring and Style section.
//    Select the Scale factor checkbox.

    model.result("pg8").feature("arws1").set("scaleactive", true);

//    In the associated text field, type 2E-6.

    model.result("pg8").feature("arws1").set("scale", "2E-6");

//    From the Color list, select Black.

    model.result("pg8").feature("arws1").set("color", "black");

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

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

//    Create a plot of the reflectance, transmittance, and SPP coupling versus the wavelength.

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

//    In the Model Builder window, under Results, click Reflectance, Transmittance, and Absorptance (ewfd3).
//    In the Settings window for 1D Plot Group, type Reflectance, Transmittance, and SPP Coupling (ewfd3) in the Label text field.

    model.result("pg9").label("Reflectance, Transmittance, and SPP Coupling (ewfd3)");

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

    model.result("pg9").set("legendpos", "middleright");
    model.result("pg9").run();

//    In the Model Builder window, expand the Reflectance, Transmittance, and SPP Coupling (ewfd3) node, then click Global 1.
//    In the Settings window for Global, locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg9").feature("glob1").setIndex("descr", "SPP Coupling", 3);

//    In the Reflectance, Transmittance, and SPP Coupling (ewfd3) toolbar, click Plot.

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

//    Visualize the port mode field.

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

//    In the Model Builder window, under Results, click Electric Mode Field, Port 1 (ewfd3).
//    In the Settings window for 2D Plot Group, locate the Data section.
//    From the Parameter value (lda0 (nm)) list, select 500.

    model.result("pg10").set("looplevel", new int[]{1, 9});

//    In the Electric Mode Field, Port 1 (ewfd3) toolbar, click Plot.

    model.result("pg10").run();
    model.result("pg11").run();

//    In the Model Builder window, click Electric Mode Field, Port 2 (ewfd3).
//    In the Settings window for 2D Plot Group, locate the Data section.
//    From the Parameter value (lda0 (nm)) list, select 500.

    model.result("pg11").set("looplevel", new int[]{1, 9});

//    In the Electric Mode Field, Port 2 (ewfd3) toolbar, click Plot.

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

//    In the Results toolbar, click Evaluation Group.

    model.result().evaluationGroup().create("eg1", "EvaluationGroup");

//    In the Settings window for Evaluation Group, locate the Data section.
//    From the Dataset list, select Study, Angle Phase Matching/Parametric Solutions 1 (sol6).

    model.result().evaluationGroup("eg1").set("data", "dset6");

//    In the Evaluation Group 1 toolbar, click More Evaluations and choose Global Evaluation Sweep.

    model.result().evaluationGroup("eg1").create("gevs1", "EvalGlobalSweep");

//    In the Settings window for Global Evaluation Sweep, locate the Data section.
//    From the Dataset list, select Study, Angle Phase Matching/Parametric Solutions 1 (sol6).

    model.result().evaluationGroup("eg1").feature("gevs1").set("data", "dset6");

//    From the Parameter value (lda0 (nm)) list, select 500.

    model.result().evaluationGroup("eg1").feature("gevs1").set("looplevel", new int[]{1, 9});

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

    model.result().evaluationGroup("eg1").feature("gevs1").setIndex("pname", "angle", 0);
    model.result().evaluationGroup("eg1").feature("gevs1").setIndex("plistarr", "range(40,1,60)", 0);
    model.result().evaluationGroup("eg1").feature("gevs1").setIndex("expr", "lda0", 0);

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

    model.result().evaluationGroup("eg1").feature("gevs1").setIndex("expr", "ewfd3.k0*n_prism*sin(angle*pi/180)", 1);
    model.result().evaluationGroup("eg1").feature("gevs1").setIndex("descr", "Tangential wavenumber", 1);
    model.result().evaluationGroup("eg1").feature("gevs1").setIndex("expr", "ewfd3.beta_1", 2);

//    In the Evaluation Group 1 toolbar, click Evaluate.

    model.result().evaluationGroup("eg1").run();

//    Click Table Graph in the window toolbar.

    model.result().create("pg12", "PlotGroup1D");
    model.result("pg12").set("data", "none");
    model.result("pg12").create("tblp1", "Table");
    model.result("pg12").feature("tblp1").set("source", "evaluationgroup");
    model.result("pg12").feature("tblp1").set("evaluationgroup", "eg1");
    model.result("pg12").feature("tblp1").set("linewidth", "preference");
    model.result("pg12").feature("tblp1").set("markerpos", "datapoints");
    model.result("pg12").run();

//    In the Settings window for Table Graph, locate the Data section.
//    From the x-axis data list, select angle.

    model.result("pg12").feature("tblp1").set("xaxisdata", 1);

//    From the Plot columns list, select Manual.

    model.result("pg12").feature("tblp1").set("plotcolumninput", "manual");

//    In the Columns list, select Tangential wavenumber (rad/m), Propagation constant (rad/m).

    model.result("pg12").feature("tblp1").set("plotcolumns", new int[]{3, 4});

//    Click to expand the Legends section.
//    Select the Show legends checkbox.

    model.result("pg12").feature("tblp1").set("legend", true);
    model.result("pg12").run();

//    In the Model Builder window, under Results, click 1D Plot Group 12.
//    In the Settings window for 1D Plot Group, type Angle Phase Matching in the Label text field.

    model.result("pg12").label("Angle Phase Matching");

//    Locate the Plot Settings section.
//    Select the x-axis label checkbox.

    model.result("pg12").set("xlabelactive", true);

//    In the associated text field, type angle [deg].

    model.result("pg12").set("xlabel", "angle [deg]");

//    Select the y-axis label checkbox.

    model.result("pg12").set("ylabelactive", true);

//    In the associated text field, type Wavenumber [rad/m].

    model.result("pg12").set("ylabel", "Wavenumber [rad/m]");

//    In the Angle Phase Matching toolbar, click Plot.

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

    model.title("Surface Plasmon Polariton Excitation via Otto and Kretschmann Configurations");

    model
         .description("This example demonstrates a simulation setup for exciting surface plasmon polaritons using Otto and Kretschmann configurations. The underlying mechanism is enabled by the interplay between total internal reflection and evanescent-wave coupling phenomena. It also calculates the reflectance, transmittance, and absorptance to analyze the surface plasmon resonance condition.");

    return model;
  }

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

}
