/*
 * heat_convection_2d.java
 */

import com.comsol.model.*;
import com.comsol.model.util.*;

/** Model exported on May 15 2026, 13:23 by COMSOL 6.4.0.421. */
public class heat_convection_2d {

  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 Heat Transfer > Heat Transfer in Solids (ht).
//    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("ht", "HeatTransfer", "geom1");

    model.study().create("std1");
    model.study("std1").create("stat", "Stationary");

//    In the Geometry toolbar, click Rectangle.

    model.component("comp1").geom("geom1").create("r1", "Rectangle");

//    In the Settings window for Rectangle, locate the Size and Shape section.
//    In the Width text field, type 0.6.

    model.component("comp1").geom("geom1").feature("r1").set("size", new double[]{0.6, 1});

//    Click Build All Objects.

    model.component("comp1").geom("geom1").runPre("fin");
    model.component("comp1").geom("geom1").run();

//    In the Physics toolbar, click Boundaries and choose Temperature.

    model.component("comp1").physics("ht").create("temp1", "TemperatureBoundary", 1);

//    Select Boundary 2.

    model.component("comp1").physics("ht").feature("temp1").selection().set(2);

//    In the Settings window for Temperature, locate the Temperature section.
//    In the \[T_{\textrm{0}}\] text field, type 100[degC].

    model.component("comp1").physics("ht").feature("temp1").set("T0", "100[degC]");

//    In the Physics toolbar, click Boundaries and choose Heat Flux.

    model.component("comp1").physics("ht").create("hf1", "HeatFluxBoundary", 1);

//    Select Boundaries 3, 4.

    model.component("comp1").physics("ht").feature("hf1").selection().set(3, 4);

//    In the Settings window for Heat Flux, locate the Heat Flux section.
//    From the Flux type list, select Convective heat flux.

    model.component("comp1").physics("ht").feature("hf1").set("HeatFluxType", "ConvectiveHeatFlux");

//    In the \[h\] text field, type 750.

    model.component("comp1").physics("ht").feature("hf1").set("h", 750);

//    In the \[T_{\textrm{ext}}\] text field, type 0[degC].

    model.component("comp1").physics("ht").feature("hf1").set("Text", "0[degC]");

//    In the Model Builder window, click Solid 1.
//    In the Settings window for Solid, locate the Heat Conduction, Solid section.
//    From the \[k\] list, select User defined.

    model.component("comp1").physics("ht").feature("solid1").set("k_mat", "userdef");

//    In the associated text field, type 52.

    model.component("comp1").physics("ht").feature("solid1").set("k", new int[]{52, 0, 0, 0, 52, 0, 0, 0, 52});

//    No other material properties enter into the domain equations for this stationary model.
//    In the Mesh toolbar, click Mapped.

    model.component("comp1").mesh("mesh1").create("map1", "Map");

//    In the Settings window for Mapped, click Build All.

    model.component("comp1").mesh("mesh1").run();

//    In the Study toolbar, click Compute.

    model.study("std1").createAutoSequences("all");

    model.sol("sol1").runAll();

    model.result().create("pg1", "PlotGroup2D");
    model.result("pg1").label("Temperature (ht)");
    model.result("pg1").set("smooth", "internal");
    model.result("pg1").feature().create("surf1", "Surface");
    model.result("pg1").feature("surf1").set("solutionparams", "parent");
    model.result("pg1").feature("surf1").set("colortable", "HeatCameraLight");
    model.result("pg1").feature("surf1").set("data", "parent");
    model.result("pg1").run();

//    Change the unit of the temperature results to degrees Celsius.
//    In the Results toolbar, click Configurations and choose Preferred Units.

    model.result().configuration().create("prfu1", "PreferredUnits");

//    In the Settings window for Preferred Units, locate the Units section.
//    Click Add Physical Quantity.
//    In the Physical Quantity dialog, select General > Temperature (K) in the tree.
//    Click OK.

    model.result().configuration("prfu1")
         .setIndex("quantityunits", new String[]{"temperature", "Temperature", "K", "K"}, 0);

//    In the Settings window for Preferred Units, locate the Units section.
//    In the table, enter the following settings:

    model.result().configuration("prfu1").setIndex("quantityunits", "\u00b0C", 0, 3);

//    Click Apply.

    model.result().configuration("prfu1").apply();
    model.result("pg1").run();

//    The benchmark value for the temperature at <eqv>x</eqv> = <eqc>0.6</eqc> m and <eqv>y</eqv> = <eqc>0.2</eqc> m is <eqc>18.25</eqc>°C. To compare this value with that from the simulation, evaluate the temperature in this position.
//    In the Results toolbar, click Cut Point 2D.

    model.result().dataset().create("cpt1", "CutPoint2D");

//    In the Settings window for Cut Point 2D, locate the Point Data section.
//    In the X text field, type 0.6.

    model.result().dataset("cpt1").set("pointx", 0.6);

//    In the Y text field, type 0.2.

    model.result().dataset("cpt1").set("pointy", 0.2);

//    In the Results toolbar, click Point Evaluation.

    model.result().numerical().create("pev1", "EvalPoint");

//    In the Settings window for Point Evaluation, locate the Data section.
//    From the Dataset list, select Cut Point 2D 1.

    model.result().numerical("pev1").set("data", "cpt1");

//    Click Evaluate.

    model.result().table().create("tbl1", "Table");
    model.result().table("tbl1").comments("Point Evaluation 1");
    model.result().numerical("pev1").set("table", "tbl1");
    model.result().numerical("pev1").setResult();

//    The result should be close to <eqc>18.265</eqc>°C.

    model.result("pg1").run();

    model.title("Steady-State 2D Heat Transfer with Conduction");

    model
         .description("This is a benchmark problem for a 2D steady-state thermal analysis with convection to 0\u00b0C on two boundaries. The temperature field from the analysis is compared with a NAFEMS benchmark solution.");

    return model;
  }

  public static void main(String[] args) {
    run();
  }

}
