/*
 * magnetic_damping.java
 */

import com.comsol.model.*;
import com.comsol.model.util.*;

/** Model exported on May 6 2026, 10:33 by COMSOL 6.4.0.414. */
public class magnetic_damping {

  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 > Magnetic Fields (mf).
//    Click Add.
//    In the Select Physics tree, select Structural Mechanics > Solid Mechanics (solid).
//    Click Add.
//    Click Study.
//    In the Select Study tree, select Empty Study.
//    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("mf", "InductionCurrents", "geom1");
    model.component("comp1").physics().create("solid", "SolidMechanics", "geom1");

    model.study().create("std1");

//    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("sigma", "3.774e7[S/m]");
    model.param().descr("sigma", "Material conductivity");
    model.param().set("a_c", "5e5[A]");
    model.param().descr("a_c", "Applied current on the wire");
    model.param().set("r0", "0.05[m]");
    model.param().descr("r0", "Radius of the coil");

//    The Applied current will be used as a sweep parameter.

    model.component("comp1").geom("geom1").create("blk1", "Block");
    model.component("comp1").geom("geom1").run("blk1");
    model.component("comp1").geom("geom1").create("blk2", "Block");

//    In the Model Builder window, under Component 1 (comp1), click Geometry 1.
//    In the Geometry toolbar, click Block to create a block for the simulation domain. Leave the default block size.
//    In the Geometry toolbar, click Block again to create a block for the cantilever beam.
//    In the Model Builder window, under Component 1 (comp1) > Geometry 1, click Block 2 (blk2).
//    In the Settings window for Block, type Cantilever Beam in the Label text field.

    model.component("comp1").geom("geom1").feature("blk2").label("Cantilever Beam");

//    Locate the Size and Shape section.
//    In the Width text field, type 0.9.

    model.component("comp1").geom("geom1").feature("blk2").set("size", new double[]{0.9, 1, 1});

//    In the Depth text field, type 0.025.

    model.component("comp1").geom("geom1").feature("blk2").set("size", new double[]{0.9, 0.025, 1});

//    In the Height text field, type 0.1.

    model.component("comp1").geom("geom1").feature("blk2").set("size", new double[]{0.9, 0.025, 0.1});

//    Locate the Position section.
//    In the y text field, type 0.575.

    model.component("comp1").geom("geom1").feature("blk2").set("pos", new double[]{0, 0.575, 0});

//    In the z text field, type 0.45.

    model.component("comp1").geom("geom1").feature("blk2").set("pos", new double[]{0, 0.575, 0.45});

//    Locate the Selections of Resulting Entities section.
//    Select the Resulting objects selection checkbox.

    model.component("comp1").geom("geom1").feature("blk2").set("selresult", true);

//    Finally, add a cylinder for the wire generating the static magnetic field.
//    In the Geometry toolbar, click Cylinder.

    model.component("comp1").geom("geom1").run("blk2");
    model.component("comp1").geom("geom1").create("cyl1", "Cylinder");

//    In the Settings window for Cylinder, type Cylindrical Coil in the Label text field.

    model.component("comp1").geom("geom1").feature("cyl1").label("Cylindrical Coil");

//    Locate the Size and Shape section.
//    In the Radius text field, type r0.

    model.component("comp1").geom("geom1").feature("cyl1").set("r", "r0");

//    Locate the Position section.
//    In the x text field, type 0.5.

    model.component("comp1").geom("geom1").feature("cyl1").set("pos", new double[]{0.5, 0, 0});

//    In the y text field, type 0.5.

    model.component("comp1").geom("geom1").feature("cyl1").set("pos", new double[]{0.5, 0.5, 0});

//    Locate the Selections of Resulting Entities section.
//    Select the Resulting objects selection checkbox.

    model.component("comp1").geom("geom1").feature("cyl1").set("selresult", true);

//    Click Build All Objects.

    model.component("comp1").geom("geom1").runPre("fin");

//    Click the Wireframe Rendering button in the Graphics toolbar.

    model.component("comp1").view("view1").set("renderwireframe", true);

//    Add variables for the induced current density and body force on the cantilever beam.

    model.component("comp1").geom("geom1").run();

//    In the Physics toolbar, click Domains and choose Ampère's Law in Solids.

    model.component("comp1").physics("mf").create("als1", "AmperesLawSolid", 3);

//    In the Settings window for Ampère's Law in Solids, locate the Domain Selection section.
//    From the Selection list, select Cantilever Beam.

    model.component("comp1").physics("mf").feature("als1").selection().named("geom1_blk2_dom");

//    In the Physics toolbar, click Domains and choose Domain Coil.

    model.component("comp1").physics("mf").create("coil1", "Coil", 3);

//    In the Settings window for Domain Coil, locate the Domain Selection section.
//    From the Selection list, select Cylindrical Coil.

    model.component("comp1").physics("mf").feature("coil1").selection().named("geom1_cyl1_dom");

//    Locate the Coil section.
//    From the Conductor model list, select Homogenized multiturn.

    model.component("comp1").physics("mf").feature("coil1").set("ConductorModel", "Multi");

//    From the Coil type list, select Linear.

    model.component("comp1").physics("mf").feature("coil1").set("CoilType", "Linear");

//    In the \[I_{\textrm{coil}}\] text field, type a_c.

    model.component("comp1").physics("mf").feature("coil1").set("ICoil", "a_c");

//    Locate the Homogenized Conductor section.
//    In the \[N\] text field, type 1.

    model.component("comp1").physics("mf").feature("coil1").set("N", 1);

//    From the Coil wire cross-section area list, select From diameter.

    model.component("comp1").physics("mf").feature("coil1").set("AreaFrom", "Diameter");

//    In the \[d\] text field, type 2*r0.

    model.component("comp1").physics("mf").feature("coil1").set("coilWindDiameter", "2*r0");

//    In the Model Builder window, click Coil Geometry 1.
//    Select Edge 25.

    model.component("comp1").physics("mf").feature("coil1").feature("cre1").selection().set(25);

//    The Free Space feature adds a small electric conductivity to the surrounding volume for numerical stabilization.
//    In the Model Builder window, under Component 1 (comp1) > Magnetic Fields (mf), click Free Space 1.
//    In the Settings window for Free Space, locate the Stabilization section.
//    From the \[\sigma_\textrm{stab}\] list, select User defined.

    model.component("comp1").physics("mf").feature("fsp1").set("sigma_stab_mat", "userdef");

//    In the associated text field, type 10[S/m].

    model.component("comp1").physics("mf").feature("fsp1")
         .set("sigma_stab", new String[]{"10[S/m]", "0", "0", "0", "10[S/m]", "0", "0", "0", "10[S/m]"});

//    The Solid Mechanics interface is active only on the cantilever beam.
//    In the Model Builder window, under Component 1 (comp1), click Solid Mechanics (solid).
//    In the Settings window for Solid Mechanics, locate the Domain Selection section.
//    From the Selection list, select Cantilever Beam.

    model.component("comp1").physics("solid").selection().named("geom1_blk2_dom");

//    Add a damping factor on Linear Elastic Material Model 1 .
//    In the Model Builder window, under Component 1 (comp1) > Solid Mechanics (solid), click Linear Elastic Material 1.
//    In the Physics toolbar, click Attributes and choose Damping.

    model.component("comp1").physics("solid").feature("lemm1").create("dmp1", "Damping", 3);

//    In the Settings window for Damping, locate the Damping Settings section.
//    From the Damping type list, select Isotropic loss factor.

    model.component("comp1").physics("solid").feature("lemm1").feature("dmp1")
         .set("DampingType", "IsotropicLossFactor");

//    From the \[\eta_{\textrm{s}}\] list, select User defined.

    model.component("comp1").physics("solid").feature("lemm1").feature("dmp1").set("eta_s_mat", "userdef");

//    In the associated text field, type 0.1.

    model.component("comp1").physics("solid").feature("lemm1").feature("dmp1").set("eta_s", 0.1);

//    In the Physics toolbar, click Boundaries and choose Fixed Constraint.

    model.component("comp1").physics("solid").create("fix1", "Fixed", 2);

//    Select Boundary 5.

    model.component("comp1").physics("solid").feature("fix1").selection().set(5);

//    In the Physics toolbar, click Boundaries and choose Boundary Load.

    model.component("comp1").physics("solid").create("bndl1", "BoundaryLoad", 2);

//    Select Boundary 17.

    model.component("comp1").physics("solid").feature("bndl1").selection().set(17);

//    In the Settings window for Boundary Load, type Harmonic Boundary Load for Frequency-Domain Vibration Analysis in the Label text field.

    model.component("comp1").physics("solid").feature("bndl1")
         .label("Harmonic Boundary Load for Frequency-Domain Vibration Analysis");

//    Locate the Force section.
//    Specify the \[\mathbf{f}_{\mathrm{A}}\] vector as

    model.component("comp1").physics("solid").feature("bndl1")
         .set("forceReferenceArea", new String[]{"0", "1e4", "0"});

//    Right-click Harmonic Boundary Load for Frequency-Domain Vibration Analysis and choose Harmonic Perturbation.

    model.component("comp1").physics("solid").feature("bndl1").set("harmonicPerturbation", true);

//    In the Physics toolbar, click Boundaries and choose Boundary Load.

    model.component("comp1").physics("solid").create("bndl2", "BoundaryLoad", 2);

//    Select Boundary 17.

    model.component("comp1").physics("solid").feature("bndl2").selection().set(17);

//    In the Settings window for Boundary Load, type Boundary Load for Time-Dependent Analysis in the Label text field.

    model.component("comp1").physics("solid").feature("bndl2").label("Boundary Load for Time-Dependent Analysis");

//    Locate the Force section.
//    Specify the \[\mathbf{f}_{\mathrm{A}}\] vector as

    model.component("comp1").physics("solid").feature("bndl2")
         .set("forceReferenceArea", new String[]{"0", "1e4", "0"});

//    In the Materials toolbar, click Add Material to open the Add Material window.
//    In the tree, select Built-in > Aluminum.
//    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("Murnaghan", "Murnaghan", "Murnaghan");
    model.component("comp1").material("mat1").label("Aluminum");
    model.component("comp1").material("mat1").set("family", "aluminum");
    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("heatcapacity", "900[J/(kg*K)]");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("thermalconductivity", new String[]{"238[W/(m*K)]", "0", "0", "0", "238[W/(m*K)]", "0", "0", "0", "238[W/(m*K)]"});
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("electricconductivity", new String[]{"3.774e7[S/m]", "0", "0", "0", "3.774e7[S/m]", "0", "0", "0", "3.774e7[S/m]"});
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("relpermittivity", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("thermalexpansioncoefficient", new String[]{"23e-6[1/K]", "0", "0", "0", "23e-6[1/K]", "0", "0", "0", "23e-6[1/K]"});
    model.component("comp1").material("mat1").propertyGroup("def").set("density", "2700[kg/m^3]");
    model.component("comp1").material("mat1").propertyGroup("Enu").set("E", "70[GPa]");
    model.component("comp1").material("mat1").propertyGroup("Enu").set("nu", "0.33");
    model.component("comp1").material("mat1").propertyGroup("Murnaghan").set("l", "-250[GPa]");
    model.component("comp1").material("mat1").propertyGroup("Murnaghan").set("m", "-330[GPa]");
    model.component("comp1").material("mat1").propertyGroup("Murnaghan").set("n", "-350[GPa]");

//    In the Materials toolbar, click Add Material to close the Add Material window.
//    In the Settings window for Material, locate the Geometric Entity Selection section.
//    From the Selection list, select Cantilever Beam.

    model.component("comp1").material("mat1").selection().named("geom1_blk2_dom");

//    In the Physics toolbar, click Multiphysics Couplings and choose Domain > Magnetomechanics, Solid.

    model.component("comp1").multiphysics().create("mmcpl1", "Magnetomechanics", 3);

//    In the Settings window for Magnetomechanics, Solid, locate the Lorentz Coupling section.
//    Select the Only use Lorentz force checkbox.

    model.component("comp1").multiphysics("mmcpl1").set("OnlyLorentz", true);

//    In the Model Builder window, under Component 1 (comp1), click Mesh 1.
//    In the Settings window for Mesh, locate the Physics-Controlled Mesh section.
//    From the Element size list, select Coarser.

    model.component("comp1").mesh("mesh1").autoMeshSize(7);

//    In the Model Builder window, click Study 1.
//    In the Settings window for Study, type Frequency-Domain Vibration Analysis in the Label text field.

    model.study("std1").label("Frequency-Domain Vibration Analysis");

//    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", "sigma", 0);
    model.study("std1").feature("param").setIndex("plistarr", "", 0);
    model.study("std1").feature("param").setIndex("punit", "S/m", 0);
    model.study("std1").feature("param").setIndex("pname", "sigma", 0);
    model.study("std1").feature("param").setIndex("plistarr", "", 0);
    model.study("std1").feature("param").setIndex("punit", "S/m", 0);

//    In the table, enter the following settings:

    model.study("std1").feature("param").setIndex("pname", "a_c", 0);
    model.study("std1").feature("param").setIndex("plistarr", "0[A] 500000[A]", 0);

//    In the Study toolbar, click Stationary.

    model.study("std1").create("stat", "Stationary");
    model.study("std1").feature("stat").setSolveFor("/physics/solid", false);

//    In the Settings window for Stationary, locate the Physics and Variables Selection section.

    model.study("std1").feature("stat").setSolveFor("/multiphysics/mmcpl1", false);

//    In the Solve for column of the table, under Component 1 (comp1), clear the checkbox for Solid Mechanics (solid).
//    In the Solve for column of the table, under Component 1 (comp1) > Multiphysics, clear the checkbox for Magnetomechanics, Solid 1 (mmcpl1).
//    In the Study toolbar, click More Study Steps and choose Frequency Domain > Frequency-Domain Perturbation.

    model.study("std1").create("frlin", "Frequencylinearized");

//    In the Settings window for Frequency-Domain Perturbation, locate the Study Settings section.
//    In the Frequencies text field, type range(5,0.5,50).

    model.study("std1").feature("frlin").set("plist", "range(5,0.5,50)");

//    Locate the Physics and Variables Selection section.
//    Select the Modify model configuration for study step checkbox.

    model.study("std1").feature("frlin").set("useadvanceddisable", true);

//    In the tree, select Component 1 (comp1) > Solid Mechanics (solid) > Boundary Load for Time-Dependent Analysis.
//    Right-click and choose Disable.

    model.study("std1").feature("frlin").set("disabledphysics", new String[]{"solid/bndl2"});

//    In the Study toolbar, click Show Default Solver.

    model.study("std1").showAutoSequences("all");

//    Some adjustments to the default solver settings will improve the performance.
//    In the Model Builder window, expand the Solution 1 (sol1) node.
//    In the Model Builder window, expand the Frequency-Domain Vibration Analysis > Solver Configurations > Solution 1 (sol1) > Stationary Solver 2 node, then click Fully Coupled 1.
//    In the Settings window for Fully Coupled, locate the General section.
//    From the Linear solver list, select Direct.

    model.sol("sol1").feature("s2").feature("fc1").set("linsolver", "dDef");

//    In the Study toolbar, click Compute.

    model.study("std1").createAutoSequences("all");

    model.sol().create("sol3");
    model.sol("sol3").study("std1");
    model.sol("sol3").label("Parametric Solutions 1");

    model.batch("p1").feature("so1").set("psol", "sol3");
    model.batch("p1").run("compute");

    model.result().create("pg1", "PlotGroup3D");
    model.result("pg1").label("Magnetic Flux Density (mf)");
    model.result("pg1").set("data", "dset3");
    model.result("pg1").setIndex("looplevel", 91, 0);
    model.result("pg1").setIndex("looplevel", 2, 1);
    model.result("pg1").set("frametype", "spatial");
    model.result("pg1").set("showlegendsmaxmin", true);
    model.result("pg1").feature().create("mslc1", "Multislice");
    model.result("pg1").feature("mslc1").set("solutionparams", "parent");
    model.result("pg1").feature("mslc1").set("multiplanexmethod", "coord");
    model.result("pg1").feature("mslc1").set("xcoord", "mf.CPx");
    model.result("pg1").feature("mslc1").set("multiplaneymethod", "coord");
    model.result("pg1").feature("mslc1").set("ycoord", "mf.CPy");
    model.result("pg1").feature("mslc1").set("multiplanezmethod", "coord");
    model.result("pg1").feature("mslc1").set("zcoord", "mf.CPz");
    model.result("pg1").feature("mslc1").set("colortable", "Prism");
    model.result("pg1").feature("mslc1").set("colortabletrans", "nonlinear");
    model.result("pg1").feature("mslc1").set("colorcalibration", -0.8);
    model.result("pg1").feature("mslc1").set("evaluationsettings", "parent");
    model.result("pg1").feature("mslc1").set("data", "parent");
    model.result("pg1").feature().create("strmsl1", "StreamlineMultislice");
    model.result("pg1").feature("strmsl1").set("solutionparams", "parent");
    model.result("pg1").feature("strmsl1").set("multiplanexmethod", "coord");
    model.result("pg1").feature("strmsl1").set("xcoord", "mf.CPx");
    model.result("pg1").feature("strmsl1").set("multiplaneymethod", "coord");
    model.result("pg1").feature("strmsl1").set("ycoord", "mf.CPy");
    model.result("pg1").feature("strmsl1").set("multiplanezmethod", "coord");
    model.result("pg1").feature("strmsl1").set("zcoord", "mf.CPz");
    model.result("pg1").feature("strmsl1").set("titletype", "none");
    model.result("pg1").feature("strmsl1").set("posmethod", "uniform");
    model.result("pg1").feature("strmsl1").set("udensity", 8);
    model.result("pg1").feature("strmsl1").set("color", "black");
    model.result("pg1").feature("strmsl1").set("evaluationsettings", "parent");
    model.result("pg1").feature("strmsl1").set("maxlen", 0.4);
    model.result("pg1").feature("strmsl1").set("maxtime", Double.POSITIVE_INFINITY);
    model.result("pg1").feature("strmsl1").set("inheritcolor", false);
    model.result("pg1").feature("strmsl1").set("maxtime", Double.POSITIVE_INFINITY);
    model.result("pg1").feature("strmsl1").set("data", "parent");
    model.result("pg1").feature("strmsl1").set("inheritplot", "mslc1");
    model.result("pg1").feature("strmsl1").feature().create("tran1", "Transparency");
    model.result("pg1").feature("strmsl1").feature("tran1").set("transparency", 0.9);
    model.result("pg1").feature("strmsl1").feature().create("filt1", "Filter");
    model.result("pg1").feature("strmsl1").feature("filt1").set("expr", "!isScalingSystemDomain");
    model.result().dataset("dset3").set("frametype", "spatial");
    model.result().create("pg2", "PlotGroup3D");
    model.result("pg2").set("data", "dset3");
    model.result("pg2").setIndex("looplevel", 91, 0);
    model.result("pg2").setIndex("looplevel", 2, 1);
    model.result("pg2").set("frametype", "spatial");
    model.result("pg2").label("Stress (solid)");
    model.result("pg2").set("frametype", "spatial");
    model.result("pg2").create("vol1", "Volume");
    model.result("pg2").feature("vol1").set("expr", new String[]{"solid.misesGp_peak"});
    model.result("pg2").feature("vol1").set("threshold", "manual");
    model.result("pg2").feature("vol1").set("thresholdvalue", 0.2);
    model.result("pg2").feature("vol1").set("colortable", "Rainbow");
    model.result("pg2").feature("vol1").set("colortabletrans", "none");
    model.result("pg2").feature("vol1").set("colorscalemode", "linear");
    model.result("pg2").feature("vol1").set("resolution", "custom");
    model.result("pg2").feature("vol1").set("refine", 2);
    model.result("pg2").feature("vol1").set("colortable", "Prism");
    model.result("pg2").feature("vol1").create("def", "Deform");
    model.result("pg2").feature("vol1").feature("def").set("differential", true);
    model.result("pg2").feature("vol1").feature("def").set("expr", new String[]{"u", "v", "w"});
    model.result("pg2").feature("vol1").feature("def").set("descr", "Displacement field");
    model.result("pg1").run();

//    In the Settings window for 3D Plot Group, type DC Magnetic Flux Density Norm in the Label text field.

    model.result("pg1").label("DC Magnetic Flux Density Norm");
    model.result("pg1").run();

//    In the Model Builder window, expand the DC Magnetic Flux Density Norm node, then click Multislice 1.
//    In the Settings window for Multislice, locate the Expression section.
//    From the Expression evaluated for list, select Static solution.

    model.result("pg1").feature("mslc1").set("evalmethod", "linpoint");
    model.result("pg1").run();

//    In the Model Builder window, click Streamline Multislice 1.
//    In the Settings window for Streamline Multislice, locate the Expression section.
//    From the Expression evaluated for list, select Static solution.

    model.result("pg1").feature("strmsl1").set("evalmethod", "linpoint");
    model.result("pg1").run();

//    In the Model Builder window, click DC Magnetic Flux Density Norm.
//    In the DC Magnetic Flux Density Norm toolbar, click Plot.

    model.result("pg1").run();

//    Click the Go to Default View button in the Graphics toolbar.
//    Right-click DC Magnetic Flux Density Norm and choose Duplicate.

    model.result().duplicate("pg3", "pg1");
    model.result("pg3").run();

//    Drag and drop DC Magnetic Flux Density Norm 1 below DC Magnetic Flux Density Norm.

    model.result().move("pg3", 1);

//    The second plot group will show the AC magnetic flux density. Improve it by plotting the data in the cantilever beam only.
//    In the Settings window for 3D Plot Group, type AC Magnetic Flux Density Norm in the Label text field.

    model.result("pg3").label("AC Magnetic Flux Density Norm");
    model.result("pg3").run();

//    In the Model Builder window, expand the AC Magnetic Flux Density Norm node, then click Multislice 1.
//    In the Settings window for Multislice, locate the Expression section.
//    From the Expression evaluated for list, select Harmonic perturbation.

    model.result("pg3").feature("mslc1").set("evalmethod", "harmonic");

//    Right-click Multislice 1 and choose Selection.

    model.result("pg3").feature("mslc1").create("sel1", "Selection");

//    Select Domain 2.

    model.result("pg3").feature("mslc1").feature("sel1").selection().set(2);
    model.result("pg3").run();

//    In the Model Builder window, under Results > AC Magnetic Flux Density Norm, click Streamline Multislice 1.
//    In the Settings window for Streamline Multislice, locate the Expression section.
//    From the Expression evaluated for list, select Harmonic perturbation.

    model.result("pg3").feature("strmsl1").set("evalmethod", "harmonic");

//    Right-click Streamline Multislice 1 and choose Selection.

    model.result("pg3").feature("strmsl1").create("sel1", "Selection");

//    Select Domain 2.

    model.result("pg3").feature("strmsl1").feature("sel1").selection().set(2);
    model.result("pg3").run();

//    In the Model Builder window, under Results, click AC Magnetic Flux Density Norm.
//    In the AC Magnetic Flux Density Norm toolbar, click Plot.

    model.result("pg3").run();

//    The plot now shows the magnitude of the AC magnetic flux density in the beam only.

    model.result("pg2").run();

//    In the Model Builder window, expand the Results > Stress (solid) node, then click Volume 1.
//    In the Settings window for Volume, locate the Expression section.
//    Clear the Compute differential checkbox.
//    In the Stress (solid) toolbar, click Plot.

    model.result("pg2").run();

//    This plot shows the peak von Mises stress in the beam.
//    Next, add a plot for the AC currents in the beam.

    model.result("pg3").run();

//    In the Model Builder window, right-click AC Magnetic Flux Density Norm and choose Duplicate.

    model.result().duplicate("pg4", "pg3");
    model.result("pg4").run();

//    In the Settings window for 3D Plot Group, type AC Electric Current Density in the Label text field.

    model.result("pg4").label("AC Electric Current Density");
    model.result("pg4").run();

//    In the Model Builder window, expand the AC Electric Current Density node, then click Multislice 1.
//    In the Settings window for Multislice, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Magnetic Fields > Currents and charge > mf.normJ - Current density norm - A/m².

    model.result("pg4").feature("mslc1").set("expr", "mf.normJ");
    model.result("pg4").feature("mslc1").set("descr", "Current density norm");
    model.result("pg4").run();

//    In the Model Builder window, click Streamline Multislice 1.
//    In the Settings window for Streamline Multislice, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Magnetic Fields > Currents and charge > mf.Jx,...,mf.Jz - Current density (spatial frame).

    model.result("pg4").feature("strmsl1").set("expr", new String[]{"mf.Jx", "mf.Jy", "mf.Jz"});
    model.result("pg4").feature("strmsl1").set("descr", "Current density (spatial frame)");

//    In the AC Electric Current Density toolbar, click Plot.

    model.result("pg4").run();

//    The AC eddy currents circulate within the beam.
//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg5", "PlotGroup1D");
    model.result("pg5").run();

//    In the Settings window for 1D Plot Group, type RMS Displacement vs. Frequency in the Label text field.

    model.result("pg5").label("RMS Displacement vs. Frequency");

//    Locate the Data section.
//    From the Dataset list, select Frequency-Domain Vibration Analysis/Parametric Solutions 1 (sol3).

    model.result("pg5").set("data", "dset3");

//    Right-click RMS Displacement vs. Frequency and choose Point Graph.

    model.result("pg5").create("ptgr1", "PointGraph");
    model.result("pg5").feature("ptgr1").set("markerpos", "datapoints");
    model.result("pg5").feature("ptgr1").set("linewidth", "preference");

//    Select Point 18.

    model.result("pg5").feature("ptgr1").selection().set(18);

//    In the Settings window for Point Graph, click Replace Expression in the upper-right corner of the y-Axis Data section.
//    From the menu, choose Component 1 (comp1) > Solid Mechanics > Displacement > solid.disp_rms - Displacement, RMS - m.

    model.result("pg5").feature("ptgr1").set("expr", "solid.disp_rms");
    model.result("pg5").feature("ptgr1").set("descr", "Displacement, RMS");

//    Click to expand the Legends section.
//    Select the Show legends checkbox.

    model.result("pg5").feature("ptgr1").set("legend", true);

//    In the RMS Displacement vs. Frequency toolbar, click Plot.

    model.result("pg5").run();

//    Now add a transient study to the model for comparison.
//    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 Time-Dependent Analysis in the Label text field.

    model.study("std2").label("Time-Dependent Analysis");

//    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", "sigma", 0);
    model.study("std2").feature("param").setIndex("plistarr", "", 0);
    model.study("std2").feature("param").setIndex("punit", "S/m", 0);
    model.study("std2").feature("param").setIndex("pname", "sigma", 0);
    model.study("std2").feature("param").setIndex("plistarr", "", 0);
    model.study("std2").feature("param").setIndex("punit", "S/m", 0);

//    In the table, enter the following settings:

    model.study("std2").feature("param").setIndex("pname", "a_c", 0);
    model.study("std2").feature("param").setIndex("plistarr", "0[A] 500000[A]", 0);
    model.study("std2").feature("stat").setSolveFor("/physics/solid", false);

//    In the Model Builder window, click Step 1: Stationary.
//    In the Settings window for Stationary, locate the Physics and Variables Selection section.

    model.study("std2").feature("stat").setSolveFor("/multiphysics/mmcpl1", false);

//    In the Solve for column of the table, under Component 1 (comp1), clear the checkbox for Solid Mechanics (solid).
//    In the Solve for column of the table, under Component 1 (comp1) > Multiphysics, clear the checkbox for Magnetomechanics, Solid 1 (mmcpl1).
//    In the Study toolbar, click Time Dependent.

    model.study("std2").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.001,0.1).

    model.study("std2").feature("time").set("tlist", "range(0,0.001,0.1)");

//    Locate the Physics and Variables Selection section.
//    Select the Modify model configuration for study step checkbox.

    model.study("std2").feature("time").set("useadvanceddisable", true);

//    In the tree, select Component 1 (comp1) > Solid Mechanics (solid) > Harmonic Boundary Load for Frequency-Domain Vibration Analysis.
//    Right-click and choose Disable.

    model.study("std2").feature("time").set("disabledphysics", new String[]{"solid/bndl1"});

//    To significantly reduce the computation time, it is also possible to tweak tolerances and solve the magnetic fields problem with a direct solver, since the air domain has a finite conductivity and the induced current acts as a gauge.
//    Locate the Study Settings section.
//    From the Tolerance list, select User controlled.

    return model;
  }

  public static Model run2(Model model) {

    model.study("std2").feature("time").set("usertol", true);

//    In the Study toolbar, click Show Default Solver.

    model.study("std2").showAutoSequences("all");

//    In the Model Builder window, expand the Solution 6 (sol6) node.
//    In the Model Builder window, expand the Time-Dependent Analysis > Solver Configurations > Solution 6 (sol6) > Dependent Variables 2 node, then click Magnetic Vector Potential (Spatial Frame) (comp1.A).
//    In the Settings window for Field, locate the Scaling section.
//    From the Method list, select None.

    model.sol("sol6").feature("v2").feature("comp1_A").set("scalemethod", "none");

//    In the Model Builder window, under Time-Dependent Analysis > Solver Configurations > Solution 6 (sol6) > Dependent Variables 2, click Filtering Variable (comp1.mf.coil1.Vf).
//    In the Settings window for Field, locate the Scaling section.
//    From the Method list, select None.

    model.sol("sol6").feature("v2").feature("comp1_mf_coil1_Vf").set("scalemethod", "none");

//    In the Study toolbar, click Compute.

    model.study("std2").createAutoSequences("all");

    model.sol().create("sol8");
    model.sol("sol8").study("std2");
    model.sol("sol8").label("Parametric Solutions 2");

    model.batch("p2").feature("so1").set("psol", "sol8");
    model.batch("p2").run("compute");

    model.result().create("pg6", "PlotGroup3D");
    model.result("pg6").label("Magnetic Flux Density (mf)");
    model.result("pg6").set("data", "dset6");
    model.result("pg6").set("frametype", "spatial");
    model.result("pg6").set("showlegendsmaxmin", true);
    model.result("pg6").feature().create("mslc1", "Multislice");
    model.result("pg6").feature("mslc1").set("solutionparams", "parent");
    model.result("pg6").feature("mslc1").set("multiplanexmethod", "coord");
    model.result("pg6").feature("mslc1").set("xcoord", "mf.CPx");
    model.result("pg6").feature("mslc1").set("multiplaneymethod", "coord");
    model.result("pg6").feature("mslc1").set("ycoord", "mf.CPy");
    model.result("pg6").feature("mslc1").set("multiplanezmethod", "coord");
    model.result("pg6").feature("mslc1").set("zcoord", "mf.CPz");
    model.result("pg6").feature("mslc1").set("colortable", "Prism");
    model.result("pg6").feature("mslc1").set("colortabletrans", "nonlinear");
    model.result("pg6").feature("mslc1").set("colorcalibration", -0.8);
    model.result("pg6").feature("mslc1").set("evaluationsettings", "parent");
    model.result("pg6").feature("mslc1").set("data", "parent");
    model.result("pg6").feature().create("strmsl1", "StreamlineMultislice");
    model.result("pg6").feature("strmsl1").set("solutionparams", "parent");
    model.result("pg6").feature("strmsl1").set("multiplanexmethod", "coord");
    model.result("pg6").feature("strmsl1").set("xcoord", "mf.CPx");
    model.result("pg6").feature("strmsl1").set("multiplaneymethod", "coord");
    model.result("pg6").feature("strmsl1").set("ycoord", "mf.CPy");
    model.result("pg6").feature("strmsl1").set("multiplanezmethod", "coord");
    model.result("pg6").feature("strmsl1").set("zcoord", "mf.CPz");
    model.result("pg6").feature("strmsl1").set("titletype", "none");
    model.result("pg6").feature("strmsl1").set("posmethod", "uniform");
    model.result("pg6").feature("strmsl1").set("udensity", 8);
    model.result("pg6").feature("strmsl1").set("color", "black");
    model.result("pg6").feature("strmsl1").set("evaluationsettings", "parent");
    model.result("pg6").feature("strmsl1").set("maxlen", 0.4);
    model.result("pg6").feature("strmsl1").set("maxtime", Double.POSITIVE_INFINITY);
    model.result("pg6").feature("strmsl1").set("inheritcolor", false);
    model.result("pg6").feature("strmsl1").set("maxtime", Double.POSITIVE_INFINITY);
    model.result("pg6").feature("strmsl1").set("data", "parent");
    model.result("pg6").feature("strmsl1").set("inheritplot", "mslc1");
    model.result("pg6").feature("strmsl1").feature().create("tran1", "Transparency");
    model.result("pg6").feature("strmsl1").feature("tran1").set("transparency", 0.9);
    model.result("pg6").feature("strmsl1").feature().create("filt1", "Filter");
    model.result("pg6").feature("strmsl1").feature("filt1").set("expr", "!isScalingSystemDomain");
    model.result().create("pg7", "PlotGroup3D");
    model.result("pg7").set("data", "dset6");
    model.result("pg7").label("Stress (solid) 1");
    model.result("pg7").set("frametype", "spatial");
    model.result("pg7").create("vol1", "Volume");
    model.result("pg7").feature("vol1").set("expr", new String[]{"solid.misesGp"});
    model.result("pg7").feature("vol1").set("threshold", "manual");
    model.result("pg7").feature("vol1").set("thresholdvalue", 0.2);
    model.result("pg7").feature("vol1").set("colortable", "Rainbow");
    model.result("pg7").feature("vol1").set("colortabletrans", "none");
    model.result("pg7").feature("vol1").set("colorscalemode", "linear");
    model.result("pg7").feature("vol1").set("resolution", "custom");
    model.result("pg7").feature("vol1").set("refine", 2);
    model.result("pg7").feature("vol1").set("colortable", "Prism");
    model.result("pg7").feature("vol1").create("def", "Deform");
    model.result("pg7").feature("vol1").feature("def").set("expr", new String[]{"u", "v", "w"});
    model.result("pg7").feature("vol1").feature("def").set("descr", "Displacement field");
    model.result("pg6").run();

//    In the Magnetic Flux Density (mf) toolbar, click Plot.

    model.result("pg6").run();

//    The next plot shows the von Mises stress in the beam at the end of the transient study.

    model.result("pg7").run();

//    In the Model Builder window, click Stress (solid) 1.
//    In the Stress (solid) 1 toolbar, click Plot.

    model.result("pg7").run();

//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg8", "PlotGroup1D");
    model.result("pg8").run();

//    In the Settings window for 1D Plot Group, type Displacement vs. Time in the Label text field.

    model.result("pg8").label("Displacement vs. Time");

//    Locate the Data section.
//    From the Dataset list, select Time-Dependent Analysis/Parametric Solutions 2 (sol8).

    model.result("pg8").set("data", "dset6");

//    Right-click Displacement vs. Time and choose Point Graph.

    model.result("pg8").create("ptgr1", "PointGraph");
    model.result("pg8").feature("ptgr1").set("markerpos", "datapoints");
    model.result("pg8").feature("ptgr1").set("linewidth", "preference");

//    Select Point 18.

    model.result("pg8").feature("ptgr1").selection().set(18);

//    In the Settings window for Point Graph, locate the y-Axis Data section.
//    In the Expression text field, type solid.disp.

    model.result("pg8").feature("ptgr1").set("expr", "solid.disp");

//    Locate the Legends section.
//    Select the Show legends checkbox.

    model.result("pg8").feature("ptgr1").set("legend", true);

//    In the Displacement vs. Time toolbar, click Plot.

    model.result("pg8").run();

    model.title("Magnetic Damping of Vibrating Conducting Solids");

    model
         .description("When a conductive solid material moves through a static magnetic field, an eddy current is induced. The current that flows through the conductor, which is itself moving through the magnetic field, induces a Lorentz force back on the solid. Therefore, a conductive solid that is vibrating in a static magnetic field will experience a structural damping. The effect of the magnetic damping is computed in two different ways in this example. First, by harmonically exciting a cantilever beam across a range of frequencies and placing it in a strong magnetic field. The same effect is then computed in a full transient study, when the beam instead experiences a sudden applied load. The approach presented here assumes that the relative magnitude of the structural displacements are small, that the material has isotropic and linear properties, and that the magnetic field is static.");

    return model;
  }

  public static void main(String[] args) {
    Model model = run();
    run2(model);
  }

}
