Overview
Heat conduction in a 2D fin, on a generated triangle mesh.
This page solves the 2D heat conduction fin problem on a mesh of triangles that FEAScript
generates itself, from the geometry of the domain, with elements: "triangles". No
mesh file and no external tool are needed. For the formulation and the theory, see the
basic tutorial; for a mesh made with Gmsh, see the
Gmsh variant.
The domain is set up in two steps, as in every FEAScript model: setGeometry describes
the domain and names its boundaries, and setMeshConfig says how to mesh it. Here the
geometry is the same 4 m × 2 m rectangle as in the basic tutorial, and only the elements change,
from quadrilaterals to triangles:
<body>
<!-- ...body region... -->
<script type="module">
import {
FEAScriptModel,
plotInterpolatedSolution,
version,
} from "https://core.feascript.com/dist/feascript.esm.js";
window.addEventListener("DOMContentLoaded", () => {
console.log("FEAScript version:", version);
// 1. Create the model and select the physics
const model = new FEAScriptModel();
model.setModelConfig("heatConduction", { solver: { method: "lusolve" } });
// 2. Define the geometry and mesh it with quadratic triangles of side 0.5 m at most
model.setGeometry({ rectangle: [4, 2] }); // Boundaries "bottom", "right", "top", "left"
model.setMeshConfig({ elements: "triangles", elementOrder: "quadratic", size: 0.5, minAngle: 30 });
// 3. Apply the boundary conditions, keyed by the boundary names
model.addBoundaryCondition("bottom", { type: "constantTemperature", temperature: 200 });
model.addBoundaryCondition("right", { type: "constantTemperature", temperature: 200 });
model.addBoundaryCondition("top", { type: "convection", h: 1, ambientTemperature: 20 });
model.addBoundaryCondition("left", { type: "symmetry" });
// 4. Solve
const result = model.solve();
// 5. Plot the results
plotInterpolatedSolution(model, result, "contour", "resultsCanvas");
});
</script>
<!-- ...rest of body region... -->
</body>
The settings of the mesh:
-
elements:"triangles"meshes any shape, with holes, by Delaunay refinement;"quadrilaterals"gives the grid of the basic tutorial. -
size: the length of an element side. Each element has at most the area of the equilateral triangle of that side. A function(x, y)grades the mesh, for examplesize: (x, y) => 0.15 + 0.35 * (2 - y) / 2for finer elements towards the convective top edge. -
minAngle: the smallest angle of the elements, in degrees. The refinement always ends below 20.7 degrees (the default is 20) and in practice up to about 33. -
elementOrder:"linear"(3-node) or"quadratic"(6-node) triangles.
A rectangle names its sides "bottom", "right", "top" and
"left", so the conditions are the same as in the
basic tutorial and the
Gmsh variant. For any other shape, the geometry is
written as a path: a start point and the boundaries, each running from where the
previous one ended to its to point. The last one may leave out to to
close the shape. The fin written that way, with the same result:
model.setGeometry({
shape: {
start: [0, 0],
boundaries: [
{ name: "bottom", to: [4, 0] },
{ name: "right", to: [4, 2] },
{ name: "top", to: [0, 2] },
{ name: "left" }, // No "to": closes the shape
],
},
});
Boundaries with the same name form one boundary of the model, so a curved side made of many
short segments, or two sides with the same condition, can share a name. A to may also
be a list of points. Holes are listed in holes, usually as
{ name: "hole", points: [...] }.
Below is the mesh that the settings above generate: 128 quadratic triangles with 281 nodes (with FEAScript 0.4.0), all with angles of at least 30 degrees. The figure is drawn from the same call.
Quadratic triangle mesh of the 4 m × 2 m fin, generated by FEAScript
The lines are the edges of the triangles: every edge is shared by two elements, or by one on the boundary, and no node lies in the middle of another element's edge. The pattern is so regular because the generator starts from the four corners only: it splits the sides at their midpoints, then at their quarters, and fills the inside from there, so on a rectangle all the triangles come out with angles of 45 or 90 degrees.
The tutorial keeps the four-corner rectangle because it is the shortest way to write the fin. To get a mesh of varied, well-shaped triangles instead, which is how a generated mesh usually looks, give the boundaries points along the sides at about the element size, so the refinement starts from a boundary that already has the right size. This code replaces step 2 above; the rest of the model stays the same:
// The 4 m × 2 m rectangle with a point every 0.5 m along its sides
const along = (from, to, count) =>
Array.from({ length: count + 1 }, (_, i) => [
from[0] + ((to[0] - from[0]) * i) / count,
from[1] + ((to[1] - from[1]) * i) / count,
]);
model.setGeometry({
shape: {
start: [0, 0],
boundaries: [
{ name: "bottom", to: along([0, 0], [4, 0], 8).slice(1) },
{ name: "right", to: along([4, 0], [4, 2], 4).slice(1) },
{ name: "top", to: along([4, 2], [0, 2], 8).slice(1) },
{ name: "left", to: along([0, 2], [0, 0], 4).slice(1) },
],
},
});
model.setMeshConfig({ elements: "triangles", elementOrder: "quadratic", size: 0.5, minAngle: 30 });
Quadratic triangle mesh of the fin, generated from a point every 0.5 m along its sides
This mesh has 131 triangles with 290 nodes, against 128 with 281, and the temperature at the tip of the fin is the same on both, 81.32 °C (with FEAScript 0.4.0): the two codes differ in the shape of the triangles, not in the result.
The generator meshes any polygon with holes, so it covers geometries that the structured mesh cannot, without leaving the browser. For curved boundaries, approximate them by short edges with one common name. For a rectangle like this fin, the structured mesh of quadrilaterals remains the simpler choice, and Gmsh the tool for meshes that need full control of the element sizes.
Below is the 2D contour plot of the computed temperature distribution, generated in real time with FEAScript. The temperatures are the same as on the structured and the Gmsh meshes, up to the discretization error of each mesh.
See also the Gmsh variant and the rhomboid fin, on meshes imported from Gmsh.
Stay in the loop
Join the mailing list.
Receive new tutorials, project updates and news.