xml import/export for fenics mesh

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

xml import/export for fenics mesh

Post by joha2 »

Hey guys,

first of all thanks for your great work with FreeCAD! I am interested in FEM and discussed a few things already in the FEM section of this forum. In particular I am interested in an easy-to-use interface of the FEM workbench to fenics (https://fenicsproject.org/) which is a very sophisticated and general tool for the solution of partial differential equations. For using fenics as part of the FEM workbench HoWil suggested to implement a stable import/export code for the fenics mesh format. Since this format is xml I want to ask if there is anything (read/write code) already implemented in Python in the code base which I could use. The second option would be to use a standard library for Python. Which one would you suggest? The third option would be to code an xml reader/writer for myself, but I think this makes no sense.

Thanks in advance!
Best wishes
Johannes
User avatar
kkremitzki
Veteran
Posts: 2511
Joined: Thu Mar 03, 2016 9:52 pm
Location: Illinois

Re: xml import/export for fenics mesh

Post by kkremitzki »

Check out http://lxml.de/
Like my FreeCAD work? I'd appreciate any level of support via Patreon, Liberapay, or PayPal! Read more about what I do at my blog.
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: xml import/export for fenics mesh

Post by ickby »

Out of interest, why are you going for direct xml export and don't use the dolfin Mesh for setting up the mesh directly? This can than be saved easily.

Anyway, as I use fenics quite intensively I'm looking very much forward to the export :)
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: xml import/export for fenics mesh

Post by joha2 »

ickby wrote:Out of interest, why are you going for direct xml export and don't use the dolfin Mesh for setting up the mesh directly? This can than be saved easily.

Anyway, as I use fenics quite intensively I'm looking very much forward to the export :)
I am really not sure which way to incorporation of fenics is the best. HoWil suggested the mesh export/import and I think this is a good starting point. There are two possibilities: Either the xml import/export between FC and fenics or a direct convesion from one mesh structure into the other. I saw that you followed the discussion in the "fenics as a solver" thread: If it is not possible to incorporate fenics directly into FC (license issues) maybe we have to use a file transfer and an external process like in the calculix case. I think the file import/export is the most straightforward and flexible way to use fenics in the future.

May I ask: For which kind of problems you use fenics? Can you suggest any documentation about the dolfin xml format? I only know the dolfin-convert script and I have printed a few pages from chapter 10 of the book. But there I cannot see, e.g., how to distinguish between tet4 and tet10 elements.

Which features do you miss in the scripted fenics most, which should be included into a possible FC fenics solver first? We also need a formula input for: the weak formulation, the bcs, the source functions, ...; any suggestions for this problem? Is the expression structure usable for this? (I think not :-( ).

BTW: kkremitzki thanks for the suggestions, I will have a look.

Edit: I found a nice paper for the mesh structure in fenics https://arxiv.org/abs/1205.3081

Best wishes
Johannes
Last edited by joha2 on Wed Feb 22, 2017 7:24 am, edited 1 time in total.
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: xml import/export for fenics mesh

Post by sgrogan »

joha2 wrote:BTW: kkremitzki thanks for the suggestions, I will have a look.
Other possibilities are dom, etree, and sax. From a quick google it seems there are potential security vulnerabilities and lacking features compared to lxml, the advantage is that they are part of most standard Python distributions (including FreeCAD's Python on Win)
"fight the good fight"
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: xml import/export for fenics mesh

Post by joha2 »

I used lxml for a first macro implementation. The parsing works well and I copied the creation of the FemMesh object from the Z88 code. But it seems that the mesh is still not correctly generated. (I am not sure whether if I read tet4 elements and their nodes from the XML file I still have to generate the edges and faces myself or if the FemMesh object takes care of that.)

Edit: Thanks for all your input! I think lxml is a good choice and who is still interested in this topic, I will discuss this stuff further in the FEM section https://forum.freecadweb.org/viewtopic. ... 7&start=60

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

Re: xml import/export for fenics mesh

Post by ickby »

joha2 wrote:May I ask: For which kind of problems you use fenics?[\quote]
Mostly Piezoelectric/Electrostrictive problems (coupled electrostatic and linear elastisity problems) and electromagnetic calculations.
Can you suggest any documentation about the dolfin xml format?
unfortunately not, I never found a documentation

Which features do you miss in the scripted fenics most, which should be included into a possible FC fenics solver first?

Honestly I will always stay at the script level, as this is the flexibility I like and need. The current problem with fenics is the meshing and domain definition, that takes most of the work and is cumbersome. So I would love to define meshs and subdomains in FreeCAD, so that I can simply load the xml file and access all subdomains. The rest I will do in my scripts anyway.
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: xml import/export for fenics mesh

Post by joha2 »

Ah do you have any good literature on electromagnetics FEM? In particular the treatment of rot rot problems is interesting (harmonic analysis of EM fields or magneto statics). I see your point for the scripting interface of fenics, but maybe a FC interface simplifies the formulation of "standard" problems and/or could help to implement multiphysics problems. For me at least the goal is to learn fenics :-)

Could you provide some example meshs (some complicated meshs would be good as test cases). Do you know whether the boundary conditions or cell/facet/... functions are also saved in the XML files?

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

Re: xml import/export for fenics mesh

Post by ickby »

Sorry, all my work is done for my company and I can't share anything. But for a comprehensive text about electro-magnetics and FEM I can recommend http://maxwell.sze.hu/docs/C4.pdf
Not simple, but detailled!
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: xml import/export for fenics mesh

Post by joha2 »

ickby wrote:Sorry, all my work is done for my company and I can't share anything. But for a comprehensive text about electro-magnetics and FEM I can recommend http://maxwell.sze.hu/docs/C4.pdf
Not simple, but detailled!
Thanks for the script! I totally understood that it is not possible to reveal the stuff from your company. Thanks anyway!

Best wishes
Johannes
Post Reply