/*
 * biot_poroelasticity.java
 */

import com.comsol.model.*;
import com.comsol.model.util.*;

/** Model exported on May 15 2026, 12:14 by COMSOL 6.4.0.421. */
public class biot_poroelasticity {

  public static Model run() {
    Model model = ModelUtil.create("Model");

//    Start by opening the model containing the solution for the compaction according to Terzaghi theory and use it as entry point for the poroelasticity study according to Biot's theory.
//    From the File menu, choose Application Libraries.
//    In the Application Libraries window, select Subsurface Flow Module > Poromechanics > terzaghi_compaction in the tree.
//    Click Open.

    model.component().create("comp1", true);

    model.component("comp1").geom().create("geom1", 2);

    model.component("comp1").mesh().create("mesh1");

    model.component("comp1").physics().create("dl", "PorousMediaFlowDarcy", "geom1");

    model.study().create("std1");
    model.study("std1").create("time", "Transient");

    model.component("comp1").geom("geom1").create("r1", "Rectangle");
    model.component("comp1").geom("geom1").feature("r1").set("size", new double[]{5200, 440});
    model.component("comp1").geom("geom1").feature("r1").set("pos", new double[]{0, -440});
    model.component("comp1").geom("geom1").feature("r1").set("layertop", true);
    model.component("comp1").geom("geom1").feature("r1").set("layerbottom", false);
    model.component("comp1").geom("geom1").feature("r1").setIndex("layer", 20, 0);
    model.component("comp1").geom("geom1").feature("r1").setIndex("layer", 20, 1);
    model.component("comp1").geom("geom1").run("r1");
    model.component("comp1").geom("geom1").create("r2", "Rectangle");
    model.component("comp1").geom("geom1").feature("r2").set("size", new double[]{1200, 320});
    model.component("comp1").geom("geom1").feature("r2").set("pos", new double[]{4000, -440});
    model.component("comp1").geom("geom1").run("r2");
    model.component("comp1").geom("geom1").create("dif1", "Difference");
    model.component("comp1").geom("geom1").feature("dif1").selection("input").set("r1");
    model.component("comp1").geom("geom1").feature("dif1").selection("input2").set("r2");
    model.component("comp1").geom("geom1").run("fin");

    model.component("comp1").view("view1").axis().set("viewscaletype", "automatic");

    model.component("comp1").variable().create("var1");
    model.component("comp1").variable("var1").selection().geom("geom1", 2);
    model.component("comp1").variable("var1").selection().set(1, 3);
    model.component("comp1").variable("var1").set("S_sk", "1e-5[m^-1]");
    model.component("comp1").variable("var1").descr("S_sk", "Skeletal specific storage");
    model.component("comp1").variable("var1").set("K_s", "25[m/day]");
    model.component("comp1").variable("var1").descr("K_s", "Saturated hydraulic conductivity");
    model.component("comp1").variable().create("var2");
    model.component("comp1").variable("var2").selection().geom("geom1", 2);
    model.component("comp1").variable("var2").selection().set(2);
    model.component("comp1").variable("var2").set("S_sk", "1e-4[m^-1]", "Skeletal specific storage");
    model.component("comp1").variable("var2").set("K_s", "0.01[m/day]", "Saturated hydraulic conductivity");

    model.material().create("mat1", "Common", "");
    model.material("mat1").label("Fluid");
    model.component("comp1").material().create("pmat1", "PorousMedia");
    model.component("comp1").material("pmat1").selection().set(1, 3);
    model.component("comp1").material("pmat1").set("porosity", "0.25");
    model.component("comp1").material("pmat1").feature().create("fluid1", "Fluid", "comp1");
    model.component("comp1").material().duplicate("pmat2", "pmat1");
    model.component("comp1").material("pmat2").selection().set(2);
    model.component("comp1").material("pmat2").set("porosity", "0.025");

    model.component("comp1").physics("dl").prop("GravityEffects").set("IncludeGravity", true);
    model.component("comp1").physics("dl").feature("gr1").set("GravityType", "Elevation");
    model.component("comp1").physics("dl").feature("porous1").set("storageModelType", "userdef");
    model.component("comp1").physics("dl").feature("porous1").set("Sp", "S_sk/dl.rho/g_const");
    model.component("comp1").physics("dl").feature("porous1").feature("fluid1")
         .set("fluidType", "compressibleLinearized");
    model.component("comp1").physics("dl").feature("porous1").feature("pm1")
         .set("permeabilityModelType", "conductivity");
    model.component("comp1").physics("dl").feature("porous1").feature("pm1")
         .set("K", new String[]{"K_s", "0", "0", "0", "K_s", "0", "0", "0", "K_s"});

    model.material("mat1").propertyGroup("def").set("density", new String[]{"1000"});
    model.material("mat1").propertyGroup("def").set("compressibility", new String[]{"4e-10"});

    model.component("comp1").physics("dl").create("hh1", "HydraulicHead", 1);
    model.component("comp1").physics("dl").feature("hh1").selection().set(1);
    model.component("comp1").physics("dl").feature("hh1").set("H0", "-6[m/year]*t");
    model.component("comp1").physics("dl").create("hh2", "HydraulicHead", 1);
    model.component("comp1").physics("dl").feature("hh2").selection().set(5, 7, 12);

    model.component("comp1").cpl().create("genproj1", "GeneralProjection");
    model.component("comp1").cpl("genproj1").selection().all();

    model.component("comp1").variable().create("var3");
    model.component("comp1").variable("var3").set("b", "genproj1(-dl.H*(y<=dest(y))*S_sk)");
    model.component("comp1").variable("var3").descr("b", "Compaction");

    model.component("comp1").mesh("mesh1").create("ftri1", "FreeTri");
    model.component("comp1").mesh("mesh1").feature("ftri1").set("yscale", 10);
    model.component("comp1").mesh("mesh1").feature("size").set("hauto", 3);
    model.component("comp1").mesh("mesh1").run();

    model.study("std1").feature("time").set("tunit", "a");
    model.study("std1").feature("time").set("tlist", "range(0,1,10)");
    model.study("std1").createAutoSequences("all");

    model.sol("sol1").runAll();

    model.result().create("pg1", "PlotGroup2D");
    model.result("pg1").label("Pressure (dl)");
    model.result("pg1").set("titletype", "custom");
    model.result("pg1").set("smooth", "internal");
    model.result("pg1").feature().create("surf1", "Surface");
    model.result("pg1").feature("surf1").label("Surface");
    model.result("pg1").feature("surf1").set("colortabletype", "discrete");
    model.result("pg1").feature("surf1").set("bandcount", 25);
    model.result("pg1").feature("surf1").set("smooth", "internal");
    model.result("pg1").feature("surf1").set("data", "parent");
    model.result().create("pg2", "PlotGroup2D");
    model.result("pg2").label("Velocity (dl)");
    model.result("pg2").set("smooth", "internal");
    model.result("pg2").feature().create("surf1", "Surface");
    model.result("pg2").feature("surf1").label("Surface");
    model.result("pg2").feature("surf1").set("expr", "dl.U");
    model.result("pg2").feature("surf1").set("colortable", "Rainbow");
    model.result("pg2").feature("surf1").set("smooth", "internal");
    model.result("pg2").feature("surf1").set("data", "parent");
    model.result("pg1").run();
    model.result("pg1").label("Hydraulic Head");
    model.result("pg1").set("titletype", "manual");
    model.result("pg1").set("title", "Time=10 years Surface: Hydraulic head (m) Streamline: Velocity field");
    model.result("pg1").run();
    model.result("pg1").feature("surf1").set("expr", "dl.H");
    model.result("pg1").feature("surf1").set("descr", "Hydraulic head");
    model.result("pg1").create("str1", "Streamline");
    model.result("pg1").feature("str1").set("evaluationsettings", "parent");
    model.result("pg1").feature("str1").selection().set(7);
    model.result("pg1").feature("str1").set("selpointdistr", "selmagctrl");
    model.result("pg1").feature("str1").set("selmdist", new double[]{0.02, 0.05});
    model.result("pg1").feature("str1").set("color", "white");
    model.result("pg1").run();
    model.result().create("pg3", "PlotGroup2D");
    model.result("pg3").run();
    model.result("pg3").label("Compaction");
    model.result("pg3").create("con1", "Contour");
    model.result("pg3").feature("con1").set("evaluationsettings", "parent");
    model.result("pg3").feature("con1").set("expr", "b");
    model.result("pg3").feature("con1").set("descr", "Compaction");
    model.result("pg3").feature("con1").set("number", 15);
    model.result("pg3").feature("con1").set("contourtype", "filled");
    model.result("pg3").feature("con1").set("colortable", "Prism");
    model.result("pg3").run();

    model.title("Terzaghi Compaction");

    model
         .description("This example solves a conventional saturated fluid flow problem for change in hydraulic head and utilizes the results to assess the vertical compaction of sediments. The analysis is based on Terzaghi theory and the concept of effective stress. The solution is compared to published results. This example is modified in the Biot Poroelasticity model to analyze bidirectionally coupled fluid flow and solid deformation.");

    model.label("terzaghi_compaction.mph");

    model.result("pg3").run();

//    Add a <l>Solid Mechanics</l> interface and a <l>Poroelasticity</l> multiphysics node.
//    In the Home toolbar, click Add Physics to open the Add Physics window.
//    In the tree, select Structural Mechanics > Solid Mechanics (solid).
//    Find the Physics interfaces in study subsection.
//    In the table, enter the following settings:
//    Click Add to Component 1 in the window toolbar.

    model.component("comp1").physics().create("solid", "SolidMechanics", "geom1");

    model.study("std1").feature("time").setSolveFor("/physics/solid", false);

//    In the Home toolbar, click Add Physics to close the Add Physics window.
//    In the Physics toolbar, click Add Multiphysics to open the Add Multiphysics window.
//    In the tree, select Structural Mechanics > Poroelasticity > Poroelasticity, Solid.
//    Find the Multiphysics couplings in study subsection.
//    In the table, enter the following settings:
//    Click Add to Component in the window toolbar.

    model.component("comp1").multiphysics().create("poro1", "PoroelasticCoupling", 2);

    model.study("std1").feature("time").setSolveFor("/multiphysics/poro1", false);

    model.component("comp1").multiphysics("poro1").selection().all();
    model.component("comp1").multiphysics("poro1").set("Solid_physics", "solid");
    model.component("comp1").multiphysics("poro1").set("PorousMediaFlow_physics", "dl");

    model.component("comp1").physics("dl").feature("porous1").set("storageModelType", new String[]{"poroelastic"});
    model.component("comp1").physics("solid").prop("StructuralTransientBehavior")
         .set("StructuralTransientBehavior", "Quasistatic");

//    In the Physics toolbar, click Add Multiphysics to close the Add Multiphysics window.
//    In the Physics toolbar, click Global and choose Gravity.

    model.component("comp1").physics("solid").create("gacc1", "GravityAcceleration", -1);

//    In the Physics toolbar, click Boundaries and choose Fixed Constraint.

    model.component("comp1").physics("solid").create("fix1", "Fixed", 1);

//    Select Boundaries 2, 8, 9.

    model.component("comp1").physics("solid").feature("fix1").selection().set(2, 8, 9);

//    In the Physics toolbar, click Boundaries and choose Roller.

    model.component("comp1").physics("solid").create("roll1", "Roller", 1);

//    Select Boundaries 1, 3, 5.

    model.component("comp1").physics("solid").feature("roll1").selection().set(1, 3, 5);

//    In the Model Builder window, under Component 1 (comp1) > Multiphysics, click Poroelasticity 1 (poro1).
//    In the Settings window for Poroelasticity, locate the Poroelastic Coupling Properties section.
//    From the \[\alpha_{\textrm{B}}\] list, select User defined.

    model.component("comp1").multiphysics("poro1").set("alphaB_mat", "userdef");

//    . 1 is the default value for the Biot–Willis coefficient.
//    Fill the required fields in the material properties tables.
//    In the Model Builder window, expand the Component 1 (comp1) > Materials node, then click Porous Material 1 (pmat1).
//    In the Settings window for Porous Material, locate the Homogenized Properties section.
//    In the table, enter the following settings:

    model.component("comp1").material("pmat1").propertyGroup("def").set("density", new String[]{"2750"});
    model.component("comp1").material("pmat1").propertyGroup()
         .create("Enu", "Enu", "Young's_modulus_and_Poisson's_ratio");
    model.component("comp1").material("pmat1").propertyGroup("Enu").set("E", new String[]{"800[MPa]"});
    model.component("comp1").material("pmat1").propertyGroup("Enu").set("nu", new String[]{"0.25"});

//    In the Model Builder window, click Porous Material 2 (pmat2).
//    In the Settings window for Porous Material, locate the Homogenized Properties section.
//    In the table, enter the following settings:

    model.component("comp1").material("pmat2").propertyGroup("def").set("density", new String[]{"2750"});
    model.component("comp1").material("pmat2").propertyGroup()
         .create("Enu", "Enu", "Young's_modulus_and_Poisson's_ratio");
    model.component("comp1").material("pmat2").propertyGroup("Enu").set("E", new String[]{"80[MPa]"});
    model.component("comp1").material("pmat2").propertyGroup("Enu").set("nu", new String[]{"0.25"});

//    Create a variable to calculate the solid-to-fluid coupling term.
//    In the Model Builder window, expand the Component 1 (comp1) > Definitions node, then click Variables 3.
//    In the Settings window for Variables, locate the Variables section.
//    In the table, enter the following settings:

    model.component("comp1").variable("var3").set("Q_biot", "-poro1.alphaB*d(solid.evol,TIME)*dl.rho");

//    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 > Time Dependent.
//    Click Add Study in the window toolbar.

    model.study().create("std2");
    model.study("std2").create("time", "Transient");

//    In the Home toolbar, click Add Study to close the Add Study window.
//    In the Settings window for Time Dependent, locate the Study Settings section.
//    From the Time unit list, select a.

    model.study("std2").feature("time").set("tunit", "a");

//    Click Range.
//    In the Range dialog, type 0.01 in the Step text field.
//    In the Stop text field, type 0.2.
//    Click Replace.

    model.study("std2").feature("time").set("tlist", "range(0,0.01,0.2)");

//    In the Settings window for Time Dependent, locate the Study Settings section.
//    Click Range.
//    In the Range dialog, type 1 in the Step text field.
//    In the Start text field, type 1.
//    In the Stop text field, type 10.
//    Click Add.

    model.study("std2").feature("time").set("tlist", "range(0,0.01,0.2) range(1,1,10)");

//    In the Study toolbar, click Compute.

    model.study("std2").createAutoSequences("all");

    model.sol("sol2").runAll();

    model.result().create("pg4", "PlotGroup2D");
    model.result("pg4").label("Pressure (dl)");
    model.result("pg4").set("data", "dset2");
    model.result("pg4").set("titletype", "custom");
    model.result("pg4").set("smooth", "internal");
    model.result("pg4").feature().create("surf1", "Surface");
    model.result("pg4").feature("surf1").label("Surface");
    model.result("pg4").feature("surf1").set("colortabletype", "discrete");
    model.result("pg4").feature("surf1").set("bandcount", 25);
    model.result("pg4").feature("surf1").set("smooth", "internal");
    model.result("pg4").feature("surf1").set("data", "parent");
    model.result().create("pg5", "PlotGroup2D");
    model.result("pg5").label("Velocity (dl) 1");
    model.result("pg5").set("data", "dset2");
    model.result("pg5").set("smooth", "internal");
    model.result("pg5").feature().create("surf1", "Surface");
    model.result("pg5").feature("surf1").label("Surface");
    model.result("pg5").feature("surf1").set("expr", "dl.U");
    model.result("pg5").feature("surf1").set("colortable", "Rainbow");
    model.result("pg5").feature("surf1").set("smooth", "internal");
    model.result("pg5").feature("surf1").set("data", "parent");
    model.result().create("pg6", "PlotGroup2D");
    model.result("pg6").set("data", "dset2");
    model.result("pg6").label("Stress (solid)");
    model.result("pg6").set("frametype", "spatial");
    model.result("pg6").create("surf1", "Surface");
    model.result("pg6").feature("surf1").set("expr", new String[]{"solid.misesGp"});
    model.result("pg6").feature("surf1").set("threshold", "manual");
    model.result("pg6").feature("surf1").set("thresholdvalue", 0.2);
    model.result("pg6").feature("surf1").set("colortable", "Rainbow");
    model.result("pg6").feature("surf1").set("colortabletrans", "none");
    model.result("pg6").feature("surf1").set("colorscalemode", "linear");
    model.result("pg6").feature("surf1").set("resolution", "normal");
    model.result("pg6").feature("surf1").set("refine", 2);
    model.result("pg6").feature("surf1").set("colortable", "Prism");
    model.result("pg6").feature("surf1").create("def", "Deform");
    model.result("pg6").feature("surf1").feature("def").set("expr", new String[]{"u", "v"});
    model.result("pg6").feature("surf1").feature("def").set("descr", "Displacement field");
    model.result("pg4").run();

//    In the Results toolbar, click 2D Plot Group.

    model.result().create("pg7", "PlotGroup2D");
    model.result("pg7").run();

//    In the Settings window for 2D Plot Group, type Hydraulic Head, Poroelasticity in the Label text field.

    model.result("pg7").label("Hydraulic Head, Poroelasticity");

//    Locate the Data section.
//    From the Dataset list, select Study 2/Solution 2 (sol2).

    model.result("pg7").set("data", "dset2");

//    Right-click Hydraulic Head, Poroelasticity and choose Surface.

    model.result("pg7").create("surf1", "Surface");
    model.result("pg7").feature("surf1").set("evaluationsettings", "parent");

//    In the Settings window for Surface, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Darcy's Law > Velocity and pressure > dl.H - Hydraulic head - m.

    model.result("pg7").feature("surf1").set("expr", "dl.H");
    model.result("pg7").feature("surf1").set("descr", "Hydraulic head");
    model.result("pg7").run();

//    In the Model Builder window, right-click Hydraulic Head, Poroelasticity and choose Contour.

    model.result("pg7").create("con1", "Contour");
    model.result("pg7").feature("con1").set("evaluationsettings", "parent");

//    In the Settings window for Contour, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Solid Mechanics > Displacement > solid.disp - Displacement magnitude - m.

    model.result("pg7").feature("con1").set("expr", "solid.disp");
    model.result("pg7").feature("con1").set("descr", "Displacement magnitude");

//    Locate the Levels section.
//    From the Entry method list, select Levels.

    model.result("pg7").feature("con1").set("levelmethod", "levels");

//    In the Levels text field, type range(0,0.2,2.3).

    model.result("pg7").feature("con1").set("levels", "range(0,0.2,2.3)");

//    Locate the Coloring and Style section.
//    From the Coloring list, select Uniform.

    model.result("pg7").feature("con1").set("coloring", "uniform");

//    From the Color list, select Black.

    model.result("pg7").feature("con1").set("color", "black");

//    Clear the Color legend checkbox.

    model.result("pg7").feature("con1").set("colorlegend", false);

//    Click to expand the Quality section.
//    From the Evaluation settings list, select Manual.

    model.result("pg7").feature("con1").set("evaluationsettings", "manual");

//    From the Resolution list, select Extra fine.

    model.result("pg7").feature("con1").set("resolution", "extrafine");
    model.result("pg7").run();

//    Right-click Hydraulic Head, Poroelasticity and choose Arrow Surface.

    model.result("pg7").create("arws1", "ArrowSurface");
    model.result("pg7").feature("arws1").set("evaluationsettings", "parent");

//    In the Settings window for Arrow Surface, locate the Expression section.
//    In the X-component text field, type d(dl.H,X).

    model.result("pg7").feature("arws1").set("expr", new String[]{"d(dl.H,X)", "dl.v"});

//    In the Y-component text field, type d(dl.H,Y).

    model.result("pg7").feature("arws1").set("expr", new String[]{"d(dl.H,X)", "d(dl.H,Y)"});

//    Select the Description checkbox.

    model.result("pg7").feature("arws1").set("descractive", true);

//    In the associated text field, type Hydraulic head gradient (1).

    model.result("pg7").feature("arws1").set("descr", "Hydraulic head gradient (1)");

//    Locate the Arrow Positioning section.
//    Find the X grid points subsection.
//    In the Points text field, type 25.

    model.result("pg7").feature("arws1").set("xnumber", 25);
    model.result("pg7").run();

//    In the Model Builder window, right-click Surface 1 and choose Deformation.

    model.result("pg7").feature("surf1").create("def1", "Deform");
    model.result("pg7").run();

//    In the Settings window for Deformation, locate the Scale section.
//    Select the Scale factor checkbox.

    model.result("pg7").feature("surf1").feature("def1").set("scaleactive", true);

//    In the associated text field, type 10.

    model.result("pg7").feature("surf1").feature("def1").set("scale", 10);

//    Right-click Deformation 1 and choose Copy.

    model.result("pg7").run();

//    In the Model Builder window, right-click Contour 1 and choose Paste Deformation.

    model.result("pg7").feature("con1").feature().copy("def1", "pg7/surf1/def1");
    model.result("pg7").run();
    model.result("pg7").run();
    model.result("pg7").run();

//    In the Settings window for Arrow Surface, locate the Coloring and Style section.
//    Select the Scale factor checkbox.

    model.result("pg7").feature("arws1").set("scaleactive", true);

//    In the Hydraulic Head, Poroelasticity toolbar, click Plot.

    model.result("pg7").run();

//    In the associated text field, type 2e4.

    model.result("pg7").feature("arws1").set("scale", "2e4");

//    Right-click Arrow Surface 1 and choose Paste Deformation.

    model.result("pg7").feature("arws1").feature().copy("def1", "pg7/surf1/def1");
    model.result("pg7").run();
    model.result("pg7").run();

//    In the Settings window for 2D Plot Group, locate the Data section.
//    From the Time (a) list, select 2.

    model.result("pg7").setIndex("looplevel", 23, 0);

//    In the Hydraulic Head, Poroelasticity toolbar, click Plot.

    model.result("pg7").run();

//    Click the Zoom Extents button in the Graphics toolbar.
//    From the Time (a) list, select 5.

    model.result("pg7").setIndex("looplevel", 26, 0);

//    In the Hydraulic Head, Poroelasticity toolbar, click Plot.

    model.result("pg7").run();

//    From the Time (a) list, select 10.

    model.result("pg7").setIndex("looplevel", 31, 0);

//    In the Hydraulic Head, Poroelasticity toolbar, click Plot.

    model.result("pg7").run();
    model.result("pg6").run();

//    In the Model Builder window, under Results, click Stress (solid).
//    In the Settings window for 2D Plot Group, type von Mises Stress in the Label text field.

    model.result("pg6").label("von Mises Stress");
    model.result("pg6").run();

//    In the Model Builder window, expand the von Mises Stress node, then click Surface 1.
//    In the Settings window for Surface, click to expand the Quality section.
//    From the Smoothing threshold list, select None.

    model.result("pg6").feature("surf1").set("threshold", "none");
    model.result("pg6").run();

//    In the Model Builder window, expand the Surface 1 node, then click Deformation.
//    In the Settings window for Deformation, locate the Scale section.
//    Select the Scale factor checkbox.

    model.result("pg6").feature("surf1").feature("def").set("scaleactive", true);

//    In the associated text field, type 10.

    model.result("pg6").feature("surf1").feature("def").set("scale", 10);
    model.result("pg6").run();

//    In the Model Builder window, right-click von Mises Stress and choose Streamline.

    model.result("pg6").create("str1", "Streamline");
    model.result("pg6").feature("str1").set("evaluationsettings", "parent");

//    In the Settings window for Streamline, locate the Streamline Positioning section.
//    From the Positioning list, select Starting-point controlled.

    model.result("pg6").feature("str1").set("posmethod", "start");

//    From the Entry method list, select Coordinates.

    model.result("pg6").feature("str1").set("startmethod", "coord");

//    In the X text field, type 0.

    model.result("pg6").feature("str1").set("xcoord", 0);

//    In the Y text field, type range(-450,50,-50).

    model.result("pg6").feature("str1").set("ycoord", "range(-450,50,-50)");

//    Locate the Coloring and Style section.
//    Find the Point style subsection.
//    From the Color list, select White.

    model.result("pg6").feature("str1").set("color", "white");

//    Click to expand the Quality section.
//    From the Evaluation settings list, select Manual.

    model.result("pg6").feature("str1").set("evaluationsettings", "manual");

//    From the Smoothing list, select Everywhere.

    model.result("pg6").feature("str1").set("smooth", "everywhere");
    model.result("pg6").run();

//    In the Model Builder window, right-click Results > von Mises Stress > Surface 1 > Deformation and choose Copy.

    model.result("pg6").run();

//    In the Model Builder window, right-click Streamline 1 and choose Paste Deformation.

    model.result("pg6").feature("str1").feature().copy("def", "pg6/surf1/def");
    model.result("pg6").run();

//    In the Results toolbar, click 2D Plot Group.

    model.result().create("pg8", "PlotGroup2D");
    model.result("pg8").run();

//    In the Settings window for 2D Plot Group, type Solid-to-Fluid Coupling Term in the Label text field.

    model.result("pg8").label("Solid-to-Fluid Coupling Term");

//    Locate the Data section.
//    From the Dataset list, select Study 2/Solution 2 (sol2).

    model.result("pg8").set("data", "dset2");

//    Right-click Solid-to-Fluid Coupling Term and choose Surface.

    model.result("pg8").create("surf1", "Surface");
    model.result("pg8").feature("surf1").set("evaluationsettings", "parent");

//    In the Settings window for Surface, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 1 (comp1) > Definitions > Variables > Q_biot - kg/(m³·s).

    model.result("pg8").feature("surf1").set("expr", "Q_biot");
    model.result("pg8").feature("surf1").set("descr", "");

//    In the Solid-to-Fluid Coupling Term toolbar, click Plot.

    model.result("pg8").run();

//    In the Results toolbar, click Cut Line 2D.

    model.result().dataset().create("cln1", "CutLine2D");

//    In the Settings window for Cut Line 2D, locate the Data section.
//    From the Dataset list, select Study 2/Solution 2 (sol2).

    model.result().dataset("cln1").set("data", "dset2");

//    Locate the Line Data section.
//    In row Point 1, set X to 1000.

    model.result().dataset("cln1").setIndex("genpoints", 1000, 0, 0);

//    In row Point 2, set X to 5000.

    model.result().dataset("cln1").setIndex("genpoints", 5000, 1, 0);

//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg9", "PlotGroup1D");
    model.result("pg9").run();

//    In the Settings window for 1D Plot Group, type Horizontal Strain in the Label text field.

    model.result("pg9").label("Horizontal Strain");

//    Locate the Data section.
//    From the Dataset list, select Cut Line 2D 1.

    model.result("pg9").set("data", "cln1");

//    From the Time selection list, select From list.

    model.result("pg9").setIndex("looplevelinput", "manual", 0);

//    In the Times (a) list, select 2, 5, 10.

    model.result("pg9").setIndex("looplevel", new int[]{23, 26, 31}, 0);

//    Right-click Horizontal Strain and choose Line Graph.

    model.result("pg9").create("lngr1", "LineGraph");
    model.result("pg9").feature("lngr1").set("markerpos", "datapoints");
    model.result("pg9").feature("lngr1").set("linewidth", "preference");
    model.result("pg9").feature("lngr1").set("evaluationsettings", "parent");

//    In the Settings window for Line Graph, click Replace Expression in the upper-right corner of the y-Axis Data section.
//    From the menu, choose Component 1 (comp1) > Solid Mechanics > Strain > Strain tensor (material and geometry frames) > solid.eXX - Strain tensor, XX-component.

    model.result("pg9").feature("lngr1").set("expr", "solid.eXX");
    model.result("pg9").feature("lngr1").set("descr", "Strain tensor, XX-component");

//    Locate the x-Axis Data section.
//    From the Parameter list, select Expression.

    model.result("pg9").feature("lngr1").set("xdata", "expr");

//    Click Replace Expression in the upper-right corner of the x-Axis Data section.
//    From the menu, choose Component 1 (comp1) > Geometry > Coordinate (material and geometry frames) > X - X-coordinate.

    model.result("pg9").feature("lngr1").set("xdataexpr", "X");
    model.result("pg9").feature("lngr1").set("xdatadescr", "X-coordinate");

//    Click to expand the Legends section.
//    Select the Show legends checkbox.

    model.result("pg9").feature("lngr1").set("legend", true);

//    In the Horizontal Strain toolbar, click Plot.

    model.result("pg9").run();
    model.result("pg7").run();

//    To produce a plot array of the hydraulic head at different times, follow the steps below.
//    In the Model Builder window, right-click Hydraulic Head, Poroelasticity and choose Duplicate.

    model.result().duplicate("pg10", "pg7");
    model.result("pg10").run();

//    In the Model Builder window, click Hydraulic Head, Poroelasticity 1.
//    In the Settings window for 2D Plot Group, type Hydraulic Head, Poroelasticity, Array in the Label text field.

    model.result("pg10").label("Hydraulic Head, Poroelasticity, Array");

//    Click to expand the Plot Array section.
//    From the Array type list, select Square.

    model.result("pg10").set("plotarraytype", "square");

//    From the Displacement list, select Absolute.

    model.result("pg10").set("displacementsquare", "absolute");

//    In the Row displacement text field, type -500.

    model.result("pg10").set("rowdisp", -500);

//    In the Column displacement text field, type 6000.

    model.result("pg10").set("columndisp", 6000);
    model.result("pg10").run();

//    In the Model Builder window, right-click Surface 1 and choose Solution Array.

    model.result("pg10").feature("surf1").create("sol1", "SolutionArray");

//    In the Settings window for Solution Array, locate the Data section.
//    From the Time selection list, select From list.

    model.result("pg10").feature("surf1").feature("sol1").setIndex("looplevelinput", "manual", 0);

//    In the Times (a) list, select 2, 5, 8, 10.

    model.result("pg10").feature("surf1").feature("sol1").setIndex("looplevel", new int[]{23, 26, 29, 31}, 0);

//    Locate the Plot Array section.
//    From the Array shape list, select Square.

    model.result("pg10").feature("surf1").feature("sol1").set("arrayshape", "square");
    model.result("pg10").run();

//    In the Model Builder window, under Results > Hydraulic Head, Poroelasticity, Array, click Arrow Surface 1.

    return model;
  }

  public static Model run2(Model model) {
//    In the Settings window for Arrow Surface, click to expand the Plot Array section.
//    Select the Manual indexing checkbox.

    model.result("pg10").feature("arws1").set("manualindexing", true);

//    Right-click Arrow Surface 1 and choose Solution Array.

    model.result("pg10").feature("arws1").create("sol1", "SolutionArray");

//    In the Settings window for Solution Array, locate the Data section.
//    From the Time selection list, select From list.

    model.result("pg10").feature("arws1").feature("sol1").setIndex("looplevelinput", "manual", 0);

//    In the Times (a) list, select 2, 5, 8, 10.

    model.result("pg10").feature("arws1").feature("sol1").setIndex("looplevel", new int[]{23, 26, 29, 31}, 0);

//    Locate the Plot Array section.
//    From the Array shape list, select Square.

    model.result("pg10").feature("arws1").feature("sol1").set("arrayshape", "square");
    model.result("pg10").run();

//    In the Model Builder window, under Results > Hydraulic Head, Poroelasticity, Array, click Contour 1.
//    In the Settings window for Contour, click to expand the Plot Array section.
//    Select the Manual indexing checkbox.

    model.result("pg10").feature("con1").set("manualindexing", true);

//    Locate the Data section.
//    From the Dataset list, select Study 2/Solution 2 (sol2).

    model.result("pg10").feature("con1").set("data", "dset2");

//    From the Time (a) list, select 2.

    model.result("pg10").feature("con1").setIndex("looplevel", 23, 0);

//    Right-click Results > Hydraulic Head, Poroelasticity, Array > Contour 1 and choose Duplicate.

    model.result("pg10").feature().duplicate("con2", "con1");
    model.result("pg10").run();

//    In the Settings window for Contour, locate the Data section.
//    From the Time (a) list, select 5.

    model.result("pg10").feature("con2").setIndex("looplevel", 26, 0);

//    Locate the Plot Array section.
//    In the Column index text field, type 1.

    model.result("pg10").feature("con2").set("colindex", 1);

//    Right-click Contour 2 and choose Duplicate.

    model.result("pg10").feature().duplicate("con3", "con2");
    model.result("pg10").run();

//    In the Model Builder window, expand the Results > Hydraulic Head, Poroelasticity, Array > Contour 1 node, then click Results > Hydraulic Head, Poroelasticity, Array > Contour 3.
//    In the Settings window for Contour, locate the Data section.
//    From the Time (a) list, select 8.

    model.result("pg10").feature("con3").setIndex("looplevel", 29, 0);

//    Locate the Plot Array section.
//    In the Row index text field, type 1.

    model.result("pg10").feature("con3").set("rowindex", 1);

//    In the Column index text field, type 0.

    model.result("pg10").feature("con3").set("colindex", 0);

//    Right-click Results > Hydraulic Head, Poroelasticity, Array > Contour 3 and choose Duplicate.

    model.result("pg10").feature().duplicate("con4", "con3");
    model.result("pg10").run();

//    In the Settings window for Contour, locate the Data section.
//    From the Time (a) list, select 10.

    model.result("pg10").feature("con4").setIndex("looplevel", 31, 0);

//    Locate the Plot Array section.
//    In the Column index text field, type 1.

    model.result("pg10").feature("con4").set("colindex", 1);

//    Click the Zoom Extents button in the Graphics toolbar.

    model.result("pg10").run();

//    In the Model Builder window, click Hydraulic Head, Poroelasticity, Array.
//    In the Hydraulic Head, Poroelasticity, Array toolbar, click More Plots and choose Table Annotation.

    model.result("pg10").create("tlan1", "TableAnnotation");

//    In the Settings window for Table Annotation, locate the Data section.
//    From the Source list, select Local table.

    model.result("pg10").feature("tlan1").set("source", "localtable");

//    In the table, enter the following settings:

    model.result("pg10").feature("tlan1").setIndex("localtablematrix", "0.2e4", 0, 0);
    model.result("pg10").feature("tlan1").setIndex("localtablematrix", -450, 0, 1);
    model.result("pg10").feature("tlan1").setIndex("localtablematrix", "time = 2 a", 0, 2);
    model.result("pg10").feature("tlan1").setIndex("localtablematrix", "0.85e4", 1, 0);
    model.result("pg10").feature("tlan1").setIndex("localtablematrix", -450, 1, 1);
    model.result("pg10").feature("tlan1").setIndex("localtablematrix", "time = 5 a", 1, 2);
    model.result("pg10").feature("tlan1").setIndex("localtablematrix", "0.2e4", 2, 0);
    model.result("pg10").feature("tlan1").setIndex("localtablematrix", -950, 2, 1);
    model.result("pg10").feature("tlan1").setIndex("localtablematrix", "time = 8 a", 2, 2);
    model.result("pg10").feature("tlan1").setIndex("localtablematrix", "0.85e4", 3, 0);
    model.result("pg10").feature("tlan1").setIndex("localtablematrix", -950, 3, 1);
    model.result("pg10").feature("tlan1").setIndex("localtablematrix", "time = 10 a", 3, 2);

//    Locate the Coloring and Style section.
//    From the Anchor point list, select Upper middle.

    model.result("pg10").feature("tlan1").set("anchorpoint", "uppermiddle");

//    Clear the Show point checkbox.

    model.result("pg10").feature("tlan1").set("showpoint", false);

//    In the Hydraulic Head, Poroelasticity, Array toolbar, click Plot.

    model.result("pg10").run();
    model.result("pg10").run();

//    In the Model Builder window, click Hydraulic Head, Poroelasticity, Array.
//    In the Settings window for 2D Plot Group, click to expand the Title section.
//    From the Title type list, select Manual.

    model.result("pg10").set("titletype", "manual");

//    In the Title text area, type Surface: Hydraulic head (m) Contour: Displacement magnitude (m) Arrow Surface: Hydraulic head gradient (1).

    model.result("pg10")
         .set("title", "Surface: Hydraulic head (m) Contour: Displacement magnitude (m) Arrow Surface: Hydraulic head gradient (1)");

//    Clear the Parameter indicator text field.

    model.result("pg10").set("paramindicator", "");

//    In the Hydraulic Head, Poroelasticity, Array toolbar, click Plot.

    model.result("pg10").run();

//    Click the Zoom Extents button in the Graphics toolbar.
//    Group the plots to keep the <l>Result</l> node clear.␤

    model.result("pg4").run();

//    In the Model Builder window, under Results, Ctrl-click to select Pressure (dl), Velocity (dl) 1, von Mises Stress, Hydraulic Head, Poroelasticity, Solid-to-Fluid Coupling Term, Horizontal Strain, Hydraulic Head, Poroelasticity, Array.
//    Right-click and choose Group.

    model.nodeGroup().create("grp1", "Results");
    model.nodeGroup("grp1").set("type", "plotgroup");
    model.nodeGroup("grp1").placeAfter("plotgroup", "pg3");
    model.nodeGroup("grp1").add("plotgroup", "pg4");
    model.nodeGroup("grp1").add("plotgroup", "pg5");
    model.nodeGroup("grp1").add("plotgroup", "pg6");
    model.nodeGroup("grp1").add("plotgroup", "pg7");
    model.nodeGroup("grp1").add("plotgroup", "pg8");
    model.nodeGroup("grp1").add("plotgroup", "pg9");
    model.nodeGroup("grp1").add("plotgroup", "pg10");

//    In the Settings window for Group, type Biot in the Label text field.

    model.nodeGroup("grp1").label("Biot");

    model.result("pg1").run();

//    In the Model Builder window, under Results, Ctrl-click to select Hydraulic Head, Velocity (dl), Compaction.
//    Right-click and choose Group.

    model.nodeGroup().create("grp2", "Results");
    model.nodeGroup("grp2").set("type", "plotgroup");
    model.nodeGroup("grp2").add("plotgroup", "pg1");
    model.nodeGroup("grp2").add("plotgroup", "pg2");
    model.nodeGroup("grp2").add("plotgroup", "pg3");

//    In the Settings window for Group, type Terzaghi in the Label text field.

    model.nodeGroup("grp2").label("Terzaghi");

    model.result("pg10").run();

    model.title("Biot Poroelasticity");

    model
         .description("The Biot Poroelasticity example uses the Poroelasticity interface available in the Subsurface Flow Module to assess deformation of porous media that results from fluid withdrawal. The model builds on top of the Terzaghi compaction example and compares the results of the Terzaghi compaction and Biot poroelasticity analyses.");

    return model;
  }

  public static void main(String[] args) {
    Model model = run();
    run2(model);
  }

}
