Overview

Heat Conduction in a 2D Rhomboid Fin Tutorial (Gmsh Mesh)

This page demonstrates solving the 2D heat conduction fin problem using a Gmsh-generated mesh. It is a variation of the rectangular fin tutorial, but applied to a rhomboidal domain. Gmsh is a powerful mesh generation tool that can create complex geometries and meshes for finite element analysis. For the mathematical formulation and theory, see the basic tutorial.

Gmsh file import

This example demonstrates how to import a Gmsh-generated mesh (.msh file format) and solve a heat conduction problem.

<body>
  <!-- ...body region... -->
  <script type="module">
    import {
      FEAScriptModel,
      importGmshMesh,
      plotInterpolatedSolution,
      printVersion,
    } from "https://core.feascript.com/dist/feascript.esm.js";

    window.addEventListener("DOMContentLoaded", async () => {
      console.log("FEAScript version:", printVersion);

      // 1. Create the model and select the physics
      const model = new FEAScriptModel();
      model.setModelConfig("heatConductionScript");

      // 2. Load the Gmsh mesh (.msh format version 4.1)
      const response = await fetch("./rhom_quad_quadratic.msh");
      if (!response.ok) {
        throw new Error(`Failed to load the mesh file: ${response.status} ${response.statusText}`);
      }
      const meshFile = new File([await response.text()], "rhom_quad_quadratic.msh");
      const mesh = await importGmshMesh(meshFile);
      model.setMeshConfig({ parsedMesh: mesh });

      // 3. Apply the boundary conditions (key = Gmsh physical group tag - 1)
      model.addBoundaryCondition("0", ["constantTemperature", 200]); // Bottom
      model.addBoundaryCondition("1", ["symmetry"]);                 // Left
      model.addBoundaryCondition("2", ["convection", 1, 20]);        // Top
      model.addBoundaryCondition("3", ["constantTemperature", 200]); // Right

      // 4. Solve
      model.setSolverMethod("lusolve");
      const result = model.solve();

      // 5. Plot the results
      plotInterpolatedSolution(model, result, "contour", "resultsCanvas");
    });
  </script>
  <!-- ...rest of body region... -->
</body>

For details on the Gmsh workflow, physical groups, and boundary condition mapping, please refer to the rectangular fin tutorial.

Example Gmsh .geo file

Below is the rhom.geo file used in this tutorial. It defines a rhomboid domain with a 4 m base and a 2 m height, whose top edge is shifted by 1 m, with a physical line for each boundary edge:

rhom.geo
// 2D rhomboid: 4 m (base width) x 2 m (height), top edge shifted by dx
// Generate the mesh with: gmsh rhom.geo -2 -format msh41 -o rhom_quad_quadratic.msh

// 1. Mesh size and shape
lc = 0.7; // Characteristic length
dx = 1.0; // Horizontal shift of the top edge (sets the rhomboid angle)

// 2. Points (x, y, z, mesh size)
Point(1) = {0,      0, 0, lc}; // Bottom left
Point(2) = {4,      0, 0, lc}; // Bottom right
Point(3) = {4 + dx, 2, 0, lc}; // Top right (shifted)
Point(4) = {dx,     2, 0, lc}; // Top left (shifted)

// 3. Lines and surface
Line(1) = {1, 2};            // Bottom
Line(2) = {2, 3};            // Right
Line(3) = {3, 4};            // Top
Line(4) = {4, 1};            // Left
Line Loop(1) = {1, 2, 3, 4}; // Closed boundary
Plane Surface(1) = {1};      // Domain

// 4. Physical groups, tagged bottom, left, top, right (the side order of FEAScript structured meshes)
Physical Line("bottom", 1) = {1};    // FEAScript boundary "0"
Physical Line("left", 2)   = {4};    // FEAScript boundary "1"
Physical Line("top", 3)    = {3};    // FEAScript boundary "2"
Physical Line("right", 4)  = {2};    // FEAScript boundary "3"
Physical Surface("domain", 5) = {1}; // Domain

// 5. Mesh
Recombine Surface{1};  // Quadrilaterals instead of triangles
Mesh.ElementOrder = 2; // Quadratic elements
Mesh 2;

To generate a mesh file from this .geo script, you would run: gmsh rhom.geo -2 -format msh41 -o rhom_quad_quadratic.msh in your terminal.

Generated mesh

Below is a visualization of the quadrilateral mesh generated with Gmsh. The mesh consists of 24 elements.

Quadrilateral mesh generated by Gmsh

Quadrilateral mesh (rhom_quad_quadratic.msh) generated using the rhom.geo script with Gmsh

Results

Below is the 2D contour plot of the computed temperature distribution. This plot is generated in real time using FEAScript.

Stay in the loop

Join the mailing list.

Receive new tutorials, project updates and news.

Open source

Star us on GitHub.

Found this tutorial useful? Give FEAScript a star.

Star FEAScript