FEM mesh: Create mesh groups in Python (exposing C++ functions to Python)

About the development of the FEM module/workbench.

Moderator: bernd

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

Re: FEM mesh: Create mesh groups in Python (exposing C++ functions to Python)

Post by joha2 »

Thanks for the file. I will submit a fix, soon. Fortunately, XDMF still works. Is the XDMF format in its current form still compatible with fenics? I ask this, since I wrote the export function between fenics 2016 and 2017, and I know there was a large API change in fenics. Further I am not interested to follow non-loggable/interrupted chats in their slack channel, I lost contact to the bleeding edge developments there. Did you follow the latest fenics development and still have contact there?

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

Re: FEM mesh: Create mesh groups in Python (exposing C++ functions to Python)

Post by joha2 »

qingfeng.xia wrote: Sun Jan 26, 2020 9:38 pm xml writing is broken, but it is easy to fix, here is the fix.

You can send in a tiny bugfix PR, it should be accepted by maintainer into master, without Bernd (seems we are all work intermittently on FC) 's comment :lol: You can refer to this thread, as we have discussed it.

Console.Message() -> Console.PrintMessage(), I tested that worked, (writing out mesh). I am not sure, if we should use u"" for force unicode, may be not.
writeFenicsXML.py
https://github.com/FreeCAD/FreeCAD/pull/2946

Best wishes
Johannes :mrgreen:
qingfeng.xia
Posts: 227
Joined: Tue Sep 22, 2015 1:47 pm
Location: Oxford UK/Shenzhen China
Contact:

Re: FEM mesh: Create mesh groups in Python (exposing C++ functions to Python)

Post by qingfeng.xia »

joha2 wrote: Sun Jan 26, 2020 9:48 pm Thanks for the file. I will submit a fix, soon. Fortunately, XDMF still works. Is the XDMF format in its current form still compatible with fenics? I ask this, since I wrote the export function between fenics 2016 and 2017, and I know there was a large API change in fenics. Further I am not interested to follow non-loggable/interrupted chats in their slack channel, I lost contact to the bleeding edge developments there. Did you follow the latest fenics development and still have contact there?

Best wishes
Johannes
Thank you for this prompt effort, I am bit tangled with family responsibility. Maintainer has suggested remove u from the fix. For Qt label showing, it seems need u"" for py2 compat.

For Fenics, XDMF API should be stable, fine. There will be FenicsX in 2020, so I will wait until there is a preview, then squeeze some time for testing the new API. At that time, your group data would be ready for us.
Ubuntu 18.04 LTS 64bit, python3, always work with latest FreeCAD daily build
Working on Cfd module for FreeCAD, FreeCAD_Module_Develop_Guide
https://github.com/ukaea/parallel-preprocessor/
https://github.com/qingfengxia/Cfd
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: FEM mesh: Create mesh groups in Python (exposing C++ functions to Python)

Post by bernd »

qingfeng.xia wrote: Mon Jan 27, 2020 1:00 pm ... has suggested remove u from the fix. For Qt label showing, it seems need u"" for py2 compat. ...
For reference see this post of Werner which I fully agree with https://forum.freecadweb.org/viewtopic. ... 21#p361297
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: FEM mesh: Create mesh groups in Python (exposing C++ functions to Python)

Post by joha2 »

bernd wrote: Mon Jan 27, 2020 3:28 pm For reference see this post of Werner which I fully agree with https://forum.freecadweb.org/viewtopic. ... 21#p361297
@bernd thanks for merging and thanks for the hint!
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: FEM mesh: Create mesh groups in Python (exposing C++ functions to Python)

Post by joha2 »

qingfeng.xia wrote: Sun Jan 26, 2020 8:14 pm As you have now experienced in femsh wrapping, I wonder if all C++ coordinates, nodes list are passed to python by copying, via py::set, If true, it may means it is not efficient to deal with large mesh.
Hey Qxia,

Could you please identity the parts of the code which are not sufficiently fast for large meshes? At a first sight, it is good to have working code, but in a second step, we can improve this parts, such that it is feasible for large meshes.

Best wishes
Johannes
qingfeng.xia
Posts: 227
Joined: Tue Sep 22, 2015 1:47 pm
Location: Oxford UK/Shenzhen China
Contact:

Re: FEM mesh: Create mesh groups in Python (exposing C++ functions to Python)

Post by qingfeng.xia »

sorry for the misunderstanding, I do not mean your code, but overall data passing in femmesh utility functions written in python. if all meshing nodeset can be done in Cpp, it will be great. However, I fully agree with you, it is not current fem module dev priority. python is fine
Ubuntu 18.04 LTS 64bit, python3, always work with latest FreeCAD daily build
Working on Cfd module for FreeCAD, FreeCAD_Module_Develop_Guide
https://github.com/ukaea/parallel-preprocessor/
https://github.com/qingfengxia/Cfd
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: FEM mesh: Create mesh groups in Python (exposing C++ functions to Python)

Post by joha2 »

qingfeng.xia wrote: Wed Feb 05, 2020 12:27 pm sorry for the misunderstanding, I do not mean your code, but overall data passing in femmesh utility functions written in python. if all meshing nodeset can be done in Cpp, it will be great. However, I fully agree with you, it is not current fem module dev priority. python is fine
Hey Qxia,

No problem. I still like those discussions, because if somebody would point me to awful slow code, it is easy to fix it, and we all win very much from this. :mrgreen:

A few months ago, I had some discussions due to a feature request for HDF5 at the gmsh project. Maybe this is of interest for you for identifying a feasible solution to the "slow Python problem" without rewriting all the stuff into C++:

https://gitlab.onelab.info/gmsh/gmsh/issues/552

If there is some easily implementable solution for us, I would be glad about helping implementing it. Although there is already a PR to the femdev branch of bernd, where I suggested some improvements for gmsh, to be able to use multi threads. Nevertheless, the file transfer between gmsh and FreeCAD is still a bottleneck. (Maybe it could be improved by using the binary msh format, I don't know.)

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

Re: FEM mesh: Create mesh groups in Python (exposing C++ functions to Python)

Post by bernd »

AFAIK, neither FreeCAD nor SMESH supports the binary msh format ATM. This would needed to be implemented first.
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: FEM mesh: Create mesh groups in Python (exposing C++ functions to Python)

Post by joha2 »

bernd wrote: Fri Feb 07, 2020 6:46 am AFAIK, neither FreeCAD nor SMESH supports the binary msh format ATM. This would needed to be implemented first.
Yeah, I had this impression, too. Another question is, whether a binary format is soooooo useful. Since you cannot read it easily. Also, the API of the other software has to be stabilized, I think binary files are more prone to fall into the version hell....

My two cents are: if we want to use meshs with zillions of elements in FreeCAD, I'm afraid, we have to rewrite a lot of code. Even if the mesher is fast enough (gmsh for certain is and a direct usage of the library or the front end is still an option), even if we find the right fileformat for exchange (we have to implement this, as bernd pointed out), I think, also FEMMesh is not able to handle such a large mesh, without any issue. And what about the ViewProviders in the GUI? Is the GUI able to handle such large meshes? Maybe these questions are worth a discussion in another thread :mrgreen:

Best wishes
Johannes
Post Reply