MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MPIInteraction.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2020, 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 MPIINTERACTION_H
27 #define MPIINTERACTION_H
28 
36 #include "Logger.h"
37 #include "MpiDataClass.h"
38 
39 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
40 class Interaction;
41 
42 //A monster of a template class, but it is rather universal for all interactions, saves a lot of typing
43 //In terms of memory it is not as efficient as declaring a class for every interaction type, this due to extra padding concerning
44 //the empty class. the extra memory used in the transmission is less than 8 bytes per interaction.
45 //Below all is used to create the MPIHistoryInteraction class which is a lean version to the actual interaction, containing only the history parameters
46 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
48 {
49 public:
51 
52  unsigned int P;
53  unsigned int I;
54  unsigned int speciesId;
56  unsigned timeStamp;
59 
60 
61  typename std::conditional<
62  //If true, enable sliding
63  std::is_base_of<SlidingFrictionInteraction, FrictionForceInteraction>::value, Vec3D, Empty>::type
65 
66  //Friction
67  typename std::conditional<
68  //if true, enable rolling
69  std::is_base_of<FrictionInteraction, FrictionForceInteraction>::value, Vec3D, Empty>::type rollingSpring;
70 
71  typename std::conditional<
72  //if true, enable torsion
73  std::is_base_of<FrictionInteraction, FrictionForceInteraction>::value, Vec3D, Empty>::type torsionSpring;
74 
75  //Contact
76  typename std::conditional<
77  //if true, enablel wasInContact
78  (std::is_base_of<LiquidMigrationWilletInteraction, AdhesiveForceInteraction>::value
79  || std::is_base_of<LiquidBridgeWilletInteraction, AdhesiveForceInteraction>::value
80  ||
81  std::is_base_of<IrreversibleAdhesiveInteraction, AdhesiveForceInteraction>::value), bool, Empty>::type wasInContact;
82 
83  //Bonded
84  typename std::conditional<
85  //if true, enable bonded
86  std::is_base_of<BondedInteraction, AdhesiveForceInteraction>::value, bool, Empty>::type bonded;
87 
88  //Liquidbridge
89  typename std::conditional<
90  //if true, enable liquidbridgeVolume
91  std::is_base_of<LiquidMigrationWilletInteraction, AdhesiveForceInteraction>::value, Mdouble, Empty>::type liquidbridgeVolume;
92 
93  //MaxOverlap
94  typename std::conditional<
95  //if true, enable max overlap
96  std::is_base_of<LinearPlasticViscoelasticInteraction, NormalForceInteraction>::value, Mdouble, Empty>::type maxOverlap;
97 
100 
101  void copyToInteraction(
103  const bool resetPointers);
104 
105  //Sliding
106  template<class DUMMY= FrictionForceInteraction>
107  typename std::enable_if<std::is_base_of<SlidingFrictionInteraction, DUMMY>::value, void>::type
110  {
111  slidingSpring = interaction->FrictionForceInteraction::getSlidingSpring();
112  }
113 
114  //Sliding
115  template<class DUMMY= FrictionForceInteraction>
116  typename std::enable_if<std::is_base_of<SlidingFrictionInteraction, DUMMY>::value, void>::type
119  {
120  interaction->FrictionForceInteraction::setSlidingSpring(slidingSpring);
121  }
122 
123  //No sliding
124  template<class DUMMY = FrictionForceInteraction>
125  typename std::enable_if<!(std::is_base_of<SlidingFrictionInteraction, DUMMY>::value), void>::type
128  {
129  }
130 
131  //No sliding
132  template<class DUMMY = FrictionForceInteraction>
133  typename std::enable_if<!(std::is_base_of<SlidingFrictionInteraction, DUMMY>::value), void>::type
136  {
137  }
138 
139 
140  //Friction
141  template<class DUMMY= FrictionForceInteraction>
142  typename std::enable_if<std::is_base_of<FrictionInteraction, DUMMY>::value, void>::type
145  {
146  rollingSpring = interaction->FrictionForceInteraction::getRollingSpring();
147  torsionSpring = interaction->FrictionForceInteraction::getTorsionSpring();
148  }
149 
150  //Friction
151  template<class DUMMY= FrictionForceInteraction>
152  typename std::enable_if<std::is_base_of<FrictionInteraction, DUMMY>::value, void>::type
155  {
156  interaction->FrictionForceInteraction::setRollingSpring(rollingSpring);
157  interaction->FrictionForceInteraction::setTorsionSpring(torsionSpring);
158  }
159 
160  //No friction
161  template<class DUMMY = FrictionForceInteraction>
162  typename std::enable_if<!(std::is_base_of<FrictionInteraction, DUMMY>::value), void>::type
165  {
166  }
167 
168  //No friction
169  template<class DUMMY = FrictionForceInteraction>
170  typename std::enable_if<!(std::is_base_of<FrictionInteraction, DUMMY>::value), void>::type
173  {
174  }
175 
176  //Contact
177  template<class DUMMY = AdhesiveForceInteraction>
178  typename std::enable_if<(
179  std::is_base_of<LiquidMigrationWilletInteraction, DUMMY>::value
180  || std::is_base_of<LiquidBridgeWilletInteraction, DUMMY>::value
181  || std::is_base_of<IrreversibleAdhesiveInteraction, DUMMY>::value), void>::type
184  {
185  wasInContact = interaction->AdhesiveForceInteraction::getWasInContact();
186  }
187 
188  //Contact
189  template<class DUMMY = AdhesiveForceInteraction>
190  typename std::enable_if<(
191  std::is_base_of<LiquidMigrationWilletInteraction, DUMMY>::value
192  || std::is_base_of<LiquidBridgeWilletInteraction, DUMMY>::value
193  || std::is_base_of<IrreversibleAdhesiveInteraction, DUMMY>::value), void>::type
196  {
197  interaction->AdhesiveForceInteraction::setWasInContact(wasInContact);
198  }
199 
200  //No contact
201  template<class DUMMY = AdhesiveForceInteraction>
202  typename std::enable_if<!(
203  std::is_base_of<LiquidMigrationWilletInteraction, DUMMY>::value
204  || std::is_base_of<LiquidBridgeWilletInteraction, DUMMY>::value
205  || std::is_base_of<IrreversibleAdhesiveInteraction, DUMMY>::value), void>::type
208  {
209  }
210 
211  //No contact
212  template<class DUMMY = AdhesiveForceInteraction>
213  typename std::enable_if<!(
214  std::is_base_of<LiquidMigrationWilletInteraction, DUMMY>::value
215  || std::is_base_of<LiquidBridgeWilletInteraction, DUMMY>::value
216  || std::is_base_of<IrreversibleAdhesiveInteraction, DUMMY>::value), void>::type
219  {
220  }
221 
222  //Bonded
223  template<class DUMMY = AdhesiveForceInteraction>
224  typename std::enable_if<(std::is_base_of<BondedInteraction, DUMMY>::value), void>::type
227  {
228  bonded = interaction->AdhesiveForceInteraction::getBonded();
229  }
230 
231  //Bonded
232  template<class DUMMY = AdhesiveForceInteraction>
233  typename std::enable_if<(std::is_base_of<BondedInteraction, DUMMY>::value), void>::type
235  {
236  interaction->AdhesiveForceInteraction::setBonded(bonded);
237  }
238 
239  //No bonded
240  template<class DUMMY = AdhesiveForceInteraction>
241  typename std::enable_if<!(std::is_base_of<BondedInteraction, DUMMY>::value), void>::type
244  {
245  }
246 
247  //No bonded
248  template<class DUMMY = AdhesiveForceInteraction>
249  typename std::enable_if<!(std::is_base_of<BondedInteraction, DUMMY>::value), void>::type
251  {
252  }
253 
254  //Liquidbridge
255  template<class DUMMY = AdhesiveForceInteraction>
256  typename std::enable_if<(std::is_base_of<LiquidMigrationWilletInteraction, DUMMY>::value), void>::type
259  {
260  liquidbridgeVolume = interaction->AdhesiveForceInteraction::getLiquidBridgeVolume();
261  }
262 
263  //Liquidbridge
264  template<class DUMMY = AdhesiveForceInteraction>
265  typename std::enable_if<(std::is_base_of<LiquidMigrationWilletInteraction, DUMMY>::value), void>::type
268  {
269  interaction->AdhesiveForceInteraction::setLiquidBridgeVolume(liquidbridgeVolume);
270  }
271 
272  //No Liquidbridge
273  template<class DUMMY = AdhesiveForceInteraction>
274  typename std::enable_if<!(std::is_base_of<LiquidMigrationWilletInteraction, DUMMY>::value), void>::type
277  {
278  }
279 
280  //No Liquidbridge
281  template<class DUMMY = AdhesiveForceInteraction>
282  typename std::enable_if<!(std::is_base_of<LiquidMigrationWilletInteraction, DUMMY>::value), void>::type
285  {
286  }
287 
288  //Max overlap
289  template<class DUMMY = NormalForceInteraction>
290  typename std::enable_if<(std::is_base_of<LinearPlasticViscoelasticInteraction, DUMMY>::value), void>::type
293  {
294  maxOverlap = interaction->NormalForceInteraction::getMaxOverlap();
295  }
296 
297  //Max overlap
298  template<class DUMMY = NormalForceInteraction>
299  typename std::enable_if<(std::is_base_of<LinearPlasticViscoelasticInteraction, DUMMY>::value), void>::type
302  {
303  interaction->NormalForceInteraction::setMaxOverlap(maxOverlap);
304  }
305 
306  //Max overlap
307  template<class DUMMY = NormalForceInteraction>
308  typename std::enable_if<!(std::is_base_of<LinearPlasticViscoelasticInteraction, DUMMY>::value), void>::type
311  {
312  }
313 
314  //Max overlap
315  template<class DUMMY = NormalForceInteraction>
316  typename std::enable_if<!(std::is_base_of<LinearPlasticViscoelasticInteraction, DUMMY>::value), void>::type
319  {
320  }
321 
322 };
323 
324 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
326 {
327 }
328 
329 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
332 {
333  //logger.assert(interaction->getP()->getId(),"Trying to copy an unreal interaction: P is not defined");
334  //logger.assert(interaction->getP()->getId(),"Trying to copy an unreal interaction: I is not defined");
335 
336  if (interaction->getP() == nullptr) logger(WARN, "P is not defined!!");
337  if (interaction->getI() == nullptr) logger(WARN, "I is not defined!!");
338  P = interaction->getP()->getId();
339  I = interaction->getI()->getId();
340 
341  if (dynamic_cast<const BaseParticle*>(interaction->getI()) == nullptr)
342  {
343  isWallInteraction = true;
344  }
345  else
346  {
347  isWallInteraction = false;
348  }
349 
350  timeStamp = interaction->getTimeStamp();
351  force = interaction->getForce();
352  torque = interaction->getTorque();
353  getSlidingSpring(interaction);
354  getFrictionSprings(interaction);
355  getWasInContact(interaction);
356  getBonded(interaction);
357  getLiquidBridge(interaction);
358  getMaximumOverlap(interaction);
359 }
360 
361 
362 template<class NormalForceInteraction, class FrictionForceInteraction, class AdhesiveForceInteraction>
365  const bool resetPointers)
366 {
367  //Basic interaction values
368  BaseInteraction* basicInteraction = static_cast<BaseInteraction*>(interaction);
369  basicInteraction->setBasicMPIInteractionValues(P, I, timeStamp, force, torque, isWallInteraction, resetPointers);
370 
371  //Specific history interaction values, interaction type denpendent
372  setSlidingSpring(interaction);
373  setFrictionSprings(interaction);
374  setWasInContact(interaction);
375  setBonded(interaction);
376  setLiquidBridge(interaction);
377  setMaximumOverlap(interaction);
378 }
379 
380 
381 #endif
std::conditional< std::is_base_of< SlidingFrictionInteraction, FrictionForceInteraction >::value, Vec3D, Empty >::type slidingSpring
std::enable_if<(std::is_base_of< LiquidMigrationWilletInteraction, DUMMY >::value), void >::type setLiquidBridge(Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
std::conditional< std::is_base_of< LinearPlasticViscoelasticInteraction, NormalForceInteraction >::value, Mdouble, Empty >::type maxOverlap
std::enable_if<!(std::is_base_of< LiquidMigrationWilletInteraction, DUMMY >::value||std::is_base_of< LiquidBridgeWilletInteraction, DUMMY >::value||std::is_base_of< IrreversibleAdhesiveInteraction, DUMMY >::value), void >::type setWasInContact(Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
std::enable_if<!(std::is_base_of< LiquidMigrationWilletInteraction, DUMMY >::value), void >::type setLiquidBridge(Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Definition: GeneralDefine.h:34
std::enable_if<!(std::is_base_of< BondedInteraction, DUMMY >::value), void >::type getBonded(const Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
unsigned int I
std::enable_if<!(std::is_base_of< LinearPlasticViscoelasticInteraction, DUMMY >::value), void >::type setMaximumOverlap(Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
std::conditional< std::is_base_of< BondedInteraction, AdhesiveForceInteraction >::value, bool, Empty >::type bonded
std::enable_if<!(std::is_base_of< BondedInteraction, DUMMY >::value), void >::type setBonded(Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
std::conditional< (std::is_base_of< LiquidMigrationWilletInteraction, AdhesiveForceInteraction >::value||std::is_base_of< LiquidBridgeWilletInteraction, AdhesiveForceInteraction >::value||std::is_base_of< IrreversibleAdhesiveInteraction, AdhesiveForceInteraction >::value), bool, Empty >::type wasInContact
Data class to send an empty class over MPI.
Definition: MpiDataClass.h:130
std::conditional< std::is_base_of< LiquidMigrationWilletInteraction, AdhesiveForceInteraction >::value, Mdouble, Empty >::type liquidbridgeVolume
std::enable_if<(std::is_base_of< BondedInteraction, DUMMY >::value), void >::type getBonded(const Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
std::enable_if<(std::is_base_of< LiquidMigrationWilletInteraction, DUMMY >::value||std::is_base_of< LiquidBridgeWilletInteraction, DUMMY >::value||std::is_base_of< IrreversibleAdhesiveInteraction, DUMMY >::value), void >::type getWasInContact(const Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
unsigned int speciesId
void copyFromInteraction(const Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
std::enable_if< std::is_base_of< FrictionInteraction, DUMMY >::value, void >::type setFrictionSprings(Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
Stores information about interactions between two interactable objects; often particles but could be ...
std::conditional< std::is_base_of< FrictionInteraction, FrictionForceInteraction >::value, Vec3D, Empty >::type torsionSpring
std::enable_if<(std::is_base_of< LinearPlasticViscoelasticInteraction, DUMMY >::value), void >::type getMaximumOverlap(const Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
unsigned int P
std::enable_if<!(std::is_base_of< SlidingFrictionInteraction, DUMMY >::value), void >::type setSlidingSpring(Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
std::enable_if<!(std::is_base_of< FrictionInteraction, DUMMY >::value), void >::type setFrictionSprings(Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
unsigned timeStamp
std::enable_if< std::is_base_of< SlidingFrictionInteraction, DUMMY >::value, void >::type setSlidingSpring(Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
LL< Log::WARN > WARN
Warning log level.
Definition: Logger.cc:54
std::enable_if<(std::is_base_of< LiquidMigrationWilletInteraction, DUMMY >::value||std::is_base_of< LiquidBridgeWilletInteraction, DUMMY >::value||std::is_base_of< IrreversibleAdhesiveInteraction, DUMMY >::value), void >::type setWasInContact(Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
std::enable_if<(std::is_base_of< LiquidMigrationWilletInteraction, DUMMY >::value), void >::type getLiquidBridge(const Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
std::enable_if<(std::is_base_of< BondedInteraction, DUMMY >::value), void >::type setBonded(Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
void copyToInteraction(Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction, const bool resetPointers)
std::conditional< std::is_base_of< FrictionInteraction, FrictionForceInteraction >::value, Vec3D, Empty >::type rollingSpring
std::enable_if<!(std::is_base_of< SlidingFrictionInteraction, DUMMY >::value), void >::type getSlidingSpring(const Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
std::enable_if<!(std::is_base_of< LiquidMigrationWilletInteraction, DUMMY >::value||std::is_base_of< LiquidBridgeWilletInteraction, DUMMY >::value||std::is_base_of< IrreversibleAdhesiveInteraction, DUMMY >::value), void >::type getWasInContact(const Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
std::enable_if<(std::is_base_of< LinearPlasticViscoelasticInteraction, DUMMY >::value), void >::type setMaximumOverlap(Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
std::enable_if<!(std::is_base_of< LinearPlasticViscoelasticInteraction, DUMMY >::value), void >::type getMaximumOverlap(const Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
std::enable_if< std::is_base_of< SlidingFrictionInteraction, DUMMY >::value, void >::type getSlidingSpring(const Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
std::enable_if< std::is_base_of< FrictionInteraction, DUMMY >::value, void >::type getFrictionSprings(const Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
std::enable_if<!(std::is_base_of< LiquidMigrationWilletInteraction, DUMMY >::value), void >::type getLiquidBridge(const Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
std::enable_if<!(std::is_base_of< FrictionInteraction, DUMMY >::value), void >::type getFrictionSprings(const Interaction< NormalForceInteraction, FrictionForceInteraction, AdhesiveForceInteraction > *interaction)
Definition: Vector.h:49
void setBasicMPIInteractionValues(int P, int I, unsigned timeStamp, Vec3D force, Vec3D torque, bool isWallInteraction, bool resetPointers)
Contains information about the contact between two interactables, BaseInteraction::P_ and BaseInterac...
Definition: Interaction.h:115