Home › Forum › SOFA › Using SOFA › [SOLVED] Exporting States
Tagged: 64_bits, Linux_ubuntu, SOFA_1512
- This topic has 14 replies, 3 voices, and was last updated 7 years, 11 months ago by Hugo.
-
AuthorPosts
-
23 August 2016 at 18:55 #7383JasonBlocked
Hi Everyone,
I want to export (and import) the state of a mechanical object, i.e. the positions and velocities. Is there a simple way to do this? I used OBJExporter to export the positions, but I don’t see a way to export/import the velocities. What do you guys do in this situation?
Thanks for your kind help.
-J
23 August 2016 at 20:45 #7384JasonBlockedTo be clear, I want to plot the velocities as a vector field, i.e. a vector representing the velocity at each position in the mechanical object.
24 August 2016 at 09:42 #7386HugoKeymasterDear Jason,
To export or import the state (position, velocity, forces), there is already two components available in SOFA for this:
- export with WriteState: set writeX=”1″ to export positions, set writeV=”1″ for velocities, set writeF=”1″ for the forces. For more info about the options, see WriteState.inl at line 47,
- and import with ReadState.
Cheers,
Hugo
26 August 2016 at 01:51 #7403JasonBlockedHi Hugo,
I get everything written out with WriteState, but I can’t figure out how to repopulate the mechanical object using ReadState. Can you give a working XML example of how to do that?
Thanks for your kind help.
-Jason
29 August 2016 at 17:22 #7404rtriviBlockedHi Jason,
here you have an example on how I use a ReadState in one of my scenes.
Although you don’t have the whole context, I hope it can still be useful 🙂Don’t hesitate to ask any other question ! 🙂
Ciao ciao
Raffa<Node name="Catheter"> <EulerSolver /> <EdgeSetTopologyContainer name="Container" position="0.01 0 0 0.015 0 0 0.02 0 0 0.025 0 0 " edges= "0 1 1 2 2 3 "/> <MechanicalObject name="ms" template="Rigid" /> <ReadState filename="catheter" /> <Sphere radius="0.0003" color="1 0 0 1" /> <Node name="CollisionCatheter"> <EdgeSetTopologyContainer name="Container" position="0.01 0 0 0.015 0 0 0.02 0 0 0.025 0 0 " edges= "0 1 1 2 2 3 "/> <MechanicalObject name="ms" /> <Line color="0 0 0 1" /> <EdgeLinearInterpolation name="catheter" /> <BeamLinearMapping localCoord="false" /> </Node> </Node>
1 September 2016 at 17:19 #7417HugoKeymaster1 September 2016 at 22:02 #7427JasonBlockedHi Everyone,
I’ve got a node under the root node:
<Node name=”Object” > <MeshTopology name=”Topology” triangles=”@/Loader.triangles” /> <EulerImplicitSolver printLog=”0″ rayleighMass=”0.1″ rayleighStiffness=”1.5e0″ /> <CGLinearSolver template=”GraphScattered” printLog=”0″ iterations=”25″ tolerance=”1e-14″ threshold=”1e-14″ verbose=”0″ /> <MechanicalObject name=”Obj” template=”Vec3d” /> <ReadState filename=”step.data” /> <UniformMass name=”mass” mass=”5.0e-2″ /> <MeshSpringForceField template=”Vec3d” name=”Springs” stiffness=”5.0e10″ damping=”1.0e5″ object1=”@./” object2=”@./” /> <TSphereModel radius=”0.2″ contactStiffness=”1.0e1″ contactFriction=”1.0″ contactRestitution=”0″ selfCollision=”1″ /> <WriteState filename=”step.data” time=”0.1″ writeX=”1″ writeX0=”1″ writeV=”1″ writeF=”1″ /> </Node>
where step.data is a valid file written out by WriteState. However, when I put this through runSofa, and look at the data in the mechanical object, everything is identically zero! What am I doing wrong? It seems like I followed Raffa’s advice.
Thanks for your kind help.
-J
2 September 2016 at 14:01 #7433HugoKeymasterHi Jason,
You cannot use both Read and WriteState in the same scene.
The WriteState must be used in a first simulation (from which you export the state).And in a second simulation (a different XML scene), you can import the state using ReadState.
But not both in the same simulation. Why do you need to export and import the state in the same time?
2 September 2016 at 18:29 #7435JasonBlockedHi Hugo,
It seems odd to me that it’s not possible to use ReadState to read in initial state vectors, and WriteState to write out the state vector at some later point in the simulation.
It seems that lack of functionality makes it so that one can’t write out the state vectors of a restarted simulation.
Consider, for example, I run a simulation as a batch job for some number of iterations, and write out the state vectors (using WriteState) at the end. I then examine the state of the system and find that it has not come to equilibrium. So I restart the simulation (using ReadState) reading in the state vectors from the output file, and now I have no way to write the state vectors at the end of the simulation?
How should I solve this situation?
Thank you for your kind help.
-Jason
13 September 2016 at 11:56 #7461HugoKeymasterDear Jason,
SOFA is originally used for direct simulations. What you intend to do is more than this, since you want your (optimization/filtering) process to run the simulation forward and restart it again and again.
To do so, it is a bit more tricky then than just Write/ReadState. There is two ways of doing what you want:
- using python: you run a scene and after n iterations, you analyze x (positions), and if no equilibrium is reached, you reset v (velocities) and f (forces) to zero and apply a new starting x_0 (position).
- writing a specific AnimationLoop. In the same way as before (but in C++), you will analyze the simulation and reset new parameters.
Hope this helps.
Best wishes,Hugo
13 September 2016 at 16:41 #7463JasonBlockedHi Hugo,
I seem to be misunderstanding something. What you describe under “using python:” is exactly the situation I want to avoid. If no equilibrium is reached, I want to restart the simulation in exactly the same state (positions, velocities, forces) as at the end of the simulation. I can use WriteState to write out all these vectors. Then I can use ReadState to reset all these vectors at the re-start. However, if I use ReadState to restart the simulation, I can’t then use WriteState to save the state vectors again?
What is it about these two classes that conflicts? I must be missing something simple in the design that prevents them from working together.
Thanks for your help,
Jason
14 September 2016 at 14:12 #7471HugoKeymasterHi Jason,
Indeed, I might have misunderstood what you intend to do.
I need to understand your purpose first before explaining the behavior of components like ReadState/WriteState. Could you then give me some explanations:
What is the general purpose of your simulation / context ?Why you need to reset the time while keeping the same state (at the end of the simulation) ? Why not just letting the simulation running ? Because if you restart the simulation with the end positions, velocities and forces, I’m afraid it won’t help reaching the equilibrium.
Thanks,
Hugo
14 September 2016 at 18:58 #7479JasonBlockedHi Hugo,
This is in the context of using runSofa in batch mode, submitted to a queuing system with finite job time limits. That is, I know the simulation won’t finish in the time allotted per job, so I perform a number of steps I know will finish in job time. I then want to restart the simulation from the state that it ended (positions, velocities, forces). I might need to resubmit a job several times for it to finish.
What’s the best way to approach this scenario, if not with ReadState/WriteState?
Thanks for your help,
Jason
15 September 2016 at 18:53 #7484HugoKeymasterHi Jason,
In this case, I would rather use :
- MeshVTKLoader
- and a VTKExporter
Could you try this ?
Note: ReadState is usually used to “replay” a previous simulation whose positions where saved with a WriteState.
20 December 2016 at 14:32 #8234HugoKeymasterHi Jason,
This is a pretty old topic. I guess you solved it.
Keep me updated about it, best wishes,Hugo
-
AuthorPosts
- You must be logged in to reply to this topic.