[Partially solved] Selected element identification in .inp file

About the development of the FEM module/workbench.

Moderator: bernd

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

Re: [Help] Selected element identification in .inp file

Postby bernd » Tue Sep 25, 2018 7:13 am

- open FEM 3D example from StartWB
- rund code

Code: Select all

mesh = App.ActiveDocument.Box_Mesh.FemMesh
mesh.Edges
mesh.Faces
mesh.Volumes
output should answer your question

Code: Select all

>>> 
>>> mesh = App.ActiveDocument.Box_Mesh.FemMesh
>>> mesh.Edges
(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L)
>>> mesh.Faces
(53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 91L, 92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L, 114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L, 125L, 126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L, 135L, 136L, 137L, 138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L, 147L, 148L)
>>> mesh.Volumes
(149L, 150L, 151L, 152L, 153L, 154L, 155L, 156L, 157L, 158L, 159L, 160L, 161L, 162L, 163L, 164L, 165L, 166L, 167L, 168L, 169L, 170L, 171L, 172L, 173L, 174L, 175L, 176L, 177L, 178L, 179L, 180L, 181L, 182L, 183L, 184L, 185L, 186L, 187L, 188L, 189L, 190L, 191L, 192L, 193L, 194L, 195L, 196L, 197L, 198L, 199L, 200L, 201L, 202L, 203L, 204L, 205L, 206L, 207L, 208L, 209L, 210L, 211L, 212L, 213L, 214L, 215L, 216L, 217L, 218L, 219L, 220L, 221L, 222L, 223L, 224L, 225L, 226L, 227L)
>>> 
EkaitzEsteban
Posts: 98
Joined: Wed Sep 12, 2018 1:31 pm

Re: [Help] Selected element identification in .inp file

Postby EkaitzEsteban » Tue Sep 25, 2018 8:21 am

bernd wrote:
Tue Sep 25, 2018 7:13 am
- open FEM 3D example from StartWB
- rund code

Code: Select all

mesh = App.ActiveDocument.Box_Mesh.FemMesh
mesh.Edges
mesh.Faces
mesh.Volumes
output should answer your question

Code: Select all

>>> 
>>> mesh = App.ActiveDocument.Box_Mesh.FemMesh
>>> mesh.Edges
(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L)
>>> mesh.Faces
(53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 91L, 92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L, 114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L, 125L, 126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L, 135L, 136L, 137L, 138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L, 147L, 148L)
>>> mesh.Volumes
(149L, 150L, 151L, 152L, 153L, 154L, 155L, 156L, 157L, 158L, 159L, 160L, 161L, 162L, 163L, 164L, 165L, 166L, 167L, 168L, 169L, 170L, 171L, 172L, 173L, 174L, 175L, 176L, 177L, 178L, 179L, 180L, 181L, 182L, 183L, 184L, 185L, 186L, 187L, 188L, 189L, 190L, 191L, 192L, 193L, 194L, 195L, 196L, 197L, 198L, 199L, 200L, 201L, 202L, 203L, 204L, 205L, 206L, 207L, 208L, 209L, 210L, 211L, 212L, 213L, 214L, 215L, 216L, 217L, 218L, 219L, 220L, 221L, 222L, 223L, 224L, 225L, 226L, 227L)
>>> 
Thank you bernd,

I use the same example in order to understand better. I attach an screenshot of this example.
CantileverNodesElements.PNG
CantileverNodesElements.PNG (113.99 KiB) Viewed 204 times
7 different selections can be seen in the botton right selection view window.
Three of them are nodes, the rest are elements I guess :roll: .
The selection of nodes is not problem because Node94 directly correspond to 94, in the .inp file, and it is very simple to identify them by typing in python API console:

Code: Select all

sel=Gui.Selection.getSelectionEx()
and extract them using:

Code: Select all

sel[0].SubElementNames[i]
where i=0,1,2,3...

If I understand correctly, Elem226F1, Elem226F2, Elem226F3, ... Elem226Fn will define a volume, but this not correspond with 226L volume... from mesh.Volumes....

best regards,

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

Re: [Help] Selected element identification in .inp file

Postby bernd » Tue Sep 25, 2018 11:03 am

EkaitzEsteban wrote:
Tue Sep 25, 2018 8:21 am
If I understand correctly, Elem226F1, Elem226F2, Elem226F3, ... Elem226Fn will define a volume, but this not correspond with 226L volume... from mesh.Volumes....
IMHO Elem226Fn correspond to 226L element which is a volume in this mesh.

BTW: How do you select mesh nodes and mesh volumes? I have never done that?

bernd
EkaitzEsteban
Posts: 98
Joined: Wed Sep 12, 2018 1:31 pm

Re: [Help] Selected element identification in .inp file

Postby EkaitzEsteban » Tue Sep 25, 2018 12:59 pm

bernd wrote:
Tue Sep 25, 2018 11:03 am
EkaitzEsteban wrote:
Tue Sep 25, 2018 8:21 am
If I understand correctly, Elem226F1, Elem226F2, Elem226F3, ... Elem226Fn will define a volume, but this not correspond with 226L volume... from mesh.Volumes....
IMHO Elem226Fn correspond to 226L element which is a volume in this mesh.

BTW: How do you select mesh nodes and mesh volumes? I have never done that?

bernd
Hi bernd,

I click on the node with the mouse and then I keep the ctrl key pressed for selecting more nodes. When I select some of them I write the following code in the python API.

Code: Select all

sel=Gui.Selection.getSelectionEx() # here sel variable contains the information about all the selection done in Selection View Window.
then you can write different things,

Code: Select all

sel[0].SubElementNames[i] # i=0,1,2,... which are the selected node names.
sel[0].PickedPoints[i]  # coordinates of the node, and so on...
See the attachment, I use your recomendation clipping plane option for facilitating the access to the internal nodes.
InternalNodeSelection.PNG
InternalNodeSelection.PNG (87.85 KiB) Viewed 185 times
User avatar
bernd
Posts: 7897
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: [Help] Selected element identification in .inp file

Postby bernd » Tue Sep 25, 2018 1:26 pm

means you are not inside any tool, just selecting?
User avatar
bernd
Posts: 7897
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: [Help] Selected element identification in .inp file

Postby bernd » Tue Sep 25, 2018 1:44 pm

OK, got it. I never used this before ...

BTW:

to highlight nodes use the following and pass a list of node numbers:

Code: Select all

Gui.ActiveDocument.Box_Mesh.HighlightedNodes = range(App.ActiveDocument.Box_Mesh.FemMesh.NodeCount)
set back by passing an empty list:

Code: Select all

Gui.ActiveDocument.Box_Mesh.HighlightedNodes = range(0)
User avatar
bernd
Posts: 7897
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: [Help] Selected element identification in .inp file

Postby bernd » Tue Sep 25, 2018 3:02 pm

For selecting groups of nodes you could also give the node set tool in FEM menue mesh a try!
EkaitzEsteban
Posts: 98
Joined: Wed Sep 12, 2018 1:31 pm

Re: [Help] Selected element identification in .inp file

Postby EkaitzEsteban » Tue Sep 25, 2018 3:35 pm

bernd wrote:
Tue Sep 25, 2018 1:44 pm
OK, got it. I never used this before ...

BTW:

to highlight nodes use the following and pass a list of node numbers:

Code: Select all

Gui.ActiveDocument.Box_Mesh.HighlightedNodes = range(App.ActiveDocument.Box_Mesh.FemMesh.NodeCount)
set back by passing an empty list:

Code: Select all

Gui.ActiveDocument.Box_Mesh.HighlightedNodes = range(0)
WoW! awesome, I should try to combine this with the selected ones in order to highlight only the selected nodes.
User avatar
bernd
Posts: 7897
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: [Help] Selected element identification in .inp file

Postby bernd » Tue Sep 25, 2018 5:37 pm

EkaitzEsteban
Posts: 98
Joined: Wed Sep 12, 2018 1:31 pm

[Help+Bug] Selected element identification in .inp file

Postby EkaitzEsteban » Wed Sep 26, 2018 7:26 am

Hello,

This post follows this one: https://forum.freecadweb.org/viewtopic. ... 10#p258488

An ad-hoc way for selecting a node and its visualization in the FreeCAD GUI.

First of all click in a node. You can check that in the Selection View Window.

Then, write the following code in the python API:

Code: Select all

sel=Gui.Selection.getSelectionEx()
A=sel[0].SubElementNames[0] # this is a string comprising "nodeXXX"
newstr = ''.join((ch if ch in '0123456789.-' else ' ') for ch in A) # select only number string (maybe there is another way)
newstr_ =" ".join(newstr.split()) # get only number as string (maybe there is another way)
node=int(newstr_) # node number as integer (maybe there is another way)
Gui.ActiveDocument.getObject("FEMMeshGmsh").HighlightedNodes = range(node,node+1)
The selected node is highlighted ;) ;)

This is an ad-hoc solution but maybe is useful for somebody :P

PD: As bernd says, this issue is related here: https://forum.freecadweb.org/viewtopic. ... 0&t=31150

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13528 (Git)
Build type: Release
Branch: releases/FreeCAD-0-17
Hash: 5c3f7bf8ec51e2c7187789f7edba71a7aa82a88b
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: Spanish/Spain (es_ES)

EDIT: I found a BUG. If you select a again the highlighted node. This one is then renamed to Node1.
I try to explain. Use the abovementioned code with solely one node. e.g Node33

If you click again in the highlighted Node33, in the selection view you will see Node1 :shock:

Thank you,

best regards,
Ekaitz.

EDIT2: Generalization of the aforementioned code much better and versatile:

Code: Select all

sel=Gui.Selection.getSelectionEx()
N=len(sel[0].SubElementNames)
shownode=[]
for i in range(N):
	A=sel[0].SubElementNames[i]
	newstr = ''.join((ch if ch in '0123456789.-' else ' ') for ch in A)
	newstr_ =" ".join(newstr.split())
	shownode.append(int(newstr_))

Gui.ActiveDocument.getObject("FEMMeshGmsh").HighlightedNodes = shownode