Removing ChBodies from ChSystemMulticore at Runtime

32 views
Skip to first unread message

Frank Poerner

unread,
Mar 17, 2023, 10:03:48 AMMar 17
to ProjectChrono
Hi everybody,

I have a problem when removing a ChBody from ChSystemMulticore at Runtime. At the moment I am trying to bring my physics simulation from single core to multicore and however I run into some runtime crashes when I try the following:

I create some ChBodies which are connected with some ChLinks - all are added to ChSystemMulticore. This works perfectly fine. However at some point I am removing ALL elements from the simulation calling:

mySystem.Clear()  -> This calls ChSystem.Clear();

However if I try to continue my simulation after adding another ChBodies I run into a runtime exception in ChSystemMulticore::ClearForceVariables() (namly a vector-out-of-range-error):

    for (int i = 0; i < (signed)data_manager->num_rigid_bodies; i++) {
        assembly.bodylist[i]->VariablesFbReset();
    }


I did some debugging and the reason is, that after calling ChSystem.Clear() the data_manager of ChSystemMulticore still has num_rigid_bodies > 0.
This looks like a bug to me?

I tried to simply set num_rigid_bodies = 0 after calling Clear(), but this is obviously a stupid idea and let to some other crashes...


I am not that deep into Project Chrono, but is there a nice way to delete elements from a ChSystemMulticore Class? Maybe if somebody can give me a hint what I need to delete inside the data_manager I might be able to fix it myself.


Thanks,
Frank

Frank Poerner

unread,
Mar 27, 2023, 9:25:30 AMMar 27
to ProjectChrono
So I found a workaround (not the nicest way though, but it works): There is no routine which deletes the elements in the host_data inside the data_manager inside ChSystemMulticore. So I added one:

void ChSystemMulticore::ResetDataManager() {
  if (data_manager) {
    // Reset to default values
    data_manager->host_data = host_container();

    data_manager->num_bilaterals = 0;
    data_manager->num_constraints = 0;
    data_manager->num_dof = 0;
    data_manager->num_fluid_bodies = 0;
    data_manager->num_linmotors = 0;
    data_manager->num_motors = 0;
    data_manager->num_rigid_bodies = 0;
    data_manager->num_rotmotors = 0;
    data_manager->num_shafts = 0;
    data_manager->num_unilaterals = 0;
  }
}

I call this function after calling Clear(). Works fine for now.


For removing one specific element I guess one has to remove this specific element from host_data and reduce the associated counter...

Best,
Frank

Radu Serban

unread,
Mar 29, 2023, 9:58:22 AMMar 29
to ProjectChrono

Hi Frank,

 

You are correct, the functionality for removing modeling components is not implemented for ChSystemMulticore. This is because of the data structures used in the Multicore module (SoA as opposed to AoS) and the consequences such an operation would have (either costly delete operations or else complications in bookkeeping).  Deleting *all* elements can be done like you describe, but at that point isn’t this pretty much equivalent to deleting the entire system and rebuilding it?

 

However, an even more basic question is whether using a Chrono::Multicore system is worthwhile in the first place. Note that the primary goal of this module was simulation of large-scale granular dynamics, possibly interacting with ma multibody system.  The benefits of multithreading (through OpenMP in this case) show up only once you have a large enough number of bodies (as in granular dynamics).  For smaller systems, the overhead is likely to result in poorer performance than what you’d get with the core Chrono module.  What problems are you interested in?

 

Finally, a note that a refactoring of Chrono::Multicore has long been in my todo list.  That will require replacing Blaze with Eigen for linear algebra and switching Chrono::Multicore from using some older (tagged for obsoletion) low-level Chrono functions.  When that refactoring happens, I will revisit the issue of allowing deletion of individual physics elements from a system.

 

--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/c109bc4b-e8e6-43ea-a036-b045ba32bb32n%40googlegroups.com.

Reply all
Reply to author
Forward
Message has been deleted
0 new messages