/*
 * static_field_halbach_rotor_3d.java
 */

import com.comsol.model.*;
import com.comsol.model.util.*;

/** Model exported on May 15 2026, 13:38 by COMSOL 6.4.0.421. */
public class static_field_halbach_rotor_3d {

  public static Model run() {
    Model model = ModelUtil.create("Model");

//    From the File menu, choose New.
//    In the New window, click Model Wizard.
//    In the Model Wizard window, click 3D.
//    In the Select Physics tree, select AC/DC > Magnetic Fields, No Currents > Magnetic Fields, No Currents (mfnc).
//    Click Add.
//    Click Study.
//    In the Select Study tree, select General Studies > Stationary.
//    Click Done.

    model.component().create("comp1", true);

    model.component("comp1").geom().create("geom1", 3);
    model.component("comp1").geom("geom1").geomRep("comsol");

    model.component("comp1").mesh().create("mesh1");
    model.component("comp1").mesh("mesh1").contribute("geom/detail", true);

    model.component("comp1").physics().create("mfnc", "MagnetostaticsNoCurrents", "geom1");

    model.study().create("std1");
    model.study("std1").create("stat", "Stationary");

//    Load the model parameters from the <c>static_field_halbach_rotor_3d_parameters.txt</c> 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 static_field_halbach_rotor_3d_parameters.txt.
//    To import content from file, use:
//    model.param().loadFile("FILENAME");
    model.param().set("Ro", "50[mm]", "Outer radius of the rotor");
    model.param().set("Ri", "30[mm]", "Inner radius of the rotor");
    model.param().set("height", "30[mm]", "Height of the rotor");
    model.param().set("n_segments", "16", "Number of magnet segments");
    model.param().set("alpha", "360[deg]/n_segments", "Rotation per segment");
    model.param().set("outer_analysis", "Ro+5[mm]", "Outer circle radius for analysis");
    model.param().set("inner_analysis", "Ri-5[mm]", "Inner circle radius for analysis");
    model.param().set("height_system", "80[mm]", "Height of the system");
    model.param().set("r_system", "80[mm]", "Radius of the system");
    model.param().set("add_angle", "-45[deg]", "Additional angle for magnetization pattern");

//    In the Model Builder window, expand the Component 1 (comp1) > Geometry 1 node.
//    Right-click Geometry 1 and choose Work Plane.

    model.component("comp1").geom("geom1").create("wp1", "WorkPlane");
    model.component("comp1").geom("geom1").feature("wp1").set("unite", true);

//    In the Settings window for Work Plane, locate the Plane Definition section.
//    In the z-coordinate text field, type -height/2.

    model.component("comp1").geom("geom1").feature("wp1").set("quickz", "-height/2");

//    In the Model Builder window, click Plane Geometry.
//    In the Work Plane toolbar, click Circle.

    model.component("comp1").geom("geom1").feature("wp1").geom().create("c1", "Circle");

//    In the Settings window for Circle, locate the Size and Shape section.
//    In the Radius text field, type Ro.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("c1").set("r", "Ro");

//    In the Sector angle text field, type alpha.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("c1").set("angle", "alpha");

//    Locate the Rotation Angle section.
//    In the Rotation text field, type -alpha/2.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("c1").set("rot", "-alpha/2");

//    Right-click Component 1 (comp1) > Geometry 1 > Work Plane 1 (wp1) > Plane Geometry > Circle 1 (c1) and choose Duplicate.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature().duplicate("c2", "c1");

//    In the Settings window for Circle, locate the Size and Shape section.
//    In the Radius text field, type Ri.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("c2").set("r", "Ri");

//    Click Build Selected.

    model.component("comp1").geom("geom1").feature("wp1").geom().run("c2");

//    In the Work Plane toolbar, click Booleans and Partitions and choose Difference.

    model.component("comp1").geom("geom1").feature("wp1").geom().create("dif1", "Difference");

//    Select the object c1.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("dif1").selection("input").set("c1");

//    In the Settings window for Difference, locate the Difference section.
//    Select the Activate Selection toggle button for Objects to subtract.
//    Select the object c2.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("dif1").selection("input2").set("c2");

//    Click Build Selected.

    model.component("comp1").geom("geom1").feature("wp1").geom().run("dif1");

//    In the Work Plane toolbar, click Transforms and choose Rotate.

    model.component("comp1").geom("geom1").feature("wp1").geom().create("rot1", "Rotate");

//    Select the object dif1.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("rot1").selection("input").set("dif1");

//    In the Settings window for Rotate, locate the Rotation section.
//    In the Angle text field, type range(alpha,alpha,360).

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("rot1")
         .set("rot", "range(alpha,alpha,360)");

//    Click Build Selected.

    model.component("comp1").geom("geom1").feature("wp1").geom().run("rot1");

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Model Builder window, right-click Geometry 1 and choose Extrude.

    model.component("comp1").geom("geom1").run("wp1");
    model.component("comp1").geom("geom1").feature().create("ext1", "Extrude");

//    In the Settings window for Extrude, type Magnets in the Label text field.

    model.component("comp1").geom("geom1").feature("ext1").label("Magnets");

//    Locate the Distances section.
//    In the table, enter the following settings:

    model.component("comp1").geom("geom1").feature("ext1").setIndex("distance", "height", 0);

//    Locate the Selections of Resulting Entities section.
//    Select the Resulting objects selection checkbox.

    model.component("comp1").geom("geom1").feature("ext1").set("selresult", true);

//    Click Build Selected.

    model.component("comp1").geom("geom1").run("ext1");

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Geometry toolbar, click Cylinder.

    model.component("comp1").geom("geom1").create("cyl1", "Cylinder");

//    In the Settings window for Cylinder, locate the Size and Shape section.
//    In the Radius text field, type r_system.

    model.component("comp1").geom("geom1").feature("cyl1").set("r", "r_system");

//    In the Height text field, type height_system.

    model.component("comp1").geom("geom1").feature("cyl1").set("h", "height_system");

//    Locate the Position section.
//    In the z text field, type -height_system/2.

    model.component("comp1").geom("geom1").feature("cyl1").set("pos", new String[]{"0", "0", "-height_system/2"});

//    In the Geometry toolbar, click Work Plane.

    model.component("comp1").geom("geom1").run("cyl1");
    model.component("comp1").geom("geom1").create("wp2", "WorkPlane");
    model.component("comp1").geom("geom1").feature("wp2").set("unite", true);

//    In the Settings window for Work Plane, type Arcs in the Label text field.

    model.component("comp1").geom("geom1").feature("wp2").label("Arcs");

//    Locate the Selections of Resulting Entities section.
//    Select the Resulting objects selection checkbox.

    model.component("comp1").geom("geom1").feature("wp2").set("selresult", true);

//    From the Show in physics list, select Edge selection.

    model.component("comp1").geom("geom1").feature("wp2").set("selresultshow", "edg");

//    Find the Selections from plane geometry subsection.
//    Select the Show in physics checkbox.

    model.component("comp1").geom("geom1").feature("wp2").set("selplaneshow", true);

//    In the Model Builder window, click Plane Geometry.
//    In the Work Plane toolbar, click Circle.

    model.component("comp1").geom("geom1").feature("wp2").geom().create("c1", "Circle");

//    In the Settings window for Circle, type Inner Arc in the Label text field.

    model.component("comp1").geom("geom1").feature("wp2").geom().feature("c1").label("Inner Arc");

//    Locate the Object Type section.
//    From the Type list, select Curve.

    model.component("comp1").geom("geom1").feature("wp2").geom().feature("c1").set("type", "curve");

//    Locate the Size and Shape section.
//    In the Radius text field, type inner_analysis.

    model.component("comp1").geom("geom1").feature("wp2").geom().feature("c1").set("r", "inner_analysis");

//    Locate the Selections of Resulting Entities section.
//    Select the Resulting objects selection checkbox.

    model.component("comp1").geom("geom1").feature("wp2").geom().feature("c1").set("selresult", true);

//    From the Show in 3D list, select Boundary selection.

    model.component("comp1").geom("geom1").feature("wp2").geom().feature("c1").set("selresultshow", "bnd");

//    Right-click Inner Arc and choose Duplicate.

    model.component("comp1").geom("geom1").feature("wp2").geom().feature().duplicate("c2", "c1");

//    In the Settings window for Circle, type Outer Arc in the Label text field.

    model.component("comp1").geom("geom1").feature("wp2").geom().feature("c2").label("Outer Arc");

//    Locate the Size and Shape section.
//    In the Radius text field, type outer_analysis.

    model.component("comp1").geom("geom1").feature("wp2").geom().feature("c2").set("r", "outer_analysis");

//    In the Home toolbar, click Build All.

    model.component("comp1").geom("geom1").run("fin");

//    Click the Zoom Extents button in the Graphics toolbar.
//    Click the Wireframe Rendering button in the Graphics toolbar.

    model.component("comp1").view("view1").set("renderwireframe", true);

//    In the Model Builder window, under Component 1 (comp1) > Geometry 1, click Form Union (fin).
//    Create selections for the north and south boundaries of one magnet segment. This will later, by extension, help define all magnets' magnetization direction.
//    In the Definitions toolbar, click Cylinder.

    model.component("comp1").selection().create("cyl1", "Cylinder");

//    In the Settings window for Cylinder, type North Boundary in the Label text field.

    model.component("comp1").selection("cyl1").label("North Boundary");

//    Locate the Geometric Entity Level section.
//    From the Level list, select Boundary.

    model.component("comp1").selection("cyl1").set("entitydim", 2);

//    Locate the Size and Shape section.
//    In the Outer radius text field, type Ri.

    model.component("comp1").selection("cyl1").set("r", "Ri");

//    In the Inner radius text field, type Ri.

    model.component("comp1").selection("cyl1").set("rin", "Ri");

//    In the Start angle text field, type -alpha/2.

    model.component("comp1").selection("cyl1").set("angle1", "-alpha/2");

//    In the End angle text field, type alpha/2.

    model.component("comp1").selection("cyl1").set("angle2", "alpha/2");

//    Locate the Output Entities section.
//    From the Include entity if list, select All vertices inside cylinder.

    model.component("comp1").selection("cyl1").set("condition", "allvertices");

//    Right-click North Boundary and choose Duplicate.

    model.component("comp1").selection().duplicate("cyl2", "cyl1");

//    In the Settings window for Cylinder, type South Boundary in the Label text field.

    model.component("comp1").selection("cyl2").label("South Boundary");

//    Locate the Size and Shape section.
//    In the Outer radius text field, type Ro.

    model.component("comp1").selection("cyl2").set("r", "Ro");

//    In the Inner radius text field, type Ro.

    model.component("comp1").selection("cyl2").set("rin", "Ro");

//    Next, create a cylindrical coordinate system and a <l>Vector Transform</l> feature to define variables for the radial and azimuthal magnetic flux densities.
//    In the Definitions toolbar, click Coordinate Systems and choose Cylindrical System.

    model.component("comp1").coordSystem().create("sys2", "Cylindrical");

//    Click the Show More Options button in the Model Builder toolbar.
//    In the Show More Options dialog, select General > Variable Utilities in the tree.
//    In the tree, select the checkbox for the General > Variable Utilities node.
//    Click OK.
//    In the Definitions toolbar, click Variable Utilities and choose Vector Transform.

    model.component("comp1").common().create("vectr1", "VectorTransform");

//    In the Settings window for Vector Transform, type B_cyl in the Name text field.

    model.component("comp1").common("vectr1").set("name", "B_cyl");

//    Locate the Geometric Entity Selection section.
//    From the Selection list, select All domains.

    model.component("comp1").common("vectr1").selection().all();

//    Click Replace Expression in the upper-right corner of the Input section.
//    From the menu, choose Component 1 (comp1) > Magnetic Fields, No Currents > Magnetic > Magnetic flux density > mfnc.B - Magnetic flux density - T.

    model.component("comp1").common("vectr1").set("vector", "mfnc.B");

//    Locate the Output section.
//    From the Coordinate system list, select Cylindrical System 2 (sys2).

    model.component("comp1").common("vectr1").set("outputSystem", "sys2");

//    Locate the Transform Settings section.
//    From the Transform as list, select Flux vector.

    model.component("comp1").common("vectr1").set("transform", "scalarFlux");

//    Hide a few boundaries to view the results only in the inner part of the model domain.
//    In the Model Builder window, right-click View 1 and choose Hide for Physics.

    model.component("comp1").view("view1").hideEntities().create("hide1");

//    In the Settings window for Hide for Physics, locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Boundary.

    model.component("comp1").view("view1").hideEntities("hide1").geom("geom1", 2);

//    Select Boundaries 1, 2, 4, 49.

    model.component("comp1").view("view1").hideEntities("hide1").set(1, 2, 4, 49);

//    Click the Transparency button in the Graphics toolbar.

    model.component("comp1").view("view1").set("transparency", true);

//    Now, set up the physics interface
//    In the Physics toolbar, click Domains and choose Magnet.

    model.component("comp1").physics("mfnc").create("mag1", "Magnet", 3);

//    In the Settings window for Magnet, locate the Domain Selection section.
//    From the Selection list, select Magnets.

    model.component("comp1").physics("mfnc").feature("mag1").selection().named("geom1_ext1_dom");

//    Locate the Magnet section.
//    From the Pattern type list, select Circular pattern.

    model.component("comp1").physics("mfnc").feature("mag1").set("PatternType", "CircularPattern");

//    From the Type of periodicity list, select User defined.

    model.component("comp1").physics("mfnc").feature("mag1").set("PeriodicType", "UserDefined");

//    In the \[\alpha\] text field, type add_angle.

    model.component("comp1").physics("mfnc").feature("mag1").setIndex("PatternAdditionalAngle", "add_angle", 0);

//    In the Model Builder window, click North 1.
//    In the Settings window for North, locate the Boundary Selection section.
//    From the Selection list, select North Boundary.

    model.component("comp1").physics("mfnc").feature("mag1").feature("north1").selection().named("cyl1");

//    In the Model Builder window, click South 1.
//    In the Settings window for South, locate the Boundary Selection section.
//    From the Selection list, select South Boundary.

    model.component("comp1").physics("mfnc").feature("mag1").feature("south1").selection().named("cyl2");

//    The final addition to the physics interface is a point constraint for the magnetic scalar potential. Without this addition, there will be no unique solution which can cause problems in the solver.
//    In the Physics toolbar, click Points and choose Zero Magnetic Scalar Potential.

    model.component("comp1").physics("mfnc").create("zsp1", "ZeroMagneticScalarPotential", 0);

//    Select Point 1.

    model.component("comp1").physics("mfnc").feature("zsp1").selection().set(1);

//    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 AC/DC > Hard Magnetic Materials > Sintered NdFeB Grades (Chinese Standard) > N50 (Sintered NdFeB).
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat2", "Common");
    model.component("comp1").material("mat2").propertyGroup()
         .create("RemanentFluxDensity", "RemanentFluxDensity", "Remanent flux density");
    model.component("comp1").material("mat2").label("N50 (Sintered NdFeB)");
    model.component("comp1").material("mat2").set("family", "chrome");
    model.component("comp1").material("mat2").propertyGroup("def")
         .set("electricconductivity", new String[]{"1/1.4[uohm*m]", "0", "0", "0", "1/1.4[uohm*m]", "0", "0", "0", "1/1.4[uohm*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("RemanentFluxDensity")
         .set("murec", new String[]{"1.05", "0", "0", "0", "1.05", "0", "0", "0", "1.05"});
    model.component("comp1").material("mat2").propertyGroup("RemanentFluxDensity").set("normBr", "1.41[T]");

//    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 Selection list, select Magnets.

    model.component("comp1").material("mat2").selection().named("geom1_ext1_dom");

//    Next, the mesh will be constructed. Now it becomes clear why the inner and outer arcs were included in the geometry. These will be given very fine meshes to allow a highly resolved analysis of the magnetic field. First, however, specify the mesh size of the magnets.
//    In the Model Builder window, right-click Component 1 (comp1) > Mesh 1 and choose Size.

    model.component("comp1").mesh("mesh1").create("size1", "Size");

//    In the Settings window for Size, locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Domain.

    model.component("comp1").mesh("mesh1").feature("size1").selection().geom("geom1", 3);

//    From the Selection list, select Magnets.

    model.component("comp1").mesh("mesh1").feature("size1").selection().named("geom1_ext1_dom");

//    Locate the Element Size section.
//    From the Predefined list, select Finer.

    model.component("comp1").mesh("mesh1").feature("size1").set("hauto", 3);

//    Specify a customized fine mesh on the curves where the magnetic flux density is to be evaluated. This helps to obtain a smooth curve for the magnetic flux density.
//    In the Model Builder window, right-click Mesh 1 and choose Size.

    model.component("comp1").mesh("mesh1").create("size2", "Size");

//    In the Settings window for Size, locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Edge.

    model.component("comp1").mesh("mesh1").feature("size2").selection().geom("geom1", 1);

//    From the Selection list, select Arcs.

    model.component("comp1").mesh("mesh1").feature("size2").selection().named("geom1_wp2_edg");

//    Locate the Element Size section.
//    Click the Custom button.

    model.component("comp1").mesh("mesh1").feature("size2").set("custom", true);

//    Locate the Element Size Parameters section.
//    Select the Maximum element size checkbox.

    model.component("comp1").mesh("mesh1").feature("size2").set("hmaxactive", true);

//    In the associated text field, type 0.5[mm].

    model.component("comp1").mesh("mesh1").feature("size2").set("hmax", "0.5[mm]");

//    In the Mesh toolbar, click Free Tetrahedral.

    model.component("comp1").mesh("mesh1").create("ftet1", "FreeTet");

//    In the Settings window for Free Tetrahedral, click Build All.

    model.component("comp1").mesh("mesh1").run();

//    Compare the mesh with the figure shown below.
//    Now, create a <l>Parametric Sweep</l> for the stationary study. This will sweep over different values for the additional angle parameter to look at the resulting magnetic fields.
//    In the Model Builder window, click Study 1.
//    In the Settings window for Study, type Study 1 - Additional Angle Sweep in the Label text field.

    model.study("std1").label("Study 1 - Additional Angle Sweep");

//    Locate the Study Settings section.
//    Clear the Generate default plots checkbox.

    model.study("std1").setGenPlots(false);

//    In the Study toolbar, click Parametric Sweep.

    model.study("std1").create("param", "Parametric");

//    In the Settings window for Parametric Sweep, locate the Study Settings section.
//    Click Add.

    model.study("std1").feature("param").setIndex("pname", "Ro", 0);
    model.study("std1").feature("param").setIndex("plistarr", "", 0);
    model.study("std1").feature("param").setIndex("punit", "m", 0);
    model.study("std1").feature("param").setIndex("pname", "Ro", 0);
    model.study("std1").feature("param").setIndex("plistarr", "", 0);
    model.study("std1").feature("param").setIndex("punit", "m", 0);

//    In the table, enter the following settings:

    model.study("std1").feature("param").setIndex("pname", "add_angle", 0);
    model.study("std1").feature("param").setIndex("plistarr", "range(-90,45,90)", 0);
    model.study("std1").feature("param").setIndex("punit", "deg", 0);

    return model;
  }

  public static Model run2(Model model) {

//    In the Study toolbar, click Compute.

    model.study("std1").createAutoSequences("all");

    model.sol().create("sol2");
    model.sol("sol2").study("std1");
    model.sol("sol2").label("Parametric Solutions 1");

    model.batch("p1").feature("so1").set("psol", "sol2");
    model.batch("p1").run("compute");

//    In the Model Builder window, expand the Results node.
//    Create a cut plane to analyze the magnetic field.
//    In the Model Builder window, expand the Results > Datasets node.
//    Right-click Results > Datasets and choose Cut Plane.

    model.result().dataset().create("cpl1", "CutPlane");

//    In the Settings window for Cut Plane, type Cut Plane - Additional Angle Sweep in the Label text field.

    model.result().dataset("cpl1").label("Cut Plane - Additional Angle Sweep");

//    Locate the Data section.
//    From the Dataset list, select Study 1 - Additional Angle Sweep/Parametric Solutions 1 (sol2).

    model.result().dataset("cpl1").set("data", "dset2");

//    Locate the Plane Data section.
//    From the Plane list, select xy-planes.

    model.result().dataset("cpl1").set("quickplane", "xy");

//    In the Results toolbar, click 2D Plot Group.

    model.result().create("pg1", "PlotGroup2D");
    model.result("pg1").run();

//    In the Settings window for 2D Plot Group, type Magnetic Flux Density, Additional Angle Sweep in the Label text field.

    model.result("pg1").label("Magnetic Flux Density, Additional Angle Sweep");

//    In the Magnetic Flux Density, Additional Angle Sweep toolbar, click Surface.

    model.result("pg1").create("surf1", "Surface");
    model.result("pg1").feature("surf1").set("evaluationsettings", "parent");

//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type mfnc.normB.

    model.result("pg1").feature("surf1").set("expr", "mfnc.normB");

//    Locate the Coloring and Style section.
//    From the Color table list, select Prism.

    model.result("pg1").feature("surf1").set("colortable", "Prism");

//    In the Magnetic Flux Density, Additional Angle Sweep toolbar, click Arrow Surface.

    model.result("pg1").create("arws1", "ArrowSurface");
    model.result("pg1").feature("arws1").set("planecoordsys", "cartesian");
    model.result("pg1").feature("arws1").set("expr", new String[]{"mfnc.Bx", "mfnc.By", "mfnc.Bz"});
    model.result("pg1").feature("arws1").set("descr", "Magnetic flux density");
    model.result("pg1").feature("arws1").set("evaluationsettings", "parent");

//    In the Settings window for Arrow Surface, locate the Arrow Positioning section.
//    Find the x grid points subsection.
//    In the Points text field, type 30.

    model.result("pg1").feature("arws1").set("xnumber", 30);

//    Find the y grid points subsection.
//    In the Points text field, type 30.

    model.result("pg1").feature("arws1").set("ynumber", 30);

//    Locate the Coloring and Style section.
//    From the Color list, select Black.

    model.result("pg1").feature("arws1").set("color", "black");

//    In the Magnetic Flux Density, Additional Angle Sweep toolbar, click Plot.

    model.result("pg1").run();

//    Compare the plots corresponding to the different parameter values by clicking <l>Plot Previous</l> or <l>Plot Next</l>. Note how the magnetic flux density changes from being predominantly inside the rotor for positive values of <c>add_angle</c> to predominantly outside for negative values. Recreate the figure below for <c>add_angle=-45[deg]</c>.

    model.result("pg1").feature("arws1").stepPrevious(0);
    model.result("pg1").run();
    model.result("pg1").feature("arws1").stepPrevious(0);
    model.result("pg1").run();
    model.result("pg1").feature("arws1").stepPrevious(0);
    model.result("pg1").run();

//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg2", "PlotGroup1D");
    model.result("pg2").run();

//    In the Settings window for 1D Plot Group, type Radial Magnetic Flux Density in the Label text field.

    model.result("pg2").label("Radial Magnetic Flux Density");

//    Locate the Data section.
//    From the Dataset list, select Study 1 - Additional Angle Sweep/Parametric Solutions 1 (sol2).

    model.result("pg2").set("data", "dset2");

//    From the Parameter selection (add_angle) list, select From list.

    model.result("pg2").setIndex("looplevelinput", "manual", 0);

//    In the Parameter values (add_angle (deg)) list, select -90.

    model.result("pg2").setIndex("looplevel", new int[]{1}, 0);

//    select -90 in the Parameter values (add_angle (deg)) list.
//    Click to expand the Title section.
//    From the Title type list, select Manual.

    model.result("pg2").set("titletype", "manual");

//    In the Title text area, type Radial magnetic flux density.

    model.result("pg2").set("title", "Radial magnetic flux density");

//    In the Parameter indicator text field, type add_angle = eval(add_angle*180/pi) deg.

    model.result("pg2").set("paramindicator", "add_angle = eval(add_angle*180/pi) deg");

//    Locate the Plot Settings section.
//    Select the x-axis label checkbox.

    model.result("pg2").set("xlabelactive", true);

//    In the associated text field, type Angle (rad/2\pi).

    model.result("pg2").set("xlabel", "Angle (rad/2\\pi)");

//    Select the y-axis label checkbox.

    model.result("pg2").set("ylabelactive", true);

//    In the associated text field, type Radial magnetic flux density (T).

    model.result("pg2").set("ylabel", "Radial magnetic flux density (T)");

//    In the Radial Magnetic Flux Density toolbar, click Line Graph.

    model.result("pg2").create("lngr1", "LineGraph");
    model.result("pg2").feature("lngr1").set("markerpos", "datapoints");
    model.result("pg2").feature("lngr1").set("linewidth", "preference");
    model.result("pg2").feature("lngr1").set("evaluationsettings", "parent");

//    In the Settings window for Line Graph, type Outer Arc in the Label text field.

    model.result("pg2").feature("lngr1").label("Outer Arc");

//    Locate the Selection section.
//    From the Selection list, select Outer Arc (Arcs).

    model.result("pg2").feature("lngr1").selection().named("geom1_wp2_c2_edg");

//    Locate the y-Axis Data section.
//    In the Expression text field, type B_cyl.vr.

    model.result("pg2").feature("lngr1").set("expr", "B_cyl.vr");

//    Locate the x-Axis Data section.
//    Select the Normalize checkbox.

    model.result("pg2").feature("lngr1").set("normalizearclength", true);

//    Click to expand the Legends section.
//    Select the Show legends checkbox.

    model.result("pg2").feature("lngr1").set("legend", true);

//    Find the Include subsection.
//    Select the Label checkbox.

    model.result("pg2").feature("lngr1").set("autoplotlabel", true);

//    Clear the Solution checkbox.

    model.result("pg2").feature("lngr1").set("autosolution", false);

//    Right-click Outer Arc and choose Duplicate.

    model.result("pg2").feature().duplicate("lngr2", "lngr1");
    model.result("pg2").run();

//    In the Settings window for Line Graph, type Inner Arc in the Label text field.

    model.result("pg2").feature("lngr2").label("Inner Arc");

//    Locate the Selection section.
//    From the Selection list, select Inner Arc (Arcs).

    model.result("pg2").feature("lngr2").selection().named("geom1_wp2_c1_edg");

//    In the Radial Magnetic Flux Density toolbar, click Plot.

    model.result("pg2").run();

//    Note how the radial magnetic flux density changes on the two arcs for all parameter values by clicking <l>Plot Next</l> or <l>Plot Previous</l>. Compare the plot for <c>add_angle=-45[deg]</c> with the figure below.

    model.result("pg2").feature("lngr2").stepNext(0);
    model.result("pg2").run();

//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg3", "PlotGroup1D");
    model.result("pg3").run();

//    In the Settings window for 1D Plot Group, type Azimuthal Magnetic Flux Density in the Label text field.

    model.result("pg3").label("Azimuthal Magnetic Flux Density");

//    Locate the Data section.
//    From the Dataset list, select Study 1 - Additional Angle Sweep/Parametric Solutions 1 (sol2).

    model.result("pg3").set("data", "dset2");

//    From the Parameter selection (add_angle) list, select From list.

    model.result("pg3").setIndex("looplevelinput", "manual", 0);

//    In the Parameter values (add_angle (deg)) list, select -90.

    model.result("pg3").setIndex("looplevel", new int[]{1}, 0);

//    select -90 in the Parameter values (add_angle (deg)) list.
//    Locate the Title section.
//    From the Title type list, select Manual.

    model.result("pg3").set("titletype", "manual");

//    In the Title text area, type Azimuthal magnetic flux density.

    model.result("pg3").set("title", "Azimuthal magnetic flux density");

//    In the Parameter indicator text field, type add_angle = eval(add_angle*180/pi) deg.

    model.result("pg3").set("paramindicator", "add_angle = eval(add_angle*180/pi) deg");

//    Locate the Plot Settings section.
//    Select the x-axis label checkbox.

    model.result("pg3").set("xlabelactive", true);

//    In the associated text field, type Angle (rad/2\pi).

    model.result("pg3").set("xlabel", "Angle (rad/2\\pi)");

//    Select the y-axis label checkbox.

    model.result("pg3").set("ylabelactive", true);

//    In the associated text field, type Azimuthal magnetic flux density (T).

    model.result("pg3").set("ylabel", "Azimuthal magnetic flux density (T)");

//    In the Azimuthal Magnetic Flux Density toolbar, click Line Graph.

    model.result("pg3").create("lngr1", "LineGraph");
    model.result("pg3").feature("lngr1").set("markerpos", "datapoints");
    model.result("pg3").feature("lngr1").set("linewidth", "preference");
    model.result("pg3").feature("lngr1").set("evaluationsettings", "parent");

//    In the Settings window for Line Graph, type Outer Arc in the Label text field.

    model.result("pg3").feature("lngr1").label("Outer Arc");

//    Locate the Selection section.
//    From the Selection list, select Outer Arc (Arcs).

    model.result("pg3").feature("lngr1").selection().named("geom1_wp2_c2_edg");

//    Locate the y-Axis Data section.
//    In the Expression text field, type B_cyl.vphi.

    model.result("pg3").feature("lngr1").set("expr", "B_cyl.vphi");

//    Locate the x-Axis Data section.
//    Select the Normalize checkbox.

    model.result("pg3").feature("lngr1").set("normalizearclength", true);

//    Locate the Legends section.
//    Select the Show legends checkbox.

    model.result("pg3").feature("lngr1").set("legend", true);

//    Find the Include subsection.
//    Select the Label checkbox.

    model.result("pg3").feature("lngr1").set("autoplotlabel", true);

//    Clear the Solution checkbox.

    model.result("pg3").feature("lngr1").set("autosolution", false);

//    Right-click Outer Arc and choose Duplicate.

    model.result("pg3").feature().duplicate("lngr2", "lngr1");
    model.result("pg3").run();

//    In the Settings window for Line Graph, type Inner Arc in the Label text field.

    model.result("pg3").feature("lngr2").label("Inner Arc");

//    Locate the Selection section.
//    From the Selection list, select Inner Arc (Arcs).

    model.result("pg3").feature("lngr2").selection().named("geom1_wp2_c1_edg");

//    In the Azimuthal Magnetic Flux Density toolbar, click Plot.

    model.result("pg3").run();

//    Once again, compare the plots corresponding to the different parameter values by Clicking <l>Plot Next</l> or <l>Plot Previous</l>. Make sure the plot for <c>add_angle=-45[deg]</c> looks like the figure below.

    model.result("pg3").feature("lngr2").stepNext(0);
    model.result("pg3").run();

//    In the Results toolbar, click Polar Plot Group.

    model.result().create("pg4", "PolarGroup");
    model.result("pg4").run();

//    In the Settings window for Polar Plot Group, type Magnetic Flux Density Norm in the Label text field.

    model.result("pg4").label("Magnetic Flux Density Norm");

//    Locate the Data section.
//    From the Dataset list, select Study 1 - Additional Angle Sweep/Parametric Solutions 1 (sol2).

    model.result("pg4").set("data", "dset2");

//    From the Parameter selection (add_angle) list, select From list.

    model.result("pg4").setIndex("looplevelinput", "manual", 0);

//    In the Parameter values (add_angle (deg)) list, select -90.

    model.result("pg4").setIndex("looplevel", new int[]{1}, 0);

//    select -90 in the Parameter values (add_angle (deg)) list.
//    Click to expand the Title section.
//    From the Title type list, select Manual.

    model.result("pg4").set("titletype", "manual");

//    In the Title text area, type Magnetic flux density norm.

    model.result("pg4").set("title", "Magnetic flux density norm");

//    In the Parameter indicator text field, type add_angle = eval(add_angle*180/pi) deg.

    model.result("pg4").set("paramindicator", "add_angle = eval(add_angle*180/pi) deg");

//    Locate the Axis section.
//    Select the Manual axis limits checkbox.

    model.result("pg4").set("axislimits", true);

//    In the r maximum text field, type 0.85.

    model.result("pg4").set("rmax", 0.85);

//    In the Magnetic Flux Density Norm toolbar, click Line Graph.

    model.result("pg4").create("lngr1", "LineGraph");
    model.result("pg4").feature("lngr1").set("markerpos", "datapoints");
    model.result("pg4").feature("lngr1").set("linewidth", "preference");
    model.result("pg4").feature("lngr1").set("evaluationsettings", "parent");

//    In the Settings window for Line Graph, type Outer Arc in the Label text field.

    model.result("pg4").feature("lngr1").label("Outer Arc");

//    Locate the Selection section.
//    From the Selection list, select Outer Arc (Arcs).

    model.result("pg4").feature("lngr1").selection().named("geom1_wp2_c2_edg");

//    Locate the r-Axis Data section.
//    In the Expression text field, type mfnc.normB.

    model.result("pg4").feature("lngr1").set("expr", "mfnc.normB");

//    Locate the θ Angle Data section.
//    From the Parameter list, select Expression.

    model.result("pg4").feature("lngr1").set("xdata", "expr");

//    In the Expression text field, type sys2.phi.

    model.result("pg4").feature("lngr1").set("xdataexpr", "sys2.phi");

//    Click to expand the Legends section.
//    Select the Show legends checkbox.

    model.result("pg4").feature("lngr1").set("legend", true);

//    Find the Include subsection.
//    Select the Label checkbox.

    model.result("pg4").feature("lngr1").set("autoplotlabel", true);

//    Clear the Solution checkbox.

    model.result("pg4").feature("lngr1").set("autosolution", false);

//    Right-click Outer Arc and choose Duplicate.

    model.result("pg4").feature().duplicate("lngr2", "lngr1");
    model.result("pg4").run();

//    In the Settings window for Line Graph, type Inner Arc in the Label text field.

    model.result("pg4").feature("lngr2").label("Inner Arc");

//    Locate the Selection section.
//    From the Selection list, select Inner Arc (Arcs).

    model.result("pg4").feature("lngr2").selection().named("geom1_wp2_c1_edg");

//    In the Magnetic Flux Density Norm toolbar, click Plot.

    model.result("pg4").run();

//    Click Plot Next.

    model.result("pg4").feature("lngr2").stepNext(0);
    model.result("pg4").run();

//    Compare the plot for <c>add_angle=-45[deg]</c> with the figure below.
//    In the Results toolbar, click 3D Plot Group.

    model.result().create("pg5", "PlotGroup3D");
    model.result("pg5").run();

//    In the Settings window for 3D Plot Group, type 3D Magnetic Flux Density in the Label text field.

    model.result("pg5").label("3D Magnetic Flux Density");

//    Locate the Data section.
//    From the Dataset list, select Study 1 - Additional Angle Sweep/Parametric Solutions 1 (sol2).

    model.result("pg5").set("data", "dset2");

//    From the Parameter value (add_angle (deg)) list, select -45.

    model.result("pg5").setIndex("looplevel", 2, 0);

//    Locate the Plot Settings section.
//    Clear the Plot dataset edges checkbox.

    model.result("pg5").set("edges", false);

//    Click to expand the Title section.
//    From the Title type list, select Label.

    model.result("pg5").set("titletype", "label");

//    Click to collapse the Title section.
//    Locate the Color Legend section.
//    Select the Show maximum and minimum values checkbox.

    model.result("pg5").set("showlegendsmaxmin", true);

//    In the 3D Magnetic Flux Density toolbar, click Volume.

    model.result("pg5").create("vol1", "Volume");
    model.result("pg5").feature("vol1").set("evaluationsettings", "parent");

//    In the Settings window for Volume, locate the Expression section.
//    In the Expression text field, type mfnc.normB.

    model.result("pg5").feature("vol1").set("expr", "mfnc.normB");

//    Locate the Coloring and Style section.
//    From the Color table list, select Prism.

    model.result("pg5").feature("vol1").set("colortable", "Prism");

//    Right-click Volume 1 and choose Selection.

    model.result("pg5").feature("vol1").create("sel1", "Selection");

//    In the Settings window for Selection, locate the Selection section.
//    From the Selection list, select Magnets.

    model.result("pg5").feature("vol1").feature("sel1").selection().named("geom1_ext1_dom");
    model.result("pg5").run();

//    In the Model Builder window, right-click Volume 1 and choose Filter.

    model.result("pg5").feature("vol1").create("filt1", "Filter");
    model.result("pg5").run();

//    In the Settings window for Filter, locate the Element Selection section.
//    In the Logical expression for inclusion text field, type z<-1[mm].

    model.result("pg5").feature("vol1").feature("filt1").set("expr", "z<-1[mm]");

//    In the 3D Magnetic Flux Density toolbar, click More Plots and choose Streamline Surface.

    model.result("pg5").create("str1", "StreamlineSurface");
    model.result("pg5").feature("str1").set("evaluationsettings", "parent");

//    In the Settings window for Streamline Surface, locate the Data section.
//    From the Dataset list, select Cut Plane - Additional Angle Sweep.

    model.result("pg5").feature("str1").set("data", "cpl1");

//    From the Solution parameters list, select From parent.

    model.result("pg5").feature("str1").set("solutionparams", "parent");

//    Locate the Streamline Positioning section.
//    From the Positioning list, select Magnitude controlled.

    model.result("pg5").feature("str1").set("posmethod", "magnitude");

//    In the Minimum density level text field, type 2.

    model.result("pg5").feature("str1").set("magdensity", new double[]{2, 12.3});

//    In the Maximum density level text field, type 11.

    model.result("pg5").feature("str1").set("magdensity", new double[]{2, 11});

//    Right-click Streamline Surface 1 and choose Color Expression.

    model.result("pg5").feature("str1").create("col1", "Color");
    model.result("pg5").run();

//    In the Settings window for Color Expression, locate the Expression section.
//    In the Expression text field, type mfnc.normB.

    model.result("pg5").feature("str1").feature("col1").set("expr", "mfnc.normB");

//    Locate the Coloring and Style section.
//    Clear the Color legend checkbox.

    model.result("pg5").feature("str1").feature("col1").set("colorlegend", false);

//    From the Color table transformation list, select Nonlinear.

    model.result("pg5").feature("str1").feature("col1").set("colortabletrans", "nonlinear");

//    In the Color calibration parameter text field, type -0.8.

    model.result("pg5").feature("str1").feature("col1").set("colorcalibration", -0.8);

//    In the 3D Magnetic Flux Density toolbar, click Plot.

    model.result("pg5").run();

//    Click the Transparency button in the Graphics toolbar.

    model.component("comp1").view("view1").set("transparency", false);

//    Compare the 3D magnetic flux density plot with the figure below.
//    Create a new stationary study with its own parametric sweep over the parameter <c>n_segments</c>. This allows for a comparison of how the number of segments changes the magnetic field.
//    In the Home toolbar, click Add Study to open the Add Study window.
//    Find the Studies subsection.
//    In the Select Study tree, select General Studies > Stationary.
//    Click Add Study in the window toolbar.

    model.study().create("std2");
    model.study("std2").create("stat", "Stationary");

//    In the Home toolbar, click Add Study to close the Add Study window.
//    In the Settings window for Study, type Study 2 - Number of Segments Sweep in the Label text field.

    model.study("std2").label("Study 2 - Number of Segments Sweep");

//    Locate the Study Settings section.
//    Clear the Generate default plots checkbox.

    model.study("std2").setGenPlots(false);

//    In the Study toolbar, click Parametric Sweep.

    model.study("std2").create("param", "Parametric");

//    In the Settings window for Parametric Sweep, locate the Study Settings section.
//    Click Add.

    model.study("std2").feature("param").setIndex("pname", "Ro", 0);
    model.study("std2").feature("param").setIndex("plistarr", "", 0);
    model.study("std2").feature("param").setIndex("punit", "m", 0);
    model.study("std2").feature("param").setIndex("pname", "Ro", 0);
    model.study("std2").feature("param").setIndex("plistarr", "", 0);
    model.study("std2").feature("param").setIndex("punit", "m", 0);

//    In the table, enter the following settings:

    model.study("std2").feature("param").setIndex("pname", "n_segments", 0);
    model.study("std2").feature("param").setIndex("plistarr", "8 16 24 32", 0);

//    Keep in mind that the number of segments is constrained such that <c>n_segments*add_angle</c> is an integer multiple of 360 degrees. This is to make sure a full rotation around the rotor results in the magnetization vector returning to its original orientation.
//    In the Study toolbar, click Compute.

    model.study("std2").createAutoSequences("all");

    model.sol().create("sol9");
    model.sol("sol9").study("std2");
    model.sol("sol9").label("Parametric Solutions 2");

    model.batch("p2").feature("so1").set("psol", "sol9");
    model.batch("p2").run("compute");

//    Create a new cut plane for the new parametric sweep.
//    In the Results toolbar, click Cut Plane.

    model.result().dataset().create("cpl2", "CutPlane");

//    In the Settings window for Cut Plane, type Cut Plane - Number of Segments Sweep in the Label text field.

    model.result().dataset("cpl2").label("Cut Plane - Number of Segments Sweep");

//    Locate the Data section.
//    From the Dataset list, select Study 2 - Number of Segments Sweep/Parametric Solutions 2 (sol9).

    model.result().dataset("cpl2").set("data", "dset4");

//    Locate the Plane Data section.
//    From the Plane list, select xy-planes.

    model.result().dataset("cpl2").set("quickplane", "xy");
    model.result("pg1").run();

//    In the Model Builder window, right-click Magnetic Flux Density, Additional Angle Sweep and choose Duplicate.

    model.result().duplicate("pg6", "pg1");
    model.result("pg6").run();

//    In the Settings window for 2D Plot Group, type Magnetic Flux Density, Number of Segments Sweep in the Label text field.

    model.result("pg6").label("Magnetic Flux Density, Number of Segments Sweep");

//    Locate the Data section.
//    From the Dataset list, select Cut Plane - Number of Segments Sweep.

    model.result("pg6").set("data", "cpl2");

//    In the Magnetic Flux Density, Number of Segments Sweep toolbar, click Plot.

    model.result("pg6").run();

//    Compare the magnetic flux densities corresponding to the different parameter values by clicking <l>Plot Previous</l> or <l>Plot Next</l>. Recreate the one-dimensional plot groups and the polar plot group for the new study.

    model.result("pg2").run();

//    In the Model Builder window, right-click Radial Magnetic Flux Density and choose Duplicate.

    model.result().duplicate("pg7", "pg2");
    model.result("pg7").run();

//    In the Settings window for 1D Plot Group, type Radial Magnetic Flux Density - Number of Segments Sweep in the Label text field.

    model.result("pg7").label("Radial Magnetic Flux Density - Number of Segments Sweep");

//    Locate the Data section.
//    From the Dataset list, select Study 2 - Number of Segments Sweep/Parametric Solutions 2 (sol9).

    model.result("pg7").set("data", "dset4");

//    Locate the Title section.
//    In the Parameter indicator text field, type n_segments = eval(n_segments).

    model.result("pg7").set("paramindicator", "n_segments = eval(n_segments)");

//    In the Radial Magnetic Flux Density - Number of Segments Sweep toolbar, click Plot.

    model.result("pg7").run();

//    Compare the radial magnetic flux densities corresponding to the different parameter values by clicking <l>Plot Previous</l> or <l>Plot Next</l>.

    model.result("pg3").run();

//    In the Model Builder window, right-click Azimuthal Magnetic Flux Density and choose Duplicate.

    model.result().duplicate("pg8", "pg3");
    model.result("pg8").run();

//    In the Settings window for 1D Plot Group, type Azimuthal Magnetic Flux Density - Number of Segments Sweep in the Label text field.

    model.result("pg8").label("Azimuthal Magnetic Flux Density - Number of Segments Sweep");

//    Locate the Data section.
//    From the Dataset list, select Study 2 - Number of Segments Sweep/Parametric Solutions 2 (sol9).

    model.result("pg8").set("data", "dset4");

//    Locate the Title section.
//    In the Parameter indicator text field, type n_segments = eval(n_segments).

    model.result("pg8").set("paramindicator", "n_segments = eval(n_segments)");

//    In the Azimuthal Magnetic Flux Density - Number of Segments Sweep toolbar, click Plot.

    model.result("pg8").run();

//    Compare the azimuthal magnetic flux densities corresponding to the different parameter values by clicking <l>Plot Previous</l> or <l>Plot Next</l>.

    model.result("pg4").run();

//    In the Model Builder window, right-click Magnetic Flux Density Norm and choose Duplicate.

    model.result().duplicate("pg9", "pg4");
    model.result("pg9").run();

//    In the Settings window for Polar Plot Group, type Magnetic Flux Density Norm - Number of Segments Sweep in the Label text field.

    model.result("pg9").label("Magnetic Flux Density Norm - Number of Segments Sweep");

//    Locate the Data section.
//    From the Dataset list, select Study 2 - Number of Segments Sweep/Parametric Solutions 2 (sol9).

    model.result("pg9").set("data", "dset4");

//    Locate the Title section.
//    In the Parameter indicator text field, type n_segments = eval(n_segments).

    model.result("pg9").set("paramindicator", "n_segments = eval(n_segments)");

//    In the Magnetic Flux Density Norm - Number of Segments Sweep toolbar, click Plot.

    model.result("pg9").run();

//    Look through the magnetic flux density norms for the different parameters and note how the difference between the inner and outer arcs changes. Compare the polar plot for <c>n_segments=32</c> with the figure below.

    model.result("pg9").stepNext(0);
    model.result("pg9").run();
    model.result("pg9").stepNext(0);
    model.result("pg9").run();

    model.component("comp1").geom("geom1").run("fin");

    model.result("pg5").run();

    model.title("Static Field Modeling of a Halbach Rotor");

    model
         .description("This example presents the static-field modeling of a flux-focusing magnetic rotor using permanent magnets, a magnetic rotor also known as a Halbach rotor. The use of permanent magnets in rotatory devices such as motors, generators, and magnetic gears is increasing due to their no-contact, frictionless operation. This model illustrates how to calculate and change the magnetic field of a Halbach rotor in 3D by changing the number of permanent magnet segments and the number of pole-pairs.");

    return model;
  }

  public static void main(String[] args) {
    Model model = run();
    run2(model);
  }

}
