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.

34 {
35  distanceLeft_ = std::numeric_limits<Mdouble>::quiet_NaN();
36  distanceRight_ = std::numeric_limits<Mdouble>::quiet_NaN();
37  maserIsActivated_ = false;
38  activationTime_ = std::numeric_limits<Mdouble>::quiet_NaN();
39  copyFlowParticles_ = false;
40 }
Mdouble distanceLeft_
position of left edge, s.t. normal*x = distanceLeft_
Definition: PeriodicBoundary.h:201
Mdouble distanceRight_
position of right edge, s.t. normal*x = distanceRight_
Definition: PeriodicBoundary.h:206
Mdouble activationTime_
Time at which the maser opens.
Definition: SubcriticalMaserBoundaryTEST.h:147
bool maserIsActivated_
Flag whether or not the gap is created and particles transformed already.
Definition: SubcriticalMaserBoundaryTEST.h:142
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:152

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

Referenced by copy().

◆ ~SubcriticalMaserBoundaryTEST()

SubcriticalMaserBoundaryTEST::~SubcriticalMaserBoundaryTEST ( )
override

destructor

destructor

46 {
47  logger(DEBUG, "SubcriticalMaserBoundaryTEST::~SubcriticalBoundary() finished");
48 }
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.

102 {
103  if (maserIsActivated_)
104  {
105  for (BaseParticle* p : getHandler()->getDPMBase()->particleHandler)
106  {
107  if (getDistance(p->getPosition()) > 0)
108  {
109  p->setMaserParticle(true);
110  }
111  }
112  }
113 }
BoundaryHandler * getHandler() const
Returns the boundary's BoundaryHandler.
Definition: BaseBoundary.cc:143
Definition: BaseParticle.h:54
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:306

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

◆ 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.

232 {
233  logger(INFO, "SubcriticalMaserBoundaryTEST::activateMaser ");
234 #ifdef MERCURYDPM_USE_MPI
235  //Clear the periodic boundaryHandler, only want real particles
237 #endif
238  //Flag that the maser is active!
239  maserIsActivated_ = true;
240 
241  extendBottom();
242  if (copyFlowParticles_)
243  {
245  }
246 
247  //Loop over all particles to see if they are within the maser boundary
249  for (BaseParticle* particle : pH)
250  {
251  particle->setMaserParticle((getDistance(particle->getPosition()) > 0));
252  }
253 
254 #ifdef MERCURYDPM_USE_MPI
255  //Generate ghost particles
257 #endif
258 
259 }
@ INFO
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725
PeriodicBoundaryHandler * getPeriodicHandler() const
Returns the periodic boundary handler.
Definition: BasePeriodicBoundary.cc:99
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created.
Definition: DPMBase.h:1437
Container to store all BaseParticle.
Definition: ParticleHandler.h:48
void addNewParticles()
Adds new particles to the periodic particle lists.
Definition: PeriodicBoundaryHandler.cc:300
void clearCommunicationLists()
Removes all ghost particles and bookkeeping for a fresh start.
Definition: PeriodicBoundaryHandler.cc:1807
void extendBottom() const
Definition: SubcriticalMaserBoundaryTEST.cc:410
void copyExtraParticles() const
Definition: SubcriticalMaserBoundaryTEST.cc:502

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
162 {
163  // check if particle passed either of the boundary walls
164  if (maserIsActivated_)
165  {
166  if (p->isMaserParticle() && (getDistanceFromRight(p->getPosition()) < 0))
167  {
168  //Do the maser stuff
169  BaseParticle* pCopy = p->copy();
170  pCopy->setMaserParticle(false);
171  pH.addObject(pCopy);
172  /*
173  logger(INFO, "copying particle");
174  p->write(std::cout);
175  */
176  logger(VERBOSE, "copying particle %", p);
177  //Shift position of the particle
178  shiftPosition(p);
179  }
180  }
181  else
182  {
183  //note, if we already made a rough bottom on beforehand, we do not want the bottom particles to be eaten up,
184  //that is, all shifted inside the domain.
185  if (getDistance(p->getPosition()) < 0)
186  {
187  shiftPosition(p);
188  }
189  }
190 
191  return false;
192 }
@ VERBOSE
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Definition: BaseInteractable.h:218
bool isMaserParticle() const
Indicates if this particle belongs to the maser boundary.
Definition: BaseParticle.cc:307
virtual BaseParticle * copy() const =0
Particle copy method. It calls to copy constructor of this Particle, useful for polymorphism.
void setMaserParticle(bool flag)
Flags the status of the particle if it belongs to the maser boundary or not.
Definition: BaseParticle.cc:312
void addObject(BaseParticle *P) override
Adds a BaseParticle to the ParticleHandler.
Definition: ParticleHandler.cc:171
virtual void shiftPosition(BaseParticle *p) const override
shifts the particle
Definition: PeriodicBoundary.cc:219
Mdouble getDistanceFromRight(const Vec3D &position) const
returns the distance to the right wall
Definition: SubcriticalMaserBoundaryTEST.cc:323

References ParticleHandler::addObject(), BaseParticle::copy(), getDistance(), getDistanceFromRight(), BaseInteractable::getPosition(), BaseParticle::isMaserParticle(), logger, maserIsActivated_, 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.

200 {
201 #ifdef MERCURYDPM_USE_MPI
202  if (NUMBER_OF_PROCESSORS == 1)
203  {
204 #endif
205  //Activate the maser at the given time
206  if (getHandler()->getDPMBase()->getTime() > activationTime_)
207  {
208  if (!maserIsActivated_)
209  {
210  logger(INFO, "Activating the maser at time: %", activationTime_);
211  activateMaser();
212  }
213  }
214 
215  //Update particles
216  for (BaseParticle* p : pH)
217  {
219  }
220 #ifdef MERCURYDPM_USE_MPI
221  }
222 
223 #endif
224 }
#define NUMBER_OF_PROCESSORS
For the MPI communication routines this quantity is often required. defining this macro makes the cod...
Definition: GeneralDefine.h:62
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:161
void activateMaser()
Activates the maser functionaly of this periodic boundary.
Definition: SubcriticalMaserBoundaryTEST.cc:231

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

◆ 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.

56 {
57  return new SubcriticalMaserBoundaryTEST(*this);
58 }
SubcriticalMaserBoundaryTEST()
MaserBoundary constructor.
Definition: SubcriticalMaserBoundaryTEST.cc:33

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_.

503 {
504  logger(INFO, "copying flow particles");
505 #ifdef MERCURYDPM_USE_MPI
506  MPIContainer& communicator = MPIContainer::Instance();
507  std::vector<unsigned int> numberOfParticlesPerCore(NUMBER_OF_PROCESSORS);
508  std::vector<std::vector<BaseParticle*>> particlesToCores(NUMBER_OF_PROCESSORS);
509  if (PROCESSOR_ID == 0)
510  {
511 #endif
512  std::vector<BaseParticle*> flowParticles;
513  std::vector<BaseParticle*> newParticles;
514  for (BaseParticle* p : getHandler()->getDPMBase()->particleHandler)
515  {
516  if (!p->isFixed() && !(p->isPeriodicGhostParticle()) && !(p->isMPIParticle()))
517  {
518  flowParticles.push_back(p);
519  }
520  }
521 
522  for (BaseParticle* p : flowParticles)
523  {
524  Vec3D newPosition = p->getPosition() + shift_;
525  for (unsigned i = 0; i < 4; ++i)
526  {
527  p = p->copy();
528  p->setPosition(newPosition);
529  newParticles.push_back(p);
530  newPosition += shift_;
531  }
532  }
533 #ifndef MERCURYDPM_USE_MPI
534  for (BaseParticle* p : newParticles)
535  {
537  }
538 #else
539  if (NUMBER_OF_PROCESSORS == 1)
540  {
541  for (BaseParticle* p : newParticles)
542  {
544  }
545  }
546  else
547  {
548  //count how many particles go to each core
549  for (BaseParticle* p : newParticles)
550  {
551  int targetGlobalIndex = getHandler()->getDPMBase()->domainHandler.getParticleDomainGlobalIndex(p);
552  int targetProcessor = getHandler()->getDPMBase()->domainHandler.getParticleProcessor(
553  targetGlobalIndex);
554  particlesToCores[targetProcessor].push_back(p);
555  }
556  for (int i = 0; i < NUMBER_OF_PROCESSORS; ++i)
557  {
558  numberOfParticlesPerCore[i] = (particlesToCores[i].size());
559  }
560  }
561 }
562 if (NUMBER_OF_PROCESSORS > 1)
563 {
564  //broadcast numberOfParticlesPerCore to other processors
565  communicator.broadcast(numberOfParticlesPerCore.data(), NUMBER_OF_PROCESSORS, 0);
566  for (unsigned i = 0; i < numberOfParticlesPerCore.size(); ++i)
567  {
568  for (unsigned p = 0; p < numberOfParticlesPerCore[i]; ++p)
569  {
570  BaseParticle* particle;
571  if (PROCESSOR_ID == 0)
572  {
573  particle = particlesToCores[i][p];
574  }
575  else
576  {
577  particle = new SphericalParticle();
578  }
579 
580  getHandler()->getDPMBase()->particleHandler.addObject(0, particle);
581  //particle->setPeriodicComplexity(getPeriodicHandler()->computePeriodicComplexity(particle->getPosition()));
582  }
583  }
584 }
585 #endif
586 
587  logger(INFO, "completed copying particles");
588 }
#define PROCESSOR_ID
Definition: GeneralDefine.h:63
DomainHandler domainHandler
An object of the class DomainHandler which deals with parallel code.
Definition: DPMBase.h:1462
int getParticleDomainGlobalIndex(BaseParticle *particle)
Definition: DomainHandler.cc:330
int getParticleProcessor(int globalIndex)
Definition: DomainHandler.cc:409
This class contains all information and functions required for communication between processors.
Definition: MpiContainer.h:130
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:441
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134
Vec3D shift_
shift from left to right boundary
Definition: PeriodicBoundary.h:216
A spherical particle is the most simple particle used in MercuryDPM.
Definition: SphericalParticle.h:37
Definition: Vector.h:51
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51

References ParticleHandler::addObject(), MPIContainer::broadcast(), DPMBase::domainHandler, BaseHandler< T >::getDPMBase(), BaseBoundary::getHandler(), DomainHandler::getParticleDomainGlobalIndex(), DomainHandler::getParticleProcessor(), constants::i, INFO, MPIContainer::Instance(), logger, NUMBER_OF_PROCESSORS, 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?
128 {
130  const Mdouble proximityDistance = p->getMaxInteractionRadius() + 2.0* pH.getLargestParticle()->getMaxInteractionRadius();
131  if (maserIsActivated_)
132  {
133  if (p->isMaserParticle())
134  {
135  //Only if the particle is close to the right wall a ghost can be generated
136  if (getDistanceFromRight(p->getPosition()) < proximityDistance)
137  {
139  }
140  }
141  }
142  else
143  {
144  //If a particle is at any wall, the ghost can be generated
145  if (getDistance(p->getPosition()) < proximityDistance)
146  {
148  }
149  }
150 }
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getMaxInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e....
Definition: BaseParticle.h:362
BaseParticle * getLargestParticle() const
Returns the pointer of the largest particle in the particle handler. When mercury is running in paral...
Definition: ParticleHandler.cc:534
void createGhostParticle(BaseParticle *pReal)
Creates and adds a ghost particle from a given real particle.
Definition: PeriodicBoundary.cc:314

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

◆ deactivateMaser()

void SubcriticalMaserBoundaryTEST::deactivateMaser ( )

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

262 {
263  if (maserIsActivated_)
264  {
265  for (BaseParticle* particle : getHandler()->getDPMBase()->particleHandler)
266  {
267  if (getDistance(particle->getPosition()) > 0)
268  {
269  particle->setMaserParticle(false);
270  }
271  }
272 
273  maserIsActivated_ = false;
274 
275 
276  // TODO JMFT: @Marnix In activateMaser(), what do extendBottom() and
277  // addNewParticles() do, and how do I undo their effects?
278  }
279  else
280  logger(WARN, "[SubcriticalMaserBoundaryTEST::deactivateMaser()] Maser is not activated, so can't deactivate");
281 }
@ 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_.

411 {
412  logger(INFO, "extending bottom");
413 #ifdef MERCURYDPM_USE_MPI
414  MPIContainer& communicator = MPIContainer::Instance();
415  std::vector<unsigned int> numberOfParticlesPerCore(NUMBER_OF_PROCESSORS);
416  std::vector<std::vector<BaseParticle*>> particlesToCores(NUMBER_OF_PROCESSORS);
417  if (PROCESSOR_ID == 0)
418  {
419 #endif
420  std::vector<BaseParticle*> fixedParticles;
421  std::vector<BaseParticle*> newParticles;
422  for (BaseParticle* p : getHandler()->getDPMBase()->particleHandler)
423  {
424  if (p->isFixed() && !(p->isPeriodicGhostParticle()) && !(p->isMPIParticle()))
425  {
426  fixedParticles.push_back(p);
427  }
428  }
429 
430  for (BaseParticle* p : fixedParticles)
431  {
432  Vec3D newPosition = p->getPosition() + shift_;
433  Vec3D maxDomain = getHandler()->getDPMBase()->getMax();
434  Vec3D minDomain = getHandler()->getDPMBase()->getMin();
435  while (newPosition.X < maxDomain.X && newPosition.Y < maxDomain.Y && newPosition.Z < maxDomain.Z
436  && newPosition.X > minDomain.X && newPosition.Y > minDomain.Y && newPosition.Z > minDomain.Z)
437  {
438  p = p->copy();
439  p->setPosition(newPosition);
440  newParticles.push_back(p);
441  newPosition += shift_;
442  }
443  }
444 #ifndef MERCURYDPM_USE_MPI
445  for (BaseParticle* p : newParticles)
446  {
448  }
449 #else
450  if (NUMBER_OF_PROCESSORS == 1)
451  {
452  for (BaseParticle* p : newParticles)
453  {
455  }
456  }
457  else
458  {
459  //count how many particles go to each core
460  for (BaseParticle* p : newParticles)
461  {
462  int targetGlobalIndex = getHandler()->getDPMBase()->domainHandler.getParticleDomainGlobalIndex(p);
463  int targetProcessor = getHandler()->getDPMBase()->domainHandler.getParticleProcessor(
464  targetGlobalIndex);
465  particlesToCores[targetProcessor].push_back(p);
466  }
467  for (int i = 0; i < NUMBER_OF_PROCESSORS; ++i)
468  {
469  numberOfParticlesPerCore[i] = (particlesToCores[i].size());
470  }
471  }
472 }
473 if (NUMBER_OF_PROCESSORS > 1)
474 {
475  //broadcast numberOfParticlesPerCore to other processors
476  communicator.broadcast(numberOfParticlesPerCore.data(), NUMBER_OF_PROCESSORS, 0);
477  for (unsigned i = 0; i < numberOfParticlesPerCore.size(); ++i)
478  {
479  for (unsigned p = 0; p < numberOfParticlesPerCore[i]; ++p)
480  {
481  BaseParticle* particle;
482  if (PROCESSOR_ID == 0)
483  {
484  particle = particlesToCores[i][p];
485  }
486  else
487  {
488  particle = new SphericalParticle();
489  }
490 
491  getHandler()->getDPMBase()->particleHandler.addObject(0, particle);
492  }
493  }
494 }
495 #endif
496 }
Vec3D getMax() const
Definition: DPMBase.h:670
Vec3D getMin() const
Definition: DPMBase.h:664
Mdouble Y
Definition: Vector.h:66
Mdouble Z
Definition: Vector.h:66
Mdouble X
the vector components
Definition: Vector.h:66

References ParticleHandler::addObject(), MPIContainer::broadcast(), DPMBase::domainHandler, BaseHandler< T >::getDPMBase(), BaseBoundary::getHandler(), DPMBase::getMax(), DPMBase::getMin(), DomainHandler::getParticleDomainGlobalIndex(), DomainHandler::getParticleProcessor(), constants::i, INFO, MPIContainer::Instance(), logger, NUMBER_OF_PROCESSORS, 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.

307 {
308  if (maserIsActivated_)
309  {
310  return getDistanceFromRight(position);
311  }
312  else
313  {
314  return PeriodicBoundary::getDistance(position);
315  }
316 }
Mdouble getDistance(const BaseParticle &p) const override
Returns the distance of the edge to the particle.
Definition: PeriodicBoundary.cc:197

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
324 {
325  Mdouble distanceFromPlaneThroughOrigin = Vec3D::dot(position, normal_);
326  return distanceRight_ - distanceFromPlaneThroughOrigin;
327 }
Vec3D normal_
outward unit normal vector for right edge
Definition: PeriodicBoundary.h:197
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:76

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.

89 {
90  return "SubcriticalMaserBoundaryTEST";
91 }

◆ isActivated()

bool SubcriticalMaserBoundaryTEST::isActivated ( ) const

Returns whether the maser is activated or not.

284 {
285  return maserIsActivated_;
286 }

References maserIsActivated_.

◆ modifyGhostAfterCreation()

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

Reimplemented from BaseBoundary.

375 {
376  if (maserIsActivated_)
377  {
378  if (!particle->isMaserParticle())
379  {
380  std::vector<int> periodicComplexity = particle->getPeriodicComplexity();
381  periodicComplexity[i] = 3;
382  particle->setPeriodicComplexity(periodicComplexity);
383  }
384  }
385 }
void setPeriodicComplexity(std::vector< int > complexity)
Set the periodic communication complexity of the particle.
Definition: BaseParticle.cc:206
const std::vector< int > & getPeriodicComplexity()
Obtains the periodic communication complexity of the particle.
Definition: BaseParticle.cc:231

References BaseParticle::getPeriodicComplexity(), constants::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.

342 {
343  if (maserIsActivated_)
344  {
345  if (particle->isMaserParticle())
346  {
347  //Check if this particle is flagged periodic in this boundary
348  if (complexity[i] < 0)
349  {
350  //Make sure that only a ghost close to the right boundary is flagged as real in this boundary
351  if (getDistanceFromRight(particle->getPosition()) < 0)
352  {
353  complexity[i] = 3;
354  }
355 
356  }
357  if (complexity[i] == -3)
358  {
359  logger(INFO, "Something went wrong in SubcriticalMaserBoundaryTEST::modifyPeriodicComplexity, "
360  "complexity[%] = -3", i);
361  }
362  }
363  else
364  {
365  if (complexity[i] == 1)
366  {
367  totalPeriodicComplexity--;
368  }
369  complexity[i] = 3;
370  }
371  }
372 }

References getDistanceFromRight(), BaseInteractable::getPosition(), constants::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.

394 {
395  //Activate the maser at the given time
396  if (getHandler()->getDPMBase()->getTime() > activationTime_)
397  {
398  if (!maserIsActivated_)
399  {
400  logger(INFO, "Activating the maser at time: %", activationTime_);
401  activateMaser();
402  }
403  }
404 }

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.

65 {
67  std::string dummy;
68  is >> dummy >> maserIsActivated_
69  >> dummy >> activationTime_;
70  logger(INFO, "maser is activated: %", maserIsActivated_);
71 }
virtual void read(std::istream &is) override
reads boundary properties from istream
Definition: PeriodicBoundary.cc:397

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

◆ 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
294 {
295  activationTime_ = time;
296 }

References activationTime_.

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

◆ setCopyFlowParticles()

void SubcriticalMaserBoundaryTEST::setCopyFlowParticles ( bool  copyFlowParticles)
94 {
95  copyFlowParticles_ = copyFlowParticles;
96 }

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.

78 {
80  os << " maserIsActivated " << maserIsActivated_
81  << " activationTime " << activationTime_;
82 }
void write(std::ostream &os) const override
writes boundary properties to ostream
Definition: PeriodicBoundary.cc:426

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: