SPHinXsys icon indicating copy to clipboard operation
SPHinXsys copied to clipboard

Regression with contact management / memory ownership model

Open FabienPean-Virtonomy opened this issue 2 years ago • 1 comments

The registration and memory management of particles field has been changed recently to move as many field out of base_particles.h

These changes have some consequent side effects due to the memory ownership design. See for example class ContactDensitySummation

https://github.com/Xiangyu-Hu/SPHinXsys/blob/e5d224d7af1d0685165e45224ecc50d65186f5cc/SPHINXsys/src/shared/particle_dynamics/solid_dynamics/contact_dynamics.cpp#L43-L50

Before, the field ContactDensity was in base_particles.h so initialized once per body. Now, it is moved in the contact algorithm ContactDensitySummation class. It means that creating 2 such objects for different body relation involving the same body in contact is no more possible. Why is it desired ? Because the user might need different contact topology at different point of the simulation, e.g. {A->B} and then {A->C,D}

Without modifying current memory ownership model, I see barely any opportunity:

  • On user side, creating a catch all body relation {A-> B,C,D} which is not necessarily possible because of the sequence of contact (A might not only collide with B at the beginning but also C, that one wants to avoid)
  • On library side, allow registering several field with the same name by overwriting and keeping only the last source, which is a dangerous implicit feature with high risk a breaking user expectations

FabienPean-Virtonomy avatar Sep 01 '22 10:09 FabienPean-Virtonomy

Yes. I agree with you that implicit dependence is not good. However, we need take the variables out the base particle class. My plan on eliminate the implicit dependence is first delete the function of getVariableByName from base class and introduce explicit dependence in the constructor. That is the constructor needs to know on which class this class is dependent on before accessing the variables in that class.

Xiangyu-Hu avatar Sep 05 '22 14:09 Xiangyu-Hu

Possibly, we can introducing a parameter switch, say, isShared, which is false by default, in the the function registering variable to identify a variable which may use an already registered variable.

Xiangyu-Hu avatar Nov 18 '22 08:11 Xiangyu-Hu

https://github.com/Xiangyu-Hu/SPHinXsys/blob/xiangyu/code_refactory_variable/SPHINXsys/src/shared/particles/base_particles.hpp

BenceVirtonomy avatar Mar 10 '23 10:03 BenceVirtonomy

shared particle has already introduced in new pull request.

Xiangyu-Hu avatar May 07 '23 17:05 Xiangyu-Hu