This page demonstrates solving the 2D heat conduction fin problem using FEAScript in a web worker for improved browser responsiveness. For the mathematical formulation and theory, see the basic tutorial.
The code below shows how to use FEAScript with a web worker. The solution is plotted as a 2D contour.
<body>
<!-- ...body region... -->
<script type="module">
// Import FEAScript library
import { FEAScriptWorker, plotSolution, printVersion } from "https://core.feascript.com/src/index.js";
window.addEventListener("DOMContentLoaded", async () => {
// Print FEAScript version in the console
printVersion();
// Create a new FEAScriptWorker instance
const model = new FEAScriptWorker();
// Ensure the worker is ready
await model.ping();
// Configure model
await model.setModelConfig("heatConductionScript");
await model.setMeshConfig({
meshDimension: "2D",
elementOrder: "quadratic",
numElementsX: 8,
numElementsY: 4,
maxX: 4,
maxY: 2,
});
// Apply boundary conditions
await model.addBoundaryCondition("0", ["constantTemp", 200]); // Bottom boundary
await model.addBoundaryCondition("1", ["symmetry"]); // Left boundary
await model.addBoundaryCondition("2", ["convection", 1, 20]); // Top boundary
await model.addBoundaryCondition("3", ["constantTemp", 200]); // Right boundary
// Solve
await model.setSolverMethod("lusolve");
const result = await model.solve();
// Plot results
const modelInfo = await model.getModelInfo(); // Get model info for plotting
plotSolution(modelInfo, result, "contour", "resultsCanvas");
// Terminate the worker
model.terminate();
});
</script>
<!-- ...rest of body region... -->
</body>
Below is the 2D contour plot of the computed temperature distribution. This plot is generated in real time using FEAScript.