MercuryDPM  Alpha
 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-2014, 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, Mdouble up)
40 {
41  velocity_ = velocity;
42  left_ = left;
43  right_ = right;
44  down_ = down;
45  up_ = up;
46 }
47 
52 void ShearBoxBoundary::read(std::istream& is)
53 {
54  std::string dummy;
56  is>>dummy>>left_>>dummy>>right_>>dummy>>down_>>dummy>>up_;
57  velocity_=[] (double time UNUSED,double velocity UNUSED) {return 0.0;};
58 }
59 
64 void ShearBoxBoundary::write(std::ostream& os) const
65 {
67  os<<" left "<<left_<<" right "<<right_<<" down "<<down_<<" up "<<up_;
68 }
69 
73 std::string ShearBoxBoundary::getName() const
74 {
75  return "ShearBoxBoundary";
76 }
77 
83 {
84  return new ShearBoxBoundary(*this);
85 }
86 
94 {
95  Mdouble left = p.getPosition().X - left_;
96  Mdouble right = right_ - p.getPosition().X;
97  if (left < right)
98  {
99  positive = true;
100  return left;
101  } else
102  {
103  positive = false;
104  return right;
105  }
106 }
107 
115 {
116  Mdouble down = p.getPosition().Y - down_;
117  Mdouble up = up_ - p.getPosition().Y;
118  if (down < up)
119  {
120  positive = true;
121  return down;
122  } else
123  {
124  positive = false;
125  return up;
126  }
127 }
128 
137 {
138  Mdouble time = getHandler()->getDPMBase()->getTime();
139  Mdouble z = p->getPosition().Z;
140  if (positive)
141  {
142  p->move(Vec3D(right_ - left_, 0.0, 0.0));
143  p->addVelocity(Vec3D(velocity_(time,z), 0.0, 0.0));
144  } else
145  {
146  p->move(Vec3D(left_ - right_, 0.0, 0.0));
147  p->addVelocity(Vec3D(velocity_(time,z), 0.0, 0.0));
148  }
149 }
150 
159 {
160  if (positive)
161  {
162  p->move(Vec3D(0.0, up_ - down_, 0.0));
163  } else
164  {
165  p->move(Vec3D(0.0, down_ - up_, 0.0));
166  }
167 }
168 
178 {
179  bool positive; // TRUE if the particle is closest to the left boundary
180  // wall (set by getVerticalDistance in the following if-statement)
181  // check if particle is close enough to either of the walls
183  {
184  // create a periodic copy of the particle
185  BaseParticle* F0 = p->copy();
186  pH.addObject(F0);
188 
189  // If Particle is doubly shifted, get correct original particle
190  BaseParticle* From = p;
191  while (From->getPeriodicFromParticle() != nullptr)
192  From = From->getPeriodicFromParticle();
193  F0->setPeriodicFromParticle(From);
194 
195  // shift the copy to the 'periodic' position
196  shiftHorizontalPosition(F0, positive);
197 
198  // NB: No extra creation of possible vertical copies of the horizontal copy
199  // here (as compared to createVerticalPeriodicParticles), because these would
200  // overlap with the extra creation of horizontal copies in createVerticalPeriodicParticles.
201  }
202 }
203 
213 {
214  bool positive; // TRUE if the particle is closest to the bottom boundary
215  // wall (set by getVerticalDistance in the following if-statement)
216  // check if particle is close enough to either of the walls
218  {
219  // create a periodic copy of the particle
220  BaseParticle* F0 = p->copy();
221  pH.addObject(F0);
223 
224  // If Particle is doubly shifted, get correct original particle
225  BaseParticle* From = p;
226  while (From->getPeriodicFromParticle() != nullptr)
227  From = From->getPeriodicFromParticle();
228  F0->setPeriodicFromParticle(From);
229 
230  // shift the copy to the 'periodic' position
231  shiftVerticalPosition(F0, positive);
232  while (getHorizontalDistance(*F0, positive) < 0)
233  {
234  shiftHorizontalPosition(F0, positive);
235  }
236 
237  // Create horizontal periodic copies of the copy particle, if needed (i.e.,
238  // if the original particle is in one of the boundary corners).
240  }
241 }
242 
249 {
252 }
253 
260 {
261  bool positive;
262  while (getVerticalDistance(*p, positive) < 0)
263  {
264  shiftVerticalPosition(p, positive);
265  }
266  while (getHorizontalDistance(*p, positive) < 0)
267  {
268  shiftHorizontalPosition(p, positive);
269  }
270  return false;
271 }
272 
273 void ShearBoxBoundary::setVelocity(std::function<double (double,double)> velocity)
274 {
275  velocity_ = velocity;
276 }
BaseParticle * getLargestParticle() const
Gets a pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
Mdouble getVerticalDistance(BaseParticle &p, bool &positive)
Returns distance from given particle to the closest vertical wall.
ShearBoxBoundary * copy() const
Creates a copy of the object.
Mdouble X
the vector components
Definition: Vector.h:52
void addVelocity(const Vec3D &velocity)
adds an increment to the velocity.
void write(std::ostream &os) const
Writes all boundary properties to a stream.
void write(std::ostream &os) const =0
Adds object's id_ to given ostream NB: purely virtual function, overriding the version of BaseObject...
Definition: BaseBoundary.cc:76
double Mdouble
virtual std::string getName() const
Returns the name of the object.
void setPeriodicFromParticle(BaseParticle *p)
Assigns the pointer to the 'original' particle this one's a periodic copy of.
void shiftHorizontalPosition(BaseParticle *p, bool positive)
Applies a horizontal shift to the given particle.
std::function< double(double, double)> velocity_
(signed) Vertical distance between the top wall and the origin
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
void createPeriodicParticles(BaseParticle *p, ParticleHandler &pH)
Creates horizontal and vertical periodic copies of given particle, if needed.
BaseParticle * getPeriodicFromParticle() const
Returns the 'original' particle this one's a periodic copy of.
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
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.
virtual void addObject(BaseParticle *P)
Adds a BaseParticle to the ParticleHandler.
Class which creates a boundary with Lees-Edwards type periodic boundary conditions.
#define UNUSED
Definition: GeneralDefine.h:39
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 read(std::istream &is)
Reads all boundary properties from a stream.
void copyInteractionsForPeriodicParticles(const BaseInteractable &p)
Copies interactions to this BaseInteractable whenever a periodic copy made.
Container to store all BaseParticle.
Mdouble Y
Definition: Vector.h:52
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:473
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
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:543
Mdouble Z
Definition: Vector.h:52
Mdouble getInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e.g., when dealing with wet particles)
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
Access function for the time.
Definition: DPMBase.cc:169
void setVelocity(std::function< double(double, double)>)
virtual BaseParticle * copy() const
Particle copy method. It calls to copy constructor of this Particle, useful for polymorfism.
void read(std::istream &is)=0
Reads the object's id_ from given istream NB: purely virtual function, overriding the version of Base...
Definition: BaseBoundary.cc:67