Hi,

Just complemented another point. You might also need to Gather and Scatter 
the acceleration and Lagrange multipliers if you want to recover the system 
state exactly as the snapshot investigated.

Something like:

        auto state_der2 = 
chrono_types::make_shared<ChStateDelta>(system.GetNumCoordsVelLevel(), 
&system);
        system.StateGatherAcceleration(*state_der2);

        auto state_L = 
chrono_types::make_shared<ChVectorDynamic<>>(system.GetNumConstraints());
        system.StateGatherReactions(*state_L);

and similarly for the Scattering (i.e. loading back into ChSystem).

The complete state of a system includes: X (position and orientation), V 
(velocity), A (acceleration), T (time), L( Lagrange multipliers).

Good luck.
Chao PENG.

在2024年6月20日星期四 UTC+2 23:24:31<[email protected]> 写道:

BTW, if you just want to load/save the state of the system, without the 
model itself, you can come up with some easier yet not complete, solution 
of using ChSystem::StateGather and ChSystem::StateScatter.

Something like:

        auto state = 
chrono_types::make_shared<ChState>(system.GetNumCoordsPosLevel(), &system);
        auto state_der = 
chrono_types::make_shared<ChStateDelta>(system.GetNumCoordsVelLevel(), 
&system);
        double time;
        system.StateGather(*state   , *state_der, time_dummy);


and similarly for the Scattering (i.e. loading back into ChSystem)

Please notice however that you have to make sure that the model is exactly 
the same and also that can be additional relevant variables (e.g. some 
variable in the timesteppers) that is not retrieved in this way thus making 
a slight difference when you load back the state.


Il giorno giovedì 20 giugno 2024 alle 23:18:46 UTC+2 Dario Mangoni ha 
scritto:

Hi,
yes there is.

You may find more references by searching for the "archive" keyword instead 
of serialization.
*demo_CH_archive 
<https://github.com/projectchrono/chrono/blob/main/src/demos/core/demo_CH_archive.cpp>*is
 
a starting point, but it's probably showing many more features that just 
simply a Chrono system serialization.
*utest_CH_archive 
<https://github.com/projectchrono/chrono/blob/main/src/tests/unit_tests/core/utest_CH_archive.cpp>*is
 
another source of information, while it's meant for testing.

In general you can import|export to JSON, XML and binary format.

In general, for a whole ChSystem, you can simply do something like.

{
    ChSystemNSC system;
    ADD THINGS TO YOUR SYSTEM
    std::ofstream mfileo("ChArchiveJSON_Pendulum.json");
    ChArchiveOutJSON archive_out(mfileo);
    archive_out << CHNVP(system);
}

std::ifstream mfilei("ChArchiveJSON_Pendulum.json");
ChArchiveInJSON archive_in(mfilei);

ChSystemNSC system;
archive_in >> CHNVP(system);

Please mind that not all the classes are enabled to serialization (e.g. 
ChVisualShapeFEA are not).
You may be able to check which are enabled by checking the relative 
ArchiveIn|ArchiveOut methods for each class.

Il giorno giovedì 20 giugno 2024 alle 20:00:49 UTC+2 [email protected] ha 
scritto:

Is there any way to serialize Chrono::Systems so that the system state is 
recoverable from disk? I'd like to be able to save the state of the system 
for debugging at a later date.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/projectchrono/ee47e377-6e3b-4f00-9f74-23acb85fff90n%40googlegroups.com.

Reply via email to