Fenics as Solver

About the development of the FEM module/workbench.

Moderator: bernd

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

Re: Fenics as Solver

Post by joha2 »

HoWil wrote: Sat Jun 16, 2018 9:10 am Hi Johannes,
I tested the integration over an inner boundary in a minimal fenics example where I created the geometry and mesh in fenics and the result is the same. I get zero when simply integrating over such an inner boundary.
So there has to be a solution inside fenics.
I am thinking of using the normal vector in combination with an inner product but did not succeed until now.
Do you have any new ideas about that?
Br,
Howil
Heyhey HoWil,

sorry for the late reply, but I was on vacation the last two weeks. First to your question:

Since my experience in Fenics is quite limited I also was not able to extract the normal vector information from the boundary. I will check whether it is possible to access different points or facets of the boundary from a facet function. From that you could easily calculate the normal vector from e.g. three points A, B, C by using (A - B) x (B - C)/||(A - B) x (B - C)||. Maybe it would also be nice to make an accessible object which extracts these quantities in the Fenics tools :-) Another possibility would be to calculate the normal vector direclty from an expression if you know your boundary analytically (i.e. for a sphere with center C it is just (x - C)/||x-C||). Hope this helps a bit.

Now to the Fenics interface: I refactored the interface such that you can load the facet functions and cell functions directly from an XDMF reader class. Also the mesh is available there which you need to define the vector spaces. They could be used as before, but now you can also define vector expressions for the cell functions (i.e. to define a current or something like this). I think the interface becomes more and more useful. Although due to the value_shape() method in the Expression class I had to define an ugly class hierarchy. Maybe this could be removed in the future. The PR is created on bernds femdev branch. Maybe you could give me your opinion.

In a few days I will provide some code for solving a vector Poisson equation or something like this.

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

Re: Fenics as Solver

Post by joha2 »

Hey guys,

due to one of the last PRs (https://forum.freecadweb.org/viewtopic.php?f=17&t=35171) the Fenics JIT compiler works now from a macro. This can be used to calculate FEM simulations with a FEMMesh from FreeCAD. Still missing:
  • Fenics simulation is done directly in Python code, therefore no interface necessary, but maybe needed
  • Embedding into Analysis structure (not necessary right now)
  • Creating of result object from Paraview solution files
Any suggestions?

Best wishes
Johannes
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Fenics as Solver

Post by HoWil »

For all still interested in using fenics in combination with FC .... I found this nice tutorial (using FC only for the geometry, and gmsh for creating the mesh externally) and thought sharing could maybe help somebody
https://comphysblog.wordpress.com/2018/ ... ng-fenics/
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: Fenics as Solver

Post by joha2 »

HoWil wrote: Tue Jul 30, 2019 4:47 pm For all still interested in using fenics in combination with FC .... I found this nice tutorial (using FC only for the geometry, and gmsh for creating the mesh externally) and thought sharing could maybe help somebody
https://comphysblog.wordpress.com/2018/ ... ng-fenics/
Nice tutorial @HoWil! I am still interested in Fenics + FC. Unfortunately the Fenics guys changed in the 2019.1 release something in the XDMF format, such that mesh transfer with markers is not working anymore. Anyway, I just prepared a docker file to create a Fenics image together with the libraries necessary to compile FreeCAD with Python3 + Qt5. This was necessary since they abandoned Python2 compatibility in Fenics. So Fenics together with FreeCAD works in principle, but the mesh transfer is not so easy anymore. Annoying is, that they use still Slack for their team communication and it prohibits to view old messages (aka know-how) before not switching to a paid plan. :cry:

Best wishes
Johannes
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Fenics as Solver

Post by HoWil »

joha2 wrote: Tue Jul 30, 2019 5:36 pm I am still interested in Fenics + FC.
Good to hear that... I once again searched a click-and-play alternative to comsol and finally ended up with fenics but it is not ready to do a quick study on a complex geometry within 5mins
joha2 wrote: Tue Jul 30, 2019 5:36 pm Unfortunately the Fenics guys changed in the 2019.1 release something in the XDMF format, such that mesh transfer with markers is not working anymore. Anyway, I just prepared a docker file to create a Fenics image together with the libraries necessary to compile FreeCAD with Python3 + Qt5. This was necessary since they abandoned Python2 compatibility in Fenics.
Please let me know if you have anything to test.
BR,
HoWil
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: Fenics as Solver

Post by joha2 »

HoWil wrote: Tue Jul 30, 2019 6:28 pm
joha2 wrote: Tue Jul 30, 2019 5:36 pm I am still interested in Fenics + FC.
Good to hear that... I once again searched a click-and-play alternative to comsol and finally ended up with fenics but it is not ready to do a quick study on a complex geometry within 5mins

Please let me know if you have anything to test.
BR,
HoWil
Yeah, they also know about this issue and they are discussing how to simplify this workflow. They said, that in the past they focused more on complicated physics and simple geometry. I have this docker file to test, but what would be the best for the user? A fully automated installation and compile process such that at the end the FreeCAD binary is ready to go in some directory? Or just the docker image with all packages to compile FreeCAD for yourself?

Did the normal vector discussion from last time lead to anything useful for your last problem?

Best wishes
Johannes
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: Fenics as Solver

Post by ickby »

I found a problem with the XDMF export. If GMSH creates 2nd order elements they are exportet with <TopologyType="tet_10"> which brings the XDMF importer of fenics to crash. It is also not XDMF compliant. It does work with 1st order elements as this exports<TopologyType="tetrahedron"> which is supported. Maybe a warnign should be given to the user that second order is not supportet and the export should fail?

keep up the good work!
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: Fenics as Solver

Post by joha2 »

ickby wrote: Thu Aug 22, 2019 1:28 pm I found a problem with the XDMF export. If GMSH creates 2nd order elements they are exportet with <TopologyType="tet_10"> which brings the XDMF importer of fenics to crash. It is also not XDMF compliant. It does work with 1st order elements as this exports<TopologyType="tetrahedron"> which is supported. Maybe a warnign should be given to the user that second order is not supportet and the export should fail?

keep up the good work!
Hey Ickby,

Thanks for reviewing the code. I already realized this problem, since my Fenics crashes, too, if I forget to reduce mesh order to one :mrgreen:. I also thought about using a warning message, but I was not sure whether this is the best way to go. In the XML export, the warning message is printed, and I think the mesh order reduction is done automatically. For XDMF I didn't do that because Paraview showed a valid mesh, even with tet_10 or other higher order elements. Long story short: you're right, printing a warning gives the user at least a hint that for a valid Fenics mesh the order should be reduced to one. I will implement this in the next few days.

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

Re: Fenics as Solver

Post by bilenemek »

Dear joha2,

Is there anything on this end? We would like to be able to use FreeCAD and FEniCS together.

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

Re: Fenics as Solver

Post by joha2 »

bilenemek wrote: Wed Feb 10, 2021 6:20 pm Dear joha2,

Is there anything on this end? We would like to be able to use FreeCAD and FEniCS together.

Best, Emek
Hey @bilenemek nice to see that there is some interest in this topic! So from a developer perspective, the XDMF and XML mesh formats are implemented to a certain extend. Since, Fenics uses a slack channel to discuss technical things, I didn't follow the development from I think late 2018 anymore, since you have to pay to see old messages, which I think is not appropriate for a spare time project. Long story short, the mesh formats are implemented and in principle mesh groups should work either. So you may setup a CAD file, mesh it with the FEM workbench, and feed the mesh into your Fenics Python script. As Fenics had a major revision in 2019, I'm not sure, whether the formats are still compatible.

Hope this helps!

Best regards
Johannes
Post Reply