Skip to content

Commit 058b089

Browse files
committed
Format the examples in five numbered steps (model, mesh, boundary conditions, solve, results).
1 parent 03feade commit 058b089

11 files changed

Lines changed: 92 additions & 148 deletions

File tree

‎examples/creepingFlowScript/lidDrivenCavity2DCreepingFlow/lidDrivenCavity2DCreepingFlow.js‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ import { FEAScriptModel, printVersion } from "feascript";
1212

1313
console.log("FEAScript Version:", printVersion);
1414

15-
// Create a new FEAScript model
15+
// 1. Create the model and select the physics
1616
const model = new FEAScriptModel();
17-
18-
// Select physics/PDE
1917
model.setModelConfig("creepingFlowScript");
2018

21-
// Define mesh configuration
19+
// 2. Define the mesh
2220
model.setMeshConfig({
2321
meshDimension: "2D",
2422
elementOrder: "quadratic",
@@ -28,19 +26,17 @@ model.setMeshConfig({
2826
maxY: 2,
2927
});
3028

31-
// Define boundary conditions
32-
model.addBoundaryCondition("0", ["constantVelocity", 0, 0]); // Bottom boundary
33-
model.addBoundaryCondition("1", ["constantVelocity", 0, 0]); // Left boundary
34-
model.addBoundaryCondition("2", ["constantVelocity", 1, 0]); // Top boundary
35-
model.addBoundaryCondition("3", ["constantVelocity", 0, 0]); // Right boundary
29+
// 3. Apply the boundary conditions
30+
model.addBoundaryCondition("0", ["constantVelocity", 0, 0]); // Bottom
31+
model.addBoundaryCondition("1", ["constantVelocity", 0, 0]); // Left
32+
model.addBoundaryCondition("2", ["constantVelocity", 1, 0]); // Top
33+
model.addBoundaryCondition("3", ["constantVelocity", 0, 0]); // Right
3634

37-
// Set solver method (optional)
35+
// 4. Solve
3836
model.setSolverMethod("lusolve");
39-
40-
// Solve the problem
4137
const { solutionVector, nodesCoordinates } = model.solve();
4238

43-
// Print results
39+
// 5. Print the results
4440
console.log(`Number of nodes in mesh: ${nodesCoordinates.nodesXCoordinates.length}`);
4541
console.log("Node coordinates:", nodesCoordinates);
4642
console.log("Solution vector:", solutionVector);

‎examples/eulerBernoulliBeamScript/clampedSpringSupportedBeam1D/clampedSpringSupportedBeam1D.js‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,36 @@ import { FEAScriptModel, printVersion } from "feascript";
1212

1313
console.log("FEAScript Version:", printVersion);
1414

15-
// Create a new FEAScript model
15+
// 1. Create the model and select the physics
1616
const model = new FEAScriptModel();
17-
18-
// Select physics/PDE
1917
model.setModelConfig("eulerBernoulliBeamScript", {
2018
coefficientFunctions: {
2119
EI: (x) => 2.0e6, // Bending stiffness
2220
q: (x) => (x <= 5 ? -1000 : 0),
2321
},
2422
});
2523

26-
// Define mesh configuration
24+
// 2. Define the mesh
2725
model.setMeshConfig({
2826
meshDimension: "1D",
2927
elementOrder: "linear",
3028
numElementsX: 2,
3129
maxX: 10,
3230
});
3331

34-
// Define boundary conditions
32+
// 3. Apply the boundary conditions
3533
model.addBoundaryCondition("1", [["fixed"]]); // Clamped support
3634
model.addBoundaryCondition("2", [["pinned"], ["moment", 1250]]); // Roller + applied moment
3735
model.addBoundaryCondition("3", [
3836
["spring", 200],
3937
["force", -2500],
4038
]); // Spring support + point load
4139

42-
// Set solver method
40+
// 4. Solve
4341
model.setSolverMethod("lusolve");
44-
45-
// Solve the problem
4642
const { solutionVector } = model.solve();
4743

48-
// Print results
44+
// 5. Print the results
4945
const flatSolution = solutionVector.map((entry) => (Array.isArray(entry) ? entry[0] : entry));
5046

5147
const nodeXCoordinates = [0, 5, 10];

‎examples/frontPropagationScript/solidificationFront2D/solidificationFront2D.js‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ import { FEAScriptModel, printVersion } from "feascript";
1212

1313
console.log("FEAScript Version:", printVersion);
1414

15-
// Create a new FEAScript model
15+
// 1. Create the model and select the physics
1616
const model = new FEAScriptModel();
17-
18-
// Select physics/PDE
1917
model.setModelConfig("frontPropagationScript");
2018

21-
// Define mesh configuration
19+
// 2. Define the mesh
2220
model.setMeshConfig({
2321
meshDimension: "2D",
2422
elementOrder: "quadratic",
@@ -28,19 +26,17 @@ model.setMeshConfig({
2826
maxY: 2,
2927
});
3028

31-
// Define boundary conditions
32-
model.addBoundaryCondition("0", ["constantValue", 0]); // Bottom boundary
33-
model.addBoundaryCondition("1", ["constantValue", 0]); // Left boundary
34-
model.addBoundaryCondition("2", ["zeroGradient"]); // Top boundary
35-
model.addBoundaryCondition("3", ["constantValue", 0]); // Right boundary
29+
// 3. Apply the boundary conditions
30+
model.addBoundaryCondition("0", ["constantValue", 0]); // Bottom
31+
model.addBoundaryCondition("1", ["constantValue", 0]); // Left
32+
model.addBoundaryCondition("2", ["zeroGradient"]); // Top
33+
model.addBoundaryCondition("3", ["constantValue", 0]); // Right
3634

37-
// Set solver method (optional)
35+
// 4. Solve
3836
model.setSolverMethod("lusolve");
39-
40-
// Solve the problem
4137
const { solutionVector, nodesCoordinates } = model.solve();
4238

43-
// Print results
39+
// 5. Print the results
4440
console.log(`Number of nodes in mesh: ${nodesCoordinates.nodesXCoordinates.length}`);
4541
console.log("Node coordinates:", nodesCoordinates);
4642
console.log("Solution vector:", solutionVector);

‎examples/generalFormPDEScript/advectionDiffusion1D/advectionDiffusion1D.js‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ import { FEAScriptModel, printVersion } from "feascript";
1212

1313
console.log("FEAScript Version:", printVersion);
1414

15-
// Create a new FEAScript model
15+
// 1. Create the model and select the physics
1616
const model = new FEAScriptModel();
17-
18-
// Select physics/PDE
1917
model.setModelConfig("generalFormPDEScript", {
2018
coefficientFunctions: {
2119
// Equation d²u/dx² - 10 du/dx = 10 * exp(-200 * (x - 0.5)²)
@@ -26,25 +24,23 @@ model.setModelConfig("generalFormPDEScript", {
2624
},
2725
});
2826

29-
// Define mesh configuration
27+
// 2. Define the mesh
3028
model.setMeshConfig({
3129
meshDimension: "1D",
3230
elementOrder: "quadratic",
3331
numElementsX: 20,
3432
maxX: 1.0,
3533
});
3634

37-
// Define boundary conditions
38-
model.addBoundaryCondition("0", ["constantValue", 1]); // Left boundary
39-
model.addBoundaryCondition("1", ["zeroGradient"]); // Right boundary
35+
// 3. Apply the boundary conditions
36+
model.addBoundaryCondition("0", ["constantValue", 1]); // Left
37+
model.addBoundaryCondition("1", ["zeroGradient"]); // Right
4038

41-
// Set solver method
39+
// 4. Solve
4240
model.setSolverMethod("lusolve");
43-
44-
// Solve the problem
4541
const { solutionVector, nodesCoordinates } = model.solve();
4642

47-
// Print results
43+
// 5. Print the results
4844
console.log(`Number of nodes in mesh: ${nodesCoordinates.nodesXCoordinates.length}`);
4945
console.log("Node coordinates:", nodesCoordinates);
5046
console.log("Solution vector:", solutionVector);

‎examples/generalFormPDEScript/nonlinearReactionDiffusion1D/nonlinearReactionDiffusion1D.js‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ import { FEAScriptModel, printVersion } from "feascript";
1212

1313
console.log("FEAScript Version:", printVersion);
1414

15-
// Create a new FEAScript model
16-
const model = new FEAScriptModel();
17-
1815
// Reaction rate coefficient for the nonlinear source term
1916
const Da = 1;
2017

21-
// Select physics/PDE
18+
// 1. Create the model and select the physics
19+
const model = new FEAScriptModel();
2220
model.setModelConfig("generalFormPDEScript", {
2321
nonlinear: true, // Solve with the Newton-Raphson method
2422
coefficientFunctions: {
@@ -31,28 +29,26 @@ model.setModelConfig("generalFormPDEScript", {
3129
},
3230
});
3331

34-
// Define mesh configuration
32+
// 2. Define the mesh
3533
model.setMeshConfig({
3634
meshDimension: "1D",
3735
elementOrder: "linear",
3836
numElementsX: 20,
3937
maxX: 10.0,
4038
});
4139

42-
// Define boundary conditions
43-
model.addBoundaryCondition("0", ["constantValue", 1]); // Left boundary
44-
model.addBoundaryCondition("1", ["zeroGradient"]); // Right boundary
40+
// 3. Apply the boundary conditions
41+
model.addBoundaryCondition("0", ["constantValue", 1]); // Left
42+
model.addBoundaryCondition("1", ["zeroGradient"]); // Right
4543

46-
// Set solver method
44+
// 4. Solve
4745
model.setSolverMethod("lusolve");
48-
49-
// Solve the problem
5046
const { solutionVector, nodesCoordinates } = model.solve({
5147
maxIterations: 100,
5248
tolerance: 1e-5,
5349
});
5450

55-
// Print results
51+
// 5. Print the results
5652
console.log(`Number of nodes in mesh: ${nodesCoordinates.nodesXCoordinates.length}`);
5753
console.log("Node coordinates:", nodesCoordinates);
5854
console.log("Solution vector:", solutionVector);

‎examples/heatConductionScript/heatConduction1DWall/heatConduction1DVaryingK.js‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ import { FEAScriptModel, printVersion } from "feascript";
2424

2525
console.log("FEAScript Version:", printVersion);
2626

27-
// Create a new FEAScript model
27+
// 1. Create the model and select the physics
2828
const model = new FEAScriptModel();
29-
30-
// Select physics/PDE
3129
model.setModelConfig("heatConductionScript", {
3230
coefficientFunctions: {
3331
// Bi-material: high-conductivity concrete | low-conductivity insulation
@@ -36,22 +34,22 @@ model.setModelConfig("heatConductionScript", {
3634
},
3735
});
3836

39-
// Define mesh configuration
37+
// 2. Define the mesh
4038
model.setMeshConfig({
4139
meshDimension: "1D",
4240
elementOrder: "linear",
4341
numElementsX: 20,
4442
maxX: 0.15,
4543
});
4644

47-
// Define boundary conditions
48-
model.addBoundaryCondition("0", ["convection", 25, 5]); // Left boundary: convection
49-
model.addBoundaryCondition("1", ["constantTemperature", 20]); // Right boundary: fixed temperature
45+
// 3. Apply the boundary conditions
46+
model.addBoundaryCondition("0", ["convection", 25, 5]); // Left: convection
47+
model.addBoundaryCondition("1", ["constantTemperature", 20]); // Right: fixed temperature
5048

51-
// Solve the problem
49+
// 4. Solve
5250
const { solutionVector, nodesCoordinates } = model.solve();
5351

54-
// Print results
52+
// 5. Print the results
5553
console.log(`Number of nodes: ${nodesCoordinates.nodesXCoordinates.length}`);
5654
console.log("Node coordinates (x):", nodesCoordinates.nodesXCoordinates);
5755
console.log("Temperature solution:", solutionVector);

‎examples/heatConductionScript/heatConduction1DWall/heatConduction1DWall.js‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,27 @@ import { FEAScriptModel, printVersion } from "feascript";
1212

1313
console.log("FEAScript Version:", printVersion);
1414

15-
// Create a new FEAScript model
15+
// 1. Create the model and select the physics
1616
const model = new FEAScriptModel();
17-
18-
// Select physics/PDE
1917
model.setModelConfig("heatConductionScript");
2018

21-
// Define mesh configuration
19+
// 2. Define the mesh
2220
model.setMeshConfig({
2321
meshDimension: "1D",
2422
elementOrder: "linear",
2523
numElementsX: 10,
2624
maxX: 0.15,
2725
});
2826

29-
// Define boundary conditions
30-
model.addBoundaryCondition("0", ["convection", 1, 25]); // Left boundary
31-
model.addBoundaryCondition("1", ["constantTemperature", 5]); // Right boundary
27+
// 3. Apply the boundary conditions
28+
model.addBoundaryCondition("0", ["convection", 1, 25]); // Left
29+
model.addBoundaryCondition("1", ["constantTemperature", 5]); // Right
3230

33-
// Set solver method (optional)
31+
// 4. Solve
3432
model.setSolverMethod("jacobi");
35-
36-
// Solve the problem
3733
const { solutionVector, nodesCoordinates } = model.solve();
3834

39-
// Print results
35+
// 5. Print the results
4036
console.log(`Number of nodes: ${nodesCoordinates.nodesXCoordinates.length}`);
4137
console.log("Node coordinates:", nodesCoordinates);
4238
console.log("Solution vector:", solutionVector);

‎examples/heatConductionScript/heatConduction2DFin/heatConduction2DFin.js‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ import { FEAScriptModel, printVersion } from "feascript";
1212

1313
console.log("FEAScript Version:", printVersion);
1414

15-
// Create a new FEAScript model
15+
// 1. Create the model and select the physics
1616
const model = new FEAScriptModel();
17-
18-
// Select physics/PDE
1917
model.setModelConfig("heatConductionScript");
2018

21-
// Define mesh configuration
19+
// 2. Define the mesh
2220
model.setMeshConfig({
2321
meshDimension: "2D",
2422
elementOrder: "quadratic",
@@ -28,19 +26,17 @@ model.setMeshConfig({
2826
maxY: 2,
2927
});
3028

31-
// Define boundary conditions
32-
model.addBoundaryCondition("0", ["constantTemperature", 200]); // Bottom boundary
33-
model.addBoundaryCondition("1", ["symmetry"]); // Left boundary
34-
model.addBoundaryCondition("2", ["convection", 1, 20]); // Top boundary
35-
model.addBoundaryCondition("3", ["constantTemperature", 200]); // Right boundary
29+
// 3. Apply the boundary conditions
30+
model.addBoundaryCondition("0", ["constantTemperature", 200]); // Bottom
31+
model.addBoundaryCondition("1", ["symmetry"]); // Left
32+
model.addBoundaryCondition("2", ["convection", 1, 20]); // Top
33+
model.addBoundaryCondition("3", ["constantTemperature", 200]); // Right
3634

37-
// Set solver method (optional)
35+
// 4. Solve
3836
model.setSolverMethod("frontal");
39-
40-
// Solve the problem
4137
const { solutionVector, nodesCoordinates } = model.solve();
4238

43-
// Print results
39+
// 5. Print the results
4440
console.log(`Number of nodes in mesh: ${nodesCoordinates.nodesXCoordinates.length}`);
4541
console.log("Node coordinates:", nodesCoordinates);
4642
console.log("Solution vector:", solutionVector);

‎examples/heatConductionScript/heatConduction2DFin/heatConduction2DFinGmsh.js‎

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,24 @@ const meshFilePath = path.join(__dirname, "rect_quad.msh");
2525
const meshContent = fs.readFileSync(meshFilePath, "utf8");
2626

2727
async function main() {
28-
// Create a new FEAScript model
28+
// 1. Create the model and select the physics
2929
const model = new FEAScriptModel();
30-
31-
// Select physics/PDE
3230
model.setModelConfig("heatConductionScript");
3331

34-
// Create a mock File object for Node.js environment
35-
const mockFile = {
36-
text: async () => meshContent,
37-
name: "rect_quad.msh",
38-
};
39-
40-
// Parse the mesh data
41-
const result = await importGmshMesh(mockFile);
42-
43-
// Define mesh configuration with the parsed result
44-
model.setMeshConfig({
45-
parsedMesh: result,
46-
});
32+
// 2. Load the Gmsh mesh (in Node.js, any object with an async text() method replaces a File)
33+
const mesh = await importGmshMesh({ text: async () => meshContent });
34+
model.setMeshConfig({ parsedMesh: mesh });
4735

48-
// Define boundary conditions
49-
model.addBoundaryCondition("0", ["constantTemperature", 200]); // Bottom boundary
50-
model.addBoundaryCondition("1", ["symmetry"]); // Left boundary
51-
model.addBoundaryCondition("2", ["convection", 1, 20]); // Top boundary
52-
model.addBoundaryCondition("3", ["constantTemperature", 200]); // Right boundary
36+
// 3. Apply the boundary conditions (key = Gmsh physical group tag - 1)
37+
model.addBoundaryCondition("0", ["constantTemperature", 200]); // Bottom
38+
model.addBoundaryCondition("1", ["symmetry"]); // Left
39+
model.addBoundaryCondition("2", ["convection", 1, 20]); // Top
40+
model.addBoundaryCondition("3", ["constantTemperature", 200]); // Right
5341

54-
// Solve the problem
42+
// 4. Solve
5543
const { solutionVector, nodesCoordinates } = model.solve();
5644

57-
// Print results
45+
// 5. Print the results
5846
console.log(`Number of nodes in mesh: ${nodesCoordinates.nodesXCoordinates.length}`);
5947
console.log("Node coordinates:", nodesCoordinates);
6048
console.log("Solution vector:", solutionVector);

0 commit comments

Comments
 (0)