MercuryDPM  Beta
 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 id)
 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 >
U::MixedSpeciesType * 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...
 
U * copyAndAddObject (const U &O)
 Creates a copy of a Object and adds it to the BaseHandler. More...
 
U * copyAndAddObject (U *O)
 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...
 
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...
 

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 37 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 56 of file SpeciesHandler.cc.

References DEBUG, and logger.

57 {
58  logger(DEBUG, "SpeciesHandler::SpeciesHandler() finished");
59 }
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 67 of file SpeciesHandler.cc.

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

68 {
69  clear();
70  setDPMBase(other.getDPMBase());
72  for (BaseSpecies* mixSpec : other.mixedObjects_)
73  {
74  mixedObjects_.push_back(mixSpec->copy());
75  mixedObjects_.back()->setHandler(this);
76  }
77  logger(DEBUG, "SpeciesHandler::SpeciesHandler(const SpeciesHandler &other) finished");
78 }
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:512
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 111 of file SpeciesHandler.cc.

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

112 {
113  clear(); //this deletes everything that comes from the BaseHandler.
114  /*for (BaseSpecies* o : mixedObjects_)
115  {
116  delete o;
117  }*/
118  for (BaseSpecies* mixSpec : mixedObjects_)
119  {
120  delete mixSpec;
121  }
122  mixedObjects_.clear();
123  logger(DEBUG, "SpeciesHandler::~SpeciesHandler() finished");
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.
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 546 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().

547 {
549  //logger(INFO, "Part / Mix: % / %", objects_.size(), mixedObjects_.size());
551  for (unsigned int id = 0; id + 1 < getNumberOfObjects(); ++id)
552  {
553  mixedObjects_.push_back(S->copyMixed());
554  mixedObjects_.back()->setIndex(id);
555  mixedObjects_.back()->setId(getNumberOfObjects()-1);
556  mixedObjects_.back()->mixAll(S,getObject(id));
557  }
558  S->setHandler(this);
562 }
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.cc:106
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:210
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:878
ParticleSpecies * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
virtual void addObject(T *O)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:284
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
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 485 of file SpeciesHandler.cc.

Referenced by getMixedObject(), and removeObject().

486 {
487  unsigned int maxId = std::max(id1,id2);
488  return (maxId*(maxId-1))/2 + std::min(id1,id2);
489 }
template<class U >
U::MixedSpeciesType * SpeciesHandler::getMixedObject ( const U *  S,
const U *  T 
)
Parameters
[in]SA pointer to the first ParticleSpecies.
[in]TA pointer to the second ParticleSpecies.
Returns
A pointer to the MixedSpecies between the ParticleSpecies S and T.

Definition at line 496 of file SpeciesHandler.cc.

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

497 {
498  return dynamic_cast<typename U::MixedSpeciesType*>(getMixedObject(S->getIndex(),T->getIndex()));
499 }
U::MixedSpeciesType * 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 516 of file SpeciesHandler.cc.

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

517 {
518  if (id1 == id2)
519  {
520  return getObject(id1);
521  }
522  else
523  {
524  if (std::max(id1,id2) >= getNumberOfObjects())
525  {
526  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());
527  return nullptr;
528  }
529  else
530  {
531  return mixedObjects_[getMixedId(id1,id2)];
532  }
533  }
534 }
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 504 of file SpeciesHandler.cc.

References mixedObjects_.

505 {
506  return mixedObjects_;
507 }
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 619 of file SpeciesHandler.cc.

620 {
621  return "SpeciesHandler";
622 }
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 87 of file SpeciesHandler.cc.

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

88 {
89  if (this != &rhs)
90  {
91  clear();
93  for (BaseSpecies* mixSpec : mixedObjects_)
94  {
95  delete mixSpec;
96  }
97  mixedObjects_.clear();
98  for (BaseSpecies* mixSpec : rhs.mixedObjects_)
99  {
100  mixedObjects_.push_back(mixSpec->copy());
101  mixedObjects_.back()->setHandler(this);
102  }
103  }
104 
105  logger(DEBUG, "SpeciesHandler SpeciesHandler::operator =(const SpeciesHandler& rhs)");
106  return *this;
107 }
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 130 of file SpeciesHandler.cc.

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

131 {
132  std::string type;
133  is >> type;
134  if (type == "LinearViscoelasticSpecies")
135  {
137  is >> species;
138  copyAndAddObject(species);
139  }
140  else if (type == "LinearPlasticViscoelasticSpecies")
141  {
143  is >> species;
144  copyAndAddObject(species);
145  }
146  else if (type == "LinearViscoelasticSlidingFrictionSpecies")
147  {
149  is >> species;
150  copyAndAddObject(species);
151  }
152  else if (type == "LinearPlasticViscoelasticSlidingFrictionSpecies")
153  {
155  is >> species;
156  copyAndAddObject(species);
157  }
158  else if (type == "LinearViscoelasticFrictionSpecies")
159  {
161  is >> species;
162  copyAndAddObject(species);
163  }
164  else if (type == "LinearPlasticViscoelasticFrictionSpecies")
165  {
167  is >> species;
168  copyAndAddObject(species);
169  }
170  else if (type == "LinearViscoelasticIrreversibleAdhesiveSpecies")
171  {
173  is >> species;
174  copyAndAddObject(species);
175  }
176  else if (type == "LinearPlasticViscoelasticIrreversibleAdhesiveSpecies")
177  {
179  is >> species;
180  copyAndAddObject(species);
181  }
182  else if (type == "LinearViscoelasticSlidingFrictionIrreversibleAdhesiveSpecies")
183  {
185  is >> species;
186  copyAndAddObject(species);
187  }
188  else if (type == "LinearPlasticViscoelasticSlidingFrictionIrreversibleAdhesiveSpecies")
189  {
191  is >> species;
192  copyAndAddObject(species);
193  }
194  else if (type == "LinearViscoelasticFrictionIrreversibleAdhesiveSpecies")
195  {
197  is >> species;
198  copyAndAddObject(species);
199  }
200  else if (type == "LinearPlasticViscoelasticFrictionIrreversibleAdhesiveSpecies")
201  {
203  is >> species;
204  copyAndAddObject(species);
205  }
206  else if (type == "LinearViscoelasticReversibleAdhesiveSpecies")
207  {
209  is >> species;
210  copyAndAddObject(species);
211  }
212  else if (type == "LinearPlasticViscoelasticReversibleAdhesiveSpecies")
213  {
215  is >> species;
216  copyAndAddObject(species);
217  }
218  else if (type == "LinearViscoelasticSlidingFrictionReversibleAdhesiveSpecies")
219  {
221  is >> species;
222  copyAndAddObject(species);
223  }
224  else if (type == "LinearPlasticViscoelasticSlidingFrictionReversibleAdhesiveSpecies")
225  {
227  is >> species;
228  copyAndAddObject(species);
229  }
230  else if (type == "LinearViscoelasticFrictionReversibleAdhesiveSpecies")
231  {
233  is >> species;
234  copyAndAddObject(species);
235  }
236  else if (type == "LinearPlasticViscoelasticFrictionReversibleAdhesiveSpecies")
237  {
239  is >> species;
240  copyAndAddObject(species);
241  }
242  else if (type == "LinearViscoelasticFrictionLiquidBridgeWilletSpecies")
243  {
245  is >> species;
246  copyAndAddObject(species);
247  }
248  else if (type == "k") //for backwards compatibility
249  {
251  }
252  else
253  {
254  std::stringstream line(std::stringstream::in | std::stringstream::out);
256  logger(ERROR, "Species type % not understood in restart file. %", type, line.str());
257  }
258 
259  //remove the default mixed species
260  for (unsigned int i = 0; i + 1 < getNumberOfObjects(); i++)
261  {
268  delete mixedObjects_.back();
269  mixedObjects_.pop_back();
270  }
271 
272  //Read the mixed species.
273  for (unsigned int i = 0; i+1 < getNumberOfObjects(); i++)
274  {
275  is >> type;
276  if (type == "LinearViscoelasticMixedSpecies")
277  {
279  is >> species;
280  mixedObjects_.push_back(species.copy());
281  }
282  else if (type == "LinearPlasticViscoelasticMixedSpecies")
283  {
285  is >> species;
286  mixedObjects_.push_back(species.copy());
287  }
288  else if (type == "LinearViscoelasticSlidingFrictionMixedSpecies")
289  {
291  is >> species;
292  mixedObjects_.push_back(species.copy());
293  }
294  else if (type == "LinearPlasticViscoelasticSlidingFrictionMixedSpecies")
295  {
297  is >> species;
298  mixedObjects_.push_back(species.copy());
299  }
300  else if (type == "LinearViscoelasticFrictionMixedSpecies")
301  {
303  is >> species;
304  mixedObjects_.push_back(species.copy());
305  }
306  else if (type == "LinearPlasticViscoelasticFrictionMixedSpecies")
307  {
309  is >> species;
310  mixedObjects_.push_back(species.copy());
311  }
312  else if (type == "LinearViscoelasticIrreversibleAdhesiveMixedSpecies")
313  {
315  is >> species;
316  mixedObjects_.push_back(species.copy());
317  }
318  else if (type == "LinearPlasticViscoelasticIrreversibleAdhesiveMixedSpecies")
319  {
321  is >> species;
322  mixedObjects_.push_back(species.copy());
323  }
324  else if (type == "LinearViscoelasticSlidingFrictionIrreversibleAdhesiveMixedSpecies")
325  {
327  is >> species;
328  mixedObjects_.push_back(species.copy());
329  }
330  else if (type == "LinearPlasticViscoelasticSlidingFrictionIrreversibleAdhesiveMixedSpecies")
331  {
333  is >> species;
334  mixedObjects_.push_back(species.copy());
335  }
336  else if (type == "LinearViscoelasticFrictionIrreversibleAdhesiveMixedSpecies")
337  {
339  is >> species;
340  mixedObjects_.push_back(species.copy());
341  }
342  else if (type == "LinearPlasticViscoelasticFrictionIrreversibleAdhesiveMixedSpecies")
343  {
345  is >> species;
346  mixedObjects_.push_back(species.copy());
347  }
348  else if (type == "LinearViscoelasticReversibleAdhesiveMixedSpecies")
349  {
351  is >> species;
352  mixedObjects_.push_back(species.copy());
353  }
354  else if (type == "LinearPlasticViscoelasticReversibleAdhesiveMixedSpecies")
355  {
357  is >> species;
358  mixedObjects_.push_back(species.copy());
359  }
360  else if (type == "LinearViscoelasticSlidingFrictionReversibleAdhesiveMixedSpecies")
361  {
363  is >> species;
364  mixedObjects_.push_back(species.copy());
365  }
366  else if (type == "LinearPlasticViscoelasticSlidingFrictionReversibleAdhesiveMixedSpecies")
367  {
369  is >> species;
370  mixedObjects_.push_back(species.copy());
371  }
372  else if (type == "LinearViscoelasticFrictionReversibleAdhesiveMixedSpecies")
373  {
375  is >> species;
376  mixedObjects_.push_back(species.copy());
377  }
378  else if (type == "LinearPlasticViscoelasticFrictionReversibleAdhesiveMixedSpecies")
379  {
381  is >> species;
382  }
383  else if (type == "LinearViscoelasticFrictionLiquidBridgeWilletMixedSpecies")
384  {
386  is >> species;
387  }
388  else if (type == "k") //for backwards compatibility
389  {
390  mixedObjects_.push_back(readOldObject(is));
391  }
392  else
393  {
394  logger(ERROR, "Species type: % not understood in restart file", type);
395  }
396  }
397 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
U * copyAndAddObject(const U &O)
Creates a copy of a Object and adds it to the BaseHandler.
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:389
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::vector< BaseSpecies * > mixedObjects_
The list of pointers to the mixed species.
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
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 407 of file SpeciesHandler.cc.

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

Referenced by readObject().

408 {
409  //read in next line
410  std::stringstream line(std::stringstream::in | std::stringstream::out);
412 
413  //read each property
414  std::string property;
415  unsigned int particleDimension=0;
416  Mdouble density=0.0, stiffness=0.0, dissipation=0.0, slidingFrictionCoefficient=0.0, slidingFrictionCoefficientStatic=0.0, slidingStiffness=0.0, slidingDissipation=0.0;
417  line >> stiffness;
418  while (true)
419  {
420  line >> property;
421  if (property == "disp")
422  line >> dissipation;
423  else if (property == "rho")
424  line >> density;
425  else if (property == "kt")
426  line >> slidingStiffness;
427  else if (property == "dispt")
428  line >> slidingDissipation;
429  else if (property == "mu")
430  line >> slidingFrictionCoefficient;
431  else if (property == "mus")
432  line >> slidingFrictionCoefficientStatic;
433  else if (property == "dim_particle")
434  {
435  line >> particleDimension;
436  getDPMBase()->setParticleDimensions(particleDimension);
437  }
438  else if (property == "(mixed)")
439  {
440  density = 0;
441  }
442  else
443  {
444  logger(WARN, "Warning: % is not a species property", property);
445  break;
446  }
447  if (line.eof())
448  break;
449  }
450 
451  //create the correct species
452  if (slidingFrictionCoefficient == 0.0)
453  {
455  species->setDensity(density);
456  species->setStiffness(stiffness);
457  species->setDissipation(dissipation);
458  return species;
459  }
460  else
461  {
463  species->setDensity(density);
464  species->setStiffness(stiffness);
465  species->setDissipation(dissipation);
466  species->setSlidingStiffness(slidingStiffness);
467  species->setSlidingDissipation(slidingDissipation);
468  species->setSlidingFrictionCoefficient(slidingFrictionCoefficient);
469  if (slidingFrictionCoefficientStatic == 0.0)
470  slidingFrictionCoefficientStatic = slidingFrictionCoefficient;
471  species->setSlidingFrictionCoefficientStatic(slidingFrictionCoefficientStatic);
472  return species;
473  }
474 }
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:474
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:389
void setDensity(Mdouble density)
Allows the 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  id)
virtual

Remove the ParticleSpecies with given id.

Parameters
[in]idThe identity of the ParticleSpecies that must be removed.

First remove the object itself, then remove all mixed species for this ParticleSpecies.

Reimplemented from BaseHandler< ParticleSpecies >.

Definition at line 569 of file SpeciesHandler.cc.

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

570 {
572  for (unsigned int id2 = 0; id2 < getNumberOfObjects(); ++id2)
573  {
574  mixedObjects_.erase(mixedObjects_.begin()+getMixedId(id, id2));
575  }
577 }
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:210
virtual void removeObject(unsigned const int id)
Removes an Object from the BaseHandler.
Definition: BaseHandler.h:303
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 627 of file SpeciesHandler.cc.

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

Referenced by addObject(), and removeObject().

628 {
629  for (unsigned int i = 0; i < getNumberOfObjects(); i++)
630  {
631  if (getObject(i)->getUseAngularDOFs())
632  return true;
633  for (unsigned int j = 0; j + 1 < i; j++)
634  {
635  if (getMixedObject(i, j)->getUseAngularDOFs())
636  return true;
637  }
638  }
639  return false;
640 }
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.
U::MixedSpeciesType * 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 583 of file SpeciesHandler.cc.

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

Referenced by DPMBase::write().

584 {
585  os << "Species " << getNumberOfObjects() << std::endl;
586  std::vector<BaseSpecies*>::const_iterator it2 = mixedObjects_.begin();
587  for (std::vector<ParticleSpecies*>::const_iterator it = begin(); it != end(); ++it)
588  {
589  os << (**it) << std::endl;
590  for (unsigned int id2 =0; id2 < (*it)->getIndex(); id2++)
591  {
592  os << (**it2) << std::endl;
593  it2++;
594  }
595  }
596  /*
597  This behaves like the code above but is actually readable
598  @weinhartt is there a reason?
599 
600  there is a reason. Curernt architecture does not allow this
601  \todo define new restart format. @dducks
602 
603  The code is written such that it writes PS0, then PS1 and MS01, then PS2 and
604  MS02, MS12, and so on (PS=ParticleSpecies, MS=MixedSpecies). We can change
605  the restart format, but we should write the read(os) function such that
606  it can also read the old format @weinhartt
607 
608  for (ParticleSpecies * spec : objects_) {
609  os << *spec << std::endl;
610  }
611  for (BaseSpecies * spec : mixedObjects_) {
612  os << *spec << std::endl;
613  }
614  */
615 }
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 93 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: