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

Defines a pair of periodic walls that are angled around the origin. More...

#include <AngledPeriodicBoundary.h>

+ Inheritance diagram for AngledPeriodicBoundary:

Public Member Functions

virtual AngledPeriodicBoundarycopy () const
 BaseBoundary copy method. More...
 
void set (Vec3D normal_left_, Vec3D normal_right_, Vec3D origin_)
 Defines a periodic wall, given a normal vector s.t. 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 *P)
 shifts the particle (after distance set the left_wall value) 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

Vec3D normal_left
 outward unit normal vector for left wall More...
 
Vec3D normal_right
 outward unit normal vector for right wall More...
 
Vec3D origin
 common point of both walls More...
 
bool left_wall
 true if closest wall is the left wall More...
 
Vec3D radialAxis_left
 outward unit normal vector for left wall More...
 
Vec3D radialAxis_right
 outward unit normal vector for right wall More...
 
Vec3D diff_radial
 
Vec3D diff_normal
 
Vec3D common_axis
 
Vec3D angularShift
 

Detailed Description

Defines a pair of periodic walls that are angled around the origin.

The particles are in {x: normal_left*(x-origin)>0 && normal_right*(x-origin)<0, with normal* being the unit normal vector of the walls. If a particle moves outside these boundaries, it will be shifted.

Definition at line 38 of file AngledPeriodicBoundary.h.

Member Function Documentation

bool AngledPeriodicBoundary::checkBoundaryAfterParticleMoved ( BaseParticle P,
ParticleHandler &pH  UNUSED 
)
inline
Todo:
{TW: can't we do the shift in the createPeriodicParticles function only? We are checking the distance three times!}

Definition at line 247 of file AngledPeriodicBoundary.h.

References distance(), and shift_position().

248  {
249  //std::cout << "checkBoundaryAfterParticleMoved" << std::endl;
250  if (distance(*P)<0)
251  shift_position(P);
252  return false;
253  }
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 *P)
shifts the particle (after distance set the left_wall value)
virtual AngledPeriodicBoundary* AngledPeriodicBoundary::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 41 of file AngledPeriodicBoundary.h.

42  {
43  #ifdef CONSTUCTOR_OUTPUT
44  std::cerr << "virtual AngledPeriodicBoundary* copy() const finished" << std::endl;
45  #endif
46  return new AngledPeriodicBoundary(*this);
47  }
Defines a pair of periodic walls that are angled around the origin.
int AngledPeriodicBoundary::createPeriodicParticles ( BaseParticle P,
ParticleHandler pH 
)
inline
Todo:
{TW: shouldn't that return a boolean?}

Definition at line 194 of file AngledPeriodicBoundary.h.

References ParticleHandler::addObject(), BaseParticle::copy(), diff_normal, diff_radial, distance(), BaseParticle::get_InteractionRadius(), BaseParticle::get_PeriodicFromParticle(), TangentialSpringParticle::get_TangentialSprings(), ParticleHandler::getLargestParticle(), left_wall, normal_left, normal_right, radialAxis_left, radialAxis_right, TangentialSpringParticle::reverseTangentialSprings(), BaseParticle::set_periodicFromParticle(), and shift_position().

195  {
196  //std::cout << "createPeriodicParticles" << std::endl;
198  {
199  BaseParticle* F0=P->copy();
200  shift_position(F0);
201 
202  //If the Particle includes TangentalSprings reverse them
203  TangentialSpringParticle* TSParticle=dynamic_cast<TangentialSpringParticle*>(F0);
204  if(TSParticle) {
205  TSParticle->reverseTangentialSprings();
206  for(std::vector<CTangentialSpring>::iterator it = TSParticle->get_TangentialSprings().begin(); it!=TSParticle->get_TangentialSprings().end();it++)
207  {
208  //std::cout << it->delta << std::endl;
209  if (!left_wall) {
210  Mdouble normalDistance = Dot(it->delta,normal_left);
211  Mdouble radialDistance = Dot(it->delta,radialAxis_left);
212  it->delta += normalDistance*diff_normal+radialDistance*diff_radial;
213  normalDistance = Dot(it->RollingSpring,normal_left);
214  radialDistance = Dot(it->RollingSpring,radialAxis_left);
215  it->RollingSpring += normalDistance*diff_normal+radialDistance*diff_radial;
216  normalDistance = Dot(it->TorsionSpring,normal_left);
217  radialDistance = Dot(it->TorsionSpring,radialAxis_left);
218  it->TorsionSpring += normalDistance*diff_normal+radialDistance*diff_radial;
219  } else {
220  Mdouble normalDistance = Dot(it->delta,normal_right);
221  Mdouble radialDistance = Dot(it->delta,radialAxis_right);
222  it->delta -= normalDistance*diff_normal+radialDistance*diff_radial;
223  normalDistance = Dot(it->RollingSpring,normal_right);
224  radialDistance = Dot(it->RollingSpring,radialAxis_right);
225  it->RollingSpring -= normalDistance*diff_normal+radialDistance*diff_radial;
226  normalDistance = Dot(it->TorsionSpring,normal_right);
227  radialDistance = Dot(it->TorsionSpring,radialAxis_right);
228  it->TorsionSpring -= normalDistance*diff_normal+radialDistance*diff_radial;
229  }
230  //std::cout << it->delta << std::endl;
231  }
232  }
233 
234  //If Particle is Mdouble shifted, get correct original particle
235  BaseParticle* From=P;
236  while(From->get_PeriodicFromParticle()!=NULL)
237  From=From->get_PeriodicFromParticle();
238  F0->set_periodicFromParticle(From);
239 
240  pH.addObject(F0);
241  return 1;
242  }
243  return 0;
244  }
Vec3D normal_right
outward unit normal vector for right wall
Vec3D radialAxis_right
outward unit normal vector for right wall
BaseParticle * getLargestParticle() const
Gets a pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
Mdouble get_InteractionRadius() const
bool left_wall
true if closest wall is the left wall
BaseParticle * get_PeriodicFromParticle() const
Vec3D normal_left
outward unit normal vector for left wall
CTangentialSprings & get_TangentialSprings()
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 ...
double Mdouble
Definition: ExtendedMath.h:33
virtual void addObject(BaseParticle *P)
Adds a BaseParticle to the ParticleHandler.
Vec3D radialAxis_left
outward unit normal vector for left wall
virtual BaseParticle * copy() const
Particle copy method. It calls to copy contrustor of this Particle, usefull for polymorfism.
void shift_position(BaseParticle *P)
shifts the particle (after distance set the left_wall value)
Mdouble AngledPeriodicBoundary::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 83 of file AngledPeriodicBoundary.h.

References BaseParticle::get_Position().

Referenced by checkBoundaryAfterParticleMoved(), and createPeriodicParticles().

83  {
84  return distance(P.get_Position());
85  }
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 AngledPeriodicBoundary::distance ( const Vec3D P)
inline

Definition at line 88 of file AngledPeriodicBoundary.h.

References left_wall, normal_left, normal_right, and origin.

88  {
89  Vec3D position = P-origin;
90  Mdouble distance_left = Dot(position,normal_left);
91  Mdouble distance_right = -Dot(position,normal_right);
92 
93  if (distance_left<distance_right) {
94  left_wall = true;
95  //std::cout << "left wall, " << position << ", distance " << distance_left << "<" << distance_right << std::endl;
96  return distance_left;
97  } else {
98  left_wall = false;
99  //std::cout << "right wall, " << position << ", distance " << distance_right << "<" << distance_left << std::endl;
100  return distance_right;
101  }
102  }
Vec3D normal_right
outward unit normal vector for right wall
bool left_wall
true if closest wall is the left wall
Vec3D normal_left
outward unit normal vector for left wall
Vec3D origin
common point of both walls
double Mdouble
Definition: ExtendedMath.h:33
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:40
Vec3D& AngledPeriodicBoundary::get_normal ( )
inline

Definition at line 188 of file AngledPeriodicBoundary.h.

References left_wall, normal_left, and normal_right.

188  {
189  if (left_wall) return normal_left;
190  else return normal_right;
191  }
Vec3D normal_right
outward unit normal vector for right wall
bool left_wall
true if closest wall is the left wall
Vec3D normal_left
outward unit normal vector for left wall
void AngledPeriodicBoundary::print ( std::ostream &  os) const
inline

outputs wall

Definition at line 182 of file AngledPeriodicBoundary.h.

References normal_left, normal_right, and origin.

182  {
183  os << "AngledPeriodicBoundary normal_left " << normal_left
184  << " normal_right " << normal_right
185  << " origin " << origin;
186  }
Vec3D normal_right
outward unit normal vector for right wall
Vec3D normal_left
outward unit normal vector for left wall
Vec3D origin
common point of both walls
void AngledPeriodicBoundary::read ( std::istream &  is)
inline

reads wall

Definition at line 176 of file AngledPeriodicBoundary.h.

References normal_left, normal_right, and origin.

176  {
177  std::string dummy;
178  is >> dummy >> normal_left >> dummy >> normal_right >> dummy >> origin;
179  }
Vec3D normal_right
outward unit normal vector for right wall
Vec3D normal_left
outward unit normal vector for left wall
Vec3D origin
common point of both walls
void AngledPeriodicBoundary::set ( Vec3D  normal_left_,
Vec3D  normal_right_,
Vec3D  origin_ 
)
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).

Todo:
{I cannot calculate angular shift; right now this works only for quarter walls; maybe this has to wait till quaternions are implemented.}

Definition at line 58 of file AngledPeriodicBoundary.h.

References common_axis, Cross(), diff_normal, diff_radial, normal_left, normal_right, origin, radialAxis_left, and radialAxis_right.

58  {
59  origin=origin_;
60  normal_left = normal_left_ / GetLength(normal_left_);
61  normal_right = normal_right_ / GetLength(normal_right_);
63  common_axis /= GetLength(common_axis);
69  //angularShift = 0;
70  // std::cout << "common_axis " << common_axis
71  // << ", radialAxis_left " << radialAxis_left
72  // << ", radialAxis_right " << radialAxis_right
73  // << ", angularShift " << angularShift
74  // << std::endl;
75  }
Vec3D normal_right
outward unit normal vector for right wall
Vec3D radialAxis_right
outward unit normal vector for right wall
Matrix3D Cross(const Vec3D &A, const Matrix3D &B)
Definition: Matrix.h:198
Vec3D normal_left
outward unit normal vector for left wall
Vec3D origin
common point of both walls
Vec3D radialAxis_left
outward unit normal vector for left wall
void AngledPeriodicBoundary::shift_position ( BaseParticle P)
inline

shifts the particle (after distance set the left_wall value)

Todo:
add velocity, angular, springs shift
Todo:
{TW: not sure how to calculate the angular position in common_axis direction}
Todo:
tangential spring

Definition at line 106 of file AngledPeriodicBoundary.h.

References BaseParticle::accelerate(), diff_normal, diff_radial, BaseParticle::get_Angle(), BaseParticle::get_Position(), BaseParticle::get_Velocity(), left_wall, BaseParticle::move(), normal_left, normal_right, origin, radialAxis_left, radialAxis_right, and BaseParticle::rotate().

Referenced by checkBoundaryAfterParticleMoved(), and createPeriodicParticles().

106  {
107  Vec3D position = P->get_Position()-origin;
108  if (left_wall) {
109  Mdouble normalDistance = Dot(position,normal_left);
110  Mdouble radialDistance = Dot(position,radialAxis_left);
111  P->move(normalDistance*diff_normal+radialDistance*diff_radial);
112  Mdouble normalVelocity = Dot(P->get_Velocity(),normal_left);
113  Mdouble radialVelocity = Dot(P->get_Velocity(),radialAxis_left);
114  P->accelerate(normalVelocity*diff_normal+radialVelocity*diff_radial);
115  Mdouble normalAngularDistance = Dot(P->get_Angle(),normal_left);
116  Mdouble radialAngularDistance = Dot(P->get_Angle(),radialAxis_left);
118  P->rotate(normalAngularDistance*diff_normal+radialAngularDistance*diff_radial);
119  left_wall = false;
121  //std::cout << "shift to right wall, " << P->get_Position() << std::endl;
122  }
123  else {
124  Mdouble normalDistance = Dot(position,normal_right);
125  Mdouble radialDistance = Dot(position,radialAxis_right);
126  P->move(-normalDistance*diff_normal-radialDistance*diff_radial);
127  Mdouble normalVelocity = Dot(P->get_Velocity(),normal_right);
128  Mdouble radialVelocity = Dot(P->get_Velocity(),radialAxis_right);
129  P->accelerate(-normalVelocity*diff_normal-radialVelocity*diff_radial);
130  Mdouble normalAngularDistance = Dot(P->get_Angle(),normal_right);
131  Mdouble radialAngularDistance = Dot(P->get_Angle(),radialAxis_right);
132  P->rotate(-normalAngularDistance*diff_normal-radialAngularDistance*diff_radial);
133  left_wall = true;
134  //std::cout << "shift to left wall, " << P->get_Position() << std::endl;
135  }
136  }
Vec3D normal_right
outward unit normal vector for right wall
Vec3D radialAxis_right
outward unit normal vector for right wall
const Vec3D & get_Velocity() const
void rotate(const Vec3D &_new)
bool left_wall
true if closest wall is the left wall
Vec3D normal_left
outward unit normal vector for left wall
Vec3D origin
common point of both walls
double Mdouble
Definition: ExtendedMath.h:33
void move(const Vec3D &_new)
const Vec3D & get_Position() const
Vec3D radialAxis_left
outward unit normal vector for left wall
const Vec3D & get_Angle() const
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:40
void accelerate(const Vec3D &_new)

Member Data Documentation

Vec3D AngledPeriodicBoundary::angularShift
private

Definition at line 267 of file AngledPeriodicBoundary.h.

Vec3D AngledPeriodicBoundary::common_axis
private

Definition at line 266 of file AngledPeriodicBoundary.h.

Referenced by set().

Vec3D AngledPeriodicBoundary::diff_normal
private

Definition at line 265 of file AngledPeriodicBoundary.h.

Referenced by createPeriodicParticles(), set(), and shift_position().

Vec3D AngledPeriodicBoundary::diff_radial
private

Definition at line 264 of file AngledPeriodicBoundary.h.

Referenced by createPeriodicParticles(), set(), and shift_position().

bool AngledPeriodicBoundary::left_wall
private

true if closest wall is the left wall

Definition at line 261 of file AngledPeriodicBoundary.h.

Referenced by createPeriodicParticles(), distance(), get_normal(), and shift_position().

Vec3D AngledPeriodicBoundary::normal_left
private

outward unit normal vector for left wall

Definition at line 257 of file AngledPeriodicBoundary.h.

Referenced by createPeriodicParticles(), distance(), get_normal(), print(), read(), set(), and shift_position().

Vec3D AngledPeriodicBoundary::normal_right
private

outward unit normal vector for right wall

Definition at line 258 of file AngledPeriodicBoundary.h.

Referenced by createPeriodicParticles(), distance(), get_normal(), print(), read(), set(), and shift_position().

Vec3D AngledPeriodicBoundary::origin
private

common point of both walls

Definition at line 259 of file AngledPeriodicBoundary.h.

Referenced by distance(), print(), read(), set(), and shift_position().

Vec3D AngledPeriodicBoundary::radialAxis_left
private

outward unit normal vector for left wall

Definition at line 262 of file AngledPeriodicBoundary.h.

Referenced by createPeriodicParticles(), set(), and shift_position().

Vec3D AngledPeriodicBoundary::radialAxis_right
private

outward unit normal vector for right wall

Definition at line 263 of file AngledPeriodicBoundary.h.

Referenced by createPeriodicParticles(), set(), and shift_position().


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