Skip to content

Commit a910d97

Browse files
committed
Refactor helper functions and update documentation: improve version logging, enhance CORS instructions in HTML and README, and remove unused numerical integration script. Implement imposeConvectionBoundaryConditions function and refactor boundary condition handling in solidHeatTransferScript.js. Rename variables to be more appropriate and consistent.
1 parent 89f3637 commit a910d97

File tree

7 files changed

+321
-253
lines changed

7 files changed

+321
-253
lines changed

examples/solidHeatTransferScript/exampleSolidHeatTransfer01/FEAScriptExampleSolidHeatTransfer01.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ <h1>Heat Conduction in a Two-Dimensional Fin</h1>
7575
</p>
7676

7777
<p>
78-
This example requires Cross-Origin Resource Sharing (CORS) to run. To
79-
enable CORS on Firefox, you can follow these steps:
78+
This example requires Cross-Origin Resource Sharing (CORS) to run if the
79+
JSON files are stored locally. To enable CORS on Firefox, you can follow
80+
these steps:
8081
</p>
8182
<ol>
8283
<li>
Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
1-
# Heat Conduction in a Two-Dimensional Fin
1+
<img src="https://feascript.github.io/FEAScript-website/images/FEAScriptLogo.png" width="80">
22

3-
This example demonstrates how to solve a stationary heat transfer problem within a 2D rectangular domain using the FEAScript library. The problem is a typical cooling fin scenario, where cooling fins are used to increase the area available for heat transfer between metal walls and poorly conducting fluids such as air.
3+
## Heat Conduction in a Two-Dimensional Fin
44

5-
## Files
5+
This example demonstrates how to solve a stationary heat transfer problem within a 2D rectangular domain using the FEAScript library. The problem is a typical cooling fin scenario.
6+
7+
### Files
68

79
- `meshConfig.json`: Defines the computational mesh parameters.
810
- `boundaryConditionsConfig.json`: Specifies the boundary conditions for the problem.
9-
- `FEAScriptExampleSolidHeatTransfer01.html`: The main HTML file that sets up and runs the example.
11+
- `FEAScriptExampleSolidHeatTransfer01.html`: The main HTML file that sets up and runs the example.
12+
13+
### CORS Configuration
14+
15+
<p>
16+
This example requires Cross-Origin Resource Sharing (CORS) to run if the JSON files are stored locally. To
17+
enable CORS on Firefox, you can follow these steps:
18+
</p>
19+
<ol>
20+
<li>
21+
Open Firefox and type <code>about:config</code> in the address bar, then
22+
press Enter.
23+
</li>
24+
<li>Accept the risk and continue to the advanced settings.</li>
25+
<li>
26+
In the search bar, type
27+
<code>security.fileuri.strict_origin_policy</code>.
28+
</li>
29+
<li>
30+
Double-click on the
31+
<code>security.fileuri.strict_origin_policy</code> preference to set it
32+
to <code>false</code>.
33+
</li>
34+
</ol>

src/mesh/meshGenerationScript.js

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class meshGeneration {
8383

8484
/**
8585
* Generate a structured mesh based on the geometry configuration
86-
* @returns {object} An object containing the coordinates of nodes,
86+
* @returns {object} An object containing the coordinates of nodes,
8787
* total number of nodes, nodal numbering (NOP) array, and boundary elements
8888
*/
8989
generateMeshFromGeometry() {
@@ -98,8 +98,9 @@ export class meshGeneration {
9898
deltaX = (this.maxX - xStart) / this.numElementsX;
9999

100100
nodesXCoordinates[0] = xStart;
101-
for (let i = 1; i < totalNodesX; i++) {
102-
nodesXCoordinates[i] = nodesXCoordinates[i - 1] + deltaX;
101+
for (let nodeIndex = 1; nodeIndex < totalNodesX; nodeIndex++) {
102+
nodesXCoordinates[nodeIndex] =
103+
nodesXCoordinates[nodeIndex - 1] + deltaX;
103104
}
104105

105106
// Generate nodal numbering (NOP) array
@@ -126,18 +127,20 @@ export class meshGeneration {
126127

127128
nodesXCoordinates[0] = xStart;
128129
nodesYCoordinates[0] = yStart;
129-
for (let i = 1; i < totalNodesY; i++) {
130-
nodesXCoordinates[i] = nodesXCoordinates[0];
131-
nodesYCoordinates[i] = nodesYCoordinates[0] + (i * deltaY) / 2;
130+
for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {
131+
nodesXCoordinates[nodeIndexY] = nodesXCoordinates[0];
132+
nodesYCoordinates[nodeIndexY] =
133+
nodesYCoordinates[0] + (nodeIndexY * deltaY) / 2;
132134
}
133-
for (let i = 1; i < totalNodesX; i++) {
134-
const nnode = i * totalNodesY;
135-
nodesXCoordinates[nnode] = nodesXCoordinates[0] + (i * deltaX) / 2;
135+
for (let nodeIndexX = 1; nodeIndexX < totalNodesX; nodeIndexX++) {
136+
const nnode = nodeIndexX * totalNodesY;
137+
nodesXCoordinates[nnode] =
138+
nodesXCoordinates[0] + (nodeIndexX * deltaX) / 2;
136139
nodesYCoordinates[nnode] = nodesYCoordinates[0];
137-
for (let j = 1; j < totalNodesY; j++) {
138-
nodesXCoordinates[nnode + j] = nodesXCoordinates[nnode];
139-
nodesYCoordinates[nnode + j] =
140-
nodesYCoordinates[nnode] + (j * deltaY) / 2;
140+
for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {
141+
nodesXCoordinates[nnode + nodeIndexY] = nodesXCoordinates[nnode];
142+
nodesYCoordinates[nnode + nodeIndexY] =
143+
nodesYCoordinates[nnode] + (nodeIndexY * deltaY) / 2;
141144
}
142145
}
143146

@@ -187,27 +190,36 @@ export class meshGeneration {
187190
if (this.dimension === "1D") {
188191
// . . . implementation for 1D . . .
189192
} else {
190-
for (let i = 0; i < this.numElementsX; i++) {
191-
for (let j = 0; j < this.numElementsY; j++) {
192-
const elementIndex = i * this.numElementsY + j;
193+
for (
194+
let elementIndexX = 0;
195+
elementIndexX < this.numElementsX;
196+
elementIndexX++
197+
) {
198+
for (
199+
let elementIndexY = 0;
200+
elementIndexY < this.numElementsY;
201+
elementIndexY++
202+
) {
203+
const elementIndex =
204+
elementIndexX * this.numElementsY + elementIndexY;
193205

194206
// Bottom boundary
195-
if (j === 0) {
207+
if (elementIndexY === 0) {
196208
boundaryElements[0].push([elementIndex, 0]);
197209
}
198210

199211
// Top boundary
200-
if (j === this.numElementsY - 1) {
212+
if (elementIndexY === this.numElementsY - 1) {
201213
boundaryElements[2].push([elementIndex, 2]);
202214
}
203215

204216
// Left boundary
205-
if (i === 0) {
217+
if (elementIndexX === 0) {
206218
boundaryElements[1].push([elementIndex, 1]);
207219
}
208220

209221
// Right boundary
210-
if (i === this.numElementsX - 1) {
222+
if (elementIndexX === this.numElementsX - 1) {
211223
boundaryElements[3].push([elementIndex, 3]);
212224
}
213225
}
@@ -244,25 +256,38 @@ export class meshGeneration {
244256
*
245257
*/
246258

247-
for (let i = 0; i < numElementsX * numElementsY; i++) {
259+
for (
260+
let elementIndex = 0;
261+
elementIndex < numElementsX * numElementsY;
262+
elementIndex++
263+
) {
248264
nop.push([]);
249-
for (let j = 0; j < 9; j++) {
250-
nop[i][j] = 0;
265+
for (let nodeIndex = 0; nodeIndex < 9; nodeIndex++) {
266+
nop[elementIndex][nodeIndex] = 0;
251267
}
252268
}
253269

254-
for (let i = 1; i <= numElementsX; i++) {
255-
for (let j = 1; j <= numElementsY; j++) {
256-
for (let k = 1; k <= 3; k++) {
257-
let l = 3 * k - 2;
270+
for (
271+
let elementIndexX = 1;
272+
elementIndexX <= numElementsX;
273+
elementIndexX++
274+
) {
275+
for (
276+
let elementIndexY = 1;
277+
elementIndexY <= numElementsY;
278+
elementIndexY++
279+
) {
280+
for (let nodeIndex = 1; nodeIndex <= 3; nodeIndex++) {
281+
let l = 3 * nodeIndex - 2;
258282
nop[elementIndex][l - 1] =
259-
totalNodesY * (2 * i + k - 3) + 2 * j - 1;
283+
totalNodesY * (2 * elementIndexX + nodeIndex - 3) +
284+
2 * elementIndexY -
285+
1;
260286
nop[elementIndex][l] = nop[elementIndex][l - 1] + 1;
261287
nop[elementIndex][l + 1] = nop[elementIndex][l - 1] + 2;
262288
}
263289
elementIndex = elementIndex + 1;
264-
265-
}
290+
}
266291
}
267292
}
268293

src/methods/numIntegrationScript.js

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)