Skip to content

Commit a38f9f4

Browse files
committed
Start over the Gmsh heat conduction tutorial (it's still in progress)
1 parent 4323031 commit a38f9f4

File tree

1 file changed

+44
-54
lines changed

1 file changed

+44
-54
lines changed

tutorials/HeatConduction2DFinGmsh.html

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -83,84 +83,74 @@ <h1 class="top">
8383
<h1>Heat Conduction in a Two-Dimensional Fin (Gmsh Example)</h1>
8484

8585
<ul id="menu">
86-
<li><a href="#introduction">Introduction</a></li>
8786
<li><a href="#gmshfileimport">Gmsh File Import</a></li>
8887
<li><a href="#results">Results</a></li>
8988
</ul>
9089

9190
<div class="highlight-container">
9291
<p>
93-
This example demonstrates solving a steady-state heat transfer problem in a 2D rectangular domain
94-
using a mesh generated by
95-
<a href="https://gmsh.info/" target="_blank">Gmsh</a>. Gmsh is a powerful mesh generation tool that
96-
can create complex geometries and meshes for finite element analysis.
92+
This page demonstrates solving the 2D heat conduction fin problem using a Gmsh-generated mesh.
93+
<a href="https://gmsh.info/" target="_blank">Gmsh</a> is a powerful mesh generation tool that can
94+
create complex geometries and meshes for finite element analysis. For the mathematical formulation and
95+
theory, see the <a href="HeatConduction2DFin.html" target="_blank">main (standard) tutorial</a>.
9796
</p>
9897
</div>
9998

100-
<h2 id="introduction"><a name="Introduction"></a>Introduction</h2>
101-
<p>
102-
This example uses a Gmsh-generated mesh to solve a typical cooling fin problem. The objective is to
103-
model heat conduction and understand temperature distribution under specific boundary conditions.
104-
</p>
105-
106-
<h2 id="gmshfileimport"><a name="Gmsh File Import"></a>Gmsh File Import</h2>
107-
<p>Upload a Gmsh (.msh) file using the form below. The parsed data will be displayed in JSON format.</p>
108-
<div class="file-input-container">
109-
<form id="inputForm">
110-
<label for="inputFile">Choose a .msh file:</label>
111-
<input type="file" id="inputFile" name="inputFile" accept=".msh" required />
112-
</form>
113-
</div>
114-
115-
<h3>Parsed Gmsh Data:</h3>
116-
<div id="resultOutput">No file uploaded yet. Please select a Gmsh (.msh) file.</div>
99+
<h2 id="gmshfileimport"><a name="gmshfileimport"></a>Gmsh File Import</h2>
100+
<p>The code below shows how to import a Gmsh (.msh) file and set up the problem.</p>
117101

118-
<h2 id="results"><a name="Results"></a>Results</h2>
119-
<p>
120-
After uploading the Gmsh file, the parsed data will be displayed above. You can use this data to set up
121-
and solve the heat conduction problem.
122-
</p>
102+
<h2 id="results"><a name="results"></a>Results</h2>
123103

124104
<ul id="menu">
125105
<li>
126-
<a href="HeatConduction2DFin.html" target="_blank">Return to Main Tutorial</a>
106+
<a href="https://feascript.com/tutorials/HeatConduction2DFin.html" target="_blank"
107+
>Return to Main Tutorial</a
108+
>
127109
</li>
128110
<li>
129111
<a href="https://feascript.com/index.html" target="_blank">Return to FEAScript Website</a>
130112
</li>
131113
</ul>
132114

133-
<script>
134-
document.getElementById("currentYear").innerHTML = new Date().getFullYear();
135-
</script>
136-
137-
<!-- Gmsh File Import Script -->
138115
<script type="module">
139-
import { importGmshQuadTri } from "../../../FEAScript-core/src/readers/gmshQuadReader.js";
140-
141-
document.getElementById("inputFile").addEventListener("change", async function (e) {
142-
const file = e.target.files[0];
143-
if (!file) return;
144-
145-
try {
146-
document.getElementById("resultOutput").innerHTML = "Processing file...";
147-
const res = await importGmshQuadTri(file);
148-
console.log(res);
149-
document.getElementById("resultOutput").innerHTML = JSON.stringify(res, null, 2);
150-
} catch (error) {
151-
document.getElementById("resultOutput").innerHTML = `Error processing file: ${error.message}`;
152-
}
153-
});
154-
</script>
155-
156-
<!-- Import FEAScript utilities -->
157-
<script type="module">
158-
import { printVersion } from "https://core.feascript.com/src/index.js";
116+
import { FEAScriptModel, plotSolution, printVersion } from "https://core.feascript.com/src/index.js";
159117

160118
window.addEventListener("DOMContentLoaded", () => {
161119
// Print FEAScript version in the console
162120
printVersion();
163-
console.log("Gmsh Import Tool loaded successfully");
121+
122+
// Create a new FEAScript model
123+
const model = new FEAScriptModel();
124+
125+
// Set solver configuration
126+
model.setSolverConfig("solidHeatTransferScript");
127+
128+
// Define mesh configuration
129+
model.setMeshConfig({
130+
meshFile: "rect_quad"
131+
});
132+
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]);
138+
139+
// Set solver method (optional) - 'lusolve' uses LU decomposition
140+
model.setSolverMethod("lusolve");
141+
142+
// 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+
);
164154
});
165155
</script>
166156

0 commit comments

Comments
 (0)