Skip to content

Commit d8de704

Browse files
committed
Add Gmsh example and .msh file. Update HeatConduction2DFinWorker and README for Gmsh support
1 parent cadaaf3 commit d8de704

File tree

4 files changed

+488
-5
lines changed

4 files changed

+488
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<!DOCTYPE html>
2+
3+
<!-- ______ ______ _____ _ _ -->
4+
<!-- | ____| ____| /\ / ____| (_) | | -->
5+
<!-- | |__ | |__ / \ | (___ ___ ____ _ ____ | |_ -->
6+
<!-- | __| | __| / /\ \ \___ \ / __| __| | _ \| __| -->
7+
<!-- | | | |____ / ____ \ ____) | (__| | | | |_) | | -->
8+
<!-- |_| |______/_/ \_\_____/ \___|_| |_| __/| | -->
9+
<!-- | | | | -->
10+
<!-- |_| | |_ -->
11+
<!-- Website: https://feascript.com/ \__| -->
12+
13+
<html lang="en">
14+
<head>
15+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
16+
<meta name="viewport" content="width=device-width" />
17+
<title>FEAScript: Heat Conduction in a Two-Dimensional Fin (Gmsh Example)</title>
18+
19+
<!-- Math.js and Plotly.js libraries -->
20+
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/5.0.0/math.min.js"></script>
21+
<script src="https://cdnjs.cloudflare.com/ajax/libs/plotly.js/2.27.0/plotly.min.js"></script>
22+
23+
<!-- Link to the CSS files -->
24+
<link href="https://feascript.com/FEAScript-website.css" rel="stylesheet" type="text/css" />
25+
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet" />
26+
</head>
27+
28+
<body>
29+
<h1>Heat Conduction in a Two-Dimensional Fin Example (Gmsh)</h1>
30+
<div id="solutionPlot"></div>
31+
32+
<p>
33+
This example demonstrates solving a steady-state heat transfer problem in a 2D rectangular domain using
34+
a Gmsh-generated mesh (<a href="./rect_quad_unstruct.msh">rect_quad_unstruct.msh</a>). The mesh
35+
configuration and boundary conditions are defined directly within the JavaScript code. Please refresh
36+
the page to update the results. Detailed instructions for this example can be found in the corresponding
37+
<a href="https://feascript.com/tutorials/HeatConduction2DFinGmsh.html" target="_blank"
38+
>FEAScript tutorial</a
39+
>. If you need further assistance, you can visit the
40+
<a href="https://feascript.com/" target="_blank">FEAScript website</a>.
41+
</p>
42+
43+
<p>&#169; 2023-<span id="currentYear"></span> FEAScript</p>
44+
<script>
45+
document.getElementById("currentYear").innerHTML = new Date().getFullYear();
46+
</script>
47+
48+
<script type="module">
49+
import {
50+
FEAScriptModel,
51+
importGmshQuadTri,
52+
plotSolution,
53+
printVersion,
54+
} from "https://core.feascript.com/src/index.js";
55+
56+
window.addEventListener("DOMContentLoaded", async () => {
57+
// Print FEAScript version in the console
58+
printVersion();
59+
60+
// Fetch the mesh file
61+
const response = await fetch("./rect_quad_unstruct.msh"); // .msh version 4.1 is supported
62+
if (!response.ok) {
63+
throw new Error(`Failed to load mesh file: ${response.status} ${response.statusText}`);
64+
}
65+
const meshContent = await response.text();
66+
67+
// Create a File object with the actual content
68+
const meshFile = new File([meshContent], "rect_quad_unstruct.msh");
69+
70+
// Create a new FEAScript model
71+
const model = new FEAScriptModel();
72+
73+
// Set solver configuration
74+
model.setSolverConfig("solidHeatTransferScript");
75+
76+
// Parse the mesh file
77+
const result = await importGmshQuadTri(meshFile);
78+
79+
// Define mesh configuration with the parsed result
80+
model.setMeshConfig({
81+
parsedMesh: result,
82+
meshDimension: "2D",
83+
elementOrder: "quadratic",
84+
});
85+
86+
// Define boundary conditions
87+
model.addBoundaryCondition("0", ["constantTemp", 200]); // bottom boundary
88+
model.addBoundaryCondition("1", ["constantTemp", 200]); // right boundary
89+
model.addBoundaryCondition("2", ["convection", 1, 20]); // top boundary
90+
model.addBoundaryCondition("3", ["symmetry"]); // left boundary
91+
92+
// Solve the problem and get the solution
93+
const { solutionVector, nodesCoordinates } = model.solve();
94+
95+
// Plot the solution as a 2D contour plot
96+
plotSolution(
97+
solutionVector,
98+
nodesCoordinates,
99+
model.solverConfig,
100+
model.meshConfig.meshDimension,
101+
"contour",
102+
"solutionPlot",
103+
"unstructured"
104+
);
105+
});
106+
</script>
107+
</body>
108+
</html>

examples/solidHeatTransferScript/HeatConduction2DFin/HeatConduction2DFinWorker.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<head>
1515
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
1616
<meta name="viewport" content="width=device-width" />
17-
<title>FEAScript: Heat Conduction in a Two-Dimensional Fin Example (Worker)</title>
17+
<title>FEAScript: Heat Conduction in a Two-Dimensional Fin Example (Web Worker)</title>
1818

1919
<!-- Math.js and Plotly.js libraries -->
2020
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/5.0.0/math.min.js"></script>
@@ -36,8 +36,8 @@ <h1>Heat Conduction in a Two-Dimensional Fin Example (Worker)</h1>
3636
<p>
3737
This is a worker-based implementation of the heat conduction in a two-dimensional fin example using a
3838
larger mesh (18x9). This implementation enables better performance for larger simulations. The mesh
39-
configuration and boundary conditions are defined directly within the JavaScript code. Detailed
40-
instructions for this example can be found in the corresponding
39+
configuration and boundary conditions are defined directly within the JavaScript code. Please refresh
40+
the page to update the results. Detailed instructions for this example can be found in the corresponding
4141
<a href="https://feascript.com/tutorials/HeatConduction2DFinWorker.html" target="_blank"
4242
>FEAScript tutorial</a
4343
>. If you need further assistance, you can visit the

examples/solidHeatTransferScript/HeatConduction2DFin/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ This example is available in three implementations:
1212

1313
1. **Standard Version** (`HeatConduction2DFin.html`) - Basic implementation using the FEAScriptModel class
1414
2. **Web Worker Version** (`HeatConduction2DFinWorker.html`) - Implementation using Web Workers for better performance with larger models
15-
3. **GMSH Version** (`HeatConduction2DFinGmsh.html`) - Experimental version supporting GMSH mesh file import
15+
3. **Gmsh Version** (`HeatConduction2DFinGmsh.html`) - Implementation using an unstructured mesh generated by [Gmsh](https://gmsh.info/) (the mesh file, `rect_quad_unstruct.msh`, is also located in the current directory)
1616

1717
### Instructions
1818

19-
The mesh configuration and boundary conditions are defined directly in the JavaScript section of the HTML files. For a step-by-step guide and additional details, refer to the corresponding [tutorial](https://feascript.com/tutorials/HeatConduction2DFin.html) or the [Web Worker tutorial](https://feascript.com/tutorials/HeatConduction2DFinWorker.html).
19+
The mesh configuration and boundary conditions are defined directly in the JavaScript section of the HTML files. For a step-by-step guide and additional details, refer to the corresponding [tutorial](https://feascript.com/tutorials/HeatConduction2DFin.html).

0 commit comments

Comments
 (0)