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

About the development of the FEM module/workbench.

Moderator: bernd

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

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

Postby bernd » Mon Oct 14, 2019 5:41 pm

the unit test modules where reorganised in GSoC. There is no good example afterwards. This might help in how to add a unit test. git commit 86930ef
joha2
Posts: 252
Joined: Tue Oct 11, 2016 9:48 pm

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

Postby joha2 » Sat Oct 26, 2019 11:14 am

bernd wrote:
Mon Oct 14, 2019 5:41 pm
the unit test modules where reorganised in GSoC. There is no good example afterwards. This might help in how to add a unit test. git commit 86930ef
Hey @bernd,

I've added some unit test to verify the functionality of the group functions roughly. Hope this is like it is intended. At the moment the tests take implicitly as granted that create_nodes(...) and create_elements(...) do not create any mesh groups before. See: https://github.com/berndhahnebach/FreeC ... f93cc21b20

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

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

Postby joha2 » Sat Nov 30, 2019 9:17 am

bernd wrote:
Mon Oct 14, 2019 5:41 pm
ping pong :mrgreen:
Hey bernd,

is there anything missing or to be done which prevents merging these functions into master?

Please just tell me, and I will try to fix it.

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

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

Postby bernd » Wed Dec 04, 2019 10:34 pm

sorry for not answering to this topic for so long. I am just overwhelmed with other stuff ... work, family, etc I would like to finish https://forum.freecadweb.org/viewtopic.php?f=17&t=41117 and afterwards I will have a look.

cheers bernd
joha2
Posts: 252
Joined: Tue Oct 11, 2016 9:48 pm

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

Postby joha2 » Fri Dec 06, 2019 7:22 am

bernd wrote:
Wed Dec 04, 2019 10:34 pm
sorry for not answering to this topic for so long. I am just overwhelmed with other stuff ... work, family, etc I would like to finish https://forum.freecadweb.org/viewtopic.php?f=17&t=41117 and afterwards I will have a look.

cheers bernd
Hey bernd,

Sorry, no pressure intended. I was not sure whether there is some show stopper from my side. Take your time!

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

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

Postby bernd » Fri Jan 10, 2020 7:52 pm

damn still not had the time to have a look ... Bug fixing and family at christmas has taken time ...

But it is not far from top of TODO list ...

cheers bernd
joha2
Posts: 252
Joined: Tue Oct 11, 2016 9:48 pm

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

Postby joha2 » Mon Jan 13, 2020 8:57 pm

bernd wrote:
Fri Jan 10, 2020 7:52 pm
damn still not had the time to have a look ... Bug fixing and family at christmas has taken time ...

But it is not far from top of TODO list ...

cheers bernd
First of all, bernd, I wish you a happy new year and hope you're doing well :-)

About the mesh group implementation: Take your time. The last thing we want to have here, is stress and pressure in a spare time project :-) So, I am around, when you find the time for a review.

Best wishes
Johannes
qingfeng.xia
Posts: 188
Joined: Tue Sep 22, 2015 1:47 pm
Location: Oxford Uk
Contact:

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

Postby qingfeng.xia » Sun Jan 26, 2020 8:14 pm

Great Job, Joha2!
It is highly desirable to have group support for FemMesh in FreeCAD.

I have not got the experience in SMesh programming, but I guess you code is fine when I read througb your code.
I wonder if `theID` in `int FemMesh::addGroup(const std::string TypeString, const std::string Name, const int theId)` is equal to the group ID in
`void FemMesh::addGroupElements(const int GroupId, const std::set<int> ElementIds)`


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.

I am also reading through your xmdf exporting py code. I am hoping your code can be merged asap. Once your code merged, is that possible to import salome mesh into FreeCAD, with groups listed in GUI as `MeshGroup` object?

The other way around, is that posible to export gmsh MeshGroups to fenics xdmf?

Qxia
Ubuntu 18.04 LTS 64bit, python3, always work with latest FreeCAD daily build
Currently I mainly work on OpenFOAM + Fenics for CFD, FSI
https://github.com/qingfengxia/FreeCAD_Mod_Dev_Guide
https://github.com/qingfengxia/Cfd
joha2
Posts: 252
Joined: Tue Oct 11, 2016 9:48 pm

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

Postby joha2 » Sun Jan 26, 2020 8:41 pm

qingfeng.xia wrote:
Sun Jan 26, 2020 8:14 pm
Great Job, Joha2!
It is highly desirable to have group support for FemMesh in FreeCAD.
Hey qingfen.xia,

Nice to hear from you! I think that too, therefore I started this code proposal.
It should really first be a proposal: if there is anything to be done before it gets usable I would be happy to implement it.
qingfeng.xia wrote:
Sun Jan 26, 2020 8:14 pm
I have not got the experience in SMesh programLet me review the code first.ming, but I guess you code is fine when I read througb your code.
I wonder if `theID` in `int FemMesh::addGroup(const std::string TypeString, const std::string Name, const int theId)` is equal to the group ID in
`void FemMesh::addGroupElements(const int GroupId, const std::set<int> ElementIds)`
Yes, this should be the same id. At least Salome accepts an id as argument to the AddGroup function, but it seems to be ignored and the group id is filled up in sequential order. Therefore the Python function which is exposed to FreeCAD returns the group id generated by the addGroup call.
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.
That may be true. Since my experience is quite limited which Python C++ functions are fast and which are slow, maybe my choice may not be wise. Nevertheless I would appreciate any hints in this direction very much. Further my C++ skills are a bit rusty and quite old, so if you got ideas in this concern, just tell me :-)
qingfeng.xia wrote:
Sun Jan 26, 2020 8:14 pm
I am also reading through your xmdf exporting py code. I am hoping your code can be merged asap. Once your code merged, is that possible to import salome mesh into FreeCAD, with groups listed in GUI as `MeshGroup` object?

The other way around, is that posible to export gmsh MeshGroups to fenics xdmf?
As far as I understood, the MeshGroup objects can not immediately use the addGroup functionality. The exposed Python functions are only useful at the moment as a low level interface to provide a group to a mesh. There have to be high level functions implemented which create a MeshGroup object if the addGroup function is called. Further, the XDMF code is somehow broken in the up to date freecaddaily, so before any implementation of addGroup I have to fix it :-) But this should be done within the next few days or weeks. But XDMF itself supports groups already. This is true for volume groups, for surface groups, and for node groups if I recall correctly.

Best wishes
Johannes

Edit: added a sentence for group functionality in XDMF.

Edit2: I checked the XML/XDMF export code. It is broken due to an API change in the FreeCAD.Console. Maybe it slipped through the unit testing due to missing unit tests for XML/XDMF :mrgreen:
Last edited by joha2 on Sun Jan 26, 2020 9:39 pm, edited 1 time in total.
qingfeng.xia
Posts: 188
Joined: Tue Sep 22, 2015 1:47 pm
Location: Oxford Uk
Contact:

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

Postby qingfeng.xia » Sun Jan 26, 2020 9:38 pm

Thank you for your explanation. I am looking forwords to this feature for my FenicsSolver.
To continue on python data structure. numpy is prefer and it is easy in pybind11, possible and hader in C-API. As there is much effort to do so, just leave it as it is.

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
(5.33 KiB) Downloaded 2 times
XML is not the favourate format, but we must fix it as it is still in.
Ubuntu 18.04 LTS 64bit, python3, always work with latest FreeCAD daily build
Currently I mainly work on OpenFOAM + Fenics for CFD, FSI
https://github.com/qingfengxia/FreeCAD_Mod_Dev_Guide
https://github.com/qingfengxia/Cfd