Mercury3DClump.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 #include "Mercury3D.h"
6 #include "Walls/InfiniteWall.h"
10 #include <stdlib.h>
11 
16 class Mercury3Dclump : public Mercury3D
17 {
18 public:
19  explicit Mercury3Dclump()
20  {
21 
22  }
23 
28  {
29  // Quit if:
30  // 1) at least one particle is master
31  // 2) pebbles of the same clump
32  if (P1->isClump() || P2->isClump())
33  return;
34  if (P1->isPebble() && P2->isPebble() && P1->getClump() == P2->getClump())
35  return;
36 
38  }
39 
44  {
45  // No interaction between walls and master particles
46  if (pI->isClump())
47  return;
48 
50  }
51 
55  void computeAllForces() override
56  {
58 
59  #pragma omp for schedule(dynamic)
62  {
63  if ((p->isPebble()) && (p->getPeriodicFromParticle() == nullptr))
64  {
65  p->getClump()->addForce(p->getForce());
66  Vec3D lever = p->getPosition()- p->getClump()->getPosition();
67 
68  // Patch to fix lever - we do not create ghost masters, that's why this workaround is needed
69  // Should affect all boundaries derived from PeriodicBoundary and do not affect other types
70  for (auto b : boundaryHandler)
71  {
72  auto pb = dynamic_cast<PeriodicBoundary*>(b);
73  if (pb){
74  Vec3D shift = pb->getShift();
75  if (lever.getLength() > (lever - shift).getLength()) lever -= shift;
76  if (lever.getLength() > (lever + shift).getLength()) lever += shift;
77  }
78  }
79  // End patch
80 
81  Vec3D torque = p->getTorque();
82  torque += Vec3D::cross(lever, p->getForce());
83  p->getClump()->addTorque(torque);
84  }
85  }
86  }
87 
92  {
93  ClumpParticle* mp = dynamic_cast<ClumpParticle*>(&particle);
94  if (mp->isClump()){
95  for (int i = 0; i< mp->NPebble(); i++){
97  if (!q->isClump()) { // check every slave vs every non-master intersection
98  if (Vec3D::getDistanceSquared(q->getPosition(), mp->getPebblePositions()[i])
99  < q->getRadius() + mp->getPebbleRadii()[i]) {
100  return false;
101  }
102  }
103  }
104  }
105  }
106  return true;
107  }
108 
113  {
114  // Note that this implementation only check for interaction with particles
115  bool NP = true;
116  // Periodic case
118  {
119  PeriodicBoundary* pb = dynamic_cast<PeriodicBoundary*>(b);
120  if (pb) NP = false;
121  if (pb && particleHandler.getNumberOfObjects() > 0 )
122  {
123  ClumpParticle* mp = dynamic_cast<ClumpParticle*>(&particle);
124  if (mp->isClump()){
125  for (int i = 0; i< mp->NPebble(); i++){
126  for (BaseParticle *q: particleHandler) {
127  if (!q->isClump()) { // check every slave vs every non-master intersection
128  if (Vec3D::getDistanceSquared(q->getPosition(), mp->getPebblePositions()[i])
129  < (q->getMaxInteractionRadius() + mp->getPebbleRadii()[i])
130  * (q->getMaxInteractionRadius() + mp->getPebbleRadii()[i]) ) {
131  return false;
132  }
133  BaseParticle *q1 = q->copy(); // check every slave vs non-master ghost intersection
134  pb->shiftPosition(q1);
136  Mdouble dist02 = (q1->getMaxInteractionRadius() + mp->getPebbleRadii()[i])
137  * (q1->getMaxInteractionRadius() + mp->getPebbleRadii()[i]);
138  delete q1;
139  if (dist2 < dist02) {
140  return false;
141  }
142  }
143  }
144  }
145  }
146  }
147  }
148  // Non-periodic case
149  if ((NP)&&(particleHandler.getNumberOfObjects() > 0 ))
150  {
151  ClumpParticle* mp = dynamic_cast<ClumpParticle*>(&particle);
152  if (mp->isClump()){
153  for (int i = 0; i< mp->NPebble(); i++){
154  for (BaseParticle *q: particleHandler) {
155  if (!q->isClump()) { // check every slave vs every non-master intersection
156  if (Vec3D::getDistanceSquared(q->getPosition(), mp->getPebblePositions()[i])
157  < (q->getRadius() + mp->getPebbleRadii()[i]) * (q->getRadius() + mp->getPebbleRadii()[i])) {
158  return false;
159  }
160  }
161  }
162  }
163  }
164  }
165  return true;
166  }
167 };
168 
169 
int i
Definition: BiCGSTAB_step_by_step.cpp:9
RowVector3d w
Definition: Matrix_resize_int.cpp:3
float * p
Definition: Tutorial_Map_using.cpp:9
Scalar * b
Definition: benchVecAdd.cpp:17
Definition: BaseBoundary.h:28
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Definition: BaseInteractable.h:197
Definition: BaseParticle.h:33
bool isPebble() const
Checks if particle is a pebble (belongs to a clump)
Definition: BaseParticle.h:639
bool isClump() const
Checks if particle is a clump (container)
Definition: BaseParticle.h:630
Mdouble getMaxInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e....
Definition: BaseParticle.h:345
BaseParticle * getClump() const
Definition: BaseParticle.h:622
Basic class for walls.
Definition: BaseWall.h:28
Definition: ClumpParticle.h:20
std::vector< Mdouble > getPebbleRadii()
Definition: ClumpParticle.h:253
int NPebble() const
Definition: ClumpParticle.cc:90
std::vector< Vec3D > getPebblePositions()
Definition: ClumpParticle.h:242
virtual void computeInternalForce(BaseParticle *, BaseParticle *)
Computes the forces between two particles (internal in the sense that the sum over all these forces i...
Definition: DPMBase.cc:3143
virtual void computeForcesDueToWalls(BaseParticle *, BaseWall *)
Computes the forces on the particles due to the walls (normals are outward normals)
Definition: DPMBase.cc:3218
BoundaryHandler boundaryHandler
An object of the class BoundaryHandler which concerns insertion and deletion of particles into or fro...
Definition: DPMBase.h:1458
virtual void computeAllForces()
Computes all the forces acting on the particles using the BaseInteractable::setForce() and BaseIntera...
Definition: DPMBase.cc:3427
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created.
Definition: DPMBase.h:1443
This adds on the hierarchical grid code for 3D problems.
Definition: Mercury3D.h:16
Definition: Mercury3DClump.h:17
void computeForcesDueToWalls(BaseParticle *pI, BaseWall *w) override
Definition: Mercury3DClump.h:43
void computeInternalForce(BaseParticle *P1, BaseParticle *P2) override
Definition: Mercury3DClump.h:27
bool checkClumpForInteractionPeriodic(BaseParticle &particle)
Definition: Mercury3DClump.h:112
Mercury3Dclump()
Definition: Mercury3DClump.h:19
bool checkClumpForInteraction(BaseParticle &particle)
Definition: Mercury3DClump.h:91
void computeAllForces() override
Definition: Mercury3DClump.h:55
unsigned int getNumberOfObjects() const override
Returns the number of objects in the container. In parallel code this practice is forbidden to avoid ...
Definition: ParticleHandler.cc:1323
Defines a pair of periodic walls. Inherits from BaseBoundary.
Definition: PeriodicBoundary.h:20
Definition: Kernel/Math/Vector.h:30
static Vec3D cross(const Vec3D &a, const Vec3D &b)
Calculates the cross product of two Vec3D: .
Definition: Vector.cc:143
static Mdouble getLength(const Vec3D &a)
Calculates the length of a Vec3D: .
Definition: Vector.cc:350
static Mdouble getDistanceSquared(const Vec3D &a, const Vec3D &b)
Calculates the squared distance between two Vec3D: .
Definition: Kernel/Math/Vector.h:303
const char const int const int const RealScalar const RealScalar const int const RealScalar * pb
Definition: level2_impl.h:28
EIGEN_DEVICE_FUNC const Scalar & q
Definition: SpecialFunctionsImpl.h:2019