/*
 * thermally_loaded_beam.java
 */

import com.comsol.model.*;
import com.comsol.model.util.*;

/** Model exported on May 15 2026, 09:32 by COMSOL 6.4.0.421. */
public class thermally_loaded_beam {

  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 3D.
//    In the Select Physics tree, select Structural Mechanics > Beam (beam).
//    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", 3);
    model.component("comp1").geom("geom1").geomRep("comsol");

    model.component("comp1").mesh().create("mesh1");
    model.component("comp1").mesh("mesh1").contribute("geom/detail", true);

    model.component("comp1").physics().create("beam", "HermitianBeam", "geom1");

    model.study().create("std1");
    model.study("std1").create("stat", "Stationary");

//    In the Model Builder window, under Global Definitions, click Parameters 1.
//    In the Settings window for Parameters, locate the Parameters section.
//    In the table, enter the following settings:

    model.param().set("a", "0.04[m]");
    model.param().descr("a", "Side length");
    model.param().set("deltaT", "50[K]");
    model.param().descr("deltaT", "Temperature difference");
    model.param().set("Tg", "deltaT/a");
    model.param().descr("Tg", "Temperature gradient");
    model.param().set("Lb", "3[m]");
    model.param().descr("Lb", "Beam length");

//    In the Geometry toolbar, click More Primitives and choose Polygon.

    model.component("comp1").geom("geom1").create("pol1", "Polygon");
    model.component("comp1").geom("geom1").feature("pol1").set("source", "table");

//    In the Settings window for Polygon, locate the Coordinates section.
//    In the table, enter the following settings:

    model.component("comp1").geom("geom1").feature("pol1").setIndex("table", 0, 0, 0);
    model.component("comp1").geom("geom1").feature("pol1").setIndex("table", 0, 0, 1);
    model.component("comp1").geom("geom1").feature("pol1").setIndex("table", 0, 0, 2);
    model.component("comp1").geom("geom1").feature("pol1").setIndex("table", "Lb/2", 1, 0);
    model.component("comp1").geom("geom1").feature("pol1").setIndex("table", 0, 1, 1);
    model.component("comp1").geom("geom1").feature("pol1").setIndex("table", 0, 1, 2);
    model.component("comp1").geom("geom1").feature("pol1").setIndex("table", "Lb", 2, 0);
    model.component("comp1").geom("geom1").feature("pol1").setIndex("table", 0, 2, 1);
    model.component("comp1").geom("geom1").feature("pol1").setIndex("table", 0, 2, 2);
    model.component("comp1").geom("geom1").run();

//    In the Model Builder window, right-click Component 1 (comp1) > Materials and choose Blank Material.

    model.component("comp1").material().create("mat1", "Common");

//    In the Settings window for Material, click to expand the Material Properties section.
//    In the Material properties tree, select Basic Properties > Coefficient of Thermal Expansion.
//    Click Add to Material.

    model.component("comp1").material("mat1").propertyGroup("def").set("thermalexpansioncoefficient", "");

//    Locate the Material Contents section.
//    In the table, enter the following settings:

    model.component("comp1").material("mat1").propertyGroup("def")
         .set("thermalexpansioncoefficient", new String[]{"11e-6"});
    model.component("comp1").material("mat1").propertyGroup()
         .create("Enu", "Enu", "Young's_modulus_and_Poisson's_ratio");
    model.component("comp1").material("mat1").propertyGroup("Enu").set("E", new String[]{"210[GPa]"});
    model.component("comp1").material("mat1").propertyGroup("Enu").set("nu", new String[]{"0.3"});
    model.component("comp1").material("mat1").propertyGroup("def").set("density", new String[]{"7800"});

//    In the Model Builder window, under Component 1 (comp1) > Beam (beam), click Cross-Section Data 1.
//    In the Settings window for Cross-Section Data, locate the Cross-Section Definition section.
//    From the Section type list, select Rectangle.

    model.component("comp1").physics("beam").feature("csd1").set("SectionType", "RectangularSection");

//    In the \[h_y\] text field, type a.

    model.component("comp1").physics("beam").feature("csd1").set("hy_rect", "a");

//    In the \[h_z\] text field, type a.

    model.component("comp1").physics("beam").feature("csd1").set("hz_rect", "a");

//    In the Model Builder window, click Section Orientation 1.
//    In the Settings window for Section Orientation, locate the Section Orientation section.
//    From the Orientation method list, select Orientation vector.

    model.component("comp1").physics("beam").feature("csd1").feature("so1").set("OrientationMethod", "vector_beam");

//    Specify the \[V\] vector as

    model.component("comp1").physics("beam").feature("csd1").feature("so1").set("vector_beam", new int[]{0, 1, 0});

//    In the Physics toolbar, click Points and choose Prescribed Displacement/Rotation.

    model.component("comp1").physics("beam").create("pdr1", "DispRot0", 0);

//    Select Point 1.

    model.component("comp1").physics("beam").feature("pdr1").selection().set(1);

//    In the Settings window for Prescribed Displacement/Rotation, locate the Prescribed Displacement section.
//    From the Displacement in x direction list, select Prescribed.

    model.component("comp1").physics("beam").feature("pdr1").setIndex("Direction", "prescribed", 0);

//    From the Displacement in y direction list, select Prescribed.

    model.component("comp1").physics("beam").feature("pdr1").setIndex("Direction", "prescribed", 1);

//    From the Displacement in z direction list, select Prescribed.

    model.component("comp1").physics("beam").feature("pdr1").setIndex("Direction", "prescribed", 2);

//    Locate the Prescribed Rotation section.
//    From the list, select Rotation.

    model.component("comp1").physics("beam").feature("pdr1").set("RotationType", "RotationGroup");

//    Select the Free rotation around y direction checkbox.

    model.component("comp1").physics("beam").feature("pdr1").setIndex("FreeRotationAround", true, 1);

//    Select the Free rotation around z direction checkbox.

    model.component("comp1").physics("beam").feature("pdr1").setIndex("FreeRotationAround", true, 2);

//    In the Physics toolbar, click Points and choose Prescribed Displacement/Rotation.

    model.component("comp1").physics("beam").create("pdr2", "DispRot0", 0);

//    Select Point 3.

    model.component("comp1").physics("beam").feature("pdr2").selection().set(3);

//    In the Settings window for Prescribed Displacement/Rotation, locate the Prescribed Displacement section.
//    From the Displacement in y direction list, select Prescribed.

    model.component("comp1").physics("beam").feature("pdr2").setIndex("Direction", "prescribed", 1);

//    From the Displacement in z direction list, select Prescribed.

    model.component("comp1").physics("beam").feature("pdr2").setIndex("Direction", "prescribed", 2);

//    In the Model Builder window, click Linear Elastic Material 1.
//    In the Physics toolbar, click Attributes and choose Thermal Expansion.

    model.component("comp1").physics("beam").feature("emm1").create("te1", "ThermalExpansion", 1);

//    In the Settings window for Thermal Expansion, locate the Model Input section.
//    Click Go to Source for Volume reference temperature.
//    In the Model Builder window, under Global Definitions, click Default Model Inputs.
//    In the Settings window for Default Model Inputs, locate the Browse Model Inputs section.
//    Find the Expression for remaining selection subsection.
//    In the Volume reference temperature text field, type 0.

    model.common("cminpt").set("modified", new String[][]{{"strainreferencetemperature", "0"}});

//    In the Model Builder window, under Component 1 (comp1) > Beam (beam) > Linear Elastic Material 1, click Thermal Expansion 1.
//    In the Settings window for Thermal Expansion, locate the Model Input section.
//    From the \[T\] list, select User defined.

    model.component("comp1").physics("beam").feature("emm1").feature("te1").set("minput_temperature_src", "userdef");

//    In the associated text field, type 200.

    model.component("comp1").physics("beam").feature("emm1").feature("te1").set("minput_temperature", 200);

//    Locate the Thermal Bending section.
//    In the \[T_{\textrm{g}y}\] text field, type Tg.

    model.component("comp1").physics("beam").feature("emm1").feature("te1").set("TGy", "Tg");

//    In the \[T_{\textrm{g}z}\] text field, type -Tg.

    model.component("comp1").physics("beam").feature("emm1").feature("te1").set("TGz", "-Tg");

//    In the Study toolbar, click Compute.

    model.study("std1").createAutoSequences("all");

    model.sol("sol1").runAll();

    model.result().dataset().create("dset1beam", "Beam");
    model.result().dataset("dset1beam").set("data", "dset1");
    model.result().dataset("dset1beam").set("physicsinterface", "beam");
    model.result().dataset("dset1beam").set("refinement", 2);
    model.result().create("pg1", "PlotGroup3D");
    model.result("pg1").set("data", "dset1beam");
    model.result("pg1").label("Stress, 3D (beam)");
    model.result("pg1").create("surf1", "Surface");
    model.result("pg1").feature("surf1").set("expr", new String[]{"beam.misesS"});
    model.result("pg1").feature("surf1").set("colortable", "Prism");
    model.result("pg1").feature("surf1").create("def", "Deform");
    model.result("pg1").feature("surf1").feature("def").set("expr", new String[]{"beam.uS", "beam.vS", "beam.wS"});
    model.result("pg1").run();

//    Set default units for result presentation.
//    In the Results toolbar, click Configurations and choose Preferred Units.

    model.result().configuration().create("prfu1", "PreferredUnits");

//    In the Settings window for Preferred Units, locate the Units section.
//    Click Add Physical Quantity.
//    In the Physical Quantity dialog, select General > Displacement (m) in the tree.
//    Click OK.

    model.result().configuration("prfu1")
         .setIndex("quantityunits", new String[]{"displacement", "Displacement", "m", "m"}, 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", "mm", 0, 3);

//    Select the Apply conversions to expressions with the same dimensions checkbox.

    model.result().configuration("prfu1").set("applytosamedims", true);

//    Click Apply.

    model.result().configuration("prfu1").apply();
    model.result("pg1").run();

//    In the Model Builder window, under Results, click Stress, 3D (beam).
//    In the Settings window for 3D Plot Group, type Displacement, 3D in the Label text field.

    model.result("pg1").label("Displacement, 3D");
    model.result("pg1").run();

//    In the Model Builder window, expand the Displacement, 3D node, then click Surface 1.
//    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) > Beam > Displacement > beam.disp - Displacement magnitude - m.

    model.result("pg1").feature("surf1").set("expr", "beam.disp");
    model.result("pg1").feature("surf1").set("descr", "Displacement magnitude");

//    Locate the Coloring and Style section.
//    From the Color table list, select SpectrumLight.

    model.result("pg1").feature("surf1").set("colortable", "SpectrumLight");

//    In the Displacement, 3D toolbar, click Plot.

    model.result("pg1").run();

//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg2", "PlotGroup1D");
    model.result("pg2").run();

//    In the Settings window for 1D Plot Group, type Transverse Displacement in the Label text field.

    model.result("pg2").label("Transverse Displacement");

//    Locate the Plot Settings section.
//    Select the y-axis label checkbox.

    model.result("pg2").set("ylabelactive", true);

//    In the associated text field, type z displacement (mm).

    model.result("pg2").set("ylabel", "z displacement (mm)");

//    Right-click Transverse Displacement and choose Line Graph.

    model.result("pg2").create("lngr1", "LineGraph");
    model.result("pg2").feature("lngr1").set("markerpos", "datapoints");
    model.result("pg2").feature("lngr1").set("linewidth", "preference");
    model.result("pg2").feature("lngr1").set("evaluationsettings", "parent");

//    In the Settings window for Line Graph, type Transverse displacement (z direction) in the Label text field.

    model.result("pg2").feature("lngr1").label("Transverse displacement (z direction)");

//    Click in the Graphics window and then press Ctrl+A to select both Edges.

    model.result("pg2").feature("lngr1").selection().set(1, 2);

//    Locate the y-Axis Data section.
//    In the Expression text field, type w.

    model.result("pg2").feature("lngr1").set("expr", "w");

//    Locate the x-Axis Data section.
//    From the Parameter list, select Expression.

    model.result("pg2").feature("lngr1").set("xdata", "expr");

//    In the Expression text field, type x.

    model.result("pg2").feature("lngr1").set("xdataexpr", "x");

//    Click to expand the Coloring and Style section.
//    From the Width list, select 2.

    model.result("pg2").feature("lngr1").set("linewidth", 2);

//    In the Transverse Displacement toolbar, click Plot.

    model.result("pg2").run();

//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg3", "PlotGroup1D");
    model.result("pg3").run();

//    In the Settings window for 1D Plot Group, type Displacement in the Label text field.

    model.result("pg3").label("Displacement");

//    Locate the Plot Settings section.
//    Select the y-axis label checkbox.

    model.result("pg3").set("ylabelactive", true);

//    In the associated text field, type displacement (mm).

    model.result("pg3").set("ylabel", "displacement (mm)");

//    Locate the Legend section.
//    From the Position list, select Center.

    model.result("pg3").set("legendpos", "center");

//    Right-click Displacement and choose Line Graph.

    model.result("pg3").create("lngr1", "LineGraph");
    model.result("pg3").feature("lngr1").set("markerpos", "datapoints");
    model.result("pg3").feature("lngr1").set("linewidth", "preference");
    model.result("pg3").feature("lngr1").set("evaluationsettings", "parent");

//    In the Settings window for Line Graph, type Displacement magnitude in the Label text field.

    model.result("pg3").feature("lngr1").label("Displacement magnitude");

//    Click in the Graphics window and then press Ctrl+A to select both Edges.

    model.result("pg3").feature("lngr1").selection().set(1, 2);

//    Locate the y-Axis Data section.
//    Select the Description checkbox.

    model.result("pg3").feature("lngr1").set("descractive", true);

//    Locate the x-Axis Data section.
//    From the Parameter list, select Expression.

    model.result("pg3").feature("lngr1").set("xdata", "expr");

//    In the Expression text field, type x.

    model.result("pg3").feature("lngr1").set("xdataexpr", "x");

//    Locate the Coloring and Style section.
//    Find the Line style subsection.
//    From the Line list, select Cycle.

    model.result("pg3").feature("lngr1").set("linestyle", "cycle");

//    Find the Line markers subsection.
//    From the Marker list, select Cycle.

    model.result("pg3").feature("lngr1").set("linemarker", "cycle");

//    From the Positioning list, select Interpolated.

    model.result("pg3").feature("lngr1").set("markerpos", "interp");

//    From the Width list, select 2.

    model.result("pg3").feature("lngr1").set("linewidth", 2);

//    Click to expand the Legends section.
//    Find the Include subsection.
//    Select the Description checkbox.

    model.result("pg3").feature("lngr1").set("autodescr", true);

//    Clear the Solution checkbox.

    model.result("pg3").feature("lngr1").set("autosolution", false);

//    Select the Show legends checkbox.

    model.result("pg3").feature("lngr1").set("legend", true);

//    Right-click Displacement magnitude and choose Duplicate.

    model.result("pg3").feature().duplicate("lngr2", "lngr1");
    model.result("pg3").run();

//    In the Settings window for Line Graph, type Magnitude of transverse displacement in the Label text field.

    model.result("pg3").feature("lngr2").label("Magnitude of transverse displacement");

//    Locate the Selection section.
//    Select the Activate Selection toggle button.
//    Locate the y-Axis Data section.
//    In the Expression text field, type sqrt(v^2+w^2).

    model.result("pg3").feature("lngr2").set("expr", "sqrt(v^2+w^2)");

//    In the Description text field, type Magnitude of transverse displacement.

    model.result("pg3").feature("lngr2").set("descr", "Magnitude of transverse displacement");

//    Right-click Magnitude of transverse displacement and choose Duplicate.

    model.result("pg3").feature().duplicate("lngr3", "lngr2");
    model.result("pg3").run();

//    In the Settings window for Line Graph, type Axial displacement in the Label text field.

    model.result("pg3").feature("lngr3").label("Axial displacement");

//    Locate the y-Axis Data section.
//    In the Expression text field, type u.

    model.result("pg3").feature("lngr3").set("expr", "u");

//    In the Description text field, type Axial displacement.

    model.result("pg3").feature("lngr3").set("descr", "Axial displacement");

//    In the Displacement toolbar, click Plot.

    model.result("pg3").run();
    model.result("pg1").run();

    model.title("Thermally Loaded Beam");

    model
         .description("In this example, a 3D beam is exposed to thermal loads. The temperature varies linearly over the beam cross section. The solution is compared with an analytical solution.");

    return model;
  }

  public static void main(String[] args) {
    run();
  }

}
