how to continue the simulation from the last time it ended?

73 views
Skip to first unread message

Qihan Xuan

unread,
Aug 10, 2022, 1:16:18 PM8/10/22
to ProjectChrono
Hi,

I am going to run two simulations.
The second one is to continue the first simulation.

So I need to store the information of the last moment of the first simulation, and use it as the start status of the second one.

I know I can store all information like position, orientation, velocity, etc., and modify the codes to reset the initial status. But this way takes too much effort. 

So, I am wondering is there an easier way to continue the second simulation?

Thanks,
Qihan 

Luning Fang

unread,
Aug 11, 2022, 6:01:09 PM8/11/22
to ProjectChrono
Hello Qihan,

The functions that could be helpful are ReadCheckpoint(ChSystem* system, const std::string& filename) and WriteCheckpoint(ChSystem* system, const std::string& filename).

Take a look at "demo_MCORE_cratering.cpp" or "demo_VEH_Cosim_WheelRig.cpp" for example. You can always customize your own checkpoint file in if you need more information.

For people using Chrono::GPU,  the demo on checkpointing is demo_GPU_ballcosim.cpp.

Thank you,
Luning

Qihan Xuan

unread,
Aug 11, 2022, 11:35:09 PM8/11/22
to ProjectChrono
Thanks!

Radu Serban

unread,
Aug 12, 2022, 1:26:14 PM8/12/22
to ProjectChrono

Qihan,

 

A word of caution about the WriteCheckpoint and ReadCheckpoint functions that Luning mentioned.  While these are indeed meant for restarting a simulation the way you intend to do, when I wrote them, I was only interested in reinitializing a granular dynamics simulation. As such, they are somewhat limited in what kind of systems they can be applied to.  If you look at them, you will see that they only extract and re-apply body states (position, orientation, linear and angular velocity).  This will not be enough for multibody systems that include other modeling elements that have states (such as ChShaft, or some of the motors in Chrono).

 

Arguably a better way of doing this reinitialization is by saving (and caching) the state vector for the entire system and then reapplying it when you want to reinitialize. I have not formalized this in Chrono, but you can see an example precisely doing that in the test_VEH_reinit_wheeled in my own fork of the Chrono repository.  The two functions in that program you should look at are SaveCheckpoint and LoadCheckpoint.  They have some extra stuff specific to a vehicle model which you should discard (or else adapt) for your own problem.

 

By the way, adding proper formal support for checkpointing in Chrono, across all modules and system types, is on our todo list.

 

--Radu

--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/c5898d28-6d64-48b5-9a25-7a8617bcef98n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages