MercuryDPM  0.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CircularPeriodicBoundary 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 <CircularPeriodicBoundary.h>

+ Inheritance diagram for CircularPeriodicBoundary:

Public Member Functions

 CircularPeriodicBoundary ()
 
 CircularPeriodicBoundary (double innerRadius)
 
CircularPeriodicBoundarycopy () const
 BaseBoundary copy method. More...
 
void rotateParticle (BaseParticle *P, double angle)
 
int createPeriodicParticles (BaseParticle *P, ParticleHandler &pH)
 
bool checkBoundaryAfterParticleMoved (BaseParticle *P, ParticleHandler &pH)
 
void read (std::istream &is)
 reads wall More...
 
void print (std::ostream &os) const
 outputs wall More...
 
- 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

double innerRadius
 

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 32 of file CircularPeriodicBoundary.h.

Constructor & Destructor Documentation

CircularPeriodicBoundary::CircularPeriodicBoundary ( )
inline

Definition at line 35 of file CircularPeriodicBoundary.h.

References innerRadius.

Referenced by copy().

35  : BaseBoundary()
36  {
37  innerRadius=1.0;
38  #ifdef CONSTUCTOR_OUTPUT
39  std::cerr << "CircularPeriodicBoundary() finished" << std::endl;
40  #endif
41  }
CircularPeriodicBoundary::CircularPeriodicBoundary ( double  innerRadius)
inline

Definition at line 43 of file CircularPeriodicBoundary.h.

References innerRadius.

43  : BaseBoundary()
44  {
46  #ifdef CONSTUCTOR_OUTPUT
47  std::cerr << "CircularPeriodicBoundary(double innerRadius) finished" << std::endl;
48  #endif
49  }

Member Function Documentation

bool CircularPeriodicBoundary::checkBoundaryAfterParticleMoved ( BaseParticle P,
ParticleHandler pH 
)
inline
Todo:
{TW: Dinant, please confirm that i and oldI should be integer}

Definition at line 122 of file CircularPeriodicBoundary.h.

References ParticleHandler::addObject(), BaseParticle::copy(), BaseParticle::get_Displacement(), BaseParticle::get_Index(), BaseParticle::get_Position(), innerRadius, constants::pi, R, BaseHandler< T >::removeObject(), rotateParticle(), BaseParticle::set_Displacement(), Vec3D::X, and Vec3D::Y.

123  {
124  double R=sqrt(pow(P->get_Position().X,2)+pow(P->get_Position().Y,2));
125  double alpha=atan2(P->get_Position().Y,P->get_Position().X);
126  int i=log(R/innerRadius)/log(2.0)+1;
127  double pieSize=2.0/pow(2.0,i)*constants::pi;
128 
129  double oldR=sqrt(pow(P->get_Position().X-P->get_Displacement().X,2)+pow(P->get_Position().Y-P->get_Displacement().Y,2));
131  int oldI=log(oldR/innerRadius)/log(2.0)+1.0;
132 
133  if(i>0&&i>oldI) //Particle moves outward so it may have to be deleted
134  {
135  //std::cout<<"Particle="<<P->get_Index()<<" moving outward with alpha="<<alpha<<" and pieSize="<<pieSize<<" ";
136  if(alpha<0||alpha>pieSize)
137  {
138  if(alpha>2.0*pieSize)
139  {
140  //std::cout<<"and it is rotated into the pie"<<std::endl;
141  rotateParticle(P,-pieSize);
142  }
143  else
144  {
145  //Delete particle
146  //std::cout<<"and it should be deleted"<<std::endl;
147  pH.removeObject(P->get_Index());
148  return true;
149  }
150  }
151  //else
152  //std::cout<<"and nothing happens"<<std::endl;
153  }
154  else if (i>=0&&i<oldI) //Particle moves inward so it has to be coppied
155  {
156  //std::cout<<"Particle="<<P->get_Index()<<" moving inward and is thus coppied with alpha="<<alpha<<" and pieSize="<<pieSize<<std::endl;
157  //std::cout<<"i="<<i<<" oldI="<<oldI<<" R="<<R<<" oldR="<<oldR<<std::endl;
158  //std::cout<<"Position="<<P->get_Position()<<" Displacement="<<P->get_Displacement()<<std::endl;
159  BaseParticle* F0=P->copy();
160  F0->set_Displacement(Vec3D(0.0,0.0,0.0));
161  if(alpha<0)
162  {
163  rotateParticle(P,pieSize);
164  rotateParticle(F0,0.5*pieSize);
165  }
166  else if(alpha<0.5*pieSize)
167  {
168  rotateParticle(F0,0.5*pieSize);
169  }
170  else if(alpha<pieSize)
171  {
172  rotateParticle(F0,-0.5*pieSize);
173  }
174  else
175  {
176  rotateParticle(P,-pieSize);
177  rotateParticle(F0,-0.5*pieSize);
178  }
179  pH.addObject(F0);
180  }
181  else if(i>0&&alpha<0)
182  {
183  //std::cout<<"Particle="<<P->get_Index()<<" i="<<i<<" R="<<R<<" alpha="<<alpha<<" positive rotated pieSize="<<pieSize<<std::endl;
184  rotateParticle(P,pieSize);
185  }
186  else if(i>0&&alpha>pieSize)
187  {
188  //std::cout<<"Particle="<<P->get_Index()<<" i="<<i<<" R="<<R<<" alpha="<<alpha<<" negative rotated pieSize="<<pieSize<<std::endl;
189  rotateParticle(P,-pieSize);
190  }
191  return false;
192  }
Mdouble X
Definition: Vector.h:44
int get_Index() const
void rotateParticle(BaseParticle *P, double angle)
const Mdouble pi
Definition: ExtendedMath.h:54
virtual void addObject(BaseParticle *P)
Adds a BaseParticle to the ParticleHandler.
const Vec3D & get_Displacement() const
const Vec3D & get_Position() const
Mdouble Y
Definition: Vector.h:44
void set_Displacement(const Vec3D &_new)
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:40
virtual void removeObject(unsigned const int id)
Removes a Object from the BaseHandler.
Definition: BaseHandler.h:122
virtual BaseParticle * copy() const
Particle copy method. It calls to copy contrustor of this Particle, usefull for polymorfism.
CircularPeriodicBoundary* CircularPeriodicBoundary::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 51 of file CircularPeriodicBoundary.h.

References CircularPeriodicBoundary().

52  {
53  #ifdef CONSTUCTOR_OUTPUT
54  std::cerr << "virtual CircularPeriodicBoundary* copy() const finished" << std::endl;
55  #endif
56  return new CircularPeriodicBoundary(*this);
57  }
int CircularPeriodicBoundary::createPeriodicParticles ( BaseParticle P,
ParticleHandler pH 
)
inline

Definition at line 73 of file CircularPeriodicBoundary.h.

References ParticleHandler::addObject(), BaseParticle::copy(), BaseParticle::get_InteractionRadius(), BaseParticle::get_PeriodicFromParticle(), BaseParticle::get_Position(), ParticleHandler::getLargestParticle(), innerRadius, constants::pi, R, rotateParticle(), BaseParticle::set_periodicFromParticle(), Vec3D::X, and Vec3D::Y.

74  {
75  double R=sqrt(pow(P->get_Position().X,2)+pow(P->get_Position().Y,2));
76  double alpha=atan2(P->get_Position().Y,P->get_Position().X);
77  int i=log(R/innerRadius)/log(2.0)+1;
78  double pieSize=2.0/pow(2.0,i)*constants::pi;
79  int C=0;
80  //std::cout<<"R="<<R<<" alpha="<<alpha<<" i="<<i<<" pieSize="<<pieSize<<std::endl;
81 
82  //Check if the particle is close to it's inner Radius or is is close to zero alpha (small y)
84  {
85  //std::cout<<"Going to shift because "<<R-P->get_Radius()<<"<"<<pow(2,i-1)*innerRadius<<" or "<<P->get_Position().Y<<"<"<<P->get_Radius()<<std::endl;
86  //std::cout<<*P<<" has been shifted"<<std::endl;
87 
88  BaseParticle* F0=P->copy();
89  rotateParticle(F0,pieSize);
90 
91  //If Particle is Mdouble shifted, get correct original particle
92  BaseParticle* From=P;
93  while(From->get_PeriodicFromParticle()!=NULL)
94  From=From->get_PeriodicFromParticle();
95  F0->set_periodicFromParticle(From);
96 
97  //std::cout<<*F0<<" is the result"<<std::endl;
98  pH.addObject(F0);
99  C++;
100  }
101  //Check here only for i>0 becuase for i=1 they both give the same particle
102  if(i>1&&R*R*(1-pow(cos(alpha-pieSize),2))<P->get_InteractionRadius()+pH.getLargestParticle()->get_InteractionRadius())
103  {
104  //std::cout<<*P<<" has been shifted back"<<std::endl;
105 
106  BaseParticle* F0=P->copy();
107  rotateParticle(F0,-pieSize);
108 
109  //If Particle is Mdouble shifted, get correct original particle
110  BaseParticle* From=P;
111  while(From->get_PeriodicFromParticle()!=NULL)
112  From=From->get_PeriodicFromParticle();
113  F0->set_periodicFromParticle(From);
114 
115  //std::cout<<*F0<<" is the result"<<std::endl;
116  pH.addObject(F0);
117  C++;
118  }
119  return C;
120  }
BaseParticle * getLargestParticle() const
Gets a pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
Mdouble X
Definition: Vector.h:44
Mdouble get_InteractionRadius() const
BaseParticle * get_PeriodicFromParticle() const
void set_periodicFromParticle(BaseParticle *_new)
void rotateParticle(BaseParticle *P, double angle)
const Mdouble pi
Definition: ExtendedMath.h:54
virtual void addObject(BaseParticle *P)
Adds a BaseParticle to the ParticleHandler.
const Vec3D & get_Position() const
Mdouble Y
Definition: Vector.h:44
virtual BaseParticle * copy() const
Particle copy method. It calls to copy contrustor of this Particle, usefull for polymorfism.
void CircularPeriodicBoundary::print ( std::ostream &  os) const
inline

outputs wall

Definition at line 201 of file CircularPeriodicBoundary.h.

References innerRadius.

201  {
202  os << "CircularPeriodicBoundary innerRadius "<<innerRadius;
203  }
void CircularPeriodicBoundary::read ( std::istream &  is)
inline

reads wall

Definition at line 195 of file CircularPeriodicBoundary.h.

References innerRadius.

195  {
196  std::string dummy;
197  is >> dummy >> innerRadius;
198  }
void CircularPeriodicBoundary::rotateParticle ( BaseParticle P,
double  angle 
)
inline

todo{Do we need to update rotations and rotational velocitys?}

Definition at line 59 of file CircularPeriodicBoundary.h.

References BaseParticle::get_Position(), BaseParticle::get_Velocity(), R, BaseParticle::set_Position(), BaseParticle::set_Velocity(), Vec3D::X, Vec3D::Y, and Vec3D::Z.

Referenced by checkBoundaryAfterParticleMoved(), and createPeriodicParticles().

60  {
61  double R=sqrt(pow(P->get_Position().X,2)+pow(P->get_Position().Y,2));
62  double alphaPos=atan2(P->get_Position().Y,P->get_Position().X);
63  double V=sqrt(pow(P->get_Velocity().X,2)+pow(P->get_Velocity().Y,2));
64  double alphaVel=atan2(P->get_Velocity().Y,P->get_Velocity().X);
65  alphaPos+=angle;
66  alphaVel+=angle;
67 
68  P->set_Position(Vec3D(cos(alphaPos)*R,sin(alphaPos*R),P->get_Position().Z));
69  P->set_Velocity(Vec3D(cos(alphaVel)*V,sin(alphaVel*V),P->get_Velocity().Z));
71  }
Mdouble X
Definition: Vector.h:44
const Vec3D & get_Velocity() const
const Vec3D & get_Position() const
Mdouble Y
Definition: Vector.h:44
void set_Velocity(const Vec3D &_new)
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:40
void set_Position(const Vec3D &_new)
Mdouble Z
Definition: Vector.h:44

Member Data Documentation

double CircularPeriodicBoundary::innerRadius
private

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