Iterate over Mesh Groups

About the development of the FEM module/workbench.

Moderator: bernd

joee
Posts: 6
Joined: Thu Jun 21, 2018 10:01 am

Iterate over Mesh Groups

Postby joee » Tue Jan 29, 2019 4:22 pm

Hi,

I would like to script a FE analysis and by using the python interface.

My model is very simple:
  • Body
    • Pad
    Analysis
    • FemConstraintFixed

      FemConstraintForce

      SolidMaterial

      FEMMeshGmsh001

In the console I get the mesh and its part instance by the following commands:

Code: Select all

> analysis = App.ActiveDocument.Analysis
> mesh = analysis.getObject("FEMMeshGmsh001")
> part = mesh.Part
Then I would like iterate over all the mesh groups like in the function get_group_data of the class GmshTools (see https://github.com/FreeCAD/FreeCAD/blob ... ls.py#L249), but the array is always empty.
When I start Gmsh via the GUI, the shape2mesh.geo file is written and it contains the group data, so the boundary conditions/mesh groups are defined right. Has anyone an idea what I'm doing wrong?

Thanks in advance!

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

Re: Iterate over Mesh Groups

Postby bernd » Tue Jan 29, 2019 4:50 pm

would you post the FreeCAD file and the python code to reproduce your empty list?
User avatar
bernd
Posts: 8208
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Iterate over Mesh Groups

Postby bernd » Tue Jan 29, 2019 9:28 pm

Which FreeCAD version do you use. For FEM you should use 0.18 dev version.
joee
Posts: 6
Joined: Thu Jun 21, 2018 10:01 am

Re: Iterate over Mesh Groups

Postby joee » Wed Jan 30, 2019 6:52 am

Hi Bernd,

I downloaded the latest 0.18 dev version and tried again, but with no luck.
These are the commands i run after opening the file (see attachment):

Code: Select all

>>> analysis = App.ActiveDocument.Analysis
>>> mesh = analysis.getObject("FEMMeshGmsh")
>>> mesh.MeshGroupList
[]
Thanks!
Attachments
ExampleMeshGroup.FCStd
(99.11 KiB) Downloaded 8 times
User avatar
bernd
Posts: 8208
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Iterate over Mesh Groups

Postby bernd » Wed Jan 30, 2019 7:44 am

sure your list is empty, because you do not have defined groups for your mesh. You need to define them with the GUI or by Python ... Attached your file with two groups and some python code to get the data ... Do not forget to remesh if you define groups.

code

Code: Select all

App.ActiveDocument.FEMMeshGmsh.MeshGroupList
App.ActiveDocument.FEMMeshGmsh.FemMesh.GroupCount
App.ActiveDocument.FEMMeshGmsh.FemMesh.Groups
App.ActiveDocument.FEMMeshGmsh.FemMesh.getGroupElementType(0)
App.ActiveDocument.FEMMeshGmsh.FemMesh.getGroupName(0)
App.ActiveDocument.FEMMeshGmsh.FemMesh.getGroupElements(0)
output

Code: Select all

>>> FreeCAD.open(u"/home/hugo/Desktop/ExampleMeshGroup_bernd1.FCStd")
>>> App.setActiveDocument("ExampleMeshGroup_bernd1")
>>> App.ActiveDocument=App.getDocument("ExampleMeshGroup_bernd1")
>>> Gui.ActiveDocument=Gui.getDocument("ExampleMeshGroup_bernd1")
>>> App.ActiveDocument.FEMMeshGmsh.MeshGroupList
[<Fem::FeaturePython object>, <Fem::FeaturePython object>]
>>> App.ActiveDocument.FEMMeshGmsh.FemMesh.GroupCount
2
>>> App.ActiveDocument.FEMMeshGmsh.FemMesh.Groups
(0, 1)
>>> App.ActiveDocument.FEMMeshGmsh.FemMesh.getGroupElementType(0)
'Face'
>>> App.ActiveDocument.FEMMeshGmsh.FemMesh.getGroupName(0)
'FEMMeshGroup'
>>> App.ActiveDocument.FEMMeshGmsh.FemMesh.getGroupElements(0)
(191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260)
>>> 

ExampleMeshGroup_bernd1.FCStd
(89.73 KiB) Downloaded 7 times
joee
Posts: 6
Joined: Thu Jun 21, 2018 10:01 am

Re: Iterate over Mesh Groups

Postby joee » Wed Jan 30, 2019 10:57 am

Thank you!

I thought mesh groups are implicitly created for FE boundary conditions. Can you tell me in which function/file the mesh groups for boundary conditions are being created when running GmshTools? Because in this class the mesh groups are present...
User avatar
bernd
Posts: 8208
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Iterate over Mesh Groups

Postby bernd » Wed Jan 30, 2019 12:27 pm

Ahh yes this should work if it is activated ...

- FreeCAD preferences --> FEM --> General --> create mesh groups for reference shapes --> activate it
- load your file
- acitvate the analysis
- remesh
- FemMesh groups will be created
- run code

code

Code: Select all

App.ActiveDocument.FEMMeshGmsh.MeshGroupList
App.ActiveDocument.FEMMeshGmsh.FemMesh.GroupCount
App.ActiveDocument.FEMMeshGmsh.FemMesh.Groups
App.ActiveDocument.FEMMeshGmsh.FemMesh.getGroupElementType(0)
App.ActiveDocument.FEMMeshGmsh.FemMesh.getGroupName(0)
App.ActiveDocument.FEMMeshGmsh.FemMesh.getGroupElements(0)
outpus

Code: Select all

>>> App.ActiveDocument.FEMMeshGmsh.MeshGroupList
[]
>>> App.ActiveDocument.FEMMeshGmsh.FemMesh.GroupCount
6
>>> App.ActiveDocument.FEMMeshGmsh.FemMesh.Groups
(0, 1, 2, 3, 4, 5)
>>> App.ActiveDocument.FEMMeshGmsh.FemMesh.getGroupElementType(0)
'Node'
>>> App.ActiveDocument.FEMMeshGmsh.FemMesh.getGroupName(0)
'FemConstraintFixed_Nodes'
>>> App.ActiveDocument.FEMMeshGmsh.FemMesh.getGroupElements(0)
(1, 2, 7, 8, 9, 10, 11, 12, 13, 80, 81, 82, 83, 84, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544)
>>> 


MeshGroupList is zero, because this is a user created object to greate FemMesh groups.