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.
⚠️ Important: Due to security restrictions, this example requires launching the browser with reduced security settings, e.g.:
start chrome --disable-web-security --user-data-dir="C:\tmp\chrome-cors" --disable-site-isolation-trials
These flags temporarily disable CORS restrictions that normally block a web worker from loading scripts or data when running from local files. For production applications, proper CORS headers should be configured on your server.
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 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.setSolverConfig("frontPropagationScript");
await model.setMeshConfig({
meshDimension: "2D",
elementOrder: "quadratic",
numElementsX: 12,
numElementsY: 8,
maxX: 4,
maxY: 2,
});
// Apply boundary conditions
await model.addBoundaryCondition("0", ["constantValue", 0]); // Bottom
await model.addBoundaryCondition("1", ["constantValue", 0]); // Left
await model.addBoundaryCondition("2", ["zeroGradient"]); // Top
await model.addBoundaryCondition("3", ["constantValue", 0]); // Right
// Solve
await model.setSolverMethod("lusolve");
const { solutionVector, nodesCoordinates } = await model.solve();
// Plot results
plotSolution(
solutionVector,
nodesCoordinates,
"frontPropagationScript",
"2D",
"contour",
"resultsCanvas"
);
// 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.