@@ -101,6 +101,8 @@ <h2 id="gmshfileimport"><a name="gmshfileimport"></a>Gmsh File Import</h2>
101101
102102 < h2 id ="results "> < a name ="results "> </ a > Results</ h2 >
103103
104+ < div id ="solutionPlot "> </ div >
105+
104106 < ul id ="menu ">
105107 < li >
106108 < a href ="https://feascript.com/tutorials/HeatConduction2DFin.html " target ="_blank "
@@ -113,44 +115,61 @@ <h2 id="results"><a name="results"></a>Results</h2>
113115 </ ul >
114116
115117 < script type ="module ">
118+ // Import FEAScript library from GitHub
116119 import { FEAScriptModel , plotSolution , printVersion } from "https://core.feascript.com/src/index.js" ;
120+ import { importGmshQuadTri } from "https://core.feascript.com/src/readers/gmshReaderScript.js" ;
121+ // Import FEAScript library from a local directory
122+ //import { FEAScriptModel, plotSolution, printVersion } from "../../FEAScript-core/src/index.js";
123+ //import { importGmshQuadTri } from "../../FEAScript-core/src/readers/gmshReaderScript.js";
117124
118- window . addEventListener ( "DOMContentLoaded" , ( ) => {
125+ window . addEventListener ( "DOMContentLoaded" , async ( ) => {
119126 // Print FEAScript version in the console
120127 printVersion ( ) ;
121128
129+ // Fetch the mesh file from your server
130+ const response = await fetch ( "./rect_quad.msh" ) ;
131+ if ( ! response . ok ) {
132+ throw new Error ( `Failed to load mesh file: ${ response . status } ${ response . statusText } ` ) ;
133+ }
134+ const meshContent = await response . text ( ) ;
135+
136+ // Create a File object with the actual content
137+ const meshFile = new File ( [ meshContent ] , "rect_quad.msh" ) ;
138+
122139 // Create a new FEAScript model
123140 const model = new FEAScriptModel ( ) ;
124-
141+
125142 // Set solver configuration
126143 model . setSolverConfig ( "solidHeatTransferScript" ) ;
127-
128- // Define mesh configuration
144+
145+ // Parse the mesh file first
146+ const result = await importGmshQuadTri ( meshFile ) ;
147+
148+ // Fix nodal numbering format for the solver
149+ if ( result . nodalNumbering . quadElements && result . nodalNumbering . quadElements . length > 0 ) {
150+ result . nodalNumbering = result . nodalNumbering . quadElements ;
151+ } else if ( result . nodalNumbering . triangleElements && result . nodalNumbering . triangleElements . length > 0 ) {
152+ result . nodalNumbering = result . nodalNumbering . triangleElements ;
153+ }
154+
155+ // Define mesh configuration with the parsed result
129156 model . setMeshConfig ( {
130- meshFile : "rect_quad"
157+ parsedMesh : result ,
158+ meshDimension : "2D" ,
159+ elementOrder : "linear"
131160 } ) ;
132161
133- // Define boundary conditions
134- model . addBoundaryCondition ( "0 " , [ "constantTemp" , 200 ] ) ;
135- model . addBoundaryCondition ( "1 " , [ "symmetry" ] ) ;
136- model . addBoundaryCondition ( "2 " , [ "convection" , 1 , 20 ] ) ;
137- model . addBoundaryCondition ( "3 " , [ "constantTemp" , 200 ] ) ;
162+ // Define boundary conditions using Gmsh physical group tags
163+ model . addBoundaryCondition ( "1 " , [ "constantTemp" , 200 ] ) ; // bottom boundary
164+ model . addBoundaryCondition ( "4 " , [ "symmetry" ] ) ; // left boundary
165+ model . addBoundaryCondition ( "3 " , [ "convection" , 1 , 20 ] ) ; // top boundary
166+ model . addBoundaryCondition ( "2 " , [ "constantTemp" , 200 ] ) ; // right boundary
138167
139- // Set solver method (optional) - 'lusolve' uses LU decomposition
168+ // Set solver method
140169 model . setSolverMethod ( "lusolve" ) ;
141170
142171 // Solve the problem and get the solution
143- const { solutionVector, nodesCoordinates } = model . solve ( ) ;
144-
145- // Plot the solution as a 2D contour plot
146- plotSolution (
147- solutionVector ,
148- nodesCoordinates ,
149- model . solverConfig ,
150- model . meshConfig . meshDimension ,
151- "contour" ,
152- "solutionPlot"
153- ) ;
172+ //const { solutionVector, nodesCoordinates } = model.solve();
154173 } ) ;
155174 </ script >
156175
0 commit comments