MercuryDPM  Beta
PeriodicBoundary Class Reference

Defines a pair of periodic walls. Inherits from BaseBoundary. More...

#include <PeriodicBoundary.h>

Inheritance diagram for PeriodicBoundary:

## Public Member Functions

PeriodicBoundary ()
default constructor More...

~PeriodicBoundary ()
destructor More...

PeriodicBoundarycopy () const
copy method More...

void set (Vec3D normal, Mdouble distanceLeft, Mdouble distanceRight)
Defines a periodic wall. More...

void set (Vec3D normal, Mdouble distanceLeft, Mdouble distanceRight, Vec3D shiftDirection)
For general parallelogramic domains, the direction of the shift vector can to be set manually. More...

void moveLeft (Mdouble distanceLeft)
Sets the distance from the origin of the 'left' periodic wall. More...

void moveRight (Mdouble distanceRight)
Sets the distance from the origin of the 'right' periodic wall. More...

Mdouble getDistance (BaseParticle &p)
Returns the distance of the wall to the particle. More...

Mdouble getDistance (const Vec3D &position)
Returns the distance of the wall to the position. More...

void shiftPosition (BaseParticle *p)
shifts the particle More...

void shiftPositions (Vec3D &postition1, Vec3D &postion2)
shifts two positions More...

bool isClosestToLeftBoundary () const
Returns TRUE if last particle/position checked is closest to the 'left' wall, and FALSE if it is closest to the 'right' wall. More...

void read (std::istream &is)
reads boundary properties from istream More...

MERCURY_DEPRECATED void oldRead (std::istream &is)
deprecated version of CubeInsertionBoundary::read(). More...

void write (std::ostream &os) const
writes boundary properties to ostream More...

virtual std::string getName () const
Returns the name of the object. More...

void createPeriodicParticles (BaseParticle *p, ParticleHandler &pH)
Checks distance of particle to closest wall and creates periodic copy if necessary. More...

bool checkBoundaryAfterParticleMoved (BaseParticle *p, ParticleHandler &pH UNUSED)
Checks if particle has crossed either boundary wall, and applies a shift if that is the case. NB: ALWAYS returns FALSE. More...

Public Member Functions inherited from BaseBoundary
BaseBoundary ()
default constructor. More...

BaseBoundary (const BaseBoundary &b)
copy constructor More...

virtual ~BaseBoundary ()
destructor More...

virtual void createPeriodicParticles (BaseParticle *P UNUSED, ParticleHandler &pH UNUSED)
Creates periodic copies of given particle in case of periodic boundaries. More...

virtual bool checkBoundaryAfterParticleMoved (BaseParticle *P UNUSED, ParticleHandler &pH UNUSED)
Checks if given particle passed the boundary. More...

virtual void checkBoundaryBeforeTimeStep (DPMBase *md UNUSED)
Fills a (3D) boundary with particles. More...

void setHandler (BoundaryHandler *handler)
Sets the boundary's BoundaryHandler. More...

BoundaryHandlergetHandler () const
Returns the boundary's BoundaryHandler. More...

Public Member Functions inherited from BaseObject
BaseObject ()
Default constructor. More...

BaseObject (const BaseObject &p)
Copy constructor, copies all the objects BaseObject contains. More...

virtual ~BaseObject ()
virtual destructor More...

virtual void moveInHandler (const unsigned int index)
Except that it is virtual, it does the same thing as setIndex() does. More...

void setIndex (const unsigned int index)
Allows one to assign an index to an object in the handler/container. More...

void setId (const unsigned int id)
Assigns a unique identifier to each object in the handler (container) which remains constant even after the object is deleted from the container/handler. More...

unsigned int getIndex () const
Returns the index of the object in the handler. More...

unsigned int getId () const
Returns the unique identifier of any particular object. More...

## Private Attributes

bool closestToLeftBoundary_
true if closest wall is the left wall More...

Vec3D normal_
outward unit normal vector for right wall More...

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

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

Mdouble scaleFactor_
This is the normal to rescale the normal vector to a unit vectors. More...

Vec3D shift_
shift from left to right boundary More...

## Detailed Description

Defines a pair of periodic walls. Inherits from BaseBoundary.

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 41 of file PeriodicBoundary.h.

## Constructor & Destructor Documentation

 PeriodicBoundary::PeriodicBoundary ( )

default constructor

constructor

Definition at line 33 of file PeriodicBoundary.cc.

References closestToLeftBoundary_, distanceLeft_, distanceRight_, and scaleFactor_.

Referenced by copy().

34  : BaseBoundary()
35 {
37  distanceLeft_ = std::numeric_limits<double>::quiet_NaN();
38  distanceRight_= std::numeric_limits<double>::quiet_NaN();
39  scaleFactor_= std::numeric_limits<double>::quiet_NaN();
40
41 #ifdef DEBUG_CONSTRUCTOR
42  std::cout<<"PeriodicBoundary::PeriodicBoundary() finished"<<std::endl;
43 #endif
44 }
bool closestToLeftBoundary_
true if closest wall is the left wall
Mdouble scaleFactor_
This is the normal to rescale the normal vector to a unit vectors.
Mdouble distanceRight_
position of right wall, s.t. normal*x=position_right
Mdouble distanceLeft_
position of left wall, s.t. normal*x=position_left
BaseBoundary()
default constructor.
Definition: BaseBoundary.cc:32
 PeriodicBoundary::~PeriodicBoundary ( )

destructor

destructor

Definition at line 49 of file PeriodicBoundary.cc.

50 {
51 #ifdef DEBUG_DESTRUCTOR
52  std::cout<<"PeriodicBoundary::~PeriodicBoundary() finished"<<std::endl;
53 #endif
54 }

## Member Function Documentation

 bool PeriodicBoundary::checkBoundaryAfterParticleMoved ( BaseParticle * p, ParticleHandler &pH UNUSED )

Checks if particle has crossed either boundary wall, and applies a shift if that is the case. NB: ALWAYS returns FALSE.

Checks whether given particle has crossed the closest wall, and if so, shifts its position so as to have it appear at the other wall

Parameters
 [in] p The particle to be checked and possibly shifted pH The ParticleHandler, which is unused in this implementation
Returns
ALWAYS returns FALSE for periodic boundaries. Only returns TRUE when particle gets actually deleted, e.g. in certain DeletionBoundary implementations.

Definition at line 358 of file PeriodicBoundary.cc.

References getDistance(), and shiftPosition().

359 {
360  if (getDistance(*p) < 0)
361  {
362  shiftPosition(p);
363  }
364  return false;
365 }
Mdouble getDistance(BaseParticle &p)
Returns the distance of the wall to the particle.
void shiftPosition(BaseParticle *p)
shifts the particle
 PeriodicBoundary * PeriodicBoundary::copy ( ) const
virtual

copy method

Copy method; creates a copy on the heap and returns its pointer.

Implements BaseBoundary.

Definition at line 59 of file PeriodicBoundary.cc.

References PeriodicBoundary().

60 {
61  return new PeriodicBoundary(*this);
62 }
PeriodicBoundary()
default constructor
 void PeriodicBoundary::createPeriodicParticles ( BaseParticle * p, ParticleHandler & pH )

Checks distance of particle to closest wall and creates periodic copy if necessary.

Checks the distance of given particle to the closest of both periodic walls, and creates a periodic copy of the particle if needed (i.e. if the particle is closer to the periodic wall than the radius of the largest particle in the system).

Parameters
 [in] p Particle to be checked and possibly periodically copied [in,out] pH System's ParticleHandler, (1) from which the interaction radius of its largest particle is retrieved to determine the maximum distance from the wall at which a particle should still have a periodic copy created, and (2) to which a possible periodic copy of the particle will be added

Definition at line 326 of file PeriodicBoundary.cc.

327 {
329  {
330  //Step 1: Copy the particle to new ghost particle.
331  BaseParticle* pGhost = p->copy();
332
333  //Step 2: Copy the interactions of the ghost particle.
335
336  //Step 3: Shift the ghost to the 'reflected' location.
337  shiftPosition(pGhost);
338
339  //Step 4: If Particle is double shifted, get correct original particle
340  BaseParticle* from = p;
341  while (from->getPeriodicFromParticle() != nullptr)
342  from = from->getPeriodicFromParticle();
343  pGhost->setPeriodicFromParticle(from);
344
346  }
347 }
BaseParticle * getLargestParticle() const
Gets a pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
Mdouble getDistance(BaseParticle &p)
Returns the distance of the wall to the particle.
void shiftPosition(BaseParticle *p)
shifts the particle
void setPeriodicFromParticle(BaseParticle *p)
Assigns the pointer to the 'original' particle this one's a periodic copy of.
BaseParticle * getPeriodicFromParticle() const
Returns the 'original' particle this one's a periodic copy of.
virtual void addObject(BaseParticle *P)
Adds a BaseParticle to the ParticleHandler.
void copyInteractionsForPeriodicParticles(const BaseInteractable &p)
Copies interactions to this BaseInteractable whenever a periodic copy made.
Returns the particle's interaction radius, which might be different from radius_ (e.g., when dealing with wet particles)
virtual BaseParticle * copy() const
Particle copy method. It calls to copy constructor of this Particle, useful for polymorfism.
 Mdouble PeriodicBoundary::getDistance ( BaseParticle & p )

Returns the distance of the wall to the particle.

Returns the distance to the closest wall of the boundary to the particle, , and sets closestToLeftBoundary_ = 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.

Parameters
 [in] p A reference to the particle which distance to the periodic boundary is calculated

Definition at line 134 of file PeriodicBoundary.cc.

References BaseInteractable::getPosition().

Referenced by checkBoundaryAfterParticleMoved(), and createPeriodicParticles().

135 {
136  return getDistance(p.getPosition());
137 }
Mdouble getDistance(BaseParticle &p)
Returns the distance of the wall to the particle.
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
 Mdouble PeriodicBoundary::getDistance ( const Vec3D & position )

Returns the distance of the wall to the position.

Returns the distance to the wall closest to the position, and sets closestToLeftBoundary_ = true if the left wall is the wall closest to the position.

Parameters
 [in] position A reference to the position which distance to the periodic boundary is to be calculated

Definition at line 145 of file PeriodicBoundary.cc.

References closestToLeftBoundary_, distanceLeft_, distanceRight_, Vec3D::dot(), and normal_.

146 {
147  Mdouble distance = Vec3D::dot(position, normal_);
148
149  if (distance - distanceLeft_ < distanceRight_ - distance)
150  {
151  closestToLeftBoundary_ = true;
152  return distance - distanceLeft_;
153  }
154  else
155  {
156  closestToLeftBoundary_ = false;
157  return distanceRight_ - distance;
158  }
159 }
bool closestToLeftBoundary_
true if closest wall is the left wall
double Mdouble
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:187
Mdouble distanceRight_
position of right wall, s.t. normal*x=position_right
Vec3D normal_
outward unit normal vector for right wall
Mdouble distanceLeft_
position of left wall, s.t. normal*x=position_left
 std::string PeriodicBoundary::getName ( ) const
virtual

Returns the name of the object.

Returns the name of the object class

Returns
the object's class' name, i.e. 'CubeInsertionBoundary'

Implements BaseObject.

Definition at line 302 of file PeriodicBoundary.cc.

303 {
304  return "PeriodicBoundary";
305 }
 bool PeriodicBoundary::isClosestToLeftBoundary ( ) const

Returns TRUE if last particle/position checked is closest to the 'left' wall, and FALSE if it is closest to the 'right' wall.

Definition at line 233 of file PeriodicBoundary.cc.

References closestToLeftBoundary_.

234 {
235  return closestToLeftBoundary_;
236 }
bool closestToLeftBoundary_
true if closest wall is the left wall
 void PeriodicBoundary::moveLeft ( Mdouble distanceLeft )

Sets the distance from the origin of the 'left' periodic wall.

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

Parameters
 [in] distanceLeft The distance (from the origin) to which the left boundary is moved

Definition at line 108 of file PeriodicBoundary.cc.

References distanceLeft_, distanceRight_, normal_, scaleFactor_, and shift_.

109 {
110  distanceLeft_ = distanceLeft * scaleFactor_;
112 }
Mdouble scaleFactor_
This is the normal to rescale the normal vector to a unit vectors.
Mdouble distanceRight_
position of right wall, s.t. normal*x=position_right
Vec3D normal_
outward unit normal vector for right wall
Mdouble distanceLeft_
position of left wall, s.t. normal*x=position_left
Vec3D shift_
shift from left to right boundary
 void PeriodicBoundary::moveRight ( Mdouble distanceRight )

Sets the distance from the origin of the 'right' periodic wall.

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

Parameters
 [in] distanceRight The distance (from the origin) to which the right boundary is moved

Definition at line 120 of file PeriodicBoundary.cc.

References distanceLeft_, distanceRight_, normal_, scaleFactor_, and shift_.

121 {
122  distanceRight_ = distanceRight * scaleFactor_;
124 }
Mdouble scaleFactor_
This is the normal to rescale the normal vector to a unit vectors.
Mdouble distanceRight_
position of right wall, s.t. normal*x=position_right
Vec3D normal_
outward unit normal vector for right wall
Mdouble distanceLeft_
position of left wall, s.t. normal*x=position_left
Vec3D shift_
shift from left to right boundary
 void PeriodicBoundary::oldRead ( std::istream & is )

deprecated version of CubeInsertionBoundary::read().

Deprecated version of read().

Deprecated:
Should be gone by Mercury 2.0. Instead, use CubeInsertionBoundary::read().

Definition at line 274 of file PeriodicBoundary.cc.

References distanceLeft_, distanceRight_, normal_, scaleFactor_, and shift_.

275 {
276  std::string dummy;
277  is >> dummy >> normal_
278  >> dummy >> scaleFactor_
279  >> dummy >> distanceLeft_
280  >> dummy >> distanceRight_
281  >> dummy >> shift_;
282 }
Mdouble scaleFactor_
This is the normal to rescale the normal vector to a unit vectors.
Mdouble distanceRight_
position of right wall, s.t. normal*x=position_right
Vec3D normal_
outward unit normal vector for right wall
Mdouble distanceLeft_
position of left wall, s.t. normal*x=position_left
Vec3D shift_
shift from left to right boundary
 void PeriodicBoundary::read ( std::istream & is )
virtual

reads boundary properties from istream

Reads the boundary properties from an istream

Parameters
 [in] is the istream

Implements BaseBoundary.

Definition at line 259 of file PeriodicBoundary.cc.

References distanceLeft_, distanceRight_, normal_, BaseBoundary::read(), scaleFactor_, and shift_.

260 {
262  std::string dummy;
263  is >> dummy >> normal_
264  >> dummy >> scaleFactor_
265  >> dummy >> distanceLeft_
266  >> dummy >> distanceRight_
267  >> dummy >> shift_;
268 }
Mdouble scaleFactor_
This is the normal to rescale the normal vector to a unit vectors.
Mdouble distanceRight_
position of right wall, s.t. normal*x=position_right
Vec3D normal_
outward unit normal vector for right wall
Mdouble distanceLeft_
position of left wall, s.t. normal*x=position_left
Vec3D shift_
shift from left to right boundary
Reads the object's id_ from given istream NB: purely virtual function.
Definition: BaseBoundary.cc:67
 void PeriodicBoundary::set ( Vec3D normal, Mdouble distanceLeft, Mdouble distanceRight )

Defines a periodic wall.

Defines the boundary, given a normal vector such that 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).

Parameters
 [in] normal The normal vector pointing from the left wall into the domain [in] distanceLeft The (signed) distance between the left wall and the origin [in] distanceRight The (signed) distance between the right wall and the origin

Definition at line 72 of file PeriodicBoundary.cc.

References distanceLeft_, distanceRight_, Vec3D::dot(), normal_, scaleFactor_, and shift_.

73 {
74  // factor is used to set normal to unit length
75  scaleFactor_ = 1. / std::sqrt(Vec3D::dot(normal, normal));
76  normal_ = normal * scaleFactor_;
77  distanceLeft_ = distanceLeft * scaleFactor_;
78  distanceRight_ = distanceRight * scaleFactor_;
80 }
Mdouble scaleFactor_
This is the normal to rescale the normal vector to a unit vectors.
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:187
Mdouble distanceRight_
position of right wall, s.t. normal*x=position_right
Vec3D normal_
outward unit normal vector for right wall
Mdouble distanceLeft_
position of left wall, s.t. normal*x=position_left
Vec3D shift_
shift from left to right boundary
 void PeriodicBoundary::set ( Vec3D normal, Mdouble distanceLeft, Mdouble distanceRight, Vec3D shiftDirection )

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

like PeriodicBoundary::set(normal, distanceLeft, distanceRight), but including the possibility of setting the shift direction vector.

Parameters
 [in] normal The normal vector pointing from the left wall into the domain [in] distanceLeft The (signed) distance between the left wall and the origin [in] distanceRight The (signed) distance between the right wall and the origin [in] shiftDirection The vector over which particles will be shifted when moving through the PeriodicBoundary

Definition at line 91 of file PeriodicBoundary.cc.

References distanceLeft_, distanceRight_, Vec3D::dot(), normal_, scaleFactor_, and shift_.

92 {
93  // factor is used to set normal to unit length
94  scaleFactor_ = 1. / std::sqrt(Vec3D::dot(normal, normal));
95  normal_ = normal * scaleFactor_;
96  distanceLeft_ = distanceLeft * scaleFactor_;
97  distanceRight_ = distanceRight * scaleFactor_;
98  // factor is used to set shift vector to correct length
99  scaleFactor_ = (distanceRight_ - distanceLeft_) * Vec3D::dot(shiftDirection, normal_);
100  shift_ = shiftDirection * scaleFactor_;
101 }
Mdouble scaleFactor_
This is the normal to rescale the normal vector to a unit vectors.
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:187
Mdouble distanceRight_
position of right wall, s.t. normal*x=position_right
Vec3D normal_
outward unit normal vector for right wall
Mdouble distanceLeft_
position of left wall, s.t. normal*x=position_left
Vec3D shift_
shift from left to right boundary
 void PeriodicBoundary::shiftPosition ( BaseParticle * p )

shifts the particle

Shifts the particle (using the closestToLeftBoundary_ value)

Parameters
 [in] p A pointer to the particle which will be shifted.
Todo:
Reconsider the way in which the shifting of particles is done. Now, the procedure is as follows: > PARTICLE's distance to either of the two walls is gotten by PeriodicBoundary::getDistance > Which of the two walls the particle is closest to, is saved in the BOUNDARY's boolean data member closestToLeftBoundary_ > PARTICLE's position is then shifted based on the BOUNDARY's closestToLeftBoundary_ data member and shift vector What might go wrong, is that it is allowed now to do a shift operation on the particle without being forced to first have the closestToLeftBoundary_ boolean set based on the same particle. Suggestion: get rid of the closestToLeftBoundary_ data member all together (it is a property of the particle after all, rather than one of the boundary), and implement the obtaining of which boundary to shift relatively to directly into the shift function.

Definition at line 178 of file PeriodicBoundary.cc.

References closestToLeftBoundary_, BaseInteractable::move(), and shift_.

Referenced by checkBoundaryAfterParticleMoved(), and createPeriodicParticles().

179 {
181  {
182  p->move(shift_);
183  closestToLeftBoundary_ = false;
184  }
185  else
186  {
187  p->move(-shift_);
188  closestToLeftBoundary_ = true;
189  }
190 }
bool closestToLeftBoundary_
true if closest wall is the left wall
Vec3D shift_
shift from left to right boundary
virtual void move(const Vec3D &move)
Moves this BaseInteractable by adding an amount to the position.
 void PeriodicBoundary::shiftPositions ( Vec3D & position1, Vec3D & position2 )

shifts two positions

Shifts two given positions by the shift_ vector.

Parameters
 [in] position1 The first position to be shifted [in] position2 The second position to be shifted
Todo:
(AT) see toDo of PeriodicBoundary::shiftPosition().

Definition at line 212 of file PeriodicBoundary.cc.

References closestToLeftBoundary_, and shift_.

213 {
215  {
216  position1 += shift_;
217  position2 += shift_;
218  closestToLeftBoundary_ = false;
219  }
220  else
221  {
222  position1 -= shift_;
223  position2 -= shift_;
224  closestToLeftBoundary_ = true;
225  }
226 }
bool closestToLeftBoundary_
true if closest wall is the left wall
Vec3D shift_
shift from left to right boundary
 void PeriodicBoundary::write ( std::ostream & os ) const
virtual

writes boundary properties to ostream

Writes boundary's properties to an ostream

Parameters
 [in] os the ostream

Implements BaseBoundary.

Definition at line 288 of file PeriodicBoundary.cc.

References distanceLeft_, distanceRight_, normal_, scaleFactor_, shift_, and BaseBoundary::write().

289  {
291  os << " normal " << normal_
292  << " scaleFactor " << scaleFactor_
293  << " distanceLeft " << distanceLeft_
294  << " distanceRight " << distanceRight_
295  << " shift " << shift_;
296 }
void write(std::ostream &os) const =0
Adds object's id_ to given ostream NB: purely virtual function.
Definition: BaseBoundary.cc:76
Mdouble scaleFactor_
This is the normal to rescale the normal vector to a unit vectors.
Mdouble distanceRight_
position of right wall, s.t. normal*x=position_right
Vec3D normal_
outward unit normal vector for right wall
Mdouble distanceLeft_
position of left wall, s.t. normal*x=position_left
Vec3D shift_
shift from left to right boundary

## Member Data Documentation

 bool PeriodicBoundary::closestToLeftBoundary_
private

true if closest wall is the left wall

Definition at line 156 of file PeriodicBoundary.h.

Referenced by getDistance(), isClosestToLeftBoundary(), PeriodicBoundary(), shiftPosition(), and shiftPositions().

 Mdouble PeriodicBoundary::distanceLeft_
private

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

Definition at line 164 of file PeriodicBoundary.h.

Referenced by getDistance(), moveLeft(), moveRight(), oldRead(), PeriodicBoundary(), read(), set(), and write().

 Mdouble PeriodicBoundary::distanceRight_
private

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

Definition at line 168 of file PeriodicBoundary.h.

Referenced by getDistance(), moveLeft(), moveRight(), oldRead(), PeriodicBoundary(), read(), set(), and write().

 Vec3D PeriodicBoundary::normal_
private

outward unit normal vector for right wall

Definition at line 160 of file PeriodicBoundary.h.

Referenced by getDistance(), moveLeft(), moveRight(), oldRead(), read(), set(), and write().

 Mdouble PeriodicBoundary::scaleFactor_
private

This is the normal to rescale the normal vector to a unit vectors.

Definition at line 172 of file PeriodicBoundary.h.

Referenced by moveLeft(), moveRight(), oldRead(), PeriodicBoundary(), read(), set(), and write().

 Vec3D PeriodicBoundary::shift_
private

shift from left to right boundary

Definition at line 176 of file PeriodicBoundary.h.

Referenced by moveLeft(), moveRight(), oldRead(), read(), set(), shiftPosition(), shiftPositions(), and write().

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