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

About the development of the FEM module/workbench.

Moderator: bernd

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

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

Postby joha2 » Sat Apr 20, 2019 11:29 am

From some discussion in https://forum.freecadweb.org/viewtopic. ... 10#p302498 the following point is to be achieved:

bernd:

to be able to create group data by python the C++ methods for creating groups need to be exposed to python. This needs to be done in C++. It is not that difficault to do this. There are lots of examples around how to do such new Python methods. If you are interested I could post some links which will help you. But for this I would need a computer, but I am on the way ... Furthermore it makes sense to make a new topic for this since it is some own topic.

joha2:

If I have a little time, I will try to implement this. In the meantime if you have to opportunity, I would like to have the links you have about this stuff, since the C++ code is quite complicated.

Thanks and best wishes
Johannes
User avatar
bernd
Posts: 8030
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 » Sat Apr 20, 2019 6:55 pm

As soon as I have a computer I post some more informations ...
User avatar
bernd
Posts: 8030
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 Apr 22, 2019 7:41 pm

the commits which added some group reading methods ...

git commit 084e163
git commit efb87dc1

some group code ...

https://github.com/FreeCAD/FreeCAD/blob ... #L211-L249 and https://github.com/FreeCAD/FreeCAD/blob ... L960-L1032

first of all we should define which defs and what def names we would like to implement ...
joha2
Posts: 230
Joined: Tue Oct 11, 2016 9:48 pm

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

Postby joha2 » Tue Apr 23, 2019 6:48 am

bernd wrote:
Mon Apr 22, 2019 7:41 pm
the commits which added some group reading methods ...

git commit 084e163
git commit efb87dc1

some group code ...

https://github.com/FreeCAD/FreeCAD/blob ... #L211-L249 and https://github.com/FreeCAD/FreeCAD/blob ... L960-L1032
Thanks for the code examples! In particular we should have a look at the copy code for groups, maybe this provides some hints on how to proceed.
bernd wrote:
Mon Apr 22, 2019 7:41 pm
first of all we should define which defs and what def names we would like to implement ...
Do you refer to the function names which should be exposed to Python? If so, I would suggest something like addGroup('name') [the group number is simply incremented) and addGroupElements(group_number, element_list) [a counterpart to getGroupElements] where the element_list may only consist of elements which already exist in the mesh structure (they were created by addNode, addEdge, ... and so on.)

Hope this helps on a first sight :-)

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

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

Postby joha2 » Tue Jul 09, 2019 6:03 am

bernd wrote:
Mon Apr 22, 2019 7:41 pm
ping pong
:mrgreen: Any news here? If we have implemented addGroup and the former mentioned functions, maybe we can think of to define boundary conditions also based on groups and not only on geometry. From this the flexibility of FEM is increased and also compliance calculations (these simulations shown in another thread removing elements to maintain a mechanism or functionality) could be done, couldn't they?

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

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

Postby joha2 » Sat Jul 13, 2019 11:53 am

User avatar
bernd
Posts: 8030
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 » Sat Jul 13, 2019 1:09 pm

wow! I will have a look! :D
joha2
Posts: 230
Joined: Tue Oct 11, 2016 9:48 pm

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

Postby joha2 » Wed Jul 17, 2019 6:38 am

bernd wrote:
Sat Jul 13, 2019 1:09 pm
wow! I will have a look! :D
:mrgreen: Hehe I knew that this would make you happy :D
Just some further short questions about groups:

  • Would it make sense to also add deleting functionality? Like a delGroup function?
  • Would it make sense to add also the whole bunch of manipulating group functions? I.e. intersect etc?
  • I realized that at several places in the code a conversion from/to elementtype into string takes place. Where would a general function doing this belong to? This is obviously nothing which should only appear in the Python implementation of FemMesh, neither in the C++ interface of FemMesh? Is there a more general file where such service functions belong to?
  • Correct me if I am wrong: The implementation of the groups at the moment works via: define them in the mesh GUI, mesh via GMSH (use PhysicalGroups), reimport the GMSH-created UNV-file and add the groups in the UNV-import from Salome. I did not really understood it from inspecting the code. Can you explain that further?
Thanks for your help!

Best wishes
Johannes