@@ -51,6 +51,155 @@ export class meshGeneration {
5151 generateMesh ( ) {
5252 // If pre-parsed mesh data is provided, use it directly
5353 if ( this . parsedMesh ) {
54+ // Process the nodalNumbering from gmshReader format to the format expected by the solver
55+ if ( this . parsedMesh . nodalNumbering ) {
56+ if (
57+ typeof this . parsedMesh . nodalNumbering === "object" &&
58+ ! Array . isArray ( this . parsedMesh . nodalNumbering )
59+ ) {
60+ // Store the nodal numbering structure before converting
61+ const quadElements = this . parsedMesh . nodalNumbering . quadElements || [ ] ;
62+ const triangleElements = this . parsedMesh . nodalNumbering . triangleElements || [ ] ;
63+
64+ console . log ( "Parsed mesh nodal numbering:" , this . parsedMesh . nodalNumbering ) ;
65+
66+ // Check if it has quadElements or triangleElements structure from gmshReader
67+ if ( quadElements && quadElements . length > 0 ) {
68+ // Map nodal numbering from GMSH format to FEAScript format for quad elements
69+ const mappedNodalNumbering = [ ] ;
70+
71+ for ( let elemIdx = 0 ; elemIdx < quadElements . length ; elemIdx ++ ) {
72+ const gmshNodes = quadElements [ elemIdx ] ;
73+ const feaScriptNodes = new Array ( gmshNodes . length ) ;
74+
75+ // Simple mapping for linear quad elements (4 nodes)
76+ // GMSH: FEAScript:
77+ // 3 --- 2 1 --- 3
78+ // | | | |
79+ // 0 --- 1 0 --- 2
80+
81+ feaScriptNodes [ 0 ] = gmshNodes [ 0 ] ; // 0 -> 0
82+ feaScriptNodes [ 1 ] = gmshNodes [ 3 ] ; // 3 -> 1
83+ feaScriptNodes [ 2 ] = gmshNodes [ 1 ] ; // 1 -> 2
84+ feaScriptNodes [ 3 ] = gmshNodes [ 2 ] ; // 2 -> 3
85+
86+ mappedNodalNumbering . push ( feaScriptNodes ) ;
87+ }
88+
89+ this . parsedMesh . nodalNumbering = mappedNodalNumbering ;
90+ } else if ( triangleElements && triangleElements . length > 0 ) {
91+ this . parsedMesh . nodalNumbering = triangleElements ;
92+ }
93+
94+ console . log ( "Mapped nodal numbering:" , this . parsedMesh . nodalNumbering ) ;
95+
96+ // Process boundary elements if they exist and if physical property mapping exists
97+ if ( this . parsedMesh . physicalPropMap && this . parsedMesh . boundaryElements ) {
98+ // Check if boundary elements need to be processed
99+ if (
100+ Array . isArray ( this . parsedMesh . boundaryElements ) &&
101+ this . parsedMesh . boundaryElements . length > 0 &&
102+ this . parsedMesh . boundaryElements [ 0 ] === undefined
103+ ) {
104+ // Create a new array without the empty first element
105+ const fixedBoundaryElements = [ ] ;
106+ for ( let i = 1 ; i < this . parsedMesh . boundaryElements . length ; i ++ ) {
107+ if ( this . parsedMesh . boundaryElements [ i ] ) {
108+ fixedBoundaryElements . push ( this . parsedMesh . boundaryElements [ i ] ) ;
109+ }
110+ }
111+ this . parsedMesh . boundaryElements = fixedBoundaryElements ;
112+ }
113+
114+ // If boundary node pairs exist but boundary elements haven't been processed
115+ if ( this . parsedMesh . boundaryNodePairs && ! this . parsedMesh . boundaryElementsProcessed ) {
116+ this . parsedMesh . boundaryElements = [ ] ;
117+
118+ this . parsedMesh . physicalPropMap . forEach ( ( prop ) => {
119+ if ( prop . dimension === 1 ) {
120+ const boundaryNodes = this . parsedMesh . boundaryNodePairs [ prop . tag ] || [ ] ;
121+
122+ if ( boundaryNodes . length > 0 ) {
123+ // Initialize boundary element array for this tag
124+ if ( ! this . parsedMesh . boundaryElements [ prop . tag ] ) {
125+ this . parsedMesh . boundaryElements [ prop . tag ] = [ ] ;
126+ }
127+
128+ // For each boundary line segment (2 nodes)
129+ boundaryNodes . forEach ( ( nodesPair ) => {
130+ // Find which element contains both nodes of this boundary
131+ let foundElement = false ;
132+ for ( let elemIdx = 0 ; elemIdx < this . parsedMesh . nodalNumbering . length ; elemIdx ++ ) {
133+ const elemNodes = this . parsedMesh . nodalNumbering [ elemIdx ] ;
134+
135+ // Check if both boundary nodes are in this element
136+ if ( elemNodes . includes ( nodesPair [ 0 ] ) && elemNodes . includes ( nodesPair [ 1 ] ) ) {
137+ // Find which side of the element these nodes form
138+ let side ;
139+
140+ // Using FEAScript orientation for sides
141+ // Side 0 (Bottom): nodes 0-2
142+ // Side 1 (Left): nodes 0-1
143+ // Side 2 (Top): nodes 1-3
144+ // Side 3 (Right): nodes 2-3
145+
146+ if (
147+ ( elemNodes . indexOf ( nodesPair [ 0 ] ) === 0 &&
148+ elemNodes . indexOf ( nodesPair [ 1 ] ) === 2 ) ||
149+ ( elemNodes . indexOf ( nodesPair [ 1 ] ) === 0 && elemNodes . indexOf ( nodesPair [ 0 ] ) === 2 )
150+ ) {
151+ side = 0 ; // Bottom side
152+ } else if (
153+ ( elemNodes . indexOf ( nodesPair [ 0 ] ) === 0 &&
154+ elemNodes . indexOf ( nodesPair [ 1 ] ) === 1 ) ||
155+ ( elemNodes . indexOf ( nodesPair [ 1 ] ) === 0 && elemNodes . indexOf ( nodesPair [ 0 ] ) === 1 )
156+ ) {
157+ side = 1 ; // Left side
158+ } else if (
159+ ( elemNodes . indexOf ( nodesPair [ 0 ] ) === 1 &&
160+ elemNodes . indexOf ( nodesPair [ 1 ] ) === 3 ) ||
161+ ( elemNodes . indexOf ( nodesPair [ 1 ] ) === 1 && elemNodes . indexOf ( nodesPair [ 0 ] ) === 3 )
162+ ) {
163+ side = 2 ; // Top side
164+ } else if (
165+ ( elemNodes . indexOf ( nodesPair [ 0 ] ) === 2 &&
166+ elemNodes . indexOf ( nodesPair [ 1 ] ) === 3 ) ||
167+ ( elemNodes . indexOf ( nodesPair [ 1 ] ) === 2 && elemNodes . indexOf ( nodesPair [ 0 ] ) === 3 )
168+ ) {
169+ side = 3 ; // Right side
170+ }
171+
172+ // Add to boundary elements
173+ this . parsedMesh . boundaryElements [ prop . tag ] . push ( [ elemIdx , side ] ) ;
174+ foundElement = true ;
175+ break ;
176+ }
177+ }
178+ } ) ;
179+ }
180+ }
181+ } ) ;
182+
183+ // Mark as processed
184+ this . parsedMesh . boundaryElementsProcessed = true ;
185+
186+ // Fix boundary elements array - remove undefined entries
187+ if (
188+ this . parsedMesh . boundaryElements . length > 0 &&
189+ this . parsedMesh . boundaryElements [ 0 ] === undefined
190+ ) {
191+ const fixedBoundaryElements = [ ] ;
192+ for ( let i = 1 ; i < this . parsedMesh . boundaryElements . length ; i ++ ) {
193+ if ( this . parsedMesh . boundaryElements [ i ] ) {
194+ fixedBoundaryElements . push ( this . parsedMesh . boundaryElements [ i ] ) ;
195+ }
196+ }
197+ this . parsedMesh . boundaryElements = fixedBoundaryElements ;
198+ }
199+ }
200+ }
201+ }
202+ }
54203 return this . parsedMesh ;
55204 } else {
56205 // Validate required geometry parameters based on mesh dimension
@@ -179,6 +328,9 @@ export class meshGeneration {
179328 // Find boundary elements
180329 const boundaryElements = this . findBoundaryElements ( ) ;
181330
331+ console . log ( "x coordinates of nodes:" , nodesXCoordinates ) ;
332+ console . log ( "y coordinates of nodes:" , nodesYCoordinates ) ;
333+
182334 // Return x and y coordinates of nodes, total nodes, NOP array, and boundary elements
183335 return {
184336 nodesXCoordinates,
0 commit comments