Skip to content

Increasing the usage #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sridhar-mani opened this issue Apr 2, 2025 · 23 comments
Open

Increasing the usage #10

sridhar-mani opened this issue Apr 2, 2025 · 23 comments
Assignees
Labels
enhancement New feature or request FEAScript 0.2.0

Comments

@sridhar-mani
Copy link
Collaborator

Currently with the web worker also when we reach the mesh size of about 1000 or so we get memory issue. I am not a CFD person so i'm guessing a workaround is needed to run the simulation in the WebGPU offloading all the work load to it and only plotting the result.

@sridhar-mani
Copy link
Collaborator Author

Also instead of plotting maybe we can make a time dependent solver and try running it in a simple mesh to see how it goes.

@nikoscham
Copy link
Member

nikoscham commented Apr 2, 2025

Currently with the web worker also when we reach the mesh size of about 1000 or so we get memory issue. I am not a CFD person so i'm guessing a workaround is needed to run the simulation in the WebGPU offloading all the work load to it and only plotting the result.

Thanks for the pull request! WebGPU can be a solution. Additionally, using a more memory-efficient linear solver would help. Currently, I’m using lusolve (LU Decomposition), which isn’t ideal for large problems (mesh size ~1000, as you noted). An iterative solver (e.g. GMRES) would be a better option. However, I believe both improvements can be combined (i.e. implementing an iterative solver optimized for GPU). I can create a roadmap for such an implementation.

@nikoscham nikoscham added the enhancement New feature or request label Apr 2, 2025
@sridhar-mani
Copy link
Collaborator Author

Yes! exactly i think openfoam using such solvers which are memory efficient to achieve near accurate results. If it is possible like that we can offload chunks of the computation to seperate workers and offload asynchronously to webgpu maybe?

@nikoscham
Copy link
Member

Yes! exactly i think openfoam using such solvers which are memory efficient to achieve near accurate results. If it is possible like that we can offload chunks of the computation to seperate workers and offload asynchronously to webgpu maybe?

Yes, we should do that. I believe that using iterative solvers on the GPU is the only way to have an efficient CFD solver in JS. Also, iterative solvers can produce results as accurate as direct solvers, but they require more iterations (however they use less memory and are better for parallel execution).

@sridhar-mani
Copy link
Collaborator Author

If possible compile this into a npm library that might be good.

@nikoscham
Copy link
Member

If possible compile this into a npm library that might be good.

I'll look into this, thanks for your suggestion

@sridhar-mani
Copy link
Collaborator Author

I can help you with that if needed

@nikoscham
Copy link
Member

nikoscham commented Apr 2, 2025

Currently with the web worker

I've temporarily disabled the web worker export due to persistent CORS issues when loading Comlink from CDN. Once we resolve these cross-origin restrictions (either by bundling Comlink locally or finding a compatible CDN), we can re-enable this feature. See here: 8e478dd

@sridhar-mani
Copy link
Collaborator Author

sridhar-mani commented Apr 2, 2025

That can be solved once we use the es export as per the standard that we will follow if we make it as a library in npm. I have solved the issue locally but i think its better to use es dynamic import as that will always maintain the functionality. Is it okay? And if it is then we can restructure the src into a library.

@nikoscham
Copy link
Member

@sridhar-mani Yes, making FEAScript into an npm library would definitely help. This would address the issues with CORS. I'll need a bit of time to read up on npm packaging (I am not as experienced as you in this).
In the meantime, I've implemented a temporary fix for the CORS issues by using a local version of the Comlink library. See here 85fa913
This should work as a temporary solution until we can properly structure the project as an npm package. I am also working on reformulating the examples in order to use the Workers functionality. I am grateful for your help in the project!

@sridhar-mani
Copy link
Collaborator Author

sridhar-mani commented Apr 3, 2025

No worries. I'm working on writing a import module to import tetra meshes from gmesh. Want a clarification whether that is the best mesh format for FEA.

FYI-Saw the pr its good to use it from local. And it would solve the issue for now in the current stage.

@nikoscham
Copy link
Member

nikoscham commented Apr 9, 2025

BTW - Also made a gpu branch where fully webgpu offloading has been implemented.

Originally posted by @sridhar-mani in #5

I have implemented a simple iterative solver (Jacobi Method) - https://github.com/FEAScript/FEAScript-core/blob/main/src/methods/jacobiMethodScript.js
You can start from this one to test the GPU acceleration on the matrices operations. Apart from WebGPU, an other option is also GPU.js.

@sridhar-mani
Copy link
Collaborator Author

GPU.js is also a light weight gpu programming wrapper in js. Taichi.js is superior to it.

@nikoscham
Copy link
Member

nikoscham commented Apr 23, 2025

If it is possible like that we can offload chunks of the computation to separate workers

I've made some updates with Web Workers. Here's a 2D fin tutorial using a worker:
https://feascript.com/tutorials/HeatConduction2DFinWorker.html
To run this, from the FEAScript website, you will need to disable "cross-origin" restrictions in your browser. For example for the Chromium browser I use the command chromium-browser --disable-web-security --user-data-dir="/tmp/chrome-cors" --disable-site-isolation-trials

To resolve this CORS issue properly, we have two main options:

  1. Copy the FEAScript-core files into the website repository (https://github.com/FEAScript/FEAScript-website) to ensure same-origin or
  2. Host the FEAScript-core library on a dedicated server (not GitHub Pages) that allows for the configuration of appropriate CORS headers.

Please share any other potential solutions you might have. Thanks again for the contribution!

@nikoscham
Copy link
Member

I have also created this minimal Web Worker example https://github.com/FEAScript/FEAScript-core/blob/main/examples/solidHeatTransferScript/HeatConduction2DFin/HeatConduction2DFinWorker.html
I have reduced the mesh size, as the 36x18 version took quite a while to run. We need a faster linear solver here!

@sridhar-mani
Copy link
Collaborator Author

If it is possible like that we can offload chunks of the computation to separate workers

I've made some updates with Web Workers. Here's a 2D fin tutorial using a worker: https://feascript.com/tutorials/HeatConduction2DFinWorker.html To run this, from the FEAScript website, you will need to disable "cross-origin" restrictions in your browser. For example for the Chromium browser I use the command chromium-browser --disable-web-security --user-data-dir="/tmp/chrome-cors" --disable-site-isolation-trials

To resolve this CORS issue properly, we have two main options:

  1. Copy the FEAScript-core files into the website repository (https://github.com/FEAScript/FEAScript-website) to ensure same-origin or
  2. Host the FEAScript-core library on a dedicated server (not GitHub Pages) that allows for the configuration of appropriate CORS headers.

Please share any other potential solutions you might have. Thanks again for the contribution!

Packaging FEAScript-core as an ES6 module and publishing it as an npm library is one of the cleanest and most future-proof solutions.

@nikoscham
Copy link
Member

If it is possible like that we can offload chunks of the computation to separate workers

I've made some updates with Web Workers. Here's a 2D fin tutorial using a worker: https://feascript.com/tutorials/HeatConduction2DFinWorker.html To run this, from the FEAScript website, you will need to disable "cross-origin" restrictions in your browser. For example for the Chromium browser I use the command chromium-browser --disable-web-security --user-data-dir="/tmp/chrome-cors" --disable-site-isolation-trials
To resolve this CORS issue properly, we have two main options:

  1. Copy the FEAScript-core files into the website repository (https://github.com/FEAScript/FEAScript-website) to ensure same-origin or
  2. Host the FEAScript-core library on a dedicated server (not GitHub Pages) that allows for the configuration of appropriate CORS headers.

Please share any other potential solutions you might have. Thanks again for the contribution!

Packaging FEAScript-core as an ES6 module and publishing it as an npm library is one of the cleanest and most future-proof solutions.

Great, we’ll go ahead with that. I just want to finalize a couple of features before we prepare the first release (v0.1.0). These are: 1) finalize the 1D solid heat transfer solver and 2) the .msh meshes import. Once those are in place, we will publish it to npm.

@sridhar-mani
Copy link
Collaborator Author

If it is possible like that we can offload chunks of the computation to separate workers

I've made some updates with Web Workers. Here's a 2D fin tutorial using a worker: https://feascript.com/tutorials/HeatConduction2DFinWorker.html To run this, from the FEAScript website, you will need to disable "cross-origin" restrictions in your browser. For example for the Chromium browser I use the command chromium-browser --disable-web-security --user-data-dir="/tmp/chrome-cors" --disable-site-isolation-trials
To resolve this CORS issue properly, we have two main options:

  1. Copy the FEAScript-core files into the website repository (https://github.com/FEAScript/FEAScript-website) to ensure same-origin or
  2. Host the FEAScript-core library on a dedicated server (not GitHub Pages) that allows for the configuration of appropriate CORS headers.

Please share any other potential solutions you might have. Thanks again for the contribution!

Packaging FEAScript-core as an ES6 module and publishing it as an npm library is one of the cleanest and most future-proof solutions.

Great, we’ll go ahead with that. I just want to finalize a couple of features before we prepare the first release (v0.1.0). These are: 1) finalize the 1D solid heat transfer solver and 2) the .msh meshes import. Once those are in place, we will publish it to npm.

Sure we can do it. Also go through this library and see if its okay to integrate this also:https://github.com/amandaghassaei/msh-parser.

@nikoscham
Copy link
Member

nikoscham commented Apr 27, 2025

Also go through this library and see if its okay to integrate this also:https://github.com/amandaghassaei/msh-parser.

Maybe we could try incorporate it in the FEAScript platform. However, I am concerned since it doesn't seem to be actively maintained and also it doesn't seem to work with the 2D meshes I have tried..

By the way, FEAScript platform is the latest addition to the project - a browser-based visual editor. You can test it by downloading this XML example and loading it into the FEAScript platform. Let me know what you think if you check it out!

@nikoscham
Copy link
Member

I just want to finalize a couple of features before we prepare the first release (v0.1.0). These are: 1) finalize the 1D solid heat transfer solver and 2) the .msh meshes import. Once those are in place, we will publish it to npm.

Sure we can do it.

These tasks are now complete — the first release is just around the corner! I’ll run some tests over the next 1–2 days to make sure everything is working properly. We will proceed with the npm packaging after that.

@sridhar-mani
Copy link
Collaborator Author

Yeah maybe we can try to modularize the code such that it can be a lego like approach like openfoam.

@nikoscham
Copy link
Member

Yeah maybe we can try to modularize the code such that it can be a lego like approach like openfoam.

Yes, that's my goal too. Hopefully, we'll get there as development progresses. The idea is to have solvers (e.g., solidHeatTransferScript) that are complete applications for specific types of simulations, analogous to OpenFOAM solvers (e.g., solidFoam). These solvers would call reusable components of the software, such as meshGenerationScript, basisFunctionsScript, numericalIntegrationScript, etc. Ideally, the integration between solvers and reusable components will become more robust and efficient as the project matures.

@nikoscham
Copy link
Member

nikoscham commented May 19, 2025

This issue has been added to the FEAScript roadmap for the upcoming 0.2.0 release (https://github.com/orgs/FEAScript/discussions/17). Specifically, it concerns using GPU acceleration to speed up iterative solvers.

Tasks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request FEAScript 0.2.0
Projects
None yet
Development

No branches or pull requests

2 participants