Fenics as Solver

About the development of the FEM module/workbench.

Moderator: bernd

Posts: 14
Joined: Thu Dec 01, 2011 10:00 pm

Fenics as Solver

Postby nonlimited » Thu Oct 03, 2013 12:06 pm


from the wiki I have seen two possible solvers, namely Calculix and Code-Aster. I'm not quite sure if there has been any itegration done yet.

So I just wanted to throw in a third one:

Fenics Project - http://fenicsproject.org/

It has a really great python interface with which you can formulate your PDEs as you would do on paper.
User avatar
Site Admin
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany

Re: Fenics as Solver

Postby jriegel » Sun Oct 20, 2013 9:03 pm

So far I go for Calculix, but the it will be later on easy to incorporate any kind of solver.
Stop whining - start coding!
Posts: 2825
Joined: Mon Nov 11, 2013 5:29 pm

Re: Fenics as Solver

Postby looo » Sat Nov 26, 2016 12:22 pm

I would like to give this a try. But I need some help to get started. What has to be done to add a new solver.

The fenics solver would be a simple object which has a solver-macro property. The function in the macro gets all the necessary data (mesh, bc, material,...). The computation is then done inside of a function. and the result is returned as a dict (for example).

@Bernd. It would be nice if you can provide some information on the files that have to be written to add a new solver. Also I am interested if such a generic approach would work. At the moment I would like to do this only with 2d fem. But it would be nice if this could work with 3d too.
Posts: 838
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Fenics as Solver

Postby HoWil » Sat Nov 26, 2016 2:07 pm

I think Code-Aster is not supported but instead Z88 is integrated in parallel to calculix.

There was also some discussion about integrating Openfoam and Elmer into FreeCAD. This simply shows that the interface should be as generic as possible. Help there helps all others and future integration attempts.
Posts: 2825
Joined: Mon Nov 11, 2013 5:29 pm

Re: Fenics as Solver

Postby looo » Sat Nov 26, 2016 2:42 pm

There are a few different levels of abstraction.... The fenics library is more the mathematical approach. It's nice because it's easy to solve any custom pde. Calculix, code aster ... are on a much higher level. Different abstraction need different interfaces.... But with fenics we could add a really generic interface I think. At least for the use cases I can think of.

I like the idea to simple plug a solver as a python file into freecad. This would need some generic boundary condition as well, but I think the bc allready available will do the job as well.
Posts: 2918
Joined: Wed Oct 05, 2011 7:36 am

Re: Fenics as Solver

Postby ickby » Sat Nov 26, 2016 4:18 pm

I use fenics a lot and like it very much. But it is gpl, so cant be shipped with freecad. Of course it would be nice to have some way. to autogenerate fenic sscripts in freecad. But most important imho is to Export Dolphin meshes. They can include defined Mesh Domains which than can easily be used in Dolphin by Name for boundary conditions etc. That would be awesome!
User avatar
Posts: 1317
Joined: Fri May 16, 2014 1:14 pm

Re: Fenics as Solver

Postby saso » Sat Nov 26, 2016 4:27 pm

All FEniCS core components are licensed under the GNU LGPL as published by the Free Software Foundation, either version 3 of the license, or (at your option) any later version.

All other FEniCS components are licensed under either the GNU GPL or the GNU LGPL, either version 3 of the license, or (at your option) any later version.

Authors and institutions have given their consent to licensing under these terms.
Their https://femtable.org/ is also quite nice :)
Posts: 2825
Joined: Mon Nov 11, 2013 5:29 pm

Re: Fenics as Solver

Postby looo » Sat Nov 26, 2016 4:32 pm

to autogenerate fenic sscripts in freecad.
my idea was to have different solvers as python scripts available via the plugin-manager. In the Fem gui one can select one of these solvers. This way there shouldn't be any license problem and also other pde-solvers could be used in the script.
Posts: 236
Joined: Tue Oct 11, 2016 9:48 pm

Re: Fenics as Solver

Postby joha2 » Sun Nov 27, 2016 1:57 am

Hey guys. I just started with Fenics, played around a little with it and I am very impressed about its flexibility. Although I am not very experienced with it, I would be very interested in coding an interface for FreeCAD. As far as I understood the FEM workbench in its actual state has "only" support for linear static analysis, modal frequencies and thermo-mechanical analysis ("only" in "" because you did a great work with it! :-) ). I think with Fenics one should focus on non-linear PDEs like fluid mechanics or non-linear static structural analysis (like large deformations or fully coupled, maybe transient, thermo-analysis).

Is there anything done, yet? If somebody sets up a github project, please inform me.

Kind regards
Posts: 2825
Joined: Mon Nov 11, 2013 5:29 pm

Re: Fenics as Solver

Postby looo » Sun Nov 27, 2016 5:56 am

Hmm, I didn't think about non linear analyses yet, but I think we could try to implement a generic interface which let us do this too.

Basically, what I am thinking of is an implementation of the solver where pre and postprocessing is made in a way it can be applied to any pde-solver or if more generic any geometry processing which results in field-data (scalar and vector). So in the preprocessing we apply attributes to geometry entitis and generate a mesh. This then gets wrapped to node or element level and passed to the generic solver class. This solver class is pure python class (no freecad object) and by subclassing this solver any pde solver can be provided. The solver-class can be choosen in the generic solver (freecad object) from a list. Registering a solver simply adds the class to this list, that is stored somewhere in the fem module. This way a new solver can be created as a macro, at startup with an Init.py file or any other way.
The solver does any calculation on the data and return cell / node - scalar / vector data which then can be used for postprocessing. I don't know if the postprocessing allready has an interface for any data, but if not we can also use the existing data-fields to display any result. (vectors as displacement for example)

The ideal case would be if the solver has everything there and only the processing of field-attributes (bc, constraints, material) and the mathematical side has to be implemented in there.