Skip to content

Commit 6560bef

Browse files
committed
Format the workflow examples (model pages, first simulation, Gmsh import, web worker, llms.txt) in the same five numbered steps.
1 parent 3f04bb6 commit 6560bef

9 files changed

Lines changed: 70 additions & 45 deletions

File tree

‎docs/api/gmsh-import.md‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,22 @@ Node.js has no `File` object for files on disk, so pass an object with a `text()
5656
import fs from "fs";
5757
import { FEAScriptModel, importGmshMesh } from "feascript";
5858

59-
const meshContent = fs.readFileSync("rect_quad.msh", "utf8");
60-
const parsedMesh = await importGmshMesh({ text: async () => meshContent });
61-
59+
// 1. Create the model and select the physics
6260
const model = new FEAScriptModel();
6361
model.setModelConfig("heatConductionScript");
62+
63+
// 2. Load the Gmsh mesh
64+
const meshContent = fs.readFileSync("rect_quad.msh", "utf8");
65+
const parsedMesh = await importGmshMesh({ text: async () => meshContent });
6466
model.setMeshConfig({ parsedMesh });
6567

68+
// 3. Apply the boundary conditions
6669
model.addBoundaryCondition("0", ["constantTemperature", 200]); // Physical curve "bottom", tag 1
6770
model.addBoundaryCondition("1", ["symmetry"]); // Physical curve "left", tag 2
6871
model.addBoundaryCondition("2", ["convection", 1, 20]); // Physical curve "top", tag 3
6972
model.addBoundaryCondition("3", ["constantTemperature", 200]); // Physical curve "right", tag 4
7073

74+
// 4. Solve
7175
const { solutionVector, nodesCoordinates } = model.solve();
7276
```
7377

‎docs/api/web-worker.md‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ method is asynchronous and returns a `Promise`.
1616
```javascript
1717
import { FEAScriptWorker, plotSolution } from "https://core.feascript.com/dist/feascript.esm.js";
1818

19+
// 1. Create the model in a web worker and select the physics
1920
const model = new FEAScriptWorker();
2021
await model.ping(); // Wait until the worker is ready
21-
2222
await model.setModelConfig("frontPropagationScript");
23+
24+
// 2. Define the mesh
2325
await model.setMeshConfig({
2426
meshDimension: "2D",
2527
elementOrder: "quadratic",
@@ -28,18 +30,22 @@ await model.setMeshConfig({
2830
maxX: 4,
2931
maxY: 2,
3032
});
31-
await model.addBoundaryCondition("0", ["constantValue", 0]);
32-
await model.addBoundaryCondition("1", ["constantValue", 0]);
33-
await model.addBoundaryCondition("2", ["zeroGradient"]);
34-
await model.addBoundaryCondition("3", ["constantValue", 0]);
35-
await model.setSolverMethod("lusolve");
3633

34+
// 3. Apply the boundary conditions
35+
await model.addBoundaryCondition("0", ["constantValue", 0]); // Bottom: initial front
36+
await model.addBoundaryCondition("1", ["constantValue", 0]); // Left: initial front
37+
await model.addBoundaryCondition("2", ["zeroGradient"]); // Top
38+
await model.addBoundaryCondition("3", ["constantValue", 0]); // Right: initial front
39+
40+
// 4. Solve
41+
await model.setSolverMethod("lusolve");
3742
const result = await model.solve();
3843

39-
// Plot in the main thread
44+
// 5. Plot the results in the main thread
4045
const modelInfo = await model.getModelInfo();
4146
plotSolution(modelInfo, result, "contour", "resultsCanvas");
4247

48+
// 6. Terminate the worker
4349
model.terminate();
4450
```
4551

‎docs/getting-started/first-simulation.md‎

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ Save the following as an `.html` file and open it through a local web server (fo
3838
<script type="module">
3939
import { FEAScriptModel, plotSolution } from "https://core.feascript.com/dist/feascript.esm.js";
4040
41-
// 1. Create a model
41+
// 1. Create the model and select the physics
4242
const model = new FEAScriptModel();
43-
44-
// 2. Select the physical model
4543
model.setModelConfig("heatConductionScript");
4644
47-
// 3. Define the mesh: 8 × 4 quadratic quadrilaterals on 0 ≤ x ≤ 4, 0 ≤ y ≤ 2
45+
// 2. Define the mesh: 8 × 4 quadratic quadrilaterals on 0 ≤ x ≤ 4, 0 ≤ y ≤ 2
4846
model.setMeshConfig({
4947
meshDimension: "2D",
5048
elementOrder: "quadratic",
@@ -54,17 +52,17 @@ Save the following as an `.html` file and open it through a local web server (fo
5452
maxY: 2,
5553
});
5654
57-
// 4. Apply the boundary conditions
55+
// 3. Apply the boundary conditions
5856
model.addBoundaryCondition("0", ["constantTemperature", 200]); // Bottom
5957
model.addBoundaryCondition("1", ["symmetry"]); // Left
6058
model.addBoundaryCondition("2", ["convection", 1, 20]); // Top
6159
model.addBoundaryCondition("3", ["constantTemperature", 200]); // Right
6260
63-
// 5. Select the solver and solve
61+
// 4. Solve
6462
model.setSolverMethod("lusolve");
6563
const result = model.solve();
6664
67-
// 6. Plot the temperature
65+
// 5. Plot the results
6866
plotSolution(model, result, "contour", "resultsCanvas");
6967
</script>
7068
</body>
@@ -73,18 +71,17 @@ Save the following as an `.html` file and open it through a local web server (fo
7371

7472
## Step by step
7573

76-
1. **Create a model.** [`FEAScriptModel`](../api/feascript-model.md) holds the whole configuration of the
77-
simulation.
78-
2. **Select the physical model.** `setModelConfig` takes the model name and, optionally, its coefficients. Here
79-
the defaults of the [heat conduction](../models/heat-conduction.md) model are used ($k = 1$, $Q = 0$).
80-
3. **Define the mesh.** `setMeshConfig` generates a structured mesh from the size of the domain and the number of
74+
1. **Create the model and select the physics.** [`FEAScriptModel`](../api/feascript-model.md) holds the whole
75+
configuration of the simulation. `setModelConfig` takes the model name and, optionally, its coefficients. Here the
76+
defaults of the [heat conduction](../models/heat-conduction.md) model are used ($k = 1$, $Q = 0$).
77+
2. **Define the mesh.** `setMeshConfig` generates a structured mesh from the size of the domain and the number of
8178
elements (see [Mesh](../fundamentals/mesh.md)), or uses a mesh imported from Gmsh.
82-
4. **Apply the boundary conditions.** The sides of a structured 2D mesh have the keys `"0"` (bottom), `"1"`
79+
3. **Apply the boundary conditions.** The sides of a structured 2D mesh have the keys `"0"` (bottom), `"1"`
8380
(left), `"2"` (top) and `"3"` (right). See [Boundary conditions](../fundamentals/boundary-conditions.md) for the
8481
condition types of every model.
85-
5. **Solve.** `setSolverMethod` is optional (the default is `"lusolve"`). `solve()` returns the
82+
4. **Solve.** `setSolverMethod` is optional (the default is `"lusolve"`). `solve()` returns the
8683
`solutionVector` and the `nodesCoordinates` of the mesh (see [Solvers](../fundamentals/solvers.md)).
87-
6. **Post-process.** [`plotSolution`](../api/visualization.md) draws the result in the `resultsCanvas` element.
84+
5. **Plot the results.** [`plotSolution`](../api/visualization.md) draws the result in the `resultsCanvas` element.
8885

8986
## The result
9087

@@ -105,8 +102,11 @@ for (let i = 0; i < solutionVector.length; i++) {
105102
```javascript
106103
import { FEAScriptModel } from "feascript";
107104

105+
// 1. Create the model and select the physics
108106
const model = new FEAScriptModel();
109107
model.setModelConfig("heatConductionScript");
108+
109+
// 2. Define the mesh
110110
model.setMeshConfig({
111111
meshDimension: "2D",
112112
elementOrder: "quadratic",
@@ -115,12 +115,17 @@ model.setMeshConfig({
115115
maxX: 4,
116116
maxY: 2,
117117
});
118-
model.addBoundaryCondition("0", ["constantTemperature", 200]);
119-
model.addBoundaryCondition("1", ["symmetry"]);
120-
model.addBoundaryCondition("2", ["convection", 1, 20]);
121-
model.addBoundaryCondition("3", ["constantTemperature", 200]);
122118

119+
// 3. Apply the boundary conditions
120+
model.addBoundaryCondition("0", ["constantTemperature", 200]); // Bottom
121+
model.addBoundaryCondition("1", ["symmetry"]); // Left
122+
model.addBoundaryCondition("2", ["convection", 1, 20]); // Top
123+
model.addBoundaryCondition("3", ["constantTemperature", 200]); // Right
124+
125+
// 4. Solve
123126
const { solutionVector, nodesCoordinates } = model.solve();
127+
128+
// 5. Print the results
124129
console.log(`Number of nodes: ${nodesCoordinates.nodesXCoordinates.length}`);
125130
console.log("Temperature:", solutionVector);
126131
```

‎docs/models/creeping-flow.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,28 +72,28 @@ The lid-driven cavity: a $4 \times 2$ cavity whose top wall moves with unit velo
7272
```javascript
7373
import { FEAScriptModel } from "feascript";
7474

75+
// 1. Create the model and select the physics
7576
const model = new FEAScriptModel();
76-
7777
model.setModelConfig("creepingFlowScript");
7878

79-
const numElementsX = 12;
80-
const numElementsY = 6;
79+
// 2. Define the mesh
8180
model.setMeshConfig({
8281
meshDimension: "2D",
8382
elementOrder: "quadratic", // Required (Taylor–Hood elements)
84-
numElementsX,
85-
numElementsY,
83+
numElementsX: 12,
84+
numElementsY: 6,
8685
maxX: 4,
8786
maxY: 2,
8887
});
8988

89+
// 3. Apply the boundary conditions
9090
model.addBoundaryCondition("0", ["constantVelocity", 0, 0]); // Bottom wall
9191
model.addBoundaryCondition("1", ["constantVelocity", 0, 0]); // Left wall
9292
model.addBoundaryCondition("2", ["constantVelocity", 1, 0]); // Moving lid
9393
model.addBoundaryCondition("3", ["constantVelocity", 0, 0]); // Right wall
9494

95+
// 4. Solve
9596
model.setSolverMethod("lusolve");
96-
9797
const { solutionVector, nodesCoordinates } = model.solve();
9898
```
9999

‎docs/models/euler-bernoulli-beam.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,31 +61,33 @@ from J. N. Reddy, _An Introduction to the Finite Element Method_, 3rd ed., McGra
6161
```javascript
6262
import { FEAScriptModel } from "feascript";
6363

64+
// 1. Create the model and select the physics
6465
const model = new FEAScriptModel();
65-
6666
model.setModelConfig("eulerBernoulliBeamScript", {
6767
coefficientFunctions: {
6868
EI: (x) => 2.0e6, // Bending stiffness
6969
q: (x) => (x <= 5 ? -1000 : 0), // Distributed load over the first span
7070
},
7171
});
7272

73+
// 2. Define the mesh
7374
model.setMeshConfig({
7475
meshDimension: "1D",
7576
elementOrder: "linear", // Required
7677
numElementsX: 2, // Nodes "1", "2", "3" at x = 0, 5, 10
7778
maxX: 10,
7879
});
7980

81+
// 3. Apply the boundary conditions
8082
model.addBoundaryCondition("1", [["fixed"]]); // Clamped end
8183
model.addBoundaryCondition("2", [["pinned"], ["moment", 1250]]); // Roller with an applied moment
8284
model.addBoundaryCondition("3", [
8385
["spring", 200],
8486
["force", -2500],
8587
]); // Spring support with an applied force
8688

89+
// 4. Solve
8790
model.setSolverMethod("lusolve");
88-
8991
const { solutionVector, nodesCoordinates } = model.solve();
9092
```
9193

‎docs/models/front-propagation.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ The solidification front in a $4 \times 2$ domain, starting from the bottom, lef
7878
```javascript
7979
import { FEAScriptModel } from "feascript";
8080

81+
// 1. Create the model and select the physics
8182
const model = new FEAScriptModel();
82-
8383
model.setModelConfig("frontPropagationScript");
8484

85+
// 2. Define the mesh
8586
model.setMeshConfig({
8687
meshDimension: "2D",
8788
elementOrder: "quadratic",
@@ -91,13 +92,14 @@ model.setMeshConfig({
9192
maxY: 2,
9293
});
9394

95+
// 3. Apply the boundary conditions
9496
model.addBoundaryCondition("0", ["constantValue", 0]); // Bottom: initial front
9597
model.addBoundaryCondition("1", ["constantValue", 0]); // Left: initial front
9698
model.addBoundaryCondition("2", ["zeroGradient"]); // Top
9799
model.addBoundaryCondition("3", ["constantValue", 0]); // Right: initial front
98100

101+
// 4. Solve
99102
model.setSolverMethod("lusolve");
100-
101103
const { solutionVector, nodesCoordinates } = model.solve();
102104
```
103105

‎docs/models/general-form-pde.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ The equation $\frac{d^2u}{dx^2} - 10 \frac{du}{dx} = 10 \, e^{-200 (x - 0.5)^2}$
7676
```javascript
7777
import { FEAScriptModel } from "feascript";
7878

79+
// 1. Create the model and select the physics
7980
const model = new FEAScriptModel();
80-
8181
model.setModelConfig("generalFormPDEScript", {
8282
coefficientFunctions: {
8383
A: (x) => 1, // Diffusion coefficient
@@ -87,18 +87,20 @@ model.setModelConfig("generalFormPDEScript", {
8787
},
8888
});
8989

90+
// 2. Define the mesh
9091
model.setMeshConfig({
9192
meshDimension: "1D",
9293
elementOrder: "quadratic",
9394
numElementsX: 20,
9495
maxX: 1.0,
9596
});
9697

98+
// 3. Apply the boundary conditions
9799
model.addBoundaryCondition("0", ["constantValue", 1]); // Left, x = 0
98100
model.addBoundaryCondition("1", ["zeroGradient"]); // Right, x = 1
99101

102+
// 4. Solve
100103
model.setSolverMethod("lusolve");
101-
102104
const { solutionVector, nodesCoordinates } = model.solve();
103105
```
104106

‎docs/models/heat-conduction.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,16 @@ The model is linear, so the system is solved once.
5252
```javascript
5353
import { FEAScriptModel } from "feascript";
5454

55+
// 1. Create the model and select the physics
5556
const model = new FEAScriptModel();
56-
5757
model.setModelConfig("heatConductionScript", {
5858
coefficientFunctions: {
5959
thermalConductivity: 1, // k
6060
heatSource: 0, // Q
6161
},
6262
});
6363

64+
// 2. Define the mesh
6465
model.setMeshConfig({
6566
meshDimension: "2D",
6667
elementOrder: "quadratic",
@@ -70,13 +71,14 @@ model.setMeshConfig({
7071
maxY: 2,
7172
});
7273

74+
// 3. Apply the boundary conditions
7375
model.addBoundaryCondition("0", ["constantTemperature", 200]); // Bottom
7476
model.addBoundaryCondition("1", ["symmetry"]); // Left
7577
model.addBoundaryCondition("2", ["convection", 1, 20]); // Top
7678
model.addBoundaryCondition("3", ["constantTemperature", 200]); // Right
7779

80+
// 4. Solve
7881
model.setSolverMethod("lusolve");
79-
8082
const { solutionVector, nodesCoordinates } = model.solve();
8183
```
8284

‎static/llms.txt‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ Exports: `FEAScriptModel`, `importGmshMesh`, `logSystem`, `printVersion` (a stri
2222
Every simulation follows the same steps:
2323

2424
```javascript
25+
// 1. Create the model and select the physics
2526
const model = new FEAScriptModel();
26-
2727
model.setModelConfig("heatConductionScript", {
2828
coefficientFunctions: { thermalConductivity: 1, heatSource: 0 },
2929
});
3030

31+
// 2. Define the mesh
3132
model.setMeshConfig({
3233
meshDimension: "2D",
3334
elementOrder: "quadratic",
@@ -37,13 +38,14 @@ model.setMeshConfig({
3738
maxY: 2,
3839
});
3940

41+
// 3. Apply the boundary conditions
4042
model.addBoundaryCondition("0", ["constantTemperature", 200]); // Bottom
4143
model.addBoundaryCondition("1", ["symmetry"]); // Left
4244
model.addBoundaryCondition("2", ["convection", 1, 20]); // Top: h = 1, T∞ = 20
4345
model.addBoundaryCondition("3", ["constantTemperature", 200]); // Right
4446

47+
// 4. Solve
4548
model.setSolverMethod("lusolve"); // Optional, "lusolve" is the default
46-
4749
const { solutionVector, nodesCoordinates } = model.solve();
4850
// solutionVector: Float64Array
4951
// nodesCoordinates: { nodesXCoordinates: number[], nodesYCoordinates: number[] }

0 commit comments

Comments
 (0)