Skip to content

Commit 9750827

Browse files
frontPropagationScript solver (#29)
* Added initial file for frontPropagationScript * Refactor Heat Conduction example: add JavaScript implementation, update README instructions, and enhance .gitignore * - Enhanced frontPropagationScript.js with a new function to assemble the front propagation matrix, including detailed JSDoc comments. - Updated version number in package.json and src/index.js to 0.1.2. - Added logging for FEAScript version in HeatConduction1DWall.js. - Updated peer dependency for plotly.js to version 2.35.3. - Removed unnecessary dependencies from package-lock.json and package.json. * Reorganize README sections for clarity: update installation options and example usage * Update README for improved clarity: reorganize installation options and example usage sections * Remove HTML examples and add Node.js implementations for heat conduction simulations * Add front propagation matrix assembly to FEAScriptModel * Enhance front propagation matrix assembly and initiate Newton-Raphson method * Update parameters names and improve convergence logic in Newton-Raphson method * Add Euclidean norm function and update Newton-Raphson method to use it for error calculation * Update README files to clarify Node.js environment suitability for heat conduction examples * Integrate Newton-Raphson method into front propagation solver * Refactor Newton-Raphson method to accept matrix assembly function and context, enhancing front propagation solver with eikonal viscous term parameterization * Add a seperate linear system solver function (linearSystemScript.js). Refactor linearSystemScript.js and FEAScript.js to utilize it * Include error logging for unknown linear solver * Refactor Jacobi and Newton-Raphson methods to standardize solution vector naming * Fix import path for logging utilities in Newton-Raphson script * Add todo statements in frontPropagationScript.js * Improve Readability and Maintainability of meshGenerationScript.js (#28) * Redefining the mesh script as a Class * Deleting meshGeneration class and replacing it to the Mesh1D and Mesh2D classes * Replace meshGeneration class with the Mesh1D and Mesh2D classes * Fix non-capitalized class names * Rename variables for consistency * Create a new file for generic boundary condutions (genericBoundaryConditionsScript.js). Possible need to consolidate with thermalBoundaryConditionsScript.js in the future * Add residual and Jacobian terms for the eikonal equation * Refactor Jacobian determinant calculation * Update boundary condition handling to use 'constantValue' instead of 'constantTemp' * Refactor Newton-Raphson implementation and improve debug logging in boundary conditions * Enhance eikonal equation solver with initial solution handling and improve logging in boundary condition applications * Refactor eikonal equation parameters and update Newton-Raphson convergence tolerance; add helper function for system size calculation * - Reduce the number of incremental steps for the eikonal term activation in FEAScript.js from 10 to 5 - Reorganize the return statement in meshGenerationScript.js since it was causing an error in the case of linear elements - Update logging messages in newtonRaphsonScript.js - Increase the base viscous term in frontPropagationScript.js from 1e-3 to 1e-2 to prevent stability issues --------- Co-authored-by: ferrari212 <felipe.ferrari.212@gmail.com>
1 parent 767da8a commit 9750827

35 files changed

+1748
-1342
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Dependencies
12
/node_modules
23
node_modules
3-
node_modules/
4+
node_modules/
5+
6+
# Example dependencies
7+
examples/**/package.json
8+
examples/**/package-lock.json
9+
examples/**/node_modules/

README.md

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,43 @@
22

33
# FEAScript-core
44

5-
[FEAScript](https://feascript.com/) is a lightweight finite element simulation library built in JavaScript. It empowers users to create and execute browser-based simulations for physics and engineering applications. This is the core library of FEAScript.
5+
[FEAScript](https://feascript.com/) is a lightweight finite element simulation library built in JavaScript. It empowers users to create and execute simulations for physics and engineering applications in both browser-based and server-side environments. This is the core library of FEAScript.
66

77
> 🚧 **FEAScript is currently under heavy development.** Functionality and interfaces may change rapidly as new features and enhancements are introduced. 🚧
88
99
## Installation
1010

11-
FEAScript is entirely implemented in pure JavaScript and requires only a simple HTML page to operate. All simulations are executed locally in your browser, without the need for any cloud services. You can use FEAScript in your projects through one of the following methods:
11+
FEAScript is entirely implemented in pure JavaScript and can run in two environments:
1212

13-
### Option 1: NPM Installation
13+
1. **In the browser** with a simple HTML page, where all simulations are executed locally without any installations or using any cloud services
14+
2. **Via Node.js** with plain JavaScript files, for server-side simulations
15+
16+
### Option 1: In the Browser
17+
18+
You can use FEAScript in browser environments in two ways:
19+
20+
**Direct Import from CDN**:
21+
Add this to your HTML file:
22+
23+
```html
24+
<script type="module">
25+
import { FEAScriptModel } from "https://core.feascript.com/dist/feascript.esm.js";
26+
</script>
27+
```
28+
29+
**Download and Use Locally**:
30+
1. Download the latest release from [GitHub Releases](https://github.com/FEAScript/FEAScript-core/releases)
31+
2. Include it in your HTML file:
32+
33+
```html
34+
<script type="module">
35+
import { FEAScriptModel } from "./path/to/dist/feascript.esm.js";
36+
</script>
37+
```
38+
39+
For browser-based examples and use cases, visit [our website tutorials](https://feascript.com/#tutorials).
40+
41+
### Option 2: Via Node.js
1442

1543
```bash
1644
# Install FEAScript and its peer dependencies
@@ -20,53 +48,36 @@ npm install feascript mathjs plotly.js
2048
Then import it in your JavaScript/TypeScript file:
2149

2250
```javascript
23-
// ES Modules
24-
import { FEAScriptModel, plotSolution } from "feascript";
25-
26-
// CommonJS
27-
const { FEAScriptModel, plotSolution } = require("feascript");
51+
import { FEAScriptModel } from "feascript";
2852
```
2953

30-
**Important:** FEAScript is built as an ES module. If you're starting a new project, make sure to configure it to use ES modules by running:
54+
**Important:** FEAScript is built as an ES module. If you're starting a completely new project (outside this repository), make sure to configure it to use ES modules by (when running examples from within this repository, this step is not needed as the root package.json already has the proper configuration):
3155

3256
```bash
3357
# Create package.json with type=module for ES modules support
3458
echo '{"type":"module"}' > package.json
3559
```
3660

37-
If you already have a package.json file, manually add `"type": "module"` to enable ES modules in your project.
61+
Explore various Node.js examples and use cases [here](https://github.com/FEAScript/FEAScript-core/tree/main/examples).
3862

39-
### Option 2: Direct Import from CDN
40-
41-
Add this line to your HTML or JavaScript module:
63+
## Example Usage
4264

65+
**Browser Import:**
4366
```javascript
44-
import { FEAScriptModel, plotSolution } from "https://core.feascript.com/dist/feascript.esm.js";
67+
// Import FEAScript library in browser
68+
import { FEAScriptModel } from "https://core.feascript.com/dist/feascript.esm.js";
4569
```
4670

47-
### Option 3: Download and Use Locally
48-
49-
1. Download the latest release from [GitHub Releases](https://github.com/FEAScript/FEAScript-core/releases)
50-
2. Include it in your project:
51-
52-
```html
53-
<script type="module">
54-
import { FEAScriptModel, plotSolution } from "./path/to/dist/feascript.esm.js";
55-
// Your code here
56-
</script>
71+
**Node.js Import:**
72+
```javascript
73+
// Import FEAScript library in Node.js
74+
import { FEAScriptModel } from "feascript";
5775
```
58-
59-
### Example Usage
60-
6176
```javascript
62-
// Import FEAScript library
63-
import { FEAScriptModel, plotSolution } from "https://core.feascript.com/dist/feascript.esm.js";
64-
6577
// Create and configure model
6678
const model = new FEAScriptModel();
6779
model.setSolverConfig("solverType"); // e.g., "solidHeatTransfer" for a stationary solid heat transfer case
6880
model.setMeshConfig({
69-
// Define mesh configuration (assuming a rectangular domain for 2D)
7081
meshDimension: "1D" | "2D", // Mesh dimension
7182
elementOrder: "linear" | "quadratic", // Element order
7283
numElementsX: number, // Number of elements in x-direction
@@ -79,21 +90,10 @@ model.setMeshConfig({
7990
model.addBoundaryCondition("boundaryIndex", ["conditionType", /* parameters */]);
8091

8192
// Solve
93+
model.setSolverMethod("linearSolver"); // lusolve (via mathjs) or jacobi
8294
const { solutionVector, nodesCoordinates } = model.solve();
83-
84-
// Plot results
85-
plotSolution(
86-
solutionVector,
87-
nodesCoordinates,
88-
model.solverConfig,
89-
model.meshConfig.meshDimension,
90-
"plotType", // e.g., "contour"
91-
"targetDivId" // HTML div ID for plot
92-
);
9395
```
9496

95-
Explore various examples and use cases of FEAScript [here](https://github.com/FEAScript/FEAScript-core/tree/main/examples).
96-
9797
## Contribute
9898

9999
We warmly welcome contributors to help expand and refine FEAScript. Please see the [CONTRIBUTING.md](./CONTRIBUTING.md) file for detailed guidance on how to contribute.

dist/feascript.cjs.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/feascript.cjs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/feascript.esm.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/feascript.esm.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/feascript.umd.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/feascript.umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/solidHeatTransferScript/HeatConduction1DWall/HeatConduction1DWall.html

Lines changed: 0 additions & 90 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// ______ ______ _____ _ _ //
2+
// | ____| ____| /\ / ____| (_) | | //
3+
// | |__ | |__ / \ | (___ ___ ____ _ ____ | |_ //
4+
// | __| | __| / /\ \ \___ \ / __| __| | _ \| __| //
5+
// | | | |____ / ____ \ ____) | (__| | | | |_) | | //
6+
// |_| |______/_/ \_\_____/ \___|_| |_| __/| | //
7+
// | | | | //
8+
// |_| | |_ //
9+
// Website: https://feascript.com/ \__| //
10+
11+
// Import Math.js
12+
import * as math from "mathjs";
13+
global.math = math;
14+
15+
// Import FEAScript library
16+
import { FEAScriptModel, logSystem, VERSION } from "feascript";
17+
18+
console.log('FEAScript Version:', VERSION);
19+
20+
// Create a new FEAScript model
21+
const model = new FEAScriptModel();
22+
23+
// Set solver configuration
24+
model.setSolverConfig("solidHeatTransferScript");
25+
26+
// Define mesh configuration
27+
model.setMeshConfig({
28+
meshDimension: "1D",
29+
elementOrder: "linear",
30+
numElementsX: 10,
31+
maxX: 0.15,
32+
});
33+
34+
// Define boundary conditions
35+
model.addBoundaryCondition("0", ["convection", 1, 25]);
36+
model.addBoundaryCondition("1", ["constantTemp", 5]);
37+
38+
// Set solver method (optional)
39+
model.setSolverMethod("lusolve");
40+
41+
// Solve the problem and get the solution
42+
const { solutionVector, nodesCoordinates } = model.solve();
43+
44+
// Print results to console
45+
console.log("Solution vector:", solutionVector);
46+
console.log("Node coordinates:", nodesCoordinates);
47+
console.log(`Number of nodes: ${nodesCoordinates.nodesXCoordinates.length}`);

0 commit comments

Comments
 (0)