|
| 1 | +<!DOCTYPE html> |
| 2 | + |
| 3 | +<!-- ______ ______ _____ _ _ --> |
| 4 | +<!-- | ____| ____| /\ / ____| (_) | | --> |
| 5 | +<!-- | |__ | |__ / \ | (___ ___ ____ _ ____ | |_ --> |
| 6 | +<!-- | __| | __| / /\ \ \___ \ / __| __| | _ \| __| --> |
| 7 | +<!-- | | | |____ / ____ \ ____) | (__| | | | |_) | | --> |
| 8 | +<!-- |_| |______/_/ \_\_____/ \___|_| |_| __/| | --> |
| 9 | +<!-- | | | | --> |
| 10 | +<!-- |_| | |_ --> |
| 11 | +<!-- Website: https://feascript.com/ \__| --> |
| 12 | + |
| 13 | +<html lang="en"> |
| 14 | + <head> |
| 15 | + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| 16 | + <meta name="viewport" content="width=device-width" /> |
| 17 | + <title>FEAScript: Heat Conduction in a Two-Dimensional Fin (Gmsh Example)</title> |
| 18 | + |
| 19 | + <!-- Math.js and Plotly.js libraries --> |
| 20 | + <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/5.0.0/math.min.js"></script> |
| 21 | + <script src="https://cdnjs.cloudflare.com/ajax/libs/plotly.js/2.27.0/plotly.min.js"></script> |
| 22 | + |
| 23 | + <!-- Link to the CSS files --> |
| 24 | + <link href="https://feascript.com/FEAScript-website.css" rel="stylesheet" type="text/css" /> |
| 25 | + <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet" /> |
| 26 | + </head> |
| 27 | + |
| 28 | + <body> |
| 29 | + <h1>Heat Conduction in a Two-Dimensional Fin Example (Gmsh)</h1> |
| 30 | + <div id="solutionPlot"></div> |
| 31 | + |
| 32 | + <p> |
| 33 | + This example demonstrates solving a steady-state heat transfer problem in a 2D rectangular domain using |
| 34 | + a Gmsh-generated mesh (<a href="./rect_quad_unstruct.msh">rect_quad_unstruct.msh</a>). The mesh |
| 35 | + configuration and boundary conditions are defined directly within the JavaScript code. Please refresh |
| 36 | + the page to update the results. Detailed instructions for this example can be found in the corresponding |
| 37 | + <a href="https://feascript.com/tutorials/HeatConduction2DFinGmsh.html" target="_blank" |
| 38 | + >FEAScript tutorial</a |
| 39 | + >. If you need further assistance, you can visit the |
| 40 | + <a href="https://feascript.com/" target="_blank">FEAScript website</a>. |
| 41 | + </p> |
| 42 | + |
| 43 | + <p>© 2023-<span id="currentYear"></span> FEAScript</p> |
| 44 | + <script> |
| 45 | + document.getElementById("currentYear").innerHTML = new Date().getFullYear(); |
| 46 | + </script> |
| 47 | + |
| 48 | + <script type="module"> |
| 49 | + import { |
| 50 | + FEAScriptModel, |
| 51 | + importGmshQuadTri, |
| 52 | + plotSolution, |
| 53 | + printVersion, |
| 54 | + } from "https://core.feascript.com/src/index.js"; |
| 55 | + |
| 56 | + window.addEventListener("DOMContentLoaded", async () => { |
| 57 | + // Print FEAScript version in the console |
| 58 | + printVersion(); |
| 59 | + |
| 60 | + // Fetch the mesh file |
| 61 | + const response = await fetch("./rect_quad_unstruct.msh"); // .msh version 4.1 is supported |
| 62 | + if (!response.ok) { |
| 63 | + throw new Error(`Failed to load mesh file: ${response.status} ${response.statusText}`); |
| 64 | + } |
| 65 | + const meshContent = await response.text(); |
| 66 | + |
| 67 | + // Create a File object with the actual content |
| 68 | + const meshFile = new File([meshContent], "rect_quad_unstruct.msh"); |
| 69 | + |
| 70 | + // Create a new FEAScript model |
| 71 | + const model = new FEAScriptModel(); |
| 72 | + |
| 73 | + // Set solver configuration |
| 74 | + model.setSolverConfig("solidHeatTransferScript"); |
| 75 | + |
| 76 | + // Parse the mesh file |
| 77 | + const result = await importGmshQuadTri(meshFile); |
| 78 | + |
| 79 | + // Define mesh configuration with the parsed result |
| 80 | + model.setMeshConfig({ |
| 81 | + parsedMesh: result, |
| 82 | + meshDimension: "2D", |
| 83 | + elementOrder: "quadratic", |
| 84 | + }); |
| 85 | + |
| 86 | + // Define boundary conditions |
| 87 | + model.addBoundaryCondition("0", ["constantTemp", 200]); // bottom boundary |
| 88 | + model.addBoundaryCondition("1", ["constantTemp", 200]); // right boundary |
| 89 | + model.addBoundaryCondition("2", ["convection", 1, 20]); // top boundary |
| 90 | + model.addBoundaryCondition("3", ["symmetry"]); // left boundary |
| 91 | + |
| 92 | + // Solve the problem and get the solution |
| 93 | + const { solutionVector, nodesCoordinates } = model.solve(); |
| 94 | + |
| 95 | + // Plot the solution as a 2D contour plot |
| 96 | + plotSolution( |
| 97 | + solutionVector, |
| 98 | + nodesCoordinates, |
| 99 | + model.solverConfig, |
| 100 | + model.meshConfig.meshDimension, |
| 101 | + "contour", |
| 102 | + "solutionPlot", |
| 103 | + "unstructured" |
| 104 | + ); |
| 105 | + }); |
| 106 | + </script> |
| 107 | + </body> |
| 108 | +</html> |
0 commit comments