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 »

@bilenemek:
be sure to read https://forum.freecadweb.org/viewtopic.php?f=18&t=12212 before start using FreeCAD FEM even if it is for meshing only
bilenemek
Posts: 4
Joined: Wed Feb 10, 2021 6:16 pm

Re: Fenics as Solver

Post by bilenemek »

Dear All

Here is a workflow working fine for a simple case. A structure has loading on one side and is clamped on the other.

Part/partdesign in FC for one part (use fusion or compound to merge) and then in FEM workbench

1. use Gmsh to mesh (first order)
2. use Mesh / FEM mesh group in order to create solid body of the whole domain (choose all bodies), choose label as option
3. use Mesh / FEM mesh group in order to create one surface for loading (Neumann boundary)
4. use Mesh / FEM mesh group in order to create one for clamping (Dirichlet boundary)
5. select in tree these mesh groups and give them better labels, I used body, loading, clamp
6. if all groups are finalized, they are not applied yet, double-click the mesh and choose apply, then OK
7. choose the mesh and export by using xdmf, there is a dialogue showing labels and that unmarked has value 0 and marked 1, I am using these values.

Now you can do a FEniCS calculation on python (if installed so, or docker, then the xdmf file needs to be in the shared folder next to the python file). I am adding here FC file and python code for elastostatic beam bending, I put some holes to make it more fancy). The output is pvd file to open in Paraview.
screen.png
screen.png (75.5 KiB) Viewed 1531 times
Attachments
fc_fenics.zip
(559.31 KiB) Downloaded 38 times
bilenemek
Posts: 4
Joined: Wed Feb 10, 2021 6:16 pm

Re: Fenics as Solver

Post by bilenemek »

In order to extend this very nice functionality, is it possible to do these changes in xdmf output method?

At the moment, there is a section in the xdmf with 0 or 1 for each ID. Therefore, in FEniCS, one has to do multiple lists (no big deal). Dirichlet boundary conditions with multiple lists will work, but if one wants to have a composite material, part of the domain is material 1 and the other part is material 2, then two different lists can only be used for two distinct integral measures. But then solving them together is not possible (since otherwise you may have overlapping elements and so on).

If possible, the xdmf writer should iterate over all 3D mesh groups and write their unmarked 0 and marked 1 for solid 1 and marked 2 (or whatever a user puts into the dialogue) for solid 2 and marked 3 for ... and compile this in one single section. The same for 2D and 1D as well. Since it is a FEniCS output, I guess this compatibility will be very nice.

Then there are no more difficulties to solve whatever you want.

How does this sound?

Best,
Emek
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: Fenics as Solver

Post by joha2 »

bilenemek wrote: Thu Jan 13, 2022 6:02 pm In order to extend this very nice functionality, is it possible to do these changes in xdmf output method?

At the moment, there is a section in the xdmf with 0 or 1 for each ID. Therefore, in FEniCS, one has to do multiple lists (no big deal). Dirichlet boundary conditions with multiple lists will work, but if one wants to have a composite material, part of the domain is material 1 and the other part is material 2, then two different lists can only be used for two distinct integral measures. But then solving them together is not possible (since otherwise you may have overlapping elements and so on).

If possible, the xdmf writer should iterate over all 3D mesh groups and write their unmarked 0 and marked 1 for solid 1 and marked 2 (or whatever a user puts into the dialogue) for solid 2 and marked 3 for ... and compile this in one single section. The same for 2D and 1D as well. Since it is a FEniCS output, I guess this compatibility will be very nice.
Hi Emek,

Thank you for your question. I wrote this code a long time ago (I think around 2017-2018), so I'm afraid I have to dig through it to get some understanding :oops:. In principle, the changes you suggested should be possible, but I am not sure whether I understand correctly:

  • At the moment every mesh group is marked with either 0 or some value != 0 and is written into the XDMF file as extra list.
  • In constrast, you want to have that every mesh group is written into a single list with different values ranging from 0 (unmarked) to n (for n groups) to avoid overlap of elements with different markings?

Is this correct?

I think the design descision to use distinct lists comes from the fact, the mesh groups may contain different elements.

So, first of all we have to check, whether the groups contain the same elements (i.e. volumes, edges, points) and collect them together. Further we have to change the save dialog box to reflect the new scheme (but maybe we can just put a checkbox there for this or that scheme), and last but not least there is some code in the solver directory which generates Fenics objects depending on the structure of the XDMF file (but it's for some old Fenics version, maybe it's obsolete anyway). So the code for handling the groups in XDMF files is very scattered. I have to collect it and learn again how it works :mrgreen:.

If you want to check the code for yourself, in the main directory of FreeCAD go to

Code: Select all

src/Mod/Fem/
there are some files

Code: Select all

./feminout/importFenicsMesh.py
./feminout/writeFenicsXDMF.py
./feminout/writeFenicsXML.py
./feminout/readFenicsXDMF.py
./feminout/readFenicsXML.py
./femsolver/fenics/fenics_tools.py
./femsolver/fenics/__init__.py
which contain the main code for handling the file output.

Hope this helps.

Best wishes
Johannes
bilenemek
Posts: 4
Joined: Wed Feb 10, 2021 6:16 pm

Re: Fenics as Solver

Post by bilenemek »

Dear Johannes

You can also have a look at the meshio, where gmsh to xdmf conversion is already implemented

https://github.com/nschloe/meshio

which is by the way often used in the FEniCS community

https://jsdokken.com/converted_files/tu ... ygmsh.html

Yes it is right!

There is no problem of having each mesh group as an extra list, as long as we have them on boundaries. But whenever one wants to use two materials, then this design choice is a big hurdle. If every mesh group is written into one list, it solves the problem. For avoiding overlapping, in the older dolfin-convert version, the first marker is used and then the rest is ignored. Technically, it does not matter if you check and skip or simply overwrite. The user has to make sure that no overlapping is used in mesh groups. Gmsh allows that, it is a FEniCS specific restriction and your export file is telling that it is for FEnICS.

You can of course go another direction and use an xml conversion by skipping xdmf. Please have a look in the code, which is a fork from the dolfin-convert to convert gmsh to xml and then h5 (more efficient for parallel computing, but no need for FreeCAD, xml would be nice as well).

Thanks for your great work by the way (often not appreciated,right?)

Best, Emek
Attachments
med2h5_serverversion.py
(24.04 KiB) Downloaded 37 times
Post Reply