revision: v0.14
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...
 
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 std::string getName () const=0
 Gets the name of this handler. 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.

79 {
80  logger(DEBUG, "SpeciesHandler::SpeciesHandler() finished");
81 }

References FATAL, 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.

90 {
91  clear();
92  setDPMBase(other.getDPMBase());
94  for (BaseSpecies* mixSpec : other.mixedObjects_)
95  {
96  mixedObjects_.push_back(mixSpec->copy());
97  mixedObjects_.back()->setHandler(this);
98  }
99  logger(DEBUG, "SpeciesHandler::SpeciesHandler(const SpeciesHandler &other) finished");
100 }

References clear(), BaseSpecies::copy(), BaseHandler< ParticleSpecies >::copyContentsFromOtherHandler(), FATAL, 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.
136 {
137  clear(); //this deletes everything that comes from the BaseHandler.
138  /*for (BaseSpecies* o : mixedObjects_)
139  {
140  delete o;
141  }*/
142  for (BaseSpecies* mixSpec : mixedObjects_)
143  {
144  delete mixSpec;
145  }
146  mixedObjects_.clear();
147  logger(DEBUG, "SpeciesHandler::~SpeciesHandler() finished");
148 }

References clear(), FATAL, 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!
798 {
800  //logger(INFO, "Part / Mix: % / %", objects_.size(), mixedObjects_.size());
802  S->setHandler(this);
803  for (unsigned int id = 0; id + 1 < getNumberOfObjects(); ++id)
804  {
805  mixedObjects_.push_back(S->copyMixed());
806  mixedObjects_.back()->setIndex(id);
807  mixedObjects_.back()->setId(getNumberOfObjects() - 1);
808  mixedObjects_.back()->mixAll(S, getObject(id));
809  }
813 }

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  }

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.

743 {
744  unsigned int maxId = std::max(id1, id2);
745  return (maxId * (maxId - 1)) / 2 + std::min(id1, id2);
746 }

Referenced by getMixedObject(), and removeObject().

◆ getMixedObject() [1/2]

◆ 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.
764 {
765  if (id1 == id2)
766  {
767  return getObject(id1);
768  }
769  else
770  {
771  const unsigned int mixedId = getMixedId(id1, id2);
772  if (mixedId>=mixedObjects_.size())
773  {
774  logger(WARN,
775  "In: Object* SpeciesHandler::getMixedObject(const unsigned int id) const. No Object exist with index %, number of objects is %",
776  std::max(id1, id2), getNumberOfObjects());
777  return nullptr;
778  }
779  else
780  {
781  return mixedObjects_[mixedId];
782  }
783  }
784 }

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.
752 {
753  return mixedObjects_;
754 }

References mixedObjects_.

Referenced by BaseSpecies::setInteractionDistance().

◆ getName()

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

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

Returns
The string "SpeciesHandler"
855 {
856  return "SpeciesHandler";
857 }

◆ 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.

110 {
111  if (this != &rhs)
112  {
113  clear();
115  for (BaseSpecies* mixSpec : mixedObjects_)
116  {
117  delete mixSpec;
118  }
119  mixedObjects_.clear();
120  for (BaseSpecies* mixSpec : rhs.mixedObjects_)
121  {
122  mixedObjects_.push_back(mixSpec->copy());
123  mixedObjects_.back()->setHandler(this);
124  }
125  }
126 
127  logger(DEBUG, "SpeciesHandler SpeciesHandler::operator =(const SpeciesHandler& rhs)");
128  return *this;
129 }

References clear(), BaseSpecies::copy(), BaseHandler< ParticleSpecies >::copyContentsFromOtherHandler(), FATAL, 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 >.

156 {
157  std::string type;
158  is >> type;
159  logger(DEBUG, "SpeciesHandler::readAndAddObject(is): reading type %.", type);
160  if (type == "LinearViscoelasticSpecies")
161  {
163  is >> species;
164  copyAndAddObject(species);
165  }
166  else if (type == "LinearPlasticViscoelasticSpecies")
167  {
169  is >> species;
170  copyAndAddObject(species);
171  }
172  else if (type == "SinterSpecies")
173  {
174  SinterSpecies species;
175  is >> species;
176  copyAndAddObject(species);
177  }
178  else if (type == "SinterReversibleAdhesiveSpecies")
179  {
181  is >> species;
182  copyAndAddObject(species);
183  }
184  else if (type == "SinterFrictionReversibleAdhesiveSpecies")
185  {
187  is >> species;
188  copyAndAddObject(species);
189  }
190  else if (type == "SinterFrictionSpecies")
191  {
192  SinterFrictionSpecies species;
193  is >> species;
194  copyAndAddObject(species);
195  }
196  else if (type == "HertzianSinterSpecies")
197  {
198  HertzianSinterSpecies species;
199  is >> species;
200  copyAndAddObject(species);
201  }
202  else if (type == "HertzianSinterFrictionSpecies")
203  {
205  is >> species;
206  copyAndAddObject(species);
207  }
208  else if (type == "HertzianSinterSlidingFrictionSpecies")
209  {
211  is >> species;
212  copyAndAddObject(species);
213  }
214  else if (type == "LinearViscoelasticSlidingFrictionSpecies")
215  {
217  is >> species;
218  copyAndAddObject(species);
219  }
220  else if (type == "LinearPlasticViscoelasticSlidingFrictionSpecies")
221  {
223  is >> species;
224  copyAndAddObject(species);
225  }
226  else if (type == "LinearViscoelasticFrictionSpecies")
227  {
229  is >> species;
230  copyAndAddObject(species);
231  }
232  else if (type == "LinearPlasticViscoelasticFrictionSpecies")
233  {
235  is >> species;
236  copyAndAddObject(species);
237  }
238  else if (type == "LinearViscoelasticIrreversibleAdhesiveSpecies")
239  {
241  is >> species;
242  copyAndAddObject(species);
243  }
244  else if (type == "LinearViscoelasticBondedSpecies")
245  {
247  is >> species;
248  copyAndAddObject(species);
249  }
250  else if (type == "LinearPlasticViscoelasticIrreversibleAdhesiveSpecies")
251  {
253  is >> species;
254  copyAndAddObject(species);
255  }
256  else if (type == "LinearViscoelasticSlidingFrictionIrreversibleAdhesiveSpecies")
257  {
259  is >> species;
260  copyAndAddObject(species);
261  }
262  else if (type == "LinearPlasticViscoelasticSlidingFrictionIrreversibleAdhesiveSpecies")
263  {
265  is >> species;
266  copyAndAddObject(species);
267  }
268  else if (type == "LinearViscoelasticFrictionIrreversibleAdhesiveSpecies")
269  {
271  is >> species;
272  copyAndAddObject(species);
273  }
274  else if (type == "LinearPlasticViscoelasticFrictionIrreversibleAdhesiveSpecies")
275  {
277  is >> species;
278  copyAndAddObject(species);
279  }
280  else if (type == "LinearViscoelasticReversibleAdhesiveSpecies")
281  {
283  is >> species;
284  copyAndAddObject(species);
285  }
286  else if (type == "LinearPlasticViscoelasticReversibleAdhesiveSpecies")
287  {
289  is >> species;
290  copyAndAddObject(species);
291  }
292  else if (type == "LinearViscoelasticSlidingFrictionReversibleAdhesiveSpecies")
293  {
295  is >> species;
296  copyAndAddObject(species);
297  }
298  else if (type == "LinearPlasticViscoelasticSlidingFrictionReversibleAdhesiveSpecies")
299  {
301  is >> species;
302  copyAndAddObject(species);
303  }
304  else if (type == "LinearViscoelasticFrictionReversibleAdhesiveSpecies")
305  {
307  is >> species;
308  copyAndAddObject(species);
309  }
310  else if (type == "LinearPlasticViscoelasticFrictionReversibleAdhesiveSpecies")
311  {
313  is >> species;
314  copyAndAddObject(species);
315  }
316  else if (type == "LinearViscoelasticFrictionLiquidBridgeWilletSpecies")
317  {
319  is >> species;
320  copyAndAddObject(species);
321  }
322  else if (type == "LinearViscoelasticFrictionLiquidMigrationWilletSpecies")
323  {
325  is >> species;
326  copyAndAddObject(species);
327  }
328  else if (type == "LinearPlasticViscoelasticSlidingFrictionLiquidMigrationWilletSpecies")
329  {
331  is >> species;
332  copyAndAddObject(species);
333  }
334  else if (type == "HertzianViscoelasticMindlinSpecies")
335  {
337  is >> species;
338  copyAndAddObject(species);
339  }
340  else if (type == "HertzianViscoelasticMindlinRollingTorsionSpecies" ||
341  type == "HertzianViscoelasticFrictionSpecies")
342  {
344  is >> species;
345  copyAndAddObject(species);
346  }
347  else if (type == "HertzianViscoelasticFrictionChargedBondedSpecies")
348  {
350  is >> species;
351  copyAndAddObject(species);
352  }
353  else if (type == "LinearViscoelasticFrictionChargedBondedSpecies")
354  {
356  is >> species;
357  copyAndAddObject(species);
358  }
359  else if (type == "ThermalSinterSlidingFrictionSpecies")
360  {
362  is >> species;
363  copyAndAddObject(species);
364  }
365  else if (type == "ThermalSinterFrictionSpecies")
366  {
368  is >> species;
369  copyAndAddObject(species);
370  }
371  else if (type == "LinearPlasticViscoelasticFrictionLiquidBridgeWilletSpecies")
372  {
374  is >> species;
375  copyAndAddObject(species);
376  }
377  else if (type == "ThermalSinterLinFrictionReversibleAdhesiveSpecies")
378  {
380  is >> species;
381  copyAndAddObject(species);
382  }
383  else if (type == "k") //for backwards compatibility
384  {
386  }
387  else
388  {
389  logger(WARN,
390  "Species type % not understood in restart file: You need to add this species to SpeciesHandler::readObject.",
391  type);
392  std::stringstream line;
395  }
396 
397  //remove the default mixed species
398  for (unsigned int i = 0; i + 1 < getNumberOfObjects(); i++)
399  {
406  delete mixedObjects_.back();
407  mixedObjects_.pop_back();
408  }
409 
410  //Read the mixed species.
411  for (unsigned int i = 0; i + 1 < getNumberOfObjects(); i++)
412  {
413  is >> type;
414  if (type == "LinearViscoelasticMixedSpecies")
415  {
417  is >> species;
418  mixedObjects_.push_back(species.copy());
419  }
420  else if (type == "LinearPlasticViscoelasticMixedSpecies")
421  {
423  is >> species;
424  mixedObjects_.push_back(species.copy());
425  }
426  else if (type == "SinterMixedSpecies")
427  {
428  SinterMixedSpecies species;
429  is >> species;
430  mixedObjects_.push_back(species.copy());
431  }
432  else if (type == "SinterReversibleAdhesiveMixedSpecies")
433  {
435  is >> species;
436  mixedObjects_.push_back(species.copy());
437  }
438  else if (type == "SinterFrictionReversibleAdhesiveMixedSpecies")
439  {
441  is >> species;
442  mixedObjects_.push_back(species.copy());
443  }
444  else if (type == "SinterFrictionMixedSpecies")
445  {
447  is >> species;
448  mixedObjects_.push_back(species.copy());
449  }
450  else if (type == "HertzianSinterMixedSpecies")
451  {
453  is >> species;
454  mixedObjects_.push_back(species.copy());
455  }
456  else if (type == "HertzianSinterFrictionMixedSpecies")
457  {
459  is >> species;
460  mixedObjects_.push_back(species.copy());
461  }
462  else if (type == "HertzianSinterSlidingFrictionMixedSpecies")
463  {
465  is >> species;
466  mixedObjects_.push_back(species.copy());
467  }
468  else if (type == "LinearViscoelasticSlidingFrictionMixedSpecies")
469  {
471  is >> species;
472  mixedObjects_.push_back(species.copy());
473  }
474  else if (type == "LinearPlasticViscoelasticSlidingFrictionMixedSpecies")
475  {
477  is >> species;
478  mixedObjects_.push_back(species.copy());
479  }
480  else if (type == "LinearViscoelasticFrictionMixedSpecies")
481  {
483  is >> species;
484  mixedObjects_.push_back(species.copy());
485  }
486  else if (type == "LinearPlasticViscoelasticFrictionMixedSpecies")
487  {
489  is >> species;
490  mixedObjects_.push_back(species.copy());
491  }
492  else if (type == "LinearViscoelasticIrreversibleAdhesiveMixedSpecies")
493  {
495  is >> species;
496  mixedObjects_.push_back(species.copy());
497  }
498  else if (type == "LinearViscoelasticBondedMixedSpecies")
499  {
501  is >> species;
502  mixedObjects_.push_back(species.copy());
503  }
504  else if (type == "LinearPlasticViscoelasticIrreversibleAdhesiveMixedSpecies")
505  {
507  is >> species;
508  mixedObjects_.push_back(species.copy());
509  }
510  else if (type == "LinearViscoelasticSlidingFrictionIrreversibleAdhesiveMixedSpecies")
511  {
513  is >> species;
514  mixedObjects_.push_back(species.copy());
515  }
516  else if (type == "LinearPlasticViscoelasticSlidingFrictionIrreversibleAdhesiveMixedSpecies")
517  {
519  is >> species;
520  mixedObjects_.push_back(species.copy());
521  }
522  else if (type == "LinearViscoelasticFrictionIrreversibleAdhesiveMixedSpecies")
523  {
525  is >> species;
526  mixedObjects_.push_back(species.copy());
527  }
528  else if (type == "LinearPlasticViscoelasticFrictionIrreversibleAdhesiveMixedSpecies")
529  {
531  is >> species;
532  mixedObjects_.push_back(species.copy());
533  }
534  else if (type == "LinearPlasticViscoelasticSlidingFrictionLiquidMigrationWilletMixedSpecies")
535  {
537  is >> species;
538  mixedObjects_.push_back(species.copy());
539  }
540  else if (type == "LinearPlasticViscoelasticFrictionLiquidBridgeWilletMixedSpecies")
541  {
543  is >> species;
544  mixedObjects_.push_back(species.copy());
545  }
546  else if (type == "LinearViscoelasticReversibleAdhesiveMixedSpecies")
547  {
549  is >> species;
550  mixedObjects_.push_back(species.copy());
551  }
552  else if (type == "LinearPlasticViscoelasticReversibleAdhesiveMixedSpecies")
553  {
555  is >> species;
556  mixedObjects_.push_back(species.copy());
557  }
558  else if (type == "LinearViscoelasticSlidingFrictionReversibleAdhesiveMixedSpecies")
559  {
561  is >> species;
562  mixedObjects_.push_back(species.copy());
563  }
564  else if (type == "LinearPlasticViscoelasticSlidingFrictionReversibleAdhesiveMixedSpecies")
565  {
567  is >> species;
568  mixedObjects_.push_back(species.copy());
569  }
570  else if (type == "LinearViscoelasticFrictionReversibleAdhesiveMixedSpecies")
571  {
573  is >> species;
574  mixedObjects_.push_back(species.copy());
575  }
576  else if (type == "LinearPlasticViscoelasticFrictionReversibleAdhesiveMixedSpecies")
577  {
579  is >> species;
580  mixedObjects_.push_back(species.copy());
581  }
582  else if (type == "LinearViscoelasticFrictionLiquidBridgeWilletMixedSpecies")
583  {
585  is >> species;
586  mixedObjects_.push_back(species.copy());
587  }
588  else if (type == "LinearViscoelasticFrictionLiquidMigrationWilletMixedSpecies")
589  {
591  is >> species;
592  mixedObjects_.push_back(species.copy());
593  }
594  else if (type == "HertzianViscoelasticMindlinMixedSpecies")
595  {
597  is >> species;
598  mixedObjects_.push_back(species.copy());
599  }
600  else if (type == "HertzianViscoelasticMindlinRollingTorsionMixedSpecies" ||
601  type == "HertzianViscoelasticFrictionMixedSpecies")
602  {
604  is >> species;
605  mixedObjects_.push_back(species.copy());
606  }
607  else if (type == "HertzianViscoelasticFrictionChargedBondedMixedSpecies")
608  {
610  is >> species;
611  mixedObjects_.push_back(species.copy());
612  }
613  else if (type == "LinearViscoelasticFrictionChargedBondedMixedSpecies")
614  {
616  is >> species;
617  mixedObjects_.push_back(species.copy());
618  }
619  else if (type == "ThermalSinterSlidingFrictionMixedSpecies")
620  {
622  is >> species;
623  mixedObjects_.push_back(species.copy());
624  }
625  else if (type == "ThermalSinterFrictionMixedSpecies")
626  {
628  is >> species;
629  mixedObjects_.push_back(species.copy());
630  }
631  else if (type == "ThermalSinterLinFrictionReversibleAdhesiveMixedSpecies")
632  {
634  is >> species;
635  mixedObjects_.push_back(species.copy());
636  }
637  else if (type == "ThermalSinterFrictionMixedSpecies")
638  {
640  is >> species;
641  mixedObjects_.push_back(species.copy());
642  }
643  else
644  {
645  logger(WARN,
646  "Species type % not understood in restart file: You need to add this species to SpeciesHandler::readMixedObject.",
647  type);
648  std::stringstream line;
651  mixedObjects_.push_back(species.copy());
652  }
653  }
654 }

References addObject(), MixedSpecies< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >::copy(), BaseHandler< ParticleSpecies >::copyAndAddObject(), FATAL, 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.

665 {
666  //read in next line
667  std::stringstream line;
669 
670  //read each property
671  std::string property;
672  unsigned int particleDimension = 0;
673  Mdouble density = 0.0, stiffness = 0.0, dissipation = 0.0, slidingFrictionCoefficient = 0.0, slidingFrictionCoefficientStatic = 0.0, slidingStiffness = 0.0, slidingDissipation = 0.0;
674  line >> stiffness;
675  while (true)
676  {
677  line >> property;
678  if (property == "disp")
679  line >> dissipation;
680  else if (property == "rho")
681  line >> density;
682  else if (property == "kt")
683  line >> slidingStiffness;
684  else if (property == "dispt")
685  line >> slidingDissipation;
686  else if (property == "mu")
687  line >> slidingFrictionCoefficient;
688  else if (property == "mus")
689  line >> slidingFrictionCoefficientStatic;
690  else if (property == "dim_particle")
691  {
692  line >> particleDimension;
693  getDPMBase()->setParticleDimensions(particleDimension);
694  }
695  else if (property == "(mixed)")
696  {
697  density = 0;
698  }
699  else
700  {
701  logger(WARN, "Warning: % is not a species property", property);
702  break;
703  }
704  if (line.eof())
705  break;
706  }
707 
708  //create the correct species
709  if (slidingFrictionCoefficient == 0.0)
710  {
712  species->setDensity(density);
713  species->setStiffness(stiffness);
714  species->setDissipation(dissipation);
715  return species;
716  }
717  else
718  {
720  species->setDensity(density);
721  species->setStiffness(stiffness);
722  species->setDissipation(dissipation);
723  species->setSlidingStiffness(slidingStiffness);
724  species->setSlidingDissipation(slidingDissipation);
725  species->setSlidingFrictionCoefficient(slidingFrictionCoefficient);
726  if (slidingFrictionCoefficientStatic == 0.0)
727  slidingFrictionCoefficientStatic = slidingFrictionCoefficient;
728  species->setSlidingFrictionCoefficientStatic(slidingFrictionCoefficientStatic);
729  return species;
730  }
731 }

References BaseHandler< ParticleSpecies >::getDPMBase(), helpers::getLineFromStringStream(), logger, DPMBase::setParticleDimensions(), 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 >.

823 {
825  for (unsigned int index2 = 0; index2 < getNumberOfObjects(); ++index2)
826  {
827  mixedObjects_.erase(mixedObjects_.begin() + getMixedId(index, index2));
828  }
830 }

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

Referenced by CurvyChute::recreateBottom().

◆ 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.
863 {
864  for (unsigned int i = 0; i < getSize(); i++)
865  {
866  if (getObject(i)->getUseAngularDOFs())
867  return true;
868  for (unsigned int j = 0; j + 1 < i; j++)
869  {
870  if (getMixedObject(i, j)->getUseAngularDOFs())
871  return true;
872  }
873  }
874  return false;
875 }

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.

837 {
838  os << "Species " << getNumberOfObjects() << "\n";
839  unsigned idMixed = 0;
840  for (const ParticleSpecies* species : objects_)
841  {
842  os << *species << "\n";
843  for (unsigned int id2 = 0; id2 < species->getIndex(); id2++)
844  {
845  os << *mixedObjects_[idMixed] << "\n";
846  idMixed++;
847  }
848  }
849 }

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:
BaseHandler< ParticleSpecies >::setDPMBase
void setDPMBase(DPMBase *DPMBase)
Sets the problem that is solved using this handler.
Definition: BaseHandler.h:718
LinearViscoelasticSlidingFrictionSpecies
Species< LinearViscoelasticNormalSpecies, SlidingFrictionSpecies > LinearViscoelasticSlidingFrictionSpecies
Definition: LinearViscoelasticSlidingFrictionSpecies.h:34
BaseSpecies::getInteractionDistance
Mdouble getInteractionDistance() const
returns the largest separation distance at which adhesive short-range forces can occur.
Definition: BaseSpecies.h:146
SpeciesHandler::clear
void clear() override
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0.
Definition: SpeciesHandler.h:54
DPMBase::setParticleDimensions
void setParticleDimensions(unsigned int particleDimensions)
Sets the particle dimensionality.
Definition: DPMBase.cc:1439
SpeciesHandler::mixedObjects_
std::vector< BaseSpecies * > mixedObjects_
The list of pointers to the mixed species.
Definition: SpeciesHandler.h:96
logger
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
SpeciesHandler::getMixedObject
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
BaseHandler< ParticleSpecies >::getSize
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
ParticleSpecies
Definition: ParticleSpecies.h:37
SlidingFrictionSpecies
SlidingFrictionSpecies contains the parameters used to describe sliding friction.
Definition: SlidingFrictionSpecies.h:38
FrictionSpecies
FrictionSpecies contains the parameters used to describe sliding, rolling and torsional friction.
Definition: FrictionSpecies.h:39
Mdouble
double Mdouble
Definition: GeneralDefine.h:34
BaseSpecies
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:50
ReversibleAdhesiveSpecies
ReversibleAdhesiveSpecies contains the parameters used to describe a linear reversible short-range fo...
Definition: ReversibleAdhesiveSpecies.h:38
BaseHandler< ParticleSpecies >::objects_
std::vector< ParticleSpecies * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
MixedSpecies
Contains contact force properties for contacts between particles with two different species.
Definition: MixedSpecies.h:43
SpeciesHandler::readOldObject
ParticleSpecies * readOldObject(std::istream &is)
Reads ParticleSpecies into the SpeciesHandler from old-style restart data.
Definition: SpeciesHandler.cc:664
BaseHandler::removeObject
virtual void removeObject(unsigned const int index)
Removes an Object from the BaseHandler.
Definition: BaseHandler.h:472
LinearViscoelasticSpecies
Species< LinearViscoelasticNormalSpecies > LinearViscoelasticSpecies
Definition: LinearViscoelasticSpecies.h:33
SpeciesHandler::addObject
void addObject(ParticleSpecies *S) override
Adds a new ParticleSpecies to the SpeciesHandler.
Definition: SpeciesHandler.cc:797
ParticleSpecies::copyMixed
virtual BaseSpecies * copyMixed() const =0
Creates a new MixedSpecies with the same force properties as the Species from which it is called....
Species< LinearViscoelasticNormalSpecies >
WARN
LL< Log::WARN > WARN
Warning log level.
Definition: Logger.cc:54
BaseSpecies::setHandler
void setHandler(SpeciesHandler *handler)
Sets the pointer to the handler to which this species belongs.
Definition: BaseSpecies.cc:91
Log::FATAL
@ FATAL
BaseObject::getIndex
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.h:118
BaseSpecies::copy
virtual BaseSpecies * copy() const =0
Creates a deep copy of the object from which it is called.
BaseHandler< ParticleSpecies >::getNumberOfObjects
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
MixedSpecies::copy
MixedSpecies< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies > * copy() const final
Creates a deep copy of the MixedSpecies from which it is called.
Definition: MixedSpecies.h:145
helpers::getLineFromStringStream
void getLineFromStringStream(std::istream &in, std::stringstream &out)
Reads a line from one stringstream into another, and prepares the latter for reading in.
Definition: Helpers.cc:423
constants::i
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
DPMBase::setRotation
void setRotation(bool rotation)
Sets whether particle rotation is enabled or disabled.
Definition: DPMBase.h:552
SpeciesHandler::useAngularDOFs
bool useAngularDOFs()
Check if angular DOF have to be used.
Definition: SpeciesHandler.cc:862
BaseHandler< ParticleSpecies >::getObject
ParticleSpecies * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:613
BaseHandler::getDPMBase
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725
SpeciesHandler::getMixedId
unsigned int getMixedId(unsigned int id1, unsigned int id2) const
Gets the Id of the behaviour between two given species.
Definition: SpeciesHandler.cc:742
BaseHandler< ParticleSpecies >::copyAndAddObject
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
ParticleSpecies::setMaxInteractionDistance
void setMaxInteractionDistance(Mdouble interactionDistance=0)
Sets maxInteractionDistance_.
Definition: ParticleSpecies.cc:220
BaseHandler< ParticleSpecies >::copyContentsFromOtherHandler
void copyContentsFromOtherHandler(const BaseHandler< ParticleSpecies > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
Definition: BaseHandler.h:367
BaseHandler::clear
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0.
Definition: BaseHandler.h:528
DPMBase::particleHandler
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created.
Definition: DPMBase.h:1395
BaseSpecies::getUseAngularDOFs
virtual bool getUseAngularDOFs() const =0
Returns true if torques (i.e. angular degrees of freedom) have to be calculated.
BaseHandler::addObject
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:431
ParticleHandler::computeAllMasses
void computeAllMasses(unsigned int indSpecies)
Computes the mass for all BaseParticle of the given species in this ParticleHandler.
Definition: ParticleHandler.cc:1205