/*
 * brewster_interface.java
 */

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

/** Model exported on May 12 2026, 09:00 by COMSOL 6.4.0.418. */
public class brewster_interface {

  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 2D.
//    In the Select Physics tree, select Optics > Wave Optics > Electromagnetic Waves, Beam Envelopes (ewbe).
//    Click Add.
//    Click Study.
//    In the Select Study tree, select General Studies > Frequency Domain.
//    Click Done.

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

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

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

    model.component("comp1").physics().create("ewbe", "ElectromagneticWavesBeamEnvelopes", "geom1");

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

//    The parameters for the model will be read from a file.
//    In the Model Builder window, under Global Definitions, click Parameters 1.
//    In the Settings window for Parameters, locate the Parameters section.
//    Click Load from File.
//    Browse to the model's Application Library folder and double-click the file brewster_interface.txt.
//    To import content from file, use:
//    model.param().loadFile("FILENAME");
    model.param().set("lda0", "1[um]", "Wavelength");
    model.param().set("f0", "c_const/lda0", "Frequency");
    model.param().set("w0", "10*lda0", "Spot radius");
    model.param().set("z0", "pi*w0^2/lda0", "Rayleigh range");
    model.param().set("alpha", "atan(n2)", "Angle of incidence (at Brewster angle)");
    model.param().set("a", "6*w0", "Width");
    model.param().set("b", "n2*a", "Propagation length");
    model.param().set("n2", "1.5", "Refractive index");
    model.param().set("alpha2", "asin(sin(alpha)/n2)", "Refracted angle");
    model.param().set("k0", "2*pi/lda0", "Wave number in air");
    model.param().set("k1x_air", "k0", "Wave vector in air, first wave, x-component");
    model.param().set("k1y_air", "0[1/m]", "Wave vector in air, first wave, y-component");
    model.param().set("k2x_air", "-k0*cos(2*alpha)", "Wave vector in air, second wave, x-component");
    model.param().set("k2y_air", "-k0*sin(2*alpha)", "Wave vector in air, second wave, y-component");
    model.param().set("k1x_glass", "k0*n2*cos(alpha-alpha2)", "Wave vector in glass, first wave, x-component");
    model.param().set("k1y_glass", "k0*n2*sin(alpha-alpha2)", "Wave vector in glass, first wave, y-component");
    model.param().set("k2x_glass", "-k0*n2*cos(alpha+alpha2)", "Wave vector in glass, second wave, x-component");
    model.param().set("k2y_glass", "-k0*n2*sin(alpha+alpha2)", "Wave vector in glass, second wave, y-component");

//    Define the geometry as a rectangle with a diagonal boundary.
//    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 b.

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

//    In the Height text field, type a.

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

//    In the Geometry toolbar, click More Primitives and choose Line Segment.

    model.component("comp1").geom("geom1").run("r1");
    model.component("comp1").geom("geom1").create("ls1", "LineSegment");

//    On the object r1, select Point 4.

    model.component("comp1").geom("geom1").feature("ls1").selection("vertex1").set("r1", 4);

//    In the Settings window for Line Segment, locate the Endpoint section.
//    Select the Activate Selection toggle button for End vertex.
//    On the object r1, select Point 2.

    model.component("comp1").geom("geom1").feature("ls1").selection("vertex2").set("r1", 2);

//    Click Build All Objects.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Home toolbar, click Add Material to open the Add Material window.
//    The leftmost part consists of air and the rightmost part will be glass.
//    In the tree, select Built-in > Air.
//    Click Add to Component in the window toolbar.

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

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

//    In the Home toolbar, click Add Material to close the Add Material window.
//    In the Model Builder window, right-click Component 1 (comp1) > Materials and choose Blank Material.

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

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

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

//    Select Domain 2.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    Define the refractive index for glass, using the parameter <c>n2</c>.
//    Locate the Material Contents section.
//    In the table, enter the following settings:

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

//    Set up expressions for the wave vector components for the two waves, with different expressions in the two domains.
//    In the Model Builder window, right-click Component 1 (comp1) > Definitions and choose Variables.

    model.component("comp1").variable().create("var1");

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

    model.component("comp1").variable("var1").selection().geom("geom1", 2);

//    Select Domain 1.

    model.component("comp1").variable("var1").selection().set(1);

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

    model.component("comp1").variable("var1").set("k1x", "k1x_air");
    model.component("comp1").variable("var1").descr("k1x", "Wave vector, first wave, x-component");
    model.component("comp1").variable("var1").set("k1y", "k1y_air");
    model.component("comp1").variable("var1").descr("k1y", "Wave vector, first wave, y-component");
    model.component("comp1").variable("var1").set("k2x", "k2x_air");
    model.component("comp1").variable("var1").descr("k2x", "Wave vector, second wave, x-component");
    model.component("comp1").variable("var1").set("k2y", "k2y_air");
    model.component("comp1").variable("var1").descr("k2y", "Wave vector, second wave, y-component");

//    In the Definitions toolbar, click Local Variables.

    model.component("comp1").variable().create("var2");

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

    model.component("comp1").variable("var2").selection().geom("geom1", 2);

//    Select Domain 2.

    model.component("comp1").variable("var2").selection().set(2);

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

    model.component("comp1").variable("var2").set("k1x", "k1x_glass", "Wave vector, first wave, x-component");
    model.component("comp1").variable("var2").set("k1y", "k1y_glass", "Wave vector, first wave, y-component");
    model.component("comp1").variable("var2").set("k2x", "k2x_glass", "Wave vector, second wave, x-component");
    model.component("comp1").variable("var2").set("k2y", "k2y_glass", "Wave vector, second wave, y-component");

//    In the Model Builder window, under Component 1 (comp1), click Electromagnetic Waves, Beam Envelopes (ewbe).
//    In the Settings window for Electromagnetic Waves, Beam Envelopes, locate the Components section.
//    From the Electric field components solved for list, select Out-of-plane vector.

    model.component("comp1").physics("ewbe").prop("components").set("components", "outofplane");

//    Locate the Wave Vectors section.
//    Specify the \[\mathbf{k}_\textrm{1}\] vector as

    model.component("comp1").physics("ewbe").prop("WaveVector").set("k1", new String[]{"k1x", "k1y", "0"});
    model.component("comp1").physics("ewbe").prop("WaveVector").set("k2", new String[]{"k2x", "ewbe.k1y", "0"});

//    Specify the \[\mathbf{k}_\textrm{2}\] vector as

    model.component("comp1").physics("ewbe").prop("WaveVector").set("k2", new String[]{"k2x", "k2y", "0"});

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

    model.component("comp1").physics("ewbe").create("mbc1", "MatchedBoundaryCondition", 1);

//    Select Boundary 1.

    model.component("comp1").physics("ewbe").feature("mbc1").selection().set(1);

//    In the Settings window for Matched Boundary Condition, locate the Matched Boundary Condition section.
//    From the Incident field list, select Gaussian beam.

    model.component("comp1").physics("ewbe").feature("mbc1").set("IncidentField", "GaussianBeam");

//    In the \[w_0\] text field, type w0.

    model.component("comp1").physics("ewbe").feature("mbc1").set("w0", "w0");

//    Specify the \[\mathbf{E}_{\textrm{g0}}\] vector as

    model.component("comp1").physics("ewbe").feature("mbc1").set("Eg0", new String[]{"0", "0", "1[V/m]"});

//    On this boundary, only an incident field is expected, but there should not be any scattered field. Thus, provide that information, with the following setting, to avoid any potential spurious solutions.
//    Find the Scattered field subsection.
//    Select the No scattered field checkbox.

    model.component("comp1").physics("ewbe").feature("mbc1").set("NoScatteredField", true);

//    On the rightmost boundary, a transmitted Gaussian beam, propagating at an angle to the boundary normal, is expected. Thus, add a Matched Boundary Condition feature that will absorb this transmitted Gaussian beam.
//    In the Physics toolbar, click Boundaries and choose Matched Boundary Condition.

    model.component("comp1").physics("ewbe").create("mbc2", "MatchedBoundaryCondition", 1);

//    Select Boundaries 4, 5.

    model.component("comp1").physics("ewbe").feature("mbc2").selection().set(4, 5);

//    In the Settings window for Matched Boundary Condition, locate the Matched Boundary Condition section.
//    From the Input wave list, select Second wave.

    model.component("comp1").physics("ewbe").feature("mbc2").set("InputWave", "SecondWave");

//    The reflected wave, propagating toward the bottom boundary, will also propagate at an angle to the normal to the bottom boundary. Thus, add a Matched Boundary Condition feature here, too, to absorb the reflected beam.
//    In the Physics toolbar, click Boundaries and choose Matched Boundary Condition.

    model.component("comp1").physics("ewbe").create("mbc3", "MatchedBoundaryCondition", 1);

//    Select Boundary 2.

    model.component("comp1").physics("ewbe").feature("mbc3").selection().set(2);

//    Set up integration operators to calculate the power of the incident, reflected, and transmitted beams.
//    In the Definitions toolbar, click Nonlocal Couplings and choose Integration.

    model.component("comp1").cpl().create("intop1", "Integration");
    model.component("comp1").cpl("intop1").set("axisym", true);

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

    model.component("comp1").cpl("intop1").selection().geom("geom1", 1);

//    Select Boundary 1.

    model.component("comp1").cpl("intop1").selection().set(1);

//    In the Definitions toolbar, click Nonlocal Couplings and choose Integration.

    model.component("comp1").cpl().create("intop2", "Integration");
    model.component("comp1").cpl("intop2").set("axisym", true);

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

    model.component("comp1").cpl("intop2").selection().geom("geom1", 1);

//    Select Boundaries 4, 5.

    model.component("comp1").cpl("intop2").selection().set(4, 5);

//    In the Definitions toolbar, click Nonlocal Couplings and choose Integration.

    model.component("comp1").cpl().create("intop3", "Integration");
    model.component("comp1").cpl("intop3").set("axisym", true);

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

    model.component("comp1").cpl("intop3").selection().geom("geom1", 1);

//    Select Boundary 2.

    model.component("comp1").cpl("intop3").selection().set(2);

//    Now, define the power variables for the beams, using the previously defined integration operators.
//    In the Model Builder window, right-click Definitions and choose Variables.

    model.component("comp1").variable().create("var3");

//    In the Settings window for Variables, locate the Variables section.
//    In the table, enter the following settings:

    model.component("comp1").variable("var3").set("Pin", "-intop1(ewbe.nPoav)");
    model.component("comp1").variable("var3").descr("Pin", "Input power");
    model.component("comp1").variable("var3").set("Pt", "intop2(ewbe.nPoav)");
    model.component("comp1").variable("var3").descr("Pt", "Transmitted power");
    model.component("comp1").variable("var3").set("Pr", "intop3(ewbe.nPoav)");
    model.component("comp1").variable("var3").descr("Pr", "Reflected power");

//    The minus sign for the input power is used as the power flow and the boundary normal point in the opposite directions.
//    Let the physics define a triangular mesh where the maximum mesh element size is set to half a wavelength, to resolve the interference pattern created by the incident and the reflected beam.
//    In the Model Builder window, under Component 1 (comp1), click Mesh 1.
//    In the Settings window for Mesh, locate the Electromagnetic Waves, Beam Envelopes (ewbe) section.
//    From the Mesh type list, select Triangular mesh.

    model.component("comp1").physics("ewbe").prop("MeshControl").set("MeshType", "Triangular");

//    In the \[h_{\mathrm{max}}\] text field, type lda0/2.

    model.component("comp1").physics("ewbe").prop("MeshControl").set("hMax", "lda0/2");

//    Define the frequency and compute the solution for the model.
//    In the Model Builder window, under Study 1, click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Study Settings section.
//    In the Frequencies text field, type f0.

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

//    In the Study toolbar, click Compute.

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

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

    model.result().create("pg1", "PlotGroup2D");
    model.result("pg1").set("data", "dset1");
    model.result("pg1").setIndex("looplevel", 1, 0);
    model.result("pg1").create("surf1", "Surface");
    model.result("pg1").feature("surf1").set("expr", new String[]{"ewbe.normE1"});
    model.result("pg1").feature("surf1").label("Electric Field");
    model.result("pg1").feature("surf1").set("colortable", "RainbowLight");
    model.result("pg1").label("Electric Field, First Wave (ewbe)");
    model.result().create("pg2", "PlotGroup2D");
    model.result("pg2").set("data", "dset1");
    model.result("pg2").setIndex("looplevel", 1, 0);
    model.result("pg2").create("surf1", "Surface");
    model.result("pg2").feature("surf1").set("expr", new String[]{"ewbe.normE2"});
    model.result("pg2").feature("surf1").label("Electric Field");
    model.result("pg2").feature("surf1").set("colortable", "RainbowLight");
    model.result("pg2").label("Electric Field, Second Wave (ewbe)");
    model.result("pg1").run();

//    This is the electric field norm of the first wave for s-polarization.

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

//    In the Model Builder window, click Electric Field, Second Wave (ewbe).
//    This is the electric field norm of the second wave for s-polarization.
//    Right-click Electric Field, Second Wave (ewbe) and choose Duplicate.

    model.result().duplicate("pg3", "pg2");
    model.result("pg3").run();

//    In the Settings window for 2D Plot Group, type Electric Field (ewbe) in the Label text field.

    model.result("pg3").label("Electric Field (ewbe)");
    model.result("pg3").run();

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

    model.result("pg3").feature("surf1").set("expr", "ewbe.normE");

//    To really resolve the inference pattern to the left of the air-glass interface, set the resolution to extra fine.
//    Click to expand the Quality section.
//    From the Evaluation settings list, select Manual.
//    From the Resolution list, select Extra fine.

    model.result("pg3").feature("surf1").set("resolution", "extrafine");

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

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    . Compare your result with the plot below.
//    Using the defined variables, compute the reflectance.
//    In the Results toolbar, click Global Evaluation.

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

//    In the Settings window for Global Evaluation, locate the Expressions section.
//    In the table, enter the following settings:

    model.result().numerical("gev1").setIndex("expr", "Pr/Pin", 0);
    model.result().numerical("gev1").setIndex("unit", 1, 0);
    model.result().numerical("gev1").setIndex("descr", "", 0);

//    Click Evaluate.

    model.result().table().create("tbl1", "Table");
    model.result().table("tbl1").comments("Global Evaluation 1");
    model.result().numerical("gev1").set("table", "tbl1");
    model.result().numerical("gev1").setResult();

//    . Compare the calculated reflectance with the theoretical value for s-polarized plane waves. Notice that the values are almost the same.
//    In the Settings window for Global Evaluation, locate the Expressions section.
//    In the table, enter the following settings:

    model.result().numerical("gev1").setIndex("expr", "((1-n2^2)/(1+n2^2))^2", 0);

//    Click Evaluate.

    model.result().numerical("gev1").set("table", "tbl1");
    model.result().numerical("gev1").appendResult();

//    Now check that all incident power is either reflected or transmitted.
//    In the table, enter the following settings:

    model.result().numerical("gev1").setIndex("expr", "(Pr+Pt)/Pin", 0);

//    Click Evaluate.

    model.result().numerical("gev1").set("table", "tbl1");
    model.result().numerical("gev1").appendResult();

//    In this simulation, set the polarization to be in-plane, that is p-polarization. For this case, there should be no reflected beam.
//    In the Model Builder window, under Component 1 (comp1), click Electromagnetic Waves, Beam Envelopes (ewbe).
//    In the Settings window for Electromagnetic Waves, Beam Envelopes, locate the Components section.
//    From the Electric field components solved for list, select In-plane vector.

    model.component("comp1").physics("ewbe").prop("components").set("components", "inplane");

//    In the Model Builder window, under Component 1 (comp1) > Electromagnetic Waves, Beam Envelopes (ewbe), click Matched Boundary Condition 1.
//    In the Settings window for Matched Boundary Condition, locate the Matched Boundary Condition section.
//    Specify the \[\mathbf{E}_{\textrm{g0}}\] vector as

    model.component("comp1").physics("ewbe").feature("mbc1").set("Eg0", new String[]{"0", "1[V/m]", "0"});

//    In the Study toolbar, click Compute.

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

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

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

//    This is the electric field norm of the first wave for p-polarization.

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

//    In the Model Builder window, click Electric Field, Second Wave (ewbe).
//    This is the electric field norm of the second wave for p-polarization. Note that the field amplitude is much smaller than the amplitude for the incident wave.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    . Compare your result with the plot below. Notice that there is no reflected beam in this case.
//    In the Model Builder window, click Electric Field (ewbe).
//    Also check numerically that the reflected wave is almost gone for p-polarization at the Brewster angle.
//    In the Model Builder window, under Results > Derived Values, click Global Evaluation 1.
//    In the Settings window for Global Evaluation, locate the Expressions section.
//    In the table, enter the following settings:

    model.result().numerical("gev1").setIndex("expr", "Pr/Pin", 0);

//    Click Evaluate.

    model.result().numerical("gev1").set("table", "tbl1");
    model.result().numerical("gev1").appendResult();
    model.result("pg3").run();

    model.title("Gaussian Beam Incident at the Brewster Angle");

    model
         .description("This example demonstrates the polarization properties for a Gaussian beam incident at an interface between two media at the Brewster angle. It shows how to use the Electromagnetic Waves, Beam Envelopes interface with a user-defined phase specification. Matched Boundary Condition features are used for absorbing waves incident on boundaries at oblique angles.");

    return model;
  }

  public static void main(String[] args) {
    run();
  }

}
