chrono::ChParticlesClones Class Reference

Description

Class for clusters of 'clone' particles, that is many rigid objects with the same shape and mass.

This can be used to make granular flows, where you have thousands of objects with the same shape. In fact, a single ChParticlesClones object can be more memory-efficient than many ChBody objects, because they share many features, such as mass and collision shape. If you have N different families of shapes in your granular simulations (ex. 50% of particles are large spheres, 25% are small spheres and 25% are polihedrons) you can simply add three ChParticlesClones objects to the ChSystem. This would be more efficient anyway than creating all shapes as ChBody.

#include <ChParticlesClones.h>

Inheritance diagram for chrono::ChParticlesClones:
Collaboration diagram for chrono::ChParticlesClones:

Public Member Functions

 ChParticlesClones (const ChParticlesClones &other)
 
virtual ChParticlesClonesClone () const override
 "Virtual" copy constructor (covariant return type).
 
void SetCollide (bool mcoll)
 Enable/disable the collision for this cluster of particles. More...
 
virtual bool GetCollide () const override
 Tell if the object is subject to collision. More...
 
void SetLimitSpeed (bool mlimit)
 Trick. More...
 
bool GetLimitSpeed () const
 
size_t GetNparticles () const override
 Get the number of particles.
 
ChParticleBaseGetParticle (unsigned int n) override
 Access the N-th particle.
 
void ResizeNparticles (int newsize) override
 Resize the particle cluster. More...
 
void AddParticle (ChCoordsys< double > initial_state=CSYSNORM) override
 Add a new particle to the particle cluster, passing a coordinate system as initial state. More...
 
void SetMaterialSurface (const std::shared_ptr< ChMaterialSurface > &mnewsurf)
 Set the material surface for contacts.
 
std::shared_ptr
< ChMaterialSurface > & 
GetMaterialSurfaceBase ()
 Set the material surface for contacts.
 
virtual void IntStateGather (const unsigned int off_x, ChState &x, const unsigned int off_v, ChStateDelta &v, double &T) override
 From item's state to global state vectors y={x,v} pasting the states at the specified offsets. More...
 
virtual void IntStateScatter (const unsigned int off_x, const ChState &x, const unsigned int off_v, const ChStateDelta &v, const double T) override
 From global state vectors y={x,v} to item's state (and update) fetching the states at the specified offsets. More...
 
virtual void IntStateGatherAcceleration (const unsigned int off_a, ChStateDelta &a) override
 From item's state acceleration to global acceleration vector.
 
virtual void IntStateScatterAcceleration (const unsigned int off_a, const ChStateDelta &a) override
 From global acceleration vector to item's state acceleration.
 
virtual void IntStateIncrement (const unsigned int off_x, ChState &x_new, const ChState &x, const unsigned int off_v, const ChStateDelta &Dv) override
 Computes x_new = x + Dt , using vectors at specified offsets. More...
 
virtual void IntLoadResidual_F (const unsigned int off, ChVectorDynamic<> &R, const double c) override
 Takes the F force term, scale and adds to R at given offset: R += c*F.
 
virtual void IntLoadResidual_Mv (const unsigned int off, ChVectorDynamic<> &R, const ChVectorDynamic<> &w, const double c) override
 Takes the M*v term, multiplying mass by a vector, scale and adds to R at given offset: R += c*M*w.
 
virtual void IntToDescriptor (const unsigned int off_v, const ChStateDelta &v, const ChVectorDynamic<> &R, const unsigned int off_L, const ChVectorDynamic<> &L, const ChVectorDynamic<> &Qc) override
 Prepare variables and constraints for a solution: From a vector R into the F 'force' term of the variables From a vector Qc into the Qb 'constraint' term of the constraints From a vector v into the q 'unknowns' term of the variables (for warm starting) From a vector L into the L 'lagrangian ' term of the constraints (for warm starting)
 
virtual void IntFromDescriptor (const unsigned int off_v, ChStateDelta &v, const unsigned int off_L, ChVectorDynamic<> &L) override
 After a solver solution, fetch values from variables and constraints: To a vector v from the q 'unknowns' term of the variables To a vector L from the L 'lagrangian ' term of the constraints.
 
virtual void VariablesFbReset () override
 Sets the 'fb' part (the known term) of the encapsulated ChVariables to zero.
 
virtual void VariablesFbLoadForces (double factor=1) override
 Adds the current forces (applied to item) into the encapsulated ChVariables, in the 'fb' part: qf+=forces*factor.
 
virtual void VariablesQbLoadSpeed () override
 Initialize the 'qb' part of the ChVariables with the current value of speeds. More...
 
virtual void VariablesFbIncrementMq () override
 Adds M*q (masses multiplied current 'qb') to Fb, ex. More...
 
virtual void VariablesQbSetSpeed (double step=0) override
 Fetches the item speed (ex. More...
 
virtual void VariablesQbIncrementPosition (double step) override
 Increment item positions by the 'qb' part of the ChVariables, multiplied by a 'step' factor. More...
 
virtual void InjectVariables (ChSystemDescriptor &mdescriptor) override
 Tell to a system descriptor that there are variables of type ChVariables in this object (for further passing it to a solver) Basically does nothing, but maybe that inherited classes may specialize this. More...
 
void SetNoSpeedNoAcceleration () override
 Set no speed and no accelerations (but does not change the position)
 
collision::ChCollisionModelGetCollisionModel ()
 Acess the collision model for the collision engine: this is the 'sample' collision model that is used by all particles. More...
 
virtual void SyncCollisionModels () override
 Synchronize coll.models coordinates and bounding boxes to the positions of the particles.
 
virtual void AddCollisionModelsToSystem () override
 If this physical item contains one or more collision models, add them to the system's collision engine. More...
 
virtual void RemoveCollisionModelsFromSystem () override
 If this physical item contains one or more collision models, remove them from the system's collision engine. More...
 
void UpdateParticleCollisionModels ()
 After you added collision shapes to the sample coll.model (the one that you access with GetCollisionModel() ) you need to call this function so that all collision models of particles will reference the sample coll.model. More...
 
void SetMass (double newmass)
 Mass of each particle. Must be positive.
 
double GetMass () const
 
void SetInertia (const ChMatrix33<> &newXInertia)
 Set the inertia tensor of each particle.
 
void SetInertiaXX (const ChVector<> &iner)
 Set the diagonal part of the inertia tensor of each particle.
 
ChVector GetInertiaXX () const
 Get the diagonal part of the inertia tensor of each particle.
 
void SetInertiaXY (const ChVector<> &iner)
 Set the extradiagonal part of the inertia tensor of each particle (xy, yz, zx values, the rest is symmetric)
 
ChVector GetInertiaXY () const
 Get the extradiagonal part of the inertia tensor of each particle (xy, yz, zx values, the rest is symmetric)
 
void SetMaxSpeed (float m_max_speed)
 Trick. More...
 
float GetMaxSpeed () const
 
void SetMaxWvel (float m_max_wvel)
 Trick. More...
 
float GetMaxWvel () const
 
void ClampSpeed ()
 When this function is called, the speed of particles is clamped into limits posed by max_speed and max_wvel - but remember to put the body in the SetLimitSpeed(true) mode. More...
 
void SetSleepTime (float m_t)
 Set the amount of time which must pass before going automatically in sleep mode when the body has very small movements. More...
 
float GetSleepTime () const
 
void SetSleepMinSpeed (float m_t)
 Set the max linear speed to be kept for 'sleep_time' before freezing.
 
float GetSleepMinSpeed () const
 
void SetSleepMinWvel (float m_t)
 Set the max linear speed to be kept for 'sleep_time' before freezing.
 
float GetSleepMinWvel () const
 
virtual void Update (double mytime, bool update_assets=true) override
 Update all auxiliary data of the particles.
 
virtual void Update (bool update_assets=true) override
 Update all auxiliary data of the particles.
 
virtual void ArchiveOUT (ChArchiveOut &marchive) override
 Method to allow serialization of transient data to archives.
 
virtual void ArchiveIN (ChArchiveIn &marchive) override
 Method to allow deserialization of transient data from archives.
 
- Public Member Functions inherited from chrono::ChIndexedParticles
 ChIndexedParticles (const ChIndexedParticles &other)
 
virtual int GetDOF () override
 Number of coordinates of the particle cluster, x7 because with quaternions for rotation.
 
virtual int GetDOF_w () override
 Number of coordinates of the particle cluster, x6 because derivatives es. angular vel.
 
virtual ChFrame GetAssetsFrame (unsigned int nclone=0) override
 Get the master coordinate system for the assets (this will return the main coordinate system of the rigid body) More...
 
virtual unsigned int GetAssetsFrameNclones () override
 Optionally, a ChPhysicsItem can return multiple asset coordinate systems; this can be helpful if, for example, when a ChPhysicsItem contains 'clones' with the same assets (ex. More...
 
- Public Member Functions inherited from chrono::ChPhysicsItem
 ChPhysicsItem (const ChPhysicsItem &other)
 
ChSystemGetSystem () const
 Get the pointer to the parent ChSystem()
 
virtual void SetSystem (ChSystem *m_system)
 Set the pointer to the parent ChSystem() and also add to new collision system / remove from old coll.system.
 
void AddAsset (std::shared_ptr< ChAsset > masset)
 Add an optional asset (it can be used to define visualization shapes, es ChSphereShape, or textures, or custom attached properties that the user can define by creating his class inherited from ChAsset)
 
std::vector< std::shared_ptr
< ChAsset > > & 
GetAssets ()
 Access to the list of optional assets.
 
std::shared_ptr< ChAssetGetAssetN (unsigned int num)
 Access the Nth asset in the list of optional assets.
 
virtual void GetTotalAABB (ChVector<> &bbmin, ChVector<> &bbmax)
 Get the entire AABB axis-aligned bounding box of the object. More...
 
virtual void GetCenter (ChVector<> &mcenter)
 Get a symbolic 'center' of the object. More...
 
virtual void StreamINstate (ChStreamInBinary &mstream)
 Method to deserialize only the state (position, speed) Must be implemented by child classes. More...
 
virtual void StreamOUTstate (ChStreamOutBinary &mstream)
 Method to serialize only the state (position, speed) Must be implemented by child classes. More...
 
virtual void Setup ()
 This might recompute the number of coordinates, DOFs, constraints, in case this might change (ex in ChAssembly), as well as state offsets of contained items (ex in ChMesh)
 
virtual int GetDOC ()
 Get the number of scalar constraints, if any, in this item.
 
virtual int GetDOC_c ()
 Get the number of scalar constraints, if any, in this item (only bilateral constr.) Children classes might override this. More...
 
virtual int GetDOC_d ()
 Get the number of scalar constraints, if any, in this item (only unilateral constr.) Children classes might override this. More...
 
unsigned int GetOffset_x ()
 Get offset in the state vector (position part)
 
unsigned int GetOffset_w ()
 Get offset in the state vector (speed part)
 
unsigned int GetOffset_L ()
 Get offset in the lagrangian multipliers.
 
void SetOffset_x (const unsigned int moff)
 Set offset in the state vector (position part) Note: only the ChSystem::Setup function should use this.
 
void SetOffset_w (const unsigned int moff)
 Set offset in the state vector (speed part) Note: only the ChSystem::Setup function should use this.
 
void SetOffset_L (const unsigned int moff)
 Set offset in the lagrangian multipliers Note: only the ChSystem::Setup function should use this.
 
virtual void IntStateGatherReactions (const unsigned int off_L, ChVectorDynamic<> &L)
 From item's reaction forces to global reaction vector. More...
 
virtual void IntStateScatterReactions (const unsigned int off_L, const ChVectorDynamic<> &L)
 From global reaction vector to item's reaction forces. More...
 
virtual void IntLoadResidual_CqL (const unsigned int off_L, ChVectorDynamic<> &R, const ChVectorDynamic<> &L, const double c)
 Takes the term Cq'*L, scale and adds to R at given offset: R += c*Cq'*L. More...
 
virtual void IntLoadConstraint_C (const unsigned int off, ChVectorDynamic<> &Qc, const double c, bool do_clamp, double recovery_clamp)
 Takes the term C, scale and adds to Qc at given offset: Qc += c*C. More...
 
virtual void IntLoadConstraint_Ct (const unsigned int off, ChVectorDynamic<> &Qc, const double c)
 Takes the term Ct, scale and adds to Qc at given offset: Qc += c*Ct. More...
 
virtual void InjectConstraints (ChSystemDescriptor &mdescriptor)
 Tell to a system descriptor that there are contraints of type ChConstraint in this object (for further passing it to a solver) Basically does nothing, but maybe that inherited classes may specialize this. More...
 
virtual void ConstraintsBiReset ()
 Sets to zero the known term (b_i) of encapsulated ChConstraints.
 
virtual void ConstraintsBiLoad_C (double factor=1, double recovery_clamp=0.1, bool do_clamp=false)
 Adds the current C (constraint violation) to the known term (b_i) of encapsulated ChConstraints.
 
virtual void ConstraintsBiLoad_Ct (double factor=1)
 Adds the current Ct (partial t-derivative, as in C_dt=0-> [Cq]*q_dt=-Ct) to the known term (b_i) of encapsulated ChConstraints.
 
virtual void ConstraintsBiLoad_Qc (double factor=1)
 Adds the current Qc (the vector of C_dtdt=0 -> [Cq]*q_dtdt=Qc ) to the known term (b_i) of encapsulated ChConstraints.
 
virtual void ConstraintsFbLoadForces (double factor=1)
 Adds the current link-forces, if any, (caused by springs, etc.) to the 'fb' vectors of the ChVariables referenced by encapsulated ChConstraints.
 
virtual void ConstraintsLoadJacobians ()
 Adds the current jacobians in encapsulated ChConstraints.
 
virtual void ConstraintsFetch_react (double factor=1)
 Fetches the reactions from the lagrangian multiplier (l_i) of encapsulated ChConstraints. More...
 
virtual void InjectKRMmatrices (ChSystemDescriptor &mdescriptor)
 Tell to a system descriptor that there are items of type ChKblock in this object (for further passing it to a solver) Basically does nothing, but maybe that inherited classes may specialize this. More...
 
virtual void KRMmatricesLoad (double Kfactor, double Rfactor, double Mfactor)
 Adds the current stiffness K and damping R and mass M matrices in encapsulated ChKblock item(s), if any. More...
 
- Public Member Functions inherited from chrono::ChObj
 ChObj (const ChObj &other)
 
int GetIdentifier () const
 Gets the numerical identifier of the object.
 
void SetIdentifier (int id)
 Sets the numerical identifier of the object.
 
double GetChTime () const
 Gets the simulation time of this object.
 
void SetChTime (double m_time)
 Sets the simulation time of this object.
 
const char * GetName () const
 Gets the name of the object as C Ascii null-terminated string -for reading only!
 
void SetName (const char myname[])
 Sets the name of this object, as ascii string.
 
std::string GetNameString () const
 Gets the name of the object as C Ascii null-terminated string.
 
void SetNameString (const std::string &myname)
 Sets the name of this object, as std::string.
 
void MFlagsSetAllOFF (int &mflag)
 
void MFlagsSetAllON (int &mflag)
 
void MFlagSetON (int &mflag, int mask)
 
void MFlagSetOFF (int &mflag, int mask)
 
int MFlagGet (int &mflag, int mask)
 

Additional Inherited Members

- Protected Attributes inherited from chrono::ChPhysicsItem
ChSystemsystem
 parent system
 
std::vector< std::shared_ptr
< ChAsset > > 
assets
 set of assets
 
unsigned int offset_x
 offset in vector of state (position part)
 
unsigned int offset_w
 offset in vector of state (speed part)
 
unsigned int offset_L
 offset in vector of lagrangian multipliers
 
- Protected Attributes inherited from chrono::ChObj
double ChTime
 the time of simulation for the object
 

Member Function Documentation

void chrono::ChParticlesClones::AddCollisionModelsToSystem ( )
overridevirtual

If this physical item contains one or more collision models, add them to the system's collision engine.

Reimplemented from chrono::ChPhysicsItem.

void chrono::ChParticlesClones::AddParticle ( ChCoordsys< double >  initial_state = CSYSNORM)
overridevirtual

Add a new particle to the particle cluster, passing a coordinate system as initial state.

NOTE! Define the sample collision shape using GetCollisionModel()->... before adding particles!

Implements chrono::ChIndexedParticles.

void chrono::ChParticlesClones::ClampSpeed ( )

When this function is called, the speed of particles is clamped into limits posed by max_speed and max_wvel - but remember to put the body in the SetLimitSpeed(true) mode.

virtual bool chrono::ChParticlesClones::GetCollide ( ) const
overridevirtual

Tell if the object is subject to collision.

Only for interface; child classes may override this, using internal flags.

Reimplemented from chrono::ChPhysicsItem.

collision::ChCollisionModel* chrono::ChParticlesClones::GetCollisionModel ( )

Acess the collision model for the collision engine: this is the 'sample' collision model that is used by all particles.

To get a non-null pointer, remember to SetCollide(true), before.

void chrono::ChParticlesClones::InjectVariables ( ChSystemDescriptor mdescriptor)
overridevirtual

Tell to a system descriptor that there are variables of type ChVariables in this object (for further passing it to a solver) Basically does nothing, but maybe that inherited classes may specialize this.

Reimplemented from chrono::ChPhysicsItem.

void chrono::ChParticlesClones::IntStateGather ( const unsigned int  off_x,
ChState x,
const unsigned int  off_v,
ChStateDelta v,
double &  T 
)
overridevirtual

From item's state to global state vectors y={x,v} pasting the states at the specified offsets.

Reimplemented from chrono::ChPhysicsItem.

void chrono::ChParticlesClones::IntStateIncrement ( const unsigned int  off_x,
ChState x_new,
const ChState x,
const unsigned int  off_v,
const ChStateDelta Dv 
)
overridevirtual

Computes x_new = x + Dt , using vectors at specified offsets.

By default, when DOF = DOF_w, it does just the sum, but in some cases (ex when using quaternions for rotations) it could do more complex stuff, and children classes might overload it.

Reimplemented from chrono::ChPhysicsItem.

void chrono::ChParticlesClones::IntStateScatter ( const unsigned int  off_x,
const ChState x,
const unsigned int  off_v,
const ChStateDelta v,
const double  T 
)
overridevirtual

From global state vectors y={x,v} to item's state (and update) fetching the states at the specified offsets.

Reimplemented from chrono::ChPhysicsItem.

void chrono::ChParticlesClones::RemoveCollisionModelsFromSystem ( )
overridevirtual

If this physical item contains one or more collision models, remove them from the system's collision engine.

Reimplemented from chrono::ChPhysicsItem.

void chrono::ChParticlesClones::ResizeNparticles ( int  newsize)
overridevirtual

Resize the particle cluster.

Also clear the state of previously created particles, if any. NOTE! Define the sample collision shape using GetCollisionModel()->... before adding particles!

Implements chrono::ChIndexedParticles.

void chrono::ChParticlesClones::SetCollide ( bool  mcoll)

Enable/disable the collision for this cluster of particles.

After setting ON, remember RecomputeCollisionModel() before anim starts (it is not automatically recomputed here because of performance issues.)

void chrono::ChParticlesClones::SetLimitSpeed ( bool  mlimit)

Trick.

Set the maximum linear speed (beyond this limit it will be clamped). This is useful in virtual reality and real-time simulations, because it reduces the risk of bad collision detection. The realism is limited, but the simulation is more stable.

void chrono::ChParticlesClones::SetMaxSpeed ( float  m_max_speed)

Trick.

Set the maximum linear speed (beyond this limit it will be clamped). This is useful in virtual reality and real-time simulations, because it reduces the risk of bad collision detection. This speed limit is active only if you set SetLimitSpeed(true);

void chrono::ChParticlesClones::SetMaxWvel ( float  m_max_wvel)

Trick.

Set the maximum angular speed (beyond this limit it will be clamped). This is useful in virtual reality and real-time simulations, because it reduces the risk of bad collision detection. This speed limit is active only if you set SetLimitSpeed(true);

void chrono::ChParticlesClones::SetSleepTime ( float  m_t)

Set the amount of time which must pass before going automatically in sleep mode when the body has very small movements.

void chrono::ChParticlesClones::UpdateParticleCollisionModels ( )

After you added collision shapes to the sample coll.model (the one that you access with GetCollisionModel() ) you need to call this function so that all collision models of particles will reference the sample coll.model.

void chrono::ChParticlesClones::VariablesFbIncrementMq ( )
overridevirtual

Adds M*q (masses multiplied current 'qb') to Fb, ex.

if qb is initialized with v_old using VariablesQbLoadSpeed, this method can be used in timestepping schemes that do: M*v_new = M*v_old + forces*dt

Reimplemented from chrono::ChPhysicsItem.

void chrono::ChParticlesClones::VariablesQbIncrementPosition ( double  step)
overridevirtual

Increment item positions by the 'qb' part of the ChVariables, multiplied by a 'step' factor.

pos+=qb*step

If qb is a speed, this behaves like a single step of 1-st order numerical integration (Eulero integration).

Reimplemented from chrono::ChPhysicsItem.

void chrono::ChParticlesClones::VariablesQbLoadSpeed ( )
overridevirtual

Initialize the 'qb' part of the ChVariables with the current value of speeds.

Note: since 'qb' is the unknown, this function seems unnecessary, unless used before VariablesFbIncrementMq()

Reimplemented from chrono::ChPhysicsItem.

void chrono::ChParticlesClones::VariablesQbSetSpeed ( double  step = 0)
overridevirtual

Fetches the item speed (ex.

linear and angular vel.in rigid bodies) from the 'qb' part of the ChVariables and sets it as the current item speed. If 'step' is not 0, also should compute the approximate acceleration of the item using backward differences, that is accel=(new_speed-old_speed)/step. Mostly used after the solver provided the solution in ChVariables.

Reimplemented from chrono::ChPhysicsItem.