Home › Forum › SofaPython3 › Using SofaPython3 › Access stress in TriangularFEMForceField
Tagged: SOFA_other, Stress, tearing, Topological Change, TriangularFEM, Windows_10
- This topic has 3 replies, 3 voices, and was last updated 2 years, 11 months ago by Hugo.
-
AuthorPosts
-
7 January 2022 at 09:42 #21297TheGreatLudiniMember
Hi everyone,
I would like to use SOFA v21.12 to simulate the tearing of a membrane, using a TriangularFEMForceField. For that purpose, I would like to access the stress in each triangle and compare it to a threshold, and after that apply different tearing approaches to elements where the threshold is exceeded (similar to this forum topic, but with a TriangularFEMForceField: https://www.sofa-framework.org/community/forum/topic/how-to-break-the-spring-between-mesh/).
Now, as far as I understand the source code, the stress in each triangle and other data that could be interesting for me is already computed and stored in an attribute called
triangleInfo
, which is implemented as a nested class in TriangularFEMForceField.h:/// Class to store FEM information on each triangle, for topology modification handling class TriangleInformation { public: ... // strain vector type::Vec<3,Real> strain; // stress vector type::Vec<3,Real> stress; Transformation initialTransformation; Coord principalStressDirection; Real maxStress; Coord principalStrainDirection; Real maxStrain; ...
Now, my issue is that I cannot access the attributes of this triangleInfo object from Python. I have access to the object itself, so
TriangularFEMForceField.triangleInfo
is working. But `TriangularFEMForceField.triangleInfo.stress’ gives me an error, as Python does not know about the attributes of the triangleInfo object. I assume that this is the case because there are no bindings explictly written for TriangularFEMForceField. Is that true?In general, I can only use the attributes of TriangularFEMForceField that are initialized in the constructor, see TriangularFEMForceField.inl. So that means I also don’t have access to all the other public methods (like computeStressAlongDirection(), …). But it would be great if I could use them with Python.
To sum up my questions: How can I get access to the stress in each element using Python, and to the public methods of TriangularFEMForceField? Do I have to write my own bindings? Or should I create my scene with C++ and go without Python? Or is there another way or technique to get the stress in each element?
Thanks in advance!
Best regards,
Ludwig10 January 2022 at 17:31 #21351HugoKeymasterDear @thegreatludini
Welcome on the SOFA forum and thanks for your patience.
As you noticed all information
strain
,stress
,principalStressDirection
etc. cannot be accessed (in python or in the GUI). This is due to the fact that these are attribute of the class, and not Data. Data are the attributes which are highlighted to the users and available in python/GUI.To access them, you need to update the TriangularFEMForceField and make these traditional C++ attributed becoming SOFA Data.
All component data are then automatically bound for python.
I hope this helps.Best wishes,
Hugo
17 January 2022 at 09:18 #21405LudiniBlockedDear @Hugo,
thank you very much for your reply. I will look into it and write my own component with the desired attributes as Data.
Best regards,
Ludwig17 January 2022 at 09:20 #21406HugoKeymasterDear @thegreatludini
I just created a similar reply on our new “forum” which is GitHub Discussions here.
Let me know whether this reply helps.
Best wishes,Hugo
—
NOTE: we are now moving the forum to GitHub Discussions. Do not hesitate to start using it already!
More information on the migration process can be found online. -
AuthorPosts
- You must be logged in to reply to this topic.