MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BaseSpecies Class Referenceabstract

BaseSpecies is the class from which all other species are derived. More...

#include <BaseSpecies.h>

+ Inheritance diagram for BaseSpecies:

Public Member Functions

 BaseSpecies ()
 The default constructor. More...
 
 BaseSpecies (BaseNormalForce *normalForce, BaseFrictionForce *frictionForce_, BaseAdhesiveForce *adhesiveForce)
 
 BaseSpecies (const BaseSpecies &p)
 The copy constructor. More...
 
 ~BaseSpecies ()
 The default destructor. More...
 
virtual BaseSpeciescopy () const =0
 Creates a deep copy of the object from which it is called. More...
 
virtual void copyInto (BaseSpecies *s) const =0
 
void setHandler (SpeciesHandler *handler)
 Sets the pointer to the handler to which this species belongs. More...
 
SpeciesHandlergetHandler () const
 Returns the pointer to the handler to which this species belongs. More...
 
virtual void mixAll (BaseSpecies *S, BaseSpecies *T)=0
 creates default values for mixed species More...
 
virtual bool getUseAngularDOFs () const =0
 Returns true if torques (i.e. angular degrees of freedom) have to be calculated. More...
 
virtual BaseInteractiongetNewInteraction (BaseInteractable *P, BaseInteractable *I, unsigned timeStamp) const =0
 returns new Interaction object. More...
 
virtual BaseInteractiongetEmptyInteraction () const =0
 
virtual void deleteEmptyInteraction (BaseInteraction *interaction) const =0
 
Mdouble getInteractionDistance () const
 returns the largest separation distance at which adhesive short-range forces can occur. More...
 
BaseNormalForcegetNormalForce () const
 
BaseFrictionForcegetFrictionForce () const
 
BaseAdhesiveForcegetAdhesiveForce () const
 
void setInteractionDistance (Mdouble interactionDistance)
 Sets BaseSpecies::interactionDistance_. More...
 
- Public Member Functions inherited from BaseObject
 BaseObject ()=default
 Default constructor. More...
 
 BaseObject (const BaseObject &p)=default
 Copy constructor, copies all the objects BaseObject contains. More...
 
virtual ~BaseObject ()=default
 virtual destructor More...
 
virtual std::string getName () const =0
 A purely virtual function. More...
 
virtual void moveInHandler (unsigned int index)
 Except that it is virtual, it does the same thing as setIndex() does. More...
 
void setIndex (unsigned int index)
 Allows one to assign an index to an object in the handler/container. More...
 
void setId (unsigned long id)
 Assigns a unique identifier to each object in the handler (container) which remains constant even after the object is deleted from the container/handler. More...
 
unsigned int getIndex () const
 Returns the index of the object in the handler. More...
 
unsigned int getId () const
 Returns the unique identifier of any particular object. More...
 
void setGroupId (unsigned groupId)
 
unsigned getGroupId () const
 

Static Public Member Functions

static Mdouble average (Mdouble a, Mdouble b)
 Returns the harmonic mean of two variables. More...
 
static Mdouble averageInf (Mdouble a, Mdouble b)
 Returns the harmonic mean of two variables, returning inf if either is inf. More...
 

Protected Member Functions

void write (std::ostream &os) const override
 Sets the boolean constantRestitution_. More...
 
void read (std::istream &is) override
 

Protected Attributes

BaseNormalForcenormalForce_
 A pointer to the normal force parameters This pointer is used by the Interaction's to get a pointer to the species The pointer is set in the constructors of SPecies and MixedSpecies. More...
 
BaseFrictionForcefrictionForce_
 A pointer to the friction force parameters This pointer is used by the Interaction's to get a pointer to the species The pointer is set in the constructors of SPecies and MixedSpecies. More...
 
BaseAdhesiveForceadhesiveForce_
 A pointer to the adhesive force parameters This pointer is used by the Interaction's to get a pointer to the species The pointer is set in the constructors of SPecies and MixedSpecies. More...
 

Private Attributes

SpeciesHandlerhandler_
 A pointer to the handler to which this species belongs. It is initialized to nullptr and gets set when SpeciesHandler::addObject() is called. More...
 
Mdouble interactionDistance_
 Returns the distance between particles of this species below which adhesive forces can occur (needed for contact detection) set by the adhesive species. More...
 

Detailed Description

BaseSpecies is the class from which all other species are derived.

A base species is almost empty, with the exception of a pointer to the particleHandler. All other properties get added in the inherited classes. See Species for more details.

Definition at line 49 of file BaseSpecies.h.

Constructor & Destructor Documentation

BaseSpecies::BaseSpecies ( )

The default constructor.

Definition at line 38 of file BaseSpecies.cc.

References DEBUG, and logger.

39  : BaseObject(), handler_(nullptr), interactionDistance_(0)
40 {
41  logger(DEBUG, "BaseSpecies::BaseSpecies() finished");
42 }
Mdouble interactionDistance_
Returns the distance between particles of this species below which adhesive forces can occur (needed ...
Definition: BaseSpecies.h:201
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
BaseObject()=default
Default constructor.
SpeciesHandler * handler_
A pointer to the handler to which this species belongs. It is initialized to nullptr and gets set whe...
Definition: BaseSpecies.h:195
BaseSpecies::BaseSpecies ( BaseNormalForce normalForce,
BaseFrictionForce frictionForce_,
BaseAdhesiveForce adhesiveForce 
)

Definition at line 44 of file BaseSpecies.cc.

References adhesiveForce_, DEBUG, frictionForce_, logger, normalForce_, and BaseForce::setBaseSpecies().

45  : BaseObject(), normalForce_(normalForce), frictionForce_(frictionForce), adhesiveForce_(adhesiveForce),
46  handler_(nullptr), interactionDistance_(0)
47 {
49  frictionForce_->setBaseSpecies(this);
51  logger(DEBUG, "BaseSpecies::BaseSpecies() finished");
52 }
void setBaseSpecies(BaseSpecies *baseSpecies)
Definition: BaseForce.h:40
Mdouble interactionDistance_
Returns the distance between particles of this species below which adhesive forces can occur (needed ...
Definition: BaseSpecies.h:201
BaseNormalForce * normalForce_
A pointer to the normal force parameters This pointer is used by the Interaction's to get a pointer ...
Definition: BaseSpecies.h:173
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
BaseObject()=default
Default constructor.
BaseAdhesiveForce * adhesiveForce_
A pointer to the adhesive force parameters This pointer is used by the Interaction's to get a pointe...
Definition: BaseSpecies.h:187
SpeciesHandler * handler_
A pointer to the handler to which this species belongs. It is initialized to nullptr and gets set whe...
Definition: BaseSpecies.h:195
BaseFrictionForce * frictionForce_
A pointer to the friction force parameters This pointer is used by the Interaction's to get a pointe...
Definition: BaseSpecies.h:180
BaseSpecies::BaseSpecies ( const BaseSpecies p)

The copy constructor.

Parameters
[in]pthe species that is copied

Definition at line 58 of file BaseSpecies.cc.

References DEBUG, and logger.

60 {
61  logger(DEBUG, "BaseSpecies::BaseSpecies(const BaseSpecies &p) finished");
62 }
Mdouble interactionDistance_
Returns the distance between particles of this species below which adhesive forces can occur (needed ...
Definition: BaseSpecies.h:201
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
BaseObject()=default
Default constructor.
SpeciesHandler * handler_
A pointer to the handler to which this species belongs. It is initialized to nullptr and gets set whe...
Definition: BaseSpecies.h:195
BaseSpecies::~BaseSpecies ( )

The default destructor.

Todo:
the BaseSpecies destructor should delete all particles and wall belonging to that species; however, that will break all codes replacing a species (e.g. Sudeshna and Hao) so we need a proper way to replace a species

Definition at line 64 of file BaseSpecies.cc.

References DEBUG, and logger.

65 {
69  //for now, I added a particleHandler.clear(); wallHandler.clear() before speciesHandler.clear() in DPMBase::read()
70 
71 // //if species gets removed, all particles/ walls of this type need to be removed as well
72 // if (getHandler()) {
73 // DPMBase* dpm = getHandler()->getDPMBase();
74 // for (const auto o : dpm->wallHandler) {
75 // if (o->getSpecies()==this) {
76 // dpm->wallHandler.removeObject(o->getIndex());
77 // }
78 // }
79 // for (const auto o : dpm->particleHandler) {
80 // if (o->getSpecies()==this) {
81 // dpm->particleHandler.removeObject(o->getIndex());
82 // }
83 // }
84 // }
85  logger(DEBUG, "BaseSpecies::~BaseSpecies() finished");
86 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")

Member Function Documentation

Mdouble BaseSpecies::average ( Mdouble  a,
Mdouble  b 
)
static

Returns the harmonic mean of two variables.

Returns the harmonic mean of two variables. This function is used to define default mixed species.

Parameters
[in]a,bThe two variables you want to average
Returns
The harmonic mean of a and b, \(\frac{2}{1/a+1/b}\)

Definition at line 110 of file BaseSpecies.cc.

Referenced by averageInf(), LiquidMigrationWilletSpecies::mix(), ReversibleAdhesiveSpecies::mix(), ChargedBondedSpecies::mix(), LiquidBridgeWilletSpecies::mix(), BondedSpecies::mix(), HertzianSinterNormalSpecies::mix(), LinearPlasticViscoelasticNormalSpecies::mix(), MindlinRollingTorsionSpecies::mix(), FrictionSpecies::mix(), SinterNormalSpecies::mix(), HertzianViscoelasticNormalSpecies::mix(), SlidingFrictionSpecies::mix(), LinearViscoelasticNormalSpecies::mix(), and MindlinSpecies::mix().

111 {
112  //the second algorithm seems to have a better accuracy, at least for the case average(2e5,2e5)
113  //return (a + b) != 0.0 ? (2. * (a * b) / (a + b)) : 0;
114  return (a==0||b==0) ? 0.0 : (2. / (1.0 / a + 1.0 / b));
115 }
Mdouble BaseSpecies::averageInf ( Mdouble  a,
Mdouble  b 
)
static

Returns the harmonic mean of two variables, returning inf if either is inf.

Returns the harmonic mean of two variables, returning inf if either is inf.

Definition at line 120 of file BaseSpecies.cc.

References average(), and constants::inf.

Referenced by FrictionSpecies::mix().

121 {
122  if (a == constants::inf || b == constants::inf)
123  return constants::inf;
124  else
125  return average(a, b);
126 }
const Mdouble inf
Definition: GeneralDefine.h:44
static Mdouble average(Mdouble a, Mdouble b)
Returns the harmonic mean of two variables.
Definition: BaseSpecies.cc:110
virtual BaseSpecies* BaseSpecies::copy ( ) const
pure virtual

Creates a deep copy of the object from which it is called.

Creates a deep copy of the Species, or MixedSpecies from which it is called. As this depends on the template parameters of Species, the definition of this function is in the Species class. It is defined as a virtual function here to allow the function to be called from a BaseSpecies pointer (which is the kind of pointer used for MixedSpecies).

To create a copy of a MixedSpecies, use

BaseSpecies* mixedSpecies->copy();

To create a copy of a Species, use

ParticleSpecies* species->copy();

Implemented in Species< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >, MixedSpecies< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >, and ParticleSpecies.

Referenced by SubcriticalMaserBoundary::addParticleToMaser(), SpeciesHandler::operator=(), and SpeciesHandler::SpeciesHandler().

virtual void BaseSpecies::copyInto ( BaseSpecies s) const
pure virtual
BaseFrictionForce* BaseSpecies::getFrictionForce ( ) const
inline
SpeciesHandler * BaseSpecies::getHandler ( ) const

Returns the pointer to the handler to which this species belongs.

Returns
the pointer to the handler to which this species belongs.

Definition at line 99 of file BaseSpecies.cc.

References handler_.

Referenced by BaseInteraction::BaseInteraction(), SuperQuadricParticle::getInteractionRadius(), SuperQuadricParticle::getInteractionWith(), ParticleSpecies::getLargestInverseParticleMassLocal(), ParticleSpecies::getMixedSpecies(), ParticleSpecies::getVolumeFromRadius(), ParticleSpecies::setDensity(), setInteractionDistance(), ParticleSpecies::setMaxInteractionDistance(), BaseInteractable::setSpecies(), BaseWall::setSpecies(), BaseParticle::setSpecies(), and BaseInteraction::writeInteraction().

100 {
101  return handler_;
102 }
SpeciesHandler * handler_
A pointer to the handler to which this species belongs. It is initialized to nullptr and gets set whe...
Definition: BaseSpecies.h:195
Mdouble BaseSpecies::getInteractionDistance ( ) const
inline

returns the largest separation distance at which adhesive short-range forces can occur.

returns the largest separation distance (negative overlap) at which (adhesive) short-range forces can occur (needed for contact detection). Defined in each of the AdhesiveForceSpecies It is defined as a virtual function here to allow the function to be called from a BaseSpecies pointer (which is the kind of pointer used for MixedSpecies).

Definition at line 146 of file BaseSpecies.h.

References interactionDistance_.

Referenced by SpeciesHandler::addObject(), NurbsWall::getDistanceAndNormal(), Screw::getDistanceAndNormal(), IntersectionOfWalls::getDistanceAndNormal(), and ChargedBondedInteraction::getElasticEnergy().

146 {return interactionDistance_;}
Mdouble interactionDistance_
Returns the distance between particles of this species below which adhesive forces can occur (needed ...
Definition: BaseSpecies.h:201
virtual BaseInteraction* BaseSpecies::getNewInteraction ( BaseInteractable P,
BaseInteractable I,
unsigned  timeStamp 
) const
pure virtual

returns new Interaction object.

As each Species has its own Interaction type, getNewInteraction can be used to access the right type of Interaction It is defined as a virtual function here to allow the function to be called from a BaseSpecies pointer (which is the kind of pointer used for MixedSpecies).

Implemented in Species< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >, and MixedSpecies< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >.

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

virtual bool BaseSpecies::getUseAngularDOFs ( ) const
pure virtual

Returns true if torques (i.e. angular degrees of freedom) have to be calculated.

returns true if torques have to be calculated. This is currently only true if a tangential force is applied, but can be true for non-spherical objects even if no tangential force is applied . Defined in FrictionForceSpecies. It is defined as a virtual function here to allow the function to be called from a BaseSpecies pointer (which is the kind of pointer used for MixedSpecies).

Implemented in Species< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >, and MixedSpecies< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >.

Referenced by SpeciesHandler::useAngularDOFs().

virtual void BaseSpecies::mixAll ( BaseSpecies S,
BaseSpecies T 
)
pure virtual

creates default values for mixed species

returns the largest separation distance (negative overlap) at which (adhesive) short-range forces can occur (needed for contact detection). Defined in each of the AdhesiveForceSpecies It is defined as a virtual function here to allow the function to be called from a BaseSpecies pointer (which is the kind of pointer used for MixedSpecies).

Implemented in Species< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >, and MixedSpecies< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >.

void BaseSpecies::read ( std::istream &  is)
overrideprotectedvirtual
Parameters
[in]isinput stream (typically the restart file)

Implements BaseObject.

Reimplemented in Species< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >, MixedSpecies< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >, and ParticleSpecies.

Definition at line 140 of file BaseSpecies.cc.

References normalForce_, helpers::readOptionalVariable(), and BaseNormalForce::setConstantRestitution().

Referenced by ParticleSpecies::read(), and MixedSpecies< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >::read().

141 {
142  //BaseObject::read(is);
143  bool constantRestitution;
144  if (helpers::readOptionalVariable(is, "constantRestitution", constantRestitution)) {
145  normalForce_->setConstantRestitution(constantRestitution);
146  }
147 }
BaseNormalForce * normalForce_
A pointer to the normal force parameters This pointer is used by the Interaction's to get a pointer ...
Definition: BaseSpecies.h:173
void setConstantRestitution(bool constantRestitution)
bool readOptionalVariable(std::istream &is, const std::string &name, T &variable)
Reads optional variables in the restart file.
Definition: Helpers.h:247
void BaseSpecies::setHandler ( SpeciesHandler handler)

Sets the pointer to the handler to which this species belongs.

Parameters
[in]thepointer to the handler to which this species belongs.

Definition at line 91 of file BaseSpecies.cc.

References handler_.

Referenced by SpeciesHandler::addObject(), and ParticleSpecies::getMassFromRadius().

92 {
93  handler_ = handler;
94 }
SpeciesHandler * handler_
A pointer to the handler to which this species belongs. It is initialized to nullptr and gets set whe...
Definition: BaseSpecies.h:195
void BaseSpecies::setInteractionDistance ( Mdouble  interactionDistance)

Sets BaseSpecies::interactionDistance_.

This function should not be called by the user, only by functions in classes derived from BaseSpecies (in particular, the adhesive-force species). This function gets called every time a variable is set on which the interaction distance depends. See for example LiquidBridgeWilletSpecies::setLiquidBridgeVolume.

Parameters
interactionDistance

Definition at line 156 of file BaseSpecies.cc.

References getHandler(), BaseObject::getId(), SpeciesHandler::getMixedObjects(), BaseHandler< T >::getObject(), interactionDistance_, and ParticleSpecies::setMaxInteractionDistance().

Referenced by LiquidBridgeWilletSpecies::setInteractionDistance(), ReversibleAdhesiveSpecies::setInteractionDistance(), LiquidMigrationWilletSpecies::setInteractionDistance(), and ChargedBondedSpecies::setInteractionDistance().

156  {
157  interactionDistance_ = interactionDistance;
158 
159  SpeciesHandler* handler = getHandler();
160  if (handler == nullptr) return;
161 
162  for (auto mixedSpecies : handler->getMixedObjects()) {
163  if (mixedSpecies == this) {
164  // get the two particlespecies id's
165  unsigned mixedId = mixedSpecies->getIndex();
166  unsigned maxId= 1;
167  unsigned maxMixedId = (maxId * (maxId + 1)) / 2;
168  while (maxMixedId<mixedId) {
169  ++maxId;
170  maxMixedId = (maxId * (maxId + 1)) / 2;
171  }
172  unsigned minId = (mixedId + maxId) - maxMixedId;
173  handler->getObject(minId)->setMaxInteractionDistance(interactionDistance);
174  handler->getObject(maxId)->setMaxInteractionDistance(interactionDistance);
175  //logger(INFO,"setInteractionDistance(%) mixed % handler %",interactionDistance, getIndex(), getHandler());
176  return;
177  }
178  }
179  handler->getObject(getId())->setMaxInteractionDistance(interactionDistance);
180 
181  //logger(INFO,"setInteractionDistance(%) species % handler %",interactionDistance, getIndex(), getHandler());
182 }
Container to store all ParticleSpecies.
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.h:125
Mdouble interactionDistance_
Returns the distance between particles of this species below which adhesive forces can occur (needed ...
Definition: BaseSpecies.h:201
void setMaxInteractionDistance(Mdouble interactionDistance=0)
Sets maxInteractionDistance_.
const std::vector< BaseSpecies * > & getMixedObjects() const
Returns a pointer to the vector of all mixed objects.
SpeciesHandler * getHandler() const
Returns the pointer to the handler to which this species belongs.
Definition: BaseSpecies.cc:99
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:613
void BaseSpecies::write ( std::ostream &  os) const
overrideprotectedvirtual

Sets the boolean constantRestitution_.

Parameters
[out]osoutput stream (typically the restart file)

Implements BaseObject.

Reimplemented in Species< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >, MixedSpecies< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >, and ParticleSpecies.

Definition at line 131 of file BaseSpecies.cc.

References BaseNormalForce::getConstantRestitution(), and normalForce_.

Referenced by ParticleSpecies::write(), and MixedSpecies< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >::write().

132 {
133  //BaseObject::write(os);
134  if (normalForce_->getConstantRestitution()) os << " constantRestitution " << normalForce_->getConstantRestitution();
135 }
bool getConstantRestitution() const
BaseNormalForce * normalForce_
A pointer to the normal force parameters This pointer is used by the Interaction's to get a pointer ...
Definition: BaseSpecies.h:173

Member Data Documentation

BaseAdhesiveForce* BaseSpecies::adhesiveForce_
protected

A pointer to the adhesive force parameters This pointer is used by the Interaction's to get a pointer to the species The pointer is set in the constructors of SPecies and MixedSpecies.

Definition at line 187 of file BaseSpecies.h.

Referenced by BaseSpecies(), getAdhesiveForce(), MixedSpecies< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >::MixedSpecies(), and Species< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >::Species().

BaseFrictionForce* BaseSpecies::frictionForce_
protected

A pointer to the friction force parameters This pointer is used by the Interaction's to get a pointer to the species The pointer is set in the constructors of SPecies and MixedSpecies.

Definition at line 180 of file BaseSpecies.h.

Referenced by BaseSpecies(), getFrictionForce(), MixedSpecies< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >::MixedSpecies(), and Species< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >::Species().

SpeciesHandler* BaseSpecies::handler_
private

A pointer to the handler to which this species belongs. It is initialized to nullptr and gets set when SpeciesHandler::addObject() is called.

Definition at line 195 of file BaseSpecies.h.

Referenced by getHandler(), and setHandler().

Mdouble BaseSpecies::interactionDistance_
private

Returns the distance between particles of this species below which adhesive forces can occur (needed for contact detection) set by the adhesive species.

Definition at line 201 of file BaseSpecies.h.

Referenced by getInteractionDistance(), and setInteractionDistance().

BaseNormalForce* BaseSpecies::normalForce_
protected

A pointer to the normal force parameters This pointer is used by the Interaction's to get a pointer to the species The pointer is set in the constructors of SPecies and MixedSpecies.

Definition at line 173 of file BaseSpecies.h.

Referenced by BaseSpecies(), getNormalForce(), MixedSpecies< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >::MixedSpecies(), read(), Species< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >::Species(), and write().


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