Skip to content

Commit bcec128

Browse files
committed
Refine boundary element handling in gmshReaderScript. Still some tasks TODO
1 parent fdb3e1d commit bcec128

File tree

5 files changed

+50
-71
lines changed

5 files changed

+50
-71
lines changed

src/FEAScript.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// Internal imports
1212
import { jacobiMethod } from "./methods/jacobiMethodScript.js";
1313
import { assembleSolidHeatTransferMat } from "./solvers/solidHeatTransferScript.js";
14-
import { basicLog, debugLog } from "./utilities/loggingScript.js";
14+
import { basicLog, debugLog, errorLog } from "./utilities/loggingScript.js";
1515

1616
/**
1717
* Class to implement finite element analysis in JavaScript

src/mesh/basisFunctionsScript.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// |_| | |_ //
99
// Website: https://feascript.com/ \__| //
1010

11+
// Internal imports
12+
import { basicLog, debugLog, errorLog } from "../utilities/loggingScript.js";
13+
1114
/**
1215
* Class to handle basis functions and their derivatives based on element configuration
1316
*/
@@ -58,7 +61,7 @@ export class basisFunctions {
5861
}
5962
} else if (this.meshDimension === "2D") {
6063
if (eta === null) {
61-
console.log("Eta coordinate is required for 2D elements");
64+
errorLog("Eta coordinate is required for 2D elements");
6265
return;
6366
}
6467

src/mesh/meshGenerationScript.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// Website: https://feascript.com/ \__| //
1010

1111
// Internal imports
12-
import { errorLog } from "../utilities/loggingScript.js";
12+
import { basicLog, debugLog, errorLog } from "../utilities/loggingScript.js";
1313

1414
/**
1515
* Class to handle the generation of structured finite element meshes
@@ -24,7 +24,7 @@ export class meshGeneration {
2424
* @param {number} [config.maxY=0] - Maximum y-coordinate of the mesh (for 1D meshes)
2525
* @param {string} [config.meshDimension='2D'] - The dimension of the mesh, either 1D or 2D
2626
* @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'
27-
* @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data
27+
* @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data
2828
*/
2929
constructor({
3030
numElementsX = null,
@@ -196,17 +196,23 @@ export class meshGeneration {
196196
}
197197

198198
/**
199-
* Function to find the elements that belong to each boundary for a simple rectangular domain
199+
* Function to find the elements that belong to each boundary for a simple domain
200200
* @returns {array} An array containing arrays of elements and their adjacent boundary side for each boundary
201-
* Each element in the array is of the form [elementIndex, side], where side for a rectangular element is:
201+
* Each element in the array is of the form [elementIndex, side], where:
202+
*
203+
* For 1D domains (line segments):
204+
* 0 - Left endpoint
205+
* 1 - Right endpoint
206+
*
207+
* For 2D domains (rectangular):
202208
* 0 - Bottom side
203209
* 1 - Left side
204210
* 2 - Top side
205211
* 3 - Right side
206212
*/
207213
findBoundaryElements() {
208214
const boundaryElements = [];
209-
const maxSides = 4; // Number of sides of the reference element
215+
const maxSides = this.meshDimension === "1D" ? 2 : 4; // Number of element sides based on mesh dimension
210216
for (let sideIndex = 0; sideIndex < maxSides; sideIndex++) {
211217
boundaryElements.push([]);
212218
}

src/readers/gmshReaderScript.js

+33-63
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
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-
325295
export { importGmshQuadTri };

src/solvers/solidHeatTransferScript.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { numericalIntegration } from "../methods/numericalIntegrationScript.js";
1313
import { basisFunctions } from "../mesh/basisFunctionsScript.js";
1414
import { meshGeneration } from "../mesh/meshGenerationScript.js";
1515
import { ThermalBoundaryConditions } from "./thermalBoundaryConditionsScript.js";
16-
import { basicLog, debugLog } from "../utilities/loggingScript.js";
16+
import { basicLog, debugLog, errorLog } from "../utilities/loggingScript.js";
1717

1818
/**
1919
* Function to assemble the solid heat transfer matrix

0 commit comments

Comments
 (0)