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

10  : BaseBoundary()
11 {
12  innerRadius_ = 1.0;
13 #ifdef DEBUG_CONSTRUCTOR
14  std::cout << "CircularPeriodicBoundary::CircularPeriodicBoundary() finished" << std::endl;
15 #endif
16 #ifdef MERCURYDPM_USE_MPI
17  MPIContainer& communicator = MPIContainer::Instance();
18  if (communicator.getNumberOfProcessors() > 1)
19  {
20  logger(WARN,"CircularPeriodicBoundaries are currently not implemented in parallel MercuryDPM");
21  }
22 #endif
23 }
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:11
double innerRadius_
Definition: CircularPeriodicBoundary.h:89
This class contains all information and functions required for communication between processors.
Definition: MpiContainer.h:109
std::size_t getNumberOfProcessors() const
Get the total number of processors participating in this simulation.
Definition: MpiContainer.cc:83
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:113

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

Referenced by copy().

◆ CircularPeriodicBoundary() [2/2]

CircularPeriodicBoundary::CircularPeriodicBoundary ( double  innerRadius)
explicit

Constructor.

26  : BaseBoundary()
27 {
28  this->innerRadius_ = innerRadius;
29 #ifdef DEBUG_CONSTRUCTOR
30  std::cout << "CircularPeriodicBoundary::CircularPeriodicBoundary(double innerRadius) finished" << std::endl;
31 #endif
32 }

References innerRadius_.

◆ ~CircularPeriodicBoundary()

CircularPeriodicBoundary::~CircularPeriodicBoundary ( )
override

destructor

35 {
36 #ifdef DEBUG_DESTRUCTOR
37  std::cerr << "CircularPeriodicBoundary::~CircularPeriodicBoundary() finished" << std::endl;
38 #endif
39 }

Member Function Documentation

◆ checkBoundaryAfterParticleMoved()

bool CircularPeriodicBoundary::checkBoundaryAfterParticleMoved ( BaseParticle P,
ParticleHandler pH 
)
Todo:
TW: Dinant, please confirm that i and oldI should be integer
122 {
123  double R = sqrt(pow(P->getPosition().X, 2) + pow(P->getPosition().Y, 2));
124  double alpha = atan2(P->getPosition().Y, P->getPosition().X);
125  int i = static_cast<int>(std::floor(std::log(R / innerRadius_) / std::log(2.0))) + 1;
126  double pieSize = 2.0 / pow(2.0, i) * constants::pi;
127 
128  double oldR = sqrt(
129  pow(P->getPreviousPosition().X, 2) + pow(P->getPreviousPosition().Y, 2));
131  int oldI = static_cast<int>(std::floor(std::log(oldR / innerRadius_) / std::log(2.0))) + 1;
132 
133  if (i > 0 && i > oldI) //Particle moves outward so it may have to be deleted
134  {
135  //std::cout<<"Particle="<<P->getIndex()<<" 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->getIndex());
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 copied
155  {
156  //std::cout<<"Particle="<<P->getIndex()<<" 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->getPosition()<<" Displacement="<<P->get_Displacement()<<std::endl;
159  BaseParticle* F0 = P->copy();
160  F0->setPreviousPosition(F0->getPosition());
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->getIndex()<<" 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->getIndex()<<" i="<<i<<" R="<<R<<" alpha="<<alpha<<" negative rotated pieSize="<<pieSize<<std::endl;
189  rotateParticle(P, -pieSize);
190  }
191  return false;
192 }
AnnoyingScalar atan2(const AnnoyingScalar &y, const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:139
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
int i
Definition: BiCGSTAB_step_by_step.cpp:9
@ R
Definition: StatisticsVector.h:21
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Definition: BaseInteractable.h:197
Definition: BaseParticle.h:33
void setPreviousPosition(const Vec3D &pos)
Sets the particle's position in the previous time step.
Definition: BaseParticle.cc:600
void rotateParticle(BaseParticle *P, double angle)
Definition: CircularPeriodicBoundary.cc:49
void addObject(BaseParticle *P) override
Adds a BaseParticle to the ParticleHandler.
Definition: ParticleHandler.cc:150
void removeObject(unsigned int index) override
Removes a BaseParticle from the ParticleHandler.
Definition: ParticleHandler.cc:388
RealScalar alpha
Definition: level1_cplx_impl.h:151
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 floor(const bfloat16 &a)
Definition: BFloat16.h:643
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 pow(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:625
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log(const bfloat16 &a)
Definition: BFloat16.h:618
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:77
const Mdouble pi
Definition: ExtendedMath.h:23

References ParticleHandler::addObject(), alpha, atan2(), Eigen::bfloat16_impl::floor(), BaseInteractable::getPosition(), i, innerRadius_, Eigen::bfloat16_impl::log(), Global_Physical_Variables::P, constants::pi, Eigen::bfloat16_impl::pow(), R, ParticleHandler::removeObject(), rotateParticle(), BaseParticle::setPreviousPosition(), and sqrt().

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.

195 {
196  for (auto p = pH.begin(); p != pH.end(); ++p)
197  {
199  {
200  p--;
201  }
202  }
203 }
float * p
Definition: Tutorial_Map_using.cpp:9
const std::vector< T * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
Definition: BaseHandler.h:698
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:712
bool checkBoundaryAfterParticleMoved(BaseParticle *P, ParticleHandler &pH)
Definition: CircularPeriodicBoundary.cc:121

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

◆ copy()

CircularPeriodicBoundary * CircularPeriodicBoundary::copy ( ) const
overridevirtual

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

Implements BaseBoundary.

42 {
43 #ifdef DEBUG_CONSTRUCTOR
44  std::cerr << "CircularPeriodicBoundary::copy() const finished" << std::endl;
45 #endif
46  return new CircularPeriodicBoundary(*this);
47 }
CircularPeriodicBoundary()
default constructor
Definition: CircularPeriodicBoundary.cc:9

References CircularPeriodicBoundary().

◆ createPeriodicParticle()

void CircularPeriodicBoundary::createPeriodicParticle ( BaseParticle p,
ParticleHandler pH 
)
override
Parameters
[in]
Todo:
TW getLargestParticle()->getInteractionRadius() should be getLargestInteractionRadius()
64 {
65  double R = sqrt(pow(p->getPosition().X, 2) + pow(p->getPosition().Y, 2));
66  double alpha = atan2(p->getPosition().Y, p->getPosition().X);
67  unsigned int i = static_cast<unsigned int>(std::floor(std::log(R / innerRadius_) / std::log(2.0))) + 1;
68  double pieSize = 2.0 / pow(2.0, i) * constants::pi;
69  //std::cout<<"R="<<R<<" alpha="<<alpha<<" i="<<i<<" pieSize="<<pieSize<<std::endl;
70 
71  //Check if the particle is close to it's inner Radius or is is close to zero alpha (small y)
73  const Mdouble maxDistance = p->getMaxInteractionRadius() + pH.getLargestParticle()->getMaxInteractionRadius();
74  if (i > 0 && (R - maxDistance <
75  pow(2.0, i - 1) * innerRadius_ ||
76  p->getPosition().Y < maxDistance))
77  {
78  //std::cout<<"Going to shift because "<<R-P->getRadius()<<"<"<<pow(2,i-1)*innerRadius<<" or "<<P->getPosition().Y<<"<"<<P->getRadius()<<std::endl;
79  //std::cout<<*P<<" has been shifted"<<std::endl;
80 
81  BaseParticle* F0 = p->copy();
82  rotateParticle(F0, pieSize);
83 
84  //If Particle is Mdouble shifted, get correct original particle
85  BaseParticle* From = p;
86  while (From->getPeriodicFromParticle() != nullptr)
87  From = From->getPeriodicFromParticle();
88  F0->setPeriodicFromParticle(From);
89 
90  //std::cout<<*F0<<" is the result"<<std::endl;
91  pH.addObject(F0);
92  }
93  //Check here only for i>0 becuase for i=1 they both give the same particle
94  if (i > 1 && R * R * (1 - pow(cos(alpha - pieSize), 2)) < maxDistance)
95  {
96  //std::cout<<*P<<" has been shifted back"<<std::endl;
97 
98  BaseParticle* F0 = p->copy();
99  rotateParticle(F0, -pieSize);
100 
101  //If Particle is Mdouble shifted, get correct original particle
102  BaseParticle* From = p;
103  while (From->getPeriodicFromParticle() != nullptr)
104  From = From->getPeriodicFromParticle();
105  F0->setPeriodicFromParticle(From);
106 
107  //std::cout<<*F0<<" is the result"<<std::endl;
108  pH.addObject(F0);
109  }
110 }
AnnoyingScalar cos(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:136
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:416
Mdouble getMaxInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e....
Definition: BaseParticle.h:345
BaseParticle * getPeriodicFromParticle() const
Returns the 'original' particle this one's a periodic copy of.
Definition: BaseParticle.h:324
BaseParticle * getLargestParticle() const
Returns the pointer of the largest particle in the particle handler. When mercury is running in paral...
Definition: ParticleHandler.cc:528

References ParticleHandler::addObject(), alpha, atan2(), cos(), Eigen::bfloat16_impl::floor(), ParticleHandler::getLargestParticle(), BaseParticle::getMaxInteractionRadius(), BaseParticle::getPeriodicFromParticle(), i, innerRadius_, Eigen::bfloat16_impl::log(), p, constants::pi, Eigen::bfloat16_impl::pow(), R, rotateParticle(), BaseParticle::setPeriodicFromParticle(), and sqrt().

Referenced by createPeriodicParticles().

◆ createPeriodicParticles()

void CircularPeriodicBoundary::createPeriodicParticles ( ParticleHandler pH)
override
113 {
114  unsigned numberOfParticles = pH.getSize();
115  for (unsigned i = 0; i < numberOfParticles; i++)
116  {
118  }
119 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:663
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:621
void createPeriodicParticle(BaseParticle *p, ParticleHandler &pH) override
Definition: CircularPeriodicBoundary.cc:63

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

◆ getName()

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

Returns the name of the object.

Returns
string type

Implements BaseObject.

225 {
226  return "CircularPeriodicBoundary";
227 }

◆ oldRead()

void CircularPeriodicBoundary::oldRead ( std::istream &  is)
213 {
214  std::string dummy;
215  is >> dummy >> innerRadius_;
216 }
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286

References innerRadius_, and oomph::Global_string_for_annotation::string().

◆ read()

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

reads the CircularPeriodicBoundary

Implements BaseBoundary.

206 {
207  BaseBoundary::read(is);
208  std::string dummy;
209  is >> dummy >> innerRadius_;
210 }
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:40

References innerRadius_, BaseBoundary::read(), and oomph::Global_string_for_annotation::string().

◆ rotateParticle()

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

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

50 {
51  double R = sqrt(pow(P->getPosition().X, 2) + pow(P->getPosition().Y, 2));
52  double alphaPos = atan2(P->getPosition().Y, P->getPosition().X);
53  double V = sqrt(pow(P->getVelocity().X, 2) + pow(P->getVelocity().Y, 2));
54  double alphaVel = atan2(P->getVelocity().Y, P->getVelocity().X);
55  alphaPos += angle;
56  alphaVel += angle;
57 
58  P->setPosition(Vec3D(cos(alphaPos) * R, sin(alphaPos * R), P->getPosition().Z));
59  P->setVelocity(Vec3D(cos(alphaVel) * V, sin(alphaVel * V), P->getVelocity().Z));
61 }
AnnoyingScalar sin(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:137
MatrixXcd V
Definition: EigenSolver_EigenSolver_MatrixType.cpp:15
Definition: Kernel/Math/Vector.h:30
double angle(const double &t)
Angular position as a function of time t.
Definition: jeffery_orbit.cc:98

References Jeffery_Solution::angle(), atan2(), cos(), Global_Physical_Variables::P, Eigen::bfloat16_impl::pow(), R, sin(), sqrt(), and V.

Referenced by checkBoundaryAfterParticleMoved(), and createPeriodicParticle().

◆ write()

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

outputs the CircularPeriodicBoundary

Implements BaseBoundary.

219 {
221  os << " innerRadius " << innerRadius_;
222 }
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:49

References innerRadius_, and BaseBoundary::write().

Member Data Documentation

◆ innerRadius_

double CircularPeriodicBoundary::innerRadius_
private

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