SpeciesHandler Class Referencefinal

Container to store all ParticleSpecies. More...

#include <SpeciesHandler.h>

+ Inheritance diagram for SpeciesHandler:

Public Member Functions

 SpeciesHandler ()
 Default constructor, it creates an empty SpeciesHandler. More...
 
 SpeciesHandler (const SpeciesHandler &other)
 Constructor that copies all species and the pointer to the DPMBase from the given SpeciesHandler. More...
 
SpeciesHandleroperator= (const SpeciesHandler &rhs)
 Assignment operator that copies all species and the pointer to the DPMBase from the given SpeciesHandler. More...
 
 ~SpeciesHandler () override
 Destructor, it destructs the SpeciesHandler and all ParticleSpecies it contains. More...
 
void addObject (ParticleSpecies *S) override
 Adds a new ParticleSpecies to the SpeciesHandler. More...
 
void clear () override
 Empties the whole BaseHandler by removing all Objects and setting all other variables to 0. More...
 
void removeObject (unsigned int index) override
 Remove the ParticleSpecies with given id. More...
 
void readAndAddObject (std::istream &is) override
 Reads Species data into the SpeciesHandler from restart file. More...
 
ParticleSpeciesreadOldObject (std::istream &is)
 Reads ParticleSpecies into the SpeciesHandler from old-style restart data. More...
 
unsigned int getMixedId (unsigned int id1, unsigned int id2) const
 Gets the Id of the behaviour between two given species. More...
 
template<typename U >
std::enable_if<!std::is_pointer< typename U::MixedSpeciesType >::value, typename U::MixedSpeciesType * >::type getMixedObject (const U *S, const U *T)
 
BaseSpeciesgetMixedObject (unsigned int id1, unsigned int id2)
 Gets the mixed object that is constructed from two given species. More...
 
const std::vector< BaseSpecies * > & getMixedObjects () const
 Returns a pointer to the vector of all mixed objects. More...
 
void updateMixedObjects ()
 Updates the mixed species. More...
 
virtual void write (std::ostream &os) const
 Write all the species and mixed species to an output stream. More...
 
std::string getName () const override
 Returns the name of the handler, namely the string "SpeciesHandler". More...
 
bool useAngularDOFs ()
 Check if angular DOF have to be used. More...
 
- Public Member Functions inherited from BaseHandler< ParticleSpecies >
 BaseHandler ()
 Default BaseHandler constructor, it creates an empty BaseHandler and assigns DPMBase_ to a null pointer. More...
 
 BaseHandler (const BaseHandler< ParticleSpecies > &BH)
 Constructor that copies the objects of the given handler into itself and sets other variables to 0/nullptr. More...
 
virtual ~BaseHandler ()
 Destructor, it destructs the BaseHandler and all Object it contains. More...
 
void copyContentsFromOtherHandler (const BaseHandler< ParticleSpecies > &BH)
 Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handler (container) to the other. More...
 
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddObject (const U &object)
 Creates a copy of a Object and adds it to the BaseHandler. More...
 
std::enable_if< std::is_pointer< U >::value, U >::type copyAndAddObject (const U object)
 Creates a copy of a Object and adds it to the BaseHandler. More...
 
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddGhostObject (const U &object)
 Creates a copy of a Object and adds it to the BaseHandler. This is one locally for inserting mpi particles, they avoid the global check if the particle can actually be inserted, because the mpi domain already knows that is the case. More...
 
std::enable_if< std::is_pointer< U >::value, U >::type copyAndAddGhostObject (const U object)
 Creates a copy of a Object and adds it to the BaseHandler. This is one locally for inserting mpi particles, they avoid the global check if the particle can actually be inserted, because the mpi domain already knows that is the case. More...
 
virtual void addExistingObject (ParticleSpecies *O)
 Adds an existing object to the BaseHandler without changing the id of the object. More...
 
virtual void addObject (ParticleSpecies *object)
 Adds a new Object to the BaseHandler. More...
 
virtual void addGhostObject (ParticleSpecies *O)
 Adds a new Object to the BaseHandler. called by the to avoid increasing the id. More...
 
void removeIf (const std::function< bool(ParticleSpecies *)> cond)
 
void removeLastObject ()
 Removes the last Object from the BaseHandler. More...
 
void read (std::istream &is)
 Reads all objects from restart data. More...
 
ParticleSpeciesgetObjectById (const unsigned int id)
 Gets a pointer to the Object at the specified index in the BaseHandler. More...
 
std::vector< ParticleSpecies * > getObjectsById (const unsigned int id)
 Gets a vector of pointers to the objects with the specific id. More...
 
ParticleSpeciesgetObject (const unsigned int id)
 Gets a pointer to the Object at the specified index in the BaseHandler.
More...
 
const ParticleSpeciesgetObject (const unsigned int id) const
 Gets a constant pointer to the Object at the specified index in the BaseHandler. More...
 
ParticleSpeciesgetLastObject ()
 Gets a pointer to the last Object in this BaseHandler. More...
 
const ParticleSpeciesgetLastObject () const
 Gets a constant pointer to the last Object in this BaseHandler. More...
 
virtual unsigned int getNumberOfObjects () const
 Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles) More...
 
unsigned int getSize () const
 Gets the size of the particleHandler (including mpi and periodic particles) More...
 
unsigned int getStorageCapacity () const
 Gets the storage capacity of this BaseHandler. More...
 
void setStorageCapacity (const unsigned int N)
 Sets the storage capacity of this BaseHandler. More...
 
void resize (const unsigned int N, const ParticleSpecies &obj)
 Resizes the container to contain N elements. More...
 
const std::vector< ParticleSpecies * >::const_iterator begin () const
 Gets the begin of the const_iterator over all Object in this BaseHandler. More...
 
const std::vector< ParticleSpecies * >::iterator begin ()
 Gets the begin of the iterator over all BaseBoundary in this BaseHandler. More...
 
const std::vector< ParticleSpecies * >::const_iterator end () const
 Gets the end of the const_iterator over all BaseBoundary in this BaseHandler. More...
 
const std::vector< ParticleSpecies * >::iterator end ()
 Gets the end of the iterator over all BaseBoundary in this BaseHandler. More...
 
void setDPMBase (DPMBase *DPMBase)
 Sets the problem that is solved using this handler. More...
 
void setId (ParticleSpecies *object, unsigned int id)
 
void increaseId ()
 
unsigned int getNextId ()
 
void setNextId (unsigned int id)
 
DPMBasegetDPMBase ()
 Gets the problem that is solved using this handler. More...
 
DPMBasegetDPMBase () const
 Gets the problem that is solved using this handler and does not change the class. More...
 
virtual void writeVTK () const
 now empty function for writing VTK files. More...
 
unsigned getNextGroupId ()
 Should be called each time you assign a groupId. Returns the value of nextGroupId_ and increases nextGroupId_ by one. More...
 

Private Attributes

std::vector< BaseSpecies * > mixedObjects_
 The list of pointers to the mixed species. More...
 

Additional Inherited Members

- Protected Attributes inherited from BaseHandler< ParticleSpecies >
std::vector< ParticleSpecies * > objects_
 The actual list of Object pointers. More...
 

Detailed Description

Container to store all ParticleSpecies.

The SpeciesHandler is a container to store all ParticleSpecies. It is implemented by a vector of pointers to ParticleSpecies.

Constructor & Destructor Documentation

◆ SpeciesHandler() [1/2]

SpeciesHandler::SpeciesHandler ( )

Default constructor, it creates an empty SpeciesHandler.

Constructor of the SpeciesHandler class. It creates an empty SpeciesHandler.

85 {
86  logger(DEBUG, "SpeciesHandler::SpeciesHandler() finished");
87 }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ DEBUG

References DEBUG, and logger.

◆ SpeciesHandler() [2/2]

SpeciesHandler::SpeciesHandler ( const SpeciesHandler other)

Constructor that copies all species and the pointer to the DPMBase from the given SpeciesHandler.

Parameters
[in]otherThe SpeciesHandler that has to be copied.

This is not a copy constructor! This constructor copies only all BaseSpecies and MixedSpecies and copies the pointer to the DPMBase. It sets all other data members to 0 or nullptr.

96 {
97  clear();
98  setDPMBase(other.getDPMBase());
100  for (BaseSpecies* mixSpec : other.mixedObjects_)
101  {
102  mixedObjects_.push_back(mixSpec->copy());
103  mixedObjects_.back()->setHandler(this);
104  }
105  logger(DEBUG, "SpeciesHandler::SpeciesHandler(const SpeciesHandler &other) finished");
106 }
void setDPMBase(DPMBase *DPMBase)
Sets the problem that is solved using this handler.
Definition: BaseHandler.h:718
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725
void copyContentsFromOtherHandler(const BaseHandler< ParticleSpecies > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
Definition: BaseHandler.h:367
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:50
virtual BaseSpecies * copy() const =0
Creates a deep copy of the object from which it is called.
void clear() override
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0.
Definition: SpeciesHandler.h:54
std::vector< BaseSpecies * > mixedObjects_
The list of pointers to the mixed species.
Definition: SpeciesHandler.h:99

References clear(), BaseSpecies::copy(), BaseHandler< ParticleSpecies >::copyContentsFromOtherHandler(), DEBUG, BaseHandler< T >::getDPMBase(), logger, mixedObjects_, and BaseHandler< ParticleSpecies >::setDPMBase().

◆ ~SpeciesHandler()

SpeciesHandler::~SpeciesHandler ( )
override

Destructor, it destructs the SpeciesHandler and all ParticleSpecies it contains.

Destructor: first destroys the objects of the BaseHandler, then destroys the mixedObjects

Todo:
TW Note: deleting the species does not delete the particles and walls of this species.
142 {
143  clear(); //this deletes everything that comes from the BaseHandler.
144  /*for (BaseSpecies* o : mixedObjects_)
145  {
146  delete o;
147  }*/
148  for (BaseSpecies* mixSpec : mixedObjects_)
149  {
150  delete mixSpec;
151  }
152  mixedObjects_.clear();
153  logger(DEBUG, "SpeciesHandler::~SpeciesHandler() finished");
154 }

References clear(), DEBUG, logger, and mixedObjects_.

Member Function Documentation

◆ addObject()

void SpeciesHandler::addObject ( ParticleSpecies S)
override

Adds a new ParticleSpecies to the SpeciesHandler.

Parameters
[in]SA pointer to the ParticleSpecies that has to be added.

First, add the ParticleSpecies to the vector of ParticleSpecies (object_), then construct all MixedSpecies. Tell the ParticleSpecies that this is its handler and compute all masses and whether it should use angular degrees of freedom.

Note: The MixedSpecies objects are initialized with averaged values from both species: e.g., the mixedSpecies between Species A and B will have a stiffness $fk=(1/k_a+1/k_b)^{-1}$f, you have to change the MixedSpecies properties if you don't like these defaults.

Todo:
TW don't put logger messages that only make sense for one application!
891 {
893  //logger(INFO, "Part / Mix: % / %", objects_.size(), mixedObjects_.size());
895  S->setHandler(this);
896  for (unsigned int id = 0; id + 1 < getNumberOfObjects(); ++id)
897  {
898  mixedObjects_.push_back(S->copyMixed());
899  mixedObjects_.back()->setIndex(id);
900  mixedObjects_.back()->setId(getNumberOfObjects() - 1);
901  mixedObjects_.back()->mixAll(S, getObject(id));
902  }
906 }
virtual unsigned int getNumberOfObjects() const
Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles)
Definition: BaseHandler.h:648
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:431
ParticleSpecies * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:613
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.h:118
Mdouble getInteractionDistance() const
returns the largest separation distance at which adhesive short-range forces can occur.
Definition: BaseSpecies.h:146
void setHandler(SpeciesHandler *handler)
Sets the pointer to the handler to which this species belongs.
Definition: BaseSpecies.cc:91
void setRotation(bool rotation)
Sets whether particle rotation is enabled or disabled.
Definition: DPMBase.h:563
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created.
Definition: DPMBase.h:1437
void computeAllMasses(unsigned int indSpecies)
Computes the mass for all BaseParticle of the given species in this ParticleHandler.
Definition: ParticleHandler.cc:1215
virtual BaseSpecies * copyMixed() const =0
Creates a new MixedSpecies with the same force properties as the Species from which it is called....
void setMaxInteractionDistance(Mdouble interactionDistance=0)
Sets maxInteractionDistance_.
Definition: ParticleSpecies.cc:221
bool useAngularDOFs()
Check if angular DOF have to be used.
Definition: SpeciesHandler.cc:955

References BaseHandler< T >::addObject(), ParticleHandler::computeAllMasses(), ParticleSpecies::copyMixed(), BaseHandler< ParticleSpecies >::getDPMBase(), BaseObject::getIndex(), BaseSpecies::getInteractionDistance(), BaseHandler< ParticleSpecies >::getNumberOfObjects(), BaseHandler< ParticleSpecies >::getObject(), mixedObjects_, DPMBase::particleHandler, BaseSpecies::setHandler(), ParticleSpecies::setMaxInteractionDistance(), DPMBase::setRotation(), and useAngularDOFs().

Referenced by GranularCollapse::GranularCollapse(), main(), MD_demo::MD_demo(), ParticleParticleInteraction::ParticleParticleInteraction(), ParticleParticleInteractionWithPlasticForces::ParticleParticleInteractionWithPlasticForces(), ParticleWallInteraction::ParticleWallInteraction(), readAndAddObject(), DPMBase::readParAndIniFiles(), BoundingRadiusTester::test(), InertiaTensorTester::test(), VolumeTest::test(), ShapeGradientHessianTester::testCushion(), ShapeGradientHessianTester::testEllipsoid(), ShapeGradientHessianTester::testRoundedBeam(), and ShapeGradientHessianTester::testSphere().

◆ clear()

void SpeciesHandler::clear ( )
inlineoverridevirtual

Empties the whole BaseHandler by removing all Objects and setting all other variables to 0.

Delete all objects stored in objects_ and set the maximum number of objects that have been in this container to 0, and set the Id of the next object that will be added to 0.

Reimplemented from BaseHandler< ParticleSpecies >.

55  {
57  mixedObjects_.clear();
58  }
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0.
Definition: BaseHandler.h:528

References BaseHandler< T >::clear(), and mixedObjects_.

Referenced by operator=(), DPMBase::readParAndIniFiles(), DrumRot::setupInitialConditions(), RotatingDrum::setupInitialConditions(), BaseCluster::setupInitialConditions(), SpeciesHandler(), and ~SpeciesHandler().

◆ getMixedId()

unsigned int SpeciesHandler::getMixedId ( unsigned int  id1,
unsigned int  id2 
) const

Gets the Id of the behaviour between two given species.

Parameters
[in]id1Id of the first species.
[in]id2Id of the second species.
Returns
An unsigned integer that denotes the Id of the mixed species.

The numbering of the mixed species is 0-1, 0-2, 1-2, 0-3, 1-3, 2-3, 0-4, 1-4, 2-4, 3-4, ..., where each pair of numbers a and b denotes the mixed species between ParticleSpecies a and b. Thus, first compute which id has a higher value, the id of the mixed species is then given by (maxId*(maxId-1))/2 + minId.

815 {
816  unsigned int maxId = std::max(id1, id2);
817  return (maxId * (maxId - 1)) / 2 + std::min(id1, id2);
818 }

Referenced by getMixedObject(), removeObject(), and updateMixedObjects().

◆ getMixedObject() [1/2]

template<typename U >
std::enable_if<!std::is_pointer<typename U::MixedSpeciesType>::value, typename U::MixedSpeciesType*>::type SpeciesHandler::getMixedObject ( const U *  S,
const U *  T 
)
inline
75  {
76  return static_cast<typename U::MixedSpeciesType*>(getMixedObject(S->getIndex(), T->getIndex()));
77  }
std::enable_if<!std::is_pointer< typename U::MixedSpeciesType >::value, typename U::MixedSpeciesType * >::type getMixedObject(const U *S, const U *T)
Definition: SpeciesHandler.h:74

Referenced by InteractionHandler::addInteraction(), ConstantMassFlowMaserBoundary::addParticleToMaser(), SubcriticalMaserBoundary::addParticleToMaser(), ChuteWithPeriodicInflow::computeInternalForces(), AngleOfRepose::createBaseSpecies(), SilbertPeriodic::createBaseSpecies(), NurbsWall::getDistanceAndNormal(), Screw::getDistanceAndNormal(), IntersectionOfWalls::getDistanceAndNormal(), InteractionHandler::getInteraction(), SuperQuadricParticle::getInteractionRadius(), ParticleSpecies::getMixedSpecies(), MembraneDemo::initializeSpecies(), MembraneSelfTest::initializeSpecies(), main(), protectiveWall::protectiveWall(), MercuryOS::setMaterialProperties(), ParticleSpecies::setMaxInteractionDistance(), Calibration::setSpecies(), Material::setSpecies(), MercuryLogo::setupInitialConditions(), RotatingDrumWet::setupInitialConditions(), Binary::setupInitialConditions(), my_problem::setupInitialConditions(), Chutebelt::setupInitialConditions(), ConstantMassFlowMaserBoundaryMixedSpeciesSelfTest::setupInitialConditions(), DPM::setupInitialConditions(), ContactDetectionIntersectionOfWallsTest::setupInitialConditions(), DrumRot::setupInitialConditions(), RotatingDrum::setupInitialConditions(), SpeciesTest::setupInitialConditions(), WallSpecies::setupInitialConditions(), T_protectiveWall::T_protectiveWall(), and useAngularDOFs().

◆ getMixedObject() [2/2]

BaseSpecies * SpeciesHandler::getMixedObject ( unsigned int  id1,
unsigned int  id2 
)

Gets the mixed object that is constructed from two given species.

Parameters
[in]id1Id of the first BaseSpecies.
[in]id2Id of the second BaseSpecies.
Returns
A pointer to an object that is a MixedSpecies of both input Species.
Todo:
This function should probably be made private. The user should use the function SpeciesHandler::getMixedObject(const U* S, const U* T), which deals with pointers.
836 {
837  if (id1 == id2)
838  {
839  return getObject(id1);
840  }
841  else
842  {
843  const unsigned int mixedId = getMixedId(id1, id2);
844  if (mixedId>=mixedObjects_.size())
845  {
846  logger(WARN,
847  "In: Object* SpeciesHandler::getMixedObject(const unsigned int id) const. No Object exist with index %, number of objects is %",
848  std::max(id1, id2), getNumberOfObjects());
849  return nullptr;
850  }
851  else
852  {
853  return mixedObjects_[mixedId];
854  }
855  }
856 }
@ WARN
unsigned int getMixedId(unsigned int id1, unsigned int id2) const
Gets the Id of the behaviour between two given species.
Definition: SpeciesHandler.cc:814

References getMixedId(), BaseHandler< ParticleSpecies >::getNumberOfObjects(), BaseHandler< ParticleSpecies >::getObject(), logger, mixedObjects_, and WARN.

◆ getMixedObjects()

const std::vector< BaseSpecies * > & SpeciesHandler::getMixedObjects ( ) const

Returns a pointer to the vector of all mixed objects.

Returns
A reference to the vector of pointers of all the mixedObjects.
824 {
825  return mixedObjects_;
826 }

References mixedObjects_.

Referenced by BaseSpecies::setInteractionDistance().

◆ getName()

std::string SpeciesHandler::getName ( ) const
overridevirtual

Returns the name of the handler, namely the string "SpeciesHandler".

Returns
The string "SpeciesHandler"

Implements BaseHandler< ParticleSpecies >.

948 {
949  return "SpeciesHandler";
950 }

◆ operator=()

SpeciesHandler & SpeciesHandler::operator= ( const SpeciesHandler rhs)

Assignment operator that copies all species and the pointer to the DPMBase from the given SpeciesHandler.

Parameters
[in]rhsThe BoundaryHandler on the right hand side of the assignment.
Returns
The SpeciesHandler that is a copy of the input SpeciesHandler rhs.

This is not a copy assignment operator! It copies only all BaseSpecies and MixedSpecies and copies the pointer to the DPMBase. It sets all other data members to 0 or nullptr.

116 {
117  if (this != &rhs)
118  {
119  clear();
121  for (BaseSpecies* mixSpec : mixedObjects_)
122  {
123  delete mixSpec;
124  }
125  mixedObjects_.clear();
126  for (BaseSpecies* mixSpec : rhs.mixedObjects_)
127  {
128  mixedObjects_.push_back(mixSpec->copy());
129  mixedObjects_.back()->setHandler(this);
130  }
131  }
132 
133  logger(DEBUG, "SpeciesHandler SpeciesHandler::operator =(const SpeciesHandler& rhs)");
134  return *this;
135 }

References clear(), BaseSpecies::copy(), BaseHandler< ParticleSpecies >::copyContentsFromOtherHandler(), DEBUG, logger, and mixedObjects_.

◆ readAndAddObject()

void SpeciesHandler::readAndAddObject ( std::istream &  is)
overridevirtual

Reads Species data into the SpeciesHandler from restart file.

Parameters
[in]isThe input stream from which the information is read.

First determine the type of the object we want to read, then read the actual object. After that, clear the mixed objects and read the mixed objects.

Todo:
TW why does deleting these objects create a segmentation fault How do you create the segmentation fault?
Author
weinhartt
Todo:
IFCD how does the numbering of mixedSpecies_ work? the numbering of mixed species is 01, 02, 12, 03, 13, 23, 04, 14, 24, 34, i.e. if you add the n-th ParticleSpecies, then you have to add n-1 MixedSpecies. So here I remove the last n-1 MixedSpecies and add n-1 new ones.
Author
weinhartt

Implements BaseHandler< ParticleSpecies >.

162 {
163  std::string type;
164  is >> type;
165  logger(DEBUG, "SpeciesHandler::readAndAddObject(is): reading type %.", type);
166  if (type == "LinearViscoelasticSpecies")
167  {
169  is >> species;
170  copyAndAddObject(species);
171  }
172  else if (type == "SPHSpecies")
173  {
174  SPHSpecies species;
175  is >> species;
176  copyAndAddObject(species);
177  }
178  else if (type == "LinearPlasticViscoelasticSpecies")
179  {
181  is >> species;
182  copyAndAddObject(species);
183  }
184  else if (type == "SinterSpecies")
185  {
186  SinterSpecies species;
187  is >> species;
188  copyAndAddObject(species);
189  }
190  else if (type == "SinterReversibleAdhesiveSpecies")
191  {
193  is >> species;
194  copyAndAddObject(species);
195  }
196  else if (type == "SinterFrictionReversibleAdhesiveSpecies")
197  {
199  is >> species;
200  copyAndAddObject(species);
201  }
202  else if (type == "SinterFrictionSpecies")
203  {
204  SinterFrictionSpecies species;
205  is >> species;
206  copyAndAddObject(species);
207  }
208  else if (type == "HertzianSinterSpecies")
209  {
210  HertzianSinterSpecies species;
211  is >> species;
212  copyAndAddObject(species);
213  }
214  else if (type == "HertzianSinterFrictionSpecies")
215  {
217  is >> species;
218  copyAndAddObject(species);
219  }
220  else if (type == "HertzianSinterSlidingFrictionSpecies")
221  {
223  is >> species;
224  copyAndAddObject(species);
225  }
226  else if (type == "LinearViscoelasticSlidingFrictionSpecies")
227  {
229  is >> species;
230  copyAndAddObject(species);
231  }
232  else if (type == "LinearPlasticViscoelasticSlidingFrictionSpecies")
233  {
235  is >> species;
236  copyAndAddObject(species);
237  }
238  else if (type == "LinearViscoelasticFrictionSpecies")
239  {
241  is >> species;
242  copyAndAddObject(species);
243  }
244  else if (type == "LinearPlasticViscoelasticFrictionSpecies")
245  {
247  is >> species;
248  copyAndAddObject(species);
249  }
250  else if (type == "LinearViscoelasticIrreversibleAdhesiveSpecies")
251  {
253  is >> species;
254  copyAndAddObject(species);
255  }
256  else if (type == "LinearViscoelasticBondedSpecies")
257  {
259  is >> species;
260  copyAndAddObject(species);
261  }
262  else if (type == "LinearPlasticViscoelasticIrreversibleAdhesiveSpecies")
263  {
265  is >> species;
266  copyAndAddObject(species);
267  }
268  else if (type == "LinearViscoelasticSlidingFrictionIrreversibleAdhesiveSpecies")
269  {
271  is >> species;
272  copyAndAddObject(species);
273  }
274  else if (type == "LinearPlasticViscoelasticSlidingFrictionIrreversibleAdhesiveSpecies")
275  {
277  is >> species;
278  copyAndAddObject(species);
279  }
280  else if (type == "LinearViscoelasticFrictionIrreversibleAdhesiveSpecies")
281  {
283  is >> species;
284  copyAndAddObject(species);
285  }
286  else if (type == "LinearPlasticViscoelasticFrictionIrreversibleAdhesiveSpecies")
287  {
289  is >> species;
290  copyAndAddObject(species);
291  }
292  else if (type == "LinearViscoelasticReversibleAdhesiveSpecies")
293  {
295  is >> species;
296  copyAndAddObject(species);
297  }
298  else if (type == "LinearPlasticViscoelasticReversibleAdhesiveSpecies")
299  {
301  is >> species;
302  copyAndAddObject(species);
303  }
304  else if (type == "LinearViscoelasticSlidingFrictionReversibleAdhesiveSpecies")
305  {
307  is >> species;
308  copyAndAddObject(species);
309  }
310  else if (type == "LinearPlasticViscoelasticSlidingFrictionReversibleAdhesiveSpecies")
311  {
313  is >> species;
314  copyAndAddObject(species);
315  }
316  else if (type == "LinearViscoelasticFrictionReversibleAdhesiveSpecies")
317  {
319  is >> species;
320  copyAndAddObject(species);
321  }
322  else if (type == "LinearPlasticViscoelasticFrictionReversibleAdhesiveSpecies")
323  {
325  is >> species;
326  copyAndAddObject(species);
327  }
328  else if (type == "LinearViscoelasticFrictionLiquidBridgeWilletSpecies")
329  {
331  is >> species;
332  copyAndAddObject(species);
333  }
334  else if (type == "LinearViscoelasticFrictionLiquidMigrationWilletSpecies")
335  {
337  is >> species;
338  copyAndAddObject(species);
339  }
340  else if (type == "LinearPlasticViscoelasticFrictionLiquidMigrationWilletSpecies")
341  {
343  is >> species;
344  copyAndAddObject(species);
345  }
346  else if (type == "LinearViscoelasticSlidingFrictionLiquidMigrationLSSpecies")
347  {
349  is >> species;
350  copyAndAddObject(species);
351  }
352  else if (type == "LinearViscoelasticFrictionLiquidMigrationLSSpecies")
353  {
355  is >> species;
356  copyAndAddObject(species);
357  }
358  else if (type == "LinearPlasticViscoelasticSlidingFrictionLiquidMigrationWilletSpecies")
359  {
361  is >> species;
362  copyAndAddObject(species);
363  }
364  else if (type == "HertzianViscoelasticMindlinSpecies")
365  {
367  is >> species;
368  copyAndAddObject(species);
369  }
370  else if (type == "HertzianViscoelasticMindlinRollingTorsionSpecies" ||
371  type == "HertzianViscoelasticFrictionSpecies")
372  {
374  is >> species;
375  copyAndAddObject(species);
376  }
377  else if (type == "HertzianViscoelasticFrictionChargedBondedSpecies")
378  {
380  is >> species;
381  copyAndAddObject(species);
382  }
383  else if (type == "HertzianBSHPViscoelasticMindlinSpecies")
384  {
386  is >> species;
387  copyAndAddObject(species);
388  }
389  else if (type == "HertzianBSHPViscoelasticSpecies")
390  {
392  is >> species;
393  copyAndAddObject(species);
394  }
395  else if (type == "LinearViscoelasticFrictionChargedBondedSpecies")
396  {
398  is >> species;
399  copyAndAddObject(species);
400  }
401  else if (type == "ThermalSinterSlidingFrictionSpecies")
402  {
404  is >> species;
405  copyAndAddObject(species);
406  }
407  else if (type == "ThermalSinterFrictionSpecies")
408  {
410  is >> species;
411  copyAndAddObject(species);
412  }
413  else if (type == "LinearPlasticViscoelasticFrictionLiquidBridgeWilletSpecies")
414  {
416  is >> species;
417  copyAndAddObject(species);
418  }
419  else if (type == "ThermalSinterLinFrictionReversibleAdhesiveSpecies")
420  {
422  is >> species;
423  copyAndAddObject(species);
424  }
425  else if (type == "k") //for backwards compatibility
426  {
428  }
429  else
430  {
431  logger(WARN,
432  "Species type % not understood in restart file: You need to add this species to SpeciesHandler::readObject.",
433  type);
434  std::stringstream line;
437  }
438 
439  //remove the default mixed species
440  for (unsigned int i = 0; i + 1 < getNumberOfObjects(); i++)
441  {
448  delete mixedObjects_.back();
449  mixedObjects_.pop_back();
450  }
451 
452  //Read the mixed species.
453  for (unsigned int i = 0; i + 1 < getNumberOfObjects(); i++)
454  {
455  is >> type;
456  if (type == "LinearViscoelasticMixedSpecies")
457  {
459  is >> species;
460  mixedObjects_.push_back(species.copy());
461  }
462  else if (type == "LinearPlasticViscoelasticMixedSpecies")
463  {
465  is >> species;
466  mixedObjects_.push_back(species.copy());
467  }
468  else if (type == "SinterMixedSpecies")
469  {
470  SinterMixedSpecies species;
471  is >> species;
472  mixedObjects_.push_back(species.copy());
473  }
474  else if (type == "SinterReversibleAdhesiveMixedSpecies")
475  {
477  is >> species;
478  mixedObjects_.push_back(species.copy());
479  }
480  else if (type == "SinterFrictionReversibleAdhesiveMixedSpecies")
481  {
483  is >> species;
484  mixedObjects_.push_back(species.copy());
485  }
486  else if (type == "SinterFrictionMixedSpecies")
487  {
489  is >> species;
490  mixedObjects_.push_back(species.copy());
491  }
492  else if (type == "HertzianSinterMixedSpecies")
493  {
495  is >> species;
496  mixedObjects_.push_back(species.copy());
497  }
498  else if (type == "HertzianSinterFrictionMixedSpecies")
499  {
501  is >> species;
502  mixedObjects_.push_back(species.copy());
503  }
504  else if (type == "HertzianSinterSlidingFrictionMixedSpecies")
505  {
507  is >> species;
508  mixedObjects_.push_back(species.copy());
509  }
510  else if (type == "LinearViscoelasticSlidingFrictionMixedSpecies")
511  {
513  is >> species;
514  mixedObjects_.push_back(species.copy());
515  }
516  else if (type == "LinearPlasticViscoelasticSlidingFrictionMixedSpecies")
517  {
519  is >> species;
520  mixedObjects_.push_back(species.copy());
521  }
522  else if (type == "LinearViscoelasticFrictionMixedSpecies")
523  {
525  is >> species;
526  mixedObjects_.push_back(species.copy());
527  }
528  else if (type == "LinearPlasticViscoelasticFrictionMixedSpecies")
529  {
531  is >> species;
532  mixedObjects_.push_back(species.copy());
533  }
534  else if (type == "LinearViscoelasticIrreversibleAdhesiveMixedSpecies")
535  {
537  is >> species;
538  mixedObjects_.push_back(species.copy());
539  }
540  else if (type == "LinearViscoelasticBondedMixedSpecies")
541  {
543  is >> species;
544  mixedObjects_.push_back(species.copy());
545  }
546  else if (type == "LinearPlasticViscoelasticIrreversibleAdhesiveMixedSpecies")
547  {
549  is >> species;
550  mixedObjects_.push_back(species.copy());
551  }
552  else if (type == "LinearViscoelasticSlidingFrictionIrreversibleAdhesiveMixedSpecies")
553  {
555  is >> species;
556  mixedObjects_.push_back(species.copy());
557  }
558  else if (type == "LinearPlasticViscoelasticSlidingFrictionIrreversibleAdhesiveMixedSpecies")
559  {
561  is >> species;
562  mixedObjects_.push_back(species.copy());
563  }
564  else if (type == "LinearViscoelasticFrictionIrreversibleAdhesiveMixedSpecies")
565  {
567  is >> species;
568  mixedObjects_.push_back(species.copy());
569  }
570  else if (type == "LinearPlasticViscoelasticFrictionIrreversibleAdhesiveMixedSpecies")
571  {
573  is >> species;
574  mixedObjects_.push_back(species.copy());
575  }
576  else if (type == "LinearPlasticViscoelasticSlidingFrictionLiquidMigrationWilletMixedSpecies")
577  {
579  is >> species;
580  mixedObjects_.push_back(species.copy());
581  }
582  else if (type == "LinearPlasticViscoelasticFrictionLiquidBridgeWilletMixedSpecies")
583  {
585  is >> species;
586  mixedObjects_.push_back(species.copy());
587  }
588  else if (type == "LinearViscoelasticReversibleAdhesiveMixedSpecies")
589  {
591  is >> species;
592  mixedObjects_.push_back(species.copy());
593  }
594  else if (type == "LinearPlasticViscoelasticReversibleAdhesiveMixedSpecies")
595  {
597  is >> species;
598  mixedObjects_.push_back(species.copy());
599  }
600  else if (type == "LinearViscoelasticSlidingFrictionReversibleAdhesiveMixedSpecies")
601  {
603  is >> species;
604  mixedObjects_.push_back(species.copy());
605  }
606  else if (type == "LinearPlasticViscoelasticSlidingFrictionReversibleAdhesiveMixedSpecies")
607  {
609  is >> species;
610  mixedObjects_.push_back(species.copy());
611  }
612  else if (type == "LinearViscoelasticFrictionReversibleAdhesiveMixedSpecies")
613  {
615  is >> species;
616  mixedObjects_.push_back(species.copy());
617  }
618  else if (type == "LinearPlasticViscoelasticFrictionReversibleAdhesiveMixedSpecies")
619  {
621  is >> species;
622  mixedObjects_.push_back(species.copy());
623  }
624  else if (type == "LinearViscoelasticFrictionLiquidBridgeWilletMixedSpecies")
625  {
627  is >> species;
628  mixedObjects_.push_back(species.copy());
629  }
630  else if (type == "LinearViscoelasticFrictionLiquidMigrationWilletMixedSpecies")
631  {
633  is >> species;
634  mixedObjects_.push_back(species.copy());
635  }
636  else if (type == "LinearPlasticViscoelasticFrictionLiquidMigrationWilletMixedSpecies")
637  {
639  is >> species;
640  mixedObjects_.push_back(species.copy());
641  }
642  else if (type == "LinearViscoelasticSlidingFrictionLiquidMigrationLSMixedSpecies")
643  {
645  is >> species;
646  mixedObjects_.push_back(species.copy());
647  }
648  else if (type == "LinearViscoelasticFrictionLiquidMigrationLSMixedSpecies")
649  {
651  is >> species;
652  mixedObjects_.push_back(species.copy());
653  }
654  else if (type == "HertzianViscoelasticMindlinMixedSpecies")
655  {
657  is >> species;
658  mixedObjects_.push_back(species.copy());
659  }
660  else if (type == "HertzianViscoelasticMindlinRollingTorsionMixedSpecies" ||
661  type == "HertzianViscoelasticFrictionMixedSpecies")
662  {
664  is >> species;
665  mixedObjects_.push_back(species.copy());
666  }
667  else if (type == "HertzianViscoelasticFrictionChargedBondedMixedSpecies")
668  {
670  is >> species;
671  mixedObjects_.push_back(species.copy());
672  }
673  else if (type == "HertzianBSHPViscoelasticMindlinMixedSpecies")
674  {
676  is >> species;
677  mixedObjects_.push_back(species.copy());
678  }
679  else if (type == "HertzianBSHPViscoelasticMixedSpecies")
680  {
682  is >> species;
683  mixedObjects_.push_back(species.copy());
684  }
685  else if (type == "LinearViscoelasticFrictionChargedBondedMixedSpecies")
686  {
688  is >> species;
689  mixedObjects_.push_back(species.copy());
690  }
691  else if (type == "ThermalSinterSlidingFrictionMixedSpecies")
692  {
694  is >> species;
695  mixedObjects_.push_back(species.copy());
696  }
697  else if (type == "ThermalSinterFrictionMixedSpecies")
698  {
700  is >> species;
701  mixedObjects_.push_back(species.copy());
702  }
703  else if (type == "ThermalSinterLinFrictionReversibleAdhesiveMixedSpecies")
704  {
706  is >> species;
707  mixedObjects_.push_back(species.copy());
708  }
709  else if (type == "ThermalSinterFrictionMixedSpecies")
710  {
712  is >> species;
713  mixedObjects_.push_back(species.copy());
714  }
715  else
716  {
717  logger(WARN,
718  "Species type % not understood in restart file: You need to add this species to SpeciesHandler::readMixedObject.",
719  type);
720  std::stringstream line;
723  mixedObjects_.push_back(species.copy());
724  }
725  }
726 }
Species< LinearViscoelasticNormalSpecies > LinearViscoelasticSpecies
Definition: LinearViscoelasticSpecies.h:33
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddObject(const U &object)
Creates a copy of a Object and adds it to the BaseHandler.
Definition: BaseHandler.h:379
FrictionSpecies contains the parameters used to describe sliding, rolling and torsional friction.
Definition: FrictionSpecies.h:39
Contains contact force properties for contacts between particles with two different species.
Definition: MixedSpecies.h:43
MixedSpecies< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies > * copy() const final
Creates a deep copy of the MixedSpecies from which it is called.
Definition: MixedSpecies.h:145
ReversibleAdhesiveSpecies contains the parameters used to describe a linear reversible short-range fo...
Definition: ReversibleAdhesiveSpecies.h:38
SlidingFrictionSpecies contains the parameters used to describe sliding friction.
Definition: SlidingFrictionSpecies.h:38
void addObject(ParticleSpecies *S) override
Adds a new ParticleSpecies to the SpeciesHandler.
Definition: SpeciesHandler.cc:890
ParticleSpecies * readOldObject(std::istream &is)
Reads ParticleSpecies into the SpeciesHandler from old-style restart data.
Definition: SpeciesHandler.cc:736
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
void getLineFromStringStream(std::istream &in, std::stringstream &out)
Reads a line from one stringstream into another, and prepares the latter for reading in.
Definition: StringHelpers.cc:62

References addObject(), MixedSpecies< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >::copy(), BaseHandler< ParticleSpecies >::copyAndAddObject(), DEBUG, helpers::getLineFromStringStream(), BaseHandler< ParticleSpecies >::getNumberOfObjects(), constants::i, logger, mixedObjects_, readOldObject(), and WARN.

◆ readOldObject()

ParticleSpecies * SpeciesHandler::readOldObject ( std::istream &  is)

Reads ParticleSpecies into the SpeciesHandler from old-style restart data.

Parameters
[in]isThe input stream from which the information is read.
Returns
A pointer to the ParticleSpecies that has just been read.

To read the old object, we first make a stringstream of the line that describes this ParticleSpecies. After that, we read the properties one by one, first the stiffness and after that the other properties. We stop when we either reach the end of the file(eof) or if a string is not recognized as a property.

737 {
738  //read in next line
739  std::stringstream line;
741 
742  //read each property
743  std::string property;
744  unsigned int particleDimension = 0;
745  Mdouble density = 0.0, stiffness = 0.0, dissipation = 0.0, slidingFrictionCoefficient = 0.0, slidingFrictionCoefficientStatic = 0.0, slidingStiffness = 0.0, slidingDissipation = 0.0;
746  line >> stiffness;
747  while (true)
748  {
749  line >> property;
750  if (property == "disp")
751  line >> dissipation;
752  else if (property == "rho")
753  line >> density;
754  else if (property == "kt")
755  line >> slidingStiffness;
756  else if (property == "dispt")
757  line >> slidingDissipation;
758  else if (property == "mu")
759  line >> slidingFrictionCoefficient;
760  else if (property == "mus")
761  line >> slidingFrictionCoefficientStatic;
762  else if (property == "dim_particle")
763  {
764  line >> particleDimension;
765  getDPMBase()->setParticleDimensions(particleDimension);
766  }
767  else if (property == "(mixed)")
768  {
769  density = 0;
770  }
771  else
772  {
773  logger(WARN, "Warning: % is not a species property", property);
774  break;
775  }
776  if (line.eof())
777  break;
778  }
779 
780  //create the correct species
781  if (slidingFrictionCoefficient == 0.0)
782  {
784  species->setDensity(density);
785  species->setStiffness(stiffness);
786  species->setDissipation(dissipation);
787  return species;
788  }
789  else
790  {
792  species->setDensity(density);
793  species->setStiffness(stiffness);
794  species->setDissipation(dissipation);
795  species->setSlidingStiffness(slidingStiffness);
796  species->setSlidingDissipation(slidingDissipation);
797  species->setSlidingFrictionCoefficient(slidingFrictionCoefficient);
798  if (slidingFrictionCoefficientStatic == 0.0)
799  slidingFrictionCoefficientStatic = slidingFrictionCoefficient;
800  species->setSlidingFrictionCoefficientStatic(slidingFrictionCoefficientStatic);
801  return species;
802  }
803 }
double Mdouble
Definition: GeneralDefine.h:34
Species< LinearViscoelasticNormalSpecies, SlidingFrictionSpecies > LinearViscoelasticSlidingFrictionSpecies
Definition: LinearViscoelasticSlidingFrictionSpecies.h:34
void setParticleDimensions(unsigned int particleDimensions)
Sets the particle dimensionality.
Definition: DPMBase.cc:1448
void setDissipation(Mdouble dissipation)
Allows the normal dissipation to be changed.
Definition: LinearViscoelasticNormalSpecies.cc:117
void setStiffness(Mdouble new_k)
Allows the spring constant to be changed.
Definition: LinearViscoelasticNormalSpecies.cc:93
void setDensity(Mdouble density)
Definition: ParticleSpecies.cc:108

References BaseHandler< ParticleSpecies >::getDPMBase(), helpers::getLineFromStringStream(), logger, ParticleSpecies::setDensity(), LinearViscoelasticNormalSpecies::setDissipation(), DPMBase::setParticleDimensions(), LinearViscoelasticNormalSpecies::setStiffness(), and WARN.

Referenced by readAndAddObject().

◆ removeObject()

void SpeciesHandler::removeObject ( unsigned int  index)
overridevirtual

Remove the ParticleSpecies with given id.

Parameters
[in]indexThe index of which ParticleSpecies has to be removed from this ParticleHandler.

The ParticleSpecies with index is removed and the last ParticleSpecies in the vector is moved to its position. It also removes all mixed species for this ParticleSpecies.

Reimplemented from BaseHandler< ParticleSpecies >.

916 {
918  for (unsigned int index2 = 0; index2 < getNumberOfObjects(); ++index2)
919  {
920  mixedObjects_.erase(mixedObjects_.begin() + getMixedId(index, index2));
921  }
923 }
virtual void removeObject(unsigned const int index)
Removes an Object from the BaseHandler.
Definition: BaseHandler.h:472

References BaseHandler< ParticleSpecies >::getDPMBase(), getMixedId(), BaseHandler< ParticleSpecies >::getNumberOfObjects(), mixedObjects_, BaseHandler< T >::removeObject(), DPMBase::setRotation(), and useAngularDOFs().

Referenced by CurvyChute::recreateBottom().

◆ updateMixedObjects()

void SpeciesHandler::updateMixedObjects ( )

Updates the mixed species.

Updates mixed species by calling the function mixAll() with the corresponding original species.

See also
mixAll(Object1, Object2) which creates sensible default values for mixed species based on the two species. Remember mixedSpecies properties can be set independently if required.

This may (should) be called, if a value is changed in the original species and the mixed species need to be aware of this change and update by the default rule. Note this only make sense if you are using the default mixed species and not a custom implementation.

869 {
870  for (unsigned int index1 = 0; index1 < getNumberOfObjects(); ++index1)
871  {
872  for (unsigned int index2 = index1+1; index2 < getNumberOfObjects(); ++index2)
873  {
874  mixedObjects_[getMixedId(index1, index2)]->mixAll(getObject(index1), getObject(index2));
875  }
876  }
877 }

References getMixedId(), BaseHandler< ParticleSpecies >::getNumberOfObjects(), BaseHandler< ParticleSpecies >::getObject(), and mixedObjects_.

◆ useAngularDOFs()

bool SpeciesHandler::useAngularDOFs ( )

Check if angular DOF have to be used.

Returns
The boolean which says whether or not AnuglarDOFs must be used in this handler.
956 {
957  for (unsigned int i = 0; i < getSize(); i++)
958  {
959  if (getObject(i)->getUseAngularDOFs())
960  return true;
961  for (unsigned int j = 0; j + 1 < i; j++)
962  {
963  if (getMixedObject(i, j)->getUseAngularDOFs())
964  return true;
965  }
966  }
967  return false;
968 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
virtual bool getUseAngularDOFs() const =0
Returns true if torques (i.e. angular degrees of freedom) have to be calculated.

References getMixedObject(), BaseHandler< ParticleSpecies >::getObject(), BaseHandler< ParticleSpecies >::getSize(), BaseSpecies::getUseAngularDOFs(), and constants::i.

Referenced by addObject(), and removeObject().

◆ write()

void SpeciesHandler::write ( std::ostream &  os) const
virtual

Write all the species and mixed species to an output stream.

First write "Species" and the amount of species in this handler, then write all ParticleSpecies and MixedSpecies.

930 {
931  os << "Species " << getNumberOfObjects() << "\n";
932  unsigned idMixed = 0;
933  for (const ParticleSpecies* species : objects_)
934  {
935  os << *species << "\n";
936  for (unsigned int id2 = 0; id2 < species->getIndex(); id2++)
937  {
938  os << *mixedObjects_[idMixed] << "\n";
939  idMixed++;
940  }
941  }
942 }
std::vector< ParticleSpecies * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
Definition: ParticleSpecies.h:37

References BaseHandler< ParticleSpecies >::getNumberOfObjects(), mixedObjects_, and BaseHandler< ParticleSpecies >::objects_.

Referenced by DPMBase::write().

Member Data Documentation

◆ mixedObjects_

std::vector<BaseSpecies*> SpeciesHandler::mixedObjects_
private

The documentation for this class was generated from the following files: