/*
 * axisymmetric_twist_and_bending.java
 */

import com.comsol.model.*;
import com.comsol.model.util.*;

/** Model exported on May 6 2026, 08:08 by COMSOL 6.4.0.414. */
public class axisymmetric_twist_and_bending {

  public static Model run() {
    Model model = ModelUtil.create("Model");

//    From the File menu, choose New.
//    In the New window, click Model Wizard.
//    In the Model Wizard window, click 2D Axisymmetric.
//    In the Select Physics tree, select Structural Mechanics > Solid Mechanics (solid).
//    Click Add.
//    Click Study.
//    In the Select Study tree, select General Studies > Stationary.
//    Click Done.

    model.component().create("comp1", true);

    model.component("comp1").geom().create("geom1", 2);
    model.component("comp1").geom("geom1").axisymmetric(true);

    model.component("comp1").mesh().create("mesh1");

    model.component("comp1").physics().create("solid", "SolidMechanics", "geom1");

    model.study().create("std1");
    model.study("std1").create("stat", "Stationary");

//    In the Model Builder window, under Global Definitions, click Parameters 1.
//    In the Settings window for Parameters, locate the Parameters section.
//    In the table, enter the following settings:

    model.param().set("r0", "2[mm]");
    model.param().descr("r0", "Inner radius");
    model.param().set("R1", "12[mm]");
    model.param().descr("R1", "Outer radius, thick section");
    model.param().set("R2", "5[mm]");
    model.param().descr("R2", "Outer radius, thin section");
    model.param().set("L1", "18[mm]");
    model.param().descr("L1", "Length, thick section");
    model.param().set("L2", "50[mm]");
    model.param().descr("L2", "Length, thin section");
    model.param().set("I", "(pi/4)*(R2^4 - r0^4)");
    model.param().descr("I", "Area moment of inertia");
    model.param().set("J", "2*I");
    model.param().descr("J", "Torsion constant");
    model.param().set("A_load", "pi*(R2^2 - r0^2)");
    model.param().descr("A_load", "Area of applied load");
    model.param().set("F_load", "10[MPa]*A_load");
    model.param().descr("F_load", "Total applied force");
    model.param().set("Mt", "(2*pi/3)*(F_load/A_load)*(R2^3 - r0^3)");
    model.param().descr("Mt", "Equivalent twisting moment");
    model.param().set("Mb", "F_load*(L2 - L1)");
    model.param().descr("Mb", "Bending moment at transition");

//    Create a 2D shaft section as a global geometry part so that it can be referenced by the 2D axisymmetric and 3D components, respectively.
//    In the Model Builder window, right-click Global Definitions and choose Geometry Parts > 2D Part.

    model.geom().create("part1", "Part", 2);

//    In the Settings window for Part, type Shaft Section in the Label text field.

    model.geom("part1").label("Shaft Section");

//    Locate the Units section.
//    From the Length unit list, select mm.

    model.geom("part1").lengthUnit("mm");

//    In the Geometry toolbar, click Polygon.

    model.geom("part1").create("pol1", "Polygon");
    model.geom("part1").feature("pol1").set("source", "table");

//    In the Settings window for Polygon, locate the Coordinates section.
//    In the table, enter the following settings:

    model.geom("part1").feature("pol1").setIndex("table", "r0", 0, 0);
    model.geom("part1").feature("pol1").setIndex("table", 0, 0, 1);
    model.geom("part1").feature("pol1").setIndex("table", "R1", 1, 0);
    model.geom("part1").feature("pol1").setIndex("table", 0, 1, 1);
    model.geom("part1").feature("pol1").setIndex("table", "R1", 2, 0);
    model.geom("part1").feature("pol1").setIndex("table", "L1", 2, 1);
    model.geom("part1").feature("pol1").setIndex("table", "R2", 3, 0);
    model.geom("part1").feature("pol1").setIndex("table", "L1", 3, 1);
    model.geom("part1").feature("pol1").setIndex("table", "R2", 4, 0);
    model.geom("part1").feature("pol1").setIndex("table", "L2", 4, 1);
    model.geom("part1").feature("pol1").setIndex("table", "r0", 5, 0);
    model.geom("part1").feature("pol1").setIndex("table", "L2", 5, 1);

//    In the Geometry toolbar, click Fillet.

    model.geom("part1").run("pol1");
    model.geom("part1").create("fil1", "Fillet");

//    On the object pol1, select Point 3.

    model.geom("part1").feature("fil1").selection("pointinsketch").set("pol1", 3);

//    In the Settings window for Fillet, locate the Radius section.
//    In the Radius text field, type 1.

    model.geom("part1").feature("fil1").set("radius", 1);

//    In the Geometry toolbar, click Fillet.

    model.geom("part1").run("fil1");
    model.geom("part1").create("fil2", "Fillet");

//    On the object fil1, select Point 3.

    model.geom("part1").feature("fil2").selection("pointinsketch").set("fil1", 3);

//    In the Settings window for Fillet, locate the Radius section.
//    In the Radius text field, type 2.

    model.geom("part1").feature("fil2").set("radius", 2);

//    In the Geometry toolbar, click Build All.

    model.geom("part1").run("fil2");

//    In the Home 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 Home toolbar, click Add Material to close the Add Material window.
//    Right-click Global Definitions and choose Load and Constraint Groups > Load Group.

    model.group().create("lg1", "LoadGroup");

//    In the Settings window for Load Group, type Axial Extension in the Label text field.

    model.group("lg1").label("Axial Extension");

//    In the Model Builder window, right-click Load and Constraint Groups and choose Load Group.

    model.group().create("lg2", "LoadGroup");

//    In the Settings window for Load Group, type Torsion in the Label text field.

    model.group("lg2").label("Torsion");

//    Right-click Load and Constraint Groups and choose Load Group.

    model.group().create("lg3", "LoadGroup");

//    In the Settings window for Load Group, type Bending in the Label text field.

    model.group("lg3").label("Bending");

//    In the Model Builder window, under Component 1 (comp1), click Geometry 1.
//    In the Settings window for Geometry, locate the Units section.
//    From the Length unit list, select mm.

    model.component("comp1").geom("geom1").lengthUnit("mm");

//    In the Geometry toolbar, click Part Instance and choose Shaft Section.

    model.component("comp1").geom("geom1").create("pi1", "PartInstance");
    model.component("comp1").geom("geom1").feature("pi1").set("selkeepnoncontr", false);
    model.component("comp1").geom("geom1").feature("pi1").set("part", "part1");
    model.component("comp1").geom("geom1").run();

//    In the Model Builder window, right-click Component 1 (comp1) > Materials and choose More Materials > Material Link.

    model.component("comp1").material().create("matlnk1", "Link");

//    Next, include the circumferential displacement as a new dependent variable to allow twisting deformations. In addition, enable the mode extension with mode number 1, which allows to compute bending deformations in frequency domain.
//    In the Settings window for Solid Mechanics, locate the Axial Symmetry Approximation section.
//    Select the Include circumferential displacement checkbox.

    model.component("comp1").physics("solid").prop("Mode2Daxi").set("includeTwist", true);

//    Find the Time-harmonic subsection.
//    Select the Circumferential mode extension checkbox.

    model.component("comp1").physics("solid").prop("Mode2Daxi").set("ModeExtension", true);

//    In the \[m\] text field, type 1.

    model.component("comp1").physics("solid").prop("Mode2Daxi").set("mk", 1);

//    In the Physics toolbar, click Boundaries and choose Fixed Constraint.

    model.component("comp1").physics("solid").create("fix1", "Fixed", 1);

//    Select Boundary 2.

    model.component("comp1").physics("solid").feature("fix1").selection().set(2);

//    In the Physics toolbar, click Boundaries and choose Boundary Load.

    model.component("comp1").physics("solid").create("bndl1", "BoundaryLoad", 1);

//    In the Settings window for Boundary Load, type Boundary Load: Axial Extension in the Label text field.

    model.component("comp1").physics("solid").feature("bndl1").label("Boundary Load: Axial Extension");

//    Select Boundary 3.

    model.component("comp1").physics("solid").feature("bndl1").selection().set(3);

//    Locate the Force section.
//    From the Load type list, select Total force.

    model.component("comp1").physics("solid").feature("bndl1").set("forceType", "TotalForce");

//    Specify the \[\mathbf{F}_{\mathrm{tot}}\] vector as

    model.component("comp1").physics("solid").feature("bndl1").set("force", new String[]{"0", "0", "F_load"});

//    In the Physics toolbar, click Load Group and choose Axial Extension.

    model.component("comp1").physics("solid").feature("bndl1").set("loadGroup", "lg1");

//    In the Physics toolbar, click Boundaries and choose Boundary Load.

    model.component("comp1").physics("solid").create("bndl2", "BoundaryLoad", 1);

//    In the Settings window for Boundary Load, type Boundary Load: Torsion in the Label text field.

    model.component("comp1").physics("solid").feature("bndl2").label("Boundary Load: Torsion");

//    Select Boundary 3.

    model.component("comp1").physics("solid").feature("bndl2").selection().set(3);

//    Locate the Force section.
//    From the Load type list, select Total force.

    model.component("comp1").physics("solid").feature("bndl2").set("forceType", "TotalForce");

//    Specify the \[\mathbf{F}_{\mathrm{tot}}\] vector as

    model.component("comp1").physics("solid").feature("bndl2").set("force", new String[]{"0", "F_load", "0"});

//    In the Physics toolbar, click Load Group and choose Torsion.

    model.component("comp1").physics("solid").feature("bndl2").set("loadGroup", "lg2");

//    In the Physics toolbar, click Boundaries and choose Boundary Load.

    model.component("comp1").physics("solid").create("bndl3", "BoundaryLoad", 1);

//    The bending force will be active only in frequency domain, where a complex-valued displacement field is assumed. The real part of the force should act only in x direction when interpreted in a Cartesian coordinate system. The coordinate transformation from the cylindrical to Cartesian system requires the force to be complex-valued.
//    In the Settings window for Boundary Load, type Boundary Load: Bending in the Label text field.

    model.component("comp1").physics("solid").feature("bndl3").label("Boundary Load: Bending");

//    Select Boundary 3.

    model.component("comp1").physics("solid").feature("bndl3").selection().set(3);

//    Locate the Force section.
//    From the Load type list, select Total force.

    model.component("comp1").physics("solid").feature("bndl3").set("forceType", "TotalForce");

//    Specify the \[\mathbf{F}_{\mathrm{tot}}\] vector as

    model.component("comp1").physics("solid").feature("bndl3")
         .set("force", new String[]{"F_load", "-i*F_load", "0"});

//    In the Physics toolbar, click Load Group and choose Bending.

    model.component("comp1").physics("solid").feature("bndl3").set("loadGroup", "lg3");

//    In the Mesh toolbar, click Free Triangular.

    model.component("comp1").mesh("mesh1").create("ftri1", "FreeTri");

//    Right-click Free Triangular 1 and choose Distribution.

    model.component("comp1").mesh("mesh1").feature("ftri1").create("dis1", "Distribution");

//    Select Boundary 7.

    model.component("comp1").mesh("mesh1").feature("ftri1").feature("dis1").selection().set(7);

//    In the Settings window for Distribution, locate the Distribution section.
//    In the Number of elements text field, type 20.

    model.component("comp1").mesh("mesh1").feature("ftri1").feature("dis1").set("numelem", 20);

//    In the Model Builder window, under Component 1 (comp1) > Mesh 1, click Size.
//    In the Settings window for Size, locate the Element Size section.
//    From the Predefined list, select Finer.

    model.component("comp1").mesh("mesh1").feature("size").set("hauto", 3);

//    Click Build All.

    model.component("comp1").mesh("mesh1").run();

//    In the Definitions toolbar, click Nonlocal Couplings and choose Maximum.

    model.component("comp1").cpl().create("maxop1", "Maximum");

//    In the Settings window for Maximum, type max2Daxi in the Operator name text field.

    model.component("comp1").cpl("maxop1").set("opname", "max2Daxi");

//    Locate the Source Selection section.
//    From the Geometric entity level list, select Boundary.

    model.component("comp1").cpl("maxop1").selection().geom("geom1", 1);

//    Select Boundaries 4, 5, 7.

    model.component("comp1").cpl("maxop1").selection().set(4, 5, 7);

//    In the Model Builder window, right-click the root node and choose Add Component > 3D.

    model.component().create("comp2", true);

    model.component("comp2").geom().create("geom2", 3);
    model.component("comp2").geom("geom2").geomRep("comsol");

    model.component("comp2").mesh().create("mesh2");
    model.component("comp2").mesh("mesh2").contribute("geom/detail", true);

//    In the Settings window for Geometry, locate the Units section.
//    From the Length unit list, select mm.

    model.component("comp2").geom("geom2").lengthUnit("mm");

//    In the Geometry toolbar, click Work Plane.

    model.component("comp2").geom("geom2").create("wp1", "WorkPlane");
    model.component("comp2").geom("geom2").feature("wp1").set("unite", true);

//    In the Settings window for Work Plane, locate the Plane Definition section.
//    From the Plane list, select xz-plane.

    model.component("comp2").geom("geom2").feature("wp1").set("quickplane", "xz");

//    In the Model Builder window, click Plane Geometry.
//    In the Work Plane toolbar, click Part Instance and choose Shaft Section.

    model.component("comp2").geom("geom2").feature("wp1").geom().create("pi1", "PartInstance");
    model.component("comp2").geom("geom2").feature("wp1").geom().feature("pi1").set("selkeepnoncontr", false);
    model.component("comp2").geom("geom2").feature("wp1").geom().feature("pi1").set("part", "part1");

//    In the Model Builder window, right-click Component 2 (comp2) > Geometry 2 > Work Plane 1 (wp1) and choose Revolve.

    model.component("comp2").geom("geom2").run("wp1");
    model.component("comp2").geom("geom2").feature().create("rev1", "Revolve");
    model.component("comp2").geom("geom2").feature("rev1").set("workplane", "wp1");
    model.component("comp2").geom("geom2").feature("rev1").selection("input").set("wp1");
    model.component("comp2").geom("geom2").feature("rev1").set("angtype", "full");

//    In the Settings window for Revolve, click Build All Objects.

    model.component("comp2").geom("geom2").runPre("fin");

//    In the Definitions toolbar, click Coordinate Systems and choose Cylindrical System.

    model.component("comp2").coordSystem().create("sys3", "Cylindrical");

    model.component("comp2").geom("geom2").run();

//    In the Settings window for Cylindrical System, type Cylindrical System (Material Frame) in the Label text field.

    model.component("comp2").coordSystem("sys3").label("Cylindrical System (Material Frame)");

//    Locate the Coordinate Names section.
//    From the Frame list, select Material (X, Y, Z).

    model.component("comp2").coordSystem("sys3").set("frametype", "material");

//    In the Home toolbar, click Add Physics to open the Add Physics window.
//    In the tree, select Structural Mechanics > Solid Mechanics (solid).
//    Click Add to Component 2 in the window toolbar.

    model.component("comp2").physics().create("solid2", "SolidMechanics", "geom2");

//    In the Home toolbar, click Add Physics to close the Add Physics window.
//    In the Model Builder window, right-click Component 2 (comp2) > Materials and choose More Materials > Material Link.

    model.component("comp2").material().create("matlnk2", "Link");

//    In the Physics toolbar, click Boundaries and choose Fixed Constraint.

    model.component("comp2").physics("solid2").create("fix1", "Fixed", 2);

//    Select Boundaries 3, 4, 18, 26.

    model.component("comp2").physics("solid2").feature("fix1").selection().set(3, 4, 18, 26);

//    In the Physics toolbar, click Boundaries and choose Boundary Load.

    model.component("comp2").physics("solid2").create("bndl1", "BoundaryLoad", 2);

//    In the Settings window for Boundary Load, type Boundary Load: Axial Extension in the Label text field.

    model.component("comp2").physics("solid2").feature("bndl1").label("Boundary Load: Axial Extension");

//    Select Boundaries 13, 14, 23, 27.

    model.component("comp2").physics("solid2").feature("bndl1").selection().set(13, 14, 23, 27);

//    Locate the Force section.
//    From the Load type list, select Total force.

    model.component("comp2").physics("solid2").feature("bndl1").set("forceType", "TotalForce");

//    Specify the \[\mathbf{F}_{\mathrm{tot}}\] vector as

    model.component("comp2").physics("solid2").feature("bndl1").set("force", new String[]{"0", "0", "F_load"});

//    In the Physics toolbar, click Load Group and choose Axial Extension.

    model.component("comp2").physics("solid2").feature("bndl1").set("loadGroup", "lg1");

//    In the Physics toolbar, click Boundaries and choose Boundary Load.

    model.component("comp2").physics("solid2").create("bndl2", "BoundaryLoad", 2);

//    In the Settings window for Boundary Load, type Boundary Load: Torsion in the Label text field.

    model.component("comp2").physics("solid2").feature("bndl2").label("Boundary Load: Torsion");

//    Select Boundaries 13, 14, 23, 27.

    model.component("comp2").physics("solid2").feature("bndl2").selection().set(13, 14, 23, 27);

//    Locate the Coordinate System Selection section.
//    From the Coordinate system list, select Cylindrical System (Material Frame) (sys3).

    model.component("comp2").physics("solid2").feature("bndl2").set("coordinateSystem", "sys3");

//    Locate the Force section.
//    From the Load type list, select Total force.

    model.component("comp2").physics("solid2").feature("bndl2").set("forceType", "TotalForce");

//    Specify the \[\mathbf{F}_{\mathrm{tot}}\] vector as

    model.component("comp2").physics("solid2").feature("bndl2").set("force", new String[]{"0", "F_load", "0"});

//    In the Physics toolbar, click Load Group and choose Torsion.

    model.component("comp2").physics("solid2").feature("bndl2").set("loadGroup", "lg2");

//    In the Physics toolbar, click Boundaries and choose Boundary Load.

    model.component("comp2").physics("solid2").create("bndl3", "BoundaryLoad", 2);

//    In the Settings window for Boundary Load, type Boundary Load: Bending in the Label text field.

    model.component("comp2").physics("solid2").feature("bndl3").label("Boundary Load: Bending");

//    Select Boundaries 13, 14, 23, 27.

    model.component("comp2").physics("solid2").feature("bndl3").selection().set(13, 14, 23, 27);

//    Locate the Force section.
//    From the Load type list, select Total force.

    model.component("comp2").physics("solid2").feature("bndl3").set("forceType", "TotalForce");

//    Specify the \[\mathbf{F}_{\mathrm{tot}}\] vector as

    model.component("comp2").physics("solid2").feature("bndl3").set("force", new String[]{"F_load", "0", "0"});

//    In the Physics toolbar, click Load Group and choose Bending.

    model.component("comp2").physics("solid2").feature("bndl3").set("loadGroup", "lg3");

//    Add a Local System Results node to evaluate stress components in cylindrical coordinates.
//    In the Physics toolbar, click Domains and choose Local System Results.

    model.component("comp2").physics("solid2").create("lsr1", "LocalSystemResults", 3);

//    In the Settings window for Local System Results, locate the Coordinate System Selection section.
//    From the Coordinate system list, select Cylindrical System (Material Frame) (sys3).

    model.component("comp2").physics("solid2").feature("lsr1").set("coordinateSystem", "sys3");

//    In the Definitions toolbar, click Nonlocal Couplings and choose Maximum.

    model.component("comp2").cpl().create("maxop2", "Maximum");

//    In the Settings window for Maximum, locate the Source Selection section.
//    From the Geometric entity level list, select Boundary.

    model.component("comp2").cpl("maxop2").selection().geom("geom2", 2);

//    In the Operator name text field, type max3D.

    model.component("comp2").cpl("maxop2").set("opname", "max3D");

//    Select Boundaries 7, 8, 9, 10, 11, 12, 20, 21, 22, 28, 29, 30.

    model.component("comp2").cpl("maxop2").selection().set(7, 8, 9, 10, 11, 12, 20, 21, 22, 28, 29, 30);

//    In the Mesh toolbar, click More Generators and choose Free Triangular.

    model.component("comp2").mesh("mesh2").create("ftri1", "FreeTri");

//    Select Boundary 33.

    return model;
  }

  public static Model run2(Model model) {

    model.component("comp2").mesh("mesh2").feature("ftri1").selection().set(33);

//    Right-click Free Triangular 1 and choose Distribution.

    model.component("comp2").mesh("mesh2").feature("ftri1").create("dis1", "Distribution");

//    Select Edge 61.

    model.component("comp2").mesh("mesh2").feature("ftri1").feature("dis1").selection().set(61);

//    In the Settings window for Distribution, locate the Distribution section.
//    In the Number of elements text field, type 20.

    model.component("comp2").mesh("mesh2").feature("ftri1").feature("dis1").set("numelem", 20);

//    In the Mesh toolbar, click Swept.

    model.component("comp2").mesh("mesh2").create("swe1", "Sweep");

//    In the Model Builder window, click Size.
//    In the Settings window for Size, locate the Element Size section.
//    From the Predefined list, select Extra fine.

    model.component("comp2").mesh("mesh2").feature("size").set("hauto", 2);

//    Click Build All.

    model.component("comp2").mesh("mesh2").run();

//    In the Model Builder window, click Study 1.
//    In the Settings window for Study, type Study 1: Axial Extension & Torsion in the Label text field.

    model.study("std1").label("Study 1: Axial Extension & Torsion");

//    In the Model Builder window, under Study 1: Axial Extension & Torsion, click Step 1: Stationary.
//    In the Settings window for Stationary, 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("loadgroup", false, 0, 1);
    model.study("std1").feature("stat").setIndex("loadgroupweight", "1.0", 0, 1);
    model.study("std1").feature("stat").setIndex("loadgroup", false, 0, 2);
    model.study("std1").feature("stat").setIndex("loadgroupweight", "1.0", 0, 2);
    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("loadgroup", false, 0, 1);
    model.study("std1").feature("stat").setIndex("loadgroupweight", "1.0", 0, 1);
    model.study("std1").feature("stat").setIndex("loadgroup", false, 0, 2);
    model.study("std1").feature("stat").setIndex("loadgroupweight", "1.0", 0, 2);

//    In the table, enter the following settings:

    model.study("std1").feature("stat").setIndex("loadcase", "Axial Extension", 0);
    model.study("std1").feature("stat").setIndex("loadgroup", true, 0, 0);

//    Click Add.

    model.study("std1").feature("stat").setIndex("loadcase", "Load case 1", 1);
    model.study("std1").feature("stat").setIndex("loadgroup", false, 1, 0);
    model.study("std1").feature("stat").setIndex("loadgroupweight", "1.0", 1, 0);
    model.study("std1").feature("stat").setIndex("loadgroup", false, 1, 1);
    model.study("std1").feature("stat").setIndex("loadgroupweight", "1.0", 1, 1);
    model.study("std1").feature("stat").setIndex("loadgroup", false, 1, 2);
    model.study("std1").feature("stat").setIndex("loadgroupweight", "1.0", 1, 2);
    model.study("std1").feature("stat").setIndex("loadcase", "Load case 1", 1);
    model.study("std1").feature("stat").setIndex("loadgroup", false, 1, 0);
    model.study("std1").feature("stat").setIndex("loadgroupweight", "1.0", 1, 0);
    model.study("std1").feature("stat").setIndex("loadgroup", false, 1, 1);
    model.study("std1").feature("stat").setIndex("loadgroupweight", "1.0", 1, 1);
    model.study("std1").feature("stat").setIndex("loadgroup", false, 1, 2);
    model.study("std1").feature("stat").setIndex("loadgroupweight", "1.0", 1, 2);

//    In the table, enter the following settings:

    model.study("std1").feature("stat").setIndex("loadcase", "Torsion", 1);
    model.study("std1").feature("stat").setIndex("loadgroup", true, 1, 1);

//    In the Study toolbar, click Compute.

    model.study("std1").createAutoSequences("all");

    model.sol("sol1").runAll();

    model.result().create("pg1", "PlotGroup2D");
    model.result("pg1").set("data", "dset1");
    model.result("pg1").setIndex("looplevel", 2, 0);
    model.result("pg1").label("Stress (solid)");
    model.result("pg1").set("frametype", "spatial");
    model.result("pg1").create("surf1", "Surface");
    model.result("pg1").feature("surf1").set("expr", new String[]{"solid.misesGp"});
    model.result("pg1").feature("surf1").set("threshold", "manual");
    model.result("pg1").feature("surf1").set("thresholdvalue", 0.2);
    model.result("pg1").feature("surf1").set("colortable", "Rainbow");
    model.result("pg1").feature("surf1").set("colortabletrans", "none");
    model.result("pg1").feature("surf1").set("colorscalemode", "linear");
    model.result("pg1").feature("surf1").set("resolution", "normal");
    model.result("pg1").feature("surf1").set("refine", 2);
    model.result("pg1").feature("surf1").set("colortable", "Prism");
    model.result("pg1").feature("surf1").create("def", "Deform");
    model.result("pg1").feature("surf1").feature("def").set("expr", new String[]{"u", "w"});
    model.result("pg1").feature("surf1").feature("def").set("descr", "Displacement field");
    model.result().dataset().create("dset1solidrev", "Revolve2D");
    model.result().dataset("dset1solidrev").set("data", "dset1");
    model.result().dataset("dset1solidrev").set("revangle", 225);
    model.result().dataset("dset1solidrev").set("startangle", -90);
    model.result().create("pg2", "PlotGroup3D");
    model.result("pg2").set("data", "dset1solidrev");
    model.result("pg2").setIndex("looplevel", 2, 0);
    model.result("pg2").label("Stress, 3D (solid)");
    model.result("pg2").set("frametype", "spatial");
    model.result("pg2").create("surf1", "Surface");
    model.result("pg2").feature("surf1").set("expr", new String[]{"solid.misesGp"});
    model.result("pg2").feature("surf1").set("threshold", "manual");
    model.result("pg2").feature("surf1").set("thresholdvalue", 0.2);
    model.result("pg2").feature("surf1").set("colortable", "Rainbow");
    model.result("pg2").feature("surf1").set("colortabletrans", "none");
    model.result("pg2").feature("surf1").set("colorscalemode", "linear");
    model.result("pg2").feature("surf1").set("colortable", "Prism");
    model.result("pg2").feature("surf1").create("def", "Deform");
    model.result("pg2").feature("surf1").feature("def").set("revcoordsys", "cylindrical");
    model.result("pg2").feature("surf1").feature("def").set("expr", new String[]{"u", "v", "w"});
    model.result("pg2").feature("surf1").feature("def").set("descr", "Displacement field");
    model.result("pg2").feature("surf1").feature("def").set("descractive", true);
    model.result().create("pg3", "PlotGroup3D");
    model.result("pg3").set("data", "dset2");
    model.result("pg3").setIndex("looplevel", 2, 0);
    model.result("pg3").label("Stress (solid2)");
    model.result("pg3").set("frametype", "spatial");
    model.result("pg3").create("vol1", "Volume");
    model.result("pg3").feature("vol1").set("expr", new String[]{"solid2.misesGp"});
    model.result("pg3").feature("vol1").set("threshold", "manual");
    model.result("pg3").feature("vol1").set("thresholdvalue", 0.2);
    model.result("pg3").feature("vol1").set("colortable", "Rainbow");
    model.result("pg3").feature("vol1").set("colortabletrans", "none");
    model.result("pg3").feature("vol1").set("colorscalemode", "linear");
    model.result("pg3").feature("vol1").set("resolution", "custom");
    model.result("pg3").feature("vol1").set("refine", 2);
    model.result("pg3").feature("vol1").set("colortable", "Prism");
    model.result("pg3").feature("vol1").create("def", "Deform");
    model.result("pg3").feature("vol1").feature("def").set("expr", new String[]{"u2", "v2", "w2"});
    model.result("pg3").feature("vol1").feature("def").set("descr", "Displacement field");
    model.result("pg1").run();

//    Set default units for result presentation.
//    In the Results toolbar, click Configurations and choose Preferred Units.

    model.result().configuration().create("prfu1", "PreferredUnits");

//    In the Settings window for Preferred Units, locate the Units section.
//    Click Add Physical Quantity.
//    In the Physical Quantity dialog, type stress in the text field.
//    In the tree, select Solid Mechanics > Stress tensor (N/m^2).
//    Click OK.

    model.result().configuration("prfu1")
         .setIndex("quantityunits", new String[]{"stress", "Stress tensor", "N/m^2", "N/m^2"}, 0);

//    In the Settings window for Preferred Units, locate the Units section.
//    In the table, enter the following settings:

    model.result().configuration("prfu1").setIndex("quantityunits", "MPa", 0, 3);

//    Click Apply.

    model.result().configuration("prfu1").apply();
    model.result("pg1").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 > Frequency Domain.
//    Click Add Study in the window toolbar.

    model.study().create("std2");
    model.study("std2").create("freq", "Frequency");

//    In the Home toolbar, click Add Study to close the Add Study window.
//    Bending in 2D axisymmetry requires a special ansatz for the displacement field which is only available for frequency-domain (and eigenfrequency) studies. In order to solve for a stationary response using a frequency-domain study, set the target frequency to 0.
//    In the Settings window for Study, type Study 2: Bending in the Label text field.

    model.study("std2").label("Study 2: Bending");

//    In the Model Builder window, under Study 2: Bending, click Step 1: Frequency Domain.
//    In the Settings window for Frequency Domain, locate the Study Settings section.
//    In the Frequencies text field, type 0.

    model.study("std2").feature("freq").set("plist", 0);

//    Click to expand the Study Extensions section.
//    Select the Define load cases checkbox.

    model.study("std2").feature("freq").set("useloadcase", true);

//    Click Add.

    model.study("std2").feature("freq").setIndex("loadcase", "Load case 1", 0);
    model.study("std2").feature("freq").setIndex("loadgroup", false, 0, 0);
    model.study("std2").feature("freq").setIndex("loadgroupweight", "1.0", 0, 0);
    model.study("std2").feature("freq").setIndex("loadgroup", false, 0, 1);
    model.study("std2").feature("freq").setIndex("loadgroupweight", "1.0", 0, 1);
    model.study("std2").feature("freq").setIndex("loadgroup", false, 0, 2);
    model.study("std2").feature("freq").setIndex("loadgroupweight", "1.0", 0, 2);
    model.study("std2").feature("freq").setIndex("loadcase", "Load case 1", 0);
    model.study("std2").feature("freq").setIndex("loadgroup", false, 0, 0);
    model.study("std2").feature("freq").setIndex("loadgroupweight", "1.0", 0, 0);
    model.study("std2").feature("freq").setIndex("loadgroup", false, 0, 1);
    model.study("std2").feature("freq").setIndex("loadgroupweight", "1.0", 0, 1);
    model.study("std2").feature("freq").setIndex("loadgroup", false, 0, 2);
    model.study("std2").feature("freq").setIndex("loadgroupweight", "1.0", 0, 2);

//    In the table, enter the following settings:

    model.study("std2").feature("freq").setIndex("loadcase", "Bending", 0);
    model.study("std2").feature("freq").setIndex("loadgroup", true, 0, 2);

//    In the Study toolbar, click Compute.

    model.study("std2").createAutoSequences("all");

    model.sol("sol2").runAll();

    model.result().create("pg4", "PlotGroup2D");
    model.result("pg4").set("data", "dset3");
    model.result("pg4").setIndex("looplevel", 1, 0);
    model.result("pg4").setIndex("looplevel", 1, 1);
    model.result("pg4").label("Stress (solid) 1");
    model.result("pg4").set("frametype", "spatial");
    model.result("pg4").create("surf1", "Surface");
    model.result("pg4").feature("surf1").set("expr", new String[]{"solid.misesGp_peak"});
    model.result("pg4").feature("surf1").set("threshold", "manual");
    model.result("pg4").feature("surf1").set("thresholdvalue", 0.2);
    model.result("pg4").feature("surf1").set("colortable", "Rainbow");
    model.result("pg4").feature("surf1").set("colortabletrans", "none");
    model.result("pg4").feature("surf1").set("colorscalemode", "linear");
    model.result("pg4").feature("surf1").set("resolution", "normal");
    model.result("pg4").feature("surf1").set("refine", 2);
    model.result("pg4").feature("surf1").set("colortable", "Prism");
    model.result("pg4").feature("surf1").create("def", "Deform");
    model.result("pg4").feature("surf1").feature("def").set("expr", new String[]{"u", "w"});
    model.result("pg4").feature("surf1").feature("def").set("descr", "Displacement field");
    model.result().dataset().create("dset3solidrev", "Revolve2D");
    model.result().dataset("dset3solidrev").set("data", "dset3");
    model.result().dataset("dset3solidrev").set("revangle", 225);
    model.result().dataset("dset3solidrev").set("startangle", -90);
    model.result().dataset("dset3solidrev").set("modenumber", "solid.mk");
    model.result().create("pg5", "PlotGroup3D");
    model.result("pg5").set("data", "dset3solidrev");
    model.result("pg5").setIndex("looplevel", 1, 0);
    model.result("pg5").setIndex("looplevel", 1, 1);
    model.result("pg5").label("Stress, 3D (solid) 1");
    model.result("pg5").set("frametype", "spatial");
    model.result("pg5").create("surf1", "Surface");
    model.result("pg5").feature("surf1").set("expr", new String[]{"solid.misesGp_peak"});
    model.result("pg5").feature("surf1").set("threshold", "manual");
    model.result("pg5").feature("surf1").set("thresholdvalue", 0.2);
    model.result("pg5").feature("surf1").set("colortable", "Rainbow");
    model.result("pg5").feature("surf1").set("colortabletrans", "none");
    model.result("pg5").feature("surf1").set("colorscalemode", "linear");
    model.result("pg5").feature("surf1").set("colortable", "Prism");
    model.result("pg5").feature("surf1").create("def", "Deform");
    model.result("pg5").feature("surf1").feature("def").set("revcoordsys", "cylindrical");
    model.result("pg5").feature("surf1").feature("def").set("expr", new String[]{"u", "v", "w"});
    model.result("pg5").feature("surf1").feature("def").set("descr", "Displacement field");
    model.result("pg5").feature("surf1").feature("def").set("descractive", true);
    model.result().create("pg6", "PlotGroup3D");
    model.result("pg6").set("data", "dset4");
    model.result("pg6").setIndex("looplevel", 1, 0);
    model.result("pg6").setIndex("looplevel", 1, 1);
    model.result("pg6").label("Stress (solid2) 1");
    model.result("pg6").set("frametype", "spatial");
    model.result("pg6").create("vol1", "Volume");
    model.result("pg6").feature("vol1").set("expr", new String[]{"solid2.misesGp_peak"});
    model.result("pg6").feature("vol1").set("threshold", "manual");
    model.result("pg6").feature("vol1").set("thresholdvalue", 0.2);
    model.result("pg6").feature("vol1").set("colortable", "Rainbow");
    model.result("pg6").feature("vol1").set("colortabletrans", "none");
    model.result("pg6").feature("vol1").set("colorscalemode", "linear");
    model.result("pg6").feature("vol1").set("resolution", "custom");
    model.result("pg6").feature("vol1").set("refine", 2);
    model.result("pg6").feature("vol1").set("colortable", "Prism");
    model.result("pg6").feature("vol1").create("def", "Deform");
    model.result("pg6").feature("vol1").feature("def").set("expr", new String[]{"u2", "v2", "w2"});
    model.result("pg6").feature("vol1").feature("def").set("descr", "Displacement field");
    model.result("pg4").run();
    model.result("pg2").run();

//    In the Model Builder window, under Results, click Stress, 3D (solid).
//    In the Settings window for 3D Plot Group, type Stress: Axial Extension & Torsion (2D axi & 3D) in the Label text field.

    model.result("pg2").label("Stress: Axial Extension & Torsion (2D axi & 3D)");

//    Click to expand the Title section.
//    From the Title type list, select None.

    model.result("pg2").set("titletype", "none");

//    Locate the Color Legend section.
//    Select the Show units checkbox.

    model.result("pg2").set("showlegendsunit", true);

//    Right-click Stress: Axial Extension & Torsion (2D axi & 3D) and choose Surface.

    model.result("pg2").create("surf2", "Surface");
    model.result("pg2").feature("surf2").set("evaluationsettings", "parent");

//    In the Settings window for Surface, locate the Data section.
//    From the Dataset list, select Study 1: Axial Extension & Torsion/Solution 1 (2) (sol1).

    model.result("pg2").feature("surf2").set("data", "dset2");

//    From the Solution parameters list, select From parent.

    model.result("pg2").feature("surf2").set("solutionparams", "parent");

//    Locate the Expression section.
//    In the Expression text field, type solid2.mises.

    model.result("pg2").feature("surf2").set("expr", "solid2.mises");

//    Click to expand the Inherit Style section.
//    From the Plot list, select Surface 1.

    model.result("pg2").feature("surf2").set("inheritplot", "surf1");

//    Right-click Surface 2 and choose Deformation.

    model.result("pg2").feature("surf2").create("def1", "Deform");
    model.result("pg2").run();
    model.result("pg2").run();

//    In the Model Builder window, right-click Surface 2 and choose Transformation.

    model.result("pg2").feature("surf2").create("trn1", "Transformation");
    model.result("pg2").run();

//    In the Settings window for Transformation, locate the Transformation section.
//    In the X text field, type 3*R1.

    model.result("pg2").feature("surf2").feature("trn1").set("move", new String[]{"3*R1", "0", "0"});

//    Clear the Apply to dataset edges checkbox.

    model.result("pg2").feature("surf2").feature("trn1").set("applytodatasetedges", false);
    model.result("pg2").run();
    model.result("pg2").create("line1", "Line");
    model.result("pg2").feature("line1").set("evaluationsettings", "parent");
    model.result("pg2").feature("line1").set("data", "dset2");
    model.result("pg2").feature("line1").set("expr", "1");
    model.result("pg2").feature("line1").set("coloring", "uniform");
    model.result("pg2").feature("line1").set("color", "black");
    model.result("pg2").feature("line1").create("trn1", "Transformation");
    model.result("pg2").run();
    model.result("pg2").feature("line1").feature("trn1").set("move", new String[]{"3*R1", "0", "0"});
    model.result("pg2").run();
    model.result("pg2").feature("line1").feature("trn1").set("applytodatasetedges", false);
    model.result("pg2").run();

//    In the Model Builder window, under Results, click Stress: Axial Extension & Torsion (2D axi & 3D).
//    In the Settings window for 3D Plot Group, click Plot First.

    model.result("pg2").stepFirst(0);
    model.result("pg2").run();

//    Click Plot Next.

    model.result("pg2").stepNext(0);
    model.result("pg2").run();
    model.result("pg5").run();

//    In the Model Builder window, expand the Results > Stress, 3D (solid) 1 node, then click Stress, 3D (solid) 1.
//    In the Settings window for 3D Plot Group, type Stress: Bending (2D axi & 3D) in the Label text field.

    model.result("pg5").label("Stress: Bending (2D axi & 3D)");

//    Locate the Title section.
//    From the Title type list, select None.

    model.result("pg5").set("titletype", "none");

//    Locate the Color Legend section.
//    Select the Show units checkbox.

    model.result("pg5").set("showlegendsunit", true);
    model.result("pg5").run();

//    In the Model Builder window, click Surface 1.
//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type solid.mises.

    model.result("pg5").feature("surf1").set("expr", "solid.mises");
    model.result("pg5").run();

//    In the Model Builder window, right-click Stress: Bending (2D axi & 3D) and choose Surface.

    model.result("pg5").create("surf2", "Surface");
    model.result("pg5").feature("surf2").set("evaluationsettings", "parent");

//    In the Settings window for Surface, locate the Data section.
//    From the Dataset list, select Study 2: Bending/Solution 2 (4) (sol2).

    model.result("pg5").feature("surf2").set("data", "dset4");

//    Locate the Expression section.
//    In the Expression text field, type solid2.mises.

    model.result("pg5").feature("surf2").set("expr", "solid2.mises");

//    Locate the Inherit Style section.
//    From the Plot list, select Surface 1.

    model.result("pg5").feature("surf2").set("inheritplot", "surf1");

//    Right-click Surface 2 and choose Deformation.

    model.result("pg5").feature("surf2").create("def1", "Deform");
    model.result("pg5").run();
    model.result("pg5").run();

//    In the Model Builder window, right-click Surface 2 and choose Transformation.

    model.result("pg5").feature("surf2").create("trn1", "Transformation");
    model.result("pg5").run();

//    In the Settings window for Transformation, locate the Transformation section.
//    In the X text field, type 3*R1.

    model.result("pg5").feature("surf2").feature("trn1").set("move", new String[]{"3*R1", "0", "0"});

//    Clear the Apply to dataset edges checkbox.

    model.result("pg5").feature("surf2").feature("trn1").set("applytodatasetedges", false);
    model.result("pg5").run();
    model.result("pg5").create("line1", "Line");
    model.result("pg5").feature("line1").set("evaluationsettings", "parent");
    model.result("pg5").feature("line1").set("data", "dset4");
    model.result("pg5").feature("line1").set("expr", "1");
    model.result("pg5").feature("line1").set("coloring", "uniform");
    model.result("pg5").feature("line1").set("color", "black");
    model.result("pg5").feature("line1").create("trn1", "Transformation");
    model.result("pg5").run();
    model.result("pg5").feature("line1").feature("trn1").set("applytodatasetedges", false);
    model.result("pg5").feature("line1").feature("trn1").set("move", new String[]{"3*R1", "0", "0"});
    model.result("pg5").run();

//    In the Results toolbar, click Evaluation Group.

    model.result().evaluationGroup().create("eg1", "EvaluationGroup");

//    In the Settings window for Evaluation Group, type Stress Concentration Factors in the Label text field.

    model.result().evaluationGroup("eg1").label("Stress Concentration Factors");

//    Locate the Data section.
//    From the Dataset list, select None.

    model.result().evaluationGroup("eg1").set("data", "none");

//    Locate the Transformation section.
//    Select the Transpose checkbox.

    model.result().evaluationGroup("eg1").set("transpose", true);

//    Click to expand the Format section.
//    From the Include parameters list, select Off.

    model.result().evaluationGroup("eg1").set("includeparameters", false);

//    Right-click Stress Concentration Factors and choose Global Evaluation.

    model.result().evaluationGroup("eg1").create("gev1", "EvalGlobal");

//    In the Settings window for Global Evaluation, locate the Data section.
//    From the Dataset list, select Study 1: Axial Extension & Torsion/Solution 1 (1) (sol1).

    model.result().evaluationGroup("eg1").feature("gev1").set("data", "dset1");

//    From the Parameter selection (Load case) list, select First.

    model.result().evaluationGroup("eg1").feature("gev1").setIndex("looplevelinput", "first", 0);

//    Locate the Expressions section.
//    In the table, enter the following settings:

    model.result().evaluationGroup("eg1").feature("gev1").setIndex("expr", "max2Daxi(solid.szz)/(F_load/A_load)", 0);
    model.result().evaluationGroup("eg1").feature("gev1").setIndex("descr", "Axial extension (2D axi)", 0);
    model.result().evaluationGroup("eg1").feature("gev1")
         .setIndex("expr", "comp2.max3D(comp2.solid2.lsr1.sl33)/(F_load/A_load)", 1);
    model.result().evaluationGroup("eg1").feature("gev1").setIndex("descr", "Axial extension (3D)", 1);

//    In the Model Builder window, right-click Stress Concentration Factors and choose Global Evaluation.

    model.result().evaluationGroup("eg1").create("gev2", "EvalGlobal");

//    In the Settings window for Global Evaluation, locate the Data section.
//    From the Dataset list, select Study 1: Axial Extension & Torsion/Solution 1 (1) (sol1).

    model.result().evaluationGroup("eg1").feature("gev2").set("data", "dset1");

//    From the Parameter selection (Load case) list, select Last.

    model.result().evaluationGroup("eg1").feature("gev2").setIndex("looplevelinput", "last", 0);

//    Locate the Expressions section.
//    In the table, enter the following settings:

    model.result().evaluationGroup("eg1").feature("gev2").setIndex("expr", "max2Daxi(solid.sphiz)/(Mt*R2/J)", 0);
    model.result().evaluationGroup("eg1").feature("gev2").setIndex("unit", "", 0);
    model.result().evaluationGroup("eg1").feature("gev2").setIndex("descr", "Torsion (2D axi)", 0);
    model.result().evaluationGroup("eg1").feature("gev2")
         .setIndex("expr", "comp2.max3D(solid2.lsr1.sl23)/(Mt*R2/J)", 1);
    model.result().evaluationGroup("eg1").feature("gev2").setIndex("descr", "Torsion (3D)", 1);

//    The local stress component solid2.lsr1.sl23 in 3D represents the shear stress s \varphi z , as a cylindrical system was selected in the Local System Results node.
//    Right-click Stress Concentration Factors and choose Global Evaluation.

    model.result().evaluationGroup("eg1").create("gev3", "EvalGlobal");

//    In the Settings window for Global Evaluation, locate the Data section.
//    From the Dataset list, select Study 2: Bending/Solution 2 (3) (sol2).

    model.result().evaluationGroup("eg1").feature("gev3").set("data", "dset3");

//    From the Parameter selection (freq) list, select Last.

    model.result().evaluationGroup("eg1").feature("gev3").setIndex("looplevelinput", "last", 1);

//    From the Parameter selection (Load case) list, select Last.

    model.result().evaluationGroup("eg1").feature("gev3").setIndex("looplevelinput", "last", 0);

//    Locate the Expressions section.
//    In the table, enter the following settings:

    model.result().evaluationGroup("eg1").feature("gev3").setIndex("expr", "max2Daxi(abs(solid.szz))/(Mb*R2/I)", 0);
    model.result().evaluationGroup("eg1").feature("gev3").setIndex("descr", "Bending (2D axi)", 0);
    model.result().evaluationGroup("eg1").feature("gev3")
         .setIndex("expr", "comp2.max3D(solid2.lsr1.sl33)/(Mb*R2/I)", 1);
    model.result().evaluationGroup("eg1").feature("gev3").setIndex("descr", "Bending (3D)", 1);

//    In the Stress Concentration Factors toolbar, click Evaluate.

    model.result().evaluationGroup("eg1").run();
    model.result("pg4").run();
    model.result("pg4").feature("surf1").set("expr", "solid.mises");
    model.result("pg4").run();
    model.result("pg6").run();
    model.result("pg6").feature("vol1").set("expr", "solid2.mises");
    model.result("pg6").run();
    model.result().dataset().create("cpt1", "CutPoint3D");
    model.result().dataset("cpt1").set("pointx", "R2");
    model.result().dataset("cpt1").set("pointy", 0);
    model.result().dataset("cpt1").set("pointz", "L2");
    model.result("pg2").run();
    model.result().duplicate("pg7", "pg2");
    model.result("pg7").run();
    model.result("pg7").label("Thumbnail");
    model.result("pg7").set("showlegends", false);
    model.result("pg7").run();
    model.result("pg7").feature("surf2").set("expr", "1");
    model.result("pg7").run();
    model.result("pg7").feature("surf2").feature().remove("def1");
    model.result("pg7").run();
    model.result("pg7").run();
    model.result("pg7").feature("surf2").create("mtrl1", "MaterialAppearance");
    model.result("pg7").run();
    model.result("pg7").feature("surf2").feature("mtrl1").set("appearance", "custom");
    model.result("pg7").feature("surf2").feature("mtrl1").set("family", "steel");
    model.result("pg7").run();
    model.result("pg7").feature().remove("line1");
    model.result("pg7").run();
    model.result("pg7").run();
    model.result("pg7").create("arpt1", "ArrowPoint");
    model.result("pg7").feature("arpt1").set("revcoordsys", "cylindrical");
    model.result("pg7").feature("arpt1").set("data", "cpt1");
    model.result("pg7").feature("arpt1").set("expr", new String[]{"0", "0", "r0*5"});
    model.result("pg7").feature("arpt1").set("arrowtype", "double");
    model.result("pg7").feature("arpt1").set("scaleactive", true);
    model.result("pg7").feature("arpt1").create("trn1", "Transformation");
    model.result("pg7").run();
    model.result("pg7").feature("arpt1").feature("trn1").set("move", new String[]{"-R2", "0", "-1*r0"});
    model.result("pg7").feature("arpt1").feature("trn1").set("applytodatasetedges", false);
    model.result("pg7").run();

    model.view("view5").set("showgrid", false);
    model.view("view5").set("showaxisorientation", false);
    model.view("view5").set("environmentmap", "Indoor");
    model.view("view5").set("shadowmapping", true);
    model.view("view5").set("displayoutput", true);
    model.view("view5").set("showgrid", true);
    model.view("view5").set("showaxisorientation", true);
    model.view("view5").set("shadowmapping", false);
    model.view("view5").set("displayoutput", false);

    model.result("pg7").run();
    model.result().remove("pg7");
    model.result().dataset().remove("cpt1");
    model.result("pg2").run();

    model.title("Axisymmetric Twist and Bending");

    model
         .description("Including circumferential displacements in a 2D axisymmetric Solid Mechanics interface allows twist and bending deformations to be computed. This model determines stress concentration factors for a hollow shaft for load cases of axial extension, torsion as well as bending using a computationally lean 2D axisymmetric formulation. To demonstrate their equivalence, the model setup and results are compared with a full 3D analysis.");

    return model;
  }

  public static void main(String[] args) {
    Model model = run();
    run2(model);
  }

}
