MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 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)
 
virtual void removeObject (unsigned const int index)
 Removes an Object from the BaseHandler. More...
 
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)
 This function sets the id and ensures that nextId is a bigger value than id. More...
 
void increaseId ()
 
unsigned int getNextId ()
 
void setNextId (unsigned int id)
 
DPMBasegetDPMBase ()
 Gets the problem that is solved using this handler. More...
 
DPMBasegetDPMBase () const
 Gets the problem that is solved using this handler and does not change the class. More...
 
virtual void writeVTK () const
 now empty function for writing VTK files. More...
 
unsigned getNextGroupId ()
 Should be called each time you assign a groupId. Returns the value of nextGroupId_ and increases nextGroupId_ by one. More...
 

Private Attributes

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

Additional Inherited Members

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

Detailed Description

Container to store all ParticleSpecies.

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

Definition at line 36 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 75 of file SpeciesHandler.cc.

References DEBUG, and logger.

76 {
77  logger(DEBUG, "SpeciesHandler::SpeciesHandler() finished");
78 }
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 86 of file SpeciesHandler.cc.

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

87 {
88  clear();
89  setDPMBase(other.getDPMBase());
91  for (BaseSpecies* mixSpec : other.mixedObjects_)
92  {
93  mixedObjects_.push_back(mixSpec->copy());
94  mixedObjects_.back()->setHandler(this);
95  }
96  logger(DEBUG, "SpeciesHandler::SpeciesHandler(const SpeciesHandler &other) finished");
97 }
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:49
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.
void clear() override
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
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:725
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.

Definition at line 132 of file SpeciesHandler.cc.

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

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

Member Function Documentation

void SpeciesHandler::addObject ( ParticleSpecies S)
overridevirtual

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

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 readAndAddObject(), and DPMBase::readParAndIniFiles().

783 {
785  //logger(INFO, "Part / Mix: % / %", objects_.size(), mixedObjects_.size());
787  S->setHandler(this);
788  for (unsigned int id = 0; id + 1 < getNumberOfObjects(); ++id)
789  {
790  mixedObjects_.push_back(S->copyMixed());
791  mixedObjects_.back()->setIndex(id);
792  mixedObjects_.back()->setId(getNumberOfObjects() - 1);
793  mixedObjects_.back()->mixAll(S, getObject(id));
794  }
798 }
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.h:118
void setMaxInteractionDistance(Mdouble interactionDistance=0)
Sets maxInteractionDistance_.
void computeAllMasses(unsigned int indSpecies)
Computes the mass for all BaseParticle of the given species in this ParticleHandler.
Mdouble getInteractionDistance() const
returns the largest separation distance at which adhesive short-range forces can occur.
Definition: BaseSpecies.h:146
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:1329
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.
virtual unsigned int getNumberOfObjects() const
Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles) ...
void setHandler(SpeciesHandler *handler)
Sets the pointer to the handler to which this species belongs.
Definition: BaseSpecies.cc:91
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:431
void setRotation(bool rotation)
Sets whether particle rotation is enabled or disabled.
Definition: DPMBase.h:538
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
bool useAngularDOFs()
Check if angular DOF have to be used.
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 >.

Definition at line 54 of file SpeciesHandler.h.

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

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

55  {
57  mixedObjects_.clear();
58  }
std::vector< BaseSpecies * > mixedObjects_
The list of pointers to the mixed species.
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
Definition: BaseHandler.h:528
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.

Definition at line 727 of file SpeciesHandler.cc.

Referenced by getMixedObject(), and removeObject().

728 {
729  unsigned int maxId = std::max(id1, id2);
730  return (maxId * (maxId - 1)) / 2 + std::min(id1, id2);
731 }
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 74 of file SpeciesHandler.h.

Referenced by InteractionHandler::addInteraction(), NurbsWall::getDistanceAndNormal(), Screw::getDistanceAndNormal(), IntersectionOfWalls::getDistanceAndNormal(), InteractionHandler::getInteraction(), SuperQuadricParticle::getInteractionRadius(), SuperQuadricParticle::getInteractionWith(), ParticleSpecies::getMixedSpecies(), ParticleSpecies::setMaxInteractionDistance(), and useAngularDOFs().

75  {
76  return static_cast<typename U::MixedSpeciesType*>(getMixedObject(S->getIndex(), T->getIndex()));
77  }
std::enable_if<!std::is_pointer< typename U::MixedSpeciesType >::value, typename U::MixedSpeciesType * >::type getMixedObject(const U *S, const U *T)
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.

Definition at line 748 of file SpeciesHandler.cc.

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

749 {
750  if (id1 == id2)
751  {
752  return getObject(id1);
753  }
754  else
755  {
756  const unsigned int mixedId = getMixedId(id1, id2);
757  if (mixedId>=mixedObjects_.size())
758  {
759  logger(WARN,
760  "In: Object* SpeciesHandler::getMixedObject(const unsigned int id) const. No Object exist with index %, number of objects is %",
761  std::max(id1, id2), getNumberOfObjects());
762  return nullptr;
763  }
764  else
765  {
766  return mixedObjects_[mixedId];
767  }
768  }
769 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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.
virtual unsigned int getNumberOfObjects() const
Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles) ...
unsigned int getMixedId(unsigned int id1, unsigned int id2) const
Gets the Id of the behaviour between two given species.
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 736 of file SpeciesHandler.cc.

References mixedObjects_.

Referenced by BaseSpecies::setInteractionDistance().

737 {
738  return mixedObjects_;
739 }
std::vector< BaseSpecies * > mixedObjects_
The list of pointers to the mixed species.
std::string SpeciesHandler::getName ( ) const
overridevirtual

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

Returns
The string "SpeciesHandler"

Implements BaseHandler< ParticleSpecies >.

Definition at line 840 of file SpeciesHandler.cc.

841 {
842  return "SpeciesHandler";
843 }
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 106 of file SpeciesHandler.cc.

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

107 {
108  if (this != &rhs)
109  {
110  clear();
112  for (BaseSpecies* mixSpec : mixedObjects_)
113  {
114  delete mixSpec;
115  }
116  mixedObjects_.clear();
117  for (BaseSpecies* mixSpec : rhs.mixedObjects_)
118  {
119  mixedObjects_.push_back(mixSpec->copy());
120  mixedObjects_.back()->setHandler(this);
121  }
122  }
123 
124  logger(DEBUG, "SpeciesHandler SpeciesHandler::operator =(const SpeciesHandler& rhs)");
125  return *this;
126 }
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:49
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
std::vector< BaseSpecies * > mixedObjects_
The list of pointers to the mixed species.
void clear() override
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
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 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 >.

Definition at line 152 of file SpeciesHandler.cc.

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

153 {
154  std::string type;
155  is >> type;
156  logger(DEBUG, "SpeciesHandler::readAndAddObject(is): reading type %.", type);
157  if (type == "LinearViscoelasticSpecies")
158  {
160  is >> species;
161  copyAndAddObject(species);
162  }
163  else if (type == "LinearPlasticViscoelasticSpecies")
164  {
166  is >> species;
167  copyAndAddObject(species);
168  }
169  else if (type == "SinterSpecies")
170  {
171  SinterSpecies species;
172  is >> species;
173  copyAndAddObject(species);
174  }
175  else if (type == "SinterReversibleAdhesiveSpecies")
176  {
178  is >> species;
179  copyAndAddObject(species);
180  }
181  else if (type == "SinterFrictionReversibleAdhesiveSpecies")
182  {
184  is >> species;
185  copyAndAddObject(species);
186  }
187  else if (type == "SinterFrictionSpecies")
188  {
189  SinterFrictionSpecies species;
190  is >> species;
191  copyAndAddObject(species);
192  }
193  else if (type == "HertzianSinterSpecies")
194  {
195  HertzianSinterSpecies species;
196  is >> species;
197  copyAndAddObject(species);
198  }
199  else if (type == "HertzianSinterFrictionSpecies")
200  {
202  is >> species;
203  copyAndAddObject(species);
204  }
205  else if (type == "HertzianSinterSlidingFrictionSpecies")
206  {
208  is >> species;
209  copyAndAddObject(species);
210  }
211  else if (type == "LinearViscoelasticSlidingFrictionSpecies")
212  {
214  is >> species;
215  copyAndAddObject(species);
216  }
217  else if (type == "LinearPlasticViscoelasticSlidingFrictionSpecies")
218  {
220  is >> species;
221  copyAndAddObject(species);
222  }
223  else if (type == "LinearViscoelasticFrictionSpecies")
224  {
226  is >> species;
227  copyAndAddObject(species);
228  }
229  else if (type == "LinearPlasticViscoelasticFrictionSpecies")
230  {
232  is >> species;
233  copyAndAddObject(species);
234  }
235  else if (type == "LinearViscoelasticIrreversibleAdhesiveSpecies")
236  {
238  is >> species;
239  copyAndAddObject(species);
240  }
241  else if (type == "LinearViscoelasticBondedSpecies")
242  {
244  is >> species;
245  copyAndAddObject(species);
246  }
247  else if (type == "LinearPlasticViscoelasticIrreversibleAdhesiveSpecies")
248  {
250  is >> species;
251  copyAndAddObject(species);
252  }
253  else if (type == "LinearViscoelasticSlidingFrictionIrreversibleAdhesiveSpecies")
254  {
256  is >> species;
257  copyAndAddObject(species);
258  }
259  else if (type == "LinearPlasticViscoelasticSlidingFrictionIrreversibleAdhesiveSpecies")
260  {
262  is >> species;
263  copyAndAddObject(species);
264  }
265  else if (type == "LinearViscoelasticFrictionIrreversibleAdhesiveSpecies")
266  {
268  is >> species;
269  copyAndAddObject(species);
270  }
271  else if (type == "LinearPlasticViscoelasticFrictionIrreversibleAdhesiveSpecies")
272  {
274  is >> species;
275  copyAndAddObject(species);
276  }
277  else if (type == "LinearViscoelasticReversibleAdhesiveSpecies")
278  {
280  is >> species;
281  copyAndAddObject(species);
282  }
283  else if (type == "LinearPlasticViscoelasticReversibleAdhesiveSpecies")
284  {
286  is >> species;
287  copyAndAddObject(species);
288  }
289  else if (type == "LinearViscoelasticSlidingFrictionReversibleAdhesiveSpecies")
290  {
292  is >> species;
293  copyAndAddObject(species);
294  }
295  else if (type == "LinearPlasticViscoelasticSlidingFrictionReversibleAdhesiveSpecies")
296  {
298  is >> species;
299  copyAndAddObject(species);
300  }
301  else if (type == "LinearViscoelasticFrictionReversibleAdhesiveSpecies")
302  {
304  is >> species;
305  copyAndAddObject(species);
306  }
307  else if (type == "LinearPlasticViscoelasticFrictionReversibleAdhesiveSpecies")
308  {
310  is >> species;
311  copyAndAddObject(species);
312  }
313  else if (type == "LinearViscoelasticFrictionLiquidBridgeWilletSpecies")
314  {
316  is >> species;
317  copyAndAddObject(species);
318  }
319  else if (type == "LinearViscoelasticFrictionLiquidMigrationWilletSpecies")
320  {
322  is >> species;
323  copyAndAddObject(species);
324  }
325  else if (type == "LinearPlasticViscoelasticSlidingFrictionLiquidMigrationWilletSpecies")
326  {
328  is >> species;
329  copyAndAddObject(species);
330  }
331  else if (type == "HertzianViscoelasticMindlinSpecies")
332  {
334  is >> species;
335  copyAndAddObject(species);
336  }
337  else if (type == "HertzianViscoelasticMindlinRollingTorsionSpecies" ||
338  type == "HertzianViscoelasticFrictionSpecies")
339  {
341  is >> species;
342  copyAndAddObject(species);
343  }
344  else if (type == "HertzianViscoelasticFrictionChargedBondedSpecies")
345  {
347  is >> species;
348  copyAndAddObject(species);
349  }
350  else if (type == "LinearViscoelasticFrictionChargedBondedSpecies")
351  {
353  is >> species;
354  copyAndAddObject(species);
355  }
356  else if (type == "ThermalSinterSlidingFrictionSpecies")
357  {
359  is >> species;
360  copyAndAddObject(species);
361  }
362  else if (type == "ThermalSinterFrictionSpecies")
363  {
365  is >> species;
366  copyAndAddObject(species);
367  }
368  else if (type == "LinearPlasticViscoelasticFrictionLiquidBridgeWilletSpecies")
369  {
371  is >> species;
372  copyAndAddObject(species);
373  }
374  else if (type == "k") //for backwards compatibility
375  {
377  }
378  else
379  {
380  logger(WARN,
381  "Species type % not understood in restart file: You need to add this species to SpeciesHandler::readObject.",
382  type);
383  std::stringstream line;
386  }
387 
388  //remove the default mixed species
389  for (unsigned int i = 0; i + 1 < getNumberOfObjects(); i++)
390  {
397  delete mixedObjects_.back();
398  mixedObjects_.pop_back();
399  }
400 
401  //Read the mixed species.
402  for (unsigned int i = 0; i + 1 < getNumberOfObjects(); i++)
403  {
404  is >> type;
405  if (type == "LinearViscoelasticMixedSpecies")
406  {
408  is >> species;
409  mixedObjects_.push_back(species.copy());
410  }
411  else if (type == "LinearPlasticViscoelasticMixedSpecies")
412  {
414  is >> species;
415  mixedObjects_.push_back(species.copy());
416  }
417  else if (type == "SinterMixedSpecies")
418  {
419  SinterMixedSpecies species;
420  is >> species;
421  mixedObjects_.push_back(species.copy());
422  }
423  else if (type == "SinterReversibleAdhesiveMixedSpecies")
424  {
426  is >> species;
427  mixedObjects_.push_back(species.copy());
428  }
429  else if (type == "SinterFrictionReversibleAdhesiveMixedSpecies")
430  {
432  is >> species;
433  mixedObjects_.push_back(species.copy());
434  }
435  else if (type == "SinterFrictionMixedSpecies")
436  {
438  is >> species;
439  mixedObjects_.push_back(species.copy());
440  }
441  else if (type == "HertzianSinterMixedSpecies")
442  {
444  is >> species;
445  mixedObjects_.push_back(species.copy());
446  }
447  else if (type == "HertzianSinterFrictionMixedSpecies")
448  {
450  is >> species;
451  mixedObjects_.push_back(species.copy());
452  }
453  else if (type == "HertzianSinterSlidingFrictionMixedSpecies")
454  {
456  is >> species;
457  mixedObjects_.push_back(species.copy());
458  }
459  else if (type == "LinearViscoelasticSlidingFrictionMixedSpecies")
460  {
462  is >> species;
463  mixedObjects_.push_back(species.copy());
464  }
465  else if (type == "LinearPlasticViscoelasticSlidingFrictionMixedSpecies")
466  {
468  is >> species;
469  mixedObjects_.push_back(species.copy());
470  }
471  else if (type == "LinearViscoelasticFrictionMixedSpecies")
472  {
474  is >> species;
475  mixedObjects_.push_back(species.copy());
476  }
477  else if (type == "LinearPlasticViscoelasticFrictionMixedSpecies")
478  {
480  is >> species;
481  mixedObjects_.push_back(species.copy());
482  }
483  else if (type == "LinearViscoelasticIrreversibleAdhesiveMixedSpecies")
484  {
486  is >> species;
487  mixedObjects_.push_back(species.copy());
488  }
489  else if (type == "LinearViscoelasticBondedMixedSpecies")
490  {
492  is >> species;
493  mixedObjects_.push_back(species.copy());
494  }
495  else if (type == "LinearPlasticViscoelasticIrreversibleAdhesiveMixedSpecies")
496  {
498  is >> species;
499  mixedObjects_.push_back(species.copy());
500  }
501  else if (type == "LinearViscoelasticSlidingFrictionIrreversibleAdhesiveMixedSpecies")
502  {
504  is >> species;
505  mixedObjects_.push_back(species.copy());
506  }
507  else if (type == "LinearPlasticViscoelasticSlidingFrictionIrreversibleAdhesiveMixedSpecies")
508  {
510  is >> species;
511  mixedObjects_.push_back(species.copy());
512  }
513  else if (type == "LinearViscoelasticFrictionIrreversibleAdhesiveMixedSpecies")
514  {
516  is >> species;
517  mixedObjects_.push_back(species.copy());
518  }
519  else if (type == "LinearPlasticViscoelasticFrictionIrreversibleAdhesiveMixedSpecies")
520  {
522  is >> species;
523  mixedObjects_.push_back(species.copy());
524  }
525  else if (type == "LinearPlasticViscoelasticSlidingFrictionLiquidMigrationWilletMixedSpecies")
526  {
528  is >> species;
529  mixedObjects_.push_back(species.copy());
530  }
531  else if (type == "LinearPlasticViscoelasticFrictionLiquidBridgeWilletMixedSpecies")
532  {
534  is >> species;
535  mixedObjects_.push_back(species.copy());
536  }
537  else if (type == "LinearViscoelasticReversibleAdhesiveMixedSpecies")
538  {
540  is >> species;
541  mixedObjects_.push_back(species.copy());
542  }
543  else if (type == "LinearPlasticViscoelasticReversibleAdhesiveMixedSpecies")
544  {
546  is >> species;
547  mixedObjects_.push_back(species.copy());
548  }
549  else if (type == "LinearViscoelasticSlidingFrictionReversibleAdhesiveMixedSpecies")
550  {
552  is >> species;
553  mixedObjects_.push_back(species.copy());
554  }
555  else if (type == "LinearPlasticViscoelasticSlidingFrictionReversibleAdhesiveMixedSpecies")
556  {
558  is >> species;
559  mixedObjects_.push_back(species.copy());
560  }
561  else if (type == "LinearViscoelasticFrictionReversibleAdhesiveMixedSpecies")
562  {
564  is >> species;
565  mixedObjects_.push_back(species.copy());
566  }
567  else if (type == "LinearPlasticViscoelasticFrictionReversibleAdhesiveMixedSpecies")
568  {
570  is >> species;
571  mixedObjects_.push_back(species.copy());
572  }
573  else if (type == "LinearViscoelasticFrictionLiquidBridgeWilletMixedSpecies")
574  {
576  is >> species;
577  mixedObjects_.push_back(species.copy());
578  }
579  else if (type == "LinearViscoelasticFrictionLiquidMigrationWilletMixedSpecies")
580  {
582  is >> species;
583  mixedObjects_.push_back(species.copy());
584  }
585  else if (type == "HertzianViscoelasticMindlinMixedSpecies")
586  {
588  is >> species;
589  mixedObjects_.push_back(species.copy());
590  }
591  else if (type == "HertzianViscoelasticMindlinRollingTorsionMixedSpecies" ||
592  type == "HertzianViscoelasticFrictionMixedSpecies")
593  {
595  is >> species;
596  mixedObjects_.push_back(species.copy());
597  }
598  else if (type == "HertzianViscoelasticFrictionChargedBondedMixedSpecies")
599  {
601  is >> species;
602  mixedObjects_.push_back(species.copy());
603  }
604  else if (type == "LinearViscoelasticFrictionChargedBondedMixedSpecies")
605  {
607  is >> species;
608  mixedObjects_.push_back(species.copy());
609  }
610  else if (type == "ThermalSinterSlidingFrictionMixedSpecies")
611  {
613  is >> species;
614  mixedObjects_.push_back(species.copy());
615  }
616  else if (type == "ThermalSinterFrictionMixedSpecies")
617  {
619  is >> species;
620  mixedObjects_.push_back(species.copy());
621  }
622  else if (type == "ThermalSinterFrictionMixedSpecies")
623  {
625  is >> species;
626  mixedObjects_.push_back(species.copy());
627  }
628  else
629  {
630  logger(WARN,
631  "Species type % not understood in restart file: You need to add this species to SpeciesHandler::readMixedObject.",
632  type);
633  std::stringstream line;
636  mixedObjects_.push_back(species.copy());
637  }
638  }
639 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
FrictionSpecies contains the parameters used to describe sliding, rolling and torsional friction...
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
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:424
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.
Species< LinearViscoelasticNormalSpecies > LinearViscoelasticSpecies
virtual unsigned int getNumberOfObjects() const
Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles) ...
MixedSpecies< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies > * copy() const final
Creates a deep copy of the MixedSpecies from which it is called.
Definition: MixedSpecies.h:145
SlidingFrictionSpecies contains the parameters used to describe sliding friction. ...
Contains contact force properties for contacts between particles with two different species...
Definition: MixedSpecies.h:42
Contains material and contact force properties.
Definition: Interaction.h:42
void addObject(ParticleSpecies *S) override
Adds a new ParticleSpecies to the SpeciesHandler.
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 649 of file SpeciesHandler.cc.

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

Referenced by readAndAddObject().

650 {
651  //read in next line
652  std::stringstream line;
654 
655  //read each property
656  std::string property;
657  unsigned int particleDimension = 0;
658  Mdouble density = 0.0, stiffness = 0.0, dissipation = 0.0, slidingFrictionCoefficient = 0.0, slidingFrictionCoefficientStatic = 0.0, slidingStiffness = 0.0, slidingDissipation = 0.0;
659  line >> stiffness;
660  while (true)
661  {
662  line >> property;
663  if (property == "disp")
664  line >> dissipation;
665  else if (property == "rho")
666  line >> density;
667  else if (property == "kt")
668  line >> slidingStiffness;
669  else if (property == "dispt")
670  line >> slidingDissipation;
671  else if (property == "mu")
672  line >> slidingFrictionCoefficient;
673  else if (property == "mus")
674  line >> slidingFrictionCoefficientStatic;
675  else if (property == "dim_particle")
676  {
677  line >> particleDimension;
678  getDPMBase()->setParticleDimensions(particleDimension);
679  }
680  else if (property == "(mixed)")
681  {
682  density = 0;
683  }
684  else
685  {
686  logger(WARN, "Warning: % is not a species property", property);
687  break;
688  }
689  if (line.eof())
690  break;
691  }
692 
693  //create the correct species
694  if (slidingFrictionCoefficient == 0.0)
695  {
697  species->setDensity(density);
698  species->setStiffness(stiffness);
699  species->setDissipation(dissipation);
700  return species;
701  }
702  else
703  {
705  species->setDensity(density);
706  species->setStiffness(stiffness);
707  species->setDissipation(dissipation);
708  species->setSlidingStiffness(slidingStiffness);
709  species->setSlidingDissipation(slidingDissipation);
710  species->setSlidingFrictionCoefficient(slidingFrictionCoefficient);
711  if (slidingFrictionCoefficientStatic == 0.0)
712  slidingFrictionCoefficientStatic = slidingFrictionCoefficient;
713  species->setSlidingFrictionCoefficientStatic(slidingFrictionCoefficientStatic);
714  return species;
715  }
716 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Definition: GeneralDefine.h:34
void setParticleDimensions(unsigned int particleDimensions)
Sets the particle dimensionality.
Definition: DPMBase.cc:1408
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:424
void setDensity(Mdouble density)
Allows density_ to be changed.
Species< LinearViscoelasticNormalSpecies > LinearViscoelasticSpecies
Contains material and contact force properties.
Definition: Interaction.h:42
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void SpeciesHandler::removeObject ( unsigned int  index)
override

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.

Definition at line 807 of file SpeciesHandler.cc.

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

808 {
810  for (unsigned int index2 = 0; index2 < getNumberOfObjects(); ++index2)
811  {
812  mixedObjects_.erase(mixedObjects_.begin() + getMixedId(index, index2));
813  }
815 }
virtual void removeObject(unsigned const int index)
Removes an Object from the BaseHandler.
Definition: BaseHandler.h:472
std::vector< BaseSpecies * > mixedObjects_
The list of pointers to the mixed species.
virtual unsigned int getNumberOfObjects() const
Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles) ...
void setRotation(bool rotation)
Sets whether particle rotation is enabled or disabled.
Definition: DPMBase.h:538
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
bool useAngularDOFs()
Check if angular DOF have to be used.
unsigned int getMixedId(unsigned int id1, unsigned int id2) const
Gets the Id of the behaviour between two given species.
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 848 of file SpeciesHandler.cc.

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

Referenced by addObject(), and removeObject().

849 {
850  for (unsigned int i = 0; i < getSize(); i++)
851  {
852  if (getObject(i)->getUseAngularDOFs())
853  return true;
854  for (unsigned int j = 0; j + 1 < i; j++)
855  {
856  if (getMixedObject(i, j)->getUseAngularDOFs())
857  return true;
858  }
859  }
860  return false;
861 }
std::enable_if<!std::is_pointer< typename U::MixedSpeciesType >::value, typename U::MixedSpeciesType * >::type getMixedObject(const U *S, const U *T)
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
ParticleSpecies * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
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 822 of file SpeciesHandler.cc.

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

Referenced by DPMBase::write().

823 {
824  os << "Species " << getNumberOfObjects() << std::endl;
825  unsigned idMixed = 0;
826  for (const ParticleSpecies* species : objects_)
827  {
828  os << *species << std::endl;
829  for (unsigned int id2 = 0; id2 < species->getIndex(); id2++)
830  {
831  os << *mixedObjects_[idMixed] << std::endl;
832  idMixed++;
833  }
834  }
835 }
std::vector< ParticleSpecies * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
std::vector< BaseSpecies * > mixedObjects_
The list of pointers to the mixed species.
virtual unsigned int getNumberOfObjects() const
Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles) ...

Member Data Documentation

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

The list of pointers to the mixed species.

Definition at line 96 of file SpeciesHandler.h.

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


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