MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ShearBoxBoundary.cc
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 #include "ShearBoxBoundary.h"
27 #include "ParticleHandler.h"
28 #include "Particles/BaseParticle.h"
29 #include "DPMBase.h"
30 
39 void ShearBoxBoundary::set(std::function<double(double, double)> velocity, Mdouble left, Mdouble right, Mdouble down,
40  Mdouble up)
41 {
42  velocity_ = velocity;
43  left_ = left;
44  right_ = right;
45  down_ = down;
46  up_ = up;
47 }
48 
53 void ShearBoxBoundary::read(std::istream& is)
54 {
55  std::string dummy;
57  is >> dummy >> left_ >> dummy >> right_ >> dummy >> down_ >> dummy >> up_;
58  velocity_ = [](double time UNUSED, double velocity UNUSED) { return 0.0; };
59 }
60 
65 void ShearBoxBoundary::write(std::ostream& os) const
66 {
68  os << " left " << left_ << " right " << right_ << " down " << down_ << " up " << up_;
69 }
70 
74 std::string ShearBoxBoundary::getName() const
75 {
76  return "ShearBoxBoundary";
77 }
78 
84 {
85  return new ShearBoxBoundary(*this);
86 }
87 
95 {
96  Mdouble left = p.getPosition().X - left_;
97  Mdouble right = right_ - p.getPosition().X;
98  if (left < right)
99  {
100  positive = true;
101  return left;
102  }
103  else
104  {
105  positive = false;
106  return right;
107  }
108 }
109 
117 {
118  Mdouble down = p.getPosition().Y - down_;
119  Mdouble up = up_ - p.getPosition().Y;
120  if (down < up)
121  {
122  positive = true;
123  return down;
124  }
125  else
126  {
127  positive = false;
128  return up;
129  }
130 }
131 
140 {
141  Mdouble time = getHandler()->getDPMBase()->getTime();
142  Mdouble z = p->getPosition().Z;
143  if (positive)
144  {
145  p->move(Vec3D(right_ - left_, 0.0, 0.0));
146  p->addVelocity(Vec3D(velocity_(time, z), 0.0, 0.0));
147  }
148  else
149  {
150  p->move(Vec3D(left_ - right_, 0.0, 0.0));
151  p->addVelocity(Vec3D(velocity_(time, z), 0.0, 0.0));
152  }
153 }
154 
163 {
164  if (positive)
165  {
166  p->move(Vec3D(0.0, up_ - down_, 0.0));
167  }
168  else
169  {
170  p->move(Vec3D(0.0, down_ - up_, 0.0));
171  }
172 }
173 
183 {
184  bool positive; // TRUE if the particle is closest to the left boundary
185  // wall (set by getVerticalDistance in the following if-statement)
186  // check if particle is close enough to either of the walls
188  if (getHorizontalDistance(*p, positive) < maxDistance)
189  {
190  // create a periodic copy of the particle
191  BaseParticle* F0 = p->copy();
192  pH.addObject(F0);
194 
195  // If Particle is doubly shifted, get correct original particle
196  BaseParticle* From = p;
197  while (From->getPeriodicFromParticle() != nullptr)
198  From = From->getPeriodicFromParticle();
199  F0->setPeriodicFromParticle(From);
200 
201  // shift the copy to the 'periodic' position
202  shiftHorizontalPosition(F0, positive);
203 
204  // NB: No extra creation of possible vertical copies of the horizontal copy
205  // here (as compared to createVerticalPeriodicParticles), because these would
206  // overlap with the extra creation of horizontal copies in createVerticalPeriodicParticles.
207  }
208 }
209 
219 {
220  bool positive; // TRUE if the particle is closest to the bottom boundary
221  // wall (set by getVerticalDistance in the following if-statement)
222  // check if particle is close enough to either of the walls
224  if (getVerticalDistance(*p, positive) < maxDistance)
225  {
226  // create a periodic copy of the particle
227  BaseParticle* F0 = p->copy();
228  pH.addObject(F0);
230 
231  // If Particle is doubly shifted, get correct original particle
232  BaseParticle* From = p;
233  while (From->getPeriodicFromParticle() != nullptr)
234  From = From->getPeriodicFromParticle();
235  F0->setPeriodicFromParticle(From);
236 
237  // shift the copy to the 'periodic' position
238  shiftVerticalPosition(F0, positive);
239  while (getHorizontalDistance(*F0, positive) < 0)
240  {
241  shiftHorizontalPosition(F0, positive);
242  }
243 
244  // Create horizontal periodic copies of the copy particle, if needed (i.e.,
245  // if the original particle is in one of the boundary corners).
247  }
248 }
249 
256 {
259 }
260 
267 {
268  bool positive;
269  while (getVerticalDistance(*p, positive) < 0)
270  {
271  shiftVerticalPosition(p, positive);
272  }
273  while (getHorizontalDistance(*p, positive) < 0)
274  {
275  shiftHorizontalPosition(p, positive);
276  }
277  return false;
278 }
279 
280 void ShearBoxBoundary::setVelocity(std::function<double(double, double)> velocity)
281 {
282  velocity_ = velocity;
283 }
BaseParticle * getLargestParticle() const
Returns the pointer of the largest particle in the particle handler. When mercury is running in paral...
Mdouble getVerticalDistance(BaseParticle &p, bool &positive)
Returns distance from given particle to the closest vertical wall.
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Mdouble X
the vector components
Definition: Vector.h:65
void addVelocity(const Vec3D &velocity)
adds an increment to the velocity.
void addObject(BaseParticle *P) override
Adds a BaseParticle to the ParticleHandler.
void read(std::istream &is) override
Reads all boundary properties from a stream.
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getMaxInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e.g., when dealing with wet particles)
Definition: BaseParticle.h:359
std::function< double(double, double)> velocity_
(signed) Vertical distance between the top wall and the origin
void setPeriodicFromParticle(BaseParticle *p)
Assigns the pointer to the 'original' particle this one's a periodic copy of (used in periodic bounda...
Definition: BaseParticle.h:438
void shiftHorizontalPosition(BaseParticle *p, bool positive)
Applies a horizontal shift to the given particle.
BaseParticle * getPeriodicFromParticle() const
Returns the 'original' particle this one's a periodic copy of.
Definition: BaseParticle.h:338
void read(std::istream &is) override=0
Reads the object's id_ from given istream NB: purely virtual function, overriding the version of Base...
Definition: BaseBoundary.cc:61
virtual BaseParticle * copy() const =0
Particle copy method. It calls to copy constructor of this Particle, useful for polymorfism.
void createPeriodicParticles(BaseParticle *p, ParticleHandler &pH)
Creates horizontal and vertical periodic copies of given particle, if needed.
void shiftVerticalPosition(BaseParticle *p, bool positive)
Applies a vertical shift to the given particle.
Mdouble up_
(signed) Vertical distance between the bottom wall and the origin
std::string getName() const override
Returns the name of the object.
void createHorizontalPeriodicParticles(BaseParticle *p, ParticleHandler &pH)
Creates horizontal periodic copies of given particle, if needed.
void createVerticalPeriodicParticles(BaseParticle *p, ParticleHandler &pH)
Creates vertical periodic copies of given particle, if needed.
Class which creates a boundary with Lees-Edwards type periodic boundary conditions.
#define UNUSED
Definition: GeneralDefine.h:39
void write(std::ostream &os) const override=0
Adds object's id_ to given ostream NB: purely virtual function, overriding the version of BaseObject...
Definition: BaseBoundary.cc:70
BoundaryHandler * getHandler() const
Returns the boundary's BoundaryHandler.
Mdouble getHorizontalDistance(BaseParticle &p, bool &positive)
Returns distance from given particle to the closest horizontal wall.
void copyInteractionsForPeriodicParticles(const BaseInteractable &p)
Copies interactions to this BaseInteractable whenever a periodic copy made.
void write(std::ostream &os) const override
Writes all boundary properties to a stream.
Container to store all BaseParticle.
Mdouble Y
Definition: Vector.h:65
void set(std::function< double(double, double)> velocity, Mdouble left, Mdouble right, Mdouble down, Mdouble up)
Sets all boundary properties.
bool checkBoundaryAfterParticleMoved(BaseParticle *p, ParticleHandler &pH UNUSED)
Checks if particle crossed a boundary wall and if so, applies periodic shift.
T * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
Definition: BaseHandler.h:634
Definition: Vector.h:49
virtual void move(const Vec3D &move)
Moves this BaseInteractable by adding an amount to the position.
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725
Mdouble Z
Definition: Vector.h:65
Mdouble right_
(signed) Horizontal distance between the left wall and the origin
Mdouble down_
(signed) Horizontal distance between the right wall and the origin
Mdouble getTime() const
Returns the current simulation time.
Definition: DPMBase.cc:797
void setVelocity(std::function< double(double, double)>)
ShearBoxBoundary * copy() const override
Creates a copy of the object.