/*
 * bracket_topology_optimization_stl.java
 */

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

/** Model exported on May 15 2026, 10:36 by COMSOL 6.4.0.421. */
public class bracket_topology_optimization_stl {

  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 Structural Mechanics > Solid Mechanics (solid).
//    Click Add.
//    Click Study.
//    In the Select Study tree, select Preset Studies for Selected Physics Interfaces > Optimization > Topology Optimization, 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("solid", "SolidMechanics", "geom1");

    model.study().create("std1");
    model.study("std1").create("stat", "Stationary");
    model.study("std1").create("topo", "TopologyOptimization");

    model.component("comp1").common().create("dtopo1", "DensityTopology");
    model.component("comp1").common("dtopo1").selection().all();

    model.component("comp1").material().create("toplnk1", "TopologyLink");
    model.component("comp1").material("toplnk1").set("topologySource", "dtopo1");
    model.component("comp1").material("toplnk1").selection().all();

    model.component("comp1").physics("solid").prop("ShapeProperty").set("order_displacement", 1);

    model.study("std1").feature("topo").setIndex("optobj", "comp1.solid.Ws_tot", 0);
    model.study("std1").feature("topo").set("objectivescaling", "init");
    model.study("std1").feature("topo").setIndex("constraintExpression", "comp1.dtopo1.theta_avg", 0);
    model.study("std1").feature("topo").setIndex("constraintUbound", "0.5", 0);

//    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 bracket_topology_optimization_stl_parameters.txt.
//    To import content from file, use:
//    model.param().loadFile("FILENAME");
    model.param().set("D1", "1.4[cm]", "Constraint diameter");
    model.param().set("D2", "5[cm]", "Load diameter");
    model.param().set("H", "10[cm]", "Height");
    model.param().set("W", "21.5[cm]", "Width");
    model.param().set("L", "35[cm]", "Length");
    model.param().set("thickness", "8[mm]", "Thickness of bracket");
    model.param().set("rfillet", "8[mm]", "Fillet radius");
    model.param().set("Y1", "2[cm]", "Position of constraint hole");
    model.param().set("X1", "4[cm]", "Position of constraint hole");
    model.param().set("DY1", "6[cm]", "Distance between constraint holes");
    model.param().set("YC", "-30[cm]", "Load hole position");
    model.param().set("L1", "10[cm]", "Connection plate width");
    model.param().set("rfillet2", "2[cm]", "Constraint plate fillet radius");
    model.param().set("W1", "7[cm]", "Constraint plate width");
    model.param().set("Da", "1[cm]", "Fixed hole padding");

//    Create the geometry. To simplify this step, insert a prepared geometry sequence.
//    In the Geometry toolbar, click Insert Sequence and choose Insert Sequence.

    model.component("comp1").geom("geom1").insertFile("bracket_topology_optimization_stl_geom_sequence.mph", "geom1");

//    Browse to the model's Application Library folder and double-click the file bracket_topology_optimization_stl_geom_sequence.mph.
//    In the Geometry toolbar, click Build All.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Model Builder window, under Component 1 (comp1), click Geometry 1.
//    In the Model Builder window, collapse the Geometry 1 node.
//    Add a new parameter group and a function for imposing the forces on the two large holes. The forces correspond to a torque on the bracket.
//    In the Model Builder window, under Global Definitions, click Parameters 1.
//    In the Settings window for Parameters, type Geometrical Parameters in the Label text field.

    model.param().label("Geometrical Parameters");

//    In the Home toolbar, click Parameters and choose Add > Parameters.

    model.param().create("par2");

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

    model.param("par2").set("Lmin", "5[mm]");
    model.param("par2").descr("Lmin", "Filter radius");
    model.param("par2").set("meshsz", "Lmin");
    model.param("par2").descr("meshsz", "Mesh size");
    model.param("par2").set("meshsz2", "Lmin/2");
    model.param("par2").descr("meshsz2", "Fine mesh size");
    model.param("par2").set("P0", "2.5[MPa]");
    model.param("par2").descr("P0", "Peak load intensity");

//    In the Definitions toolbar, click Analytic.

    model.component("comp1").func().create("an1", "Analytic");

//    In the Settings window for Analytic, type load in the Function name text field.

    model.component("comp1").func("an1").set("funcname", "load");

//    Locate the Definition section.
//    In the Expression text field, type F*cos(atan2(py,abs(px))).

    model.component("comp1").func("an1").set("expr", "F*cos(atan2(py,abs(px)))");

//    In the Arguments text field, type F,px,py.

    model.component("comp1").func("an1").set("args", "F,px,py");

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

    model.component("comp1").func("an1").setIndex("argunit", "Pa", 0);
    model.component("comp1").func("an1").setIndex("argunit", "m", 1);
    model.component("comp1").func("an1").setIndex("argunit", "m", 2);

//    In the Function text field, type Pa.

    model.component("comp1").func("an1").set("fununit", "Pa");

//    In the Materials toolbar, click Add Material to open the Add Material window.
//    In the tree, select Built-in > Structural steel.
//    Right-click and choose Add to Global Materials.

    model.material().create("mat1", "Common", "");
    model.material("mat1").propertyGroup().create("Enu", "Enu", "Young's modulus and Poisson's ratio");
    model.material("mat1").propertyGroup("Enu").func().create("int1", "Interpolation");
    model.material("mat1").propertyGroup("Enu").func().create("int2", "Interpolation");
    model.material("mat1").propertyGroup().create("Murnaghan", "Murnaghan", "Murnaghan");
    model.material("mat1").propertyGroup()
         .create("ElastoplasticModel", "ElastoplasticModel", "Elastoplastic material model");
    model.material("mat1").propertyGroup("ElastoplasticModel").func().create("int1", "Interpolation");
    model.material("mat1").propertyGroup().create("Ludwik", "Ludwik", "Ludwik");
    model.material("mat1").propertyGroup("Ludwik").func().create("int1", "Interpolation");
    model.material("mat1").propertyGroup().create("JohnsonCook", "JohnsonCook", "Johnson-Cook");
    model.material("mat1").propertyGroup().create("Swift", "Swift", "Swift");
    model.material("mat1").propertyGroup().create("Voce", "Voce", "Voce");
    model.material("mat1").propertyGroup("Voce").func().create("int1", "Interpolation");
    model.material("mat1").propertyGroup().create("HockettSherby", "HockettSherby", "Hockett-Sherby");
    model.material("mat1").propertyGroup("HockettSherby").func().create("int1", "Interpolation");
    model.material("mat1").propertyGroup().create("ArmstrongFrederick", "ArmstrongFrederick", "Armstrong-Frederick");
    model.material("mat1").propertyGroup("ArmstrongFrederick").func().create("int1", "Interpolation");
    model.material("mat1").propertyGroup().create("Norton", "Norton", "Norton");
    model.material("mat1").propertyGroup().create("Garofalo", "Garofalo", "Garofalo (hyperbolic sine)");
    model.material("mat1").propertyGroup()
         .create("ChabocheViscoplasticity", "ChabocheViscoplasticity", "Chaboche viscoplasticity");
    model.material("mat1").label("Structural steel");
    model.material("mat1").set("family", "custom");
    model.material("mat1")
         .set("customspecular", new double[]{0.7843137254901961, 0.7843137254901961, 0.7843137254901961});
    model.material("mat1").set("diffuse", "custom");
    model.material("mat1")
         .set("customdiffuse", new double[]{0.6666666666666666, 0.6666666666666666, 0.6666666666666666});
    model.material("mat1").set("ambient", "custom");
    model.material("mat1")
         .set("customambient", new double[]{0.6666666666666666, 0.6666666666666666, 0.6666666666666666});
    model.material("mat1").set("noise", true);
    model.material("mat1").set("fresnel", 0.9);
    model.material("mat1").set("roughness", 0.3);
    model.material("mat1").set("diffusewrap", 0);
    model.material("mat1").set("reflectance", 0);
    model.material("mat1").propertyGroup("def").set("lossfactor", "0.02");
    model.material("mat1").propertyGroup("def")
         .set("relpermeability", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.material("mat1").propertyGroup("def").set("heatcapacity", "475[J/(kg*K)]");
    model.material("mat1").propertyGroup("def")
         .set("thermalconductivity", new String[]{"44.5[W/(m*K)]", "0", "0", "0", "44.5[W/(m*K)]", "0", "0", "0", "44.5[W/(m*K)]"});
    model.material("mat1").propertyGroup("def")
         .set("electricconductivity", new String[]{"4.032e6[S/m]", "0", "0", "0", "4.032e6[S/m]", "0", "0", "0", "4.032e6[S/m]"});
    model.material("mat1").propertyGroup("def")
         .set("relpermittivity", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
    model.material("mat1").propertyGroup("def")
         .set("thermalexpansioncoefficient", new String[]{"12.3e-6[1/K]", "0", "0", "0", "12.3e-6[1/K]", "0", "0", "0", "12.3e-6[1/K]"});
    model.material("mat1").propertyGroup("def").set("density", "7850[kg/m^3]");
    model.material("mat1").propertyGroup("Enu").func("int1").set("funcname", "E");
    model.material("mat1").propertyGroup("Enu").func("int1")
         .set("table", new String[][]{{"293.15", "200e9"}, {"793.15", "166.6e9"}});
    model.material("mat1").propertyGroup("Enu").func("int1").set("extrap", "linear");
    model.material("mat1").propertyGroup("Enu").func("int1").set("fununit", new String[]{"Pa"});
    model.material("mat1").propertyGroup("Enu").func("int1").set("argunit", new String[]{"K"});
    model.material("mat1").propertyGroup("Enu").func("int2").set("funcname", "nu");
    model.material("mat1").propertyGroup("Enu").func("int2")
         .set("table", new String[][]{{"293.15", "0.30"}, {"793.15", "0.315"}});
    model.material("mat1").propertyGroup("Enu").func("int2").set("extrap", "linear");
    model.material("mat1").propertyGroup("Enu").func("int2").set("fununit", new String[]{"1"});
    model.material("mat1").propertyGroup("Enu").func("int2").set("argunit", new String[]{"K"});
    model.material("mat1").propertyGroup("Enu").set("E", "E(T)");
    model.material("mat1").propertyGroup("Enu").set("nu", "nu(T)");
    model.material("mat1").propertyGroup("Enu").addInput("temperature");
    model.material("mat1").propertyGroup("Murnaghan").set("l", "-3.0e11[Pa]");
    model.material("mat1").propertyGroup("Murnaghan").set("m", "-6.2e11[Pa]");
    model.material("mat1").propertyGroup("Murnaghan").set("n", "-7.2e11[Pa]");
    model.material("mat1").propertyGroup("ElastoplasticModel").func("int1").set("funcname", "a");
    model.material("mat1").propertyGroup("ElastoplasticModel").func("int1")
         .set("table", new String[][]{{"600", "1"}, {"1100", "0.1"}, {"1643", "0"}});
    model.material("mat1").propertyGroup("ElastoplasticModel").func("int1").set("fununit", new String[]{"1"});
    model.material("mat1").propertyGroup("ElastoplasticModel").func("int1").set("argunit", new String[]{"K"});
    model.material("mat1").propertyGroup("ElastoplasticModel").set("sigmags", "350[MPa]*a(T)");
    model.material("mat1").propertyGroup("ElastoplasticModel").set("Et", "1.045[GPa]*a(T)");
    model.material("mat1").propertyGroup("ElastoplasticModel").set("Ek", "1.045[GPa]*a(T)");
    model.material("mat1").propertyGroup("ElastoplasticModel").set("sigmagh", "1.050[GPa]*epe*a(T)");
    model.material("mat1").propertyGroup("ElastoplasticModel")
         .set("Hillcoefficients", new String[]{"0[m^2*s^4/kg^2]", "0[m^2*s^4/kg^2]", "0[m^2*s^4/kg^2]", "0[m^2*s^4/kg^2]", "0[m^2*s^4/kg^2]", "0[m^2*s^4/kg^2]"});
    model.material("mat1").propertyGroup("ElastoplasticModel")
         .set("ys", new String[]{"0[N/m^2]", "0[N/m^2]", "0[N/m^2]", "0[N/m^2]", "0[N/m^2]", "0[N/m^2]"});
    model.material("mat1").propertyGroup("ElastoplasticModel").addInput("temperature");
    model.material("mat1").propertyGroup("ElastoplasticModel").addInput("effectiveplasticstrain");
    model.material("mat1").propertyGroup("Ludwik").func("int1").set("funcname", "a");
    model.material("mat1").propertyGroup("Ludwik").func("int1")
         .set("table", new String[][]{{"600", "1"}, {"1100", "0.1"}, {"1643", "0"}});
    model.material("mat1").propertyGroup("Ludwik").func("int1").set("fununit", new String[]{"1"});
    model.material("mat1").propertyGroup("Ludwik").func("int1").set("argunit", new String[]{"K"});
    model.material("mat1").propertyGroup("Ludwik").set("k_lud", "560[MPa]*a(T)");
    model.material("mat1").propertyGroup("Ludwik").set("n_lud", "0.61");
    model.material("mat1").propertyGroup("Ludwik").addInput("temperature");
    model.material("mat1").propertyGroup("JohnsonCook").label("Johnson-Cook");
    model.material("mat1").propertyGroup("JohnsonCook").set("k_jcook", "560[MPa]");
    model.material("mat1").propertyGroup("JohnsonCook").set("n_jcook", "0.61");
    model.material("mat1").propertyGroup("JohnsonCook").set("C_jcook", "0.12");
    model.material("mat1").propertyGroup("JohnsonCook").set("epet0_jcook", "1[1/s]");
    model.material("mat1").propertyGroup("JohnsonCook").set("m_jcook", "0.6");
    model.material("mat1").propertyGroup("Swift").set("e0_swi", "0.021");
    model.material("mat1").propertyGroup("Swift").set("n_swi", "0.2");
    model.material("mat1").propertyGroup("Voce").func("int1").set("funcname", "a");
    model.material("mat1").propertyGroup("Voce").func("int1")
         .set("table", new String[][]{{"600", "1"}, {"1100", "0.1"}, {"1643", "0"}});
    model.material("mat1").propertyGroup("Voce").func("int1").set("fununit", new String[]{"1"});
    model.material("mat1").propertyGroup("Voce").func("int1").set("argunit", new String[]{"K"});
    model.material("mat1").propertyGroup("Voce").set("sigma_voc", "249[MPa]*a(T)");
    model.material("mat1").propertyGroup("Voce").set("beta_voc", "9.3");
    model.material("mat1").propertyGroup("Voce").addInput("temperature");
    model.material("mat1").propertyGroup("HockettSherby").label("Hockett-Sherby");
    model.material("mat1").propertyGroup("HockettSherby").func("int1").set("funcname", "a");
    model.material("mat1").propertyGroup("HockettSherby").func("int1")
         .set("table", new String[][]{{"600", "1"}, {"1100", "0.1"}, {"1643", "0"}});
    model.material("mat1").propertyGroup("HockettSherby").func("int1").set("fununit", new String[]{"1"});
    model.material("mat1").propertyGroup("HockettSherby").func("int1").set("argunit", new String[]{"K"});
    model.material("mat1").propertyGroup("HockettSherby").set("sigma_hoc", "684[MPa]*a(T)");
    model.material("mat1").propertyGroup("HockettSherby").set("m_hoc", "3.9");
    model.material("mat1").propertyGroup("HockettSherby").set("n_hoc", "0.85");
    model.material("mat1").propertyGroup("HockettSherby").addInput("temperature");
    model.material("mat1").propertyGroup("ArmstrongFrederick").label("Armstrong-Frederick");
    model.material("mat1").propertyGroup("ArmstrongFrederick").func("int1").set("funcname", "a");
    model.material("mat1").propertyGroup("ArmstrongFrederick").func("int1")
         .set("table", new String[][]{{"600", "1"}, {"1100", "0.1"}, {"1643", "0"}});
    model.material("mat1").propertyGroup("ArmstrongFrederick").func("int1").set("fununit", new String[]{"1"});
    model.material("mat1").propertyGroup("ArmstrongFrederick").func("int1").set("argunit", new String[]{"K"});
    model.material("mat1").propertyGroup("ArmstrongFrederick").set("Ck", "2.070[GPa]*a(T)");
    model.material("mat1").propertyGroup("ArmstrongFrederick").set("gammak", "8.0");
    model.material("mat1").propertyGroup("ArmstrongFrederick").addInput("temperature");
    model.material("mat1").propertyGroup("Norton").set("A_nor", "1.2e-15[1/s]");
    model.material("mat1").propertyGroup("Norton").set("sigRef_nor", "1[MPa]");
    model.material("mat1").propertyGroup("Norton").set("n_nor", "4.5");
    model.material("mat1").propertyGroup("Garofalo").set("A_gar", "1e-6[1/s]");
    model.material("mat1").propertyGroup("Garofalo").set("sigRef_gar", "100[MPa]");
    model.material("mat1").propertyGroup("Garofalo").set("n_gar", "4.6");
    model.material("mat1").propertyGroup("ChabocheViscoplasticity").set("A_cha", "1[1/s]");
    model.material("mat1").propertyGroup("ChabocheViscoplasticity").set("sigRef_cha", "490[MPa]");
    model.material("mat1").propertyGroup("ChabocheViscoplasticity").set("n_cha", "9");

//    In the Materials toolbar, click Add Material to close the Add Material window.
//    In the Settings window for Topology Link, locate the Link Settings section.
//    From the Material list, select Structural steel (mat1).

    model.component("comp1").material("toplnk1").set("link", "mat1");

//    In the Physics toolbar, click Boundaries and choose Fixed Constraint.

    model.component("comp1").physics("solid").create("fix1", "Fixed", 2);

//    In the Settings window for Fixed Constraint, locate the Boundary Selection section.
//    From the Selection list, select Constraint 1.

    model.component("comp1").physics("solid").feature("fix1").selection().named("geom1_cylsel1");

//    In the Physics toolbar, click Constraint Group and choose New Constraint Group.

    model.group().create("cg1", "ConstraintGroup");

    model.component("comp1").physics("solid").feature("fix1").set("constraintGroup", "cg1");

//    In the Physics toolbar, click Boundaries and choose Fixed Constraint.

    model.component("comp1").physics("solid").create("fix2", "Fixed", 2);

//    In the Settings window for Fixed Constraint, locate the Boundary Selection section.
//    From the Selection list, select Constraint 2.

    model.component("comp1").physics("solid").feature("fix2").selection().named("geom1_cylsel2");

//    In the Physics toolbar, click Constraint Group and choose New Constraint Group.

    model.group().create("cg2", "ConstraintGroup");

    model.component("comp1").physics("solid").feature("fix2").set("constraintGroup", "cg2");

//    In the Physics toolbar, click Boundaries and choose Fixed Constraint.

    model.component("comp1").physics("solid").create("fix3", "Fixed", 2);

//    In the Settings window for Fixed Constraint, locate the Boundary Selection section.
//    From the Selection list, select Constraint 3.

    model.component("comp1").physics("solid").feature("fix3").selection().named("geom1_cylsel3");

//    In the Physics toolbar, click Constraint Group and choose New Constraint Group.

    model.group().create("cg3", "ConstraintGroup");

    model.component("comp1").physics("solid").feature("fix3").set("constraintGroup", "cg3");

//    In the Physics toolbar, click Boundaries and choose Fixed Constraint.

    model.component("comp1").physics("solid").create("fix4", "Fixed", 2);

//    In the Settings window for Fixed Constraint, locate the Boundary Selection section.
//    From the Selection list, select Constraint 4.

    model.component("comp1").physics("solid").feature("fix4").selection().named("geom1_cylsel4");

//    In the Physics toolbar, click Constraint Group and choose New Constraint Group.

    model.group().create("cg4", "ConstraintGroup");

    model.component("comp1").physics("solid").feature("fix4").set("constraintGroup", "cg4");

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

    model.component("comp1").physics("solid").create("bndl1", "BoundaryLoad", 2);

//    In the Settings window for Boundary Load, locate the Boundary Selection section.
//    From the Selection list, select Load 1.

    model.component("comp1").physics("solid").feature("bndl1").selection().named("geom1_unisel1");

//    Locate the Coordinate System Selection section.
//    From the Coordinate system list, select Boundary System 1 (sys1).

    model.component("comp1").physics("solid").feature("bndl1").set("coordinateSystem", "sys1");

//    Locate the Force section.
//    Specify the \[\mathbf{f}_{\mathrm{A}}\] vector as

    model.component("comp1").physics("solid").feature("bndl1")
         .set("forceReferenceArea", new String[]{"0", "0", "load(-P0,Y-YC,Z)"});

//    In the Physics toolbar, click Load Group and choose New Load Group.

    model.group().create("lg1", "LoadGroup");

    model.component("comp1").physics("solid").feature("bndl1").set("loadGroup", "lg1");

//    Mesh one side of the domain using swept and tetrahedral meshes.
//    In the Mesh toolbar, click More Generators and choose Free Triangular.

    model.component("comp1").mesh("mesh1").create("ftri1", "FreeTri");

//    Select Boundaries 1, 4, 33, 37, 43, 47.

    model.component("comp1").mesh("mesh1").feature("ftri1").selection().set(1, 4, 33, 37, 43, 47);

//    In the Model Builder window, click Size.
//    In the Settings window for Size, locate the Element Size section.
//    Click the Custom button.

    model.component("comp1").mesh("mesh1").feature("size").set("custom", true);

//    Locate the Element Size Parameters section.
//    In the Maximum element size text field, type meshsz.

    model.component("comp1").mesh("mesh1").feature("size").set("hmax", "meshsz");

//    In the Minimum element size text field, type meshsz/2.

    model.component("comp1").mesh("mesh1").feature("size").set("hmin", "meshsz/2");

//    In the Mesh toolbar, click Swept.

    model.component("comp1").mesh("mesh1").create("swe1", "Sweep");

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

    model.component("comp1").mesh("mesh1").feature("swe1").selection().geom("geom1", 3);

//    From the Selection list, select Swept Domains.

    model.component("comp1").mesh("mesh1").feature("swe1").selection().named("geom1_difsel2");

//    In the Mesh toolbar, click Free Tetrahedral.

    model.component("comp1").mesh("mesh1").create("ftet1", "FreeTet");

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

    model.component("comp1").mesh("mesh1").feature("ftet1").selection().geom("geom1", 3);

//    From the Selection list, select Free Tetrahedral Domains.

    model.component("comp1").mesh("mesh1").feature("ftet1").selection().named("geom1_boxsel3");

//    Copy the mesh from one side to the other.
//    In the Model Builder window, right-click Mesh 1 and choose Copying Operations > Copy Domain.

    model.component("comp1").mesh("mesh1").create("cpd1", "CopyDomain");
    model.component("comp1").mesh("mesh1").feature("cpd1").selection("source").geom(3);
    model.component("comp1").mesh("mesh1").feature("cpd1").selection("destination").geom(3);

//    In the Settings window for Copy Domain, locate the Source Domains section.
//    From the Selection list, select Source Domain.

    model.component("comp1").mesh("mesh1").feature("cpd1").selection("source").named("geom1_boxsel1");

//    Locate the Destination Domains section.
//    From the Selection list, select Destination Domain.

    model.component("comp1").mesh("mesh1").feature("cpd1").selection("destination").named("geom1_boxsel2");

//    In the Model Builder window, under Global Definitions, click Parameters 2.
//    In the Settings window for Parameters, locate the Parameters section.
//    In the table, enter the following settings:

    model.param("par2").set("Vfrac", "0.5");
    model.param("par2").descr("Vfrac", "Volume fraction");
    model.param("par2").set("simpP", "1");
    model.param("par2").descr("simpP", "SIMP exponent");
    model.param("par2").set("proj_beta", "1");
    model.param("par2").descr("proj_beta", "Projection slope");

//    The characteristic strain energy is taken as double the computed value to compensate for the fact that half of the material will be removed.
//    Set up the density topology feature and let it control Young's modulus.
//    In the Model Builder window, under Component 1 (comp1) > Topology Optimization, click Density Model 1 (dtopo1).
//    In the Settings window for Density Model, locate the Geometric Entity Selection section.
//    From the Selection list, select Design Space Domains.

    model.component("comp1").common("dtopo1").selection().named("geom1_difsel1");

//    Locate the Filtering section.
//    From the \[R_{\textrm{min}}\] list, select User defined.

    model.component("comp1").common("dtopo1").set("filterLengthType", "Custom");

//    In the \[\] text field, type Lmin.

    model.component("comp1").common("dtopo1").set("L_min", "Lmin");

//    The filter radius must be larger or equal to the mesh size.
//    Locate the Projection section.
//    From the Projection type list, select Hyperbolic tangent projection.

    model.component("comp1").common("dtopo1").set("projectionType", "TanhProjection");

//    In the \[\beta\] text field, type proj_beta.

    model.component("comp1").common("dtopo1").set("beta", "proj_beta");

//    Locate the Interpolation section.
//    From the \[p_{\textrm{SIMP}}\] list, select User defined.

    model.component("comp1").common("dtopo1").set("simpExponentType", "Custom");

//    In the \[\] text field, type simpP.

    model.component("comp1").common("dtopo1").set("p_SIMP", "simpP");

//    Locate the Control Variable Discretization section.
//    From the Element order list, select Constant.

    model.component("comp1").common("dtopo1").set("discretization", "constant");

//    Locate the Control Variable Initial Value section.
//    In the \[\theta_0\] text field, type Vfrac.

    model.component("comp1").common("dtopo1").set("theta_0", "Vfrac");

//    In the Topology Optimization toolbar, click Prescribed Material.

    model.component("comp1").common().create("ftopom1", "MaterialTopologyDomain");

//    In the Settings window for Prescribed Material, locate the Geometric Entity Selection section.
//    From the Selection list, select Domains Outside Design Space.

    model.component("comp1").common("ftopom1").selection().named("geom1_adjsel1");

//    In the Topology Optimization toolbar, click Prescribed Material Boundary.

    model.component("comp1").common().create("ftopobm1", "MaterialTopologyBoundary");

//    In the Settings window for Prescribed Material Boundary, locate the Geometric Entity Selection section.
//    From the Selection list, select Material Boundaries.

    model.component("comp1").common("ftopobm1").selection().named("geom1_cylsel9");

//    In the Topology Optimization toolbar, click Mirror Symmetry.

    model.component("comp1").common().create("mtopo1", "MirrorTopology");

//    In the Settings window for Mirror Symmetry, locate the Geometric Entity Selection section.
//    From the Selection list, select Mirror Domain.

    model.component("comp1").common("mtopo1").selection().named("geom1_boxsel4");

//    Disable the imposed symmetry in this initial study.
//    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.
//    Select the Modify model configuration for study step checkbox.

    model.study("std1").feature("stat").set("useadvanceddisable", true);

//    In the tree, select Component 1 (comp1) > Topology Optimization > Mirror Symmetry 1.
//    Click Disable.

    model.study("std1").feature("stat").setSolveFor("/common/mtopo1", false);
    model.study("std1").feature("stat").set("disabledcommon", new String[]{"mtopo1"});

//    Click to expand the Study Extensions section.
//    Select the Define load cases checkbox.

    model.study("std1").feature("stat").set("useloadcase", true);

//    Click Add.

    model.study("std1").feature("stat").setIndex("loadcase", "Load case 1", 0);
    model.study("std1").feature("stat").setIndex("loadgroup", false, 0, 0);
    model.study("std1").feature("stat").setIndex("loadgroupweight", "1.0", 0, 0);
    model.study("std1").feature("stat").setIndex("constraintgroup", false, 0, 0);
    model.study("std1").feature("stat").setIndex("constraintgroup", false, 0, 1);
    model.study("std1").feature("stat").setIndex("constraintgroup", false, 0, 2);
    model.study("std1").feature("stat").setIndex("constraintgroup", false, 0, 3);
    model.study("std1").feature("stat").setIndex("loadcase", "Load case 1", 0);
    model.study("std1").feature("stat").setIndex("loadgroup", false, 0, 0);
    model.study("std1").feature("stat").setIndex("loadgroupweight", "1.0", 0, 0);
    model.study("std1").feature("stat").setIndex("constraintgroup", false, 0, 0);
    model.study("std1").feature("stat").setIndex("constraintgroup", false, 0, 1);
    model.study("std1").feature("stat").setIndex("constraintgroup", false, 0, 2);
    model.study("std1").feature("stat").setIndex("constraintgroup", false, 0, 3);

//    In the table, enter the following settings:

    model.study("std1").feature("stat").setIndex("loadgroup", true, 0, 0);
    model.study("std1").feature("stat").setIndex("constraintgroup", true, 0, 0);
    model.study("std1").feature("stat").setIndex("constraintgroup", true, 0, 1);
    model.study("std1").feature("stat").setIndex("constraintgroup", true, 0, 2);
    model.study("std1").feature("stat").setIndex("constraintgroup", true, 0, 3);

//    In the Model Builder window, click Topology Optimization.
//    In the Settings window for Topology Optimization, locate the Optimization Solver section.
//    In the Maximum number of iterations text field, type 50.

    model.study("std1").feature("topo").set("mmamaxiter", 50);

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

    model.study("std1").feature("topo").setIndex("constraintExpression", "comp1.dtopo1.theta_avg", 0);
    model.study("std1").feature("topo").setIndex("constraintLbound", "", 0);
    model.study("std1").feature("topo").setIndex("constraintLbound", "", 0);
    model.study("std1").feature("topo").setIndex("constraintUbound", "Vfrac", 0);

//    In the Model Builder window, click Study 1.
//    In the Settings window for Study, type Study 1: One Load Case, No Symmetry in the Label text field.

    model.study("std1").label("Study 1: One Load Case, No Symmetry");

//    In the Study toolbar, click Get Initial Value.

    model.study("std1").createAutoSequences("sol");
    model.study("std1").createAutoSequences("jobs");

    model.sol("sol1").runFromTo("st1", "v1");

    model.result().create("pg1", "PlotGroup3D");
    model.result("pg1").set("data", "dset1");
    model.result("pg1").label("Stress (solid)");
    model.result("pg1").set("frametype", "spatial");
    model.result("pg1").create("vol1", "Volume");
    model.result("pg1").feature("vol1").set("expr", new String[]{"solid.misesGp"});
    model.result("pg1").feature("vol1").set("threshold", "manual");
    model.result("pg1").feature("vol1").set("thresholdvalue", 0.2);
    model.result("pg1").feature("vol1").set("colortable", "Rainbow");
    model.result("pg1").feature("vol1").set("colortabletrans", "none");
    model.result("pg1").feature("vol1").set("colorscalemode", "linear");
    model.result("pg1").feature("vol1").set("resolution", "custom");
    model.result("pg1").feature("vol1").set("refine", 2);
    model.result("pg1").feature("vol1").set("colortable", "Prism");
    model.result("pg1").feature("vol1").create("def", "Deform");
    model.result("pg1").feature("vol1").feature("def").set("expr", new String[]{"u", "v", "w"});
    model.result("pg1").feature("vol1").feature("def").set("descr", "Displacement field");

    model.nodeGroup().create("grp1", "Results");

    return model;
  }

  public static Model run2(Model model) {
    model.nodeGroup("grp1").label("Topology Optimization");
    model.nodeGroup("grp1").set("type", "plotgroup");
    model.nodeGroup("grp1").placeAfter("plotgroup", "pg1");
    model.nodeGroup().move("grp1", 1);

    model.result().create("pg2", "PlotGroup3D");
    model.result("pg2").label("Output material volume factor");
    model.result().create("pg3", "PlotGroup3D");
    model.result("pg3").label("Threshold");

    model.nodeGroup("grp1").add("plotgroup", "pg2");
    model.nodeGroup("grp1").add("plotgroup", "pg3");

    model.result().dataset().create("filt1", "Filter");
    model.result().dataset("filt1").label("Filter");
    model.result().dataset("filt1").set("data", "dset1");
    model.result().dataset("filt1").set("expr", "dtopo1.theta");
    model.result().dataset("filt1").set("lowerexpr", "0.5");
    model.result().dataset("filt1").set("smooth", "none");
    model.result().dataset("filt1").set("useder", false);
    model.result("pg2").set("data", "dset1");
    model.result("pg2").create("mslc1", "Multislice");
    model.result("pg2").feature("mslc1").set("expr", "dtopo1.theta");
    model.result("pg2").feature("mslc1").set("rangecoloractive", true);
    model.result("pg2").feature("mslc1").set("rangecolormin", 0);
    model.result("pg2").feature("mslc1").set("rangecolormax", 1);
    model.result("pg2").feature("mslc1").set("xnumber", "1");
    model.result("pg2").feature("mslc1").set("ynumber", "1");
    model.result("pg2").feature("mslc1").set("znumber", "1");
    model.result("pg3").set("data", "filt1");
    model.result("pg3").create("vol1", "Volume");
    model.result("pg3").feature("vol1").set("expr", "1");
    model.result("pg3").feature("vol1").set("coloring", "uniform");
    model.result("pg3").feature("vol1").set("color", "gray");
    model.result("pg3").feature("vol1").set("titletype", "none");
    model.result().export().create("plot1", "Plot");
    model.result().export("plot1").set("plotgroup", "pg3");
    model.result().export("plot1").label("Topology Optimized Geometry (STL)");
    model.result().export("plot1").set("exporttype", "stlbin");
    model.result().export("plot1").set("filename", "comp1_dtopo1.stl");
    model.result().export().create("plot2", "Plot");
    model.result().export("plot2").set("plotgroup", "pg3");
    model.result().export("plot2").label("Topology Optimized Geometry (PLY)");
    model.result().export("plot2").set("exporttype", "plybin");
    model.result().export("plot2").set("filename", "comp1_dtopo1.ply");
    model.result("pg1").run();

//    Use the plot to show the design during the optimization.
//    In the Model Builder window, click Topology Optimization.
//    In the Settings window for Topology Optimization, click to expand the Output section.
//    Select the Plot checkbox.

    model.study("std1").feature("topo").set("plot", true);

//    In the table, enter the following settings:

    model.study("std1").feature("topo").setIndex("plotgrouparr", "pg3", 0);

//    In general it is best to scale the objective function with the initial value, but in this case the scale is close enough to 1 that it is unnecessary.
//    In the Model Builder window, click Study 1: One Load Case, No Symmetry.
//    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 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", "D1", 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", "D1", 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", "D2", 1);
    model.study("std1").feature("param").setIndex("plistarr", "", 1);
    model.study("std1").feature("param").setIndex("punit", "m", 1);
    model.study("std1").feature("param").setIndex("pname", "D2", 1);
    model.study("std1").feature("param").setIndex("plistarr", "", 1);
    model.study("std1").feature("param").setIndex("punit", "m", 1);

//     twice.
//    In the table, enter the following settings:

    model.study("std1").feature("param").setIndex("pname", "simpP", 0);
    model.study("std1").feature("param").setIndex("plistarr", "1 2 3 4", 0);
    model.study("std1").feature("param").setIndex("punit", "", 0);
    model.study("std1").feature("param").setIndex("pname", "proj_beta", 1);
    model.study("std1").feature("param").setIndex("plistarr", "2 4 6 8", 1);
    model.study("std1").feature("param").setIndex("punit", "", 1);

//    Click to expand the Advanced Settings section.
//    Select the Reuse solution from previous step checkbox.

    model.study("std1").feature("param").set("reusesol", true);

//    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");

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

    model.study("std1").feature("topo").set("probewindow", "");

//    In the Model Builder window, under Results, click Topology Optimization.
//    In the Settings window for Group, type One Load Case in the Label text field.

    model.nodeGroup("grp1").label("One Load Case");

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

//    In the Model Builder window, expand the One Load Case node, then click Stress (solid).
//    Drag and drop above One Load Case > Output material volume factor.

    model.nodeGroup("grp1").add("plotgroup", "pg1");

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

//    In the Model Builder window, click Threshold.
//    In the Threshold toolbar, click Plot.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    The resulting design is asymmetric due to the load and the two halves are poorly connected. If one of the bolts breaks, significant stiffness will be lost. Add a second load case together with a study using two load groups and four constraints giving a total of four load cases. Run the optimization again to see what effect this has on the optimal design.
//    In the Model Builder window, right-click Component 1 (comp1) > Solid Mechanics (solid) > Boundary Load 1 and choose Duplicate.

    model.component("comp1").physics("solid").feature().duplicate("bndl2", "bndl1");

//    In the Settings window for Boundary Load, locate the Boundary Selection section.
//    From the Selection list, select Load 2.

    model.component("comp1").physics("solid").feature("bndl2").selection().named("geom1_unisel2");

//    In the Physics toolbar, click Load Group and choose New Load Group.

    model.group().create("lg2", "LoadGroup");

    model.component("comp1").physics("solid").feature("bndl2").set("loadGroup", "lg2");

//    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.
//    We are effectively solving for four load cases, but it is sufficient to consider two load cases due to the use of the <l>Mirror Symmetry</l> feature in the <l>Topology Optimization</l> interface.
//    In the Settings window for Stationary, locate the Study Extensions section.
//    Select the Define load cases checkbox.

    model.study("std2").feature("stat").set("useloadcase", true);

//    Click Add.

    model.study("std2").feature("stat").setIndex("loadcase", "Load case 1", 0);
    model.study("std2").feature("stat").setIndex("loadgroup", false, 0, 0);
    model.study("std2").feature("stat").setIndex("loadgroupweight", "1.0", 0, 0);
    model.study("std2").feature("stat").setIndex("loadgroup", false, 0, 1);
    model.study("std2").feature("stat").setIndex("loadgroupweight", "1.0", 0, 1);
    model.study("std2").feature("stat").setIndex("constraintgroup", false, 0, 0);
    model.study("std2").feature("stat").setIndex("constraintgroup", false, 0, 1);
    model.study("std2").feature("stat").setIndex("constraintgroup", false, 0, 2);
    model.study("std2").feature("stat").setIndex("constraintgroup", false, 0, 3);
    model.study("std2").feature("stat").setIndex("loadcase", "Load case 1", 0);
    model.study("std2").feature("stat").setIndex("loadgroup", false, 0, 0);
    model.study("std2").feature("stat").setIndex("loadgroupweight", "1.0", 0, 0);
    model.study("std2").feature("stat").setIndex("loadgroup", false, 0, 1);
    model.study("std2").feature("stat").setIndex("loadgroupweight", "1.0", 0, 1);
    model.study("std2").feature("stat").setIndex("constraintgroup", false, 0, 0);
    model.study("std2").feature("stat").setIndex("constraintgroup", false, 0, 1);
    model.study("std2").feature("stat").setIndex("constraintgroup", false, 0, 2);
    model.study("std2").feature("stat").setIndex("constraintgroup", false, 0, 3);

//     twice.

    model.study("std2").feature("stat").setIndex("loadcase", "Load case 2", 1);
    model.study("std2").feature("stat").setIndex("loadgroup", false, 1, 0);
    model.study("std2").feature("stat").setIndex("loadgroupweight", "1.0", 1, 0);
    model.study("std2").feature("stat").setIndex("loadgroup", false, 1, 1);
    model.study("std2").feature("stat").setIndex("loadgroupweight", "1.0", 1, 1);
    model.study("std2").feature("stat").setIndex("constraintgroup", false, 1, 0);
    model.study("std2").feature("stat").setIndex("constraintgroup", false, 1, 1);
    model.study("std2").feature("stat").setIndex("constraintgroup", false, 1, 2);
    model.study("std2").feature("stat").setIndex("constraintgroup", false, 1, 3);
    model.study("std2").feature("stat").setIndex("loadcase", "Load case 2", 1);
    model.study("std2").feature("stat").setIndex("loadgroup", false, 1, 0);
    model.study("std2").feature("stat").setIndex("loadgroupweight", "1.0", 1, 0);
    model.study("std2").feature("stat").setIndex("loadgroup", false, 1, 1);
    model.study("std2").feature("stat").setIndex("loadgroupweight", "1.0", 1, 1);
    model.study("std2").feature("stat").setIndex("constraintgroup", false, 1, 0);
    model.study("std2").feature("stat").setIndex("constraintgroup", false, 1, 1);
    model.study("std2").feature("stat").setIndex("constraintgroup", false, 1, 2);
    model.study("std2").feature("stat").setIndex("constraintgroup", false, 1, 3);

//    In the table, enter the following settings:

    model.study("std2").feature("stat").setIndex("loadgroup", true, 0, 0);
    model.study("std2").feature("stat").setIndex("constraintgroup", true, 0, 1);
    model.study("std2").feature("stat").setIndex("constraintgroup", true, 0, 2);
    model.study("std2").feature("stat").setIndex("constraintgroup", true, 0, 3);
    model.study("std2").feature("stat").setIndex("loadgroup", true, 1, 1);
    model.study("std2").feature("stat").setIndex("constraintgroup", true, 1, 0);
    model.study("std2").feature("stat").setIndex("constraintgroup", true, 1, 2);
    model.study("std2").feature("stat").setIndex("constraintgroup", true, 1, 3);

//    In the Model Builder window, click Study 2.
//    In the Settings window for Study, type Study 2: Two Load Cases in the Label text field.

    model.study("std2").label("Study 2: Two Load Cases");

//    In the Study toolbar, click Compute.

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

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

    model.result().create("pg4", "PlotGroup3D");
    model.result("pg4").set("data", "dset3");
    model.result("pg4").setIndex("looplevel", 2, 0);
    model.result("pg4").label("Stress (solid) 1");
    model.result("pg4").set("frametype", "spatial");
    model.result("pg4").create("vol1", "Volume");
    model.result("pg4").feature("vol1").set("expr", new String[]{"solid.misesGp"});
    model.result("pg4").feature("vol1").set("threshold", "manual");
    model.result("pg4").feature("vol1").set("thresholdvalue", 0.2);
    model.result("pg4").feature("vol1").set("colortable", "Rainbow");
    model.result("pg4").feature("vol1").set("colortabletrans", "none");
    model.result("pg4").feature("vol1").set("colorscalemode", "linear");
    model.result("pg4").feature("vol1").set("resolution", "custom");
    model.result("pg4").feature("vol1").set("refine", 2);
    model.result("pg4").feature("vol1").set("colortable", "Prism");
    model.result("pg4").feature("vol1").create("def", "Deform");
    model.result("pg4").feature("vol1").feature("def").set("expr", new String[]{"u", "v", "w"});
    model.result("pg4").feature("vol1").feature("def").set("descr", "Displacement field");

    model.nodeGroup().create("grp2", "Results");
    model.nodeGroup("grp2").label("Topology Optimization");
    model.nodeGroup("grp2").set("type", "plotgroup");
    model.nodeGroup("grp2").placeAfter("plotgroup", "pg4");
    model.nodeGroup().move("grp2", 2);

    model.result().create("pg5", "PlotGroup3D");
    model.result("pg5").label("Output material volume factor 1");
    model.result().create("pg6", "PlotGroup3D");
    model.result("pg6").label("Threshold 1");

    model.nodeGroup("grp2").add("plotgroup", "pg5");
    model.nodeGroup("grp2").add("plotgroup", "pg6");

    model.result().dataset().create("filt2", "Filter");
    model.result().dataset("filt2").label("Filter 1");
    model.result().dataset("filt2").set("data", "dset3");
    model.result().dataset("filt2").set("expr", "dtopo1.theta");
    model.result().dataset("filt2").set("lowerexpr", "0.5");
    model.result().dataset("filt2").set("smooth", "none");
    model.result().dataset("filt2").set("useder", false);
    model.result("pg5").set("data", "dset3");
    model.result("pg5").create("mslc1", "Multislice");
    model.result("pg5").feature("mslc1").set("expr", "dtopo1.theta");
    model.result("pg5").feature("mslc1").set("rangecoloractive", true);
    model.result("pg5").feature("mslc1").set("rangecolormin", 0);
    model.result("pg5").feature("mslc1").set("rangecolormax", 1);
    model.result("pg5").feature("mslc1").set("xnumber", "1");
    model.result("pg5").feature("mslc1").set("ynumber", "1");
    model.result("pg5").feature("mslc1").set("znumber", "1");
    model.result("pg6").set("data", "filt2");
    model.result("pg6").create("vol1", "Volume");
    model.result("pg6").feature("vol1").set("expr", "1");
    model.result("pg6").feature("vol1").set("coloring", "uniform");
    model.result("pg6").feature("vol1").set("color", "gray");
    model.result("pg6").feature("vol1").set("titletype", "none");
    model.result().export().create("plot3", "Plot");
    model.result().export("plot3").set("plotgroup", "pg6");
    model.result().export("plot3").label("Topology Optimized Geometry (STL) 1");
    model.result().export("plot3").set("exporttype", "stlbin");
    model.result().export("plot3").set("filename", "comp1_dtopo1.stl");
    model.result().export().create("plot4", "Plot");
    model.result().export("plot4").set("plotgroup", "pg6");
    model.result().export("plot4").label("Topology Optimized Geometry (PLY) 1");
    model.result().export("plot4").set("exporttype", "plybin");
    model.result().export("plot4").set("filename", "comp1_dtopo1.ply");
    model.result("pg4").run();

//    Right-click and choose Copy.
//    In the Model Builder window, right-click Study 2: Two Load Cases and choose Paste Multiple Items.

    model.study("std2").feature().copy("param", "std1/param");
    model.study("std2").feature().copy("topo", "std1/topo");

//    In the Settings window for Topology Optimization, locate the Objective Function section.
//    In the table, enter the following settings:

    model.study("std2").feature("topo").setIndex("optobj", "comp1.solid.Ws_tot/4", 0);
    model.study("std2").feature("topo").setIndex("descr", "", 0);
    model.study("std2").feature("topo").setIndex("plotgrouparr", "pg6", 0);

//    Locate the Output section.
//    In the table, enter the following settings:
//    In the Model Builder window, click Study 2: Two Load Cases.
//    In the Settings window for Study, locate the Study Settings section.
//    Clear the Generate default plots checkbox.

    model.study("std2").setGenPlots(false);

//    The default direct solver works, but the computational time can be decreased by using the iterative solver and avoiding reuse of the sparsity pattern. Finally, the log becomes cleaner if the solver is not allowed to change the order of the load cases.
//    In the Model Builder window, right-click Solver Configurations and choose Reset Solver to Default.

    model.sol("sol7").createAutoSequence("std2");

//    In the Model Builder window, expand the Solution 7 (sol7) node.
//    In the Model Builder window, expand the Study 2: Two Load Cases > Solver Configurations > Solution 7 (sol7) > Optimization Solver 1 node.
//    In the Model Builder window, expand the Study 2: Two Load Cases > Solver Configurations > Solution 7 (sol7) > Optimization Solver 1 > Stationary Solver 1 node.
//    In the Model Builder window, expand the Study 2: Two Load Cases > Solver Configurations > Solution 7 (sol7) > Optimization Solver 1 > Stationary Solver 1 > Segregated 1 node, then click Solid Mechanics.
//    In the Settings window for Segregated Step, locate the General section.
//    From the Linear solver list, select Suggested Iterative Solver (GMRES with SA AMG) (solid).

    model.sol("sol7").feature("o1").feature("s1").feature("se1").feature("ss2").set("linsolver", "i2");

//    In the Model Builder window, click Segregated 1.
//    In the Settings window for Segregated, locate the General section.
//    From the Termination technique list, select Iterations.

    model.sol("sol7").feature("o1").feature("s1").feature("se1").set("segterm", "iter");

//     to reduce the computational time.
//    In the Model Builder window, click Advanced.
//    In the Settings window for Advanced, click to expand the Assembly Settings section.
//    Clear the Reuse sparsity pattern checkbox.

    model.sol("sol7").feature("o1").feature("s1").feature("aDef").set("cachepattern", false);

//    In the Model Builder window, click Parametric.
//    In the Settings window for Parametric, locate the General section.
//    From the Parameter value run order list, select As specified.

    model.sol("sol7").feature("o1").feature("s1").feature("pDef").set("plooporder", "manual");

//    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("pg4").run();

    model.study("std2").feature("topo").set("probewindow", "");

//    In the Model Builder window, under Results, click Topology Optimization.
//    In the Settings window for Group, type Two Load Cases in the Label text field.

    model.nodeGroup("grp2").label("Two Load Cases");

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

//    In the Model Builder window, expand the Two Load Cases node, then click Stress (solid) 1.
//    Drag and drop above Two Load Cases > Output material volume factor 1.

    model.nodeGroup("grp2").add("plotgroup", "pg4");

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

//    In the Model Builder window, click Threshold 1.
//    In the Threshold 1 toolbar, click Plot.

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

//    Now the design is symmetric and the two halves are better connected.
//    Click the Zoom Extents button in the Graphics toolbar.
//    Add a finer mesh and solve for the filtered material volume factor.
//    In the Model Builder window, right-click Component 1 (comp1) > Mesh 1 and choose Duplicate.

    model.component("comp1").mesh().duplicate("mesh2", "mesh1");

//    In the Model Builder window, expand the Mesh 2 node, then click Size.
//    In the Settings window for Size, locate the Element Size Parameters section.
//    In the Maximum element size text field, type meshsz/2.

    model.component("comp1").mesh("mesh2").feature("size").set("hmax", "meshsz/2");

//    In the Minimum element size text field, type meshsz/4.

    model.component("comp1").mesh("mesh2").feature("size").set("hmin", "meshsz/4");

//    Click Build All.

    model.component("comp1").mesh("mesh2").run();

//    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.
//    Find the Physics interfaces in study subsection.
//    In the table, enter the following settings:
//    Click Add Study in the window toolbar.

    model.study().create("std3");
    model.study("std3").create("stat", "Stationary");
    model.study("std3").feature("stat").setSolveFor("/physics/solid", false);

//    In the Home toolbar, click Add Study to close the Add Study window.
//    In the Settings window for Study, type Study 3: Smooth Design (mesh2) in the Label text field.

    model.study("std3").label("Study 3: Smooth Design (mesh2)");

//    In the Study toolbar, click Show Default Solver.

    model.study("std3").showAutoSequences("all");

//    In the Model Builder window, under Study 3: Smooth Design (mesh2), click Step 1: Stationary.
//    In the Settings window for Stationary, click to expand the Values of Dependent Variables section.
//    Find the Initial values of variables solved for subsection.
//    From the Settings list, select User controlled.

    model.study("std3").feature("stat").set("useinitsol", true);

//    From the Method list, select Solution.

    model.study("std3").feature("stat").set("initmethod", "sol");

//    From the Study list, select Study 2: Two Load Cases, Stationary.

    model.study("std3").feature("stat").set("initstudy", "std2");

//    In the Study toolbar, click Compute.

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

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

    model.nodeGroup().create("grp3", "Results");
    model.nodeGroup("grp3").label("Topology Optimization");
    model.nodeGroup("grp3").set("type", "plotgroup");
    model.nodeGroup().move("grp3", 3);

    model.result().create("pg7", "PlotGroup3D");
    model.result("pg7").label("Output material volume factor 2");
    model.result().create("pg8", "PlotGroup3D");
    model.result("pg8").label("Threshold 2");

    model.nodeGroup("grp3").add("plotgroup", "pg7");
    model.nodeGroup("grp3").add("plotgroup", "pg8");

    model.result().dataset().create("filt3", "Filter");
    model.result().dataset("filt3").label("Filter 2");
    model.result().dataset("filt3").set("data", "dset5");
    model.result().dataset("filt3").set("expr", "dtopo1.theta");
    model.result().dataset("filt3").set("lowerexpr", "0.5");
    model.result().dataset("filt3").set("smooth", "none");
    model.result().dataset("filt3").set("useder", false);
    model.result("pg7").set("data", "dset5");
    model.result("pg7").create("mslc1", "Multislice");
    model.result("pg7").feature("mslc1").set("expr", "dtopo1.theta");
    model.result("pg7").feature("mslc1").set("rangecoloractive", true);
    model.result("pg7").feature("mslc1").set("rangecolormin", 0);
    model.result("pg7").feature("mslc1").set("rangecolormax", 1);
    model.result("pg7").feature("mslc1").set("xnumber", "1");
    model.result("pg7").feature("mslc1").set("ynumber", "1");
    model.result("pg7").feature("mslc1").set("znumber", "1");
    model.result("pg8").set("data", "filt3");
    model.result("pg8").create("vol1", "Volume");
    model.result("pg8").feature("vol1").set("expr", "1");
    model.result("pg8").feature("vol1").set("coloring", "uniform");
    model.result("pg8").feature("vol1").set("color", "gray");
    model.result("pg8").feature("vol1").set("titletype", "none");
    model.result().export().create("plot5", "Plot");
    model.result().export("plot5").set("plotgroup", "pg8");
    model.result().export("plot5").label("Topology Optimized Geometry (STL) 2");
    model.result().export("plot5").set("exporttype", "stlbin");
    model.result().export("plot5").set("filename", "comp1_dtopo1.stl");
    model.result().export().create("plot6", "Plot");
    model.result().export("plot6").set("plotgroup", "pg8");
    model.result().export("plot6").label("Topology Optimized Geometry (PLY) 2");
    model.result().export("plot6").set("exporttype", "plybin");
    model.result().export("plot6").set("filename", "comp1_dtopo1.ply");
    model.result("pg7").run();

//    In the Model Builder window, expand the Results > Datasets node.
//    Right-click Results > Datasets > Filter 2 and choose Create Mesh-Based Geometry.

    model.component().create("comp2", "Component");

    model.component("comp2").geom().create("geom2", 3);

    model.result().dataset("filt3").createMeshBasedGeom("comp2", "gmesh1");

    model.component("comp2").mesh().create("mesh3");
    model.component("comp2").mesh("mesh3").contribute("geom/detail", true);

//    In the Mesh toolbar, click More Generators and choose Remesh Faces.

    model.component("comp2").mesh("gmesh1").run("imp1");
    model.component("comp2").mesh("gmesh1").create("remf1", "RemeshFaces");

//    In the Settings window for Remesh Faces, locate the Boundary Selection section.
//    From the Selection list, select All boundaries.

    model.component("comp2").mesh("gmesh1").feature("remf1").selection().all();

//    In the Model Builder window, expand the Remesh Faces 1 node, then click Size.
//    In the Settings window for Size, click to expand the Element Size Parameters section.
//    In the Maximum element size text field, type meshsz.

    model.component("comp2").mesh("gmesh1").feature("remf1").feature("size").set("hmax", "meshsz");

//    In the Minimum element size text field, type meshsz/2.

    model.component("comp2").mesh("gmesh1").feature("remf1").feature("size").set("hmin", "meshsz/2");

//    In the Curvature factor text field, type 1.

    model.component("comp2").mesh("gmesh1").feature("remf1").feature("size").set("hcurve", 1);

//    In the Resolution of narrow regions text field, type 0.

    model.component("comp2").mesh("gmesh1").feature("remf1").feature("size").set("hnarrow", 0);

//    Click Build All.

    model.component("comp2").mesh("gmesh1").run();

//    In the Model Builder window, right-click Component 2 (comp2) > Materials and choose More Materials > Material Link.

    model.component("comp2").material().create("matlnk1", "Link");

//    Copy/paste the physics from the first component and fix the selections.
//    In the Model Builder window, right-click Component 1 (comp1) > Solid Mechanics (solid) and choose Copy.
//    In the Model Builder window, right-click Component 2 (comp2) and choose Paste Solid Mechanics.

    model.component("comp2").physics().copy("solid2", "solid");

//    In the Messages from Paste dialog, click OK.
//    You can use second-order displacements now that you have an explicit geometry representation.
//    In the Settings window for Solid Mechanics, click to expand the Discretization section.
//    From the Displacement field list, select Quadratic serendipity.

    model.component("comp2").physics("solid2").prop("ShapeProperty").set("order_displacement", "2s");

//    In the Model Builder window, expand the Solid Mechanics (solid2) node, then click Fixed Constraint 1.
//    In the Settings window for Fixed Constraint, locate the Boundary Selection section.
//    From the Selection list, select Constraint 1.

    model.component("comp2").physics("solid2").feature("fix1").selection().named("gmesh1_imp1_geom1_cylsel1");

//    In the Model Builder window, click Fixed Constraint 2.
//    In the Settings window for Fixed Constraint, locate the Boundary Selection section.
//    From the Selection list, select Constraint 2.

    model.component("comp2").physics("solid2").feature("fix2").selection().named("gmesh1_imp1_geom1_cylsel2");

//    In the Model Builder window, click Fixed Constraint 3.
//    In the Settings window for Fixed Constraint, locate the Boundary Selection section.
//    From the Selection list, select Constraint 3.

    model.component("comp2").physics("solid2").feature("fix3").selection().named("gmesh1_imp1_geom1_cylsel3");

//    In the Model Builder window, click Fixed Constraint 4.
//    In the Settings window for Fixed Constraint, locate the Boundary Selection section.
//    From the Selection list, select Constraint 4.

    model.component("comp2").physics("solid2").feature("fix4").selection().named("gmesh1_imp1_geom1_cylsel4");

//    In the Model Builder window, click Boundary Load 1.
//    In the Settings window for Boundary Load, locate the Boundary Selection section.
//    From the Selection list, select Load 1.

    model.component("comp2").physics("solid2").feature("bndl1").selection().named("gmesh1_imp1_geom1_unisel1");

//    Locate the Force section.
//    Specify the \[\mathbf{f}_{\mathrm{A}}\] vector as

    model.component("comp2").physics("solid2").feature("bndl1")
         .set("forceReferenceArea", new String[]{"0", "0", "comp1.load(-P0,Y-YC,Z)"});

//    In the Model Builder window, click Boundary Load 2.
//    In the Settings window for Boundary Load, locate the Boundary Selection section.
//    From the Selection list, select Load 2.

    model.component("comp2").physics("solid2").feature("bndl2").selection().named("gmesh1_imp1_geom1_unisel2");

//    Locate the Force section.
//    Specify the \[\mathbf{f}_{\mathrm{A}}\] vector as

    model.component("comp2").physics("solid2").feature("bndl2")
         .set("forceReferenceArea", new String[]{"0", "0", "comp1.load(-P0,Y-YC,Z)"});

//    In the Model Builder window, click Component 1 (comp1).
//    In the Settings window for Component, type Component 1: Optimization in the Label text field.

    model.component("comp1").label("Component 1: Optimization");

//    In the Model Builder window, click Component 2 (comp2).
//    In the Settings window for Component, type Component 2: Verification in the Label text field.

    model.component("comp2").label("Component 2: Verification");

//    In the Mesh toolbar, click Free Tetrahedral.

    model.component("comp2").mesh("mesh3").create("ftet1", "FreeTet");

//    In the Model Builder window, expand the Free Tetrahedral 1 node, then click Component 2: Verification (comp2) > Mesh 3 > Size.
//    In the Settings window for Size, locate the Element Size section.
//    From the Predefined list, select Extremely fine.

    model.component("comp2").mesh("mesh3").feature("size").set("hauto", 1);

//    Click Build All.

    model.component("comp2").mesh("mesh3").run();

//    In the Home toolbar, click Add Study to open the Add Study window.
//    Find the Physics interfaces in study subsection.
//    In the table, enter the following settings:
//    The filtered material volume factor is always solved for, but this takes less time on the coarse mesh.
//    Find the Studies subsection.
//    In the Select Study tree, select Empty Study.
//    Click Add Study in the window toolbar.

    model.study().create("std4");

//    In the Home toolbar, click Add Study to close the Add Study window.
//    In the Settings window for Study, type Study 4: Verification in the Label text field.

    model.study("std4").label("Study 4: Verification");

//    Locate the Study Settings section.
//    Clear the Generate default plots checkbox.

    model.study("std4").setGenPlots(false);

//    In the Model Builder window, under Study 1: One Load Case, No Symmetry, click Step 1: Stationary.
//    In the Settings window for Stationary, locate the Physics and Variables Selection section.

    return model;
  }

  public static Model run3(Model model) {
//    In the tree, select Component 2: Verification (comp2) > Solid Mechanics (solid2).
//    Click Disable in Solvers.

    model.study("std1").feature("stat").setSolveFor("/physics/solid2", false);
    model.study("std3").feature("stat").setSolveFor("/physics/solid2", false);

//    In the Model Builder window, under Study 3: Smooth Design (mesh2), 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 2: Verification (comp2), clear the checkbox for Solid Mechanics (solid2).

    model.study("std2").feature("stat").setSolveFor("/physics/solid2", false);

//    In the Model Builder window, under Study 2: Two Load Cases, 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 2: Verification (comp2), clear the checkbox for Solid Mechanics (solid2).
//    Right-click Study 2: Two Load Cases > Step 1: Stationary and choose Copy.
//    In the Model Builder window, right-click Study 4: Verification and choose Paste Stationary.

    model.study("std4").feature().copy("stat", "std2/stat");
    model.study("std4").feature("stat").setSolveFor("/physics/solid2", true);

//    In the Settings window for Stationary, locate the Physics and Variables Selection section.

    model.study("std4").feature("stat").setSolveFor("/common/dtopo1", false);

//    In the Solve for column of the table, under Component 2: Verification (comp2), select the checkbox for Solid Mechanics (solid2).
//    In the Solve for column of the table, under Component 1: Optimization (comp1), clear the checkbox for Topology Optimization.
//    In the Study toolbar, click Compute.

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

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

//    Add a new 3D plot group to plot the displacement.
//    In the Model Builder window, right-click Results > Topology Optimization and choose Delete.

    model.nodeGroup().remove("grp3");

//    In the Results toolbar, click 3D Plot Group.

    model.result().create("pg7", "PlotGroup3D");
    model.result("pg7").run();

//    In the Settings window for 3D Plot Group, type Displacement (solid2) in the Label text field.

    model.result("pg7").label("Displacement (solid2)");

//    Locate the Data section.
//    From the Dataset list, select Study 4: Verification/Solution 14 (7) (sol14).

    model.result("pg7").set("data", "dset7");

//    Right-click Displacement (solid2) and choose Surface.

    model.result("pg7").create("surf1", "Surface");
    model.result("pg7").feature("surf1").set("evaluationsettings", "parent");

//    In the Model Builder window, right-click Surface 1 and choose Deformation.

    model.result("pg7").feature("surf1").create("def1", "Deform");
    model.result("pg7").run();

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Displacement (solid2) toolbar, click Plot.

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

    model.title("Bracket \u2014 Topology Optimization");

    model
         .description("This example shows how to perform a topology optimization with several load and constraint cases. The density feature for topology optimization is used together with a parametric sweep where each optimized solution is used as input for a further improved optimization. The final optimized geometry is exported and then imported for a verification analysis in which the now void regions are excluded.");

    return model;
  }

  public static void main(String[] args) {
    Model model = run();
    model = run2(model);
    run3(model);
  }

}
