Identification of faces

Need help, or want to share a macro? Post here!
AtD
Posts: 23
Joined: Mon Mar 18, 2019 7:14 am

Identification of faces

Post by AtD » Fri Dec 20, 2019 8:35 am

Hi all,

first, I must apologize for not having searched around alot for my problem, I have no time :D But I am willing to invest some time, when maybe you can point me in a direction of how to tackle my issue.

I am a CFD engineer and my ultimate goal is to have a geometry that is parametrized, have some predefined boundary conditions which I apply to certain faces in the model and perform a simulation. I use the CFD workbench for that, where I was able to implement my whole workflow already: parametrize the geometry, mesh it, add boundary conditions, run the simulation - all automated.
Now, a major drawback is still, that the complexity of the model is quite constrained: some of the parameters I introduced lead to a change of the overall number of faces inside the model. Which is problematic, because inside the CfdOFWorkbench (and all other cfd software), boundary conditions are set on faces. Now, if the number of faces changes, the references set inside the boundary conditions need to be updated. This can be done by looking closely how the numbering changes and adapt that pattern. However, this is a tedious task and requires to have at least someone who understands Python, and needs to be done for every variant of geometry that can arise from the parameters. Alright, so thats the problem.

My question is: can I / how can I identify faces that are created by certain features? Imagine a box (Feature 1), with a smaller box (Feature 2) subtracted. Now I have a pattern (Feature 3), which is parametrized and allows me to subtract the smaller box however often I want (of course with some offset). So I now have a big box (F1) and some, say 5, smaller boxes which are cut out. The problem is, I can access all faces in the model by doing something like faces = App.ActiveDocument.<LastFeatureName>.Shape.Faces. But this will give me ALL the faces in the model, instead of the ones created by the last feature operation, which I need to know to assign to a certain patch. Is there a way to distinguish the faces created by each feature?

Excuse the long text. I am happy for suggestions.
Thanks!
Attachments
fc.PNG
fc.PNG (39.96 KiB) Viewed 404 times
User avatar
microelly2
Posts: 4560
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Identification of faces

Post by microelly2 » Fri Dec 20, 2019 9:13 am

I use to identify a face a key defind by the location (center of mass) and a topological key

Code: Select all

def topokey(s):
    a=s.PrincipalProperties['Moments']
    f=a[2]
    return tuple([round(s.Area/f**2,1),round(s.Volume/f**3,1),round(a[0]/f,1),round(a[1]/f,1),round(a[2]/f,1)])
#or:    return tuple([round(s.Area,1),round(s.Volume,1),round(a[0],1),round(a[1],1),round(a[2],1)])
topokey is a method to get a number which is in most cases uniq for a special layout of the shape.
I store for each shape this information into a database , so I can track the same shape during a design process.
when a face is renamed the topokey still is the same,
when a face is modified the topokey changes.
AtD
Posts: 23
Joined: Mon Mar 18, 2019 7:14 am

Re: Identification of faces

Post by AtD » Fri Dec 20, 2019 9:53 am

So if I understand correctly, you iterate through the features and get the faces after each step and store face information away. Then after each step you can identify which faces changed by looking at the new and old information.
Thats seems perfect, thanks for your suggestion. How have I not considered this^^ Sometimes working intensively on something make you blind for other ideas :)
I will definitely try that out and provide some feedback in the new year. Happy holidays!
vocx
Posts: 2829
Joined: Thu Oct 18, 2018 9:18 pm

Re: Identification of faces

Post by vocx » Fri Dec 20, 2019 11:54 pm

AtD wrote:
Fri Dec 20, 2019 9:53 am
So if I understand correctly, you iterate through the features and get the faces after each step and store face information away. Then after each step you can identify which faces changed by looking at the new and old information.
Yes, in general, doing what you want requires iteration, but there is a huge issue, and that is the topological naming problem.

In general, an operation that creates a new face may rename the previously created faces. That is, if you have three faces, Face1, Face2, Face3, and add a new one, you would expect this, Face1, Face2, Face3, Face4.

However, due to the topological naming problem, this is not consistent, and may actually result in an arbitrary name. For example, Face4, Face5, Face6, Face7. If you iterate over all faces, you may find that you have "four new faces" instead of only "one new face".

This is a huge problem if you are going to be searching by name. But if you will be searching by position, that is, coordinates of the faces, or some other property, maybe it's possible to do what you want and automatically detect those new faces.

The topological naming problem may be solved in the future, maybe in the next development version 0.20, as there is a proposal by realthunder, Topological Naming, My Take. This proposal should improve the way the software keeps track of elements thus having a more consistent naming.
To support the documentation effort, and code development, your donation is appreciated: paypal.
AtD
Posts: 23
Joined: Mon Mar 18, 2019 7:14 am

Re: Identification of faces

Post by AtD » Sat Dec 21, 2019 3:05 pm

Thanks for your detailed description and some terms to look out for. I will check these links.

I usually work with Solidwork which keeps track of faces quite nicely in most situations and even in some I wouldn't have expected. On the other hand it sometimes just deletes features related to surfaces without warning if the base feature is changed too much. Its a tricky task for sure.
User avatar
wandererfan
Posts: 3483
Joined: Tue Nov 06, 2012 5:42 pm

Re: Identification of faces

Post by wandererfan » Sat Dec 21, 2019 5:31 pm

vocx wrote:
Fri Dec 20, 2019 11:54 pm
However, due to the topological naming problem, this is not consistent, and may actually result in an arbitrary name. For example, Face4, Face5, Face6, Face7. If you iterate over all faces, you may find that you have "four new faces" instead of only "one new face".
If there are 4 faces in the result, the faces will always be Face1, Face2, Face3 and Face4. The names are just made up from the index in the list of faces.

What might very well happen though, is that the newly added face is second in the list and becomes Face2 and the face we knew as Face2 is now Face4 (or Face1 or Face3).
vocx
Posts: 2829
Joined: Thu Oct 18, 2018 9:18 pm

Re: Identification of faces

Post by vocx » Sat Dec 21, 2019 7:06 pm

wandererfan wrote:
Sat Dec 21, 2019 5:31 pm
...
What might very well happen though, is that the newly added face is second in the list and becomes Face2 and the face we knew as Face2 is now Face4 (or Face1 or Face3).
Okay, so something like this.

Code: Select all

old        new
Face1 ---> Face4
Face2 ---> Face2
Face3 ---> Face1
           Face3 (new one)
That is, the new face may not appear in sequence, and one of the previous faces may be renamed.
To support the documentation effort, and code development, your donation is appreciated: paypal.
AtD
Posts: 23
Joined: Mon Mar 18, 2019 7:14 am

Re: Identification of faces

Post by AtD » Thu Jan 02, 2020 8:08 am

What might very well happen though, is that the newly added face is second in the list and becomes Face2 and the face we knew as Face2 is now Face4 (or Face1 or Face3).
Yea, which is exactly the problem we face here. I worked on it a bit over the holidays and was able to deal with that. I used a cube and a rectangular cut to slice it, so one of the original faces is split in two, forcing FreeCAD to rename it and other faces as well. Using the face area and bounding boxes as references, I was able to track the face names during the design process. I did this in my free time so maybe I can provide my solution here once its finished (still have some minor numbering issue).
If there are 4 faces in the result, the faces will always be Face1, Face2, Face3 and Face4. The names are just made up from the index in the list of faces.
I was a bit confused by this either, since I expected the Faces to have some property like "name" or "id" which would be updated in each step. But I found that "generating" the name from the list indeces gives the same numbering FreeCAD shows in the GUI.
jbi
Posts: 54
Joined: Sun Apr 24, 2016 3:28 pm

Re: Identification of faces

Post by jbi » Thu Jan 02, 2020 10:25 am

Wouldn't it be sufficient to use face.hashCode() to track down with the topological naming and use the hashcodes instead of unique identifiers?
User avatar
wandererfan
Posts: 3483
Joined: Tue Nov 06, 2012 5:42 pm

Re: Identification of faces

Post by wandererfan » Thu Jan 02, 2020 4:22 pm

jbi wrote:
Thu Jan 02, 2020 10:25 am
Wouldn't it be sufficient to use face.hashCode() to track down with the topological naming and use the hashcodes instead of unique identifiers?
It has been a while since I looked at this, so take with a grain of salt.

OCC TopoDS_Shape::hashCode() is not guaranteed to be unique. It is computed from the underlying TShape (which may be shared by multiple TopoDS_Shapes) + Location. Don't know what the odds of collision are.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests