/*
 * radar_cross_section.java
 */

import com.comsol.model.*;
import com.comsol.model.util.*;

/** Model exported on May 15 2026, 12:34 by COMSOL 6.4.0.421. */
public class radar_cross_section {

  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 Radio Frequency > Electromagnetic Waves, Frequency Domain (emw).
//    Click Add.
//    Click Study.
//    In the Select Study tree, select General Studies > Frequency Domain.
//    Click Done.

    model.component().create("comp1", true);

    model.component("comp1").geom().create("geom1", 2);

    model.component("comp1").mesh().create("mesh1");

    model.component("comp1").physics().create("emw", "ElectromagneticWaves", "geom1");

    model.study().create("std1");
    model.study("std1").create("freq", "Frequency");
    model.study("std1").feature("freq").set("solnum", "auto");
    model.study("std1").feature("freq").set("notsolnum", "auto");
    model.study("std1").feature("freq").set("outputmap", new String[]{});
    model.study("std1").feature("freq").set("ngenAUX", "1");
    model.study("std1").feature("freq").set("goalngenAUX", "1");
    model.study("std1").feature("freq").set("ngenAUX", "1");
    model.study("std1").feature("freq").set("goalngenAUX", "1");

//    Define the study frequency ahead of performing any frequency-dependent operation such as building mesh. The physics-controlled mesh uses the specified frequency value.
//    In the 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 100[MHz].

    model.study("std1").feature("freq").set("plist", "100[MHz]");

//    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("phi", "0[deg]");
    model.param().descr("phi", "Angle of incidence, degrees");
    model.param().set("r0", "12[m]");
    model.param().descr("r0", "Radius, air domain");

//    In the Geometry toolbar, click Circle.

    model.component("comp1").geom("geom1").create("c1", "Circle");

//    In the Settings window for Circle, locate the Size and Shape section.
//    In the Radius text field, type r0+3[m].

    model.component("comp1").geom("geom1").feature("c1").set("r", "r0+3[m]");

//    Click to expand the Layers section.
//    In the table, enter the following settings:

    model.component("comp1").geom("geom1").feature("c1").setIndex("layer", "3[m]", 0);

//    In the Geometry toolbar, click More Primitives and choose Circular Arc.

    model.component("comp1").geom("geom1").run("c1");
    model.component("comp1").geom("geom1").create("ca1", "CircularArc");

//    In the Settings window for Circular Arc, locate the Properties section.
//    From the Specify list, select Endpoints and start angle.

    model.component("comp1").geom("geom1").feature("ca1").set("specify", "endsangle1");

//    Locate the Starting Point section.
//    In the x text field, type 6.

    model.component("comp1").geom("geom1").feature("ca1").set("point1", new double[]{6, 0});

//    Locate the Endpoint section.
//    In the x text field, type 4.

    model.component("comp1").geom("geom1").feature("ca1").set("point2", new double[]{4, 1});

//    In the y text field, type 2.

    model.component("comp1").geom("geom1").feature("ca1").set("point2", new double[]{4, 2});

//    In the Geometry toolbar, click More Primitives and choose Circular Arc.

    model.component("comp1").geom("geom1").run("ca1");
    model.component("comp1").geom("geom1").create("ca2", "CircularArc");

//    In the Settings window for Circular Arc, locate the Properties section.
//    From the Specify list, select Endpoints and start angle.

    model.component("comp1").geom("geom1").feature("ca2").set("specify", "endsangle1");

//    Locate the Starting Point section.
//    In the x text field, type 4.

    model.component("comp1").geom("geom1").feature("ca2").set("point1", new double[]{4, 0});

//    In the y text field, type -2.

    model.component("comp1").geom("geom1").feature("ca2").set("point1", new double[]{4, -2});

//    Locate the Endpoint section.
//    In the x text field, type 6.

    model.component("comp1").geom("geom1").feature("ca2").set("point2", new double[]{6, 1});

//    In the y text field, type 0.

    model.component("comp1").geom("geom1").feature("ca2").set("point2", new double[]{6, 0});

//    Locate the Angles section.
//    In the Start angle text field, type 270.

    model.component("comp1").geom("geom1").feature("ca2").set("angle1", 270);

//    In the Geometry toolbar, click More Primitives and choose Line Segment.

    model.component("comp1").geom("geom1").run("ca2");
    model.component("comp1").geom("geom1").create("ls1", "LineSegment");

//    In the Settings window for Line Segment, locate the Starting Point section.
//    From the Specify list, select Coordinates.

    model.component("comp1").geom("geom1").feature("ls1").set("specify1", "coord");

//    Locate the Endpoint section.
//    From the Specify list, select Coordinates.

    model.component("comp1").geom("geom1").feature("ls1").set("specify2", "coord");

//    Locate the Starting Point section.
//    In the x text field, type -4.

    model.component("comp1").geom("geom1").feature("ls1").set("coord1", new double[]{-4, 0});

//    In the y text field, type -2.

    model.component("comp1").geom("geom1").feature("ls1").set("coord1", new double[]{-4, -2});

//    Locate the Endpoint section.
//    In the x text field, type 4.

    model.component("comp1").geom("geom1").feature("ls1").set("coord2", new double[]{4, 0});

//    In the y text field, type -2.

    model.component("comp1").geom("geom1").feature("ls1").set("coord2", new double[]{4, -2});

//    In the Geometry toolbar, click More Primitives and choose Line Segment.

    model.component("comp1").geom("geom1").run("ls1");
    model.component("comp1").geom("geom1").create("ls2", "LineSegment");

//    In the Settings window for Line Segment, locate the Starting Point section.
//    From the Specify list, select Coordinates.

    model.component("comp1").geom("geom1").feature("ls2").set("specify1", "coord");

//    Locate the Endpoint section.
//    From the Specify list, select Coordinates.

    model.component("comp1").geom("geom1").feature("ls2").set("specify2", "coord");

//    Locate the Starting Point section.
//    In the x text field, type -4.

    model.component("comp1").geom("geom1").feature("ls2").set("coord1", new double[]{-4, 0});

//    In the y text field, type 2.

    model.component("comp1").geom("geom1").feature("ls2").set("coord1", new double[]{-4, 2});

//    Locate the Endpoint section.
//    In the x text field, type 4.

    model.component("comp1").geom("geom1").feature("ls2").set("coord2", new double[]{4, 0});

//    In the y text field, type 2.

    model.component("comp1").geom("geom1").feature("ls2").set("coord2", new double[]{4, 2});

//    In the Geometry toolbar, click More Primitives and choose Quadratic Bézier.

    model.component("comp1").geom("geom1").run("ls2");
    model.component("comp1").geom("geom1").create("qb1", "QuadraticBezier");

//    In the Settings window for Quadratic Bézier, locate the Control Points section.
//    In row 1, set x to -4.

    model.component("comp1").geom("geom1").feature("qb1").setIndex("p", -4, 0, 0);

//     and <l>y</l> to <c>2</c>.

    model.component("comp1").geom("geom1").feature("qb1").setIndex("p", 2, 1, 0);

//    In row 2, set x to -6.

    model.component("comp1").geom("geom1").feature("qb1").setIndex("p", -6, 0, 1);

//     and <l>y</l> to <c>2</c>.&gt;

    model.component("comp1").geom("geom1").feature("qb1").setIndex("p", 2, 1, 1);

//    In row 3, set x to -8.

    model.component("comp1").geom("geom1").feature("qb1").setIndex("p", -8, 0, 2);

//    In the Geometry toolbar, click More Primitives and choose Quadratic Bézier.

    model.component("comp1").geom("geom1").run("qb1");
    model.component("comp1").geom("geom1").create("qb2", "QuadraticBezier");

//    In the Settings window for Quadratic Bézier, locate the Control Points section.
//    In row 1, set x to -8.

    model.component("comp1").geom("geom1").feature("qb2").setIndex("p", -8, 0, 0);

//    In row 2, set x to -6.

    model.component("comp1").geom("geom1").feature("qb2").setIndex("p", -6, 0, 1);

//     and <l>y</l> to <c>-2</c>.

    model.component("comp1").geom("geom1").feature("qb2").setIndex("p", -2, 1, 1);

//    In row 3, set x to -4.

    model.component("comp1").geom("geom1").feature("qb2").setIndex("p", -4, 0, 2);

//     and <l>y</l> to <c>-2</c>.

    model.component("comp1").geom("geom1").feature("qb2").setIndex("p", -2, 1, 2);

//    In the Geometry toolbar, click Conversions and choose Convert to Solid.

    model.component("comp1").geom("geom1").run("qb2");
    model.component("comp1").geom("geom1").create("csol1", "ConvertToSolid");

//    Select the objects ca1, ca2, ls1, ls2, qb1, qb2.

    model.component("comp1").geom("geom1").feature("csol1").selection("input")
         .set("ca1", "ca2", "ls1", "ls2", "qb1", "qb2");

//    In the Definitions toolbar, click Explicit.

    model.component("comp1").selection().create("sel1", "Explicit");

    model.component("comp1").geom("geom1").run();

//    In the Settings window for Explicit, type Boat Boundaries in the Label text field.

    model.component("comp1").selection("sel1").label("Boat Boundaries");

//    Select Domain 4.

    model.component("comp1").selection("sel1").set(4);

//    Locate the Output Entities section.
//    From the Output entities list, select Adjacent boundaries.

    model.component("comp1").selection("sel1").geom("geom1", 2, 1, new String[]{"exterior"});
    model.component("comp1").selection("sel1").set(4);

//    You will select the boundaries of the boat several times throughout this tutorial. The Named Selection you just defined makes this more convenient.
//    In the Definitions toolbar, click Perfectly Matched Layer.

    model.component("comp1").coordSystem().create("pml1", "PML");

//    Select Domains 1, 2, 5, 6.

    model.component("comp1").coordSystem("pml1").selection().set(1, 2, 5, 6);

//    In the Settings window for Perfectly Matched Layer, locate the Geometry section.
//    From the Type list, select Cylindrical.

    model.component("comp1").coordSystem("pml1").set("ScalingType", "Cylindrical");

//    The PML will make sure that the scattered field from the boat is almost completely absorbed before what remains of it reflects on the exterior boundaries of the model. Note that the background field is not affected by any of this - it is by definition what you are setting it to be.
//    In the Materials toolbar, click Add Material to open the Add Material window.
//    In the tree, select Built-in > Air.
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat1", "Common");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("eta", "Piecewise");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("Cp", "Piecewise");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("rho", "Analytic");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("k", "Piecewise");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("cs", "Analytic");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("an1", "Analytic");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("an2", "Analytic");
    model.component("comp1").material("mat1").propertyGroup()
         .create("RefractiveIndex", "RefractiveIndex", "Refractive index");
    model.component("comp1").material("mat1").propertyGroup()
         .create("NonlinearModel", "NonlinearModel", "Nonlinear model");
    model.component("comp1").material("mat1").propertyGroup().create("idealGas", "idealGas", "Ideal gas");
    model.component("comp1").material("mat1").propertyGroup("idealGas").func().create("Cp", "Piecewise");
    model.component("comp1").material("mat1").label("Air");
    model.component("comp1").material("mat1").set("family", "air");
    model.component("comp1").material("mat1").propertyGroup("def").func("eta").set("arg", "T");
    model.component("comp1").material("mat1").propertyGroup("def").func("eta")
         .set("pieces", new String[][]{{"200.0", "1600.0", "-8.38278E-7+8.35717342E-8*T^1-7.69429583E-11*T^2+4.6437266E-14*T^3-1.06585607E-17*T^4"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("eta").set("argunit", "K");
    model.component("comp1").material("mat1").propertyGroup("def").func("eta").set("fununit", "Pa*s");
    model.component("comp1").material("mat1").propertyGroup("def").func("Cp").set("arg", "T");
    model.component("comp1").material("mat1").propertyGroup("def").func("Cp")
         .set("pieces", new String[][]{{"200.0", "1600.0", "1047.63657-0.372589265*T^1+9.45304214E-4*T^2-6.02409443E-7*T^3+1.2858961E-10*T^4"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("Cp").set("argunit", "K");
    model.component("comp1").material("mat1").propertyGroup("def").func("Cp").set("fununit", "J/(kg*K)");
    model.component("comp1").material("mat1").propertyGroup("def").func("rho")
         .set("expr", "pA*0.02897/R_const[K*mol/J]/T");
    model.component("comp1").material("mat1").propertyGroup("def").func("rho").set("args", new String[]{"pA", "T"});
    model.component("comp1").material("mat1").propertyGroup("def").func("rho").set("fununit", "kg/m^3");
    model.component("comp1").material("mat1").propertyGroup("def").func("rho")
         .set("argunit", new String[]{"Pa", "K"});
    model.component("comp1").material("mat1").propertyGroup("def").func("rho")
         .set("plotaxis", new String[]{"off", "on"});
    model.component("comp1").material("mat1").propertyGroup("def").func("rho")
         .set("plotfixedvalue", new String[]{"101325", "273.15"});
    model.component("comp1").material("mat1").propertyGroup("def").func("rho")
         .set("plotargs", new String[][]{{"pA", "101325", "101325"}, {"T", "273.15", "293.15"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("k").set("arg", "T");
    model.component("comp1").material("mat1").propertyGroup("def").func("k")
         .set("pieces", new String[][]{{"200.0", "1600.0", "-0.00227583562+1.15480022E-4*T^1-7.90252856E-8*T^2+4.11702505E-11*T^3-7.43864331E-15*T^4"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("k").set("argunit", "K");
    model.component("comp1").material("mat1").propertyGroup("def").func("k").set("fununit", "W/(m*K)");
    model.component("comp1").material("mat1").propertyGroup("def").func("cs")
         .set("expr", "sqrt(1.4*R_const[K*mol/J]/0.02897*T)");
    model.component("comp1").material("mat1").propertyGroup("def").func("cs").set("args", new String[]{"T"});
    model.component("comp1").material("mat1").propertyGroup("def").func("cs").set("fununit", "m/s");
    model.component("comp1").material("mat1").propertyGroup("def").func("cs").set("argunit", new String[]{"K"});
    model.component("comp1").material("mat1").propertyGroup("def").func("cs")
         .set("plotfixedvalue", new String[]{"273.15"});
    model.component("comp1").material("mat1").propertyGroup("def").func("cs")
         .set("plotargs", new String[][]{{"T", "273.15", "373.15"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("an1").set("funcname", "alpha_p");
    model.component("comp1").material("mat1").propertyGroup("def").func("an1")
         .set("expr", "-1/rho(pA,T)*d(rho(pA,T),T)");
    model.component("comp1").material("mat1").propertyGroup("def").func("an1").set("args", new String[]{"pA", "T"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an1").set("fununit", "1/K");
    model.component("comp1").material("mat1").propertyGroup("def").func("an1")
         .set("argunit", new String[]{"Pa", "K"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an1")
         .set("plotaxis", new String[]{"off", "on"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an1")
         .set("plotfixedvalue", new String[]{"101325", "273.15"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an1")
         .set("plotargs", new String[][]{{"pA", "101325", "101325"}, {"T", "273.15", "373.15"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("an2").set("funcname", "muB");
    model.component("comp1").material("mat1").propertyGroup("def").func("an2").set("expr", "0.6*eta(T)");
    model.component("comp1").material("mat1").propertyGroup("def").func("an2").set("args", new String[]{"T"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an2").set("fununit", "Pa*s");
    model.component("comp1").material("mat1").propertyGroup("def").func("an2").set("argunit", new String[]{"K"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an2")
         .set("plotfixedvalue", new String[]{"200"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an2")
         .set("plotargs", new String[][]{{"T", "200", "1600"}});
    model.component("comp1").material("mat1").propertyGroup("def").set("thermalexpansioncoefficient", "");
    model.component("comp1").material("mat1").propertyGroup("def").set("molarmass", "");
    model.component("comp1").material("mat1").propertyGroup("def").set("bulkviscosity", "");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("thermalexpansioncoefficient", new String[]{"alpha_p(pA,T)", "0", "0", "0", "alpha_p(pA,T)", "0", "0", "0", "alpha_p(pA,T)"});
    model.component("comp1").material("mat1").propertyGroup("def").set("molarmass", "0.02897[kg/mol]");
    model.component("comp1").material("mat1").propertyGroup("def").set("bulkviscosity", "muB(T)");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("relpermeability", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("relpermittivity", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat1").propertyGroup("def").set("dynamicviscosity", "eta(T)");
    model.component("comp1").material("mat1").propertyGroup("def").set("ratioofspecificheat", "1.4");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("electricconductivity", new String[]{"0[S/m]", "0", "0", "0", "0[S/m]", "0", "0", "0", "0[S/m]"});
    model.component("comp1").material("mat1").propertyGroup("def").set("heatcapacity", "Cp(T)");
    model.component("comp1").material("mat1").propertyGroup("def").set("density", "rho(pA,T)");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("thermalconductivity", new String[]{"k(T)", "0", "0", "0", "k(T)", "0", "0", "0", "k(T)"});
    model.component("comp1").material("mat1").propertyGroup("def").set("soundspeed", "cs(T)");
    model.component("comp1").material("mat1").propertyGroup("def").addInput("temperature");
    model.component("comp1").material("mat1").propertyGroup("def").addInput("pressure");
    model.component("comp1").material("mat1").propertyGroup("RefractiveIndex")
         .set("n", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat1").propertyGroup("NonlinearModel").set("BA", "def.gamma-1");
    model.component("comp1").material("mat1").propertyGroup("idealGas").func("Cp").label("Piecewise 2");
    model.component("comp1").material("mat1").propertyGroup("idealGas").func("Cp").set("arg", "T");
    model.component("comp1").material("mat1").propertyGroup("idealGas").func("Cp")
         .set("pieces", new String[][]{{"200.0", "1600.0", "1047.63657-0.372589265*T^1+9.45304214E-4*T^2-6.02409443E-7*T^3+1.2858961E-10*T^4"}});
    model.component("comp1").material("mat1").propertyGroup("idealGas").func("Cp").set("argunit", "K");
    model.component("comp1").material("mat1").propertyGroup("idealGas").func("Cp").set("fununit", "J/(kg*K)");
    model.component("comp1").material("mat1").propertyGroup("idealGas").set("Rs", "R_const/Mn");
    model.component("comp1").material("mat1").propertyGroup("idealGas").set("heatcapacity", "Cp(T)");
    model.component("comp1").material("mat1").propertyGroup("idealGas").set("ratioofspecificheat", "1.4");
    model.component("comp1").material("mat1").propertyGroup("idealGas").set("molarmass", "0.02897[kg/mol]");
    model.component("comp1").material("mat1").propertyGroup("idealGas").addInput("temperature");
    model.component("comp1").material("mat1").propertyGroup("idealGas").addInput("pressure");
    model.component("comp1").material("mat1").materialType("nonSolid");

//    In the tree, select Built-in > Aluminum.
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat2", "Common");
    model.component("comp1").material("mat2").propertyGroup()
         .create("Enu", "Enu", "Young's modulus and Poisson's ratio");
    model.component("comp1").material("mat2").propertyGroup().create("Murnaghan", "Murnaghan", "Murnaghan");
    model.component("comp1").material("mat2").label("Aluminum");
    model.component("comp1").material("mat2").set("family", "aluminum");
    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("heatcapacity", "900[J/(kg*K)]");
    model.component("comp1").material("mat2").propertyGroup("def")
         .set("thermalconductivity", new String[]{"238[W/(m*K)]", "0", "0", "0", "238[W/(m*K)]", "0", "0", "0", "238[W/(m*K)]"});
    model.component("comp1").material("mat2").propertyGroup("def")
         .set("electricconductivity", new String[]{"3.774e7[S/m]", "0", "0", "0", "3.774e7[S/m]", "0", "0", "0", "3.774e7[S/m]"});
    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("thermalexpansioncoefficient", new String[]{"23e-6[1/K]", "0", "0", "0", "23e-6[1/K]", "0", "0", "0", "23e-6[1/K]"});
    model.component("comp1").material("mat2").propertyGroup("def").set("density", "2700[kg/m^3]");
    model.component("comp1").material("mat2").propertyGroup("Enu").set("E", "70[GPa]");
    model.component("comp1").material("mat2").propertyGroup("Enu").set("nu", "0.33");
    model.component("comp1").material("mat2").propertyGroup("Murnaghan").set("l", "-250[GPa]");
    model.component("comp1").material("mat2").propertyGroup("Murnaghan").set("m", "-330[GPa]");
    model.component("comp1").material("mat2").propertyGroup("Murnaghan").set("n", "-350[GPa]");

//    In the Materials toolbar, click Add Material to close the Add Material window.
//    In the Settings window for Material, locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Boundary.

    model.component("comp1").material("mat2").selection().geom("geom1", 1);

//    From the Selection list, select Boat Boundaries.

    model.component("comp1").material("mat2").selection().named("sel1");

//    In the Model Builder window, under Component 1 (comp1), click Electromagnetic Waves, Frequency Domain (emw).
//    Select Domains 1, 2, 3, 5, 6.

    model.component("comp1").physics("emw").selection().set(1, 2, 3, 5, 6);

//    Because you will be using a boundary condition to represent the boat, the field inside it will be identically zero and is not necessary to solve for. Removing the boat domain this way will save time and memory.
//    In the Settings window for Electromagnetic Waves, Frequency Domain, locate the Formulation section.
//    From the list, select Scattered field.

    model.component("comp1").physics("emw").prop("BackgroundField").set("SolveFor", "scatteredField");

//    The option you just selected lets you enter a background field. The expression you will use, represents a plane wave coming in from an angle phi. In this expression, the wave propagation constant in vacuum, emw.k0, is automatically provided by the physics interface. Once you have solved the model, you can plot the background field to verify that you have set it up correctly.
//    Specify the \[\mathbf{E}_{\textrm{b}}\] vector as

    model.component("comp1").physics("emw").prop("BackgroundField")
         .set("Eb", new String[]{"0", "0", "1[V/m]*exp(j*emw.k0*(x*cos(phi)+y*sin(phi)))"});

//    Locate the Components section.
//    From the Electric field components solved for list, select Out-of-plane vector.

    model.component("comp1").physics("emw").prop("components").set("components", "outofplane");

//    The background field has only the <eqv>z</eqv>-component of electric field. By choosing the <l>Out-of-plane vector</l>, the computation can be more efficient.
//    In the Physics toolbar, click Boundaries and choose Impedance Boundary Condition.

    model.component("comp1").physics("emw").create("imp1", "Impedance", 1);

//    In the Settings window for Impedance Boundary Condition, locate the Boundary Selection section.
//    From the Selection list, select Boat Boundaries.

    model.component("comp1").physics("emw").feature("imp1").selection().named("sel1");

//    The use of an impedance boundary condition assumes that the skin depth in the material is much less than the material thickness. At 200 MHz, the skin depth in Aluminum is of the order of microns, so it is safe to say this is the case. You could even have used a perfect electric conductor condition instead, with largely unchanged results. In the case of scattering on a nanoparticle, the skin depth is often of the same order of magnitude as the particle itself. In such situations, you should not use the impedance boundary condition but rather keep the material domain active.
//    In the Physics toolbar, click Domains and choose Far-Field Domain.

    model.component("comp1").physics("emw").create("ffd1", "FarFieldDomain", 2);

//    In the Model Builder window, right-click Component 1 (comp1) > Mesh 1 and choose Build All.

    model.component("comp1").mesh("mesh1").run();

//    In the Model Builder window, under Study 1, click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, click to expand the Study Extensions section.
//    Select the Auxiliary sweep checkbox.

    model.study("std1").feature("freq").set("useparam", true);

//    Click Add.

    model.study("std1").feature("freq").setIndex("pname_aux", "phi", 0);
    model.study("std1").feature("freq").setIndex("plistarr_aux", "", 0);
    model.study("std1").feature("freq").setIndex("punit_aux", "rad", 0);
    model.study("std1").feature("freq").setIndex("pname_aux", "phi", 0);
    model.study("std1").feature("freq").setIndex("plistarr_aux", "", 0);
    model.study("std1").feature("freq").setIndex("punit_aux", "rad", 0);

//    In the table, enter the following settings:

    model.study("std1").feature("freq").setIndex("plistarr_aux", "range(0,1,360)", 0);
    model.study("std1").feature("freq").setIndex("punit_aux", "deg", 0);

//    You are solving this model for incidence angles from 0 to 360 degrees, in steps of 1 degree. Smaller steps would give you more accurate RCS plots, but the total solution time as well as the size of the model file increases linearly with the number of angles.
//    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", 361, 0);
    model.result("pg1").setIndex("looplevel", 1, 1);
    model.result("pg1").create("surf1", "Surface");
    model.result("pg1").feature("surf1").set("expr", "emw.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 (emw)");
    model.result("pg1").selection().geom("geom1", 2);
    model.result("pg1").selection().set(3);
    model.result("pg1").set("applyselectiontodatasetedges", true);
    model.result("pg1").run();
    model.result().create("pg2", "PlotGroup2D");
    model.result("pg2").set("data", "dset1");
    model.result("pg2").setIndex("looplevel", 361, 0);
    model.result("pg2").setIndex("looplevel", 1, 1);
    model.result("pg2").create("surf1", "Surface");
    model.result("pg2").feature("surf1").set("expr", new String[]{"emw.normEbi"});
    model.result("pg2").feature("surf1").set("colortable", "RainbowLight");
    model.result("pg2").label("Electric Field, Background (emw)");
    model.result("pg2").set("showlegendsmaxmin", true);
    model.result("pg2").selection().geom("geom1", 2);
    model.result("pg2").selection().set(3);
    model.result("pg2").set("applyselectiontodatasetedges", true);
    model.result("pg2").run();
    model.result().create("pg3", "PolarGroup");
    model.result("pg3").label("2D Far Field (emw)");
    model.result("pg3").set("data", "dset1");
    model.result("pg3").create("rp1", "RadiationPattern");
    model.result("pg3").feature("rp1").set("legend", "on");
    model.result("pg3").feature("rp1").set("phidisc", "180");
    model.result("pg3").feature("rp1").set("expr", new String[]{"emw.normEfar"});
    model.result("pg3").feature("rp1").create("exp1", "Export");
    model.result("pg3").feature("rp1").feature("exp1").setIndex("expr", "comp1.emw.phi", 0);
    model.result("pg1").set("applyselectiontodatasetedges", true);
    model.result("pg1").run();
    model.result("pg1").run();

//    In the Model Builder window, expand the Electric Field (emw) node.
//    Right-click Surface 1 and choose Selection.

    model.result("pg1").feature("surf1").create("sel1", "Selection");

//    Select Domain 3.

    model.result("pg1").feature("surf1").feature("sel1").selection().set(3);

//    In the Electric Field (emw) toolbar, click Plot.

    model.result("pg1").run();
    model.result("pg1").run();

//    In the Model Builder window, under Results, click Electric Field (emw).
//    In the Settings window for 2D Plot Group, locate the Data section.
//    From the Parameter value (phi (deg)) list, select 30.

    model.result("pg1").setIndex("looplevel", 31, 0);

//    In the Electric Field (emw) toolbar, click Plot.

    model.result("pg1").run();

//    At 30 degrees, the wake widens. It is also possible to discern an increased field above and to the left of the boat, due to the reflections on its upper side. Try also plotting the instantaneous value of the total and the relative field.

    model.result("pg1").run();

//    In the Model Builder window, click Surface 1.
//    In the Settings window for Surface, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Electromagnetic Waves, Frequency Domain > Electric > Electric field - V/m > emw.Ez - Electric field, z-component.

    model.result("pg1").feature("surf1").set("expr", "emw.Ez");
    model.result("pg1").feature("surf1").set("descr", "Electric field, z-component");

//    In the Electric Field (emw) toolbar, click Plot.

    model.result("pg1").run();

//    Click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Electromagnetic Waves, Frequency Domain > Electric > Relative electric field - V/m > emw.relEz - Relative electric field, z-component.

    return model;
  }

  public static Model run2(Model model) {

    model.result("pg1").feature("surf1").set("expr", "emw.relEz");
    model.result("pg1").feature("surf1").set("descr", "Relative electric field, z-component");

//    In the Electric Field (emw) toolbar, click Plot.

    model.result("pg1").run();

//    Because the relative field is the difference between the observed and the background field, its magnitude will increase both in the wake and where the total field is enhanced by reflections. This trend is even clearer if you plot the absolute value of the relative field.
//    Locate the Expression section.
//    In the Expression text field, type abs(comp1.emw.relEz).

    model.result("pg1").feature("surf1").set("expr", "abs(comp1.emw.relEz)");

//    In the Electric Field (emw) toolbar, click Plot.

    model.result("pg1").run();
    model.result("pg2").run();

//    In the Model Builder window, under Results, click Electric Field, Background (emw).
//    In the Settings window for 2D Plot Group, locate the Data section.
//    From the Parameter value (phi (deg)) list, select 30.

    model.result("pg2").setIndex("looplevel", 31, 0);
    model.result("pg2").run();

//    In the Model Builder window, expand the Electric Field, Background (emw) node.
//    Right-click Surface 1 and choose Selection.

    model.result("pg2").feature("surf1").create("sel1", "Selection");

//    Select Domain 3.

    model.result("pg2").feature("surf1").feature("sel1").selection().set(3);

//    In the Electric Field, Background (emw) toolbar, click Plot.

    model.result("pg2").run();

//    This is the instantaneous norm of the background electric field.

    model.result("pg3").run();

//    In the Model Builder window, under Results, click 2D Far Field (emw).
//    In the Settings window for Polar Plot Group, locate the Data section.
//    From the Parameter selection (phi) list, select From list.

    model.result("pg3").setIndex("looplevelinput", "manual", 0);

//    In the Parameter values (phi (deg)) list, select 30.

    model.result("pg3").setIndex("looplevel", new int[]{31}, 0);

//    select 30 in the Parameter values (phi (deg)) list.

    model.result("pg3").run();

//    In the Model Builder window, expand the 2D Far Field (emw) node, then click Radiation Pattern 1.
//    In the Settings window for Radiation Pattern, locate the Evaluation section.
//    Find the Angles subsection.
//    In the Number of angles text field, type 360.

    model.result("pg3").feature("rp1").set("phidisc", 360);

//    In the 2D Far Field (emw) toolbar, click Plot.

    model.result("pg3").run();

//    To conclude, create a similar plot of the monostatic RCS per unit length. While the far-field plot is for one specific angle of incidence at a time, this plot will visualize the back scattering as a function of the angle of incidence.
//    In the Results toolbar, click Polar Plot Group.

    model.result().create("pg4", "PolarGroup");
    model.result("pg4").run();

//    Right-click Polar Plot Group 4 and choose Global.

    model.result("pg4").create("glob1", "Global");
    model.result("pg4").feature("glob1").set("markerpos", "datapoints");
    model.result("pg4").feature("glob1").set("linewidth", "preference");

//    In the Settings window for Global, locate the r-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg4").feature("glob1").setIndex("expr", "10*log10(emw.mRCS2D)", 0);

//    Locate the θ Angle Data section.
//    From the Parameter list, select Expression.

    model.result("pg4").feature("glob1").set("xdata", "expr");

//    In the Expression text field, type phi.

    model.result("pg4").feature("glob1").set("xdataexpr", "phi");

//    Click to expand the Title section.
//    From the Title type list, select Manual.

    model.result("pg4").feature("glob1").set("titletype", "manual");

//    In the Title text area, type RCS per unit length in dB.

    model.result("pg4").feature("glob1").set("title", "RCS per unit length in dB");

//    In the Polar Plot Group 4 toolbar, click Plot.

    model.result("pg4").run();

    model.title("Radar Cross Section");

    model
         .description("This example of a boat detected by a radar demonstrates the use of a background field in an electromagnetic scattering problem. Results include the radar cross section and the far field as functions of the angle of incidence.");

    return model;
  }

  public static void main(String[] args) {
    Model model = run();
    run2(model);
  }

}
