CircularPeriodicBoundary Class Reference

used to create a circular periodic boundary More...

#include <CircularPeriodicBoundary.h>

+ Inheritance diagram for CircularPeriodicBoundary:

Public Member Functions

 CircularPeriodicBoundary ()
 default constructor More...
 
 CircularPeriodicBoundary (double innerRadius)
 Constructor. More...
 
 ~CircularPeriodicBoundary () override
 destructor More...
 
CircularPeriodicBoundarycopy () const override
 Used to create a copy of the object NB: purely virtual function. More...
 
void rotateParticle (BaseParticle *P, double angle)
 
void createPeriodicParticle (BaseParticle *p, ParticleHandler &pH) override
 
void createPeriodicParticles (ParticleHandler &pH) override
 
bool checkBoundaryAfterParticleMoved (BaseParticle *P, ParticleHandler &pH)
 
void checkBoundaryAfterParticlesMove (ParticleHandler &pH) override
 
void read (std::istream &is) override
 reads the CircularPeriodicBoundary More...
 
void oldRead (std::istream &is)
 
void write (std::ostream &os) const override
 outputs the CircularPeriodicBoundary More...
 
std::string getName () const override
 Returns the name of the object. More...
 
- Public Member Functions inherited from BaseBoundary
 BaseBoundary ()
 default constructor. More...
 
 BaseBoundary (const BaseBoundary &b)
 copy constructor More...
 
 ~BaseBoundary () override
 destructor More...
 
virtual void createPeriodicParticle (BaseParticle *p UNUSED, ParticleHandler &pH UNUSED)
 Creates a periodic particle in case of periodic boundaries in serial build. More...
 
virtual void createPeriodicParticles (ParticleHandler &pH UNUSED)
 Creates periodic copies of given particle in case of periodic boundaries. More...
 
virtual void checkBoundaryBeforeTimeStep (DPMBase *md)
 Virtual function that does things before each time step. More...
 
virtual void actionsBeforeTimeLoop ()
 Virtual function that does something after DPMBase::setupInitialConditions but before the first time step. More...
 
virtual void modifyGhostAfterCreation (BaseParticle *particle, int i)
 
virtual void writeVTK (std::fstream &file)
 
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
 Default constructor. More...
 
 BaseObject (const BaseObject &p)=default
 Copy constructor, copies all the objects BaseObject contains. More...
 
virtual ~BaseObject ()=default
 virtual destructor More...
 
virtual void moveInHandler (unsigned int index)
 Except that it is virtual, it does the same thing as setIndex() does. More...
 
void setIndex (unsigned int index)
 Allows one to assign an index to an object in the handler/container. More...
 
void setId (unsigned long 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...
 
void setGroupId (unsigned groupId)
 
unsigned getGroupId () const
 

Private Attributes

double innerRadius_
 

Detailed Description

used to create a circular periodic boundary

Constructor & Destructor Documentation

◆ CircularPeriodicBoundary() [1/2]

CircularPeriodicBoundary::CircularPeriodicBoundary ( )

default constructor

31  : BaseBoundary()
32 {
33  innerRadius_ = 1.0;
34 #ifdef DEBUG_CONSTRUCTOR
35  std::cout << "CircularPeriodicBoundary::CircularPeriodicBoundary() finished" << std::endl;
36 #endif
37 #ifdef MERCURYDPM_USE_MPI
38  MPIContainer& communicator = MPIContainer::Instance();
39  if (communicator.getNumberOfProcessors() > 1)
40  {
41  logger(WARN,"CircularPeriodicBoundaries are currently not implemented in parallel MercuryDPM");
42  }
43 #endif
44 }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ WARN
BaseBoundary()
default constructor.
Definition: BaseBoundary.cc:32
double innerRadius_
Definition: CircularPeriodicBoundary.h:110
This class contains all information and functions required for communication between processors.
Definition: MpiContainer.h:130
std::size_t getNumberOfProcessors() const
Get the total number of processors participating in this simulation.
Definition: MpiContainer.cc:104
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134

References MPIContainer::getNumberOfProcessors(), innerRadius_, MPIContainer::Instance(), logger, and WARN.

Referenced by copy().

◆ CircularPeriodicBoundary() [2/2]

CircularPeriodicBoundary::CircularPeriodicBoundary ( double  innerRadius)
explicit

Constructor.

47  : BaseBoundary()
48 {
49  this->innerRadius_ = innerRadius;
50 #ifdef DEBUG_CONSTRUCTOR
51  std::cout << "CircularPeriodicBoundary::CircularPeriodicBoundary(double innerRadius) finished" << std::endl;
52 #endif
53 }

References innerRadius_.

◆ ~CircularPeriodicBoundary()

CircularPeriodicBoundary::~CircularPeriodicBoundary ( )
override

destructor

56 {
57 #ifdef DEBUG_DESTRUCTOR
58  std::cerr << "CircularPeriodicBoundary::~CircularPeriodicBoundary() finished" << std::endl;
59 #endif
60 }

Member Function Documentation

◆ checkBoundaryAfterParticleMoved()

bool CircularPeriodicBoundary::checkBoundaryAfterParticleMoved ( BaseParticle P,
ParticleHandler pH 
)
Todo:
TW: Dinant, please confirm that i and oldI should be integer
143 {
144  double R = sqrt(pow(P->getPosition().X, 2) + pow(P->getPosition().Y, 2));
145  double alpha = atan2(P->getPosition().Y, P->getPosition().X);
146  int i = static_cast<int>(std::floor(std::log(R / innerRadius_) / std::log(2.0))) + 1;
147  double pieSize = 2.0 / pow(2.0, i) * constants::pi;
148 
149  double oldR = sqrt(
150  pow(P->getPosition().X - P->getDisplacement().X, 2) + pow(P->getPosition().Y - P->getDisplacement().Y, 2));
152  int oldI = static_cast<int>(std::floor(std::log(oldR / innerRadius_) / std::log(2.0))) + 1;
153 
154  if (i > 0 && i > oldI) //Particle moves outward so it may have to be deleted
155  {
156  //std::cout<<"Particle="<<P->getIndex()<<" moving outward with alpha="<<alpha<<" and pieSize="<<pieSize<<" ";
157  if (alpha < 0 || alpha > pieSize)
158  {
159  if (alpha > 2.0 * pieSize)
160  {
161  //std::cout<<"and it is rotated into the pie"<<std::endl;
162  rotateParticle(P, -pieSize);
163  }
164  else
165  {
166  //Delete particle
167  //std::cout<<"and it should be deleted"<<std::endl;
168  pH.removeObject(P->getIndex());
169  return true;
170  }
171  }
172  //else
173  //std::cout<<"and nothing happens"<<std::endl;
174  }
175  else if (i >= 0 && i < oldI) //Particle moves inward so it has to be coppied
176  {
177  //std::cout<<"Particle="<<P->getIndex()<<" moving inward and is thus coppied with alpha="<<alpha<<" and pieSize="<<pieSize<<std::endl;
178  //std::cout<<"i="<<i<<" oldI="<<oldI<<" R="<<R<<" oldR="<<oldR<<std::endl;
179  //std::cout<<"Position="<<P->getPosition()<<" Displacement="<<P->get_Displacement()<<std::endl;
180  BaseParticle* F0 = P->copy();
181  F0->setDisplacement(Vec3D(0.0, 0.0, 0.0));
182  if (alpha < 0)
183  {
184  rotateParticle(P, pieSize);
185  rotateParticle(F0, 0.5 * pieSize);
186  }
187  else if (alpha < 0.5 * pieSize)
188  {
189  rotateParticle(F0, 0.5 * pieSize);
190  }
191  else if (alpha < pieSize)
192  {
193  rotateParticle(F0, -0.5 * pieSize);
194  }
195  else
196  {
197  rotateParticle(P, -pieSize);
198  rotateParticle(F0, -0.5 * pieSize);
199  }
200  pH.addObject(F0);
201  }
202  else if (i > 0 && alpha < 0)
203  {
204  //std::cout<<"Particle="<<P->getIndex()<<" i="<<i<<" R="<<R<<" alpha="<<alpha<<" positive rotated pieSize="<<pieSize<<std::endl;
205  rotateParticle(P, pieSize);
206  }
207  else if (i > 0 && alpha > pieSize)
208  {
209  //std::cout<<"Particle="<<P->getIndex()<<" i="<<i<<" R="<<R<<" alpha="<<alpha<<" negative rotated pieSize="<<pieSize<<std::endl;
210  rotateParticle(P, -pieSize);
211  }
212  return false;
213 }
@ R
Definition: StatisticsVector.h:42
Definition: BaseParticle.h:54
void setDisplacement(const Vec3D &disp)
Sets the particle's displacement (= difference between current position and that of the previous time...
Definition: BaseParticle.cc:605
void rotateParticle(BaseParticle *P, double angle)
Definition: CircularPeriodicBoundary.cc:70
void addObject(BaseParticle *P) override
Adds a BaseParticle to the ParticleHandler.
Definition: ParticleHandler.cc:171
void removeObject(unsigned int index) override
Removes a BaseParticle from the ParticleHandler.
Definition: ParticleHandler.cc:394
Definition: Vector.h:51
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:73
const Mdouble pi
Definition: ExtendedMath.h:45
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
Mdouble log(Mdouble Power)
Definition: ExtendedMath.cc:104

References ParticleHandler::addObject(), constants::i, innerRadius_, mathsFunc::log(), Global_Physical_Variables::P, constants::pi, R, ParticleHandler::removeObject(), rotateParticle(), and BaseParticle::setDisplacement().

Referenced by checkBoundaryAfterParticlesMove().

◆ checkBoundaryAfterParticlesMove()

void CircularPeriodicBoundary::checkBoundaryAfterParticlesMove ( ParticleHandler pH)
overridevirtual
Todo:
MX: When implementing this function, I realised there might not be a unit test for this boundary

Reimplemented from BaseBoundary.

216 {
217  for (auto p = pH.begin(); p != pH.end(); ++p)
218  {
220  {
221  p--;
222  }
223  }
224 }
const std::vector< T * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
Definition: BaseHandler.h:690
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:704
bool checkBoundaryAfterParticleMoved(BaseParticle *P, ParticleHandler &pH)
Definition: CircularPeriodicBoundary.cc:142

References BaseHandler< T >::begin(), checkBoundaryAfterParticleMoved(), and BaseHandler< T >::end().

◆ copy()

CircularPeriodicBoundary * CircularPeriodicBoundary::copy ( ) const
overridevirtual

Used to create a copy of the object NB: purely virtual function.

Implements BaseBoundary.

63 {
64 #ifdef DEBUG_CONSTRUCTOR
65  std::cerr << "CircularPeriodicBoundary::copy() const finished" << std::endl;
66 #endif
67  return new CircularPeriodicBoundary(*this);
68 }
CircularPeriodicBoundary()
default constructor
Definition: CircularPeriodicBoundary.cc:30

References CircularPeriodicBoundary().

◆ createPeriodicParticle()

void CircularPeriodicBoundary::createPeriodicParticle ( BaseParticle p,
ParticleHandler pH 
)
override
Parameters
[in]
Todo:
TW getLargestParticle()->getInteractionRadius() should be getLargestInteractionRadius()
85 {
86  double R = sqrt(pow(p->getPosition().X, 2) + pow(p->getPosition().Y, 2));
87  double alpha = atan2(p->getPosition().Y, p->getPosition().X);
88  unsigned int i = static_cast<unsigned int>(std::floor(std::log(R / innerRadius_) / std::log(2.0))) + 1;
89  double pieSize = 2.0 / pow(2.0, i) * constants::pi;
90  //std::cout<<"R="<<R<<" alpha="<<alpha<<" i="<<i<<" pieSize="<<pieSize<<std::endl;
91 
92  //Check if the particle is close to it's inner Radius or is is close to zero alpha (small y)
95  if (i > 0 && (R - maxDistance <
96  pow(2.0, i - 1) * innerRadius_ ||
97  p->getPosition().Y < maxDistance))
98  {
99  //std::cout<<"Going to shift because "<<R-P->getRadius()<<"<"<<pow(2,i-1)*innerRadius<<" or "<<P->getPosition().Y<<"<"<<P->getRadius()<<std::endl;
100  //std::cout<<*P<<" has been shifted"<<std::endl;
101 
102  BaseParticle* F0 = p->copy();
103  rotateParticle(F0, pieSize);
104 
105  //If Particle is Mdouble shifted, get correct original particle
106  BaseParticle* From = p;
107  while (From->getPeriodicFromParticle() != nullptr)
108  From = From->getPeriodicFromParticle();
109  F0->setPeriodicFromParticle(From);
110 
111  //std::cout<<*F0<<" is the result"<<std::endl;
112  pH.addObject(F0);
113  }
114  //Check here only for i>0 becuase for i=1 they both give the same particle
115  if (i > 1 && R * R * (1 - pow(cos(alpha - pieSize), 2)) < maxDistance)
116  {
117  //std::cout<<*P<<" has been shifted back"<<std::endl;
118 
119  BaseParticle* F0 = p->copy();
120  rotateParticle(F0, -pieSize);
121 
122  //If Particle is Mdouble shifted, get correct original particle
123  BaseParticle* From = p;
124  while (From->getPeriodicFromParticle() != nullptr)
125  From = From->getPeriodicFromParticle();
126  F0->setPeriodicFromParticle(From);
127 
128  //std::cout<<*F0<<" is the result"<<std::endl;
129  pH.addObject(F0);
130  }
131 }
double Mdouble
Definition: GeneralDefine.h:34
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Definition: BaseInteractable.h:218
void setPeriodicFromParticle(BaseParticle *p)
Assigns the pointer to the 'original' particle this one's a periodic copy of (used in periodic bounda...
Definition: BaseParticle.h:441
Mdouble getMaxInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e....
Definition: BaseParticle.h:362
virtual BaseParticle * copy() const =0
Particle copy method. It calls to copy constructor of this Particle, useful for polymorphism.
BaseParticle * getPeriodicFromParticle() const
Returns the 'original' particle this one's a periodic copy of.
Definition: BaseParticle.h:341
BaseParticle * getLargestParticle() const
Returns the pointer of the largest particle in the particle handler. When mercury is running in paral...
Definition: ParticleHandler.cc:534
Mdouble Y
Definition: Vector.h:66
Mdouble X
the vector components
Definition: Vector.h:66
Mdouble cos(Mdouble x)
Definition: ExtendedMath.cc:64

References ParticleHandler::addObject(), BaseParticle::copy(), mathsFunc::cos(), ParticleHandler::getLargestParticle(), BaseParticle::getMaxInteractionRadius(), BaseParticle::getPeriodicFromParticle(), BaseInteractable::getPosition(), constants::i, innerRadius_, mathsFunc::log(), constants::pi, R, rotateParticle(), BaseParticle::setPeriodicFromParticle(), Vec3D::X, and Vec3D::Y.

Referenced by createPeriodicParticles().

◆ createPeriodicParticles()

void CircularPeriodicBoundary::createPeriodicParticles ( ParticleHandler pH)
override
134 {
135  unsigned numberOfParticles = pH.getSize();
136  for (unsigned i = 0; i < numberOfParticles; i++)
137  {
139  }
140 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:613
void createPeriodicParticle(BaseParticle *p, ParticleHandler &pH) override
Definition: CircularPeriodicBoundary.cc:84

References createPeriodicParticle(), BaseHandler< T >::getObject(), BaseHandler< T >::getSize(), and constants::i.

◆ getName()

std::string CircularPeriodicBoundary::getName ( ) const
overridevirtual

Returns the name of the object.

Returns
string type

Implements BaseObject.

246 {
247  return "CircularPeriodicBoundary";
248 }

◆ oldRead()

void CircularPeriodicBoundary::oldRead ( std::istream &  is)
234 {
235  std::string dummy;
236  is >> dummy >> innerRadius_;
237 }

References innerRadius_.

◆ read()

void CircularPeriodicBoundary::read ( std::istream &  is)
overridevirtual

reads the CircularPeriodicBoundary

Implements BaseBoundary.

227 {
228  BaseBoundary::read(is);
229  std::string dummy;
230  is >> dummy >> innerRadius_;
231 }
void read(std::istream &is) override=0
Reads the object's id_ from given istream NB: purely virtual function, overriding the version of Base...
Definition: BaseBoundary.cc:61

References innerRadius_, and BaseBoundary::read().

◆ rotateParticle()

void CircularPeriodicBoundary::rotateParticle ( BaseParticle P,
double  angle 
)
Parameters
[in]

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

71 {
72  double R = sqrt(pow(P->getPosition().X, 2) + pow(P->getPosition().Y, 2));
73  double alphaPos = atan2(P->getPosition().Y, P->getPosition().X);
74  double V = sqrt(pow(P->getVelocity().X, 2) + pow(P->getVelocity().Y, 2));
75  double alphaVel = atan2(P->getVelocity().Y, P->getVelocity().X);
76  alphaPos += angle;
77  alphaVel += angle;
78 
79  P->setPosition(Vec3D(cos(alphaPos) * R, sin(alphaPos * R), P->getPosition().Z));
80  P->setVelocity(Vec3D(cos(alphaVel) * V, sin(alphaVel * V), P->getVelocity().Z));
82 }
Mdouble sin(Mdouble x)
Definition: ExtendedMath.cc:44

References mathsFunc::cos(), Global_Physical_Variables::P, R, and mathsFunc::sin().

Referenced by checkBoundaryAfterParticleMoved(), and createPeriodicParticle().

◆ write()

void CircularPeriodicBoundary::write ( std::ostream &  os) const
overridevirtual

outputs the CircularPeriodicBoundary

Implements BaseBoundary.

240 {
242  os << " innerRadius " << innerRadius_;
243 }
void write(std::ostream &os) const override=0
Adds object's id_ to given ostream NB: purely virtual function, overriding the version of BaseObject.
Definition: BaseBoundary.cc:70

References innerRadius_, and BaseBoundary::write().

Member Data Documentation

◆ innerRadius_

double CircularPeriodicBoundary::innerRadius_
private

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