MercuryDPM  0.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PeriodicBoundary Class Reference

Defines a pair of periodic walls. The particles are in {x: position_left<=normal*x <position_right}, with normal being the outward unit normal vector of the right wall. If a particle moves outside these boundaries, it will be shifted. More...

#include <PeriodicBoundary.h>

+ Inheritance diagram for PeriodicBoundary:

Public Member Functions

virtual PeriodicBoundarycopy () const
 BaseBoundary copy method. More...
 
void set (Vec3D normal_, Mdouble position_left_, Mdouble position_right_)
 Defines a periodic wall, given a normal vector s.t. More...
 
void set (Vec3D normal_, Mdouble position_left_, Mdouble position_right_, Vec3D shift_direction)
 For general parallelogramic domains, the direction of the shift vector has to be set manually. More...
 
void move_left (Mdouble position_)
 Allows the left periodic wall to be moved to a new position and automatically changes its shift value. More...
 
void move_right (Mdouble position_)
 Allows the right periodic wall to be moved to a new position and automatically changes its shift value. More...
 
Mdouble distance (BaseParticle &P)
 Returns the distance of the wall to the particle, and sets left_wall = true, if the left wall is the wall closest to the particle. More...
 
Mdouble distance (const Vec3D &P)
 
void shift_position (BaseParticle *F0)
 shifts the particle (after distance set the left_wall value) More...
 
Vec3D get_shifted_position (Vec3D &Position)
 returns the shifted particle w/o actually shifting More...
 
void shift_positions (Vec3D &PI, Vec3D &PJ)
 shifts two particles More...
 
void get_close_together (Vec3D &P, Vec3D &Q)
 shift P such that it is closest to Q More...
 
void read (std::istream &is)
 reads wall More...
 
void print (std::ostream &os) const
 outputs wall More...
 
Vec3Dget_normal ()
 
int createPeriodicParticles (BaseParticle *P, ParticleHandler &pH)
 
bool checkBoundaryAfterParticleMoved (BaseParticle *P, ParticleHandler &pH UNUSED)
 
- Public Member Functions inherited from BaseBoundary
virtual ~BaseBoundary ()
 
virtual int createPeriodicParticles (BaseParticle *P UNUSED, ParticleHandler &pH UNUSED)
 
virtual bool checkBoundaryAfterParticleMoved (BaseParticle *P UNUSED, ParticleHandler &pH UNUSED)
 
virtual void checkBoundaryActionsBeforeTimeStep (ParticleHandler &pH UNUSED, WallHandler &wH UNUSED, RNG &random UNUSED)
 
void set_Index (int index)
 
void set_Id (int id)
 
void setHandler (BoundaryHandler *handler)
 
virtual void read (std::istream &is UNUSED)=0
 reads boundary More...
 
virtual void print (std::ostream &os UNUSED) const =0
 outputs boundary More...
 
virtual void moveInHandler (int newPos)
 

Private Attributes

bool left_wall
 true if closest wall is the left wall More...
 
Vec3D normal
 outward unit normal vector for right wall More...
 
Mdouble position_left
 position of left wall, s.t. normal*x=position_left More...
 
Mdouble position_right
 position of right wall, s.t. normal*x=position_right More...
 
Mdouble factor
 This is the normal to rescale to unit vectoers. More...
 
Vec3D shift
 shift from left to right boundary More...
 

Detailed Description

Defines a pair of periodic walls. The particles are in {x: position_left<=normal*x <position_right}, with normal being the outward unit normal vector of the right wall. If a particle moves outside these boundaries, it will be shifted.

Definition at line 35 of file PeriodicBoundary.h.

Member Function Documentation

bool PeriodicBoundary::checkBoundaryAfterParticleMoved ( BaseParticle P,
ParticleHandler &pH  UNUSED 
)
inline

Definition at line 201 of file PeriodicBoundary.h.

References distance(), and shift_position().

202  {
203  if (distance(*P)<0)
204  {
205  shift_position(P);
206  }
207  return false;
208  }
Mdouble distance(BaseParticle &P)
Returns the distance of the wall to the particle, and sets left_wall = true, if the left wall is the ...
void shift_position(BaseParticle *F0)
shifts the particle (after distance set the left_wall value)
virtual PeriodicBoundary* PeriodicBoundary::copy ( ) const
inlinevirtual

BaseBoundary copy method.

It calls the copy constructor of this BaseBoundary, useful for polymorphism todo{Does this work correctly?}

Implements BaseBoundary.

Definition at line 38 of file PeriodicBoundary.h.

39  {
40  #ifdef CONSTUCTOR_OUTPUT
41  std::cerr << "virtual PeriodicBoundary* copy() const finished" << std::endl;
42  #endif
43  return new PeriodicBoundary(*this);
44  }
Defines a pair of periodic walls. The particles are in {x: position_left<=normal*x
int PeriodicBoundary::createPeriodicParticles ( BaseParticle P,
ParticleHandler pH 
)
inline

Definition at line 177 of file PeriodicBoundary.h.

References ParticleHandler::addObject(), BaseParticle::copy(), distance(), BaseParticle::get_InteractionRadius(), BaseParticle::get_PeriodicFromParticle(), ParticleHandler::getLargestParticle(), TangentialSpringParticle::reverseTangentialSprings(), BaseParticle::set_periodicFromParticle(), and shift_position().

178  {
180  {
181  BaseParticle* F0=P->copy();
182  shift_position(F0);
183 
184  //If the Particle includes TangentalSprings reverse them
185  TangentialSpringParticle* TSParticle=dynamic_cast<TangentialSpringParticle*>(F0);
186  if(TSParticle)
187  TSParticle->reverseTangentialSprings();
188 
189  //If Particle is Mdouble shifted, get correct original particle
190  BaseParticle* From=P;
191  while(From->get_PeriodicFromParticle()!=NULL)
192  From=From->get_PeriodicFromParticle();
193  F0->set_periodicFromParticle(From);
194 
195  pH.addObject(F0);
196  return 1;
197  }
198  return 0;
199  }
BaseParticle * getLargestParticle() const
Gets a pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
Mdouble get_InteractionRadius() const
BaseParticle * get_PeriodicFromParticle() const
void set_periodicFromParticle(BaseParticle *_new)
Mdouble distance(BaseParticle &P)
Returns the distance of the wall to the particle, and sets left_wall = true, if the left wall is the ...
virtual void addObject(BaseParticle *P)
Adds a BaseParticle to the ParticleHandler.
void shift_position(BaseParticle *F0)
shifts the particle (after distance set the left_wall value)
virtual BaseParticle * copy() const
Particle copy method. It calls to copy contrustor of this Particle, usefull for polymorfism.
Mdouble PeriodicBoundary::distance ( BaseParticle P)
inline

Returns the distance of the wall to the particle, and sets left_wall = true, if the left wall is the wall closest to the particle.

Since this function should be called before calculating any Particle-Wall interactions, it can also be used to set the shift vector in case of curved walls.

Definition at line 96 of file PeriodicBoundary.h.

References BaseParticle::get_Position().

Referenced by checkBoundaryAfterParticleMoved(), createPeriodicParticles(), MD::do_integration_after_force_computation(), StatisticsVector< T >::evaluate_force_statistics(), StatisticsVector< T >::evaluate_particle_statistics(), and StatisticsVector< T >::evaluate_wall_force_statistics().

96  {
97  return distance(P.get_Position());
98  }
Mdouble distance(BaseParticle &P)
Returns the distance of the wall to the particle, and sets left_wall = true, if the left wall is the ...
const Vec3D & get_Position() const
Mdouble PeriodicBoundary::distance ( const Vec3D P)
inline

Definition at line 100 of file PeriodicBoundary.h.

References left_wall, normal, position_left, and position_right.

100  {
101  Mdouble position = Dot(P, normal);
102 
103  if (position - position_left < position_right - position) {
104  left_wall = true;
105  return position - position_left;
106  } else {
107  left_wall = false;
108  return position_right - position;
109  }
110  }
Mdouble position_left
position of left wall, s.t. normal*x=position_left
bool left_wall
true if closest wall is the left wall
Vec3D normal
outward unit normal vector for right wall
double Mdouble
Definition: ExtendedMath.h:33
Mdouble position_right
position of right wall, s.t. normal*x=position_right
void PeriodicBoundary::get_close_together ( Vec3D P,
Vec3D Q 
)
inline

shift P such that it is closest to Q

Definition at line 149 of file PeriodicBoundary.h.

References Vec3D::GetLength2, normal, shift, and sqr.

149  {
150  Mdouble PQdotn = Dot(P-Q, normal);
151  Mdouble shift_norm2 = shift.GetLength2();
152  //Check if P is so far from Q that a shift would move it closer
153  if (sqr(PQdotn) > .25 * shift_norm2) {
154  //Now determine the direction of the shift
155  if (PQdotn>0.0) P -= shift;
156  else P += shift;
157  }
158  }
#define sqr(a)
Definition: ExtendedMath.h:36
friend Mdouble GetLength2(const Vec3D &A)
Definition: Vector.h:183
Vec3D normal
outward unit normal vector for right wall
double Mdouble
Definition: ExtendedMath.h:33
Vec3D shift
shift from left to right boundary
Vec3D& PeriodicBoundary::get_normal ( )
inline

Definition at line 175 of file PeriodicBoundary.h.

References normal.

175 {return normal;}
Vec3D normal
outward unit normal vector for right wall
Vec3D PeriodicBoundary::get_shifted_position ( Vec3D Position)
inline

returns the shifted particle w/o actually shifting

Definition at line 125 of file PeriodicBoundary.h.

References left_wall, and shift.

125  {
126  if (left_wall) {
127  return Position + shift;
128  }
129  else {
130  return Position - shift;
131  }
132  }
bool left_wall
true if closest wall is the left wall
Vec3D shift
shift from left to right boundary
void PeriodicBoundary::move_left ( Mdouble  position_)
inline

Allows the left periodic wall to be moved to a new position and automatically changes its shift value.

Definition at line 75 of file PeriodicBoundary.h.

References factor, normal, position_left, position_right, and shift.

76  {
77  position_left=position_*factor;
79  }
Mdouble position_left
position of left wall, s.t. normal*x=position_left
Vec3D normal
outward unit normal vector for right wall
Mdouble factor
This is the normal to rescale to unit vectoers.
Mdouble position_right
position of right wall, s.t. normal*x=position_right
Vec3D shift
shift from left to right boundary
void PeriodicBoundary::move_right ( Mdouble  position_)
inline

Allows the right periodic wall to be moved to a new position and automatically changes its shift value.

Definition at line 82 of file PeriodicBoundary.h.

References factor, normal, position_left, position_right, and shift.

83  {
84  position_right=position_*factor;
86  }
Mdouble position_left
position of left wall, s.t. normal*x=position_left
Vec3D normal
outward unit normal vector for right wall
Mdouble factor
This is the normal to rescale to unit vectoers.
Mdouble position_right
position of right wall, s.t. normal*x=position_right
Vec3D shift
shift from left to right boundary
void PeriodicBoundary::print ( std::ostream &  os) const
inline

outputs wall

Definition at line 168 of file PeriodicBoundary.h.

References normal, position_left, position_right, and shift.

168  {
169  os << "PeriodicBoundary normal " << normal
170  << " position_left " << position_left
171  << " position_right " << position_right
172  << " shift " << shift;
173  }
Mdouble position_left
position of left wall, s.t. normal*x=position_left
Vec3D normal
outward unit normal vector for right wall
Mdouble position_right
position of right wall, s.t. normal*x=position_right
Vec3D shift
shift from left to right boundary
void PeriodicBoundary::read ( std::istream &  is)
inline

reads wall

Definition at line 162 of file PeriodicBoundary.h.

References normal, position_left, position_right, and shift.

162  {
163  std::string dummy;
164  is >> dummy >> normal >> dummy >> position_left >> dummy >> position_right >> dummy >> shift;
165  }
Mdouble position_left
position of left wall, s.t. normal*x=position_left
Vec3D normal
outward unit normal vector for right wall
Mdouble position_right
position of right wall, s.t. normal*x=position_right
Vec3D shift
shift from left to right boundary
void PeriodicBoundary::set ( Vec3D  normal_,
Mdouble  position_left_,
Mdouble  position_right_ 
)
inline

Defines a periodic wall, given a normal vector s.t.

all particles are within {x: position_left<=normal*x<position_right}. The shift vector is set assuming that the domain is rectangular (shift parallel to normal).

Definition at line 52 of file PeriodicBoundary.h.

References factor, normal, position_left, position_right, and shift.

Referenced by MD::load_par_ini_file(), Chute::setup_particles_initial_conditions(), and ChuteBottom::setup_particles_initial_conditions().

52  {
53  // factor is used to set normal to unit length
54  factor = 1. / sqrt(Dot(normal_, normal_));
55  normal = normal_ * factor;
56  position_left = position_left_ * factor;
57  position_right = position_right_ * factor;
59  }
Mdouble position_left
position of left wall, s.t. normal*x=position_left
Vec3D normal
outward unit normal vector for right wall
Mdouble factor
This is the normal to rescale to unit vectoers.
Mdouble position_right
position of right wall, s.t. normal*x=position_right
Vec3D shift
shift from left to right boundary
void PeriodicBoundary::set ( Vec3D  normal_,
Mdouble  position_left_,
Mdouble  position_right_,
Vec3D  shift_direction 
)
inline

For general parallelogramic domains, the direction of the shift vector has to be set manually.

Definition at line 63 of file PeriodicBoundary.h.

References factor, normal, position_left, position_right, and shift.

63  {
64  // factor is used to set normal to unit length
65  factor = 1. / sqrt(Dot(normal_, normal_));
66  normal = normal_ * factor;
67  position_left = position_left_ * factor;
68  position_right = position_right_ * factor;
69  // factor is used to set shift vector to correct length
70  factor = (position_right - position_left) * Dot(shift_direction, normal);
71  shift = shift_direction * factor;
72  }
Mdouble position_left
position of left wall, s.t. normal*x=position_left
Vec3D normal
outward unit normal vector for right wall
Mdouble factor
This is the normal to rescale to unit vectoers.
Mdouble position_right
position of right wall, s.t. normal*x=position_right
Vec3D shift
shift from left to right boundary
void PeriodicBoundary::shift_position ( BaseParticle F0)
inline

shifts the particle (after distance set the left_wall value)

Definition at line 113 of file PeriodicBoundary.h.

References left_wall, BaseParticle::move(), and shift.

Referenced by checkBoundaryAfterParticleMoved(), createPeriodicParticles(), MD::do_integration_after_force_computation(), and StatisticsVector< T >::evaluate_particle_statistics().

113  {
114  if (left_wall) {
115  F0->move(shift);
116  left_wall = false;
117  }
118  else {
119  F0->move(-shift);
120  left_wall = true;
121  }
122  }
bool left_wall
true if closest wall is the left wall
void move(const Vec3D &_new)
Vec3D shift
shift from left to right boundary
void PeriodicBoundary::shift_positions ( Vec3D PI,
Vec3D PJ 
)
inline

shifts two particles

Definition at line 135 of file PeriodicBoundary.h.

References left_wall, and shift.

Referenced by StatisticsVector< T >::evaluate_force_statistics(), and StatisticsVector< T >::evaluate_wall_force_statistics().

135  {
136  if (left_wall) {
137  PI += shift;
138  PJ += shift;
139  left_wall = false;
140  }
141  else {
142  PI -= shift;
143  PJ -= shift;
144  left_wall = true;
145  }
146  }
bool left_wall
true if closest wall is the left wall
Vec3D shift
shift from left to right boundary

Member Data Documentation

Mdouble PeriodicBoundary::factor
private

This is the normal to rescale to unit vectoers.

Definition at line 215 of file PeriodicBoundary.h.

Referenced by move_left(), move_right(), and set().

bool PeriodicBoundary::left_wall
private

true if closest wall is the left wall

Definition at line 211 of file PeriodicBoundary.h.

Referenced by distance(), get_shifted_position(), shift_position(), and shift_positions().

Vec3D PeriodicBoundary::normal
private

outward unit normal vector for right wall

Definition at line 212 of file PeriodicBoundary.h.

Referenced by distance(), get_close_together(), get_normal(), move_left(), move_right(), print(), read(), and set().

Mdouble PeriodicBoundary::position_left
private

position of left wall, s.t. normal*x=position_left

Definition at line 213 of file PeriodicBoundary.h.

Referenced by distance(), move_left(), move_right(), print(), read(), and set().

Mdouble PeriodicBoundary::position_right
private

position of right wall, s.t. normal*x=position_right

Definition at line 214 of file PeriodicBoundary.h.

Referenced by distance(), move_left(), move_right(), print(), read(), and set().

Vec3D PeriodicBoundary::shift
private

shift from left to right boundary

Definition at line 216 of file PeriodicBoundary.h.

Referenced by get_close_together(), get_shifted_position(), move_left(), move_right(), print(), read(), set(), shift_position(), and shift_positions().


The documentation for this class was generated from the following file: