Skip to content

Commit 7719d8c

Browse files
committed
Update mesh generation to support pre-parsed mesh data and improve logging for mesh size calculations
1 parent 6608afc commit 7719d8c

File tree

3 files changed

+30
-38
lines changed

3 files changed

+30
-38
lines changed

src/FEAScript.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ export class FEAScriptModel {
3737
setMeshConfig(meshConfig) {
3838
this.meshConfig = meshConfig;
3939
debugLog(
40-
`Mesh config set with dimensions: ${meshConfig.meshDimension}, elements: ${meshConfig.numElementsX}x${
41-
meshConfig.numElementsY || 1
42-
}`
40+
`Mesh config set with dimensions: ${meshConfig.meshDimension}`
4341
);
4442
}
4543

src/mesh/meshGenerationScript.js

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,35 @@ 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 (.msh)
2827
* @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'
28+
* @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data
2929
*/
3030
constructor({
3131
numElementsX = null,
3232
maxX = null,
3333
numElementsY = null,
3434
maxY = null,
3535
meshDimension = null,
36-
meshFile = null,
3736
elementOrder = "linear",
37+
parsedMesh = null,
3838
}) {
3939
this.numElementsX = numElementsX;
4040
this.numElementsY = numElementsY;
4141
this.maxX = maxX;
4242
this.maxY = maxY;
4343
this.meshDimension = meshDimension;
44-
this.meshFile = meshFile;
4544
this.elementOrder = elementOrder;
45+
this.parsedMesh = parsedMesh;
4646
}
4747

4848
/**
49-
* Function to generate the mesh based on the dimension or parse a custom mesh file
49+
* Function to generate the mesh based on the dimension or use a pre-parsed mesh
5050
* @returns {object} The generated mesh containing node coordinates and total nodes
5151
*/
5252
generateMesh() {
53-
if (this.meshFile) {
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-
}
53+
// If pre-parsed mesh data is provided, use it directly
54+
if (this.parsedMesh) {
55+
return this.parsedMesh;
6356
} else {
6457
// Validate required geometry parameters based on mesh dimension
6558
if (this.meshDimension === "1D") {
@@ -88,19 +81,6 @@ export class meshGeneration {
8881
}
8982
}
9083

91-
/**
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)
94-
* @returns {object} An object containing the coordinates of nodes,
95-
* total number of nodes, nodal numbering (NOP) array, and boundary elements
96-
*/
97-
async generateMeshFromMshFile(file) {
98-
// Import mesh data from the Gmsh file
99-
const outputMesh = await importGmshQuadTri(file);
100-
101-
return outputMesh;
102-
}
103-
10484
/**
10585
* Function to generate a structured mesh based on the geometry configuration
10686
* @returns {object} An object containing the coordinates of nodes,

src/solvers/solidHeatTransferScript.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,9 @@ export function assembleSolidHeatTransferMat(meshConfig, boundaryConditions) {
3535
maxX, // Max x-coordinate (m) of the domain
3636
maxY, // Max y-coordinate (m) of the domain (only for 2D)
3737
elementOrder, // The order of elements
38+
parsedMesh, // The pre-parsed mesh data (if available)
3839
} = meshConfig;
3940

40-
debugLog(
41-
`Mesh configuration: ${meshDimension}, Elements: ${numElementsX}x${numElementsY || 1}, Size: ${maxX}x${
42-
maxY || 0
43-
}, Order: ${elementOrder}`
44-
);
45-
4641
// Create a new instance of the meshGeneration class
4742
debugLog("Generating mesh...");
4843
const meshGenerationData = new meshGeneration({
@@ -52,6 +47,7 @@ export function assembleSolidHeatTransferMat(meshConfig, boundaryConditions) {
5247
maxY,
5348
meshDimension,
5449
elementOrder,
50+
parsedMesh, // Pass the parsed mesh to the mesh generator
5551
});
5652

5753
// Generate the mesh
@@ -65,9 +61,27 @@ export function assembleSolidHeatTransferMat(meshConfig, boundaryConditions) {
6561
let nop = nodesCoordinatesAndNumbering.nodalNumbering;
6662
let boundaryElements = nodesCoordinatesAndNumbering.boundaryElements;
6763

64+
// Check the mesh type
65+
const isParsedMesh = parsedMesh !== undefined && parsedMesh !== null;
66+
67+
// Calculate totalElements and totalNodes based on mesh type
68+
let totalElements, totalNodes;
69+
70+
if (isParsedMesh) {
71+
totalElements = nop.length; // Number of elements is the length of the nodal numbering array
72+
totalNodes = nodesXCoordinates.length; // Number of nodes is the length of the coordinates array
73+
74+
// Debug log for mesh size
75+
debugLog(`Using parsed mesh with ${totalElements} elements and ${totalNodes} nodes`);
76+
} else {
77+
// For structured mesh, calculate based on dimensions
78+
totalElements = numElementsX * (meshDimension === "2D" ? numElementsY : 1);
79+
totalNodes = totalNodesX * (meshDimension === "2D" ? totalNodesY : 1);
80+
// Debug log for mesh size
81+
debugLog(`Using mesh generated from geometry with ${totalElements} elements and ${totalNodes} nodes`);
82+
}
83+
6884
// Initialize variables for matrix assembly
69-
const totalElements = numElementsX * (meshDimension === "2D" ? numElementsY : 1); // Total number of elements
70-
const totalNodes = totalNodesX * (meshDimension === "2D" ? totalNodesY : 1); // Total number of nodes
7185
let localNodalNumbers = []; // Local nodal numbering
7286
let gaussPoints = []; // Gauss points
7387
let gaussWeights = []; // Gauss weights

0 commit comments

Comments
 (0)