MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SpeciesHandler Class Reference

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...
 
SpeciesHandler operator= (const SpeciesHandler &rhs)
 Assignment operator that copies all species and the pointer to the DPMBase from the given SpeciesHandler. More...
 
 ~SpeciesHandler ()
 Destructor, it destructs the SpeciesHandler and all ParticleSpecies it contains. More...
 
virtual void addObject (ParticleSpecies *const S)
 Adds a new ParticleSpecies to the SpeciesHandler. More...
 
void removeObject (unsigned const int index)
 Remove the ParticleSpecies with given id. More...
 
void readObject (std::istream &is)
 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 (const unsigned int id1, const 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 (const unsigned int id1, const 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
 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...
 
void removeLastObject ()
 Removes the last Object from the BaseHandler. More...
 
void clear ()
 Empties the whole BaseHandler by removing all Objects and setting all other variables to 0. 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...
 
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...
 
unsigned int getNumberOfObjects () const
 Gets the number of Object in this BaseHandler. 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...
 
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)
 This function sets the id and ensures that nextId is a bigger value than id. More...
 
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 ()
 Over written in WallHandler and ParticleHandler. 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.

Definition at line 38 of file SpeciesHandler.h.

Constructor & Destructor Documentation

SpeciesHandler::SpeciesHandler ( )

Default constructor, it creates an empty SpeciesHandler.

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

Definition at line 73 of file SpeciesHandler.cc.

References DEBUG, and logger.

74 {
75  logger(DEBUG, "SpeciesHandler::SpeciesHandler() finished");
76 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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.

Definition at line 84 of file SpeciesHandler.cc.

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

85 {
86  clear();
87  setDPMBase(other.getDPMBase());
89  for (BaseSpecies* mixSpec : other.mixedObjects_)
90  {
91  mixedObjects_.push_back(mixSpec->copy());
92  mixedObjects_.back()->setHandler(this);
93  }
94  logger(DEBUG, "SpeciesHandler::SpeciesHandler(const SpeciesHandler &other) finished");
95 }
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:44
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
void setDPMBase(DPMBase *DPMBase)
Sets the problem that is solved using this handler.
std::vector< BaseSpecies * > mixedObjects_
The list of pointers to the mixed species.
virtual BaseSpecies * copy() const =0
Creates a deep copy of the object from which it is called.
void copyContentsFromOtherHandler(const BaseHandler< ParticleSpecies > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:543
void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
SpeciesHandler::~SpeciesHandler ( )

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

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

Definition at line 128 of file SpeciesHandler.cc.

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

129 {
130  clear(); //this deletes everything that comes from the BaseHandler.
131  /*for (BaseSpecies* o : mixedObjects_)
132  {
133  delete o;
134  }*/
135  for (BaseSpecies* mixSpec : mixedObjects_)
136  {
137  delete mixSpec;
138  }
139  mixedObjects_.clear();
140  logger(DEBUG, "SpeciesHandler::~SpeciesHandler() finished");
141 }
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:44
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
std::vector< BaseSpecies * > mixedObjects_
The list of pointers to the mixed species.
void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...

Member Function Documentation

void SpeciesHandler::addObject ( ParticleSpecies *const  S)
virtual

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!

Reimplemented from BaseHandler< ParticleSpecies >.

Definition at line 737 of file SpeciesHandler.cc.

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

Referenced by readObject(), and DPMBase::readParAndIniFiles().

738 {
740  //logger(INFO, "Part / Mix: % / %", objects_.size(), mixedObjects_.size());
742  for (unsigned int id = 0; id + 1 < getNumberOfObjects(); ++id)
743  {
744  mixedObjects_.push_back(S->copyMixed());
745  mixedObjects_.back()->setIndex(id);
746  mixedObjects_.back()->setId(getNumberOfObjects()-1);
747  mixedObjects_.back()->mixAll(S,getObject(id));
748  }
749  S->setHandler(this);
753 }
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.cc:108
void computeAllMasses(unsigned int indSpecies)
Computes the mass for all BaseParticle of the given species in this ParticleHandler.
void setRotation(bool newRotFlag)
Allows to set the flag for enabling or disabling particle rotation in the simulations.
Definition: DPMBase.cc:231
virtual BaseSpecies * copyMixed() const =0
Creates a new MixedSpecies with the same force properties as the Species from which it is called...
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created...
Definition: DPMBase.h:1001
ParticleSpecies * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
std::vector< BaseSpecies * > mixedObjects_
The list of pointers to the mixed species.
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
void setHandler(SpeciesHandler *handler)
Sets the pointer to the handler to which this species belongs.
Definition: BaseSpecies.cc:66
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:313
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
bool useAngularDOFs()
Check if angular DOF have to be used.
unsigned int SpeciesHandler::getMixedId ( const unsigned int  id1,
const 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.

Definition at line 686 of file SpeciesHandler.cc.

Referenced by getMixedObject(), and removeObject().

687 {
688  unsigned int maxId = std::max(id1,id2);
689  return (maxId*(maxId-1))/2 + std::min(id1,id2);
690 }
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

Definition at line 70 of file SpeciesHandler.h.

Referenced by InteractionHandler::getInteraction(), and useAngularDOFs().

71  {
72  return dynamic_cast<typename U::MixedSpeciesType*>(getMixedObject(S->getIndex(),T->getIndex()));
73  }
std::enable_if<!std::is_pointer< typename U::MixedSpeciesType >::value, typename U::MixedSpeciesType * >::type getMixedObject(const U *S, const U *T)
BaseSpecies * SpeciesHandler::getMixedObject ( const unsigned int  id1,
const 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.

Definition at line 707 of file SpeciesHandler.cc.

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

708 {
709  if (id1 == id2)
710  {
711  return getObject(id1);
712  }
713  else
714  {
715  if (std::max(id1,id2) >= getNumberOfObjects())
716  {
717  logger(ERROR, "In: Object* SpeciesHandler::getMixedObject(const unsigned int id) const. No Object exist with index %, number of objects is %", std::max(id1, id2), getNumberOfObjects());
718  return nullptr;
719  }
720  else
721  {
722  return mixedObjects_[getMixedId(id1,id2)];
723  }
724  }
725 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
unsigned int getMixedId(const unsigned int id1, const unsigned int id2) const
Gets the Id of the behaviour between two given species.
ParticleSpecies * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
std::vector< BaseSpecies * > mixedObjects_
The list of pointers to the mixed species.
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
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.

Definition at line 695 of file SpeciesHandler.cc.

References mixedObjects_.

696 {
697  return mixedObjects_;
698 }
std::vector< BaseSpecies * > mixedObjects_
The list of pointers to the mixed species.
std::string SpeciesHandler::getName ( ) const
virtual

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

Returns
The string "SpeciesHandler"

Implements BaseHandler< ParticleSpecies >.

Definition at line 813 of file SpeciesHandler.cc.

814 {
815  return "SpeciesHandler";
816 }
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.

Definition at line 104 of file SpeciesHandler.cc.

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

105 {
106  if (this != &rhs)
107  {
108  clear();
110  for (BaseSpecies* mixSpec : mixedObjects_)
111  {
112  delete mixSpec;
113  }
114  mixedObjects_.clear();
115  for (BaseSpecies* mixSpec : rhs.mixedObjects_)
116  {
117  mixedObjects_.push_back(mixSpec->copy());
118  mixedObjects_.back()->setHandler(this);
119  }
120  }
121 
122  logger(DEBUG, "SpeciesHandler SpeciesHandler::operator =(const SpeciesHandler& rhs)");
123  return *this;
124 }
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:44
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
std::vector< BaseSpecies * > mixedObjects_
The list of pointers to the mixed species.
virtual BaseSpecies * copy() const =0
Creates a deep copy of the object from which it is called.
void copyContentsFromOtherHandler(const BaseHandler< ParticleSpecies > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
void SpeciesHandler::readObject ( std::istream &  is)
virtual

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

Definition at line 147 of file SpeciesHandler.cc.

References addObject(), BaseHandler< ParticleSpecies >::copyAndAddObject(), DEBUG, ERROR, helpers::getLineFromStringStream(), BaseHandler< ParticleSpecies >::getNumberOfObjects(), logger, mixedObjects_, and readOldObject().

148 {
149  std::string type;
150  is >> type;
151  logger.log(Log::DEBUG, "SpeciesHandler::readObject(is): reading type %.", type);
152 // if (strncmp(type,"LinearViscoelastic",strlen("LinearViscoelastic")))
153 // {
154 // typedef LinearViscoelasticNormalSpecies NormalSpecies;
155 // }
156  if (type == "LinearViscoelasticSpecies")
157  {
159  is >> species;
160  copyAndAddObject(species);
161  }
162  else if (type == "LinearPlasticViscoelasticSpecies")
163  {
165  is >> species;
166  copyAndAddObject(species);
167  }
168  else if (type == "SinterSpecies")
169  {
170  SinterSpecies species;
171  is >> species;
172  copyAndAddObject(species);
173  }
174  else if (type == "SinterReversibleAdhesiveSpecies")
175  {
177  is >> species;
178  copyAndAddObject(species);
179  }
180  else if (type == "SinterFrictionReversibleAdhesiveSpecies")
181  {
183  is >> species;
184  copyAndAddObject(species);
185  }
186  else if (type == "SinterFrictionSpecies")
187  {
188  SinterFrictionSpecies species;
189  is >> species;
190  copyAndAddObject(species);
191  }
192  else if (type == "HertzianSinterSpecies")
193  {
194  HertzianSinterSpecies species;
195  is >> species;
196  copyAndAddObject(species);
197  }
198  else if (type == "HertzianSinterFrictionSpecies")
199  {
201  is >> species;
202  copyAndAddObject(species);
203  }
204  else if (type == "HertzianSinterSlidingFrictionSpecies")
205  {
207  is >> species;
208  copyAndAddObject(species);
209  }
210  else if (type == "LinearViscoelasticSlidingFrictionSpecies")
211  {
213  is >> species;
214  copyAndAddObject(species);
215  }
216  else if (type == "LinearPlasticViscoelasticSlidingFrictionSpecies")
217  {
219  is >> species;
220  copyAndAddObject(species);
221  }
222  else if (type == "LinearViscoelasticFrictionSpecies")
223  {
225  is >> species;
226  copyAndAddObject(species);
227  }
228  else if (type == "LinearPlasticViscoelasticFrictionSpecies")
229  {
231  is >> species;
232  copyAndAddObject(species);
233  }
234  else if (type == "LinearViscoelasticIrreversibleAdhesiveSpecies")
235  {
237  is >> species;
238  copyAndAddObject(species);
239  }
240  else if (type == "LinearViscoelasticBondedSpecies")
241  {
243  is >> species;
244  copyAndAddObject(species);
245  }
246  else if (type == "LinearPlasticViscoelasticIrreversibleAdhesiveSpecies")
247  {
249  is >> species;
250  copyAndAddObject(species);
251  }
252  else if (type == "LinearViscoelasticSlidingFrictionIrreversibleAdhesiveSpecies")
253  {
255  is >> species;
256  copyAndAddObject(species);
257  }
258  else if (type == "LinearPlasticViscoelasticSlidingFrictionIrreversibleAdhesiveSpecies")
259  {
261  is >> species;
262  copyAndAddObject(species);
263  }
264  else if (type == "LinearViscoelasticFrictionIrreversibleAdhesiveSpecies")
265  {
267  is >> species;
268  copyAndAddObject(species);
269  }
270  else if (type == "LinearPlasticViscoelasticFrictionIrreversibleAdhesiveSpecies")
271  {
273  is >> species;
274  copyAndAddObject(species);
275  }
276  else if (type == "LinearViscoelasticReversibleAdhesiveSpecies")
277  {
279  is >> species;
280  copyAndAddObject(species);
281  }
282  else if (type == "LinearPlasticViscoelasticReversibleAdhesiveSpecies")
283  {
285  is >> species;
286  copyAndAddObject(species);
287  }
288  else if (type == "LinearViscoelasticSlidingFrictionReversibleAdhesiveSpecies")
289  {
291  is >> species;
292  copyAndAddObject(species);
293  }
294  else if (type == "LinearPlasticViscoelasticSlidingFrictionReversibleAdhesiveSpecies")
295  {
297  is >> species;
298  copyAndAddObject(species);
299  }
300  else if (type == "LinearViscoelasticFrictionReversibleAdhesiveSpecies")
301  {
303  is >> species;
304  copyAndAddObject(species);
305  }
306  else if (type == "LinearPlasticViscoelasticFrictionReversibleAdhesiveSpecies")
307  {
309  is >> species;
310  copyAndAddObject(species);
311  }
312  else if (type == "LinearViscoelasticFrictionLiquidBridgeWilletSpecies")
313  {
315  is >> species;
316  copyAndAddObject(species);
317  }
318  else if (type == "LinearViscoelasticFrictionLiquidMigrationWilletSpecies")
319  {
321  is >> species;
322  copyAndAddObject(species);
323  }
324  else if (type == "HertzianViscoelasticMindlinRollingTorsionSpecies")
325  {
327  is >> species;
328  copyAndAddObject(species);
329  }
330  else if (type == "HertzianViscoelasticFrictionChargedBondedSpecies")
331  {
333  is >> species;
334  copyAndAddObject(species);
335  }
336  else if (type == "LinearViscoelasticFrictionChargedBondedSpecies")
337  {
339  is >> species;
340  copyAndAddObject(species);
341  }
342  else if (type == "HertzianViscoelasticMindlinSpecies")
343  {
345  is >> species;
346  copyAndAddObject(species);
347  }
348  else if (type == "ThermalSinterSlidingFrictionSpecies")
349  {
351  is >> species;
352  copyAndAddObject(species);
353  }
354  else if (type == "ThermalSinterFrictionSpecies")
355  {
357  is >> species;
358  copyAndAddObject(species);
359  }
360  else if (type == "k") //for backwards compatibility
361  {
363  }
364  else
365  {
366  std::stringstream line(std::stringstream::in | std::stringstream::out);
368  logger(ERROR, "Species type % not understood in restart file: You need to add this species to SpeciesHandler::readObject.", type);
369  }
370 
371  //remove the default mixed species
372  for (unsigned int i = 0; i + 1 < getNumberOfObjects(); i++)
373  {
380  delete mixedObjects_.back();
381  mixedObjects_.pop_back();
382  }
383 
384  //Read the mixed species.
385  for (unsigned int i = 0; i+1 < getNumberOfObjects(); i++)
386  {
387  is >> type;
388  if (type == "LinearViscoelasticMixedSpecies")
389  {
391  is >> species;
392  mixedObjects_.push_back(species.copy());
393  }
394  else if (type == "LinearPlasticViscoelasticMixedSpecies")
395  {
397  is >> species;
398  mixedObjects_.push_back(species.copy());
399  }
400  else if (type == "SinterMixedSpecies")
401  {
402  SinterMixedSpecies species;
403  is >> species;
404  mixedObjects_.push_back(species.copy());
405  }
406  else if (type == "SinterReversibleAdhesiveMixedSpecies")
407  {
409  is >> species;
410  mixedObjects_.push_back(species.copy());
411  }
412  else if (type == "SinterFrictionReversibleAdhesiveMixedSpecies")
413  {
415  is >> species;
416  mixedObjects_.push_back(species.copy());
417  }
418  else if (type == "SinterFrictionMixedSpecies")
419  {
421  is >> species;
422  mixedObjects_.push_back(species.copy());
423  }
424  else if (type == "HertzianSinterMixedSpecies")
425  {
427  is >> species;
428  mixedObjects_.push_back(species.copy());
429  }
430  else if (type == "HertzianSinterFrictionMixedSpecies")
431  {
433  is >> species;
434  mixedObjects_.push_back(species.copy());
435  }
436  else if (type == "HertzianSinterSlidingFrictionMixedSpecies")
437  {
439  is >> species;
440  mixedObjects_.push_back(species.copy());
441  }
442  else if (type == "LinearViscoelasticSlidingFrictionMixedSpecies")
443  {
445  is >> species;
446  mixedObjects_.push_back(species.copy());
447  }
448  else if (type == "LinearPlasticViscoelasticSlidingFrictionMixedSpecies")
449  {
451  is >> species;
452  mixedObjects_.push_back(species.copy());
453  }
454  else if (type == "LinearViscoelasticFrictionMixedSpecies")
455  {
457  is >> species;
458  mixedObjects_.push_back(species.copy());
459  }
460  else if (type == "LinearPlasticViscoelasticFrictionMixedSpecies")
461  {
463  is >> species;
464  mixedObjects_.push_back(species.copy());
465  }
466  else if (type == "LinearViscoelasticIrreversibleAdhesiveMixedSpecies")
467  {
469  is >> species;
470  mixedObjects_.push_back(species.copy());
471  }
472  else if (type == "LinearViscoelasticBondedMixedSpecies")
473  {
475  is >> species;
476  mixedObjects_.push_back(species.copy());
477  }
478  else if (type == "LinearPlasticViscoelasticIrreversibleAdhesiveMixedSpecies")
479  {
481  is >> species;
482  mixedObjects_.push_back(species.copy());
483  }
484  else if (type == "LinearViscoelasticSlidingFrictionIrreversibleAdhesiveMixedSpecies")
485  {
487  is >> species;
488  mixedObjects_.push_back(species.copy());
489  }
490  else if (type == "LinearPlasticViscoelasticSlidingFrictionIrreversibleAdhesiveMixedSpecies")
491  {
493  is >> species;
494  mixedObjects_.push_back(species.copy());
495  }
496  else if (type == "LinearViscoelasticFrictionIrreversibleAdhesiveMixedSpecies")
497  {
499  is >> species;
500  mixedObjects_.push_back(species.copy());
501  }
502  else if (type == "LinearPlasticViscoelasticFrictionIrreversibleAdhesiveMixedSpecies")
503  {
505  is >> species;
506  mixedObjects_.push_back(species.copy());
507  }
508  else if (type == "LinearViscoelasticReversibleAdhesiveMixedSpecies")
509  {
511  is >> species;
512  mixedObjects_.push_back(species.copy());
513  }
514  else if (type == "LinearPlasticViscoelasticReversibleAdhesiveMixedSpecies")
515  {
517  is >> species;
518  mixedObjects_.push_back(species.copy());
519  }
520  else if (type == "LinearViscoelasticSlidingFrictionReversibleAdhesiveMixedSpecies")
521  {
523  is >> species;
524  mixedObjects_.push_back(species.copy());
525  }
526  else if (type == "LinearPlasticViscoelasticSlidingFrictionReversibleAdhesiveMixedSpecies")
527  {
529  is >> species;
530  mixedObjects_.push_back(species.copy());
531  }
532  else if (type == "LinearViscoelasticFrictionReversibleAdhesiveMixedSpecies")
533  {
535  is >> species;
536  mixedObjects_.push_back(species.copy());
537  }
538  else if (type == "LinearPlasticViscoelasticFrictionReversibleAdhesiveMixedSpecies")
539  {
541  is >> species;
542  mixedObjects_.push_back(species.copy());
543  }
544  else if (type == "LinearViscoelasticFrictionLiquidBridgeWilletMixedSpecies")
545  {
547  is >> species;
548  mixedObjects_.push_back(species.copy());
549  }
550  else if (type == "LinearViscoelasticFrictionLiquidMigrationWilletMixedSpecies")
551  {
553  is >> species;
554  mixedObjects_.push_back(species.copy());
555  }
556  else if (type == "HertzianViscoelasticMindlinRollingTorsionMixedSpecies")
557  {
559  is >> species;
560  mixedObjects_.push_back(species.copy());
561  }
562  else if (type == "HertzianViscoelasticFrictionChargedBondedMixedSpecies")
563  {
565  is >> species;
566  mixedObjects_.push_back(species.copy());
567  }
568  else if (type == "LinearViscoelasticFrictionChargedBondedMixedSpecies")
569  {
571  is >> species;
572  mixedObjects_.push_back(species.copy());
573  }
574  else if (type == "HertzianViscoelasticMindlinMixedSpecies")
575  {
577  is >> species;
578  }
579  else if (type == "ThermalSinterSlidingFrictionMixedSpecies")
580  {
582  is >> species;
583  }
584  else if (type == "ThermalSinterFrictionMixedSpecies")
585  {
587  is >> species;
588  }
589  else if (type == "k") //for backwards compatibility
590  {
591  mixedObjects_.push_back(readOldObject(is));
592  }
593  else
594  {
595  logger(ERROR, "Species type % not understood in restart file: You need to add this species to SpeciesHandler::readMixedObject.", type);
596  }
597  }
598 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
FrictionSpecies contains the parameters used to describe sliding, rolling and torsional friction...
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:396
virtual void addObject(ParticleSpecies *const S)
Adds a new ParticleSpecies to the SpeciesHandler.
ParticleSpecies * readOldObject(std::istream &is)
Reads ParticleSpecies into the SpeciesHandler from old-style restart data.
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.
std::vector< BaseSpecies * > mixedObjects_
The list of pointers to the mixed species.
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
SlidingFrictionSpecies contains the parameters used to describe sliding friction. ...
Contains contact force properties for contacts between particles with two different species...
Definition: MixedSpecies.h:40
Contains material and contact force properties.
Definition: Interaction.h:35
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.

Definition at line 608 of file SpeciesHandler.cc.

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

Referenced by readObject().

609 {
610  //read in next line
611  std::stringstream line(std::stringstream::in | std::stringstream::out);
613 
614  //read each property
615  std::string property;
616  unsigned int particleDimension=0;
617  Mdouble density=0.0, stiffness=0.0, dissipation=0.0, slidingFrictionCoefficient=0.0, slidingFrictionCoefficientStatic=0.0, slidingStiffness=0.0, slidingDissipation=0.0;
618  line >> stiffness;
619  while (true)
620  {
621  line >> property;
622  if (property == "disp")
623  line >> dissipation;
624  else if (property == "rho")
625  line >> density;
626  else if (property == "kt")
627  line >> slidingStiffness;
628  else if (property == "dispt")
629  line >> slidingDissipation;
630  else if (property == "mu")
631  line >> slidingFrictionCoefficient;
632  else if (property == "mus")
633  line >> slidingFrictionCoefficientStatic;
634  else if (property == "dim_particle")
635  {
636  line >> particleDimension;
637  getDPMBase()->setParticleDimensions(particleDimension);
638  }
639  else if (property == "(mixed)")
640  {
641  density = 0;
642  }
643  else
644  {
645  logger(WARN, "Warning: % is not a species property", property);
646  break;
647  }
648  if (line.eof())
649  break;
650  }
651 
652  //create the correct species
653  if (slidingFrictionCoefficient == 0.0)
654  {
656  species->setDensity(density);
657  species->setStiffness(stiffness);
658  species->setDissipation(dissipation);
659  return species;
660  }
661  else
662  {
664  species->setDensity(density);
665  species->setStiffness(stiffness);
666  species->setDissipation(dissipation);
667  species->setSlidingStiffness(slidingStiffness);
668  species->setSlidingDissipation(slidingDissipation);
669  species->setSlidingFrictionCoefficient(slidingFrictionCoefficient);
670  if (slidingFrictionCoefficientStatic == 0.0)
671  slidingFrictionCoefficientStatic = slidingFrictionCoefficient;
672  species->setSlidingFrictionCoefficientStatic(slidingFrictionCoefficientStatic);
673  return species;
674  }
675 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
void setParticleDimensions(unsigned int particleDimensions)
Allows the dimension of the particle (f.e. for mass) to be changed. e.g. discs or spheres...
Definition: DPMBase.cc:583
Species< LinearViscoelasticNormalSpecies, SlidingFrictionSpecies > LinearViscoelasticSlidingFrictionSpecies
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:396
void setDensity(Mdouble density)
Allows density_ to be changed.
Species< LinearViscoelasticNormalSpecies > LinearViscoelasticSpecies
Contains material and contact force properties.
Definition: Interaction.h:35
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void SpeciesHandler::removeObject ( unsigned const int  index)
virtual

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

Definition at line 762 of file SpeciesHandler.cc.

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

763 {
765  for (unsigned int index2 = 0; index2 < getNumberOfObjects(); ++index2)
766  {
767  mixedObjects_.erase(mixedObjects_.begin()+getMixedId(index, index2));
768  }
770 }
unsigned int getMixedId(const unsigned int id1, const unsigned int id2) const
Gets the Id of the behaviour between two given species.
void setRotation(bool newRotFlag)
Allows to set the flag for enabling or disabling particle rotation in the simulations.
Definition: DPMBase.cc:231
virtual void removeObject(unsigned const int id)
Removes an Object from the BaseHandler.
Definition: BaseHandler.h:333
std::vector< BaseSpecies * > mixedObjects_
The list of pointers to the mixed species.
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
bool useAngularDOFs()
Check if angular DOF have to be used.
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.

Definition at line 821 of file SpeciesHandler.cc.

References getMixedObject(), BaseHandler< ParticleSpecies >::getNumberOfObjects(), BaseHandler< ParticleSpecies >::getObject(), and BaseSpecies::getUseAngularDOFs().

Referenced by addObject(), and removeObject().

822 {
823  for (unsigned int i = 0; i < getNumberOfObjects(); i++)
824  {
825  if (getObject(i)->getUseAngularDOFs())
826  return true;
827  for (unsigned int j = 0; j + 1 < i; j++)
828  {
829  if (getMixedObject(i, j)->getUseAngularDOFs())
830  return true;
831  }
832  }
833  return false;
834 }
ParticleSpecies * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
std::enable_if<!std::is_pointer< typename U::MixedSpeciesType >::value, typename U::MixedSpeciesType * >::type getMixedObject(const U *S, const U *T)
virtual bool getUseAngularDOFs() const =0
Returns true if torques (i.e. angular degrees of freedom) have to be calculated.
void SpeciesHandler::write ( std::ostream &  os) const
virtual

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

Parameters
[in]osThe output stream where the object needs to be written to.

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

Definition at line 777 of file SpeciesHandler.cc.

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

Referenced by DPMBase::write().

778 {
779  os << "Species " << getNumberOfObjects() << std::endl;
780  std::vector<BaseSpecies*>::const_iterator it2 = mixedObjects_.begin();
781  for (std::vector<ParticleSpecies*>::const_iterator it = begin(); it != end(); ++it)
782  {
783  os << (**it) << std::endl;
784  for (unsigned int id2 =0; id2 < (*it)->getIndex(); id2++)
785  {
786  os << (**it2) << std::endl;
787  it2++;
788  }
789  }
790  /*
791  This behaves like the code above but is actually readable
792  @weinhartt is there a reason?
793 
794  there is a reason. Curernt architecture does not allow this
795  \todo define new restart format. @dducks
796 
797  The code is written such that it writes PS0, then PS1 and MS01, then PS2 and
798  MS02, MS12, and so on (PS=ParticleSpecies, MS=MixedSpecies). We can change
799  the restart format, but we should write the read(os) function such that
800  it can also read the old format @weinhartt
801 
802  for (ParticleSpecies * spec : objects_) {
803  os << *spec << std::endl;
804  }
805  for (BaseSpecies * spec : mixedObjects_) {
806  os << *spec << std::endl;
807  }
808  */
809 }
const std::vector< ParticleSpecies * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
const std::vector< ParticleSpecies * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
std::vector< BaseSpecies * > mixedObjects_
The list of pointers to the mixed species.
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.

Member Data Documentation

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

The list of pointers to the mixed species.

Definition at line 92 of file SpeciesHandler.h.

Referenced by addObject(), getMixedObject(), getMixedObjects(), operator=(), readObject(), removeObject(), SpeciesHandler(), write(), and ~SpeciesHandler().


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