88// |_| | |_ //
99// Website: https://feascript.com/ \__| //
1010
11+ // Internal imports
12+ import { basicLog , debugLog , errorLog } from "../utilities/loggingScript.js" ;
13+
1114/**
1215 * Function to import mesh data from Gmsh format containing quadrilateral and triangular elements
1316 * @param {File } file - The Gmsh file to be parsed (.msh version 4.1)
@@ -21,7 +24,7 @@ const importGmshQuadTri = async (file) => {
2124 quadElements : [ ] ,
2225 triangleElements : [ ] ,
2326 } ,
24- boundaryElements : [ ] , // Will be initialized as array of arrays below
27+ boundaryElements : [ ] ,
2528 boundaryConditions : [ ] ,
2629 gmshV : 0 ,
2730 ascii : false ,
@@ -32,11 +35,6 @@ const importGmshQuadTri = async (file) => {
3235 elementTypes : { } ,
3336 } ;
3437
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-
4038 let content = await file . text ( ) ;
4139 let lines = content
4240 . split ( "\n" )
@@ -258,68 +256,40 @@ const importGmshQuadTri = async (file) => {
258256 tag : prop . tag ,
259257 nodes : boundaryNodes ,
260258 } ) ;
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+ */
261288 }
262289 }
263290 } ) ;
264291
265- processBoundaryElements ( result . nodalNumbering . triangleElements , result . boundaryElements , 3 , "triangle" ) ;
266- processBoundaryElements ( result . nodalNumbering . quadElements , result . boundaryElements , 4 , "quad" ) ;
267-
268292 return result ;
269293} ;
270294
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-
325295export { importGmshQuadTri } ;
0 commit comments