/*
 * magnetic_brake.java
 */

import com.comsol.model.*;
import com.comsol.model.util.*;

/** Model exported on May 15 2026, 09:04 by COMSOL 6.4.0.421. */
public class magnetic_brake {

  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 > Electromagnetic Fields > Vector Formulations > Magnetic and Electric Fields (mef).
//    Click Add.
//    In the Select Physics tree, select Mathematics > ODE and DAE Interfaces > Global ODEs and DAEs (ge).
//    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("mef", "ElectricInductionCurrents", "geom1");
    model.component("comp1").physics().create("ge", "GlobalEquations", "geom1");
    model.component("comp1").physics("ge").prop("EquationForm").set("form", "Automatic");

    model.study().create("std1");
    model.study("std1").create("stat", "Stationary");

//    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("dt", "1[cm]");
    model.param().descr("dt", "Disc thickness");
    model.param().set("dr", "10[cm]");
    model.param().descr("dr", "Disc radius");
    model.param().set("mh", "12[cm]");
    model.param().descr("mh", "Magnet height");
    model.param().set("mw", "2[cm]");
    model.param().descr("mw", "Magnet width");
    model.param().set("ml", "8[cm]");
    model.param().descr("ml", "Magnet length");
    model.param().set("mt", "2[cm]");
    model.param().descr("mt", "Magnet thickness");
    model.param().set("mg", "1.5[cm]");
    model.param().descr("mg", "Magnet air gap");
    model.param().set("mB", "1[T]");
    model.param().descr("mB", "Magnet flux");
    model.param().set("ymur", "4000");
    model.param().descr("ymur", "Yoke relative permeability");
    model.param().set("dV0", "1000[rpm]");
    model.param().descr("dV0", "Disc initial angular frequency");

//    In the Geometry toolbar, click Sphere.

    model.component("comp1").geom("geom1").create("sph1", "Sphere");

//    In the Settings window for Sphere, locate the Size section.
//    In the Radius text field, type dr*3.

    model.component("comp1").geom("geom1").feature("sph1").set("r", "dr*3");

//    In the Geometry toolbar, click Cylinder.

    model.component("comp1").geom("geom1").run("sph1");
    model.component("comp1").geom("geom1").create("cyl1", "Cylinder");

//    In the Settings window for Cylinder, type Disc in the Label text field.

    model.component("comp1").geom("geom1").feature("cyl1").label("Disc");

//    Locate the Size and Shape section.
//    In the Radius text field, type dr.

    model.component("comp1").geom("geom1").feature("cyl1").set("r", "dr");

//    In the Height text field, type dt.

    model.component("comp1").geom("geom1").feature("cyl1").set("h", "dt");

//    Locate the Position section.
//    In the z text field, type -dt/2.

    model.component("comp1").geom("geom1").feature("cyl1").set("pos", new String[]{"0", "0", "-dt/2"});

//    Locate the Selections of Resulting Entities section.
//    Select the Resulting objects selection checkbox.

    model.component("comp1").geom("geom1").feature("cyl1").set("selresult", true);

//    A selection named <l>Disc</l> is then automatically created for the disc.
//    Now, design the magnet and the yoke on a plane, and then extrude them.
//    In the Geometry toolbar, click Work Plane.

    model.component("comp1").geom("geom1").run("cyl1");
    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.
//    From the Plane list, select yz-plane.

    model.component("comp1").geom("geom1").feature("wp1").set("quickplane", "yz");

//    In the x-coordinate text field, type -mt/2.

    model.component("comp1").geom("geom1").feature("wp1").set("quickx", "-mt/2");

//    Click Go to Plane Geometry.
//    In the Work Plane toolbar, click Rectangle.

    model.component("comp1").geom("geom1").feature("wp1").geom().create("r1", "Rectangle");

//    In the Settings window for Rectangle, locate the Size and Shape section.
//    In the Width text field, type mw.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("r1").set("size", new String[]{"mw", "1"});

//    In the Height text field, type mh-2*mw.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("r1")
         .set("size", new String[]{"mw", "mh-2*mw"});

//    Locate the Position section.
//    From the Base list, select Center.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("r1").set("base", "center");

//    In the xw text field, type dr+ml/2-mw/2.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("r1")
         .set("pos", new String[]{"dr+ml/2-mw/2", "0"});

//    In the Work Plane toolbar, click Rectangle.

    model.component("comp1").geom("geom1").feature("wp1").geom().run("r1");
    model.component("comp1").geom("geom1").feature("wp1").geom().create("r2", "Rectangle");

//    In the Settings window for Rectangle, locate the Size and Shape section.
//    In the Width text field, type ml-mw.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("r2")
         .set("size", new String[]{"ml-mw", "1"});

//    In the Height text field, type mw.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("r2")
         .set("size", new String[]{"ml-mw", "mw"});

//    Locate the Position section.
//    In the xw text field, type dr-ml/2+mw.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("r2")
         .set("pos", new String[]{"dr-ml/2+mw", "0"});

//    In the yw text field, type mh/2-mw.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("r2")
         .set("pos", new String[]{"dr-ml/2+mw", "mh/2-mw"});

//    In the Work Plane toolbar, click Rectangle.

    model.component("comp1").geom("geom1").feature("wp1").geom().run("r2");
    model.component("comp1").geom("geom1").feature("wp1").geom().create("r3", "Rectangle");

//    In the Settings window for Rectangle, locate the Size and Shape section.
//    In the Width text field, type mw.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("r3").set("size", new String[]{"mw", "1"});

//    In the Height text field, type mh/2-mg/2.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("r3")
         .set("size", new String[]{"mw", "mh/2-mg/2"});

//    Locate the Position section.
//    In the xw text field, type dr-ml/2.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("r3")
         .set("pos", new String[]{"dr-ml/2", "0"});

//    In the yw text field, type mg/2.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("r3")
         .set("pos", new String[]{"dr-ml/2", "mg/2"});

//    In the Work Plane toolbar, click Transforms and choose Mirror.

    model.component("comp1").geom("geom1").feature("wp1").geom().run("r3");
    model.component("comp1").geom("geom1").feature("wp1").geom().create("mir1", "Mirror");

//    Click the Zoom Extents button in the Graphics toolbar.
//    Select the objects r2, r3.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("mir1").selection("input").set("r2", "r3");

//    In the Settings window for Mirror, locate the Input section.
//    Select the Keep input objects checkbox.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("mir1").set("keep", true);

//    Locate the Normal Vector to Line of Reflection section.
//    In the xw text field, type 0.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("mir1").set("axis", new double[]{0, 0});

//    In the yw text field, type 1.

    model.component("comp1").geom("geom1").feature("wp1").geom().feature("mir1").set("axis", new double[]{0, 1});

//    Right-click Mirror 1 (mir1) and choose Build Selected.

    model.component("comp1").geom("geom1").feature("wp1").geom().run("mir1");

//    The geometry on the work plane should now look like the figure below.
//    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, locate the Distances section.
//    In the table, enter the following settings:

    model.component("comp1").geom("geom1").feature("ext1").setIndex("distance", "mt", 0);

//    Click Build All Objects.

    model.component("comp1").geom("geom1").runPre("fin");

//    Hide the exterior boundaries to show the yoke and the disc only.
//    Click the Click and Hide button in the Graphics toolbar.
//    In the Graphics window toolbar, click ^ next to Select Objects, then choose Select Boundaries.
//    Select the exterior boundaries of the sphere (Boundaries 1–8 on the object <c>sph1</c>).

    model.component("comp1").view("view1").hideObjects().create("hide1");
    model.component("comp1").view("view1").hideObjects("hide1").init(2);
    model.component("comp1").view("view1").hideObjects("hide1").add("sph1", 1, 2, 3, 4, 5, 6, 7, 8);

//    Click the Click and Hide button in the Graphics toolbar.
//    Click the Go to Default View button in the Graphics toolbar.
//    The model geometry is now complete.
//    Define a nonlocal integration coupling on the disc to compute the total dissipated power.
//    In the Definitions toolbar, click Nonlocal Couplings and choose Integration.

    model.component("comp1").cpl().create("intop1", "Integration");

    model.component("comp1").geom("geom1").run();

    model.component("comp1").cpl("intop1").set("axisym", true);

//    In the Settings window for Integration, type intdisc in the Operator name text field.

    model.component("comp1").cpl("intop1").set("opname", "intdisc");

//    Select Domain 2.

    model.component("comp1").cpl("intop1").selection().set(2);

//    In the Label text field, type Integration over Disc.

    model.component("comp1").cpl("intop1").label("Integration over Disc");

//    In the Model Builder window, right-click Definitions and choose Physics Utilities > Mass Properties.

    model.component("comp1").massProp().create("mass1", "MassProperties");

//    In the Settings window for Mass Properties, locate the Source Selection section.
//    Click Clear Selection.

    model.component("comp1").massProp("mass1").selection().set();

//    From the Selection list, select Disc.

    model.component("comp1").massProp("mass1").selection().named("geom1_cyl1_dom");

//    Locate the Variables section.
//    From the Frame list, select Spatial (x, y, z).

    model.component("comp1").massProp("mass1").set("outputFrame", "spatial");

//    Use the density of the material (in this case, copper) to compute the moment of inertia.
//    Locate the Density section.
//    In the Density expression text field, type mat1.def.rho.

    model.component("comp1").massProp("mass1").set("expr", "mat1.def.rho");

//    Clear all checkboxes except <l>Create moment of inertia variables</l>.

    model.component("comp1").massProp("mass1").set("createVolume", false);
    model.component("comp1").massProp("mass1").set("createMass", false);
    model.component("comp1").massProp("mass1").set("createCenterOfMass", false);
    model.component("comp1").massProp("mass1").set("createPrincipalInertia", false);

//    The <l>Mass Properties</l> node will define the moment of inertia variables <c>mass1.Ixx</c>, <c>mass1.Ixy</c>, and so on.
//    In the Physics toolbar, click Domains and choose Ampère's Law and Current Conservation in Solids.

    model.component("comp1").physics("mef").create("alcs1", "ElectromagneticModelSolid", 3);

//    Select Domains 3, 4, 5, 6.

    model.component("comp1").physics("mef").feature("alcs1").selection().set(3, 4, 5, 6);

//    In the Physics toolbar, click Domains and choose Ampère's Law and Current Conservation in Solids.

    model.component("comp1").physics("mef").create("alcs2", "ElectromagneticModelSolid", 3);

//    Select Domain 7.

    model.component("comp1").physics("mef").feature("alcs2").selection().set(7);

//    In the Settings window for Ampère's Law and Current Conservation in Solids, locate the Constitutive Relation B-H section.
//    From the Magnetization model list, select Remanent flux density.

    model.component("comp1").physics("mef").feature("alcs2").set("ConstitutiveRelationBH", "RemanentFluxDensity");

//    Specify the \[\mathbf{e}\] vector as

    model.component("comp1").physics("mef").feature("alcs2")
         .set("e_crel_BH_RemanentFluxDensity", new int[]{0, 0, 1});

//    In the Label text field, type Permanent Magnet.

    model.component("comp1").physics("mef").feature("alcs2").label("Permanent Magnet");

//    In the Physics toolbar, click Domains and choose Ampère's Law and Current Conservation in Solids.

    model.component("comp1").physics("mef").create("alcs3", "ElectromagneticModelSolid", 3);

//    In the Settings window for Ampère's Law and Current Conservation in Solids, locate the Domain Selection section.
//    From the Selection list, select Disc.

    model.component("comp1").physics("mef").feature("alcs3").selection().named("geom1_cyl1_dom");

//    In the Label text field, type Disc.

    model.component("comp1").physics("mef").feature("alcs3").label("Disc");

//    In the Physics toolbar, click Domains and choose Velocity (Lorentz Term).

    model.component("comp1").physics("mef").create("vlt1", "Velocity", 3);

//    In the Settings window for Velocity (Lorentz Term), locate the Domain Selection section.
//    From the Selection list, select Disc.

    model.component("comp1").physics("mef").feature("vlt1").selection().named("geom1_cyl1_dom");

//    Locate the Velocity (Lorentz Term) section.
//    Specify the \[\mathbf{v}\] vector as

    model.component("comp1").physics("mef").feature("vlt1").set("v", new String[]{"-y*W", "x*W", "0"});

//    Specifying the variable <c>W</c> as angular velocity (that will be used later as a state variable in the ODE) couples the <l>Magnetic and Electric Fields</l> interface with the ODE.
//    In the Materials toolbar, click Add Material to open the Add Material window.
//    In the tree, select Built-in > Copper.
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat1", "Common");
    model.component("comp1").material("mat1").propertyGroup()
         .create("Enu", "Enu", "Young's modulus and Poisson's ratio");
    model.component("comp1").material("mat1").propertyGroup().create("linzRes", "linzRes", "Linearized resistivity");
    model.component("comp1").material("mat1").label("Copper");
    model.component("comp1").material("mat1").set("family", "copper");
    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("electricconductivity", new String[]{"5.998e7[S/m]", "0", "0", "0", "5.998e7[S/m]", "0", "0", "0", "5.998e7[S/m]"});
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("thermalexpansioncoefficient", new String[]{"17e-6[1/K]", "0", "0", "0", "17e-6[1/K]", "0", "0", "0", "17e-6[1/K]"});
    model.component("comp1").material("mat1").propertyGroup("def").set("heatcapacity", "385[J/(kg*K)]");
    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("density", "8960[kg/m^3]");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("thermalconductivity", new String[]{"400[W/(m*K)]", "0", "0", "0", "400[W/(m*K)]", "0", "0", "0", "400[W/(m*K)]"});
    model.component("comp1").material("mat1").propertyGroup("Enu").set("E", "110[GPa]");
    model.component("comp1").material("mat1").propertyGroup("Enu").set("nu", "0.35");
    model.component("comp1").material("mat1").propertyGroup("linzRes").set("rho0", "1.72e-8[ohm*m]");
    model.component("comp1").material("mat1").propertyGroup("linzRes").set("alpha", "0.0039[1/K]");
    model.component("comp1").material("mat1").propertyGroup("linzRes").set("Tref", "298[K]");
    model.component("comp1").material("mat1").propertyGroup("linzRes").addInput("temperature");

//    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 Disc.

    model.component("comp1").material("mat1").selection().named("geom1_cyl1_dom");

//    In the Model Builder window, right-click Materials and choose Blank Material.

    model.component("comp1").material().create("mat2", "Common");

//    Select Domains 3, 4, 5, 6.

    model.component("comp1").material("mat2").selection().set(3, 4, 5, 6);

//    In the Settings window for Material, locate the Material Contents section.
//    In the table, enter the following settings:

    model.component("comp1").material("mat2").propertyGroup("def").set("relpermeability", new String[]{"ymur"});
    model.component("comp1").material("mat2").propertyGroup("def").set("electricconductivity", new String[]{"1"});
    model.component("comp1").material("mat2").propertyGroup("def").set("relpermittivity", new String[]{"1"});

//    In the Label text field, type Yoke.

    model.component("comp1").material("mat2").label("Yoke");

//    In the Materials toolbar, click Add Material to open the Add Material window.
//    In the tree, select AC/DC > Hard Magnetic Materials > Sintered NdFeB Grades (Chinese Standard) > N50 (Sintered NdFeB).
//    Right-click and choose Add to Component 1 (comp1).

    model.component("comp1").material().create("mat3", "Common");
    model.component("comp1").material("mat3").propertyGroup()
         .create("RemanentFluxDensity", "RemanentFluxDensity", "Remanent flux density");
    model.component("comp1").material("mat3").label("N50 (Sintered NdFeB)");
    model.component("comp1").material("mat3").set("family", "chrome");
    model.component("comp1").material("mat3").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("mat3").propertyGroup("def")
         .set("relpermittivity", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat3").propertyGroup("RemanentFluxDensity")
         .set("murec", new String[]{"1.05", "0", "0", "0", "1.05", "0", "0", "0", "1.05"});
    model.component("comp1").material("mat3").propertyGroup("RemanentFluxDensity").set("normBr", "1.41[T]");

//    In the Materials toolbar, click Add Material to close the Add Material window.
//    Select Domain 7.

    model.component("comp1").material("mat3").selection().set(7);

//    In the Settings window for Material, locate the Material Contents section.
//    In the table, enter the following settings:

    model.component("comp1").material("mat3").propertyGroup("def").set("electricconductivity", new String[]{"1"});
    model.component("comp1").material("mat3").propertyGroup("RemanentFluxDensity").set("murec", new String[]{"1"});
    model.component("comp1").material("mat3").propertyGroup("RemanentFluxDensity").set("normBr", new String[]{"mB"});

//    In the Label text field, type Generic Magnet.

    model.component("comp1").material("mat3").label("Generic Magnet");

//    Add a <l>Mass Properties</l> node to compute the moment of inertia of the disc.
//    Specify the differential equation that describes the dynamics of the disc in the table. Torque is computed by integrating the Lorentz force contribution.
//    In the Model Builder window, under Component 1 (comp1) > Global ODEs and DAEs (ge), click Global Equations 1 (ODE1).
//    In the Settings window for Global Equations, locate the Global Equations section.
//    In the table, enter the following settings:

    model.component("comp1").physics("ge").feature("ge1").setIndex("name", "W", 0, 0);
    model.component("comp1").physics("ge").feature("ge1")
         .setIndex("equation", "Wt-intdisc(x*mef.FLtzy-y*mef.FLtzx)/mass1.Izz", 0, 0);
    model.component("comp1").physics("ge").feature("ge1").setIndex("initialValueU", "2*pi*dV0", 0, 0);
    model.component("comp1").physics("ge").feature("ge1").setIndex("description", "Angular Velocity", 0, 0);

//    Locate the Units section.
//    Click Select Dependent Variable Quantity.
//    In the Physical Quantity dialog, type angularfrequency in the text field.
//    In the tree, select General > Angular frequency (rad/s).
//    Click OK.

    model.component("comp1").physics("ge").feature("ge1").set("DependentVariableQuantity", "angularfrequency");

//    In the Settings window for Global Equations, locate the Units section.
//    Click Select Source Term Quantity.
//    In the Physical Quantity dialog, type angularacceleration in the text field.
//    In the tree, select General > Angular acceleration (rad/s^2).
//    Click OK.

    model.component("comp1").physics("ge").feature("ge1").set("SourceTermQuantity", "angularacceleration");

//    This is the differential equation that describes the dynamics of the disc.
//    In the Model Builder window, right-click Component 1 (comp1) > Definitions and choose Variables.

    model.component("comp1").variable().create("var1");

//    In the Settings window for Variables, locate the Variables section.
//    In the table, enter the following settings:

    model.component("comp1").variable("var1").set("axialTorque", "-intdisc(x*mef.FLtzy-y*mef.FLtzx)");
    model.component("comp1").variable("var1").descr("axialTorque", "Axial torque");
    model.component("comp1").variable("var1").set("totalHeating", "intdisc(mef.Qh)");
    model.component("comp1").variable("var1").descr("totalHeating", "Total heating");

//    In the Definitions toolbar, click Probes and choose Global Variable Probe.

    model.component("comp1").probe().create("var1", "GlobalVariable");

//    In the Settings window for Global Variable Probe, click to expand the Table and Window Settings section.
//    From the Plot window list, select New window.

    model.component("comp1").probe("var1").set("window", "new");

//    In the Definitions toolbar, click Probes and choose Global Variable Probe.

    model.component("comp1").probe().create("var2", "GlobalVariable");

//    In the Settings window for Global Variable Probe, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Definitions > Variables > axialTorque - Axial torque - N·m.

    model.component("comp1").probe("var2").set("expr", "axialTorque");
    model.component("comp1").probe("var2").set("descr", "Axial torque");

//    Locate the Table and Window Settings section.
//    From the Plot window list, select New window.

    model.component("comp1").probe("var2").set("window", "new");

//    In the Definitions toolbar, click Probes and choose Global Variable Probe.

    model.component("comp1").probe().create("var3", "GlobalVariable");

//    In the Settings window for Global Variable Probe, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Definitions > Variables > totalHeating - Total heating - W.

    model.component("comp1").probe("var3").set("expr", "totalHeating");
    model.component("comp1").probe("var3").set("descr", "Total heating");

//    Locate the Table and Window Settings section.
//    From the Plot window list, select New window.

    model.component("comp1").probe("var3").set("window", "new");

//    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 Element Size section.
//    From the Predefined list, select Coarser.

    model.component("comp1").mesh("mesh1").feature("size").set("hauto", 7);

//    In the Model Builder window, click Size 1.
//    In the Settings window for Size, locate the Element Size section.
//    From the Predefined list, select Extremely fine.

    model.component("comp1").mesh("mesh1").feature("size1").set("hauto", 1);

//    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);

//    Select Domains 2, 3, 4.

    model.component("comp1").mesh("mesh1").feature("size1").selection().set(2, 3, 4);

//    In the Mesh toolbar, click Free Tetrahedral.

    model.component("comp1").mesh("mesh1").create("ftet1", "FreeTet");

//    In the Settings window for Free Tetrahedral, click to expand the Scale Geometry section.
//    In the z-direction scale text field, type 1.1.

    model.component("comp1").mesh("mesh1").feature("ftet1").set("zscale", 1.1);

//    Click Build All.

    model.component("comp1").mesh("mesh1").run();

//    The stationary solver will compute initial values for the time dependent solver.

    model.study("std1").feature("stat").setSolveFor("/physics/ge", false);

//    In the Model Builder window, under Study 1, click Step 1: Stationary.
//    In the Settings window for Stationary, locate the Physics and Variables Selection section.
//    In the Solve for column of the table, under Component 1 (comp1), clear the checkbox for Global ODEs and DAEs (ge).
//    In the Study toolbar, click Time Dependent.

    model.study("std1").create("time", "Transient");

//    In the Settings window for Time Dependent, locate the Study Settings section.
//    In the Output times text field, type range(0,0.5,25).

    model.study("std1").feature("time").set("tlist", "range(0,0.5,25)");

//    In the Model Builder window, click Study 1.
//    In the Settings window for Study, locate the Study Settings section.
//    Clear the Generate default plots checkbox.

    model.study("std1").setGenPlots(false);

//    In the Study toolbar, click Show Default Solver.

    model.study("std1").showAutoSequences("all");

//    For a time-dependent problem, the default error estimate will be too conservative and may result in stagnation of the iterative solver. To overcome this, solver tolerances are tuned.
//    In the Model Builder window, expand the Solution 1 (sol1) node, then click Time-Dependent Solver 1.
//    In the Settings window for Time-Dependent Solver, click to expand the Absolute Tolerance section.
//    In the Variables list, select Global Equations 1 (comp1.ODE1).
//    select Global Equations 1 (comp1.ODE1) in the Variables list.
//    From the Method list, select Unscaled.

    model.sol("sol1").feature("t1").setEntry("atolmethod", "comp1_ODE1", "unscaled");

//    From the Tolerance method list, select Manual.

    model.sol("sol1").feature("t1").setEntry("atolvaluemethod", "comp1_ODE1", "manual");

//    In the Tolerance text field, type 0.1.

    model.sol("sol1").feature("t1").setEntry("atol", "comp1_ODE1", "0.1");

//    Click to expand the Time Stepping section.
//    From the Steps taken by solver list, select Intermediate.

    model.sol("sol1").feature("t1").set("tstepsbdf", "intermediate");

//    In the Model Builder window, expand the Study 1 > Solver Configurations > Solution 1 (sol1) > Time-Dependent Solver 1 node, then click Iterative 1.
//    In the Settings window for Iterative, click to expand the Error section.
//    In the Factor in error estimate text field, type 1.

    model.sol("sol1").feature("t1").feature("i1").set("rhob", 1);

//    In the Study toolbar, click Compute.

    model.study("std1").createAutoSequences("all");

    model.component("comp1").probe("var1").genResult("none");
    model.component("comp1").probe("var2").genResult("none");
    model.component("comp1").probe("var3").genResult("none");

    model.sol("sol1").runAll();

//    During the computation, the angular velocity as a function of time has been plotted together with torque and dissipated power. Give a proper label and compare with those reported in documentation.

    model.result("pg1").set("window", "window1");
    model.result("pg1").run();

//    In the Model Builder window, under Results, click Probe Plot Group 1.
//    In the Settings window for 1D Plot Group, type Angular Velocity vs. Time in the Label text field.

    model.result("pg1").label("Angular Velocity vs. Time");
    model.result("pg2").set("window", "window2");
    model.result("pg2").set("windowtitle", "Probe Plot 2");
    model.result("pg2").run();

//    In the Model Builder window, under Results, click Probe Plot Group 2.
//    In the Settings window for 1D Plot Group, type Axial Torque vs. Time in the Label text field.

    model.result("pg2").label("Axial Torque vs. Time");
    model.result("pg3").set("window", "window3");
    model.result("pg3").set("windowtitle", "Probe Plot 3");
    model.result("pg3").run();

//    In the Model Builder window, under Results, click Probe Plot Group 3.
//    In the Settings window for 1D Plot Group, type Total Heating vs. Time in the Label text field.

    model.result("pg3").label("Total Heating vs. Time");

//    In the Results toolbar, click 3D Plot Group.

    model.result().create("pg4", "PlotGroup3D");
    model.result("pg4").run();

//    In the Settings window for 3D Plot Group, locate the Plot Settings section.
//    Clear the Plot dataset edges checkbox.

    model.result("pg4").set("edges", false);

//    Right-click 3D Plot Group 4 and choose Volume.

    model.result("pg4").create("vol1", "Volume");
    model.result("pg4").feature("vol1").set("evaluationsettings", "parent");

//    In the Settings window for Volume, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Magnetic and Electric Fields > Currents and charge > mef.normJ - Current density norm - A/m².

    model.result("pg4").feature("vol1").set("expr", "mef.normJ");
    model.result("pg4").feature("vol1").set("descr", "Current density norm");

//    Right-click Volume 1 and choose Selection.

    model.result("pg4").feature("vol1").create("sel1", "Selection");

//    Select Domain 2.

    model.result("pg4").feature("vol1").feature("sel1").selection().set(2);
    model.result("pg4").run();

//    In the Model Builder window, right-click 3D Plot Group 4 and choose Volume.

    model.result("pg4").create("vol2", "Volume");
    model.result("pg4").feature("vol2").set("evaluationsettings", "parent");

//    In the Settings window for Volume, locate the Expression section.
//    In the Expression text field, type 1.

    model.result("pg4").feature("vol2").set("expr", "1");

//    Locate the Coloring and Style section.
//    From the Coloring list, select Uniform.

    model.result("pg4").feature("vol2").set("coloring", "uniform");

//    From the Color list, select Gray.

    model.result("pg4").feature("vol2").set("color", "gray");

//    Right-click Volume 2 and choose Selection.

    model.result("pg4").feature("vol2").create("sel1", "Selection");

//    Select Domains 3, 4, 5, 6, 7.

    return model;
  }

  public static Model run2(Model model) {

    model.result("pg4").feature("vol2").feature("sel1").selection().set(3, 4, 5, 6, 7);
    model.result("pg4").run();

//    In the Model Builder window, right-click 3D Plot Group 4 and choose Arrow Surface.

    model.result("pg4").create("arws1", "ArrowSurface");
    model.result("pg4").feature("arws1").set("evaluationsettings", "parent");

//    In the Settings window for Arrow Surface, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Magnetic and Electric Fields > Currents and charge > mef.Jx,mef.Jy,mef.Jz - Current density.

    model.result("pg4").feature("arws1").set("expr", new String[]{"mef.Jx", "mef.Jy", "mef.Jz"});
    model.result("pg4").feature("arws1").set("descr", "Current density");

//    Locate the Arrow Positioning section.
//    In the Number of arrows text field, type 1000.

    model.result("pg4").feature("arws1").set("arrowcount", 1000);

//    Locate the Coloring and Style section.
//    From the Color list, select White.

    model.result("pg4").feature("arws1").set("color", "white");
    model.result("pg4").run();

//    In the Model Builder window, click 3D Plot Group 4.
//    In the Settings window for 3D Plot Group, locate the Data section.
//    From the Time (s) list, select 0.

    model.result("pg4").setIndex("looplevel", 1, 0);

//    In the 3D Plot Group 4 toolbar, click Plot.

    model.result("pg4").run();

//    Click the Zoom Extents button in the Graphics toolbar.
//    The plot shows the current density on the surface of the disc at \[t=0\] (when the disc is still spinning).
//    From the Time (s) list, select 25.

    model.result("pg4").setIndex("looplevel", 51, 0);

//    In the 3D Plot Group 4 toolbar, click Plot.

    model.result("pg4").run();

//    Now, the plot shows the current density when the disc has almost stopped.

    model.title("Magnetic Brake");

    model
         .description("A metal disk is rotating in the air gap of a magnet. Currents are induced, and the resulting Lorentz forces (JxB) yield a braking torque that slows down the disk. This 3D model computes the eddy current and Lorentz force distribution and in parallel solves a coupled ordinary differential equation for the time evolution of the angular velocity.");

    return model;
  }

  public static void main(String[] args) {
    Model model = run();
    run2(model);
  }

}
