multiphysics fem in freecad

About the development of the FEM module/workbench.

Moderator: bernd

User avatar
halbux
Posts: 6
Joined: Wed Feb 21, 2018 7:05 am
Location: Tampere, Finland

multiphysics fem in freecad

Postby halbux » Mon May 03, 2021 7:32 am

Hi,

Regarding providing high-performance multiphysics FEM capabilities in FreeCAD:

I am the developer of sparselizard.org FEM library. There has been some minor talks already to couple it with FreeCAD and I would like to express my support for that. There should already be more than enough capabilities for any physic you'd like to consider and all what might be missing can be added. I know you provide already an interface to CalculiX but I am sure additional physics and seriously faster computations would be welcome to bring FreeCAD closer to a commercial-grade FEM software: why would you limit yourself to mechanics or cfd when you can as well provide electromagnetic simulation (antenna radiation patterns,...) all in one single package. That's just one step away, you already have most of what's needed in terms of CAD, interactive region selection, gmsh coupling and user-interfacing!
Source code at: https://github.com/halbux/sparselizard

Alex
User avatar
johnwang
Posts: 676
Joined: Sun Jan 27, 2019 12:41 am

Re: multiphysics fem in freecad

Postby johnwang » Mon May 03, 2021 8:26 am

One easy way is you read calculix's inp file.
hfc series CAE workbenches for FreeCAD (hfcNastran95, hfcMystran, hfcFrame3DD, hfcSU2 and more)
User avatar
halbux
Posts: 6
Joined: Wed Feb 21, 2018 7:05 am
Location: Tampere, Finland

Re: multiphysics fem in freecad

Postby halbux » Mon May 03, 2021 9:18 am

No I don't. I had a look at the format though... It seems quite specific to mechanics and somewhat not modern :p
RatonLaveur
Posts: 976
Joined: Wed Mar 27, 2019 10:45 am

Re: multiphysics fem in freecad

Postby RatonLaveur » Mon May 03, 2021 10:06 am

I know that I am technically "off topic" by talking about this, but since Elmer is the closest multi-physics implementation we have at the moment I have to mention it.

I have no information yet on Sparselizard but will check it out.

Currently multi-physics in FreeCAD has been initially implemented for the Elmer solver.
https://forum.freecadweb.org/viewtopic. ... ilit=elmer

A cursive search through our forums show that since 2010 there was already discussion and suggestion of using Elmer for multi-physics in FC.

A Google Summer of Code (GSoC) was proposed, validated and conducted in 2017 to fast-track a basic level of implementation:
https://forum.freecadweb.org/viewtopic. ... ilit=elmer
https://forum.freecadweb.org/viewtopic. ... ilit=elmer

The main effort of development was described as an activity log:
https://forum.freecadweb.org/viewtopic. ... ilit=elmer

During and since then, many discussions on the implementation have been discussed with the following difficulties being raised:

- It is a lot of work to have the FreeCAD GUI control all the solver possibilities
- specifically the calling of "all" physics models
- as well as types of Boundary Condition.

Essentially, each solver system needs to be translated from User--> FreeCAD GUI --> Solver Input File Writing and then solving.

I am sharing all this so you understand the current capabilities/shortcomings of FC_FEM regarding multi-physics as well as the quantity and type of work involved in implementing/integrating another solver.

That being said, I am in no way, shape or form trying to discourage/disparage or otherwise detract from your proposition regarding Sparselizard (quite the contrary). You will find the FEM community here is happy to try their hands on "new toys" and to give constructive testing and feedback.

If I can share one opinion, in order to get up and running as fast and painlessly as possible with a new solver, i would now suggest the following actions be undertaken:

- a complete back-end able to:
-- take a FC-FEM mesh generated by gmsh and convert it as a useable mesh for your solver
-- able to generate a solver input file and send it to the solver of your choice
-- capable of reading the results of said solver back into freecad.

- a sparse front-end able to:
-- target case elements (volumes, boundaries...) correctly in the solver input file
-- add "Free Text Input" to those elements so that initially there is no need to create complete new GUI tools (the most painful work, and the most limiting...since there is no way the developer will be able to create a comprehensive set of GUI tools...as much as it would help).


In such an approach, users can "write" the case in blocks, based on the documentation of the solver, and the developer gives themselves the time and opportunity to slowly work on user-friendliness by:
- implementing templates of the FreeTextInput based on where it is called (BC, ...etc)
- implementing suggestions for the FreeTextInput by "simply" copy-pasting the relevant documentation paragraphs so that the user can easily read and write.

Later on, more automated/GUI features can be implemented piece-meal based on the users/developers time, will and need.

Hopefully my post is useful.
User avatar
halbux
Posts: 6
Joined: Wed Feb 21, 2018 7:05 am
Location: Tampere, Finland

Re: multiphysics fem in freecad

Postby halbux » Mon May 03, 2021 10:28 am

Thanks for the post!

I understand it is quite some work to take into account all physics with their own type of boundary conditions and all their coupling, but the impact for users is huge and there is no open source tool doing that really!
Concerning the mesh loading part, sparselizard reads GMSH format natively so that box can be ticked.

Advantages of sparselizard over Elmer: you get an extremely concise and readable code without loss of capabilities or speed, so from that part you are not getting lost in 1000 lines of Elmer code and managing all the physics code on the FEM side becomes easier.

For the rest I am in to add things you need to interface sparselizard with FreeCAD, e.g. the output format needed by FreeCAD (unless you support ParaView format .vtk or .vtu already), I can provide the sparselizard code for the physics you want to add,... I'am yours to make all the interfacing easy.

Alex
RatonLaveur
Posts: 976
Joined: Wed Mar 27, 2019 10:45 am

Re: multiphysics fem in freecad

Postby RatonLaveur » Mon May 03, 2021 11:44 am

halbux wrote:
Mon May 03, 2021 10:28 am
but the impact for users is huge and there is no open source tool doing that really!
Yes indeed!
halbux wrote:
Mon May 03, 2021 10:28 am
Advantages of sparselizard over Elmer: you get an extremely concise and readable code without loss of capabilities or speed, so from that part you are not getting lost in 1000 lines of Elmer code and managing all the physics code on the FEM side becomes easier.
Last I checked, from the user perspective, the Elmer Solver Input File is quite readable and easy to write/maintain. Just want to keep the record straight here ;)
halbux wrote:
Mon May 03, 2021 10:28 am
For the rest I am in to add things you need to interface sparselizard with FreeCAD, e.g. the output format needed by FreeCAD (unless you support ParaView format .vtk or .vtu already),
Here you can check, FreeCAD already has .vtk and .vtu visualization tools. I am not so versed in what file freecad would receive for post-processing, but i know .vtu can work. Many people already use ParaView, so again for a first draft, ParaView visualization may suffice and the FreeCAD .vtk tools can be used/implemented later.
halbux wrote:
Mon May 03, 2021 10:28 am
I can provide the sparselizard code for the physics you want to add,
Essentially here, from a user point of view, what could work is:

1. Create the CAD file
2. Go to FEM workbench, create an new analysis
3. Select "Sparselizard" as a solver
4. Use gmsh to mesh/refine mesh.
5. Pick a face/edge and press the "FreeBoundaryCondition" (or whatever) button:
5.a. here a prompt appears with a text input field
5.b. the text may be a template or completely free, a tool-tip may suggest what to write for what case
6. Repeat for other BCs / Solver data
7. Press "Write Case" (all the text data is compiled into the solver file for SparseLizard)
8. Press "Solve" (initiate solving routine).

What I suggest is that you try to do it once with Elmer (to have an idea what happens currently). And that could guide you.
User avatar
halbux
Posts: 6
Joined: Wed Feb 21, 2018 7:05 am
Location: Tampere, Finland

Re: multiphysics fem in freecad

Postby halbux » Mon May 03, 2021 11:51 am

Developing the FEM library is itself already very time consuming and I unfortunately cannot add more work to that. If anyone at some point was going in that direction however and gives clear indication of what's needed to be added from the sparselizard side or what physic example he wants, I would gladly do that!

Alex
User avatar
johnwang
Posts: 676
Joined: Sun Jan 27, 2019 12:41 am

Re: multiphysics fem in freecad

Postby johnwang » Mon May 03, 2021 3:00 pm

Reading inp is easy, but you can do no more than calculix.
If you want to let freecad output your format, it is a bit hard.
hfc series CAE workbenches for FreeCAD (hfcNastran95, hfcMystran, hfcFrame3DD, hfcSU2 and more)