@@ -117,75 +117,117 @@ <h2 id="results"><a name="results"></a>Results</h2>
117117 < script type ="module ">
118118 // Import FEAScript library from GitHub
119119 //import { FEAScriptModel, importGmshQuadTri, plotSolution, printVersion } from "https://core.feascript.com/src/index.js";
120- // Import FEAScript library from a local directory
121- import { FEAScriptModel , importGmshQuadTri , plotSolution , printVersion } from "../../FEAScript-core/src/index.js" ;
120+ // Import FEAScript library from a local directory
121+ import {
122+ FEAScriptModel ,
123+ importGmshQuadTri ,
124+ plotSolution ,
125+ printVersion ,
126+ } from "../../FEAScript-core/src/index.js" ;
122127
123128 window . addEventListener ( "DOMContentLoaded" , async ( ) => {
124129 // Print FEAScript version in the console
125130 printVersion ( ) ;
126131
132+ console . log ( "-------- GMSH MESH APPROACH --------" ) ;
127133 // Fetch the mesh file from your server
128134 const response = await fetch ( "./rect_quad.msh" ) ;
129135 if ( ! response . ok ) {
130136 throw new Error ( `Failed to load mesh file: ${ response . status } ${ response . statusText } ` ) ;
131137 }
132138 const meshContent = await response . text ( ) ;
133-
139+
134140 // Create a File object with the actual content
135141 const meshFile = new File ( [ meshContent ] , "rect_quad.msh" ) ;
136-
142+
137143 // Create a new FEAScript model
138- const model = new FEAScriptModel ( ) ;
139-
144+ const gmshModel = new FEAScriptModel ( ) ;
145+
140146 // Set solver configuration
141- model . setSolverConfig ( "solidHeatTransferScript" ) ;
142-
147+ gmshModel . setSolverConfig ( "solidHeatTransferScript" ) ;
148+
143149 // Parse the mesh file first
144150 const result = await importGmshQuadTri ( meshFile ) ;
145151
146- console . log ( "Boundary Conditions :" , result . boundaryConditions ) ;
152+ console . log ( "GMSH Boundary Elements :" , result . boundaryElements ) ;
147153
148154 // Fix nodal numbering format for the solver
149155 if ( result . nodalNumbering . quadElements && result . nodalNumbering . quadElements . length > 0 ) {
150156 result . nodalNumbering = result . nodalNumbering . quadElements ;
151- } else if ( result . nodalNumbering . triangleElements && result . nodalNumbering . triangleElements . length > 0 ) {
157+ } else if (
158+ result . nodalNumbering . triangleElements &&
159+ result . nodalNumbering . triangleElements . length > 0
160+ ) {
152161 result . nodalNumbering = result . nodalNumbering . triangleElements ;
153162 }
154163
155- console . log ( "Nodal Numbering:" , result . nodalNumbering ) ;
156-
157164 // Define mesh configuration with the parsed result
158- model . setMeshConfig ( {
165+ gmshModel . setMeshConfig ( {
159166 parsedMesh : result ,
160167 meshDimension : "2D" ,
161- elementOrder : "linear"
168+ elementOrder : "linear" ,
162169 } ) ;
163170
164171 // Define boundary conditions using Gmsh physical group tags
165- model . addBoundaryCondition ( "1" , [ "constantTemp" , 200 ] ) ; // bottom boundary
166- model . addBoundaryCondition ( "4" , [ "symmetry" ] ) ; // left boundary
167- model . addBoundaryCondition ( "3" , [ "convection" , 1 , 20 ] ) ; // top boundary
168- model . addBoundaryCondition ( "2" , [ "constantTemp" , 200 ] ) ; // right boundary
172+ gmshModel . addBoundaryCondition ( "1" , [ "constantTemp" , 200 ] ) ; // bottom boundary
173+ gmshModel . addBoundaryCondition ( "4" , [ "symmetry" ] ) ; // left boundary
174+ gmshModel . addBoundaryCondition ( "3" , [ "convection" , 1 , 20 ] ) ; // top boundary
175+ gmshModel . addBoundaryCondition ( "2" , [ "constantTemp" , 200 ] ) ; // right boundary
176+
177+ console . log ( "GMSH Boundary Conditions:" , gmshModel . boundaryConditions ) ;
169178
170179 // Set solver method
171- model . setSolverMethod ( "lusolve" ) ;
180+ //model.setSolverMethod("jacobi");
181+ gmshModel . setSolverMethod ( "lusolve" ) ;
172182
173183 // Solve the problem and get the solution
174- const { solutionVector, nodesCoordinates } = model . solve ( ) ;
184+ const { solutionVector : gmshSolutionVector , nodesCoordinates : gmshNodesCoordinates } = gmshModel . solve ( ) ;
175185
176- console . log ( "Solution Vector:" , solutionVector ) ;
177- console . log ( "Nodes Coordinates:" , nodesCoordinates ) ;
186+ console . log ( "GMSH Solution Vector:" , gmshSolutionVector ) ;
178187
179- // Add this code to display the contour plot
188+ // Plot the GMSH solution
180189 plotSolution (
181- solutionVector ,
182- nodesCoordinates ,
183- model . solverConfig ,
184- model . meshConfig . meshDimension ,
190+ gmshSolutionVector ,
191+ gmshNodesCoordinates ,
192+ gmshModel . solverConfig ,
193+ gmshModel . meshConfig . meshDimension ,
185194 "contour" ,
186195 "solutionPlot" ,
187196 "unstructured"
188197 ) ;
198+
199+ console . log ( "-------- GEOMETRY MESH APPROACH --------" ) ;
200+ // Create a new FEAScript model for the geometry-based mesh
201+ const geoModel = new FEAScriptModel ( ) ;
202+
203+ // Set solver configuration
204+ geoModel . setSolverConfig ( "solidHeatTransferScript" ) ;
205+
206+ // Define mesh configuration using geometry
207+ geoModel . setMeshConfig ( {
208+ meshDimension : "2D" ,
209+ elementOrder : "quadratic" ,
210+ numElementsX : 8 ,
211+ numElementsY : 4 ,
212+ maxX : 4 ,
213+ maxY : 2 ,
214+ } ) ;
215+
216+ // Define boundary conditions - equivalent to the GMSH setup
217+ geoModel . addBoundaryCondition ( "0" , [ "constantTemp" , 200 ] ) ; // bottom boundary
218+ geoModel . addBoundaryCondition ( "1" , [ "symmetry" ] ) ; // left boundary
219+ geoModel . addBoundaryCondition ( "2" , [ "convection" , 1 , 20 ] ) ; // top boundary
220+ geoModel . addBoundaryCondition ( "3" , [ "constantTemp" , 200 ] ) ; // right boundary
221+
222+ console . log ( "GEO Boundary Conditions:" , geoModel . boundaryConditions ) ;
223+
224+ // Set solver method
225+ //model.setSolverMethod("jacobi");
226+ geoModel . setSolverMethod ( "lusolve" ) ;
227+
228+ // Solve the problem and get the solution
229+ const { solutionVector : geoSolutionVector , nodesCoordinates : geoNodesCoordinates } = geoModel . solve ( ) ;
230+
189231 } ) ;
190232 </ script >
191233
0 commit comments