8
8
// |_| | |_ //
9
9
// Website: https://feascript.com/ \__| //
10
10
11
+ // Internal imports
12
+ import { basicLog , debugLog , errorLog } from "../utilities/loggingScript.js" ;
13
+
11
14
/**
12
15
* Function to import mesh data from Gmsh format containing quadrilateral and triangular elements
13
16
* @param {File } file - The Gmsh file to be parsed (.msh version 4.1)
@@ -21,7 +24,7 @@ const importGmshQuadTri = async (file) => {
21
24
quadElements : [ ] ,
22
25
triangleElements : [ ] ,
23
26
} ,
24
- boundaryElements : [ ] , // Will be initialized as array of arrays below
27
+ boundaryElements : [ ] ,
25
28
boundaryConditions : [ ] ,
26
29
gmshV : 0 ,
27
30
ascii : false ,
@@ -32,11 +35,6 @@ const importGmshQuadTri = async (file) => {
32
35
elementTypes : { } ,
33
36
} ;
34
37
35
- // Initialize boundaryElements as an array of 4 empty arrays (one for each side)
36
- for ( let i = 0 ; i < 4 ; i ++ ) {
37
- result . boundaryElements [ i ] = [ ] ;
38
- }
39
-
40
38
let content = await file . text ( ) ;
41
39
let lines = content
42
40
. split ( "\n" )
@@ -258,68 +256,40 @@ const importGmshQuadTri = async (file) => {
258
256
tag : prop . tag ,
259
257
nodes : boundaryNodes ,
260
258
} ) ;
259
+
260
+ // Initialize boundary element array based on the number of PhysicalNames
261
+ if ( ! result . boundaryElements [ prop . tag ] ) {
262
+ result . boundaryElements [ prop . tag ] = [ ] ;
263
+ }
264
+ // TODO: Calculate the boundaryElements based on boundaryElementsByTag and nodalNumbering
265
+ // NEXT TODO: Remap nodalNumbering according to https://gmsh.info/doc/texinfo/gmsh.html#Node-ordering.
266
+ // In the case of quadrilaterals, the order is:
267
+ /**
268
+ * Gmsh quadrilateral node numbering (linear elements):
269
+ *
270
+ * 3__ __2
271
+ * | |
272
+ * |__ __|
273
+ * 0 1
274
+ *
275
+ * FEAScript quadrilateral node numbering:
276
+ *
277
+ * 1__ __3
278
+ * | |
279
+ * |__ __|
280
+ * 0 2
281
+ *
282
+ * Remapping:
283
+ * - 0 (bottom left): stays as 0
284
+ * - 3 (top left): becomes 1
285
+ * - 1 (bottom right): becomes 2
286
+ * - 2 (top right): becomes 3
287
+ */
261
288
}
262
289
}
263
290
} ) ;
264
291
265
- processBoundaryElements ( result . nodalNumbering . triangleElements , result . boundaryElements , 3 , "triangle" ) ;
266
- processBoundaryElements ( result . nodalNumbering . quadElements , result . boundaryElements , 4 , "quad" ) ;
267
-
268
292
return result ;
269
293
} ;
270
294
271
- /**
272
- * Function to process boundary elements from a mesh
273
- * @param {array } elements - Array of elements to process
274
- * @param {array } boundaryElements - Array to store the boundary elements
275
- * @param {number } numNodes - Number of nodes per element
276
- * @param {string } elementType - Type of element (triangle, quad)
277
- */
278
- function processBoundaryElements ( elements , boundaryElements , numNodes , elementType ) {
279
- const edgeCount = { } ;
280
-
281
- // Count occurrences of each edge
282
- for ( let i = 0 ; i < elements . length ; i ++ ) {
283
- const element = elements [ i ] ;
284
-
285
- for ( let j = 0 ; j < numNodes ; j ++ ) {
286
- const node1 = element [ j ] ;
287
- const node2 = element [ ( j + 1 ) % numNodes ] ;
288
-
289
- const edgeKey = node1 < node2 ? `${ node1 } -${ node2 } ` : `${ node2 } -${ node1 } ` ;
290
-
291
- edgeCount [ edgeKey ] = ( edgeCount [ edgeKey ] || 0 ) + 1 ;
292
- }
293
- }
294
-
295
- // Process boundary edges
296
- for ( let i = 0 ; i < elements . length ; i ++ ) {
297
- const element = elements [ i ] ;
298
-
299
- for ( let j = 0 ; j < numNodes ; j ++ ) {
300
- const node1 = element [ j ] ;
301
- const node2 = element [ ( j + 1 ) % numNodes ] ;
302
-
303
- const edgeKey = node1 < node2 ? `${ node1 } -${ node2 } ` : `${ node2 } -${ node1 } ` ;
304
-
305
- if ( edgeCount [ edgeKey ] === 1 ) { // Boundary edge
306
- // Map local edge index to side index (0: bottom, 1: left, 2: top, 3: right)
307
- let sideIndex ;
308
-
309
- if ( elementType === "quad" ) {
310
- // For quadrilateral elements
311
- // Gmsh format: 0 → bottom, 1 → right, 2 → top, 3 → left
312
- // Adjusted to match the FEAScript format: 0 → bottom, 1 → left, 2 → top, 3 → right
313
- const sideMap = [ 0 , 3 , 2 , 1 ] ;
314
- sideIndex = sideMap [ j ] ;
315
- } else if ( elementType === "triangle" ) {
316
- // For triangular elements
317
- }
318
-
319
- boundaryElements [ sideIndex ] . push ( [ i , j ] ) ;
320
- }
321
- }
322
- }
323
- }
324
-
325
295
export { importGmshQuadTri } ;
0 commit comments