Fenics as Solver

About the development of the FEM module/workbench.

Moderator: bernd

User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Fenics as Solver

Post by bernd »

joha2 wrote:
bernd wrote: - I would start with export too
- tex/hex --> I do not understan the question
- netgen --> which OS, when linux which distribution ?
Hi bernd,

thanks for your fast answer!
OS is Linux, distribution: Ubuntu 14.04 type (Lubuntu).
tet/hex question: I think you showed in one of the other threads that it is also possible to generate purely hexaeder meshes with gmsh. As far as I have seen, fenics uses only tet4 elements; is there any helper function in the FEM workbench which converts between the hexaeder and tet meshes?
why would you like to convert hex to tet. FreeCAD FEM has great support for tet meshes, so just use tet meshes.

You need to compile FreeCAD against netget, see topic https://forum.freecadweb.org/viewtopic.php?f=4&t=18967 or use ubuntu daily ppa, or use FreeCAD.FEM GMSH object for meshing.
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: Fenics as Solver

Post by joha2 »

Thanks for the script! My question about the hex/tet conversion was due to: assume someone has created a really complicated and nice hex mesh which was meshed over night. Is for this mesh a fast conversion routine available? Yeah I know this is somewhat artificial problem :D

Edit: OK, I got netgen also running now. I only missed the header files and this compiler switch in my cmake call, but now it works and I can export a tet4 mesh to fenics XML file
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Fenics as Solver

Post by bernd »

joha2 wrote:Thanks for the script! My question about the hex/tet conversion was due to: assume someone has created a really complicated and nice hex mesh which was meshed over night. Is for this mesh a fast conversion routine available? Yeah I know this is somewhat artificial problem:D
No there is no such tool available in FreeCAD FEM. Meshing a complicated part overnight with hexa20 --> dreams would come true ...
Edit: OK, I got netgen also running now. I only missed the header files and this compiler switch in my cmake call, but now it works and I can export a tet4 mesh to fenics XML file
:D
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: Fenics as Solver

Post by joha2 »

Here are some pictures.
The FreeCAD mesh for some more or less complicated geometry
scrot_fc_compl.jpg
scrot_fc_compl.jpg (548.77 KiB) Viewed 1548 times
and the Paraview of the mesh read in from Fenics and written into an pvd file
scrot_para_compl.jpg
scrot_para_compl.jpg (519.17 KiB) Viewed 1548 times
The Fenics script was also relatively simple:

Code: Select all

from fenics import *
from mshr import *
from dolfin import Point, Mesh
mesh = Mesh("testmesh.xml")
File('testmesh.pvd') << mesh
plot(mesh)
I have still some questions: Is there a best practice way to distuingish in FreeCAD between linemesh, facemesh and volumemesh? Or do I have to count the appropriate entities (what is to be done for mixed meshs?)? How do I integrate my export function now into the FC-code? I wrote them in python, so they are not suitable for the C++ part. bernd do you have a suggestion?

Best wishes
Johannes
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Fenics as Solver

Post by bernd »

wow cool, to integeate it, best is to use github. Do you have it in your freecad allready, or how do you call your export code?

In the regard off the other questions I post late, I am on the way.
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: Fenics as Solver

Post by joha2 »

bernd wrote:wow cool, to integeate it, best is to use github. Do you have it in your freecad allready, or how do you call your export code?

In the regard off the other questions I post late, I am on the way.
Yeah I have a github fork, but the code is at the moment just implemented as a macro. I am very unfamiliar with the github development of large projects, therefore maybe I need little help for setting up an appropriate pull request.

Meanwhile I will clean up the code a little and at least try to implement the proper export of low dimensional meshes.

Thanks in advance!

Edit: Low dimensional line and triangle meshs are also working
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Fenics as Solver

Post by bernd »

joha2 wrote: I have still some questions: Is there a best practice way to distuingish in FreeCAD between linemesh, facemesh and volumemesh? Or do I have to count the appropriate entities (what is to be done for mixed meshs?)?
When is a mesh a linemesh, facemesh and volumemesh? Because a volume mesh could have faces and lines too. To distinguish between linemesh, facemesh and volumemesh I use some simple methods see: https://github.com/FreeCAD/FreeCAD/blob ... s.py#L1299 The z88 exporter does not export mixed meshes. The C++ inp exporter of FreeCAD does not export mixed meshes either, because this is not supported by CalculiX input writer at the moment, but for sure this needs to be attracted at some point in the future. For support of mixed meshes you just need to export all elements of the mesh.

joha2 wrote:How do I integrate my export function now into the FC-code? I wrote them in python, so they are not suitable for the C++ part. bernd do you have a suggestion?
see https://github.com/FreeCAD/FreeCAD/blob ... Z88Mesh.py especially the def https://github.com/FreeCAD/FreeCAD/blob ... esh.py#L65 you need to register the export file type in the init file of FEM workbench see https://github.com/FreeCAD/FreeCAD/blob ... nit.py#L42 You need to add your new importFenicsOrWhatEverYouNameIt.py in the cmake files See https://github.com/FreeCAD/FreeCAD/blob ... ts.txt#L25 and https://github.com/FreeCAD/FreeCAD/blob ... ts.txt#L69

hope that helps Bernd
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: Fenics as Solver

Post by joha2 »

Thanks for the detailed reply! I will write a file importFenics.py and take the structure from your mentioned Z88 files.
Is there any good discussion or a wiki entry for the best-practice git workflow? Best wishes
Johannes

Edit: I just prepared a pull request. Let's see if it is merged :mrgreen:
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Fenics as Solver

Post by bernd »

joha2 wrote:Thanks for the detailed reply! I will write a file importFenics.py and take the structure from your mentioned Z88 files.
Is there any good discussion or a wiki entry for the best-practice git workflow? Best wishes
viewtopic.php?f=10&t=17531#p138182
joha2 wrote: I just prepared a pull request. Let's see if it is merged :mrgreen:
The normal way is to make your changes public at the forum first. For FEM mostly I do integrate them in my development branch and we gone make a bigger PR together. This way it is much much more less work for Yorik and Werner and your code is tested by other people as well. Ahh and if you gone make changes in FEM best to start your commit message with FEM: ...

my up to date dev branch for next PR:
https://github.com/berndhahnebach/FreeC ... its/femdev
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: Fenics as Solver

Post by joha2 »

Oh I'm sorry. There I was too fast :-( Should I revert this pull request?
Thanks for the tips&tricks section for git!
Post Reply