FEAScript: Heat Conduction in a Two-Dimensional Fin Example
by nikoscham
HTML
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>FEAScript: Heat Conduction in a Two-Dimensional Fin Example</title>
<!-- Math.js and Plotly.js libraries -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/5.0.0/math.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/plotly.js/2.27.0/plotly.min.js"></script>
<!-- Link to the CSS file -->
<link
href="https://feascript.com/FEAScript-website.css"
rel="stylesheet"
type="text/css"
/>
<link
href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap"
rel="stylesheet"
/>
</head>
<body>
<h1>Heat Conduction in a Two-Dimensional Fin Example</h1>
<p>
This example demonstrates solving a steady-state heat transfer problem in
a 2D rectangular domain
</p>
<div id="solutionPlot"></div>
<p>
The mesh configuration and boundary conditions are defined directly within
the JavaScript code in this example. Detailed instructions for this
example can be found in the corresponding
<a
href="https://feascript.com/tutorials/HeatConduction2DFin.html"
target="_blank"
>FEAScript tutorial</a
>.
</p>
</body>
</html>
JavaScript
import {
FEAScriptModel,
plotSolution,
} from "https://feascript.github.io/FEAScript-core/src/index.js";
window.addEventListener("DOMContentLoaded", () => {
// Create a new FEAScript model
const model = new FEAScriptModel();
// Set solver configuration
model.setSolverConfig("solidHeatTransferScript");
// Define mesh configuration
model.setMeshConfig({
meshDimension: "2D",
elementOrder: "quadratic",
numElementsX: 8,
numElementsY: 4,
maxX: 4,
maxY: 2,
});
// Define boundary conditions
model.addBoundaryCondition("0", ["constantTemp", 200]);
model.addBoundaryCondition("1", ["symmetry"]);
model.addBoundaryCondition("2", ["convection", 1, 20]);
model.addBoundaryCondition("3", ["constantTemp", 200]);
// Solve the problem and get the solution
const { solutionVector, nodesCoordinates } = model.solve();
// Plot the solution as a 2D contour plot
plotSolution(
solutionVector,
nodesCoordinates,
model.solverConfig,
model.meshConfig.meshDimension,
"contour",
"solutionPlot"
);
});