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

From: [email protected] <[email protected]> On Behalf 
Of Frank Poerner
Sent: Monday, March 27, 2023 8:26 AM
To: ProjectChrono <[email protected]>
Subject: [chrono] Re: Removing ChBodies from ChSystemMulticore at Runtime

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
Frank Poerner schrieb am Freitag, 17. März 2023 um 15:03:48 UTC+1:
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

--
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]<mailto:[email protected]>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/projectchrono/c109bc4b-e8e6-43ea-a036-b045ba32bb32n%40googlegroups.com<https://groups.google.com/d/msgid/projectchrono/c109bc4b-e8e6-43ea-a036-b045ba32bb32n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
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/PH0PR06MB82371E9B323B0040149131D7A7899%40PH0PR06MB8237.namprd06.prod.outlook.com.

Reply via email to