MixedSpecies.h
Go to the documentation of this file.
1 // This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2 // Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3 // License: BSD 3-Clause License; see the LICENSE file in the root directory.
4 
5 #ifndef MIXEDSPECIES_H
6 #define MIXEDSPECIES_H
7 
11 
12 class BaseInteraction;
13 
20 template<class NormalForceSpecies, class FrictionForceSpecies = EmptyFrictionSpecies, class AdhesiveForceSpecies = EmptyAdhesiveSpecies>
22 {
23 public:
24 
26  MixedSpecies();
27 
29  MixedSpecies(const MixedSpecies& s);
30 
33 
35  virtual ~MixedSpecies();
36 
41 
45  void copyInto(BaseSpecies* bs) const final;
46 
48  void read(std::istream& is) final;
49 
51  void write(std::ostream& os) const final;
52 
54  std::string getName() const final;
55 
61  getNewInteraction(BaseInteractable* const P, BaseInteractable* const I, unsigned timeStamp) const final;
62 
63  //used to create a dummy for MPI purposes (I need a prototype of the interaction)
64  BaseInteraction* getEmptyInteraction() const final;
65 
66  void deleteEmptyInteraction(BaseInteraction* interaction) const final;
67 
71  bool getUseAngularDOFs() const final;
72 
77  void mixAll(BaseSpecies* const S, BaseSpecies* const T) final;
78 };
79 
80 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
83 {
84  normalForce_ = this;
85  frictionForce_ = this;
86  adhesiveForce_ = this;
90  logger(DEBUG, "MixedSpecies::MixedSpecies() finished");
91 }
92 
93 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
96 {
97  normalForce_ = this;
98  frictionForce_ = this;
99  adhesiveForce_ = this;
103  logger(DEBUG, "MixedSpecies::MixedSpecies(const MixedSpecies &p) finished");
104 }
105 
106 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
110 {
111  normalForce_ = this;
112  frictionForce_ = this;
113  adhesiveForce_ = this;
117  logger(DEBUG, "MixedSpecies::MixedSpecies(const MixedSpecies &p) finished");
118 }
119 
120 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
122 {
123  logger(DEBUG, "MixedSpecies::~MixedSpecies() finished");
124 }
125 
127 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
130 ::copy() const
131 {
132  return new MixedSpecies(*this);
133 }
134 
142 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
145 {
146  if (bs == nullptr)
147  {
148  logger(WARN, "Error in %::copyInto: cannot copy into a nullptr");
149  return;
150  }
152  if (s == nullptr)
153  {
154  logger(WARN, "Error in %::copyInto: copying of species failed", getName());
155  return;
156  }
157  *s = *this;
158 }
159 
167 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
169 ::write(std::ostream& os) const
170 {
171  os << getName();
172  os << " idA " << BaseObject::getId();
173  os << " idB " << BaseObject::getIndex();
174  BaseSpecies::write(os);
178 }
179 
184 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
186 ::read(std::istream& is)
187 {
188  //note: name is already read by SpeciesHandler::readAndAddObject
189  std::string dummy;
190  unsigned int id, index;
191  is >> dummy >> id;
192  is >> dummy >> index;
193  BaseObject::setId(id);
194  BaseObject::setIndex(index);
195  BaseSpecies::read(is);
199  // ensure that interaction distance is recomputed after restarting
200  AdhesiveForceSpecies::setInteractionDistance();
201 }
202 
217 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
219 {
220  return NormalForceSpecies::getBaseName()
221  + FrictionForceSpecies::getBaseName()
222  + AdhesiveForceSpecies::getBaseName() + "MixedSpecies";
223 }
224 
233 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
235  BaseInteractable* const P, BaseInteractable* const I, unsigned timeStamp) const
236 {
237  // JMFT: memory is allocated here, so it will need to be freed later
239  P, I, timeStamp);
240 }
241 
242 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
245 {
247 }
248 
249 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
251  BaseInteraction* interaction) const
252 {
255  delete interactionDestroyer;
256 }
257 
264 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
266 {
267  return FrictionForceSpecies::getUseAngularDOFs();
268 }
269 
276 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
278  BaseSpecies* const T)
279 {
280  logger.assert_always(T!= nullptr && S!= nullptr,"Arguments of mixAll cannot be null pointers");
281 
282  logger.assert_always(S->getNormalForce()->getConstantRestitution() == T->getNormalForce()->getConstantRestitution(), "mixing two LinearPlasticViscoelasticNormalSpecies, but only one has constantRestitution");
283  NormalForceSpecies::setConstantRestitution(S->getNormalForce()->getConstantRestitution());
284 
285  const auto TN = dynamic_cast<NormalForceSpecies*> (T);
286  const auto TF = dynamic_cast<FrictionForceSpecies*> (T);
287  const auto TA = dynamic_cast<AdhesiveForceSpecies*> (T);
288  logger.assert_always(TN!= nullptr && TF!= nullptr && TA!= nullptr,
289  "Cannot mix two species of different type (% and %)",S->getName(),T->getName());
290 
291  const auto SN = dynamic_cast<NormalForceSpecies*> (S);
292  const auto SF = dynamic_cast<FrictionForceSpecies*> (S);
293  const auto SA = dynamic_cast<AdhesiveForceSpecies*> (S);
294  logger.assert_always(SN!= nullptr && SF!= nullptr && SA!= nullptr,
295  "Cannot mix two species of different type (% and %)",S->getName(),T->getName());
296 
297  NormalForceSpecies::mix(SN,TN);
298  FrictionForceSpecies::mix(SF,TF);
299  AdhesiveForceSpecies::mix(SA,TA);
300 }
301 
302 
303 #endif
std::string getName(int argc, char *argv[])
Definition: CombineParallelDataFiles.cpp:16
Eigen::Triplet< double > T
Definition: EigenUnitTest.cpp:11
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
LL< Log::WARN > WARN
Warning log level.
Definition: Logger.cc:33
@ DEBUG
Defines a short-range (non-contact) force parallel to the contact normal, usually adhesive.
void setBaseSpecies(BaseSpecies *baseSpecies)
Definition: BaseForce.h:21
Defines the basic properties that a interactable object can have.
Definition: BaseInteractable.h:34
Stores information about interactions between two interactable objects; often particles but could be ...
Definition: BaseInteraction.h:39
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.h:104
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.h:97
void setIndex(unsigned int index)
Allows one to assign an index to an object in the handler/container.
Definition: BaseObject.cc:42
void setId(unsigned long id)
Assigns a unique identifier to each object in the handler (container) which remains constant even aft...
Definition: BaseObject.cc:50
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:29
BaseAdhesiveForce * adhesiveForce_
A pointer to the adhesive force parameters.
Definition: BaseSpecies.h:166
void read(std::istream &is) override
Definition: BaseSpecies.cc:119
BaseFrictionForce * frictionForce_
A pointer to the friction force parameters.
Definition: BaseSpecies.h:159
BaseNormalForce * normalForce_
A pointer to the normal force parameters.
Definition: BaseSpecies.h:152
void write(std::ostream &os) const override
Sets the boolean constantRestitution_.
Definition: BaseSpecies.cc:110
Defines a contact force orthogonal to the contact normal.
Contains information about the contact between two interactables, BaseInteraction::P_ and BaseInterac...
Definition: Interaction.h:95
Contains contact force properties for contacts between particles with two different species.
Definition: MixedSpecies.h:22
void deleteEmptyInteraction(BaseInteraction *interaction) const final
Definition: MixedSpecies.h:250
BaseInteraction * getNewInteraction(BaseInteractable *const P, BaseInteractable *const I, unsigned timeStamp) const final
When a contact between two particles is determined, an Interaction object is created,...
Definition: MixedSpecies.h:234
bool getUseAngularDOFs() const final
Returns true if torques have to be calculated.
Definition: MixedSpecies.h:265
std::string getName() const final
Returns the name of the MixedSpecies as it is used in the restart file.
Definition: MixedSpecies.h:218
BaseInteraction * getEmptyInteraction() const final
Definition: MixedSpecies.h:244
void mixAll(BaseSpecies *const S, BaseSpecies *const T) final
sets the MixedSpecies properties by mixing the properties of two particle species
Definition: MixedSpecies.h:277
MixedSpecies()
The default constructor.
Definition: MixedSpecies.h:81
MixedSpecies< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies > * copy() const final
Creates a deep copy of the MixedSpecies from which it is called.
Definition: MixedSpecies.h:130
virtual ~MixedSpecies()
The default destructor.
Definition: MixedSpecies.h:121
void read(std::istream &is) final
Reads the species properties from an input stream.
Definition: MixedSpecies.h:186
void write(std::ostream &os) const final
Writes the MixedSpecies properties to an output stream.
Definition: MixedSpecies.h:169
void copyInto(BaseSpecies *bs) const final
Copies the content of this into the species bs, if they are of the same type.
Definition: MixedSpecies.h:144
Defines a contact force parallel to the contact normal.
Contains material and contact force properties.
Definition: Species.h:14
RealScalar s
Definition: level1_cplx_impl.h:130
#define I
Definition: main.h:127
#define DEBUG
Definition: main.h:181
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::enable_if_t< dt !=data_source::global_mem, void > write(PacketType &packet_data, DataScalar ptr)
write, a template function used for storing the data to local memory. This function is used to guaran...
Definition: TensorContractionSycl.h:221
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::enable_if_t< PacketLoad, PacketType > read(const TensorMapper &tensorMapper, const StorageIndex &NCIndex, const StorageIndex &CIndex, const StorageIndex &ld)
read, a template function used for loading the data from global memory. This function is used to guar...
Definition: TensorContractionSycl.h:162
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:77
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
@ S
Definition: quadtree.h:62