Interaction.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 INTERACTION_H
27 #define INTERACTION_H
28 
31 #include "InteractionHandler.h"
32 #include "BaseInteractable.h"
33 
34 //used for mpi
35 #include "MpiContainer.h"
36 #include "MPIInteraction.h"
37 #include "Logger.h"
38 
39 class BaseInteractable;
40 
41 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
42 class Species;
43 
113 //this class combines normal and tangential force laws
114 template<class NormalForceInteraction, class FrictionForceInteraction=EmptyFrictionInteraction, class AdhesiveForceInteraction=EmptyAdhesiveInteraction>
115 class Interaction : public NormalForceInteraction, public FrictionForceInteraction, public AdhesiveForceInteraction
116 {
117 public:
118 
120  Interaction(BaseInteractable* P, BaseInteractable* I, unsigned timeStamp);
121 
123  Interaction();
124 
126  Interaction(const Interaction& p);
127 
129  virtual ~Interaction();
130 
133 
135  void computeForce() final;
136 
139 
141  void read(std::istream& is) final;
142 
144  void write(std::ostream& os) const final;
145 
147  std::string getName() const final;
148 
150  Mdouble getElasticEnergy() const final;
151 
153  void integrate(Mdouble timeStep) final;
154 
156  void reverseHistory() final;
157 
158  void rotateHistory(Matrix3D& rotationMatrix) final;
159 
160  void actionsAfterTimeStep();
161 
165  Mdouble getElasticEnergyAtEquilibrium(Mdouble adhesiveForce) const;
166 
167  void getMPIInteraction(void* historyDataArray, unsigned int index) const final;
168 
169  //if resetPointers is true, then the pointers in the interaction will be set to nullptr, indicating it is a dummyInteraction
170  //and that it is not actually linked to real particles (which might not be in the domain)
171  void setMPIInteraction(void* historyDataArray, unsigned int index, const bool resetPointers) final;
172 
173  void getInteractionDetails(void* interactionDataArray, unsigned int index, unsigned int& identificationP,
174  unsigned int& identificationI, bool& isWallInteraction, unsigned& timeStamp);
175 
176  void createMPIType() final;
177 
178  void* createMPIInteractionDataArray(unsigned int numberOfInteractions) const final;
179 
180  void deleteMPIInteractionDataArray(void* dataArray) final;
181 };
182 
183 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
184 Interaction<NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction>::Interaction(
185  BaseInteractable* P, BaseInteractable* I, unsigned timeStamp)
186  : BaseInteraction(P, I, timeStamp), NormalForceInteraction(P, I, timeStamp),
187  FrictionForceInteraction(P, I, timeStamp), AdhesiveForceInteraction(P, I, timeStamp)
188 {
189 #ifdef DEBUG_CONSTRUCTOR
190  std::cout<<"Interaction::Interaction() finished"<<std::endl;
191 #endif
192 }
193 
194 
195 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
197  : BaseInteraction(), NormalForceInteraction(), FrictionForceInteraction(), AdhesiveForceInteraction()
198 {
199 #ifdef DEBUG_CONSTRUCTOR
200  std::cout<<"Interaction::Interaction() finished"<<std::endl;
201 #endif
202 }
203 
204 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
206  const Interaction& p)
207  : BaseInteraction(p), NormalForceInteraction(p), FrictionForceInteraction(p), AdhesiveForceInteraction(p)
208 {
209 #ifdef DEBUG_CONSTRUCTOR
210  std::cout<<"Interaction::Interaction(const Interaction &p finished"<<std::endl;
211 #endif
212 }
213 
214 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
216 {
217 #ifdef DEBUG_DESTRUCTOR
218  std::cout<<"Interaction::~Interaction() finished"<<std::endl;
219 #endif
220 }
221 
225 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
228 {
229  return new Interaction(*this);
230 }
231 
236 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
237 void
239 {
240  NormalForceInteraction::write(os);
241  FrictionForceInteraction::write(os);
242  AdhesiveForceInteraction::write(os);
243 
244 }
245 
250 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
252 {
253  NormalForceInteraction::read(is);
254  FrictionForceInteraction::read(is);
255  AdhesiveForceInteraction::read(is);
256 }
257 
263 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
265 {
266  NormalForceInteraction::reverseHistory();
267  FrictionForceInteraction::reverseHistory();
268  AdhesiveForceInteraction::reverseHistory();
269 }
270 
271 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
273  Matrix3D& rotationMatrix)
274 {
275  NormalForceInteraction::rotateHistory(rotationMatrix);
276  FrictionForceInteraction::rotateHistory(rotationMatrix);
277  AdhesiveForceInteraction::rotateHistory(rotationMatrix);
278 }
279 
284 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
286 {
287  return NormalForceInteraction::getBaseName() + FrictionForceInteraction::getBaseName() +
288  AdhesiveForceInteraction::getBaseName() + "Interaction";
289 }
290 
296 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
297 void
299 {
300  FrictionForceInteraction::integrate(timeStep);
301 }
302 
311 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
313 {
314  NormalForceInteraction::computeNormalForce();
315  FrictionForceInteraction::computeFrictionForce();
316  AdhesiveForceInteraction::computeAdhesionForce();
317 }
318 
325 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
326 Mdouble
328 {
329  return NormalForceInteraction::getElasticEnergy() + FrictionForceInteraction::getElasticEnergy() +
330  AdhesiveForceInteraction::getElasticEnergy();
331 }
332 
333 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
335 {
336  AdhesiveForceInteraction::actionsAfterTimeStep();
337 }
338 
342 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
343 Mdouble
345  Mdouble adhesiveForce) const
346 {
347  return NormalForceInteraction::getElasticEnergyAtEquilibrium(adhesiveForce);
348 };
349 
350 
351 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
353  void* interactionDataArray, unsigned int index) const
354 {
356 
357  interactionData.copyFromInteraction(this);
358 
360  array[index] = interactionData;
361 }
362 
363 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
365  void* interactionDataArray, unsigned int index, const bool resetPointers)
366 {
369 
370  //Copy the interaction data into the interaction
371  interactionData.copyToInteraction(this, resetPointers);
372 }
373 
374 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
376  void* interactionDataArray, unsigned int index, unsigned int& identificationP, unsigned int& identificationI,
377  bool& isWallInteraction, unsigned& timeStamp)
378 {
381 
382  identificationP = interactionData.P;
383  identificationI = interactionData.I;
384  isWallInteraction = interactionData.isWallInteraction;
385  timeStamp = interactionData.timeStamp;
386 }
387 
388 
389 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
390 void*
392  unsigned int numberOfInteractions) const
393 {
395  void* interactionArray = static_cast<void*>(array);
396  return interactionArray;
397 }
398 
399 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
400 void
402  void* dataArray)
403 {
405  delete[] array;
406 }
407 
408 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
410 {
411 #ifdef MERCURYDPM_USE_MPI
412  MPIContainer& communicator = MPIContainer::Instance();
414 
415  communicator.createMercuryMPIType(dummyHistoryInteraction, MercuryMPIType::INTERACTION);
416 #endif
417 }
418 
419 #endif
420 
double Mdouble
Definition: GeneralDefine.h:34
@ INTERACTION
Definition: MpiContainer.h:67
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 isWallInteraction()
Definition: BaseInteraction.cc:955
Contains information about the contact between two interactables, BaseInteraction::P_ and BaseInterac...
Definition: Interaction.h:116
Interaction()
Empty constructor.
Definition: Interaction.h:196
void createMPIType() final
Definition: Interaction.h:409
void setMPIInteraction(void *historyDataArray, unsigned int index, const bool resetPointers) final
Definition: Interaction.h:364
void * createMPIInteractionDataArray(unsigned int numberOfInteractions) const final
Definition: Interaction.h:391
Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > * copy() const final
Creates a copy of this Interaction.
Definition: Interaction.h:227
void rotateHistory(Matrix3D &rotationMatrix) final
When periodic particles are used, some interactions need certain history properties rotated (e....
Definition: Interaction.h:272
void getMPIInteraction(void *historyDataArray, unsigned int index) const final
copies the history interactions into the data array
Definition: Interaction.h:352
std::string getName() const final
Returns the name of the Interaction.
Definition: Interaction.h:285
Mdouble getElasticEnergy() const final
Returns the elastic energy stored in the Interaction.
Definition: Interaction.h:327
void getInteractionDetails(void *interactionDataArray, unsigned int index, unsigned int &identificationP, unsigned int &identificationI, bool &isWallInteraction, unsigned &timeStamp)
Definition: Interaction.h:375
void read(std::istream &is) final
Read Interaction properties from a file.
Definition: Interaction.h:251
void computeInteraction()
Computes the interaction parameters based on the forces and torques.
void deleteMPIInteractionDataArray(void *dataArray) final
Definition: Interaction.h:401
void computeForce() final
Computes the normal, tangential, and adhesive forces.
Definition: Interaction.h:312
void reverseHistory() final
Reverses the parameters of the contact force.
Definition: Interaction.h:264
void integrate(Mdouble timeStep) final
Integrates the time-dependent parameters of the contact force.
Definition: Interaction.h:298
Mdouble getElasticEnergyAtEquilibrium(Mdouble adhesiveForce) const
returns the overlap at which the repulsive elastic force equals a given adhesive force; to be impleme...
Definition: Interaction.h:344
void actionsAfterTimeStep()
Definition: Interaction.h:334
void write(std::ostream &os) const final
Writes Interaction properties to a file.
Definition: Interaction.h:238
virtual ~Interaction()
The default destructor.
Definition: Interaction.h:215
This class contains all information and functions required for communication between processors.
Definition: MpiContainer.h:130
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134
void createMercuryMPIType(T t, MercuryMPIType type)
Get the communicator used for MPI commands.
Definition: MpiContainer.h:564
Definition: MPIInteraction.h:48
bool isWallInteraction
Definition: MPIInteraction.h:55
unsigned int P
Definition: MPIInteraction.h:52
unsigned timeStamp
Definition: MPIInteraction.h:56
void copyToInteraction(Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction, const bool resetPointers)
Definition: MPIInteraction.h:363
void copyFromInteraction(const Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
Definition: MPIInteraction.h:330
unsigned int I
Definition: MPIInteraction.h:53
Implementation of a 3D matrix.
Definition: Matrix.h:38
Contains material and contact force properties.
Definition: Species.h:35
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:73