/*
 * single_edge_crack.java
 */

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

/** Model exported on May 13 2026, 12:41 by COMSOL 6.4.0.419. */
public class single_edge_crack {

  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.
//    In the Select Physics tree, select Structural Mechanics > Solid Mechanics (solid).
//    Click Add.
//    Click Done.

    model.component().create("comp1", true);

    model.component("comp1").geom().create("geom1", 2);

    model.component("comp1").mesh().create("mesh1");

    model.component("comp1").physics().create("solid", "SolidMechanics", "geom1");

//    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 single_edge_crack_parameters.txt.
//    To import content from file, use:
//    model.param().loadFile("FILENAME");
    model.param().set("Xa", "0.6[m]", "Crack length");
    model.param().set("da", "0.01[m]", "Crack length increment");
    model.param().set("Wp", "1.5[m]", "Plate width");
    model.param().set("Hp", "1.5*Wp", "Half length of plate");
    model.param().set("Th", "10[mm]", "Plate thickness");
    model.param().set("Q0", "20[MPa]", "Load intensity");
    model.param().set("AP", "1.4E-11", "Paris' law coefficient (in MN/m^1.5 units)");
    model.param().set("mP", "3.1", "Paris' law exponent");
    model.param().set("ar", "pi*Xa/(2*Wp)", "Intermediate crack length parameter");
    model.param()
         .set("K1r", "Q0/1[Pa]*sqrt(pi*Xa/1[m])*sqrt(tan(ar)/ar)/cos(ar)*(0.752+2.02*(Xa/Wp)+0.37*(1-sin(ar))^3)", "Reference stress intensity factor");

//    In the Model Builder window, right-click Component 1 (comp1) > Definitions and choose Variables.

    model.component("comp1").variable().create("var1");

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

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

    model.component("comp1").variable("var1").set("dadN", "AP*(solid.crack1.jint1.KI/1e6)^mP");
    model.component("comp1").variable("var1").descr("dadN", "Crack growth rate (m/cycle)");

//    In the Geometry toolbar, click Rectangle.

    model.component("comp1").geom("geom1").create("r1", "Rectangle");

//    In the Settings window for Rectangle, locate the Size and Shape section.
//    In the Width text field, type Wp.

    model.component("comp1").geom("geom1").feature("r1").set("size", new String[]{"Wp", "1"});

//    In the Height text field, type Hp.

    model.component("comp1").geom("geom1").feature("r1").set("size", new String[]{"Wp", "Hp"});

//    Add a point at the crack tip.
//    In the Geometry toolbar, click Point.

    model.component("comp1").geom("geom1").run("r1");
    model.component("comp1").geom("geom1").create("pt1", "Point");

//    In the Settings window for Point, locate the Point section.
//    In the x text field, type Xa.

    model.component("comp1").geom("geom1").feature("pt1").setIndex("p", "Xa", 0);

//    In the Model Builder window, right-click Form Union (fin) and choose Build All Objects.

    model.component("comp1").geom("geom1").runPre("fin");
    model.component("comp1").geom("geom1").run();

//    In the Model Builder window, right-click Component 1 (comp1) > Materials and choose Blank Material.

    model.component("comp1").material().create("mat1", "Common");

//    In the Settings window for Material, type Steel in the Label text field.

    model.component("comp1").material("mat1").label("Steel");

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

    model.component("comp1").material("mat1").propertyGroup()
         .create("Enu", "Enu", "Young's_modulus_and_Poisson's_ratio");
    model.component("comp1").material("mat1").propertyGroup("Enu").set("E", new String[]{"206[GPa]"});
    model.component("comp1").material("mat1").propertyGroup("Enu").set("nu", new String[]{"0.3"});
    model.component("comp1").material("mat1").propertyGroup("def").set("density", new String[]{"7850"});

//    In the Model Builder window, under Component 1 (comp1), click Solid Mechanics (solid).
//    In the Settings window for Solid Mechanics, locate the 2D Approximation section.
//    From the list, select Plane stress.

    model.component("comp1").physics("solid").prop("Type2D").set("Type2D", "PlaneStress");

//    Locate the Thickness section.
//    In the \[d\] text field, type Th.

    model.component("comp1").physics("solid").prop("d").set("d", "Th");

//    In the Physics toolbar, click Boundaries and choose Symmetry.

    model.component("comp1").physics("solid").create("sym1", "SymmetrySolid", 1);

//    Select Boundaries 2, 4.

    model.component("comp1").physics("solid").feature("sym1").selection().set(2, 4);

//    It does not matter whether you select boundary 2 as a symmetry boundary or not. If selected, it will be overridden when the <l>Crack</l> node is added.
//    In the Physics toolbar, click Boundaries and choose Boundary Load.

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

//    Select Boundary 3.

    model.component("comp1").physics("solid").feature("bndl1").selection().set(3);

//    In the Settings window for Boundary Load, locate the Force section.
//    Specify the \[\mathbf{f}_{\mathrm{A}}\] vector as

    model.component("comp1").physics("solid").feature("bndl1")
         .set("forceReferenceArea", new String[]{"0", "20[MPa]", "0"});

//    In the Physics toolbar, click Points and choose Prescribed Displacement.

    model.component("comp1").physics("solid").create("disp1", "Displacement0", 0);

//    Constrain the <eqv>x</eqv>-displacement in a point on the symmetry axis to suppress rigid body motion.
//    Select Point 4.

    model.component("comp1").physics("solid").feature("disp1").selection().set(4);

//    In the Settings window for Prescribed Displacement, locate the Prescribed Displacement section.
//    From the Displacement in x direction list, select Prescribed.

    model.component("comp1").physics("solid").feature("disp1").setIndex("Direction", "prescribed", 0);

//    In the Physics toolbar, click Boundaries and choose Crack.

    model.component("comp1").physics("solid").create("crack1", "Crack", 1);

//    In the Settings window for Crack, locate the Crack Definition section.
//    From the Crack surface list, select Symmetric.

    model.component("comp1").physics("solid").feature("crack1").set("CrackSurface", "Symmetric");

//    Select Boundary 2.

    model.component("comp1").physics("solid").feature("crack1").selection().set(2);

//    Click to expand the Crack Front section.
//    Click Clear Selection.

    model.component("comp1").physics("solid").feature("crack1").selection("CrackFront").set();

//    Select Point 3.

    model.component("comp1").physics("solid").feature("crack1").selection("CrackFront").set(3);

//    In the Physics toolbar, click Attributes and choose J-Integral.

    model.component("comp1").physics("solid").feature("crack1").create("jint1", "JIntegral", 0);

//    Right-click J-Integral 1 and choose Duplicate.

    model.component("comp1").physics("solid").feature("crack1").feature().duplicate("jint2", "jint1");

//    In the Settings window for J-Integral, locate the J-Integral section.
//    In the \[r_\Gamma\] text field, type solid.crack1.crackSize*0.7.

    model.component("comp1").physics("solid").feature("crack1").feature("jint2")
         .set("r", "solid.crack1.crackSize*0.7");

//    In the Model Builder window, click Crack 1.
//    In the Physics toolbar, click Attributes and choose J-Integral.

    model.component("comp1").physics("solid").feature("crack1").create("jint3", "JIntegral", 0);

//    In the Settings window for J-Integral, locate the J-Integral section.
//    From the Integration path list, select On edges.

    model.component("comp1").physics("solid").feature("crack1").feature("jint3").set("IntegrationPath", "Edges");

//    Select Point 3.
//    Locate the Integration Path section.
//    Select the Activate Selection toggle button.
//    Select Boundaries 1, 3, 5.

    model.component("comp1").physics("solid").feature("crack1").feature("jint3").selection("Path").set(1, 3, 5);

//    To compute the energy release rate, add a <l>Virtual Crack Extension</l> subnode. Use the action buttons in the feature to generate the deformed geometry and study.
//    In the Model Builder window, click Crack 1.
//    In the Physics toolbar, click Attributes and choose Virtual Crack Extension.

    model.component("comp1").physics("solid").feature("crack1").create("vce1", "VirtualCrackExtension", 1);

//    To create a parametric study, use options in the <l>Advanced</l> section. To see this section, enable <l>Advanced Physics Options</l> as follows:
//    Click the Show More Options button in the Model Builder toolbar.
//    In the Show More Options dialog, in the tree, select the checkbox for the Physics > Advanced Physics Options node.
//    Click OK.
//    In the Settings window for Virtual Crack Extension, click to expand the Advanced section.
//    From the Add parametric sweep list, select Yes.

    model.component("comp1").physics("solid").feature("crack1").feature("vce1").set("parametricStudy", "yes");

//    In the Parameters table, enter the following settings:

    model.component("comp1").physics("solid").feature("crack1").feature("vce1").setIndex("parameterName", "Xa", 0, 0);
    model.component("comp1").physics("solid").feature("crack1").feature("vce1")
         .setIndex("parameterRange", "range(0.5,da,0.7)", 0, 0);
    model.component("comp1").physics("solid").feature("crack1").feature("vce1").setIndex("parameterUnit", "m", 0, 0);

//    Click Automated Model Setup in the upper-right corner of the Sensitivity section.
//    From the menu, choose Create Deformed Geometry and Study.

    model.component("comp1").physics("solid").feature("crack1").feature("vce1")
         .runCommand("createDeformedGeometryandStudy");

//    In the Model Builder window, under Component 1 (comp1), click Mesh 1.
//    In the Settings window for Mesh, locate the Physics-Controlled Mesh section.
//    From the Element size list, select Finer.

    model.component("comp1").mesh("mesh1").autoMeshSize(3);

//    Locate the Sequence Type section.
//    From the list, select User-controlled mesh.

    model.component("comp1").mesh("mesh1").automatic(false);

//    In the Model Builder window, under Component 1 (comp1) > Mesh 1, click Size 1.
//    In the Settings window for Size, locate the Element Size section.
//    Click the Custom button.

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

//    Locate the Element Size Parameters section.
//    Select the Maximum element size checkbox.

    model.component("comp1").mesh("mesh1").feature("size1").set("hmaxactive", true);

//    In the associated text field, type 0.01.

    model.component("comp1").mesh("mesh1").feature("size1").set("hmax", 0.01);

//    Click Build All.

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

//    In the Study toolbar, click Compute.

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

    model.batch("solidcrack1p").run("compute");

    model.result().create("pg1", "PlotGroup2D");
    model.result("pg1").set("data", "dset2");
    model.result("pg1").setIndex("looplevel", 2, 0);
    model.result("pg1").setIndex("looplevel", 21, 1);
    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").set("smooth", "none");
    model.result("pg1").feature("surf1").set("colortabletrans", "nonlinear");
    model.result("pg1").feature("surf1").set("colorcalibration", -1);
    model.result("pg1").feature("surf1").create("def", "Deform");
    model.result("pg1").feature("surf1").feature("def").set("expr", new String[]{"u", "v"});
    model.result("pg1").feature("surf1").feature("def").set("descr", "Displacement field");
    model.result().create("pg2", "PlotGroup2D");
    model.result("pg2").set("data", "dset2");
    model.result("pg2").setIndex("looplevel", 2, 0);
    model.result("pg2").setIndex("looplevel", 21, 1);
    model.result("pg2").label("Deformed Geometry");
    model.result("pg2").create("mesh1", "Mesh");
    model.result("pg2").feature("mesh1").set("meshdomain", "surface");
    model.result("pg2").feature("mesh1").set("colortable", "TrafficFlow");
    model.result("pg2").feature("mesh1").set("colortabletrans", "nonlinear");
    model.result("pg2").feature("mesh1").set("nonlinearcolortablerev", true);
    model.result("pg2").feature("mesh1").create("sel1", "MeshSelection");
    model.result("pg2").feature("mesh1").feature("sel1").selection().set(1);
    model.result("pg2").feature("mesh1").set("qualmeasure", "custom");
    model.result("pg2").feature("mesh1").set("qualexpr", "comp1.material.relVol");
    model.result("pg2").feature("mesh1").set("colorrangeunitinterval", false);
    model.result("pg1").run();

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Results toolbar, click More Datasets and choose Mirror 2D.

    model.result().dataset().create("mir1", "Mirror2D");

//    In the Settings window for Mirror 2D, locate the Axis Data section.
//    In row Point 2, set X to 1.

    model.result().dataset("mir1").setIndex("genpoints", 1, 1, 0);

//    In row Point 2, set Y to 0.

    model.result().dataset("mir1").setIndex("genpoints", 0, 1, 1);

//    Locate the Data section.
//    From the Dataset list, select Virtual Crack Extension Study/Solution 2 (solidcrack1solp).

    model.result().dataset("mir1").set("data", "dset2");
    model.result("pg1").run();

//    In the Model Builder window, under Results, click Stress (solid).
//    In the Settings window for 2D Plot Group, locate the Data section.
//    From the Dataset list, select Mirror 2D 1.

    model.result("pg1").set("data", "mir1");

//    From the Parameter value (Xa (m)) list, select 0.6.

    model.result("pg1").setIndex("looplevel", 11, 1);

//    Locate the Plot Settings section.
//    Clear the Plot dataset edges checkbox.

    model.result("pg1").set("edges", false);
    model.result("pg1").run();

//    In the Model Builder window, expand the Stress (solid) node, then click Surface 1.
//    In the Settings window for Surface, locate the Expression section.
//    From the Unit list, select MPa.

    model.result("pg1").feature("surf1").set("unit", "MPa");

//    Click to expand the Range section.
//    Select the Manual color range checkbox.

    model.result("pg1").feature("surf1").set("rangecoloractive", true);

//    In the Maximum text field, type 200.

    model.result("pg1").feature("surf1").set("rangecolormax", 200);

//    Right-click Results > Stress (solid) > Surface 1 and choose Arrow Line.

    model.result("pg1").create("arwl1", "ArrowLine");
    model.result("pg1").feature("arwl1").set("evaluationsettings", "parent");

//    In the Settings window for Arrow Line, type Boundary Load in the Label text field.

    model.result("pg1").feature("arwl1").label("Boundary Load");

//    Click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Solid Mechanics > Load > solid.fax,solid.fay - Force per deformed area (spatial frame).

    model.result("pg1").feature("arwl1").set("expr", new String[]{"solid.fax", "solid.fay"});
    model.result("pg1").feature("arwl1").set("descr", "Force per deformed area (spatial frame)");

//    Click to expand the Title section.
//    From the Title type list, select None.

    model.result("pg1").feature("arwl1").set("titletype", "none");

//    Locate the Arrow Positioning section.
//    From the Placement list, select Mesh vertices.

    model.result("pg1").feature("arwl1").set("placement", "elements");

//    Locate the Coloring and Style section.
//    Select the Scale factor checkbox.

    model.result("pg1").feature("arwl1").set("scaleactive", true);

//    In the associated text field, type 1e-8.

    model.result("pg1").feature("arwl1").set("scale", "1e-8");

//    Click to expand the Inherit Style section.
//    From the Plot list, select Surface 1.

    model.result("pg1").feature("arwl1").set("inheritplot", "surf1");

//    Clear the Color and data range checkbox.

    model.result("pg1").feature("arwl1").set("inheritrange", false);

//    Clear the Color checkbox.

    model.result("pg1").feature("arwl1").set("inheritcolor", false);

//    Clear the Arrow scale factor checkbox.

    model.result("pg1").feature("arwl1").set("inheritarrowscale", false);

//    Right-click Boundary Load and choose Color Expression.

    model.result("pg1").feature("arwl1").create("col1", "Color");
    model.result("pg1").run();

//    In the Settings window for Color Expression, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Solid Mechanics > Load > solid.famag - Force per deformed area, magnitude - N/m².

    model.result("pg1").feature("arwl1").feature("col1").set("expr", "solid.famag");
    model.result("pg1").feature("arwl1").feature("col1").set("descr", "Force per deformed area, magnitude");

//    Locate the Coloring and Style section.
//    From the Coloring list, select Gradient.

    model.result("pg1").feature("arwl1").feature("col1").set("coloring", "gradient");

//    From the Top color list, select Red.

    model.result("pg1").feature("arwl1").feature("col1").set("topcolor", "red");

//    From the Bottom color list, select Gray.

    model.result("pg1").feature("arwl1").feature("col1").set("bottomcolor", "gray");

//    Clear the Color legend checkbox.

    model.result("pg1").feature("arwl1").feature("col1").set("colorlegend", false);
    model.result("pg1").run();

//    Right-click Boundary Load and choose Deformation.

    model.result("pg1").feature("arwl1").create("def1", "Deform");
    model.result("pg1").run();
    model.result("pg1").run();

//    In the Stress (solid) toolbar, click Line.

    model.result("pg1").create("line1", "Line");
    model.result("pg1").feature("line1").set("evaluationsettings", "parent");

//    In the Settings window for Line, locate the Expression section.
//    In the Expression text field, type 1.

    model.result("pg1").feature("line1").set("expr", "1");

//    Click to expand the Title section.
//    From the Title type list, select None.

    model.result("pg1").feature("line1").set("titletype", "none");

//    Locate the Coloring and Style section.
//    From the Coloring list, select Uniform.

    model.result("pg1").feature("line1").set("coloring", "uniform");

//    From the Color list, select From theme.

    model.result("pg1").feature("line1").set("color", "fromtheme");

//    Click to expand the Quality section.
//    From the Evaluation settings list, select Manual.

    model.result("pg1").feature("line1").set("evaluationsettings", "manual");

//    From the Smoothing list, select None.

    model.result("pg1").feature("line1").set("smooth", "none");

//    In the Stress (solid) toolbar, click Deformation.

    model.result("pg1").feature("line1").create("def1", "Deform");
    model.result("pg1").run();
    model.result("pg1").run();

//    In the Model Builder window, click Line 1.
//    Click to expand the Inherit Style section.
//    From the Plot list, select Surface 1.

    model.result("pg1").feature("line1").set("inheritplot", "surf1");

//    Clear the Color checkbox.

    model.result("pg1").feature("line1").set("inheritcolor", false);

//    Clear the Color and data range checkbox.

    model.result("pg1").feature("line1").set("inheritrange", false);
    model.result("pg1").run();

//    In the Model Builder window, expand the Results > Stress (solid) > Surface 1 node, then click Deformation.
//    In the Settings window for Deformation, locate the Scale section.
//    Select the Scale factor checkbox.

    model.result("pg1").feature("surf1").feature("def").set("scaleactive", true);

//    In the associated text field, type 200.

    model.result("pg1").feature("surf1").feature("def").set("scale", 200);

//    In the Stress (solid) toolbar, click Plot.

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

//    Click the Zoom Extents button in the Graphics toolbar.

    model.result("pg1").run();
    model.result("pg1").set("titletype", "none");
    model.result("pg1").run();
    model.result("pg1").feature("surf1").set("coloring", "uniform");
    model.result("pg1").feature("surf1").set("color", "gray");
    model.result("pg1").run();
    model.result("pg1").run();
    model.result("pg1").feature("line1").active(false);
    model.result("pg1").run();
    model.result("pg1").feature("surf1").feature("def").set("scale", 50);
    model.result("pg1").run();
    model.result("pg1").feature("surf1").feature("def").set("scale", 200);
    model.result("pg1").run();
    model.result("pg1").feature("line1").active(true);
    model.result("pg1").run();
    model.result("pg1").feature("surf1").set("coloring", "colortable");
    model.result("pg1").run();
    model.result("pg1").set("titletype", "auto");

//    Check the placement of the integration contours. In particular, ensure that circular paths remain inside the domain.
//    In the Results toolbar, click Result Templates to open the Result Templates window.
//    In the tree, select Virtual Crack Extension Study/Solution 2 (solidcrack1solp) > Solid Mechanics > Cracks (solid).
//    Click Add Result Template in the window toolbar.

    model.result().create("pg3", "PlotGroup2D");
    model.result("pg3").set("data", "dset2");
    model.result("pg3").setIndex("looplevel", 2, 0);
    model.result("pg3").setIndex("looplevel", 21, 1);
    model.result("pg3").label("Cracks (solid)");
    model.result("pg3").set("showlegends", true);
    model.result("pg3").set("titletype", "label");
    model.result("pg3").set("frametype", "material");
    model.result("pg3").set("showlegendsunit", true);
    model.result("pg3").create("arpt1", "ArrowPoint");
    model.result("pg3").feature("arpt1")
         .set("expr", new String[]{"solid.crack1.e1X*solid.crack1.crackSize ", "solid.crack1.e1Y*solid.crack1.crackSize "});
    model.result("pg3").feature("arpt1").set("scaleactive", true);
    model.result("pg3").feature("arpt1").set("scale", "1");
    model.result("pg3").feature("arpt1").label("Crack Growth Direction (Crack 1)");
    model.result("pg3").create("con1", "Contour");
    model.result("pg3").feature("con1").set("expr", "sqrt((X-solid.crack1.jint1.Xp)^2+(Y-solid.crack1.jint1.Yp)^2)");
    model.result("pg3").feature("con1").set("levelmethod", "levels");
    model.result("pg3").feature("con1").set("levels", new String[]{"solid.crack1.jint1.r"});
    model.result("pg3").feature("con1").set("coloring", "uniform");
    model.result("pg3").feature("con1").set("color", "magenta");
    model.result("pg3").feature("con1").set("colorlegend", false);
    model.result("pg3").feature("con1").label("J-Integral 1, Integration Path");
    model.result("pg3").create("ann1", "Annotation");
    model.result("pg3").feature("ann1").set("text", "J=eval(solid.crack1.jint1.J)");
    model.result("pg3").feature("ann1").set("posxexpr", "solid.crack1.jint1.Xp");
    model.result("pg3").feature("ann1").set("posyexpr", "solid.crack1.jint1.Yp");
    model.result("pg3").feature("ann1").label("J-Integral 1, Evaluation");
    model.result("pg3").create("con2", "Contour");
    model.result("pg3").feature("con2").set("expr", "sqrt((X-solid.crack1.jint2.Xp)^2+(Y-solid.crack1.jint2.Yp)^2)");
    model.result("pg3").feature("con2").set("levelmethod", "levels");
    model.result("pg3").feature("con2").set("levels", new String[]{"solid.crack1.jint2.r"});
    model.result("pg3").feature("con2").set("coloring", "uniform");
    model.result("pg3").feature("con2").set("color", "magenta");
    model.result("pg3").feature("con2").set("colorlegend", false);
    model.result("pg3").feature("con2").label("J-Integral 2, Integration Path");
    model.result("pg3").create("ann2", "Annotation");
    model.result("pg3").feature("ann2").set("text", "J=eval(solid.crack1.jint2.J)");
    model.result("pg3").feature("ann2").set("posxexpr", "solid.crack1.jint2.Xp");
    model.result("pg3").feature("ann2").set("posyexpr", "solid.crack1.jint2.Yp");
    model.result("pg3").feature("ann2").label("J-Integral 2, Evaluation");
    model.result("pg3").create("line1", "Line");
    model.result("pg3").feature("line1").set("expr", "sqrt(solid.crack1.jint3.mX^2+solid.crack1.jint3.mY^2)");
    model.result("pg3").feature("line1").set("coloring", "uniform");
    model.result("pg3").feature("line1").set("color", "magenta");
    model.result("pg3").feature("line1").label("J-Integral 3, Integration Path");
    model.result("pg3").create("ann3", "Annotation");
    model.result("pg3").feature("ann3").set("text", "J=eval(solid.crack1.jint3.J)");
    model.result("pg3").feature("ann3").set("posxexpr", "solid.crack1.jint3.Xp");
    model.result("pg3").feature("ann3").set("posyexpr", "solid.crack1.jint3.Yp");
    model.result("pg3").feature("ann3").label("J-Integral 3, Evaluation");
    model.result("pg3").label("Cracks (solid)");
    model.result("pg3").run();

//    In the Cracks (solid) toolbar, click Plot.

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

//    In the Model Builder window, under Results, click Cracks (solid).
//    In the Settings window for 2D Plot Group, click cycle_plot_level.
//    Click Plot First.

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

//    Check if there are any differences between the results for the three contours, which could indicate a too coarse mesh. An <l>Evaluation Group</l> with predefined fracture mechanics result quantities is available from the <l>Result Templates</l> plot menu.
//    In the tree, select Virtual Crack Extension Study/Solution 2 (solidcrack1solp) > Solid Mechanics > Fracture Mechanics Results (solid).
//    Click Add Result Template in the window toolbar.

    model.result().evaluationGroup().create("eg_dset2solid", "EvaluationGroup");
    model.result().evaluationGroup("eg_dset2solid").label("Fracture Mechanics Results (solid)");
    model.result().evaluationGroup("eg_dset2solid").set("data", "dset2");
    model.result().evaluationGroup("eg_dset2solid").set("transpose", true);
    model.result().evaluationGroup("eg_dset2solid").create("jint", "EvalGlobal");
    model.result().evaluationGroup("eg_dset2solid").feature("jint").label("J-Integrals");
    model.result().evaluationGroup("eg_dset2solid").feature("jint").setIndex("expr", "solid.crack1.jint1.J", 0);
    model.result().evaluationGroup("eg_dset2solid").feature("jint").setIndex("descr", "J-integral [crack1/jint1]", 0);
    model.result().evaluationGroup("eg_dset2solid").feature("jint").setIndex("expr", "solid.crack1.jint2.J", 1);
    model.result().evaluationGroup("eg_dset2solid").feature("jint").setIndex("descr", "J-integral [crack1/jint2]", 1);
    model.result().evaluationGroup("eg_dset2solid").feature("jint").setIndex("expr", "solid.crack1.jint3.J", 2);
    model.result().evaluationGroup("eg_dset2solid").feature("jint").setIndex("descr", "J-integral [crack1/jint3]", 2);
    model.result().evaluationGroup("eg_dset2solid").create("sif1", "EvalGlobal");
    model.result().evaluationGroup("eg_dset2solid").feature("sif1").label("Stress Intensity Factors, Mode 1");
    model.result().evaluationGroup("eg_dset2solid").feature("sif1").setIndex("expr", "solid.crack1.jint1.KI", 0);
    model.result().evaluationGroup("eg_dset2solid").feature("sif1")
         .setIndex("descr", "Stress intensity factor, mode I [crack1/jint1]", 0);
    model.result().evaluationGroup("eg_dset2solid").feature("sif1").setIndex("expr", "solid.crack1.jint2.KI", 1);
    model.result().evaluationGroup("eg_dset2solid").feature("sif1")
         .setIndex("descr", "Stress intensity factor, mode I [crack1/jint2]", 1);
    model.result().evaluationGroup("eg_dset2solid").feature("sif1").setIndex("expr", "solid.crack1.jint3.KI", 2);
    model.result().evaluationGroup("eg_dset2solid").feature("sif1")
         .setIndex("descr", "Stress intensity factor, mode I [crack1/jint3]", 2);
    model.result().evaluationGroup("eg_dset2solid").feature("sif1").setIndex("expr", "solid.crack1.vce1.KIG", 3);
    model.result().evaluationGroup("eg_dset2solid").feature("sif1")
         .setIndex("descr", "Stress intensity factor, mode I [crack1/vce1]", 3);
    model.result().evaluationGroup("eg_dset2solid").create("sif2", "EvalGlobal");
    model.result().evaluationGroup("eg_dset2solid").feature("sif2").label("Stress Intensity Factors, Mode 2");
    model.result().evaluationGroup("eg_dset2solid").feature("sif2").setIndex("expr", "solid.crack1.jint1.KII", 0);
    model.result().evaluationGroup("eg_dset2solid").feature("sif2")
         .setIndex("descr", "Stress intensity factor, mode II [crack1/jint1]", 0);
    model.result().evaluationGroup("eg_dset2solid").feature("sif2").setIndex("expr", "solid.crack1.jint2.KII", 1);
    model.result().evaluationGroup("eg_dset2solid").feature("sif2")
         .setIndex("descr", "Stress intensity factor, mode II [crack1/jint2]", 1);
    model.result().evaluationGroup("eg_dset2solid").feature("sif2").setIndex("expr", "solid.crack1.jint3.KII", 2);
    model.result().evaluationGroup("eg_dset2solid").feature("sif2")
         .setIndex("descr", "Stress intensity factor, mode II [crack1/jint3]", 2);
    model.result().evaluationGroup("eg_dset2solid").feature("sif2").setIndex("expr", "solid.crack1.vce1.KIIG", 3);
    model.result().evaluationGroup("eg_dset2solid").feature("sif2")
         .setIndex("descr", "Stress intensity factor, mode II [crack1/vce1]", 3);
    model.result().evaluationGroup("eg_dset2solid").create("grel", "EvalGlobal");
    model.result().evaluationGroup("eg_dset2solid").feature("grel").label("Energy Release Rates");
    model.result().evaluationGroup("eg_dset2solid").feature("grel").setIndex("expr", "solid.crack1.vce1.G", 0);
    model.result().evaluationGroup("eg_dset2solid").feature("grel")
         .setIndex("descr", "Energy release rate [crack1/vce1]", 0);
    model.result().evaluationGroup("eg_dset2solid").label("Fracture Mechanics Results (solid)");

//    In the Results toolbar, click Result Templates to close the Result Templates window.
//    Since this is a pure Mode I case, remove the evaluation of the Mode II stress intensity factors.
//    In the Model Builder window, expand the Results > Fracture Mechanics Results (solid) node.
//    Right-click Stress Intensity Factors, Mode 2 and choose Delete.

    model.result().evaluationGroup("eg_dset2solid").feature().remove("sif2");

//    Add a comparison between the values from the second integration path and the reference stress intensity factor.
//    In the Model Builder window, under Results > Fracture Mechanics Results (solid), click Stress Intensity Factors, Mode 1.
//    In the Settings window for Global Evaluation, locate the Expressions section.
//    In the table, enter the following settings:

    model.result().evaluationGroup("eg_dset2solid").feature("sif1").setIndex("expr", "K1r", 3);
    model.result().evaluationGroup("eg_dset2solid").feature("sif1").setIndex("unit", 1, 3);
    model.result().evaluationGroup("eg_dset2solid").feature("sif1")
         .setIndex("descr", "Reference stress intensity factor", 3);
    model.result().evaluationGroup("eg_dset2solid").feature("sif1")
         .setIndex("expr", "(solid.crack1.jint2.KI-K1r)/K1r*100", 4);

    return model;
  }

  public static Model run2(Model model) {
    model.result().evaluationGroup("eg_dset2solid").feature("sif1").setIndex("unit", 1, 4);
    model.result().evaluationGroup("eg_dset2solid").feature("sif1")
         .setIndex("descr", "Percent difference from reference value", 4);

//    In the Model Builder window, click Fracture Mechanics Results (solid).
//    In the Settings window for Evaluation Group, locate the Data section.
//    From the Parameter selection (solidcrack1auxPara) list, select Last.

    model.result().evaluationGroup("eg_dset2solid").setIndex("looplevelinput", "last", 0);

//    In the Fracture Mechanics Results (solid) toolbar, click Evaluate.

    model.result().evaluationGroup("eg_dset2solid").run();

//    Compare the J-integral with the energy release rate.
//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg4", "PlotGroup1D");
    model.result("pg4").run();

//    In the Settings window for 1D Plot Group, type J-Integral and Energy Release Rate in the Label text field.

    model.result("pg4").label("J-Integral and Energy Release Rate");

//    Locate the Data section.
//    From the Dataset list, select Virtual Crack Extension Study/Solution 2 (solidcrack1solp).

    model.result("pg4").set("data", "dset2");

//    From the Parameter selection (Xa) list, select Manual.

    model.result("pg4").setIndex("looplevelinput", "manualindices", 1);

//    In the Parameter indices (1-21) text field, type range(2,20).

    model.result("pg4").setIndex("looplevelindices", "range(2,20)", 1);

//    From the Parameter selection (solidcrack1auxPara) list, select Last.

    model.result("pg4").setIndex("looplevelinput", "last", 0);

//    Right-click J-Integral and Energy Release Rate and choose Global.

    model.result("pg4").create("glob1", "Global");
    model.result("pg4").feature("glob1").set("markerpos", "datapoints");
    model.result("pg4").feature("glob1").set("linewidth", "preference");

//    In the Settings window for Global, click Replace Expression in the upper-right corner of the y-Axis Data section.
//    From the menu, choose Component 1 (comp1) > Solid Mechanics > Cracks > solid.crack1.jint1.J - J-integral - J/m².

    model.result("pg4").feature("glob1").set("expr", new String[]{"solid.crack1.jint1.J"});
    model.result("pg4").feature("glob1").set("descr", new String[]{"J-integral"});
    model.result("pg4").feature("glob1").set("unit", new String[]{"J/m^2"});

//    Locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg4").feature("glob1").setIndex("descr", "J-integral, contour 1", 0);
    model.result("pg4").feature("glob1").setIndex("expr", "solid.crack1.vce1.G", 1);
    model.result("pg4").feature("glob1").setIndex("unit", "J/m^2", 1);
    model.result("pg4").feature("glob1").setIndex("descr", "Energy release rate", 1);

//    Locate the x-Axis Data section.
//    From the Axis source data list, select Xa.

    model.result("pg4").feature("glob1").set("xdatasolnumtype", "level2");

//    Click to expand the Coloring and Style section.
//    Find the Line style subsection.
//    From the Line list, select Cycle.

    model.result("pg4").feature("glob1").set("linestyle", "cycle");

//    From the Width list, select 2.

    model.result("pg4").feature("glob1").set("linewidth", 2);

//    Find the Line markers subsection.
//    From the Marker list, select Cycle.

    model.result("pg4").feature("glob1").set("linemarker", "cycle");

//    From the Positioning list, select Interpolated.

    model.result("pg4").feature("glob1").set("markerpos", "interp");

//    Click to expand the Legends section.
//    Find the Include subsection.
//    Clear the Solution checkbox.

    model.result("pg4").feature("glob1").set("autosolution", false);
    model.result("pg4").run();

//    In the Model Builder window, click J-Integral and Energy Release Rate.
//    In the Settings window for 1D Plot Group, locate the Plot Settings section.
//    Select the x-axis label checkbox.

    model.result("pg4").set("xlabelactive", true);

//    In the associated text field, type Crack length (m).

    model.result("pg4").set("xlabel", "Crack length (m)");

//    Select the y-axis label checkbox.

    model.result("pg4").set("ylabelactive", true);

//    In the associated text field, type Energy release rate (J/m^2).

    model.result("pg4").set("ylabel", "Energy release rate (J/m^2)");

//    Locate the Legend section.
//    From the Position list, select Lower right.

    model.result("pg4").set("legendpos", "lowerright");

//    In the J-Integral and Energy Release Rate toolbar, click Plot.

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

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

    model.result().create("pg5", "PlotGroup1D");
    model.result("pg5").run();

//    In the Settings window for 1D Plot Group, type Crack Growth Rate in the Label text field.

    model.result("pg5").label("Crack Growth Rate");

//    Locate the Data section.
//    From the Dataset list, select Virtual Crack Extension Study/Solution 2 (solidcrack1solp).

    model.result("pg5").set("data", "dset2");

//    From the Parameter selection (solidcrack1auxPara) list, select Last.

    model.result("pg5").setIndex("looplevelinput", "last", 0);

//    Right-click Crack Growth Rate and choose Global.

    model.result("pg5").create("glob1", "Global");
    model.result("pg5").feature("glob1").set("markerpos", "datapoints");
    model.result("pg5").feature("glob1").set("linewidth", "preference");

//    In the Settings window for Global, locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg5").feature("glob1").setIndex("expr", "dadN", 0);
    model.result("pg5").feature("glob1").setIndex("unit", 1, 0);
    model.result("pg5").feature("glob1").setIndex("descr", "Crack growth rate (m/cycle)", 0);

//    Locate the x-Axis Data section.
//    From the Axis source data list, select Xa.

    model.result("pg5").feature("glob1").set("xdatasolnumtype", "level2");

//    Locate the Coloring and Style section.
//    From the Width list, select 2.

    model.result("pg5").feature("glob1").set("linewidth", 2);
    model.result("pg5").run();

//    In the Model Builder window, click Crack Growth Rate.
//    In the Settings window for 1D Plot Group, click to expand the Title section.
//    From the Title type list, select None.

    model.result("pg5").set("titletype", "none");

//    Locate the Plot Settings section.
//    Select the x-axis label checkbox.

    model.result("pg5").set("xlabelactive", true);

//    In the associated text field, type Crack length (m).

    model.result("pg5").set("xlabel", "Crack length (m)");

//    Select the y-axis label checkbox.

    model.result("pg5").set("ylabelactive", true);

//    In the associated text field, type Crack growth rate (m/cycle).

    model.result("pg5").set("ylabel", "Crack growth rate (m/cycle)");

//    Locate the Legend section.
//    Clear the Show legends checkbox.

    model.result("pg5").set("showlegends", false);

//    In the Crack Growth Rate toolbar, click Plot.

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

//    Compute the total number of cycles needed for driving the crack from 0.5 m to 0.7 m.
//    In the Results toolbar, click Global Evaluation.

    model.result().numerical().create("gev1", "EvalGlobal");

//    In the Settings window for Global Evaluation, type Number of cycles in the Label text field.

    model.result().numerical("gev1").label("Number of cycles");

//    Locate the Data section.
//    From the Dataset list, select Virtual Crack Extension Study/Solution 2 (solidcrack1solp).

    model.result().numerical("gev1").set("data", "dset2");

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

    model.result().numerical("gev1").setIndex("expr", "1/dadN", 0);
    model.result().numerical("gev1").setIndex("unit", 1, 0);
    model.result().numerical("gev1").setIndex("descr", "", 0);

//    Locate the Data Series Operation section.
//    From the Transformation list, select Integral.

    model.result().numerical("gev1").set("dataseries", "integral");

//    Click Evaluate.

    model.result().table().create("tbl1", "Table");
    model.result().table("tbl1").comments("Number of cycles");
    model.result().numerical("gev1").set("table", "tbl1");
    model.result().numerical("gev1").setResult();
    model.result("pg1").run();

    model.title("Single Edge Crack");

    model
         .description("A plate with a single edge crack is subjected to a tensile load. The stress intensity factor KI is determined for this load case using the so-called J-integral for three different contours.");

    return model;
  }

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

}
