MixedSpecies.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2023, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #ifndef MIXEDSPECIES_H
27 #define MIXEDSPECIES_H
28 
32 
33 class BaseInteraction;
34 
41 template<class NormalForceSpecies, class FrictionForceSpecies = EmptyFrictionSpecies, class AdhesiveForceSpecies = EmptyAdhesiveSpecies>
43 {
44 public:
45 
47  MixedSpecies();
48 
50  MixedSpecies(const MixedSpecies& s);
51 
54 
56  virtual ~MixedSpecies();
57 
62 
66  void copyInto(BaseSpecies* bs) const final;
67 
69  void read(std::istream& is) final;
70 
72  void write(std::ostream& os) const final;
73 
75  std::string getName() const final;
76 
82  getNewInteraction(BaseInteractable* const P, BaseInteractable* const I, unsigned timeStamp) const final;
83 
84  //used to create a dummy for MPI purposes (I need a prototype of the interaction)
85  BaseInteraction* getEmptyInteraction() const final;
86 
87  void deleteEmptyInteraction(BaseInteraction* interaction) const final;
88 
92  bool getUseAngularDOFs() const final;
93 
98  void mixAll(BaseSpecies* const S, BaseSpecies* const T) final;
99 };
100 
101 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
104 {
105  logger(DEBUG, "MixedSpecies::MixedSpecies() finished");
106 }
107 
108 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
111 {
112  normalForce_ = this;
113  frictionForce_ = this;
114  adhesiveForce_ = this;
118  logger(DEBUG, "MixedSpecies::MixedSpecies(const MixedSpecies &p) finished");
119 }
120 
121 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
125 {
126  normalForce_ = this;
127  frictionForce_ = this;
128  adhesiveForce_ = this;
132  logger(DEBUG, "MixedSpecies::MixedSpecies(const MixedSpecies &p) finished");
133 }
134 
135 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
137 {
138  logger(DEBUG, "MixedSpecies::~MixedSpecies() finished");
139 }
140 
142 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
145 ::copy() const
146 {
147  return new MixedSpecies(*this);
148 }
149 
157 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
160 {
161  if (bs == nullptr)
162  {
163  logger(WARN, "Error in %::copyInto: cannot copy into a nullptr");
164  return;
165  }
167  if (s == nullptr)
168  {
169  logger(WARN, "Error in %::copyInto: copying of species failed", getName());
170  return;
171  }
172  *s = *this;
173 }
174 
182 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
184 ::write(std::ostream& os) const
185 {
186  os << getName();
187  os << " idA " << BaseObject::getId();
188  os << " idB " << BaseObject::getIndex();
189  BaseSpecies::write(os);
190  NormalForceSpecies::write(os);
191  FrictionForceSpecies::write(os);
192  AdhesiveForceSpecies::write(os);
193 }
194 
199 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
201 ::read(std::istream& is)
202 {
203  //note: name is already read by SpeciesHandler::readAndAddObject
204  std::string dummy;
205  unsigned int id, index;
206  is >> dummy >> id;
207  is >> dummy >> index;
208  BaseObject::setId(id);
209  BaseObject::setIndex(index);
210  BaseSpecies::read(is);
211  NormalForceSpecies::read(is);
212  FrictionForceSpecies::read(is);
213  AdhesiveForceSpecies::read(is);
214 }
215 
230 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
232 {
233  return NormalForceSpecies::getBaseName()
234  + FrictionForceSpecies::getBaseName()
235  + AdhesiveForceSpecies::getBaseName() + "MixedSpecies";
236 }
237 
246 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
248  BaseInteractable* const P, BaseInteractable* const I, unsigned timeStamp) const
249 {
250  // JMFT: memory is allocated here, so it will need to be freed later
252  P, I, timeStamp);
253 }
254 
255 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
258 {
260 }
261 
262 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
264  BaseInteraction* interaction) const
265 {
268  delete interactionDestroyer;
269 }
270 
277 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
279 {
280  return FrictionForceSpecies::getUseAngularDOFs();
281 }
282 
289 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
291  BaseSpecies* const T)
292 {
293  logger.assert_always(T!= nullptr && S!= nullptr,"Arguments of mixAll cannot be null pointers");
294 
295  logger.assert_always(S->getNormalForce()->getConstantRestitution() == T->getNormalForce()->getConstantRestitution(), "mixing two LinearPlasticViscoelasticNormalSpecies, but only one has constantRestitution");
296  NormalForceSpecies::setConstantRestitution(S->getNormalForce()->getConstantRestitution());
297 
298  const auto TN = dynamic_cast<NormalForceSpecies*> (T);
299  const auto TF = dynamic_cast<FrictionForceSpecies*> (T);
300  const auto TA = dynamic_cast<AdhesiveForceSpecies*> (T);
301  logger.assert_always(TN!= nullptr && TF!= nullptr && TA!= nullptr,
302  "Cannot mix two species of different type (% and %)",S->getName(),T->getName());
303 
304  const auto SN = dynamic_cast<NormalForceSpecies*> (S);
305  const auto SF = dynamic_cast<FrictionForceSpecies*> (S);
306  const auto SA = dynamic_cast<AdhesiveForceSpecies*> (S);
307  logger.assert_always(SN!= nullptr && SF!= nullptr && SA!= nullptr,
308  "Cannot mix two species of different type (% and %)",S->getName(),T->getName());
309 
310  NormalForceSpecies::mix(SN,TN);
311  FrictionForceSpecies::mix(SF,TF);
312  AdhesiveForceSpecies::mix(SA,TA);
313 }
314 
315 
316 #endif
std::string getName(int argc, char *argv[])
Definition: CombineParallelDataFiles.cpp:12
LL< Log::DEBUG > DEBUG
Debug information.
Definition: Logger.cc:58
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:54
@ DEBUG
Defines a short-range (non-contact) force parallel to the contact normal, usually adhesive.
void setBaseSpecies(BaseSpecies *baseSpecies)
Definition: BaseForce.h:40
Defines the basic properties that a interactable object can have.
Definition: BaseInteractable.h:55
Stores information about interactions between two interactable objects; often particles but could be ...
Definition: BaseInteraction.h:60
bool getConstantRestitution() const
Definition: BaseNormalForce.h:46
virtual std::string getName() const =0
A purely virtual function.
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.h:125
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.h:118
void setIndex(unsigned int index)
Allows one to assign an index to an object in the handler/container.
Definition: BaseObject.cc:64
void setId(unsigned long id)
Assigns a unique identifier to each object in the handler (container) which remains constant even aft...
Definition: BaseObject.cc:72
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:50
BaseAdhesiveForce * adhesiveForce_
A pointer to the adhesive force parameters \detail This pointer is used by the Interaction's to get a...
Definition: BaseSpecies.h:187
void read(std::istream &is) override
Definition: BaseSpecies.cc:140
BaseNormalForce * getNormalForce() const
Definition: BaseSpecies.h:148
BaseFrictionForce * frictionForce_
A pointer to the friction force parameters \detail This pointer is used by the Interaction's to get a...
Definition: BaseSpecies.h:180
BaseNormalForce * normalForce_
A pointer to the normal force parameters \detail This pointer is used by the Interaction's to get a p...
Definition: BaseSpecies.h:173
void write(std::ostream &os) const override
Sets the boolean constantRestitution_.
Definition: BaseSpecies.cc:131
Defines a contact force orthogonal to the contact normal.
Contains information about the contact between two interactables, BaseInteraction::P_ and BaseInterac...
Definition: Interaction.h:116
Contains contact force properties for contacts between particles with two different species.
Definition: MixedSpecies.h:43
void deleteEmptyInteraction(BaseInteraction *interaction) const final
Definition: MixedSpecies.h:263
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:247
bool getUseAngularDOFs() const final
Returns true if torques have to be calculated.
Definition: MixedSpecies.h:278
std::string getName() const final
Returns the name of the MixedSpecies as it is used in the restart file.
Definition: MixedSpecies.h:231
BaseInteraction * getEmptyInteraction() const final
Definition: MixedSpecies.h:257
void mixAll(BaseSpecies *const S, BaseSpecies *const T) final
sets the MixedSpecies properties by mixing the properties of two particle species
Definition: MixedSpecies.h:290
MixedSpecies()
The default constructor.
Definition: MixedSpecies.h:102
MixedSpecies< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies > * copy() const final
Creates a deep copy of the MixedSpecies from which it is called.
Definition: MixedSpecies.h:145
virtual ~MixedSpecies()
The default destructor.
Definition: MixedSpecies.h:136
void read(std::istream &is) final
Reads the species properties from an input stream.
Definition: MixedSpecies.h:201
void write(std::ostream &os) const final
Writes the MixedSpecies properties to an output stream.
Definition: MixedSpecies.h:184
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:159
Defines a contact force parallel to the contact normal.
Contains material and contact force properties.
Definition: Species.h:35
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:73