@@ -24,7 +24,7 @@ export class meshGeneration {
2424 * @param {number } [config.numElementsY=1] - Number of elements along the y-axis (for 1D meshes)
2525 * @param {number } [config.maxY=0] - Maximum y-coordinate of the mesh (for 1D meshes)
2626 * @param {string } [config.meshDimension='2D'] - The dimension of the mesh, either 1D or 2D
27- * @param {string|File } [config.meshFile=null] - Optional mesh file for predefined meshes (.json or . msh)
27+ * @param {string|File } [config.meshFile=null] - Optional mesh file for predefined meshes (.msh)
2828 * @param {string } [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'
2929 */
3030 constructor ( {
@@ -46,14 +46,20 @@ export class meshGeneration {
4646 }
4747
4848 /**
49- * Function to generate the mesh based on the dimension or custom mesh file
49+ * Function to generate the mesh based on the dimension or parse a custom mesh file
5050 * @returns {object } The generated mesh containing node coordinates and total nodes
5151 */
5252 generateMesh ( ) {
5353 if ( this . meshFile ) {
54- // If a custom mesh file is provided, read and parse it
55- const meshData = this . generateMeshFromCustomFile ( this . meshFile ) ;
56- return meshData ;
54+ // If a mesh file is provided, check if it's a Gmsh (.msh) file and parse it
55+ if ( ( typeof this . meshFile === 'string' && this . meshFile . toLowerCase ( ) . endsWith ( '.msh' ) ) ||
56+ ( this . meshFile instanceof File && this . meshFile . name . toLowerCase ( ) . endsWith ( '.msh' ) ) ) {
57+ return this . generateMeshFromMshFile ( this . meshFile ) ;
58+ } else {
59+ const errorMessage = "Only .msh files are supported for mesh import" ;
60+ errorLog ( errorMessage ) ;
61+ throw new Error ( errorMessage ) ;
62+ }
5763 } else {
5864 // Validate required geometry parameters based on mesh dimension
5965 if ( this . meshDimension === "1D" ) {
@@ -83,40 +89,13 @@ export class meshGeneration {
8389 }
8490
8591 /**
86- * Function to parse a custom mesh JSON file and generate the mesh
87- * @param {string } meshFilePath - Path to the custom mesh file (JSON format)
88- * @returns {object } Mesh data containing coordinates and connectivity
89- */
90- generateMeshFromCustomFile ( meshFilePath ) {
91- const response = fetch ( meshFilePath ) ;
92- const meshData = response . json ( ) ;
93-
94- const nodesXCoordinates = [ ] ;
95- const nodesYCoordinates = [ ] ;
96- const { nodes, elements } = meshData ;
97-
98- // Parse the node coordinates
99- nodes . forEach ( ( node ) => {
100- nodesXCoordinates . push ( node . x ) ;
101- nodesYCoordinates . push ( node . y ) ;
102- } ) ;
103-
104- return {
105- nodesXCoordinates,
106- nodesYCoordinates,
107- totalNodesX : nodesXCoordinates . length ,
108- totalNodesY : nodesYCoordinates . length ,
109- elements,
110- } ;
111- }
112-
113- /**
114- * Function to generate a structured mesh based on the msh file
92+ * Function to import a mesh from a Gmsh (.msh) file
93+ * @param {string|File } file - Path or File object to the mesh file (.msh format)
11594 * @returns {object } An object containing the coordinates of nodes,
11695 * total number of nodes, nodal numbering (NOP) array, and boundary elements
11796 */
11897 async generateMeshFromMshFile ( file ) {
119- //for now i have made a parsing of simple quadrilateral .msh file of version 4.1
98+ // Import mesh data from the Gmsh file
12099 const outputMesh = await importGmshQuadTri ( file ) ;
121100
122101 return outputMesh ;
0 commit comments