Skip to content

Commit 913cddc

Browse files
committed
Refactor WebGPU solver methods, and remove deprecated files
1 parent fe316da commit 913cddc

File tree

9 files changed

+246
-175
lines changed

9 files changed

+246
-175
lines changed

NOTICE.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ FEAScript makes use of the following third-party software:
1111

1212
3. **Comlink**
1313
- License: Apache 2.0 (https://github.com/GoogleChromeLabs/comlink/blob/main/LICENSE)
14-
- Source: https://github.com/GoogleChromeLabs/comlink
14+
- Source: https://github.com/GoogleChromeLabs/comlink
15+
16+
4. **taichi.js**
17+
- License: MIT (https://github.com/AmesingFlank/taichi.js/blob/main/LICENSE)
18+
- Source: https://github.com/AmesingFlank/taichi.js

README.md

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@
44

55
[![npm version](https://img.shields.io/npm/v/feascript)](https://www.npmjs.com/package/feascript)
66

7-
<!-- [![liberapay](https://img.shields.io/liberapay/receives/FEAScript.svg?logo=liberapay)](https://liberapay.com/FEAScript/) -->
8-
97
[FEAScript](https://feascript.com/) is a lightweight finite element simulation library written in JavaScript. It empowers users to perform simulations for physics and engineering applications in both browser-based and server-side environments. This is the core library of the FEAScript project.
108

119
> 🚧 **FEAScript is currently under heavy development.** Its functionality and interfaces may change rapidly as new features and enhancements are introduced.
1210
1311
## Contents
1412

1513
- [Ways to Use FEAScript](#ways-to-use-feascript)
16-
- [JavaScript API (FEAScript Core)](#javascript-api-feascript-core)
14+
- [FEAScript API](#feascript-api)
1715
- [Use FEAScript in the Browser](#use-feascript-in-the-browser)
1816
- [Use FEAScript with Node.js](#use-feascript-with-nodejs)
19-
- [Use FEAScript with Scribbler](#use-feascript-with-scribbler)
20-
- [Visual Editor (FEAScript Platform)](#visual-editor-feascript-platform)
17+
- [Use FEAScript in JavaScript Playgrounds](#use-feascript-in-javascript-playgrounds)
18+
- [FEAScript Platform](#feascript-platform)
2119
- [Quick Example](#quick-example)
2220
- [Support FEAScript](#support-feascript)
2321
- [Contributing](#contributing)
@@ -27,22 +25,22 @@
2725

2826
FEAScript offers two main approaches to creating simulations:
2927

30-
1. **[JavaScript API (FEAScript Core)](#javascript-api-feascript-core)** – For developers comfortable with coding, providing full programmatic control in browsers, Node.js, or interactive notebooks.
31-
2. **[Visual Editor (FEAScript Platform)](#visual-editor-feascript-platform)** – For users who prefer a no-code approach, offering a block-based visual interface built with [Blockly](https://developers.google.com/blockly).
28+
1. **[FEAScript API](#feascript-api)** – For developers comfortable with coding, providing full programmatic control in browsers, Node.js, or interactive notebooks.
29+
2. **[FEAScript Platform](#feascript-platform)** – For users who prefer a no-code approach, offering a block-based visual interface built with [Blockly](https://blockly.com/).
3230

3331
Each approach is explained in detail below.
3432

35-
### JavaScript API (FEAScript Core)
33+
### FEAScript API
3634

37-
The JavaScript API is the core programmatic interface for FEAScript. Written entirely in pure JavaScript, it runs in three environments:
35+
The FEAScript API is the core programmatic interface for FEAScript. Written entirely in pure JavaScript, it runs in three environments:
3836

3937
1. **[In the browser](#use-feascript-in-the-browser)** – Use FEAScript in a simple HTML page, running simulations locally without additional installations or cloud services.
4038
2. **[With Node.js](#use-feascript-with-nodejs)** – Use FEAScript in server-side JavaScript applications or CLI tools.
41-
3. **[With Scribbler](#use-feascript-with-scribbler)** – Use FEAScript in the [Scribbler](https://scribbler.live/) interactive JavaScript notebook environment.
39+
3. **[In JavaScript playgrounds](#use-feascript-in-javascript-playgrounds)** – Use FEAScript in the [Scribbler](https://scribbler.live/) interactive JavaScript notebook environment.
4240

4341
#### Use FEAScript in the Browser
4442

45-
You can use FEAScript in browser environments in two ways:
43+
You can use FEAScript in browser environments in three ways:
4644

4745
- **Import from Hosted ESM Build:**
4846

@@ -52,6 +50,14 @@ You can use FEAScript in browser environments in two ways:
5250
</script>
5351
```
5452

53+
- **Import from CDN:**
54+
55+
```html
56+
<script type="module">
57+
import { FEAScriptModel } from "https://cdn.jsdelivr.net/gh/FEAScript/FEAScript-core/dist/feascript.esm.js";
58+
</script>
59+
```
60+
5561
- **Download and Use Locally:**
5662

5763
You can download the latest stable release from [GitHub Releases](https://github.com/FEAScript/FEAScript-core/releases).
@@ -89,27 +95,29 @@ When running examples from within this repository, this step isn’t needed as t
8995

9096
👉 Explore Node.js use cases on the [examples directory](https://github.com/FEAScript/FEAScript-core/tree/main/examples).
9197

92-
#### Use FEAScript with Scribbler
98+
#### Use FEAScript in JavaScript Playgrounds
9399

94-
FEAScript also works well in interactive JavaScript notebook environments where you can write code, visualize results inline, and share your work with others. [Scribbler](https://scribbler.live/) is one such platform that comes with preloaded scientific libraries, making it an excellent choice for FEAScript simulations.
100+
FEAScript works well in interactive JavaScript playgrounds where you can write code, visualize results inline, and share your work.
95101

96-
👉 Explore FEAScript notebook examples on the [Scribbler Hub](https://hub.scribbler.live/portfolio/#!nikoscham/FEAScript-Scribbler-examples).
102+
👉 Explore the following examples:
103+
- [CodePen (interactive pens)](https://codepen.io/FEAScript)
104+
- [Scribbler (notebooks)](https://hub.scribbler.live/portfolio/#!nikoscham/FEAScript-Scribbler-examples)
97105

98-
### Visual Editor (FEAScript Platform)
106+
### FEAScript Platform
99107

100-
For users who prefer a visual approach to creating simulations, we offer the [FEAScript Platform](https://platform.feascript.com/) - a browser-based visual editor built on the [Blockly](https://developers.google.com/blockly) library. This no-code interface allows you to:
108+
For users who prefer a visual approach to creating simulations, we offer the [FEAScript Platform](https://feascript.com/feascript-platform.html) - a browser-based visual editor built on the [Blockly](https://blockly.com/) library. This no-code interface allows you to:
101109

102110
- Build and run finite element simulations directly in your browser by connecting visual blocks together.
103111
- Create complex simulations without writing any JavaScript code.
104112
- Save and load projects in XML format for easy sharing and reuse.
105113

106-
While FEAScript's JavaScript API offers full programmatic control for advanced customization, the FEAScript Platform provides an accessible entry point for users without coding experience.
114+
While FEAScript API offers full programmatic control for advanced customization, the FEAScript Platform provides an accessible entry point for users without coding experience.
107115

108-
👉 Explore FEAScript Platform examples on our [website](https://feascript.com/#tutorials).
116+
<!-- > Note: The FEAScript Platform is not yet available -->
109117

110118
## Quick Example
111119

112-
Here is a minimal browser-based example using the JavaScript API. Adapt paths, solver types, and boundary conditions as needed for your specific problem:
120+
Here is a minimal browser-based example using the FEAScript API. Adapt paths, solver types, and boundary conditions as needed for your specific problem:
113121

114122
```html
115123
<body>

examples/heatConductionScript/heatConduction2DFin/HeatConduction2DFinCG.html

Lines changed: 0 additions & 96 deletions
This file was deleted.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Heat Conduction 2D Fin - GPU Jacobi Solver</title>
8+
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/5.0.0/math.min.js"></script>
9+
<script src="https://cdnjs.cloudflare.com/ajax/libs/plotly.js/2.27.0/plotly.min.js"></script>
10+
<style>
11+
body {
12+
font-family: Arial, sans-serif;
13+
max-width: 1200px;
14+
margin: 0 auto;
15+
padding: 20px;
16+
}
17+
18+
.result {
19+
background-color: #f5f5f5;
20+
padding: 10px;
21+
margin: 10px 0;
22+
border-radius: 3px;
23+
}
24+
25+
.success {
26+
color: green;
27+
}
28+
29+
.error {
30+
color: red;
31+
}
32+
</style>
33+
</head>
34+
35+
<body>
36+
<h1>Heat Conduction in 2D Fin - GPU Jacobi Solver</h1>
37+
<div id="solutionPlot"></div>
38+
<div id="result" class="result"></div>
39+
40+
<script type="module">
41+
import { FEAScriptModel, plotSolution } from "../../../src/index.js";
42+
43+
window.addEventListener("DOMContentLoaded", async () => {
44+
const model = new FEAScriptModel();
45+
model.setSolverConfig("heatConductionScript");
46+
47+
model.setMeshConfig({
48+
meshDimension: "2D",
49+
elementOrder: "quadratic",
50+
numElementsX: 20,
51+
numElementsY: 10,
52+
maxX: 4000,
53+
maxY: 2000,
54+
});
55+
56+
model.addBoundaryCondition("0", ["constantTemp", 200]);
57+
model.addBoundaryCondition("1", ["symmetry"]);
58+
model.addBoundaryCondition("2", ["convection", 1, 20]);
59+
model.addBoundaryCondition("3", ["constantTemp", 200]);
60+
61+
const resultDiv = document.getElementById("result");
62+
resultDiv.innerHTML = "Assembling system and solving with GPU Jacobi...";
63+
64+
// GPU Jacobi; worker is managed internally by solveLinearSystemAsync
65+
model.setSolverMethod("jacobi-gpu");
66+
67+
// Keep the first arg undefined: the API still accepts an optional computeEngine
68+
const { solutionVector, nodesCoordinates } = await model.solveAsync({
69+
maxIterations: 10000,
70+
tolerance: 1e-3,
71+
});
72+
73+
const n = solutionVector.length;
74+
resultDiv.innerHTML = `
75+
<div>System size: ${n} x ${n}</div>
76+
<div>Solution computed with WebGPU Jacobi</div>
77+
<div class="success">SOLUTION COMPLETED</div>
78+
`;
79+
80+
plotSolution(
81+
solutionVector,
82+
nodesCoordinates,
83+
model.solverConfig,
84+
model.meshConfig.meshDimension,
85+
"contour",
86+
"solutionPlot"
87+
);
88+
});
89+
</script>
90+
</body>
91+
92+
</html>

0 commit comments

Comments
 (0)