7 September 2018 at 1 h 27 min #11903
I am simulating a scene in SOFA-Python. A model of a cube with tetrahedral mesh topology is acted upon by a linear force in a TetrahedralCorotationalFEMForceField.
Upon detecting certain criteria for displacement of the vertices of the cube, I want to reset the scene. By ‘reset’, I mean a return to the original undeformed, rest position of the model, before any forces have been applied on it.
I understand there is a reset() callback method in the Python plugin of SOFA, but I’m not sure how to use this. I don’t want to trigger this event from the UI (I am implementing this in batch mode).
I can set all the force field acting on the object to a zero vector, but I will have to wait for the dynamics of the object to stabilize, before a steady state is reached. In other words, when I remove all the input forces, the vertices do not snap back to the rest position in the very next iteration. I will have to wait for the vertex position/displacement to stabilize over multiple iterations. Can this be avoided?
Is there any way to revert back to the rest configuration, preferably in one step?
Please help.7 September 2018 at 18 h 19 min #11909
- SOFA Consortium
This is a very good question. But to make you a complete reply, could you give me a bit more context?
Why do you need to reset the scene?
Do you know how many times you have to do it?
Do you need to save information from one simulation to another?
Hugo7 September 2018 at 18 h 38 min #11911
I am trying to apply a small force to a specific node along X, Y and Z axis…. and study the result of the application of this force on the object.
Given the object in its rest configuration, I apply \Delta F_x, \Delta F_y and \Delta F_z on the node. This produces three different output, which I capture using the OBJExporter script. I intend to use these three responses (the .obj files that are exported), to evaluate a certain error function so that I can numerically compute the gradient along these three axes.
So, between the application of the forces \Delta F_x, \Delta F_y and \Delta F_z, I do not want the effect of one of the force to be carried over to the next force’s effect. Since I am trying to run this as a batch application in a loop for a large number of iterations (and intend to have some kind of a real-time system in the future), I am concerned about the run time. Therefore, I would prefer to not wait for many time-steps before the system stabilizes in between the application of the forces.
Obviously, the same system dynamics causes problem when I apply the force. It takes time to stabilize in its deformed configuration. But I kind of worked around the problem by setting the time-step ‘dt’ to a very large value. The deformation stabilizes in one time step (of 25-30 iterations of the CG Linear Solver). However, while removing the force, the same trick does not work. The system oscillates quite a bit, over many time-steps, before returning to the rest configuration.
To answer your other questions:
Do you know how many times you have to do it? Many times over. Nearly 12 – 18 times per frame.
Do you need to save information from one simulation to another? Not really. Once the force has been applied and the output logged, it is preferable that the system ‘forgets’ about all the previous forces applied.
Agniv.7 September 2018 at 18 h 49 min #11912
One more update, I tried to reset the mechanical object using:
However, it still seems like the model is slowly converging back to the neutral configuration. The surface of the object slowly oscillates back to rest.
Agniv.12 September 2018 at 18 h 20 min #11932
- SOFA Consortium
Sorry for the delay of my reply, but your question is not trivial.
The SOFA API implements a reset() visitor, reseting all components of the simulation. To do so in Python, all you need to do is:
However (yes, otherwise it would be an easy answer), the reset() function inherited in all SOFA classes is NOT always implemented (or well-implemented). Therefore, to make sure that the reset does what you want, you should check the reset() function of the components used in your scene.
Another solution would be to make the reset yourself: reseting the state vectors of the MechanicalObject (position, velocity, force, constraint ..) and all other classes.
Another solution would be to create a new node at each new force you want to apply and deactivate the node
node.activated=0when the simulation is over.
Does this help a bit ?
Hugo11 October 2018 at 12 h 04 min #12147
You must be logged in to reply to this topic.