SubcriticalMaserBoundaryTEST Class Reference

#include <SubcriticalMaserBoundaryTEST.h>

+ Inheritance diagram for SubcriticalMaserBoundaryTEST:

Public Member Functions

 SubcriticalMaserBoundaryTEST ()
 MaserBoundary constructor. More...
 
 ~SubcriticalMaserBoundaryTEST () override
 destructor More...
 
SubcriticalMaserBoundaryTESTcopy () const override
 Creates a copy of this maser on the heap. More...
 
void read (std::istream &is) override
 reads boundary properties from istream More...
 
void write (std::ostream &os) const override
 writes boundary properties to ostream More...
 
std::string getName () const override
 Returns the name of the object. More...
 
void actionsBeforeTimeLoop () override
 
void createPeriodicParticle (BaseParticle *p, ParticleHandler &pH) override
 Creates periodic particles when the particle is a maser particle and is sufficiently close to one of the boundary walls. More...
 
bool checkBoundaryAfterParticleMoved (BaseParticle *p, ParticleHandler &pH) const
 Shifts the particle to its 'periodic' position if it is a maser particle and has crossed either of the walls. Creates a 'normal' particle at its current position if it is a maser particle which crossed the RIGHT boundary wall. More...
 
void checkBoundaryAfterParticlesMove (ParticleHandler &pH) override
 Evaluates what the particles have to do after they have changed position. More...
 
void activateMaser ()
 Activates the maser functionaly of this periodic boundary. More...
 
void deactivateMaser ()
 Stops copying particles, and act merely as a periodic domain. More...
 
bool isActivated () const
 Returns whether the maser is activated or not. More...
 
void setActivationTime (Mdouble time)
 sets the activate time of the maser More...
 
Mdouble getDistance (const Vec3D &position) const override
 gets the distance to the closest wall if maser is inactive, otherwise distance to right wall More...
 
Mdouble getDistanceFromRight (const Vec3D &position) const
 returns the distance to the right wall More...
 
void modifyPeriodicComplexity (std::vector< int > &complexity, int &totalPeriodicComplexity, BaseParticle *particle, int i) const override
 modifies the periodic complexity to support a maser boundary More...
 
void modifyGhostAfterCreation (BaseParticle *particle, int i) override
 
void performActionsBeforeAddingParticles () override
 Checks before adding particles if the maser needs to be activated. More...
 
void extendBottom () const
 
void copyExtraParticles () const
 
void setCopyFlowParticles (bool copyFlowParticles)
 
- Public Member Functions inherited from PeriodicBoundary
 PeriodicBoundary ()
 default constructor More...
 
 ~PeriodicBoundary () override
 destructor More...
 
 PeriodicBoundary (const PeriodicBoundary &other)
 copy constructor More...
 
void set (Vec3D normal, Mdouble distanceLeft, Mdouble distanceRight)
 Defines a PeriodicBoundary by its normal and positions. More...
 
void set (Vec3D normal, Vec3D positionLeft, Vec3D positionRight)
 As above, but by specifying two positions that the boundaries go through instead of distanceLeft and distanceRight. 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 setPlanewiseShift (Vec3D planewiseShift)
 Set the planewise shift (projected onto the planewise direction, and zero by default). More...
 
Vec3D getNormal () const
 returns the vector normal to the periodic boundary More...
 
Mdouble getDistanceLeft () const
 Returns the distance of the left wall to the origin, in normal direction. More...
 
Mdouble getDistanceRight () const
 Returns the distance of the right wall to the origin, in normal direction. More...
 
Vec3D getShift () const
 Returns the vector going from the left to the right side of the periodic boundary. 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 (const BaseParticle &p) const override
 Returns the distance of the edge to the particle. More...
 
virtual void shiftPosition (BaseParticle *p) const override
 shifts the particle More...
 
void shiftPosition (Vec3D &p) const
 
virtual void shiftPositions (Vec3D &postition1, Vec3D &postion2) const
 shifts two positions More...
 
virtual bool isClosestToLeftBoundary (const BaseParticle &p) const
 Returns TRUE if particle checked is closest to the 'left' edge, and FALSE if it is closest to the 'right' edge. More...
 
bool isClosestToLeftBoundary (const Vec3D &p) const override
 
virtual void createPeriodicParticles (ParticleHandler &pH) override
 Checks distance of particle to closer edge and creates a periodic copy if necessary. More...
 
void createGhostParticle (BaseParticle *pReal)
 Creates and adds a ghost particle from a given real particle. More...
 
void createPeriodicParticle (BaseParticle *p, ParticleHandler &pH) override
 Creates a single periodic particle if required from a given particle. More...
 
MERCURYDPM_DEPRECATED void oldRead (std::istream &is)
 deprecated version of CubeInsertionBoundary::read(). More...
 
- Public Member Functions inherited from BasePeriodicBoundary
 BasePeriodicBoundary ()
 default constructor. More...
 
 BasePeriodicBoundary (const BasePeriodicBoundary &b)
 copy constructor More...
 
 ~BasePeriodicBoundary () override
 destructor More...
 
void setPeriodicHandler (PeriodicBoundaryHandler *periodicHandler)
 Sets the periodicBoundaryHandler, required for parallel periodic boundaries. More...
 
PeriodicBoundaryHandlergetPeriodicHandler () const
 Returns the periodic boundary handler. More...
 
void createPeriodicParticles (ParticleHandler &pH) override
 Creates periodic ocpies of given particle in case of periodic boundaries in serial build. 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 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

bool maserIsActivated_
 Flag whether or not the gap is created and particles transformed already. More...
 
Mdouble activationTime_
 Time at which the maser opens. More...
 
bool copyFlowParticles_
 Flag for whether or not we copy a few blocks of flow particles in the front when activating the maser. More...
 

Additional Inherited Members

- Protected Attributes inherited from PeriodicBoundary
Vec3D normal_
 outward unit normal vector for right edge More...
 
Mdouble distanceLeft_
 position of left edge, s.t. normal*x = distanceLeft_ More...
 
Mdouble distanceRight_
 position of right edge, s.t. normal*x = distanceRight_ 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...
 

Constructor & Destructor Documentation

◆ SubcriticalMaserBoundaryTEST()

SubcriticalMaserBoundaryTEST::SubcriticalMaserBoundaryTEST ( )

MaserBoundary constructor.

MaserBoundary constructor, sets all scalars to non-sensible values.

12 {
13  distanceLeft_ = std::numeric_limits<Mdouble>::quiet_NaN();
14  distanceRight_ = std::numeric_limits<Mdouble>::quiet_NaN();
15  maserIsActivated_ = false;
16  activationTime_ = std::numeric_limits<Mdouble>::quiet_NaN();
17  copyFlowParticles_ = false;
18 }
Mdouble distanceLeft_
position of left edge, s.t. normal*x = distanceLeft_
Definition: PeriodicBoundary.h:180
Mdouble distanceRight_
position of right edge, s.t. normal*x = distanceRight_
Definition: PeriodicBoundary.h:185
Mdouble activationTime_
Time at which the maser opens.
Definition: SubcriticalMaserBoundaryTEST.h:125
bool maserIsActivated_
Flag whether or not the gap is created and particles transformed already.
Definition: SubcriticalMaserBoundaryTEST.h:120
bool copyFlowParticles_
Flag for whether or not we copy a few blocks of flow particles in the front when activating the maser...
Definition: SubcriticalMaserBoundaryTEST.h:130

References activationTime_, copyFlowParticles_, PeriodicBoundary::distanceLeft_, PeriodicBoundary::distanceRight_, and maserIsActivated_.

Referenced by copy().

◆ ~SubcriticalMaserBoundaryTEST()

SubcriticalMaserBoundaryTEST::~SubcriticalMaserBoundaryTEST ( )
override

destructor

destructor

24 {
25  logger(DEBUG, "SubcriticalMaserBoundaryTEST::~SubcriticalBoundary() finished");
26 }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ DEBUG

References DEBUG, and logger.

Member Function Documentation

◆ actionsBeforeTimeLoop()

void SubcriticalMaserBoundaryTEST::actionsBeforeTimeLoop ( )
overridevirtual

Helper function to make sure that the particles are maser particles after restarting.

Reimplemented from BaseBoundary.

80 {
82  {
83  for (BaseParticle* p : getHandler()->getDPMBase()->particleHandler)
84  {
85  if (getDistance(p->getPosition()) > 0)
86  {
87  p->setMaserParticle(true);
88  }
89  }
90  }
91 }
float * p
Definition: Tutorial_Map_using.cpp:9
BoundaryHandler * getHandler() const
Returns the boundary's BoundaryHandler.
Definition: BaseBoundary.cc:122
Definition: BaseParticle.h:33
Mdouble getDistance(const Vec3D &position) const override
gets the distance to the closest wall if maser is inactive, otherwise distance to right wall
Definition: SubcriticalMaserBoundaryTEST.cc:284

References getDistance(), BaseBoundary::getHandler(), maserIsActivated_, and p.

◆ activateMaser()

void SubcriticalMaserBoundaryTEST::activateMaser ( )

Activates the maser functionaly of this periodic boundary.

Activates the maser boundary by flagging all particles within as isMaserParticles. These maser particle will generate real particles at the right side of the maser.

210 {
211  logger(INFO, "SubcriticalMaserBoundaryTEST::activateMaser ");
212 #ifdef MERCURYDPM_USE_MPI
213  //Clear the periodic boundaryHandler, only want real particles
215 #endif
216  //Flag that the maser is active!
217  maserIsActivated_ = true;
218 
219  extendBottom();
220  if (copyFlowParticles_)
221  {
223  }
224 
225  //Loop over all particles to see if they are within the maser boundary
227  for (BaseParticle* particle : pH)
228  {
229  particle->setMaserParticle((getDistance(particle->getPosition()) > 0));
230  }
231 
232 #ifdef MERCURYDPM_USE_MPI
233  //Generate ghost particles
235 #endif
236 
237 }
@ INFO
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:733
PeriodicBoundaryHandler * getPeriodicHandler() const
Returns the periodic boundary handler.
Definition: BasePeriodicBoundary.cc:78
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created.
Definition: DPMBase.h:1443
Container to store pointers to all particles.
Definition: ParticleHandler.h:28
void addNewParticles()
Adds new particles to the periodic particle lists.
Definition: PeriodicBoundaryHandler.cc:278
void clearCommunicationLists()
Removes all ghost particles and bookkeeping for a fresh start.
Definition: PeriodicBoundaryHandler.cc:1785
void extendBottom() const
Definition: SubcriticalMaserBoundaryTEST.cc:388
void copyExtraParticles() const
Definition: SubcriticalMaserBoundaryTEST.cc:480

References PeriodicBoundaryHandler::addNewParticles(), PeriodicBoundaryHandler::clearCommunicationLists(), copyExtraParticles(), copyFlowParticles_, extendBottom(), getDistance(), BaseHandler< T >::getDPMBase(), BaseBoundary::getHandler(), BasePeriodicBoundary::getPeriodicHandler(), INFO, logger, maserIsActivated_, and DPMBase::particleHandler.

Referenced by checkBoundaryAfterParticlesMove(), and performActionsBeforeAddingParticles().

◆ checkBoundaryAfterParticleMoved()

bool SubcriticalMaserBoundaryTEST::checkBoundaryAfterParticleMoved ( BaseParticle p,
ParticleHandler pH 
) const

Shifts the particle to its 'periodic' position if it is a maser particle and has crossed either of the walls. Creates a 'normal' particle at its current position if it is a maser particle which crossed the RIGHT boundary wall.

Checks whether a given particle (a) is in the Maser and (b) has crossed the closest wall. If so, shifts its position so as to have it appear at the other wall, and creates a 'real' equivalent in the outflow domain.

Parameters
[in]pThe particle to be checked and possibly shifted and copied
pHThe ParticleHandler, which is unused in this implementation
Returns
Returns true if particle p has interacted with the boundary, false otherwise
140 {
141  // check if particle passed either of the boundary walls
142  if (maserIsActivated_)
143  {
144  if (p->isMaserParticle() && (getDistanceFromRight(p->getPosition()) < 0))
145  {
146  //Do the maser stuff
147  BaseParticle* pCopy = p->copy();
148  pCopy->setMaserParticle(false);
149  pH.addObject(pCopy);
150  /*
151  logger(INFO, "copying particle");
152  p->write(std::cout);
153  */
154  logger(VERBOSE, "copying particle %", p);
155  //Shift position of the particle
156  shiftPosition(p);
157  }
158  }
159  else
160  {
161  //note, if we already made a rough bottom on beforehand, we do not want the bottom particles to be eaten up,
162  //that is, all shifted inside the domain.
163  if (getDistance(p->getPosition()) < 0)
164  {
165  shiftPosition(p);
166  }
167  }
168 
169  return false;
170 }
@ VERBOSE
void setMaserParticle(bool flag)
Flags the status of the particle if it belongs to the maser boundary or not.
Definition: BaseParticle.cc:295
void addObject(BaseParticle *P) override
Adds a BaseParticle to the ParticleHandler.
Definition: ParticleHandler.cc:150
virtual void shiftPosition(BaseParticle *p) const override
shifts the particle
Definition: PeriodicBoundary.cc:198
Mdouble getDistanceFromRight(const Vec3D &position) const
returns the distance to the right wall
Definition: SubcriticalMaserBoundaryTEST.cc:301

References ParticleHandler::addObject(), getDistance(), getDistanceFromRight(), logger, maserIsActivated_, p, BaseParticle::setMaserParticle(), PeriodicBoundary::shiftPosition(), and VERBOSE.

Referenced by checkBoundaryAfterParticlesMove().

◆ checkBoundaryAfterParticlesMove()

void SubcriticalMaserBoundaryTEST::checkBoundaryAfterParticlesMove ( ParticleHandler pH)
overridevirtual

Evaluates what the particles have to do after they have changed position.

After particles have moved, check if the maser needs to be update or not. This function also updates the particles in the particleHandler based on their new position

Parameters
[in]pHThe particle handler, is used to loop over all particles to flag maser particles

Reimplemented from PeriodicBoundary.

178 {
179 #ifdef MERCURYDPM_USE_MPI
180  if (NUMBER_OF_PROCESSORS == 1)
181  {
182 #endif
183  //Activate the maser at the given time
184  if (getHandler()->getDPMBase()->getTime() > activationTime_)
185  {
186  if (!maserIsActivated_)
187  {
188  logger(INFO, "Activating the maser at time: %", activationTime_);
189  activateMaser();
190  }
191  }
192 
193  //Update particles
194  for (BaseParticle* p : pH)
195  {
197  }
198 #ifdef MERCURYDPM_USE_MPI
199  }
200 
201 #endif
202 }
#define NUMBER_OF_PROCESSORS
For the MPI communication routines this quantity is often required. defining this macro makes the cod...
Definition: GeneralDefine.h:41
bool checkBoundaryAfterParticleMoved(BaseParticle *p, ParticleHandler &pH) const
Shifts the particle to its 'periodic' position if it is a maser particle and has crossed either of th...
Definition: SubcriticalMaserBoundaryTEST.cc:139
void activateMaser()
Activates the maser functionaly of this periodic boundary.
Definition: SubcriticalMaserBoundaryTEST.cc:209

References activateMaser(), activationTime_, checkBoundaryAfterParticleMoved(), BaseBoundary::getHandler(), INFO, logger, maserIsActivated_, NUMBER_OF_PROCESSORS, and p.

◆ copy()

SubcriticalMaserBoundaryTEST * SubcriticalMaserBoundaryTEST::copy ( ) const
overridevirtual

Creates a copy of this maser on the heap.

Copy method, creates a copy of the object on the heap and returns a pointer to it.

Returns
pointer to the copy

Reimplemented from PeriodicBoundary.

34 {
35  return new SubcriticalMaserBoundaryTEST(*this);
36 }
SubcriticalMaserBoundaryTEST()
MaserBoundary constructor.
Definition: SubcriticalMaserBoundaryTEST.cc:11

References SubcriticalMaserBoundaryTEST().

◆ copyExtraParticles()

void SubcriticalMaserBoundaryTEST::copyExtraParticles ( ) const

when activating the maser, extend the bottom periodically until the end of the domain, by copying the fixed particles of the periodic part of the maser with intervals of shift_.

481 {
482  logger(INFO, "copying flow particles");
483 #ifdef MERCURYDPM_USE_MPI
484  MPIContainer& communicator = MPIContainer::Instance();
485  std::vector<unsigned int> numberOfParticlesPerCore(NUMBER_OF_PROCESSORS);
486  std::vector<std::vector<BaseParticle*>> particlesToCores(NUMBER_OF_PROCESSORS);
487  if (PROCESSOR_ID == 0)
488  {
489 #endif
490  std::vector<BaseParticle*> flowParticles;
491  std::vector<BaseParticle*> newParticles;
492  for (BaseParticle* p : getHandler()->getDPMBase()->particleHandler)
493  {
494  if (!p->isFixed() && !(p->isPeriodicGhostParticle()) && !(p->isMPIParticle()))
495  {
496  flowParticles.push_back(p);
497  }
498  }
499 
500  for (BaseParticle* p : flowParticles)
501  {
502  Vec3D newPosition = p->getPosition() + shift_;
503  for (unsigned i = 0; i < 4; ++i)
504  {
505  p = p->copy();
506  p->setPosition(newPosition);
507  newParticles.push_back(p);
508  newPosition += shift_;
509  }
510  }
511 #ifndef MERCURYDPM_USE_MPI
512  for (BaseParticle* p : newParticles)
513  {
515  }
516 #else
517  if (NUMBER_OF_PROCESSORS == 1)
518  {
519  for (BaseParticle* p : newParticles)
520  {
522  }
523  }
524  else
525  {
526  //count how many particles go to each core
527  for (BaseParticle* p : newParticles)
528  {
529  int targetGlobalIndex = getHandler()->getDPMBase()->domainHandler.getParticleDomainGlobalIndex(p);
530  int targetProcessor = getHandler()->getDPMBase()->domainHandler.getParticleProcessor(
531  targetGlobalIndex);
532  particlesToCores[targetProcessor].push_back(p);
533  }
534  for (int i = 0; i < NUMBER_OF_PROCESSORS; ++i)
535  {
536  numberOfParticlesPerCore[i] = (particlesToCores[i].size());
537  }
538  }
539 }
540 if (NUMBER_OF_PROCESSORS > 1)
541 {
542  //broadcast numberOfParticlesPerCore to other processors
543  communicator.broadcast(numberOfParticlesPerCore.data(), NUMBER_OF_PROCESSORS, 0);
544  for (unsigned i = 0; i < numberOfParticlesPerCore.size(); ++i)
545  {
546  for (unsigned p = 0; p < numberOfParticlesPerCore[i]; ++p)
547  {
548  BaseParticle* particle;
549  if (PROCESSOR_ID == 0)
550  {
551  particle = particlesToCores[i][p];
552  }
553  else
554  {
555  particle = new SphericalParticle();
556  }
557 
558  getHandler()->getDPMBase()->particleHandler.addObject(0, particle);
559  //particle->setPeriodicComplexity(getPeriodicHandler()->computePeriodicComplexity(particle->getPosition()));
560  }
561  }
562 }
563 #endif
564 
565  logger(INFO, "completed copying particles");
566 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define PROCESSOR_ID
Definition: GeneralDefine.h:42
DomainHandler domainHandler
An object of the class DomainHandler which deals with parallel code.
Definition: DPMBase.h:1468
int getParticleDomainGlobalIndex(BaseParticle *particle)
Definition: DomainHandler.cc:308
int getParticleProcessor(int globalIndex)
Definition: DomainHandler.cc:387
This class contains all information and functions required for communication between processors.
Definition: MpiContainer.h:109
std::enable_if< std::is_scalar< T >::value, void >::type broadcast(T &t, int fromProcessor=0)
Broadcasts a scalar from the root to all other processors.
Definition: MpiContainer.h:420
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:113
Vec3D shift_
shift from left to right boundary
Definition: PeriodicBoundary.h:195
A spherical particle is the most simple particle used in MercuryDPM.
Definition: SphericalParticle.h:16
Definition: Kernel/Math/Vector.h:30

References ParticleHandler::addObject(), MPIContainer::broadcast(), DPMBase::domainHandler, BaseHandler< T >::getDPMBase(), BaseBoundary::getHandler(), DomainHandler::getParticleDomainGlobalIndex(), DomainHandler::getParticleProcessor(), i, INFO, MPIContainer::Instance(), logger, NUMBER_OF_PROCESSORS, p, DPMBase::particleHandler, PROCESSOR_ID, and PeriodicBoundary::shift_.

Referenced by activateMaser().

◆ createPeriodicParticle()

void SubcriticalMaserBoundaryTEST::createPeriodicParticle ( BaseParticle p,
ParticleHandler pH 
)
override

Creates periodic particles when the particle is a maser particle and is sufficiently close to one of the boundary walls.

If the maser is active only maser particles can create a ghost of they are close to the right boundary. If this is the case a ghost will be created and added to the particleHandler at the appropriate position. If the maser is not active then this acts as a normal periodic boundary and so the left boundary is also allowed to create ghosts.

Parameters
[in]pParticle to be checked and possibly periodically copied
[in,out]pHSystem'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
Todo:
why 2.0?
106 {
108  const Mdouble proximityDistance = p->getMaxInteractionRadius() + 2.0* pH.getLargestParticle()->getMaxInteractionRadius();
109  if (maserIsActivated_)
110  {
111  if (p->isMaserParticle())
112  {
113  //Only if the particle is close to the right wall a ghost can be generated
114  if (getDistanceFromRight(p->getPosition()) < proximityDistance)
115  {
117  }
118  }
119  }
120  else
121  {
122  //If a particle is at any wall, the ghost can be generated
123  if (getDistance(p->getPosition()) < proximityDistance)
124  {
126  }
127  }
128 }
Mdouble getMaxInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e....
Definition: BaseParticle.h:345
BaseParticle * getLargestParticle() const
Returns the pointer of the largest particle in the particle handler. When mercury is running in paral...
Definition: ParticleHandler.cc:528
void createGhostParticle(BaseParticle *pReal)
Creates and adds a ghost particle from a given real particle.
Definition: PeriodicBoundary.cc:293

References PeriodicBoundary::createGhostParticle(), getDistance(), getDistanceFromRight(), ParticleHandler::getLargestParticle(), BaseParticle::getMaxInteractionRadius(), maserIsActivated_, and p.

◆ deactivateMaser()

void SubcriticalMaserBoundaryTEST::deactivateMaser ( )

Stops copying particles, and act merely as a periodic domain.

240 {
241  if (maserIsActivated_)
242  {
243  for (BaseParticle* particle : getHandler()->getDPMBase()->particleHandler)
244  {
245  if (getDistance(particle->getPosition()) > 0)
246  {
247  particle->setMaserParticle(false);
248  }
249  }
250 
251  maserIsActivated_ = false;
252 
253 
254  // TODO JMFT: @Marnix In activateMaser(), what do extendBottom() and
255  // addNewParticles() do, and how do I undo their effects?
256  }
257  else
258  logger(WARN, "[SubcriticalMaserBoundaryTEST::deactivateMaser()] Maser is not activated, so can't deactivate");
259 }
@ WARN

References getDistance(), BaseBoundary::getHandler(), logger, maserIsActivated_, and WARN.

◆ extendBottom()

void SubcriticalMaserBoundaryTEST::extendBottom ( ) const

when activating the maser, extend the bottom periodically until the end of the domain, by copying the fixed particles of the periodic part of the maser with intervals of shift_.

389 {
390  logger(INFO, "extending bottom");
391 #ifdef MERCURYDPM_USE_MPI
392  MPIContainer& communicator = MPIContainer::Instance();
393  std::vector<unsigned int> numberOfParticlesPerCore(NUMBER_OF_PROCESSORS);
394  std::vector<std::vector<BaseParticle*>> particlesToCores(NUMBER_OF_PROCESSORS);
395  if (PROCESSOR_ID == 0)
396  {
397 #endif
398  std::vector<BaseParticle*> fixedParticles;
399  std::vector<BaseParticle*> newParticles;
400  for (BaseParticle* p : getHandler()->getDPMBase()->particleHandler)
401  {
402  if (p->isFixed() && !(p->isPeriodicGhostParticle()) && !(p->isMPIParticle()))
403  {
404  fixedParticles.push_back(p);
405  }
406  }
407 
408  for (BaseParticle* p : fixedParticles)
409  {
410  Vec3D newPosition = p->getPosition() + shift_;
411  Vec3D maxDomain = getHandler()->getDPMBase()->getMax();
412  Vec3D minDomain = getHandler()->getDPMBase()->getMin();
413  while (newPosition.X < maxDomain.X && newPosition.Y < maxDomain.Y && newPosition.Z < maxDomain.Z
414  && newPosition.X > minDomain.X && newPosition.Y > minDomain.Y && newPosition.Z > minDomain.Z)
415  {
416  p = p->copy();
417  p->setPosition(newPosition);
418  newParticles.push_back(p);
419  newPosition += shift_;
420  }
421  }
422 #ifndef MERCURYDPM_USE_MPI
423  for (BaseParticle* p : newParticles)
424  {
426  }
427 #else
428  if (NUMBER_OF_PROCESSORS == 1)
429  {
430  for (BaseParticle* p : newParticles)
431  {
433  }
434  }
435  else
436  {
437  //count how many particles go to each core
438  for (BaseParticle* p : newParticles)
439  {
440  int targetGlobalIndex = getHandler()->getDPMBase()->domainHandler.getParticleDomainGlobalIndex(p);
441  int targetProcessor = getHandler()->getDPMBase()->domainHandler.getParticleProcessor(
442  targetGlobalIndex);
443  particlesToCores[targetProcessor].push_back(p);
444  }
445  for (int i = 0; i < NUMBER_OF_PROCESSORS; ++i)
446  {
447  numberOfParticlesPerCore[i] = (particlesToCores[i].size());
448  }
449  }
450 }
451 if (NUMBER_OF_PROCESSORS > 1)
452 {
453  //broadcast numberOfParticlesPerCore to other processors
454  communicator.broadcast(numberOfParticlesPerCore.data(), NUMBER_OF_PROCESSORS, 0);
455  for (unsigned i = 0; i < numberOfParticlesPerCore.size(); ++i)
456  {
457  for (unsigned p = 0; p < numberOfParticlesPerCore[i]; ++p)
458  {
459  BaseParticle* particle;
460  if (PROCESSOR_ID == 0)
461  {
462  particle = particlesToCores[i][p];
463  }
464  else
465  {
466  particle = new SphericalParticle();
467  }
468 
469  getHandler()->getDPMBase()->particleHandler.addObject(0, particle);
470  }
471  }
472 }
473 #endif
474 }
Vec3D getMax() const
Returns the maximum coordinates of the problem domain.
Definition: DPMBase.h:659
Vec3D getMin() const
Returns the minimum coordinates of the problem domain.
Definition: DPMBase.h:653
Mdouble Y
Definition: Kernel/Math/Vector.h:45
Mdouble Z
Definition: Kernel/Math/Vector.h:45
Mdouble X
the vector components
Definition: Kernel/Math/Vector.h:45

References ParticleHandler::addObject(), MPIContainer::broadcast(), DPMBase::domainHandler, BaseHandler< T >::getDPMBase(), BaseBoundary::getHandler(), DPMBase::getMax(), DPMBase::getMin(), DomainHandler::getParticleDomainGlobalIndex(), DomainHandler::getParticleProcessor(), i, INFO, MPIContainer::Instance(), logger, NUMBER_OF_PROCESSORS, p, DPMBase::particleHandler, PROCESSOR_ID, PeriodicBoundary::shift_, Vec3D::X, Vec3D::Y, and Vec3D::Z.

Referenced by activateMaser().

◆ getDistance()

Mdouble SubcriticalMaserBoundaryTEST::getDistance ( const Vec3D position) const
overridevirtual

gets the distance to the closest wall if maser is inactive, otherwise distance to right wall

getDistance is used in a periodic boundary to measure the distance from a certain position to the periodic boundary that actually mirrors are particle. For a maser boundary, if the boundary is active, this is only the right boundary and hence the generic getDistance function is overwritten with getDistanceFromRight()

Parameters
[in]positionThe position of which we want to know the distance towards the nearest active boundary

Reimplemented from PeriodicBoundary.

285 {
286  if (maserIsActivated_)
287  {
288  return getDistanceFromRight(position);
289  }
290  else
291  {
292  return PeriodicBoundary::getDistance(position);
293  }
294 }
Mdouble getDistance(const BaseParticle &p) const override
Returns the distance of the edge to the particle.
Definition: PeriodicBoundary.cc:176

References PeriodicBoundary::getDistance(), getDistanceFromRight(), and maserIsActivated_.

Referenced by actionsBeforeTimeLoop(), activateMaser(), checkBoundaryAfterParticleMoved(), createPeriodicParticle(), and deactivateMaser().

◆ getDistanceFromRight()

Mdouble SubcriticalMaserBoundaryTEST::getDistanceFromRight ( const Vec3D position) const

returns the distance to the right wall

The maser only requires particles at the right boundary to create ghosts therefore the distance towards the right boundary is an important quantity to compute.

Parameters
[in]Positionfrom which the distance to the right wall is computd
302 {
303  Mdouble distanceFromPlaneThroughOrigin = Vec3D::dot(position, normal_);
304  return distanceRight_ - distanceFromPlaneThroughOrigin;
305 }
Vec3D normal_
outward unit normal vector for right edge
Definition: PeriodicBoundary.h:176
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:56

References PeriodicBoundary::distanceRight_, Vec3D::dot(), and PeriodicBoundary::normal_.

Referenced by checkBoundaryAfterParticleMoved(), createPeriodicParticle(), getDistance(), and modifyPeriodicComplexity().

◆ getName()

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

Returns the name of the object.

Returns the name of the object class

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

Reimplemented from PeriodicBoundary.

67 {
68  return "SubcriticalMaserBoundaryTEST";
69 }

◆ isActivated()

bool SubcriticalMaserBoundaryTEST::isActivated ( ) const

Returns whether the maser is activated or not.

262 {
263  return maserIsActivated_;
264 }

References maserIsActivated_.

◆ modifyGhostAfterCreation()

void SubcriticalMaserBoundaryTEST::modifyGhostAfterCreation ( BaseParticle particle,
int  i 
)
overridevirtual

Reimplemented from BaseBoundary.

353 {
354  if (maserIsActivated_)
355  {
356  if (!particle->isMaserParticle())
357  {
358  std::vector<int> periodicComplexity = particle->getPeriodicComplexity();
359  periodicComplexity[i] = 3;
360  particle->setPeriodicComplexity(periodicComplexity);
361  }
362  }
363 }
void setPeriodicComplexity(std::vector< int > complexity)
Set the periodic communication complexity of the particle.
Definition: BaseParticle.cc:189
bool isMaserParticle() const
Indicates if this particle belongs to the maser boundary.
Definition: BaseParticle.cc:290
const std::vector< int > & getPeriodicComplexity()
Obtains the periodic communication complexity of the particle.
Definition: BaseParticle.cc:214

References BaseParticle::getPeriodicComplexity(), i, BaseParticle::isMaserParticle(), maserIsActivated_, and BaseParticle::setPeriodicComplexity().

◆ modifyPeriodicComplexity()

void SubcriticalMaserBoundaryTEST::modifyPeriodicComplexity ( std::vector< int > &  complexity,
int totalPeriodicComplexity,
BaseParticle particle,
int  i 
) const
overridevirtual

modifies the periodic complexity to support a maser boundary

In the parallel periodic boundary, everything is computed by the periodic complexity of a particle. Generally it is not possible to be a real particle outside a periodic boundary, but in case of a maser this is definetly possible. To accomodate this the periodic complexity needs to be modified such that this particle remains to be marked as a real particle. When the distance from the maser boundary is negative we give the flag 3 of the periodic complexity to mark that this is actually a real particle outside the maser boundary

Parameters
[in,out]complexityThe periodic complexity, indicates how a position/particle is related to periodioc boundaries
[in]positionThe position of the given periodic complexity
[in]Theindex in the complexity vector that this boundary corresponds to

Reimplemented from BasePeriodicBoundary.

320 {
321  if (maserIsActivated_)
322  {
323  if (particle->isMaserParticle())
324  {
325  //Check if this particle is flagged periodic in this boundary
326  if (complexity[i] < 0)
327  {
328  //Make sure that only a ghost close to the right boundary is flagged as real in this boundary
329  if (getDistanceFromRight(particle->getPosition()) < 0)
330  {
331  complexity[i] = 3;
332  }
333 
334  }
335  if (complexity[i] == -3)
336  {
337  logger(INFO, "Something went wrong in SubcriticalMaserBoundaryTEST::modifyPeriodicComplexity, "
338  "complexity[%] = -3", i);
339  }
340  }
341  else
342  {
343  if (complexity[i] == 1)
344  {
345  totalPeriodicComplexity--;
346  }
347  complexity[i] = 3;
348  }
349  }
350 }
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Definition: BaseInteractable.h:197

References getDistanceFromRight(), BaseInteractable::getPosition(), i, INFO, BaseParticle::isMaserParticle(), logger, and maserIsActivated_.

◆ performActionsBeforeAddingParticles()

void SubcriticalMaserBoundaryTEST::performActionsBeforeAddingParticles ( )
overridevirtual

Checks before adding particles if the maser needs to be activated.

Before adding particles a check is made to see if the maser needs to be activated or not This check is based on the give activation time, if not set by default it is NaN and the maser will never be activated

Reimplemented from BasePeriodicBoundary.

372 {
373  //Activate the maser at the given time
374  if (getHandler()->getDPMBase()->getTime() > activationTime_)
375  {
376  if (!maserIsActivated_)
377  {
378  logger(INFO, "Activating the maser at time: %", activationTime_);
379  activateMaser();
380  }
381  }
382 }

References activateMaser(), activationTime_, BaseBoundary::getHandler(), INFO, logger, and maserIsActivated_.

◆ read()

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

reads boundary properties from istream

Reads the boundary properties from an istream

Parameters
[in,out]isthe istream from which the boundary must be read

Reimplemented from PeriodicBoundary.

43 {
45  std::string dummy;
46  is >> dummy >> maserIsActivated_
47  >> dummy >> activationTime_;
48  logger(INFO, "maser is activated: %", maserIsActivated_);
49 }
virtual void read(std::istream &is) override
reads boundary properties from istream
Definition: PeriodicBoundary.cc:376
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286

References activationTime_, INFO, logger, maserIsActivated_, PeriodicBoundary::read(), and oomph::Global_string_for_annotation::string().

◆ setActivationTime()

void SubcriticalMaserBoundaryTEST::setActivationTime ( Mdouble  time)

sets the activate time of the maser

The maser is disabled by default and has to be activated. The activation can be done by setting the activation time.

Parameters
[in]timeThe time at which the maser needs to be activated
272 {
273  activationTime_ = time;
274 }

References activationTime_.

Referenced by MaserRepeatedOutInMPI2Test::setupInitialConditions(), and MpiMaserChuteTest::setupInitialConditions().

◆ setCopyFlowParticles()

void SubcriticalMaserBoundaryTEST::setCopyFlowParticles ( bool  copyFlowParticles)
72 {
73  copyFlowParticles_ = copyFlowParticles;
74 }

References copyFlowParticles_.

◆ write()

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

writes boundary properties to ostream

Writes boundary's properties to an ostream

Parameters
[in]osthe ostream to which the boundary must be written

Reimplemented from PeriodicBoundary.

56 {
58  os << " maserIsActivated " << maserIsActivated_
59  << " activationTime " << activationTime_;
60 }
void write(std::ostream &os) const override
writes boundary properties to ostream
Definition: PeriodicBoundary.cc:405

References activationTime_, maserIsActivated_, and PeriodicBoundary::write().

Member Data Documentation

◆ activationTime_

Mdouble SubcriticalMaserBoundaryTEST::activationTime_
private

◆ copyFlowParticles_

bool SubcriticalMaserBoundaryTEST::copyFlowParticles_
private

Flag for whether or not we copy a few blocks of flow particles in the front when activating the maser.

Referenced by activateMaser(), setCopyFlowParticles(), and SubcriticalMaserBoundaryTEST().

◆ maserIsActivated_


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