/*
 * buoyancy_water.java
 */

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

/** Model exported on May 14 2026, 10:10 by COMSOL 6.4.0.420. */
public class buoyancy_water {

  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 Fluid Flow > Nonisothermal Flow > Laminar Flow.
//    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").mesh().create("mesh1");

    model.component("comp1").physics().create("spf", "LaminarFlow", "geom1");
    model.component("comp1").physics("spf").prop("AdvancedSettingProperty").set("UsePseudoTime", "1");
    model.component("comp1").physics("spf").prop("PhysicalModelProperty")
         .set("Compressibility", "WeaklyCompressible");
    model.component("comp1").physics().create("ht", "HeatTransferInFluids", "geom1");
    model.component("comp1").physics("ht").prop("PhysicalModelProperty").set("dz", "1[m]");
    model.component("comp1").physics("ht").prop("ShapeProperty").set("order_temperature", "1");

    model.component("comp1").multiphysics().create("nitf1", "NonIsothermalFlow", 2);
    model.component("comp1").multiphysics("nitf1").set("Fluid_physics", "spf");
    model.component("comp1").multiphysics("nitf1").set("Heat_physics", "ht");

    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("L", "10[cm]");
    model.param().descr("L", "Square side length");
    model.param().set("DeltaT", "10[K]");
    model.param().descr("DeltaT", "Temperature difference");
    model.param().set("Tc", "283.15[K]");
    model.param().descr("Tc", "Low temperature");
    model.param().set("Th", "Tc+DeltaT");
    model.param().descr("Th", "High temperature");
    model.param().set("rho", "1000[kg/m^3]");
    model.param().descr("rho", "Density");
    model.param().set("mu", "1.3e-3[N*s/m^2]");
    model.param().descr("mu", "Dynamic viscosity");
    model.param().set("k", "0.58[W/(m*K)]");
    model.param().descr("k", "Thermal conductivity");
    model.param().set("Cp", "4.2[kJ/(kg*K)]");
    model.param().descr("Cp", "Heat capacity");
    model.param().set("alpha", "9e-5[1/K]");
    model.param().descr("alpha", "Coefficient of thermal expansion");
    model.param().set("U0", "sqrt(g_const*alpha*DeltaT*L)");
    model.param().descr("U0", "Typical velocity due to buoyancy");
    model.param().set("U1", "U0/sqrt(Pr)");
    model.param().descr("U1", "Typical velocity estimation");
    model.param().set("Pr", "mu*Cp/k");
    model.param().descr("Pr", "Prandtl number");
    model.param().set("Gr", "(U0*rho*L/mu)^2");
    model.param().descr("Gr", "Grashof number");
    model.param().set("Ra", "Pr*Gr");
    model.param().descr("Ra", "Rayleigh number");
    model.param().set("Re0", "rho*U0*L/mu");
    model.param().descr("Re0", "Reynolds number approximation with U0");
    model.param().set("Re1", "rho*U1*L/mu");
    model.param().descr("Re1", "Reynolds number approximation with U1");
    model.param().set("eps_t", "L/(Ra)^0.25");
    model.param().descr("eps_t", "Thermal boundary layer thickness");
    model.param().set("eps_m", "L/sqrt(Re1)");
    model.param().descr("eps_m", "Momentum boundary layer thickness");

//    The Grashof and Rayleigh numbers should be less than \[10^9\], indicating that a laminar regime is expected.
//    In the Geometry toolbar, click Square.

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

//    In the Settings window for Square, locate the Size section.
//    In the Side length text field, type L.

    model.component("comp1").geom("geom1").feature("sq1").set("size", "L");

//    In the Geometry toolbar, click Build All.

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

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Materials toolbar, click Add Material to open the Add Material window.
//    In the tree, select Built-in > Water, liquid.
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat1", "Common");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("eta", "Piecewise");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("Cp", "Piecewise");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("rho", "Piecewise");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("k", "Piecewise");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("cs", "Interpolation");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("an1", "Analytic");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("an2", "Analytic");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("an3", "Analytic");
    model.component("comp1").material("mat1").label("Water, liquid");
    model.component("comp1").material("mat1").set("family", "water");
    model.component("comp1").material("mat1").propertyGroup("def").func("eta").set("arg", "T");
    model.component("comp1").material("mat1").propertyGroup("def").func("eta")
         .set("pieces", new String[][]{{"273.15", "413.15", "1.3799566804-0.021224019151*T^1+1.3604562827E-4*T^2-4.6454090319E-7*T^3+8.9042735735E-10*T^4-9.0790692686E-13*T^5+3.8457331488E-16*T^6"}, {"413.15", "553.75", "0.00401235783-2.10746715E-5*T^1+3.85772275E-8*T^2-2.39730284E-11*T^3"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("eta").set("argunit", "K");
    model.component("comp1").material("mat1").propertyGroup("def").func("eta").set("fununit", "Pa*s");
    model.component("comp1").material("mat1").propertyGroup("def").func("Cp").set("arg", "T");
    model.component("comp1").material("mat1").propertyGroup("def").func("Cp")
         .set("pieces", new String[][]{{"273.15", "553.75", "12010.1471-80.4072879*T^1+0.309866854*T^2-5.38186884E-4*T^3+3.62536437E-7*T^4"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("Cp").set("argunit", "K");
    model.component("comp1").material("mat1").propertyGroup("def").func("Cp").set("fununit", "J/(kg*K)");
    model.component("comp1").material("mat1").propertyGroup("def").func("rho").set("arg", "T");
    model.component("comp1").material("mat1").propertyGroup("def").func("rho").set("smooth", "contd1");
    model.component("comp1").material("mat1").propertyGroup("def").func("rho")
         .set("pieces", new String[][]{{"273.15", "293.15", "0.000063092789034*T^3-0.060367639882855*T^2+18.9229382407066*T-950.704055329848"}, {"293.15", "373.15", "0.000010335053319*T^3-0.013395065634452*T^2+4.969288832655160*T+432.257114008512"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("rho").set("argunit", "K");
    model.component("comp1").material("mat1").propertyGroup("def").func("rho").set("fununit", "kg/m^3");
    model.component("comp1").material("mat1").propertyGroup("def").func("k").set("arg", "T");
    model.component("comp1").material("mat1").propertyGroup("def").func("k")
         .set("pieces", new String[][]{{"273.15", "553.75", "-0.869083936+0.00894880345*T^1-1.58366345E-5*T^2+7.97543259E-9*T^3"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("k").set("argunit", "K");
    model.component("comp1").material("mat1").propertyGroup("def").func("k").set("fununit", "W/(m*K)");
    model.component("comp1").material("mat1").propertyGroup("def").func("cs")
         .set("table", new String[][]{{"273", "1403"}, 
         {"278", "1427"}, 
         {"283", "1447"}, 
         {"293", "1481"}, 
         {"303", "1507"}, 
         {"313", "1526"}, 
         {"323", "1541"}, 
         {"333", "1552"}, 
         {"343", "1555"}, 
         {"353", "1555"}, 
         {"363", "1550"}, 
         {"373", "1543"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("cs").set("interp", "piecewisecubic");
    model.component("comp1").material("mat1").propertyGroup("def").func("cs").set("fununit", new String[]{"m/s"});
    model.component("comp1").material("mat1").propertyGroup("def").func("cs").set("argunit", new String[]{"K"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an1").set("funcname", "alpha_p");
    model.component("comp1").material("mat1").propertyGroup("def").func("an1").set("expr", "-1/rho(T)*d(rho(T),T)");
    model.component("comp1").material("mat1").propertyGroup("def").func("an1").set("args", new String[]{"T"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an1").set("fununit", "1/K");
    model.component("comp1").material("mat1").propertyGroup("def").func("an1").set("argunit", new String[]{"K"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an1")
         .set("plotfixedvalue", new String[]{"273.15"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an1")
         .set("plotargs", new String[][]{{"T", "273.15", "373.15"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("an2").set("funcname", "gamma_w");
    model.component("comp1").material("mat1").propertyGroup("def").func("an2")
         .set("expr", "1+(T/Cp(T))*(alpha_p(T)*cs(T))^2");
    model.component("comp1").material("mat1").propertyGroup("def").func("an2").set("args", new String[]{"T"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an2").set("fununit", "1");
    model.component("comp1").material("mat1").propertyGroup("def").func("an2").set("argunit", new String[]{"K"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an2")
         .set("plotfixedvalue", new String[]{"273.15"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an2")
         .set("plotargs", new String[][]{{"T", "273.15", "373.15"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("an3").set("funcname", "muB");
    model.component("comp1").material("mat1").propertyGroup("def").func("an3").set("expr", "2.79*eta(T)");
    model.component("comp1").material("mat1").propertyGroup("def").func("an3").set("args", new String[]{"T"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an3").set("fununit", "Pa*s");
    model.component("comp1").material("mat1").propertyGroup("def").func("an3").set("argunit", new String[]{"K"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an3")
         .set("plotfixedvalue", new String[]{"273.15"});
    model.component("comp1").material("mat1").propertyGroup("def").func("an3")
         .set("plotargs", new String[][]{{"T", "273.15", "553.75"}});
    model.component("comp1").material("mat1").propertyGroup("def").set("thermalexpansioncoefficient", "");
    model.component("comp1").material("mat1").propertyGroup("def").set("bulkviscosity", "");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("thermalexpansioncoefficient", new String[]{"alpha_p(T)", "0", "0", "0", "alpha_p(T)", "0", "0", "0", "alpha_p(T)"});
    model.component("comp1").material("mat1").propertyGroup("def").set("bulkviscosity", "muB(T)");
    model.component("comp1").material("mat1").propertyGroup("def").set("dynamicviscosity", "eta(T)");
    model.component("comp1").material("mat1").propertyGroup("def").set("ratioofspecificheat", "gamma_w(T)");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("electricconductivity", new String[]{"5.5e-6[S/m]", "0", "0", "0", "5.5e-6[S/m]", "0", "0", "0", "5.5e-6[S/m]"});
    model.component("comp1").material("mat1").propertyGroup("def").set("heatcapacity", "Cp(T)");
    model.component("comp1").material("mat1").propertyGroup("def").set("density", "rho(T)");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("thermalconductivity", new String[]{"k(T)", "0", "0", "0", "k(T)", "0", "0", "0", "k(T)"});
    model.component("comp1").material("mat1").propertyGroup("def").set("soundspeed", "cs(T)");
    model.component("comp1").material("mat1").propertyGroup("def").addInput("temperature");

//    In the Materials toolbar, click Add Material to close the Add Material window.
//    In order to ensure mass conservation, as the volume is constant, the water density cannot depend only on the temperature. It has to be either constant or pressure and temperature dependent. Select the <l>Incompressible flow</l> option to define a constant density evaluated from the material properties at the reference pressure and temperature.
//    In the Settings window for Laminar Flow, locate the Physical Model section.
//    From the Compressibility list, select Incompressible flow.

    model.component("comp1").physics("spf").prop("PhysicalModelProperty").set("Compressibility", "Incompressible");

//    Select the Include gravity checkbox.

    model.component("comp1").physics("spf").prop("PhysicalModelProperty").set("IncludeGravity", true);

//    In the Physics toolbar, click Points and choose Pressure Point Constraint.

    model.component("comp1").physics("spf").create("prpc1", "PressurePointConstraint", 0);

//    Select Point 2.

    model.component("comp1").physics("spf").feature("prpc1").selection().set(2);

//    Fixing the pressure at an arbitrary point is necessary to define a well-posed model.
//    In the Model Builder window, under Component 1 (comp1), click Heat Transfer in Fluids (ht).
//    In the Settings window for Heat Transfer in Fluids, locate the Physical Model section.
//    In the \[T_\textrm{ref}\] text field, type (Tc+Th)/2.

    model.component("comp1").physics("ht").prop("PhysicalModelProperty").set("Tref", "(Tc+Th)/2");

//    Define the initial temperature as the mean value between the high and low temperature values.
//    In the Model Builder window, under Component 1 (comp1) > Heat Transfer in Fluids (ht), click Initial Values 1.
//    In the Settings window for Initial Values, locate the Initial Values section.
//    In the \[T\] text field, type (Tc+Th)/2.

    model.component("comp1").physics("ht").feature("init1").set("Tinit", "(Tc+Th)/2");

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

    model.component("comp1").physics("ht").create("temp1", "TemperatureBoundary", 1);

//    Select Boundary 1.

    model.component("comp1").physics("ht").feature("temp1").selection().set(1);

//    In the Settings window for Temperature, locate the Temperature section.
//    In the \[T_{\textrm{0}}\] text field, type Tc.

    model.component("comp1").physics("ht").feature("temp1").set("T0", "Tc");

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

    model.component("comp1").physics("ht").create("temp2", "TemperatureBoundary", 1);

//    Select Boundary 4.

    model.component("comp1").physics("ht").feature("temp2").selection().set(4);

//    In the Settings window for Temperature, locate the Temperature section.
//    In the \[T_{\textrm{0}}\] text field, type Th.

    model.component("comp1").physics("ht").feature("temp2").set("T0", "Th");

//    In the Model Builder window, under Component 1 (comp1) > Multiphysics, click Nonisothermal Flow 1 (nitf1).
//    In the Settings window for Nonisothermal Flow, locate the Material Properties section.
//    Select the Boussinesq approximation checkbox.

    model.component("comp1").multiphysics("nitf1").set("BoussinesqApproximation", true);

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

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

//    Click Build All.

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

//    Because the Grashof number is near the critical value of around \[10^9\], the model is highly nonlinear. To achieve convergence, use continuation to ramp up the temperature difference value from \[10^{-3}\] K to 10 K, which corresponds to a Grashof number from \[10^3\] to \[10^7\].
//    In the Model Builder window, under Study 1, click Step 1: Stationary.
//    In the Settings window for Stationary, click to expand the Study Extensions section.
//    Select the Auxiliary sweep checkbox.

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

//    Click Add.

    model.study("std1").feature("stat").setIndex("pname", "L", 0);
    model.study("std1").feature("stat").setIndex("plistarr", "", 0);
    model.study("std1").feature("stat").setIndex("punit", "m", 0);
    model.study("std1").feature("stat").setIndex("pname", "L", 0);
    model.study("std1").feature("stat").setIndex("plistarr", "", 0);
    model.study("std1").feature("stat").setIndex("punit", "m", 0);

//    In the table, enter the following settings:

    model.study("std1").feature("stat").setIndex("pname", "DeltaT", 0);
    model.study("std1").feature("stat").setIndex("plistarr", "1e-3 1e-2 1e-1 1 10", 0);
    model.study("std1").feature("stat").setIndex("punit", "K", 0);

//    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.
//    The pseudo time-stepping option is generally useful to help the convergence of a stationary flow model. However, a continuation approach is already used here. In this precise model, disabling the pseudo time-stepping option improves the convergence. Follow the instructions below to do so.
//    In the Model Builder window, under Component 1 (comp1), click Laminar Flow (spf).
//    In the Settings window for Laminar Flow, click to expand the Advanced Settings section.
//    Find the Pseudo time stepping subsection.
//    From the Use pseudo time stepping for stationary equation form list, select Off.

    model.component("comp1").physics("spf").prop("AdvancedSettingProperty").set("PseudoTimeSetting", "Off");

//    In the Study toolbar, click Compute.

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

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

    model.result().dataset("dset1").set("geom", "geom1");
    model.result().create("pg1", "PlotGroup2D");
    model.result("pg1").label("Velocity (spf)");
    model.result("pg1").set("frametype", "spatial");
    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("smooth", "internal");
    model.result("pg1").feature("surf1").set("data", "parent");
    model.result().create("pg2", "PlotGroup2D");
    model.result("pg2").label("Pressure (spf)");
    model.result("pg2").set("frametype", "spatial");
    model.result("pg2").set("smooth", "internal");
    model.result("pg2").feature().create("surf1", "Surface");
    model.result("pg2").feature("surf1").set("expr", "p");
    model.result("pg2").feature("surf1").set("colortable", "Tectocoris");
    model.result("pg2").feature("surf1").set("colortabletype", "discrete");
    model.result("pg2").feature("surf1").set("bandcount", 25);
    model.result("pg2").feature("surf1").set("smooth", "internal");
    model.result("pg2").feature("surf1").set("data", "parent");
    model.result().create("pg3", "PlotGroup2D");
    model.result("pg3").label("Temperature (ht)");
    model.result("pg3").set("smooth", "internal");
    model.result("pg3").feature().create("surf1", "Surface");
    model.result("pg3").feature("surf1").set("solutionparams", "parent");
    model.result("pg3").feature("surf1").set("expr", "T");
    model.result("pg3").feature("surf1").set("colortable", "HeatCameraLight");
    model.result("pg3").feature("surf1").set("data", "parent");
    model.result().create("pg4", "PlotGroup2D");
    model.result("pg4").label("Temperature and Fluid Flow (nitf1)");
    model.result("pg4").set("showlegendsunit", true);
    model.result("pg4").set("smooth", "internal");
    model.result("pg4").feature().create("surf1", "Surface");
    model.result("pg4").feature("surf1").label("Fluid Temperature");
    model.result("pg4").feature("surf1").set("solutionparams", "parent");
    model.result("pg4").feature("surf1").set("expr", "nitf1.T");
    model.result("pg4").feature("surf1").set("colortable", "HeatCameraLight");
    model.result("pg4").feature("surf1").set("smooth", "internal");
    model.result("pg4").feature("surf1").set("data", "parent");
    model.result("pg4").feature("surf1").feature().create("sel1", "Selection");
    model.result("pg4").feature("surf1").feature("sel1").selection().geom("geom1", 2);
    model.result("pg4").feature("surf1").feature("sel1").selection().set(1);
    model.result("pg4").feature().create("arws1", "ArrowSurface");
    model.result("pg4").feature("arws1").label("Fluid Flow");
    model.result("pg4").feature("arws1").set("solutionparams", "parent");
    model.result("pg4").feature("arws1").set("expr", new String[]{"nitf1.ux", "nitf1.uy"});
    model.result("pg4").feature("arws1").set("xnumber", 30);
    model.result("pg4").feature("arws1").set("ynumber", 30);
    model.result("pg4").feature("arws1").set("arrowtype", "cone");
    model.result("pg4").feature("arws1").set("arrowlength", "logarithmic");
    model.result("pg4").feature("arws1").set("data", "parent");
    model.result("pg4").feature("arws1").feature().create("col1", "Color");
    model.result("pg4").feature("arws1").feature().create("filt1", "Filter");
    model.result("pg4").feature("arws1").feature("filt1").set("expr", "spf.U>nitf1.Uave");
    model.result("pg1").run();

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

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

//    In the Model Builder window, expand the Results > Temperature and Fluid Flow (nitf1) node, then click Fluid Flow.
//    In the Settings window for Arrow Surface, locate the Arrow Positioning section.
//    Find the x grid points subsection.
//    In the Points text field, type 20.

    model.result("pg4").feature("arws1").set("xnumber", 20);

//    Find the y grid points subsection.
//    In the Points text field, type 20.

    model.result("pg4").feature("arws1").set("ynumber", 20);
    model.result("pg4").run();

//    In the Model Builder window, click Temperature and Fluid Flow (nitf1).
//    In the Temperature and Fluid Flow (nitf1) toolbar, click Plot.

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

//    In the following steps, the temperature and velocity profiles are plotted near the left boundary in order to estimate the boundary layer thicknesses of the solution.
//    In the Results toolbar, click Cut Line 2D.

    model.result().dataset().create("cln1", "CutLine2D");

//    In the Settings window for Cut Line 2D, locate the Line Data section.
//    In row Point 1, set y to 5[cm].

    model.result().dataset("cln1").setIndex("genpoints", "5[cm]", 0, 1);

//    In row Point 2, set x to 1[cm].

    model.result().dataset("cln1").setIndex("genpoints", "1[cm]", 1, 0);

//    , and <l>y</l> to <c>5[cm]</c>.

    model.result().dataset("cln1").setIndex("genpoints", "5[cm]", 1, 1);

//    Click Plot.
//    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 Temperature at Boundary Layer in the Label text field.

    model.result("pg5").label("Temperature at Boundary Layer");

//    Locate the Data section.
//    From the Dataset list, select Cut Line 2D 1.

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

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

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

//    In the Temperature at Boundary Layer toolbar, click Line Graph.

    model.result("pg5").create("lngr1", "LineGraph");
    model.result("pg5").feature("lngr1").set("markerpos", "datapoints");
    model.result("pg5").feature("lngr1").set("linewidth", "preference");
    model.result("pg5").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) > Heat Transfer in Fluids > Temperature > T - Temperature - K.

    model.result("pg5").feature("lngr1").set("expr", "T");
    model.result("pg5").feature("lngr1").set("descr", "Temperature");

//    In the Temperature at Boundary Layer toolbar, click Plot.

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

//    The thermal boundary layer is around 3 mm.
//    In the Results toolbar, click 1D Plot Group.

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

//    In the Settings window for 1D Plot Group, type Velocity at Boundary Layer in the Label text field.

    model.result("pg6").label("Velocity at Boundary Layer");

//    Locate the Data section.
//    From the Dataset list, select Cut Line 2D 1.

    model.result("pg6").set("data", "cln1");

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

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

//    In the Velocity at Boundary Layer toolbar, click Line Graph.

    model.result("pg6").create("lngr1", "LineGraph");
    model.result("pg6").feature("lngr1").set("markerpos", "datapoints");
    model.result("pg6").feature("lngr1").set("linewidth", "preference");
    model.result("pg6").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) > Laminar Flow > Velocity and pressure > spf.U - Velocity magnitude - m/s.

    model.result("pg6").feature("lngr1").set("expr", "spf.U");
    model.result("pg6").feature("lngr1").set("descr", "Velocity magnitude");

//    In the Velocity at Boundary Layer toolbar, click Plot.

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

//    The momentum boundary layer is around 1 mm and the outer layer between 5 mm and 10 mm.
//    Now create the 3D version of the model.
//    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 Home toolbar, click Add Physics to open the Add Physics window.
//    In the tree, select Fluid Flow > Nonisothermal Flow > Laminar Flow.
//    Find the Physics interfaces in study subsection.
//    In the table, enter the following settings:
//    Click Add to Component 2 in the window toolbar.

    model.component("comp2").physics().create("spf2", "LaminarFlow", "geom2");

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

    model.component("comp2").physics("spf2").prop("AdvancedSettingProperty").set("UsePseudoTime", "1");
    model.component("comp2").physics("spf2").prop("PhysicalModelProperty")
         .set("Compressibility", "WeaklyCompressible");
    model.component("comp2").physics().create("ht2", "HeatTransferInFluids", "geom2");

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

    model.component("comp2").physics("ht2").prop("ShapeProperty").set("order_temperature", "1");

    model.component("comp2").multiphysics().create("nitf2", "NonIsothermalFlow", 3);

    model.study("std1").feature("stat").setSolveFor("/multiphysics/nitf2", false);

    model.component("comp2").multiphysics("nitf2").set("Fluid_physics", "spf2");
    model.component("comp2").multiphysics("nitf2").set("Heat_physics", "ht2");

    model.component("comp2").geom("geom2").run();

//    In the Home toolbar, click Add Physics to close the Add Physics window.
//    In the Home toolbar, click Add Study to open the Add Study window.
//    Find the Studies subsection.
//    In the Select Study tree, select General Studies > Stationary.
//    Find the Physics interfaces in study subsection.
//    In the table, enter the following settings:
//    Find the Multiphysics couplings in study subsection.
//    In the table, enter the following settings:
//    Click Add Study in the window toolbar.

    model.study().create("std2");
    model.study("std2").create("stat", "Stationary");
    model.study("std2").feature("stat").setSolveFor("/physics/spf", false);
    model.study("std2").feature("stat").setSolveFor("/physics/ht", false);
    model.study("std2").feature("stat").setSolveFor("/multiphysics/nitf1", false);

//    In the Home toolbar, click Add Study to close the Add Study window.
//    In the Geometry toolbar, click Block.

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

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

    model.component("comp2").geom("geom2").feature("blk1").set("size", new String[]{"L", "1", "1"});

//    In the Depth text field, type L/2.

    model.component("comp2").geom("geom2").feature("blk1").set("size", new String[]{"L", "L/2", "1"});

//    In the Height text field, type L.

    model.component("comp2").geom("geom2").feature("blk1").set("size", new String[]{"L", "L/2", "L"});

//    In the Geometry toolbar, click Build All.

    model.component("comp2").geom("geom2").run("fin");

//    In the Materials toolbar, click Add Material to open the Add Material window.
//    In the tree, select Built-in > Water, liquid.
//    Click Add to Component in the window toolbar.

    model.component("comp2").material().create("mat2", "Common");
    model.component("comp2").material("mat2").propertyGroup("def").func().create("eta", "Piecewise");
    model.component("comp2").material("mat2").propertyGroup("def").func().create("Cp", "Piecewise");
    model.component("comp2").material("mat2").propertyGroup("def").func().create("rho", "Piecewise");
    model.component("comp2").material("mat2").propertyGroup("def").func().create("k", "Piecewise");
    model.component("comp2").material("mat2").propertyGroup("def").func().create("cs", "Interpolation");
    model.component("comp2").material("mat2").propertyGroup("def").func().create("an1", "Analytic");
    model.component("comp2").material("mat2").propertyGroup("def").func().create("an2", "Analytic");
    model.component("comp2").material("mat2").propertyGroup("def").func().create("an3", "Analytic");
    model.component("comp2").material("mat2").label("Water, liquid");
    model.component("comp2").material("mat2").set("family", "water");
    model.component("comp2").material("mat2").propertyGroup("def").func("eta").set("arg", "T");
    model.component("comp2").material("mat2").propertyGroup("def").func("eta")
         .set("pieces", new String[][]{{"273.15", "413.15", "1.3799566804-0.021224019151*T^1+1.3604562827E-4*T^2-4.6454090319E-7*T^3+8.9042735735E-10*T^4-9.0790692686E-13*T^5+3.8457331488E-16*T^6"}, {"413.15", "553.75", "0.00401235783-2.10746715E-5*T^1+3.85772275E-8*T^2-2.39730284E-11*T^3"}});
    model.component("comp2").material("mat2").propertyGroup("def").func("eta").set("argunit", "K");
    model.component("comp2").material("mat2").propertyGroup("def").func("eta").set("fununit", "Pa*s");
    model.component("comp2").material("mat2").propertyGroup("def").func("Cp").set("arg", "T");
    model.component("comp2").material("mat2").propertyGroup("def").func("Cp")
         .set("pieces", new String[][]{{"273.15", "553.75", "12010.1471-80.4072879*T^1+0.309866854*T^2-5.38186884E-4*T^3+3.62536437E-7*T^4"}});
    model.component("comp2").material("mat2").propertyGroup("def").func("Cp").set("argunit", "K");
    model.component("comp2").material("mat2").propertyGroup("def").func("Cp").set("fununit", "J/(kg*K)");
    model.component("comp2").material("mat2").propertyGroup("def").func("rho").set("arg", "T");

    return model;
  }

  public static Model run2(Model model) {
    model.component("comp2").material("mat2").propertyGroup("def").func("rho").set("smooth", "contd1");
    model.component("comp2").material("mat2").propertyGroup("def").func("rho")
         .set("pieces", new String[][]{{"273.15", "293.15", "0.000063092789034*T^3-0.060367639882855*T^2+18.9229382407066*T-950.704055329848"}, {"293.15", "373.15", "0.000010335053319*T^3-0.013395065634452*T^2+4.969288832655160*T+432.257114008512"}});
    model.component("comp2").material("mat2").propertyGroup("def").func("rho").set("argunit", "K");
    model.component("comp2").material("mat2").propertyGroup("def").func("rho").set("fununit", "kg/m^3");
    model.component("comp2").material("mat2").propertyGroup("def").func("k").set("arg", "T");
    model.component("comp2").material("mat2").propertyGroup("def").func("k")
         .set("pieces", new String[][]{{"273.15", "553.75", "-0.869083936+0.00894880345*T^1-1.58366345E-5*T^2+7.97543259E-9*T^3"}});
    model.component("comp2").material("mat2").propertyGroup("def").func("k").set("argunit", "K");
    model.component("comp2").material("mat2").propertyGroup("def").func("k").set("fununit", "W/(m*K)");
    model.component("comp2").material("mat2").propertyGroup("def").func("cs")
         .set("table", new String[][]{{"273", "1403"}, 
         {"278", "1427"}, 
         {"283", "1447"}, 
         {"293", "1481"}, 
         {"303", "1507"}, 
         {"313", "1526"}, 
         {"323", "1541"}, 
         {"333", "1552"}, 
         {"343", "1555"}, 
         {"353", "1555"}, 
         {"363", "1550"}, 
         {"373", "1543"}});
    model.component("comp2").material("mat2").propertyGroup("def").func("cs").set("interp", "piecewisecubic");
    model.component("comp2").material("mat2").propertyGroup("def").func("cs").set("fununit", new String[]{"m/s"});
    model.component("comp2").material("mat2").propertyGroup("def").func("cs").set("argunit", new String[]{"K"});
    model.component("comp2").material("mat2").propertyGroup("def").func("an1").set("funcname", "alpha_p");
    model.component("comp2").material("mat2").propertyGroup("def").func("an1").set("expr", "-1/rho(T)*d(rho(T),T)");
    model.component("comp2").material("mat2").propertyGroup("def").func("an1").set("args", new String[]{"T"});
    model.component("comp2").material("mat2").propertyGroup("def").func("an1").set("fununit", "1/K");
    model.component("comp2").material("mat2").propertyGroup("def").func("an1").set("argunit", new String[]{"K"});
    model.component("comp2").material("mat2").propertyGroup("def").func("an1")
         .set("plotfixedvalue", new String[]{"273.15"});
    model.component("comp2").material("mat2").propertyGroup("def").func("an1")
         .set("plotargs", new String[][]{{"T", "273.15", "373.15"}});
    model.component("comp2").material("mat2").propertyGroup("def").func("an2").set("funcname", "gamma_w");
    model.component("comp2").material("mat2").propertyGroup("def").func("an2")
         .set("expr", "1+(T/Cp(T))*(alpha_p(T)*cs(T))^2");
    model.component("comp2").material("mat2").propertyGroup("def").func("an2").set("args", new String[]{"T"});
    model.component("comp2").material("mat2").propertyGroup("def").func("an2").set("fununit", "1");
    model.component("comp2").material("mat2").propertyGroup("def").func("an2").set("argunit", new String[]{"K"});
    model.component("comp2").material("mat2").propertyGroup("def").func("an2")
         .set("plotfixedvalue", new String[]{"273.15"});
    model.component("comp2").material("mat2").propertyGroup("def").func("an2")
         .set("plotargs", new String[][]{{"T", "273.15", "373.15"}});
    model.component("comp2").material("mat2").propertyGroup("def").func("an3").set("funcname", "muB");
    model.component("comp2").material("mat2").propertyGroup("def").func("an3").set("expr", "2.79*eta(T)");
    model.component("comp2").material("mat2").propertyGroup("def").func("an3").set("args", new String[]{"T"});
    model.component("comp2").material("mat2").propertyGroup("def").func("an3").set("fununit", "Pa*s");
    model.component("comp2").material("mat2").propertyGroup("def").func("an3").set("argunit", new String[]{"K"});
    model.component("comp2").material("mat2").propertyGroup("def").func("an3")
         .set("plotfixedvalue", new String[]{"273.15"});
    model.component("comp2").material("mat2").propertyGroup("def").func("an3")
         .set("plotargs", new String[][]{{"T", "273.15", "553.75"}});
    model.component("comp2").material("mat2").propertyGroup("def").set("thermalexpansioncoefficient", "");
    model.component("comp2").material("mat2").propertyGroup("def").set("bulkviscosity", "");
    model.component("comp2").material("mat2").propertyGroup("def")
         .set("thermalexpansioncoefficient", new String[]{"alpha_p(T)", "0", "0", "0", "alpha_p(T)", "0", "0", "0", "alpha_p(T)"});
    model.component("comp2").material("mat2").propertyGroup("def").set("bulkviscosity", "muB(T)");
    model.component("comp2").material("mat2").propertyGroup("def").set("dynamicviscosity", "eta(T)");
    model.component("comp2").material("mat2").propertyGroup("def").set("ratioofspecificheat", "gamma_w(T)");
    model.component("comp2").material("mat2").propertyGroup("def")
         .set("electricconductivity", new String[]{"5.5e-6[S/m]", "0", "0", "0", "5.5e-6[S/m]", "0", "0", "0", "5.5e-6[S/m]"});
    model.component("comp2").material("mat2").propertyGroup("def").set("heatcapacity", "Cp(T)");
    model.component("comp2").material("mat2").propertyGroup("def").set("density", "rho(T)");
    model.component("comp2").material("mat2").propertyGroup("def")
         .set("thermalconductivity", new String[]{"k(T)", "0", "0", "0", "k(T)", "0", "0", "0", "k(T)"});
    model.component("comp2").material("mat2").propertyGroup("def").set("soundspeed", "cs(T)");
    model.component("comp2").material("mat2").propertyGroup("def").addInput("temperature");

//    In the Materials toolbar, click Add Material to close the Add Material window.
//    In order to ensure mass conservation, as the volume is constant, the water density cannot depend only on the temperature. It has to be either constant or pressure and temperature dependent. Select the <l>Incompressible flow</l> option to define a constant density evaluated from the material properties at the reference pressure and temperature.
//    In the Settings window for Laminar Flow, locate the Physical Model section.
//    From the Compressibility list, select Incompressible flow.

    model.component("comp2").physics("spf2").prop("PhysicalModelProperty").set("Compressibility", "Incompressible");

//    Select the Include gravity checkbox.

    model.component("comp2").physics("spf2").prop("PhysicalModelProperty").set("IncludeGravity", true);

//    In the Physics toolbar, click Points and choose Pressure Point Constraint.

    model.component("comp2").physics("spf2").create("prpc1", "PressurePointConstraint", 0);

//    Select Point 4.

    model.component("comp2").physics("spf2").feature("prpc1").selection().set(4);

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

    model.component("comp2").physics("spf2").create("sym1", "Symmetry", 2);

//    Select Boundary 2.

    model.component("comp2").physics("spf2").feature("sym1").selection().set(2);

//    In the Model Builder window, under Component 2 (comp2), click Heat Transfer in Fluids 2 (ht2).
//    In the Settings window for Heat Transfer in Fluids, locate the Physical Model section.
//    In the \[T_\textrm{ref}\] text field, type (Tc+Th)/2.

    model.component("comp2").physics("ht2").prop("PhysicalModelProperty").set("Tref", "(Tc+Th)/2");

//    In the Model Builder window, under Component 2 (comp2) > Heat Transfer in Fluids 2 (ht2), click Initial Values 1.
//    In the Settings window for Initial Values, locate the Initial Values section.
//    In the \[T2\] text field, type (Tc+Th)/2.

    model.component("comp2").physics("ht2").feature("init1").set("Tinit", "(Tc+Th)/2");

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

    model.component("comp2").physics("ht2").create("temp1", "TemperatureBoundary", 2);

//    Select Boundary 1.

    model.component("comp2").physics("ht2").feature("temp1").selection().set(1);

//    In the Settings window for Temperature, locate the Temperature section.
//    In the \[T_{\textrm{0}}\] text field, type Tc.

    model.component("comp2").physics("ht2").feature("temp1").set("T0", "Tc");

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

    model.component("comp2").physics("ht2").create("temp2", "TemperatureBoundary", 2);

//    Select Boundary 6.

    model.component("comp2").physics("ht2").feature("temp2").selection().set(6);

//    In the Settings window for Temperature, locate the Temperature section.
//    In the \[T_{\textrm{0}}\] text field, type Th.

    model.component("comp2").physics("ht2").feature("temp2").set("T0", "Th");

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

    model.component("comp2").physics("ht2").create("sym1", "Symmetry", 2);

//    Select Boundary 2.

    model.component("comp2").physics("ht2").feature("sym1").selection().set(2);

//    In the Model Builder window, under Component 2 (comp2), click Laminar Flow 2 (spf2).
//    In the Settings window for Laminar Flow, click to expand the Advanced Settings section.
//    Find the Pseudo time stepping subsection.
//    From the Use pseudo time stepping for stationary equation form list, select Off.

    model.component("comp2").physics("spf2").prop("AdvancedSettingProperty").set("PseudoTimeSetting", "Off");

//    In the Model Builder window, under Component 2 (comp2) > Multiphysics, click Nonisothermal Flow 2 (nitf2).
//    In the Settings window for Nonisothermal Flow, locate the Material Properties section.
//    Select the Boussinesq approximation checkbox.

    model.component("comp2").multiphysics("nitf2").set("BoussinesqApproximation", true);

//    To obtain reliable results within in a reasonable computing time, create a structured mesh by following the steps below.
//    In the Mesh toolbar, click More Generators and choose Mapped.

    model.component("comp2").mesh("mesh2").create("map1", "Map");

//    Select Boundary 2.

    model.component("comp2").mesh("mesh2").feature("map1").selection().set(2);

//    Right-click Mapped 1 and choose Distribution.

    model.component("comp2").mesh("mesh2").feature("map1").create("dis1", "Distribution");

//    Select Edges 1, 3, 5, 9.

    model.component("comp2").mesh("mesh2").feature("map1").feature("dis1").selection().set(1, 3, 5, 9);

//    In the Settings window for Distribution, locate the Distribution section.
//    From the Distribution type list, select Predefined.

    model.component("comp2").mesh("mesh2").feature("map1").feature("dis1").set("type", "predefined");

//    In the Number of elements text field, type 16.

    model.component("comp2").mesh("mesh2").feature("map1").feature("dis1").set("elemcount", 16);

//    In the Element ratio text field, type 3.

    model.component("comp2").mesh("mesh2").feature("map1").feature("dis1").set("elemratio", 3);

//    Select the Symmetric distribution checkbox.

    model.component("comp2").mesh("mesh2").feature("map1").feature("dis1").set("symmetric", true);

//    Click Build Selected.

    model.component("comp2").mesh("mesh2").run("map1");

//    The front face mesh has smaller elements near the edges because large variations in velocity and temperature are expected there.
//    Now extend the front mesh to the remaining structure.
//    In the Mesh toolbar, click Swept.

    model.component("comp2").mesh("mesh2").create("swe1", "Sweep");

//    Right-click Swept 1 and choose Distribution.

    model.component("comp2").mesh("mesh2").feature("swe1").create("dis1", "Distribution");

//    In the Settings window for Distribution, locate the Distribution section.
//    From the Distribution type list, select Predefined.

    model.component("comp2").mesh("mesh2").feature("swe1").feature("dis1").set("type", "predefined");

//    In the Number of elements text field, type 8.

    model.component("comp2").mesh("mesh2").feature("swe1").feature("dis1").set("elemcount", 8);

//    In the Element ratio text field, type 3.

    model.component("comp2").mesh("mesh2").feature("swe1").feature("dis1").set("elemratio", 3);

//    Select the Reverse direction checkbox.

    model.component("comp2").mesh("mesh2").feature("swe1").feature("dis1").set("reverse", true);

//    To resolve the boundary layers, use a <l>Boundary Layers</l> feature to generate smaller mesh elements near the walls. The thermal boundary layer for the temperature difference of 10 K is approximately 1 mm (see the parameter <c>eps_t</c> defined previously). Use this value to define the thickness of the boundary layers.
//    In the Mesh toolbar, click Boundary Layers.

    model.component("comp2").mesh("mesh2").create("bl1", "BndLayer");
    model.component("comp2").mesh("mesh2").feature("bl1").create("blp", "BndLayerProp");
    model.component("comp2").mesh("mesh2").feature("bl1").selection().geom(3);
    model.component("comp2").mesh("mesh2").feature("bl1").selection().set();
    model.component("comp2").mesh("mesh2").feature("bl1").selection().allGeom();

//    In the Model Builder window, click Boundary Layer Properties.
//    Select Boundaries 1, 3, 4, 5, 6.

    model.component("comp2").mesh("mesh2").feature("bl1").feature("blp").selection().set(1, 3, 4, 5, 6);

//    In the Settings window for Boundary Layer Properties, locate the Layers section.
//    In the Number of layers text field, type 5.

    model.component("comp2").mesh("mesh2").feature("bl1").feature("blp").set("blnlayers", 5);

//    From the Thickness specification list, select First layer.

    model.component("comp2").mesh("mesh2").feature("bl1").feature("blp").set("inittype", "blhmin");

//    In the Thickness text field, type 1[mm]/5.

    model.component("comp2").mesh("mesh2").feature("bl1").feature("blp").set("blhmin", "1[mm]/5");

//    Click Build All.

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

//    Finer mesh is needed for accurate results with higher Rayleigh numbers.
//    In the Mesh toolbar, click Add Mesh and choose Add Mesh.

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

//    In the Mesh toolbar, click Modify and choose Reference.

    model.component("comp2").mesh("mesh3").create("rf1", "Reference");

//    In the Settings window for Reference, locate the Reference section.
//    From the Mesh list, select Mesh 2.

    model.component("comp2").mesh("mesh3").feature("rf1").set("sequence", "mesh2");

//    In the Mesh toolbar, click Modify and choose Refine.

    model.component("comp2").mesh("mesh3").create("ref1", "Refine");

//    In the Settings window for Refine, locate the Refine Options section.
//    From the Refinement method list, select Regular refinement.

    model.component("comp2").mesh("mesh3").feature("ref1").set("rmethod", "regular");

//    Click Build All.

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

//    First step solves for the smallest Rayleigh numbers using the first mesh.
//    In the Model Builder window, under Study 2, click Step 1: Stationary.
//    In the Settings window for Stationary, locate the Study Extensions section.
//    Select the Auxiliary sweep checkbox.

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

//    Click Add.

    model.study("std2").feature("stat").setIndex("pname", "L", 0);
    model.study("std2").feature("stat").setIndex("plistarr", "", 0);
    model.study("std2").feature("stat").setIndex("punit", "m", 0);
    model.study("std2").feature("stat").setIndex("pname", "L", 0);
    model.study("std2").feature("stat").setIndex("plistarr", "", 0);
    model.study("std2").feature("stat").setIndex("punit", "m", 0);

//    In the table, enter the following settings:

    model.study("std2").feature("stat").setIndex("pname", "DeltaT", 0);
    model.study("std2").feature("stat").setIndex("plistarr", "1e-3 1e-2 1e-1", 0);
    model.study("std2").feature("stat").setIndex("punit", "K", 0);

//    Right-click Study 2 > Step 1: Stationary and choose Duplicate.

    model.study("std2").feature().duplicate("stat1", "stat");

//    Second step solves for the largest Rayleigh numbers using the finest mesh.
//    In the Settings window for Stationary, locate the Study Extensions section.
//    In the table, enter the following settings:

    model.study("std2").feature("stat1").setIndex("plistarr", "1 10", 0);
    model.study("std2").feature("stat1").setIndex("punit", "K", 0);

//    Click to expand the Mesh Selection section.
//    In the table, enter the following settings:

    model.study("std2").feature("stat1").setEntry("mesh", "geom2", "mesh3");

//    Click to expand the Values of Dependent Variables section.
//    Find the Initial values of variables solved for subsection.
//    From the Settings list, select User controlled.

    model.study("std2").feature("stat1").set("useinitsol", true);

//    From the Method list, select Solution.

    model.study("std2").feature("stat1").set("initmethod", "sol");

//    From the Study list, select Study 2, Stationary.

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

//    From the Selection list, select Last.

    model.study("std2").feature("stat1").set("solnum", "last");

//    Add a <l>Combine Solutions</l> study step that concatenates the two solutions and makes it possible to treat the output as a single parametric study.
//    In the Study toolbar, click More Study Extensions and choose Combine Solutions.

    model.study("std2").create("cmbsol", "CombineSolution");

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

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

//    The first solution governs the mesh used to discretize the combined solution. The finest mesh is chosen to minimize interpolation error.
//    In the Model Builder window, under Study 2, click Step 3: Combine Solutions.
//    In the Settings window for Combine Solutions, locate the Combine Solutions Settings section.
//    From the First solution list, select Study 2/Solution Store 2 (sol4).

    model.study("std2").feature("cmbsol").set("cssol1", "sol4");

//    From the Second solution list, select Study 2/Solution Store 1 (sol3).

    model.study("std2").feature("cmbsol").set("cssol2", "sol3");

//    In the Model Builder window, expand the Solution 2 (sol2) node.
//    In the Model Builder window, expand the Study 2 > Solver Configurations > Solution 2 (sol2) > Stationary Solver 1 node, then click Fully Coupled 1.
//    In the Settings window for Fully Coupled, click to expand the Method and Termination section.
//    From the Nonlinear method list, select Constant (Newton).

    model.sol("sol2").feature("s1").feature("fc1").set("dtech", "const");

//    In the Model Builder window, expand the Study 2 > Solver Configurations > Solution 2 (sol2) > Stationary Solver 2 node, then click Fully Coupled 1.
//    In the Settings window for Fully Coupled, locate the Method and Termination section.
//    From the Nonlinear method list, select Constant (Newton).

    model.sol("sol2").feature("s2").feature("fc1").set("dtech", "const");

//    In the Damping factor text field, type 0.8.

    model.sol("sol2").feature("s2").feature("fc1").set("damp", "0.8");

//    While the default solver solves the problem without any issue, GMG is faster for this model.
//    In the Model Builder window, expand the Study 2 > Solver Configurations > Solution 2 (sol2) > Stationary Solver 2 > AMG, nonisothermal flow (nitf2) node, then click Multigrid 1.
//    In the Settings window for Multigrid, locate the General section.
//    From the Solver list, select Geometric multigrid.

    model.sol("sol2").feature("s2").feature("i1").feature("mg1").set("prefun", "gmg");

//    In the Study toolbar, click Compute.

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

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

    model.result().dataset("dset3").set("geom", "geom2");
    model.result().create("pg7", "PlotGroup3D");
    model.result("pg7").label("Velocity (spf2)");
    model.result("pg7").set("frametype", "spatial");
    model.result("pg7").set("smooth", "internal");
    model.result("pg7").feature().create("mslc1", "Multislice");
    model.result("pg7").feature("mslc1").set("smooth", "internal");
    model.result("pg7").feature("mslc1").set("data", "parent");
    model.result().create("pg8", "PlotGroup3D");
    model.result("pg8").label("Pressure (spf2)");
    model.result("pg8").set("frametype", "spatial");
    model.result("pg8").set("smooth", "internal");
    model.result("pg8").feature().create("surf1", "Surface");
    model.result("pg8").feature("surf1").label("Surface");
    model.result("pg8").feature("surf1").set("expr", "p2");
    model.result("pg8").feature("surf1").set("colortable", "Tectocoris");
    model.result("pg8").feature("surf1").set("colortabletype", "discrete");
    model.result("pg8").feature("surf1").set("bandcount", 25);
    model.result("pg8").feature("surf1").set("smooth", "internal");
    model.result("pg8").feature("surf1").set("data", "parent");
    model.result("pg8").feature("surf1").feature().create("sel1", "Selection");
    model.result("pg8").feature("surf1").feature("sel1").selection().geom("geom2", 2);
    model.result("pg8").feature("surf1").feature("sel1").selection().set(1, 3, 4, 5, 6);
    model.result().create("pg9", "PlotGroup3D");
    model.result("pg9").label("Temperature (ht2)");
    model.result("pg9").set("smooth", "internal");
    model.result("pg9").feature().create("vol1", "Volume");
    model.result("pg9").feature("vol1").set("solutionparams", "parent");
    model.result("pg9").feature("vol1").set("expr", "T2");
    model.result("pg9").feature("vol1").set("colortable", "HeatCameraLight");
    model.result("pg9").feature("vol1").set("smooth", "internal");
    model.result("pg9").feature("vol1").set("data", "parent");
    model.result().create("pg10", "PlotGroup3D");
    model.result("pg10").label("Temperature and Fluid Flow (nitf2)");
    model.result("pg10").set("showlegendsunit", true);
    model.result("pg10").set("smooth", "internal");
    model.result("pg10").feature().create("surf1", "Surface");
    model.result("pg10").feature("surf1").label("Wall Temperature");
    model.result("pg10").feature("surf1").set("solutionparams", "parent");
    model.result("pg10").feature("surf1").set("expr", "ht2.Tvar");
    model.result("pg10").feature("surf1").set("colortable", "HeatCameraLight");
    model.result("pg10").feature("surf1").set("smooth", "internal");
    model.result("pg10").feature("surf1").set("data", "parent");
    model.result("pg10").feature("surf1").feature().create("sel1", "Selection");
    model.result("pg10").feature("surf1").feature("sel1").selection().geom("geom2", 2);
    model.result("pg10").feature("surf1").feature("sel1").selection().set(1, 3, 4, 5, 6);
    model.result("pg10").feature().create("arwv1", "ArrowVolume");
    model.result("pg10").feature("arwv1").label("Fluid Flow");
    model.result("pg10").feature("arwv1").set("solutionparams", "parent");
    model.result("pg10").feature("arwv1").set("expr", new String[]{"nitf2.ux", "nitf2.uy", "nitf2.uz"});
    model.result("pg10").feature("arwv1").set("xnumber", 30);
    model.result("pg10").feature("arwv1").set("ynumber", 30);
    model.result("pg10").feature("arwv1").set("znumber", 30);
    model.result("pg10").feature("arwv1").set("arrowtype", "cone");
    model.result("pg10").feature("arwv1").set("arrowlength", "logarithmic");
    model.result("pg10").feature("arwv1").set("data", "parent");
    model.result("pg10").feature("arwv1").feature().create("col1", "Color");
    model.result("pg10").feature("arwv1").feature().create("filt1", "Filter");
    model.result("pg10").feature("arwv1").feature("filt1").set("expr", "spf2.U>nitf2.Uave");
    model.result("pg7").run();

//    This default plot group shows the fluid velocity magnitude in only half of the cube. To plot the other half, proceed as follows.
//    In the Results toolbar, click More Datasets and choose Mirror 3D.

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

//    In the Settings window for Mirror 3D, locate the Plane Data section.
//    From the Plane list, select zx-planes.

    model.result().dataset("mir1").set("quickplane", "zx");

//    A new dataset containing mirror values is now created. Return to the velocity plot to use this dataset.

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

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

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

//    In the Velocity (spf2) toolbar, click Plot.

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

//    This default plot group shows the temperature distribution. The mirror dataset created previously can be reused here to plot the entire cube.
//    In the Model Builder window, click Temperature (ht2).
//    In the Settings window for 3D Plot Group, locate the Data section.
//    From the Dataset list, select Mirror 3D 1.

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

//    In the Temperature (ht2) toolbar, click Plot.

    model.result("pg9").run();
    model.result("pg10").run();

//    In the Model Builder window, expand the Results > Temperature and Fluid Flow (nitf2) node, then click Temperature and Fluid Flow (nitf2).
//    In the Settings window for 3D Plot Group, locate the Data section.
//    From the Dataset list, select Mirror 3D 1.

    model.result("pg10").set("data", "mir1");
    model.result("pg10").run();

//    In the Model Builder window, right-click Wall Temperature and choose Transparency.

    model.result("pg10").feature("surf1").create("tran1", "Transparency");
    model.result("pg10").run();
    model.result("pg10").run();

//    In the Settings window for Arrow Volume, locate the Arrow Positioning section.
//    Find the x grid points subsection.
//    In the Points text field, type 15.

    model.result("pg10").feature("arwv1").set("xnumber", 15);

//    Find the y grid points subsection.
//    In the Points text field, type 15.

    model.result("pg10").feature("arwv1").set("ynumber", 15);

//    Find the z grid points subsection.
//    In the Points text field, type 15.

    model.result("pg10").feature("arwv1").set("znumber", 15);

//    In the Temperature and Fluid Flow (nitf2) toolbar, click Plot.

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

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

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

//    In the Settings window for 3D Plot Group, type Velocity, Front Plane in the Label text field.

    model.result("pg11").label("Velocity, Front Plane");

//    Locate the Data section.
//    From the Dataset list, select Mirror 3D 1.

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

//    In the Velocity, Front Plane toolbar, click Slice.

    model.result("pg11").create("slc1", "Slice");
    model.result("pg11").feature("slc1").set("evaluationsettings", "parent");

//    In the Settings window for Slice, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 2 (comp2) > Laminar Flow 2 > Velocity and pressure > spf2.U - Velocity magnitude - m/s.

    model.result("pg11").feature("slc1").set("expr", "spf2.U");
    model.result("pg11").feature("slc1").set("descr", "Velocity magnitude");

//    Locate the Plane Data section.
//    From the Plane list, select zx-planes.

    model.result("pg11").feature("slc1").set("quickplane", "zx");

//    In the Velocity, Front Plane toolbar, click Plot.

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

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

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

//    In the Settings window for 3D Plot Group, type Temperature, 10 K Offset in the Label text field.

    model.result("pg12").label("Temperature, 10 K Offset");

//    Locate the Data section.
//    From the Dataset list, select Mirror 3D 1.

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

//    In the Temperature, 10 K Offset toolbar, click Slice.

    model.result("pg12").create("slc1", "Slice");
    model.result("pg12").feature("slc1").set("evaluationsettings", "parent");

//    In the Settings window for Slice, click Replace Expression in the upper-right corner of the Expression section.
//    From the menu, choose Component 2 (comp2) > Heat Transfer in Fluids 2 > Temperature > T2 - Temperature - K.

    model.result("pg12").feature("slc1").set("expr", "T2");
    model.result("pg12").feature("slc1").set("descr", "Temperature");

//    Locate the Plane Data section.
//    In the Planes text field, type 1.

    model.result("pg12").feature("slc1").set("quickxnumber", 1);

//    Locate the Coloring and Style section.
//    From the Color table list, select HeatCameraLight.

    model.result("pg12").feature("slc1").set("colortable", "HeatCameraLight");

//    In the Temperature, 10 K Offset toolbar, click Plot.

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

//    In the Model Builder window, click Temperature, 10 K Offset.
//    In the Temperature, 10 K Offset toolbar, click Arrow Volume.

    model.result("pg12").create("arwv1", "ArrowVolume");
    model.result("pg12").feature("arwv1").set("evaluationsettings", "parent");

//    In the Settings window for Arrow Volume, locate the Expression section.
//    In the x-component text field, type 0.

    model.result("pg12").feature("arwv1").set("expr", new String[]{"0", "v2", "w2"});

//    Locate the Arrow Positioning section.
//    Find the x grid points subsection.
//    In the Points text field, type 1.

    model.result("pg12").feature("arwv1").set("xnumber", 1);

//    Find the y grid points subsection.
//    In the Points text field, type 20.

    model.result("pg12").feature("arwv1").set("ynumber", 20);

//    Find the z grid points subsection.
//    In the Points text field, type 20.

    model.result("pg12").feature("arwv1").set("znumber", 20);

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

    model.result("pg12").feature("arwv1").set("color", "black");

//    In the Temperature, 10 K Offset toolbar, click Plot.

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

//    Right-click Temperature, 10 K Offset and choose Duplicate.

    model.result().duplicate("pg13", "pg12");
    model.result("pg13").run();

//    In the Settings window for 3D Plot Group, type Temperature, 1 K Offset in the Label text field.

    model.result("pg13").label("Temperature, 1 K Offset");

//    Locate the Data section.
//    From the Parameter value (DeltaT (K)) list, select 1.

    model.result("pg13").set("looplevel", new int[]{4});

//    In the Temperature, 1 K Offset toolbar, click Plot.

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

//    Right-click Temperature, 1 K Offset and choose Duplicate.

    model.result().duplicate("pg14", "pg13");
    model.result("pg14").run();

//    In the Settings window for 3D Plot Group, type Temperature, 0.1 K Offset in the Label text field.

    model.result("pg14").label("Temperature, 0.1 K Offset");

//    Locate the Data section.
//    From the Parameter value (DeltaT (K)) list, select 0.1.

    model.result("pg14").set("looplevel", new int[]{3});

//    In the Temperature, 0.1 K Offset toolbar, click Plot.

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

    model.title("Buoyancy Flow in Water");

    model
         .description("This example studies the stationary state of free convection in a cavity filled with water and bounded by two vertical plates. To generate the buoyancy flow, the plates are heated at different temperatures, bringing the regime close to the transition between laminar and turbulent.");

    return model;
  }

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

}
