Skip to content

Commit f89eedc

Browse files
committed
Refactor mesh configuration and helper functions: rename dimension to meshDimension, update element order handling, and improve version printing functionality
1 parent 558cf4e commit f89eedc

File tree

10 files changed

+67
-69
lines changed

10 files changed

+67
-69
lines changed

examples/solidHeatTransferScript/exampleSolidHeatTransfer01/FEAScriptExampleSolidHeatTransfer01.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,12 @@ <h1>Heat Conduction in a Two-Dimensional Fin</h1>
128128
import {
129129
FEAScript,
130130
plotSolution,
131-
FEAScriptVersion,
131+
printVersion,
132132
} from "https://feascript.github.io/FEAScript/src/index.js";
133133

134134
window.addEventListener("DOMContentLoaded", () => {
135135
// Print FEAScript version in the console
136-
FEAScriptVersion();
136+
printVersion();
137137
// Calculate solution and render plot once JSON data is loaded
138138
let { solutionVector, nodesCoordinates } = FEAScript(
139139
solverConfig,
@@ -145,7 +145,7 @@ <h1>Heat Conduction in a Two-Dimensional Fin</h1>
145145
solutionVector,
146146
nodesCoordinates,
147147
solverConfig,
148-
meshConfig.dimension,
148+
meshConfig.meshDimension,
149149
"contour"
150150
);
151151
});
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"dimension": "2D",
2+
"meshDimension": "2D",
3+
"elementOrder": "quadratic",
34
"numElementsX": 8,
45
"numElementsY": 4,
56
"maxX": 4,
6-
"maxY": 2,
7-
"order": "quadratic"
7+
"maxY": 2
88
}

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010

1111
export { FEAScript } from "./FEAScript.js";
1212
export { plotSolution } from "./visualization/plotSolutionScript.js";
13-
export { FEAScriptVersion } from "./utilities/helperFunctionsScript.js";
13+
export { printVersion } from "./utilities/helperFunctionsScript.js";

src/mesh/basisFunctionsScript.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
export class basisFunctions {
1515
/**
1616
* Constructor to initialize the basisFunctions class
17-
* @param {string} dimension - The dimension of the mesh
18-
* @param {string} order - The order of elements
17+
* @param {string} meshDimension - The dimension of the mesh
18+
* @param {string} elementOrder - The order of elements
1919
*/
20-
constructor({ dimension, order }) {
21-
this.dimension = dimension;
22-
this.order = order;
20+
constructor({ meshDimension, elementOrder }) {
21+
this.meshDimension = meshDimension;
22+
this.elementOrder = elementOrder;
2323
}
2424

2525
/**
@@ -36,16 +36,16 @@ export class basisFunctions {
3636
let basisFunctionDerivKsi = [];
3737
let basisFunctionDerivEta = [];
3838

39-
if (this.dimension === "1D") {
40-
if (this.order === 'linear') {
39+
if (this.meshDimension === "1D") {
40+
if (this.elementOrder === 'linear') {
4141
// Linear basis functions for 1D elements
4242
basisFunction[0] = 1 - ksi;
4343
basisFunction[1] = ksi;
4444

4545
// Derivatives of basis functions with respect to ksi
4646
basisFunctionDerivKsi[0] = -1;
4747
basisFunctionDerivKsi[1] = 1;
48-
} else if (this.order === 'quadratic') {
48+
} else if (this.elementOrder === 'quadratic') {
4949
// Quadratic basis functions for 1D elements
5050
basisFunction[0] = 1 - 3*ksi + 2*ksi**2;
5151
basisFunction[1] = 4*ksi - 4*ksi**2;
@@ -56,13 +56,13 @@ export class basisFunctions {
5656
basisFunctionDerivKsi[1] = 4 - 8*ksi;
5757
basisFunctionDerivKsi[2] = -1 + 4*ksi;
5858
}
59-
} else if (this.dimension === "2D") {
59+
} else if (this.meshDimension === "2D") {
6060
if (eta === null) {
6161
console.log("Eta coordinate is required for 2D elements");
6262
return;
6363
}
6464

65-
if (this.order === 'linear') {
65+
if (this.elementOrder === 'linear') {
6666
// Linear basis functions for 2D elements
6767
function l1(c) {
6868
return 1 - c;
@@ -94,7 +94,7 @@ export class basisFunctions {
9494
basisFunctionDerivEta[1] = l1(ksi) * dl2();
9595
basisFunctionDerivEta[2] = l2(ksi) * dl1();
9696
basisFunctionDerivEta[3] = l2(ksi) * dl2();
97-
} else if (this.order === 'quadratic') {
97+
} else if (this.elementOrder === 'quadratic') {
9898
// Quadratic basis functions for 2D elements
9999
function l1(c) {
100100
return 2 * c ** 2 - 3 * c + 1;

src/mesh/meshGenerationScript.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@ export class meshGeneration {
1919
* @param {number} config.maxX - Maximum x-coordinate of the mesh
2020
* @param {number} [config.numElementsY=1] - Number of elements along the y-axis (default is 1 for 1D meshes)
2121
* @param {number} [config.maxY=0] - Maximum y-coordinate of the mesh (default is 0 for 1D meshes)
22-
* @param {string} [config.dimension='2D'] - The dimension of the mesh, either 1D or 2D (default is 2D)
22+
* @param {string} [config.meshDimension='2D'] - The dimension of the mesh, either 1D or 2D (default is 2D)
2323
* @param {string} [config.meshFile=null] - Optional mesh file (JSON) for predefined meshes
24-
* @param {string} [config.order='linear'] - The order of elements, either 'linear' or 'quadratic' (default is 'linear')
24+
* @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic' (default is 'linear')
2525
*/
2626
constructor({
2727
numElementsX,
2828
maxX,
2929
numElementsY = 1,
3030
maxY = 0,
31-
dimension = "2D",
31+
meshDimension = "2D",
3232
meshFile = null,
33-
order = 'linear',
33+
elementOrder = 'linear',
3434
}) {
3535
this.numElementsX = numElementsX;
3636
this.numElementsY = numElementsY;
3737
this.maxX = maxX;
3838
this.maxY = maxY;
39-
this.dimension = dimension;
39+
this.meshDimension = meshDimension;
4040
this.meshFile = meshFile;
41-
this.order = order;
41+
this.elementOrder = elementOrder;
4242
}
4343

4444
/**
@@ -96,7 +96,7 @@ export class meshGeneration {
9696
const yStart = 0;
9797
let totalNodesX, totalNodesY, deltaX, deltaY;
9898

99-
if (this.dimension === "1D") {
99+
if (this.meshDimension === "1D") {
100100
totalNodesX = 2 * this.numElementsX + 1;
101101
deltaX = (this.maxX - xStart) / this.numElementsX;
102102

@@ -110,7 +110,7 @@ export class meshGeneration {
110110
const nodalNumbering = this.generateNodalNumbering(
111111
this.numElementsX,
112112
totalNodesX,
113-
this.order
113+
this.elementOrder
114114
);
115115

116116
// Find boundary elements
@@ -154,7 +154,7 @@ export class meshGeneration {
154154
this.numElementsY,
155155
totalNodesX,
156156
totalNodesY,
157-
this.order
157+
this.elementOrder
158158
);
159159

160160
// Find boundary elements
@@ -196,9 +196,9 @@ export class meshGeneration {
196196
boundaryElements.push([]);
197197
}
198198

199-
if (this.dimension === "1D") {
199+
if (this.meshDimension === "1D") {
200200
console.log("Unsupported dimension or element order");
201-
} else if (this.dimension === "2D") {
201+
} else if (this.meshDimension === "2D") {
202202
for (
203203
let elementIndexX = 0;
204204
elementIndexX < this.numElementsX;
@@ -212,9 +212,9 @@ export class meshGeneration {
212212
const elementIndex =
213213
elementIndexX * this.numElementsY + elementIndexY;
214214

215-
if (this.order === 'linear') {
215+
if (this.elementOrder === 'linear') {
216216
console.log("Unsupported dimension or element order");
217-
} else if (this.order === 'quadratic') {
217+
} else if (this.elementOrder === 'quadratic') {
218218
// Bottom boundary
219219
if (elementIndexY === 0) {
220220
boundaryElements[0].push([elementIndex, 0]);
@@ -249,23 +249,23 @@ export class meshGeneration {
249249
* @param {number} [numElementsY] - Number of elements along the y-axis (optional for 1D)
250250
* @param {number} totalNodesX - Total number of nodes along the x-axis
251251
* @param {number} [totalNodesY] - Total number of nodes along the y-axis (optional for 1D)
252-
* @param {string} order - The order of elements, either 'linear' or 'quadratic'
252+
* @param {string} elementOrder - The order of elements, either 'linear' or 'quadratic'
253253
* @returns {array} NOP - A two-dimensional array which represents the element-to-node connectivity for the entire mesh
254254
*/
255-
generateNodalNumbering(numElementsX, numElementsY, totalNodesX, totalNodesY, order) {
255+
generateNodalNumbering(numElementsX, numElementsY, totalNodesX, totalNodesY, elementOrder) {
256256
let elementIndex = 0;
257257
let nop = [];
258258

259-
if (this.dimension === "1D") {
260-
if (order === 'linear') {
259+
if (this.meshDimension === "1D") {
260+
if (elementOrder === 'linear') {
261261
console.log("Unsupported dimension or element order");
262-
} else if (order === 'quadratic') {
262+
} else if (elementOrder === 'quadratic') {
263263
console.log("Unsupported dimension or element order");
264264
}
265-
} else if (this.dimension === "2D") {
266-
if (order === 'linear') {
265+
} else if (this.meshDimension === "2D") {
266+
if (elementOrder === 'linear') {
267267
console.log("Unsupported dimension or element order");
268-
} else if (order === 'quadratic') {
268+
} else if (elementOrder === 'quadratic') {
269269
/**
270270
* Quadratic rectangular elements with the following nodes representation:
271271
*

src/methods/numericalIntegrationScript.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
export class numericalIntegration {
1515
/**
1616
* Constructor to initialize the numIntegration class
17-
* @param {string} dimension - The dimension of the mesh
18-
* @param {number} order - The order of elements
17+
* @param {string} meshDimension - The dimension of the mesh
18+
* @param {number} elementOrder - The order of elements
1919
*/
20-
constructor({ dimension, order }) {
21-
this.dimension = dimension;
22-
this.order = order;
20+
constructor({ meshDimension, elementOrder }) {
21+
this.meshDimension = meshDimension;
22+
this.elementOrder = elementOrder;
2323
}
2424

2525
/**
@@ -32,16 +32,16 @@ export class numericalIntegration {
3232
let gaussPoints = []; // Gauss points
3333
let gaussWeights = []; // Gauss weights
3434

35-
if (this.dimension === "1D") {
36-
if (this.order === 'linear') {
35+
if (this.meshDimension === "1D") {
36+
if (this.elementOrder === 'linear') {
3737
console.log("Unsupported dimension or element order");
38-
} else if (this.order === 'quadratic') {
38+
} else if (this.elementOrder === 'quadratic') {
3939
console.log("Unsupported dimension or element order");
4040
}
41-
} else if (this.dimension === "2D") {
42-
if (this.order === 'linear') {
41+
} else if (this.meshDimension === "2D") {
42+
if (this.elementOrder === 'linear') {
4343
console.log("Unsupported dimension or element order");
44-
} else if (this.order === 'quadratic') {
44+
} else if (this.elementOrder === 'quadratic') {
4545
// For 2D quadratic elements, use 3-point Gauss quadrature in each direction
4646
gaussPoints[0] = (1 - Math.sqrt(3 / 5)) / 2;
4747
gaussPoints[1] = 0.5;

src/methods/thermalBoundaryConditionsScript.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
* Class to handle thermal boundary conditions application
1313
*/
1414
export class ThermalBoundaryConditions {
15-
constructor(boundaryConditions, boundaryElements, nop, dimension) {
15+
constructor(boundaryConditions, boundaryElements, nop, meshDimension) {
1616
this.boundaryConditions = boundaryConditions;
1717
this.boundaryElements = boundaryElements;
1818
this.nop = nop;
19-
this.dimension = dimension;
19+
this.meshDimension = meshDimension;
2020
}
2121

2222
imposeConstantTempBoundaryConditions(residualVector, jacobianMatrix) {
23-
if (this.dimension === "2D") {
23+
if (this.meshDimension === "2D") {
2424
const boundarySides = {
2525
0: [0, 3, 6], // Nodes at the bottom side of the reference element
2626
1: [0, 1, 2], // Nodes at the left side of the reference element
@@ -60,7 +60,7 @@ export class ThermalBoundaryConditions {
6060
convectionHeatTranfCoeff,
6161
convectionExtTemp
6262
) {
63-
if (this.dimension === "2D") {
63+
if (this.meshDimension === "2D") {
6464
Object.keys(this.boundaryConditions).forEach((key) => {
6565
if (this.boundaryConditions[key][0] === "convection") {
6666
const convectionCoeff = convectionHeatTranfCoeff[key];

src/solvers/solidHeatTransferScript.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ import { ThermalBoundaryConditions } from "../methods/thermalBoundaryConditionsS
2525
export function assembleSolidHeatTransferMat(meshConfig, boundaryConditions) {
2626
// Extract mesh details from the configuration object
2727
const {
28-
dimension, // The dimension of the mesh
28+
meshDimension, // The dimension of the mesh
2929
numElementsX, // Number of elements in x-direction
3030
numElementsY, // Number of elements in y-direction
3131
maxX, // Max x-coordinate (m) of the domain
3232
maxY, // Max y-coordinate (m) of the domain
33-
order, // The order of elements
33+
elementOrder, // The order of elements
3434
} = meshConfig;
3535

3636
// Extract boundary conditions from the configuration object
@@ -50,8 +50,8 @@ export function assembleSolidHeatTransferMat(meshConfig, boundaryConditions) {
5050
numElementsY,
5151
maxX,
5252
maxY,
53-
dimension,
54-
order,
53+
meshDimension,
54+
elementOrder,
5555
});
5656

5757
// Generate the mesh
@@ -97,14 +97,14 @@ export function assembleSolidHeatTransferMat(meshConfig, boundaryConditions) {
9797

9898
// Initialize the basisFunctions class
9999
const basisFunctionsData = new basisFunctions({
100-
dimension,
101-
order,
100+
meshDimension,
101+
elementOrder,
102102
});
103103

104104
// Initialize the numericalIntegration class
105105
const numIntegrationData = new numericalIntegration({
106-
dimension,
107-
order,
106+
meshDimension,
107+
elementOrder,
108108
});
109109

110110
// Calculate Gauss points and weights
@@ -208,7 +208,7 @@ export function assembleSolidHeatTransferMat(meshConfig, boundaryConditions) {
208208
boundaryConditions,
209209
boundaryElements,
210210
nop,
211-
dimension
211+
meshDimension
212212
);
213213

214214
// Impose Convection boundary conditions

src/utilities/helperFunctionsScript.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* Function to handle version information and fetch the latest update date and release from GitHub
1313
*/
14-
export async function FEAScriptVersion() {
14+
export async function printVersion() {
1515
// Fetch the latest release information
1616
const releaseResponse = await fetch('https://api.github.com/repos/FEAScript/FEAScript/releases/latest');
1717
const releaseData = await releaseResponse.json();

src/visualization/plotSolutionScript.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,19 @@
88
// |_| | |_ //
99
// Website: https://feascript.com/ \__| //
1010

11-
import { FEAScript } from "../FEAScript.js";
12-
1311
/**
1412
* Create plots of the solution vector
1513
* @param {*} solutionVector - The computed solution vector
1614
* @param {*} nodesCoordinates - Object containing x and y coordinates for the nodes
1715
* @param {string} solverConfig - Parameter specifying the type of solver
18-
* @param {string} dimension - The dimension of the solution
16+
* @param {string} meshDimension - The dimension of the solution
1917
* @param {string} plotType - The type of plot
2018
*/
2119
export function plotSolution(
2220
solutionVector,
2321
nodesCoordinates,
2422
solverConfig,
25-
dimension,
23+
meshDimension,
2624
plotType
2725
) {
2826
const { nodesXCoordinates, nodesYCoordinates } = nodesCoordinates;
@@ -34,7 +32,7 @@ export function plotSolution(
3432
return;
3533
}
3634

37-
if (dimension === "2D" && plotType === "contour") {
35+
if (meshDimension === "2D" && plotType === "contour") {
3836
// Calculate the number of nodes along the x-axis and y-axis
3937
const numNodesX = new Set(nodesXCoordinates).size;
4038
const numNodesY = new Set(nodesYCoordinates).size;

0 commit comments

Comments
 (0)