Overview
Solidification front propagation in a 2D domain, multi-threaded.
This page demonstrates solving the solidification front propagation 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 to solve the eikonal equation for front propagation. This approach moves the computation to a separate thread, preventing the UI from freezing during complex calculations. The solution is plotted as a 2D contour.
<body>
<!-- ...body region... -->
<script type="module">
import {
FEAScriptWorker,
plotSolution,
version,
} from "https://core.feascript.com/src/index.js";
window.addEventListener("DOMContentLoaded", async () => {
console.log("FEAScript version:", version);
// 1. Create the model in a web worker and select the physics
const model = new FEAScriptWorker();
await model.ping(); // Wait until the worker is ready
await model.setModelConfig("frontPropagation", { solver: { method: "lusolve" } });
// 2. Define the mesh
await model.setGeometry({ rectangle: [4, 2] });
await model.setMeshConfig({ elements: "quadrilaterals", elementOrder: "quadratic", divisions: [12, 8] });
// 3. Apply the boundary conditions
await model.addBoundaryCondition("bottom", { type: "constantValue", value: 0 }); // Bottom: initial front
await model.addBoundaryCondition("left", { type: "constantValue", value: 0 }); // Left: initial front
await model.addBoundaryCondition("top", { type: "zeroGradient" }); // Top
await model.addBoundaryCondition("right", { type: "constantValue", value: 0 }); // Right: initial front
// 4. Solve
const result = await model.solve();
// 5. Plot the results
const modelInfo = await model.getModelInfo();
plotSolution(modelInfo, result, "contour", "resultsCanvas");
// 6. Terminate the worker
model.terminate();
});
</script>
<!-- ...rest of body region... -->
</body>
Below is the 2D contour plot of the computed front propagation. The contour values represent the arrival time of the front at each position. This plot is generated in real time using FEAScript.
Stay in the loop
Join the mailing list.
Receive new tutorials, project updates and news.