|
| 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 Example (Experimental)</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 | + |
| 27 | + <!-- Custom layout styles --> |
| 28 | + <style> |
| 29 | + .container { |
| 30 | + display: flex; |
| 31 | + flex-wrap: wrap; |
| 32 | + } |
| 33 | + |
| 34 | + .column { |
| 35 | + flex: 1 1 100%; |
| 36 | + padding: 20px; |
| 37 | + box-sizing: border-box; |
| 38 | + } |
| 39 | + |
| 40 | + @media (min-width: 768px) { |
| 41 | + .column { |
| 42 | + flex: 1 1 50%; |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + #solutionPlot { |
| 47 | + width: 100%; |
| 48 | + max-width: 800px; |
| 49 | + height: 500px; |
| 50 | + } |
| 51 | + |
| 52 | + #inputForm { |
| 53 | + margin-top: 20px; |
| 54 | + } |
| 55 | + |
| 56 | + #resultOutput { |
| 57 | + height: 500px; |
| 58 | + margin-top: 10px; |
| 59 | + padding: 10px; |
| 60 | + background: #f0f0f0; |
| 61 | + overflow: auto; |
| 62 | + border: 1px solid #ccc; |
| 63 | + white-space: pre-wrap; |
| 64 | + } |
| 65 | + |
| 66 | + .experimental-badge { |
| 67 | + background-color: #ff4500; |
| 68 | + color: white; |
| 69 | + padding: 3px 8px; |
| 70 | + border-radius: 3px; |
| 71 | + font-size: 0.8em; |
| 72 | + margin-left: 10px; |
| 73 | + vertical-align: middle; |
| 74 | + } |
| 75 | + |
| 76 | + h1 .experimental-badge { |
| 77 | + font-size: 0.5em; |
| 78 | + vertical-align: middle; |
| 79 | + } |
| 80 | + </style> |
| 81 | + </head> |
| 82 | + |
| 83 | + <body> |
| 84 | + <h1>Heat Conduction in a Two-Dimensional Fin Example <span class="experimental-badge">EXPERIMENTAL</span></h1> |
| 85 | + |
| 86 | + <div class="container"> |
| 87 | + <!-- Left Column: Simulation Content --> |
| 88 | + <div class="column"> |
| 89 | + <h2>Worker-Based Simulation</h2> |
| 90 | + <div id="solutionPlot"></div> |
| 91 | + |
| 92 | + <p> |
| 93 | + This is an experimental version using FEAWorkerScript and a larger mesh (36x18). |
| 94 | + The worker-based implementation enables better performance for larger simulations. |
| 95 | + Please refresh the page to update the results. If you need assistance, you can visit the |
| 96 | + <a href="https://feascript.com/" target="_blank">FEAScript website</a>. |
| 97 | + </p> |
| 98 | + |
| 99 | + <p> |
| 100 | + <a href="HeatConduction2DFin.html">View Standard Example</a> |
| 101 | + </p> |
| 102 | + |
| 103 | + <p>© 2023-<span id="currentYear"></span> FEAScript</p> |
| 104 | + </div> |
| 105 | + |
| 106 | + <!-- Right Column: File Upload & Output --> |
| 107 | + <div class="column"> |
| 108 | + <h2>GMSH File Import <span class="experimental-badge">BETA</span></h2> |
| 109 | + <form id="inputForm"> |
| 110 | + <label for="inputFile">Choose a .msh file:</label> |
| 111 | + <input |
| 112 | + type="file" |
| 113 | + id="inputFile" |
| 114 | + name="inputFile" |
| 115 | + accept=".msh" |
| 116 | + required |
| 117 | + /> |
| 118 | + </form> |
| 119 | + <div id="resultOutput">No file uploaded yet. Please select a GMSH (.msh) file.</div> |
| 120 | + </div> |
| 121 | + </div> |
| 122 | + |
| 123 | + <script> |
| 124 | + document.getElementById("currentYear").innerHTML = new Date().getFullYear(); |
| 125 | + </script> |
| 126 | + |
| 127 | + <!-- GMSH File Import Script --> |
| 128 | + <script type="module"> |
| 129 | + import { importGmshQuadTri } from "../../../src/readers/gmshQuadReader.js"; |
| 130 | + |
| 131 | + document.getElementById("inputFile").addEventListener("change", async function (e) { |
| 132 | + const file = e.target.files[0]; |
| 133 | + if (!file) return; |
| 134 | + |
| 135 | + try { |
| 136 | + document.getElementById("resultOutput").innerHTML = "Processing file..."; |
| 137 | + const res = await importGmshQuadTri(file); |
| 138 | + console.log(res); |
| 139 | + document.getElementById("resultOutput").innerHTML = JSON.stringify(res, null, 2); |
| 140 | + } catch (error) { |
| 141 | + document.getElementById("resultOutput").innerHTML = `Error processing file: ${error.message}`; |
| 142 | + } |
| 143 | + }); |
| 144 | + </script> |
| 145 | + |
| 146 | + <!-- Worker-Based Simulation Script --> |
| 147 | + <script type="module"> |
| 148 | + import { |
| 149 | + plotSolution, |
| 150 | + printVersion |
| 151 | + } from "https://feascript.github.io/FEAScript-core/src/index.js"; |
| 152 | + |
| 153 | + import { FEAWorkerScript } from "../../../src/FEAWorkerScript.js"; |
| 154 | + |
| 155 | + window.addEventListener("DOMContentLoaded", async () => { |
| 156 | + try { |
| 157 | + // Print FEAScript version in the console |
| 158 | + printVersion(); |
| 159 | + |
| 160 | + // Create a new FEAScript model |
| 161 | + const model = new FEAWorkerScript(); |
| 162 | + |
| 163 | + // Ensure the worker is ready |
| 164 | + await model.ping(); |
| 165 | + |
| 166 | + // Set solver configuration |
| 167 | + await model.setSolverConfig("solidHeatTransferScript"); |
| 168 | + |
| 169 | + // Define mesh configuration |
| 170 | + await model.setMeshConfig({ |
| 171 | + meshDimension: "2D", |
| 172 | + elementOrder: "quadratic", |
| 173 | + numElementsX: 36, |
| 174 | + numElementsY: 18, |
| 175 | + maxX: 125, |
| 176 | + maxY: 50, |
| 177 | + }); |
| 178 | + |
| 179 | + // Define boundary conditions |
| 180 | + await model.addBoundaryCondition("0", ["constantTemp", 200]); |
| 181 | + await model.addBoundaryCondition("1", ["symmetry"]); |
| 182 | + await model.addBoundaryCondition("2", ["convection", 1, 20]); |
| 183 | + await model.addBoundaryCondition("3", ["constantTemp", 200]); |
| 184 | + |
| 185 | + // Set solver method (optional) - 'lusolve' uses LU decomposition |
| 186 | + await model.setSolverMethod("lusolve"); |
| 187 | + |
| 188 | + // Solve the problem and get the solution |
| 189 | + const { solutionVector, nodesCoordinates } = await model.solve(); |
| 190 | + |
| 191 | + // Plot the solution as a 2D contour plot |
| 192 | + plotSolution( |
| 193 | + solutionVector, |
| 194 | + nodesCoordinates, |
| 195 | + "solidHeatTransferScript", |
| 196 | + "2D", |
| 197 | + "contour", |
| 198 | + "solutionPlot" |
| 199 | + ); |
| 200 | + |
| 201 | + // Terminate the worker when done |
| 202 | + model.terminate(); |
| 203 | + } catch (error) { |
| 204 | + console.error("Error in experimental features:", error); |
| 205 | + document.getElementById("solutionPlot").innerHTML = |
| 206 | + `<div style="color: red; padding: 20px;">Error running simulation: ${error.message}</div>`; |
| 207 | + } |
| 208 | + }); |
| 209 | + </script> |
| 210 | + </body> |
| 211 | +</html> |
0 commit comments