Skip to content

Commit 066febe

Browse files
committed
Update HeatConduction2DFinGmsh.html tutorial
1 parent a38f9f4 commit 066febe

File tree

5 files changed

+140
-2022
lines changed

5 files changed

+140
-2022
lines changed

tutorials/HeatConduction2DFin.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ <h2 id="results"><a name="Results"></a>Results</h2>
244244
</ul>
245245

246246
<script type="module">
247-
//Import FEAScript library from GitHub
247+
// Import FEAScript library from GitHub
248248
import { FEAScriptModel, plotSolution, printVersion } from "https://core.feascript.com/src/index.js";
249-
//Import FEAScript library from a local directory
249+
// Import FEAScript library from a local directory
250250
//import { FEAScriptModel, plotSolution, printVersion } from "../../FEAScript-core/src/index.js";
251251

252252
window.addEventListener("DOMContentLoaded", () => {

tutorials/HeatConduction2DFinGmsh.html

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ <h2 id="gmshfileimport"><a name="gmshfileimport"></a>Gmsh File Import</h2>
101101

102102
<h2 id="results"><a name="results"></a>Results</h2>
103103

104+
<div id="solutionPlot"></div>
105+
104106
<ul id="menu">
105107
<li>
106108
<a href="https://feascript.com/tutorials/HeatConduction2DFin.html" target="_blank"
@@ -113,44 +115,61 @@ <h2 id="results"><a name="results"></a>Results</h2>
113115
</ul>
114116

115117
<script type="module">
118+
// Import FEAScript library from GitHub
116119
import { FEAScriptModel, plotSolution, printVersion } from "https://core.feascript.com/src/index.js";
120+
import { importGmshQuadTri } from "https://core.feascript.com/src/readers/gmshReaderScript.js";
121+
// Import FEAScript library from a local directory
122+
//import { FEAScriptModel, plotSolution, printVersion } from "../../FEAScript-core/src/index.js";
123+
//import { importGmshQuadTri } from "../../FEAScript-core/src/readers/gmshReaderScript.js";
117124

118-
window.addEventListener("DOMContentLoaded", () => {
125+
window.addEventListener("DOMContentLoaded", async () => {
119126
// Print FEAScript version in the console
120127
printVersion();
121128

129+
// Fetch the mesh file from your server
130+
const response = await fetch("./rect_quad.msh");
131+
if (!response.ok) {
132+
throw new Error(`Failed to load mesh file: ${response.status} ${response.statusText}`);
133+
}
134+
const meshContent = await response.text();
135+
136+
// Create a File object with the actual content
137+
const meshFile = new File([meshContent], "rect_quad.msh");
138+
122139
// Create a new FEAScript model
123140
const model = new FEAScriptModel();
124-
141+
125142
// Set solver configuration
126143
model.setSolverConfig("solidHeatTransferScript");
127-
128-
// Define mesh configuration
144+
145+
// Parse the mesh file first
146+
const result = await importGmshQuadTri(meshFile);
147+
148+
// Fix nodal numbering format for the solver
149+
if (result.nodalNumbering.quadElements && result.nodalNumbering.quadElements.length > 0) {
150+
result.nodalNumbering = result.nodalNumbering.quadElements;
151+
} else if (result.nodalNumbering.triangleElements && result.nodalNumbering.triangleElements.length > 0) {
152+
result.nodalNumbering = result.nodalNumbering.triangleElements;
153+
}
154+
155+
// Define mesh configuration with the parsed result
129156
model.setMeshConfig({
130-
meshFile: "rect_quad"
157+
parsedMesh: result,
158+
meshDimension: "2D",
159+
elementOrder: "linear"
131160
});
132161

133-
// Define boundary conditions
134-
model.addBoundaryCondition("0", ["constantTemp", 200]);
135-
model.addBoundaryCondition("1", ["symmetry"]);
136-
model.addBoundaryCondition("2", ["convection", 1, 20]);
137-
model.addBoundaryCondition("3", ["constantTemp", 200]);
162+
// Define boundary conditions using Gmsh physical group tags
163+
model.addBoundaryCondition("1", ["constantTemp", 200]); // bottom boundary
164+
model.addBoundaryCondition("4", ["symmetry"]); // left boundary
165+
model.addBoundaryCondition("3", ["convection", 1, 20]); // top boundary
166+
model.addBoundaryCondition("2", ["constantTemp", 200]); // right boundary
138167

139-
// Set solver method (optional) - 'lusolve' uses LU decomposition
168+
// Set solver method
140169
model.setSolverMethod("lusolve");
141170

142171
// Solve the problem and get the solution
143-
const { solutionVector, nodesCoordinates } = model.solve();
144-
145-
// Plot the solution as a 2D contour plot
146-
plotSolution(
147-
solutionVector,
148-
nodesCoordinates,
149-
model.solverConfig,
150-
model.meshConfig.meshDimension,
151-
"contour",
152-
"solutionPlot"
153-
);
172+
//const { solutionVector, nodesCoordinates } = model.solve();
154173
});
155174
</script>
156175

tutorials/rect.geo

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// 2D Rectangle: 4m (width) x 2m (height)
22
// With Physical Lines for boundary labeling
3+
// Use the command "gmsh rect.geo -2" to generate the mesh
34

4-
lc = 0.2; // Characteristic length (mesh density)
5+
lc = 0.8; // Characteristic length (mesh density)
56

67
// Points (x, y, z, mesh size)
78
Point(1) = {0, 0, 0, lc}; // Bottom left
@@ -29,6 +30,6 @@ Physical Line("left") = {4};
2930
Physical Surface("domain") = {1};
3031

3132
// Generate 2D mesh
32-
//Recombine Surface{1}; // Turns triangle mesh into quads
33+
Recombine Surface{1}; // Turns triangle mesh into quads
3334
Mesh 2;
3435

0 commit comments

Comments
 (0)