MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SubcriticalMaserBoundary Class Reference

Variation on the PeriodicBoundary which also has an outflow part. More...

#include <SubcriticalMaserBoundary.h>

+ Inheritance diagram for SubcriticalMaserBoundary:

Public Member Functions

 SubcriticalMaserBoundary ()
 MaserBoundary constructor. More...
 
 SubcriticalMaserBoundary (const PeriodicBoundary &periodicBoundary)
 Maserboundary constructor that takes a periodic boundary, and converts it to a maser boundary. More...
 
SubcriticalMaserBoundarycopy () const override
 Creates a copy of this maser on the heap. More...
 
void set (Vec3D normal, Mdouble distanceLeft, Mdouble distanceRight)
 Sets all boundary properties at once and adds particles of the handler to the maser. 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 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...
 
void createPeriodicParticles (ParticleHandler &pH) override
 
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 addParticleToMaser (BaseParticle *p)
 Converts a 'normal' particle into a maser particle. More...
 
void removeParticleFromMaser (BaseParticle *p)
 Convert a maser particle into a 'normal' particle. More...
 
bool isMaserParticle (BaseParticle *p) const
 Returns true if the particle is a Maser particle, and false otherwise. More...
 
bool isNormalParticle (BaseParticle *p) const
 Returns true if the particle is a Normal particle, and false otherwise. More...
 
void actionsBeforeTimeLoop () override
 Does everything that needs to be done for this boundary between setupInitialConditions and the time loop, in this case, it activates the maser. More...
 
void activateMaser ()
 Opens the gap, and transforms particles to maser particles. Also calls turnOnCopying(). More...
 
void deactivateMaser ()
 Stops copying particles (and act merely as a chute) More...
 
Mdouble getDistanceLeft () const
 
Mdouble getDistanceRight () const
 
- 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 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 Member Functions

void shiftPosition (BaseParticle *p) const
 Shifts the particle to its 'periodic' position. More...
 
BaseParticlecreateGhostCopy (BaseParticle *p) const
 Creates a copy of the input particle, that gets removed again in DPMBase::removeDuplicatePeriodicParticles. More...
 
bool isClosestToRightBoundary (const BaseParticle *const p) const
 Returns whether the given particle is closer to the right boundary of the periodic part. More...
 
Mdouble getDistance (BaseParticle *p) const
 Returns the distance of the wall to the particle. More...
 

Private Attributes

Vec3D normal_
 Normal unit vector of both maser walls. Points in the flowing direction. More...
 
Mdouble distanceLeft_
 position of left boundary wall, s.t. normal*x=position_left More...
 
Mdouble distanceRight_
 position of right boundary wall, s.t. normal*x=position_right More...
 
Vec3D shift_
 Direction in which particles are to be shifted when they cross the boundary. More...
 
std::map< const
ParticleSpecies *, const
ParticleSpecies * > 
speciesConversionNormalToMaser_
 List of 'normal' particles' species, and their maser counterparts. More...
 
std::map< const
ParticleSpecies *, const
ParticleSpecies * > 
speciesConversionMaserToNormal_
 List of 'maser' particles' species, and their normal counterparts. More...
 
bool maserIsActivated_
 Flag whether or not the gap is created and particles transformed already. More...
 

Detailed Description

Variation on the PeriodicBoundary which also has an outflow part.

Creates a boundary which divides the domain into two parts: a periodic domain and an outflow domain. Any particle flowing through the right of the periodic domain is moved to both the left side of the periodic domain (as with a PeriodicBoundary), and also copied the left side of the outflow domain. Furthermore, the particles near the right side of the periodic domain also exert forces on the left side of the outflow domain, and vice versa. The left side of the periodic domain does not influence the right side of the periodic domain. When a particle in the outflow domain tries to enter the periodic domain, it gets removed. If a particle tries to leave the periodic domain to the left, it gets removed.

The difference between SubcriticalMaserBoundary (formerly known as MaserBoundaryOldStyle) and ConstantMassFlowMaserBoundary (formerly known simply as MaserBoundary) is that in ConstantMassFlowMaserBoundary, the left hand side of the periodic box does not have any influence on the rest of the flow, but the right side of the periodic box and the left side of the outflow domain interact. The ConstantMassFlowMaserBoundary is most useful for fast (supercritical) flows, and for flows for which the flux across the boundary needs to be controlled. The SubcriticalMaserBoundary is more useful for slow flows, as the ConstantMassFlowMaserBoundary might generate "pulse-waves" in those cases.

For a compact overview of the behaviour of SubcriticalMaserBoundary, please look at the output of SubcriticalMaserBoundarySelfTest.

Todo:
Which Maser is it used in Denissen2019? To cite the Maser: I. F. C. Denissen, T. Weinhart, A. Te Voortwis, S. Luding, J. M. N. T. Gray and A. R. Thornton, Bulbous head formation in bidisperse shallow granular flow over an inclined plane. Journal of Fluid Mechanics, 866:263–297, mar 2019.

Definition at line 77 of file SubcriticalMaserBoundary.h.

Constructor & Destructor Documentation

SubcriticalMaserBoundary::SubcriticalMaserBoundary ( )

MaserBoundary constructor.

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

Definition at line 33 of file SubcriticalMaserBoundary.cc.

References distanceLeft_, distanceRight_, logger, maserIsActivated_, and WARN.

Referenced by copy().

34 {
35 #ifdef MERCURY_USE_MPI
36  logger(WARN,"Make sure the whole maser boundary is on one processor when using parallel code");
37 #endif
38  distanceLeft_ = std::numeric_limits<double>::quiet_NaN();
39  distanceRight_ = std::numeric_limits<double>::quiet_NaN();
40  maserIsActivated_ = false;
41 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
bool maserIsActivated_
Flag whether or not the gap is created and particles transformed already.
Mdouble distanceRight_
position of right boundary wall, s.t. normal*x=position_right
Mdouble distanceLeft_
position of left boundary wall, s.t. normal*x=position_left
SubcriticalMaserBoundary::SubcriticalMaserBoundary ( const PeriodicBoundary periodicBoundary)
explicit

Maserboundary constructor that takes a periodic boundary, and converts it to a maser boundary.

MaserBoundary constructor from a periodic boundary. It copies the properties of the periodic boundary, and then immediately opens the maser. Do not insert particles for the maser after this constructor.

Parameters
[in]periodicBoundaryThe periodic boundary on which this maser boundary is based.

Definition at line 48 of file SubcriticalMaserBoundary.cc.

References activateMaser(), distanceLeft_, distanceRight_, PeriodicBoundary::getDistanceLeft(), PeriodicBoundary::getDistanceRight(), PeriodicBoundary::getNormal(), PeriodicBoundary::getShift(), INFO, logger, maserIsActivated_, normal_, and shift_.

48  : BaseBoundary(
49  periodicBoundary)
50 {
51  logger(INFO, "Constructor SubcriticalMaserBoundary(const PeriodicBoundary&) started");
52  distanceLeft_ = periodicBoundary.getDistanceLeft();
53  distanceRight_ = periodicBoundary.getDistanceRight();
54  normal_ = periodicBoundary.getNormal();
55  shift_ = periodicBoundary.getShift();
56  maserIsActivated_ = false;
57 
58  logger(INFO, "going to activate the maser");
59  //assume that the maser should be activated immediately when it gets constructed from a periodic boundary
60  activateMaser();
61 }
Mdouble getDistanceLeft() const
Returns the distance of the left wall to the origin, in normal direction.
void activateMaser()
Opens the gap, and transforms particles to maser particles. Also calls turnOnCopying().
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Vec3D shift_
Direction in which particles are to be shifted when they cross the boundary.
Mdouble getDistanceRight() const
Returns the distance of the right wall to the origin, in normal direction.
Vec3D getNormal() const
returns the vector normal to the periodic boundary
Vec3D getShift() const
Returns the vector going from the left to the right side of the periodic boundary.
bool maserIsActivated_
Flag whether or not the gap is created and particles transformed already.
Mdouble distanceRight_
position of right boundary wall, s.t. normal*x=position_right
Vec3D normal_
Normal unit vector of both maser walls. Points in the flowing direction.
Mdouble distanceLeft_
position of left boundary wall, s.t. normal*x=position_left
BaseBoundary()
default constructor.
Definition: BaseBoundary.cc:32

Member Function Documentation

void SubcriticalMaserBoundary::actionsBeforeTimeLoop ( )
overridevirtual

Does everything that needs to be done for this boundary between setupInitialConditions and the time loop, in this case, it activates the maser.

The maser boundary should be activated before the time loop starts, but after all particles are added.

Reimplemented from BaseBoundary.

Definition at line 372 of file SubcriticalMaserBoundary.cc.

References activateMaser().

373 {
374  activateMaser();
375 }
void activateMaser()
Opens the gap, and transforms particles to maser particles. Also calls turnOnCopying().
void SubcriticalMaserBoundary::activateMaser ( )

Opens the gap, and transforms particles to maser particles. Also calls turnOnCopying().

Activate the maser by creating a gap betweeen the periodic domain and the outflow domain, and transforming all the particles in the domain to maser particles. For an explanation of the magic number 6, see the detailed documentation for gapSize_. Note that gapSize_ is set here and not in set, since it is possible that the user first adds boundaries to the domain before the particles. The maser boundary should only be activated after all particles are in.

Definition at line 384 of file SubcriticalMaserBoundary.cc.

References addParticleToMaser(), getDistance(), BaseHandler< T >::getDPMBase(), BaseBoundary::getHandler(), INFO, logger, maserIsActivated_, DPMBase::particleHandler, and WARN.

Referenced by actionsBeforeTimeLoop(), and SubcriticalMaserBoundary().

385 {
386  if (!maserIsActivated_)
387  {
388  logger(INFO, "Going to add particles to the maser and shift the periodic maser boundaries");
390  logger(INFO, "just before particle loop");
391  for (BaseParticle* const p : pH)
392  {
393  if (getDistance(p) > 0)
394  {
396  }
397  }
398  maserIsActivated_ = true;
399  }
400  else
401  {
402  logger(WARN, "Cannot activate the maser boundary twice!");
403  }
404 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
bool maserIsActivated_
Flag whether or not the gap is created and particles transformed already.
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created...
Definition: DPMBase.h:1329
BoundaryHandler * getHandler() const
Returns the boundary's BoundaryHandler.
Container to store all BaseParticle.
void addParticleToMaser(BaseParticle *p)
Converts a 'normal' particle into a maser particle.
Mdouble getDistance(BaseParticle *p) const
Returns the distance of the wall to the particle.
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725
void SubcriticalMaserBoundary::addParticleToMaser ( BaseParticle p)

Converts a 'normal' particle into a maser particle.

Turns given particle into a 'maser particle' by changing its species into a 'maser particle' copy species. If the particle species is not yet in the std::map speciesConversionNormalToMaser_, it and its maser copy species are added. This function should be called at the beginning of the simulation, right after actually filling the maser with particles, flagging each particle as one belonging to the maser.

Parameters
[in,out]pThe particle which is added to the maser. Its species is 'changed' to the maser copy species.

Definition at line 293 of file SubcriticalMaserBoundary.cc.

References BaseSpecies::copy(), BaseHandler< T >::copyAndAddObject(), DEBUG, BaseHandler< T >::getDPMBase(), BaseBoundary::getHandler(), BaseObject::getId(), BaseInteractable::getSpecies(), INFO, logger, BaseObject::setId(), BaseObject::setIndex(), BaseParticle::setSpecies(), speciesConversionMaserToNormal_, speciesConversionNormalToMaser_, DPMBase::speciesHandler, and VERBOSE.

Referenced by activateMaser().

294 {
295  // check if particle species already known by the maser
296  auto conversion = speciesConversionNormalToMaser_.find(p->getSpecies());
297  if (conversion != speciesConversionNormalToMaser_.end())
298  {
299  //species known and flagged (i.e. 'converted')
300  logger(VERBOSE, "[SubcriticalMaserBoundary::addParticleToMaser()] Species conversion already present");
301  p->setSpecies(conversion->second);
302  }
303  else
304  {
305  SpeciesHandler& speciesHandler = (getHandler()->getDPMBase()->speciesHandler);
306  // species is not yet known by the maser, it has to be added to both maps
307  ParticleSpecies* newSpecies = speciesHandler.copyAndAddObject(*(p->getSpecies()));
309  std::pair<const ParticleSpecies*, const ParticleSpecies*>(p->getSpecies(), newSpecies));
311  std::pair<const ParticleSpecies*, const ParticleSpecies*>(newSpecies, p->getSpecies()));
312  logger(INFO, "[SubcriticalMaserBoundary::addParticleToMaser()] New species conversion created");
313  logger(INFO, "Original species ID: %, new species ID: %", p->getSpecies()->getId(), newSpecies->getId());
314 
315  //Copy over the mixed species. The delete is necessary here since it is overwritten with a copy of the old mixed
316  //species, and otherwise the properties are not copied over correctly.
317  //
318  //setId and setIndex refer to the two different species which are present in this mixed species.
319  //The highest species-index should appear first and is therefore the ID, while the second species-index is the
320  //"index" of the mixed species.
321  for (const BaseSpecies* const s : speciesHandler)
322  {
323  if (s->getId() != newSpecies->getId() && s->getId() != p->getSpecies()->getId())
324  {
325  BaseSpecies* newMixed = speciesHandler.getMixedObject(s->getId(), newSpecies->getId());
326  delete newMixed;
327  const BaseSpecies* const oldMixed = speciesHandler.getMixedObject(s->getId(), p->getSpecies()->getId());
328  newMixed = oldMixed->copy();
329  newMixed->setId(newSpecies->getId());
330  newMixed->setIndex(s->getId());
331  logger(DEBUG, "mixed species of % and % is now \n %, should be \n %", s->getId(), newSpecies->getId(),
332  *newMixed, *oldMixed);
333  }
334  }
335 
336  // now the species IS added, so flag (convert) it!
337  p->setSpecies(newSpecies);
338  }
339 }
Container to store all ParticleSpecies.
void setIndex(unsigned int index)
Allows one to assign an index to an object in the handler/container.
Definition: BaseObject.cc:64
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.h:125
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:49
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
const ParticleSpecies * getSpecies() const
Returns a pointer to the species of this BaseInteractable.
void setSpecies(const ParticleSpecies *species)
std::map< const ParticleSpecies *, const ParticleSpecies * > speciesConversionNormalToMaser_
List of 'normal' particles' species, and their maser counterparts.
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddObject(const U &object)
Creates a copy of a Object and adds it to the BaseHandler.
Definition: BaseHandler.h:379
BoundaryHandler * getHandler() const
Returns the boundary's BoundaryHandler.
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1319
std::map< const ParticleSpecies *, const ParticleSpecies * > speciesConversionMaserToNormal_
List of 'maser' particles' species, and their normal counterparts.
virtual BaseSpecies * copy() const =0
Creates a deep copy of the object from which it is called.
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725
void setId(unsigned long id)
Assigns a unique identifier to each object in the handler (container) which remains constant even aft...
Definition: BaseObject.cc:72
bool SubcriticalMaserBoundary::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

Definition at line 249 of file SubcriticalMaserBoundary.cc.

References ParticleHandler::addObject(), BaseParticle::copy(), getDistance(), BaseInteractable::getSpecies(), isClosestToRightBoundary(), isMaserParticle(), maserIsActivated_, BaseParticle::setSpecies(), shiftPosition(), and speciesConversionMaserToNormal_.

Referenced by checkBoundaryAfterParticlesMove().

250 {
251  // check if particle passed either of the boundary walls
252  if (isMaserParticle(p) && getDistance(p) < 0)
253  {
254  // Checks if the particle is closest to the right boundary.
255  // If so, and if the Maser is turned on, then create a 'real'
256  // equivalent and move it over to the outflow domain
258  {
259  BaseParticle* pCopy = p->copy();
260  pCopy->setSpecies(speciesConversionMaserToNormal_.find(p->getSpecies())->second);
261  pH.addObject(pCopy);
262 
263  // If the (original) particle has crossed a right boundary,
264  // then shift that particle periodically.
265  shiftPosition(p);
266  }
267  else if (!maserIsActivated_)
268  {
269  shiftPosition(p);
270  }
271  }
272  return false;
273 }
void addObject(BaseParticle *P) override
Adds a BaseParticle to the ParticleHandler.
const ParticleSpecies * getSpecies() const
Returns a pointer to the species of this BaseInteractable.
void setSpecies(const ParticleSpecies *species)
virtual BaseParticle * copy() const =0
Particle copy method. It calls to copy constructor of this Particle, useful for polymorfism.
bool maserIsActivated_
Flag whether or not the gap is created and particles transformed already.
bool isClosestToRightBoundary(const BaseParticle *const p) const
Returns whether the given particle is closer to the right boundary of the periodic part...
bool isMaserParticle(BaseParticle *p) const
Returns true if the particle is a Maser particle, and false otherwise.
std::map< const ParticleSpecies *, const ParticleSpecies * > speciesConversionMaserToNormal_
List of 'maser' particles' species, and their normal counterparts.
Mdouble getDistance(BaseParticle *p) const
Returns the distance of the wall to the particle.
void shiftPosition(BaseParticle *p) const
Shifts the particle to its 'periodic' position.
void SubcriticalMaserBoundary::checkBoundaryAfterParticlesMove ( ParticleHandler pH)
overridevirtual

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

Reimplemented from BaseBoundary.

Definition at line 275 of file SubcriticalMaserBoundary.cc.

References checkBoundaryAfterParticleMoved().

276 {
277  for (BaseParticle* p : pH)
278  {
280  }
281 }
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...
SubcriticalMaserBoundary * SubcriticalMaserBoundary::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

Implements BaseBoundary.

Definition at line 68 of file SubcriticalMaserBoundary.cc.

References SubcriticalMaserBoundary().

69 {
70  return new SubcriticalMaserBoundary(*this);
71 }
SubcriticalMaserBoundary()
MaserBoundary constructor.
BaseParticle * SubcriticalMaserBoundary::createGhostCopy ( BaseParticle p) const
private

Creates a copy of the input particle, that gets removed again in DPMBase::removeDuplicatePeriodicParticles.

Helper function for createPeriodicParticles. It makes a copy of the particle p, and labels the copy as a ghost particle. Same function as in PeriodicBoundary.

Parameters
[in]pParticle that needs to be copied
Returns
Copy of particle p, labeled as a ghost particle

Definition at line 224 of file SubcriticalMaserBoundary.cc.

References BaseParticle::copy(), BaseInteractable::copyInteractionsForPeriodicParticles(), BaseParticle::getPeriodicFromParticle(), and BaseParticle::setPeriodicFromParticle().

Referenced by createPeriodicParticle().

225 {
226  // Copy the particle and its interactions
227  BaseParticle* pGhost = p->copy();
229 
230  //Set the 'last' particle. If Particle is multiply shifted, get correct original particle
231  BaseParticle* last = p;
232  while (last->getPeriodicFromParticle() != nullptr)
233  {
234  last = last->getPeriodicFromParticle();
235  }
236  pGhost->setPeriodicFromParticle(last);
237  return pGhost;
238 }
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:438
BaseParticle * getPeriodicFromParticle() const
Returns the 'original' particle this one's a periodic copy of.
Definition: BaseParticle.h:338
virtual BaseParticle * copy() const =0
Particle copy method. It calls to copy constructor of this Particle, useful for polymorfism.
void copyInteractionsForPeriodicParticles(const BaseInteractable &p)
Copies interactions to this BaseInteractable whenever a periodic copy made.
void SubcriticalMaserBoundary::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.

Checks the distance of given particle to the closest of both walls, and creates a periodic copy of the particle if needed (i.e. if the particle is closer to the periodic wall than the radius of the largest particle in the system). Note that this is the same function as in PeriodicBoundary, but with the extra check to make sure that only maser particles on the right side of the domain are periodic particles, to prevent double forces on the right side of the periodic domain.

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

Definition at line 176 of file SubcriticalMaserBoundary.cc.

References ParticleHandler::addObject(), createGhostCopy(), getDistance(), ParticleHandler::getLargestParticle(), BaseParticle::getMaxInteractionRadius(), isClosestToRightBoundary(), isMaserParticle(), maserIsActivated_, and shiftPosition().

Referenced by createPeriodicParticles().

177 {
179  {
180  // check if particle is near the boundaries of the maser domain
181  const Mdouble periodicDistance = p->getMaxInteractionRadius() + 2.0* pH.getLargestParticle()->getMaxInteractionRadius();
182  if (getDistance(p) < periodicDistance)
183  {
184  //furthermore, if the particle is on the right it has to be copied over to the outflow domain
186  {
187  BaseParticle* pGhost = createGhostCopy(p);
188 
189  // shift to the periodic location
190  shiftPosition(pGhost);
191 
192  // add the periodic particle to the handler
193  pH.addObject(pGhost);
194  }
195  else if (!maserIsActivated_)
196  {
197  BaseParticle* pGhost = createGhostCopy(p);
198 
199  // shift to the periodic location
200  shiftPosition(pGhost);
201 
202  // add the periodic particle to the handler
203  pH.addObject(pGhost);
204  }
205  }
206  }
207 }
BaseParticle * getLargestParticle() const
Returns the pointer of the largest particle in the particle handler. When mercury is running in paral...
void addObject(BaseParticle *P) override
Adds a BaseParticle to the ParticleHandler.
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getMaxInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e.g., when dealing with wet particles)
Definition: BaseParticle.h:359
bool maserIsActivated_
Flag whether or not the gap is created and particles transformed already.
bool isClosestToRightBoundary(const BaseParticle *const p) const
Returns whether the given particle is closer to the right boundary of the periodic part...
bool isMaserParticle(BaseParticle *p) const
Returns true if the particle is a Maser particle, and false otherwise.
Mdouble getDistance(BaseParticle *p) const
Returns the distance of the wall to the particle.
void shiftPosition(BaseParticle *p) const
Shifts the particle to its 'periodic' position.
BaseParticle * createGhostCopy(BaseParticle *p) const
Creates a copy of the input particle, that gets removed again in DPMBase::removeDuplicatePeriodicPart...
void SubcriticalMaserBoundary::createPeriodicParticles ( ParticleHandler pH)
override

Definition at line 209 of file SubcriticalMaserBoundary.cc.

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

210 {
211  unsigned numberOfParticles = pH.getSize();
212  for (unsigned i = 0; i < numberOfParticles; i++)
213  {
215  }
216 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:613
void createPeriodicParticle(BaseParticle *p, ParticleHandler &pH) override
Creates periodic particles when the particle is a maser particle and is sufficiently close to one of ...
void SubcriticalMaserBoundary::deactivateMaser ( )

Stops copying particles (and act merely as a chute)

closing the maser: do exactly the opposite of activating the maser: close the gap by moving all particles, and assign the "normal" species to all maser particles again.

Definition at line 408 of file SubcriticalMaserBoundary.cc.

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

409 {
410  if (maserIsActivated_)
411  {
412  for (BaseParticle* const p : getHandler()->getDPMBase()->particleHandler)
413  {
414  if (getDistance(p) > 0)
415  {
417  }
418  }
419  maserIsActivated_ = false;
420  logger(INFO, "The Maser is no longer copying particles.");
421  }
422  else
423  {
424  logger(WARN, "Cannot close the maser if it is not active");
425  }
426 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
bool maserIsActivated_
Flag whether or not the gap is created and particles transformed already.
BoundaryHandler * getHandler() const
Returns the boundary's BoundaryHandler.
Mdouble getDistance(BaseParticle *p) const
Returns the distance of the wall to the particle.
void removeParticleFromMaser(BaseParticle *p)
Convert a maser particle into a 'normal' particle.
Mdouble SubcriticalMaserBoundary::getDistance ( BaseParticle p) const
inlineprivate

Returns the distance of the wall to the particle.

Parameters
[in]pPointer to the particle of which we want to know the distance to the wall to
Returns
Distance of the particle to the boundary: positive means the particle is inside the periodic part of the boundary, negative means it's outside.

Definition at line 204 of file SubcriticalMaserBoundary.h.

References distanceLeft_, distanceRight_, Vec3D::dot(), BaseInteractable::getPosition(), and normal_.

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

205  {
206  const Mdouble distance = Vec3D::dot(p->getPosition(), normal_);
207  return std::min(distance - distanceLeft_, distanceRight_ - distance);
208  }
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
double Mdouble
Definition: GeneralDefine.h:34
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:76
Mdouble distanceRight_
position of right boundary wall, s.t. normal*x=position_right
Vec3D normal_
Normal unit vector of both maser walls. Points in the flowing direction.
Mdouble distanceLeft_
position of left boundary wall, s.t. normal*x=position_left
Mdouble SubcriticalMaserBoundary::getDistanceLeft ( ) const

Definition at line 428 of file SubcriticalMaserBoundary.cc.

References distanceLeft_.

429 {
430  return distanceLeft_;
431 }
Mdouble distanceLeft_
position of left boundary wall, s.t. normal*x=position_left
Mdouble SubcriticalMaserBoundary::getDistanceRight ( ) const

Definition at line 433 of file SubcriticalMaserBoundary.cc.

References distanceRight_.

434 {
435  return distanceRight_;
436 }
Mdouble distanceRight_
position of right boundary wall, s.t. normal*x=position_right
std::string SubcriticalMaserBoundary::getName ( ) const
overridevirtual

Returns the name of the object.

Returns the name of the object class

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

Implements BaseObject.

Definition at line 141 of file SubcriticalMaserBoundary.cc.

142 {
143  return "SubcriticalMaserBoundary";
144 }
bool SubcriticalMaserBoundary::isClosestToRightBoundary ( const BaseParticle *const  p) const
inlineprivate

Returns whether the given particle is closer to the right boundary of the periodic part.

Parameters
[in]pParticle for which we would like to know whether it is closest to the right boundary
Returns
True if p is closer to the right boundary, false otherwise

Definition at line 192 of file SubcriticalMaserBoundary.h.

References distanceLeft_, distanceRight_, Vec3D::dot(), BaseInteractable::getPosition(), and normal_.

Referenced by checkBoundaryAfterParticleMoved(), createPeriodicParticle(), and shiftPosition().

193  {
194  const Mdouble distance = Vec3D::dot(p->getPosition(), normal_);
195  return (distanceRight_ - distance < distance - distanceLeft_);
196  }
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
double Mdouble
Definition: GeneralDefine.h:34
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:76
Mdouble distanceRight_
position of right boundary wall, s.t. normal*x=position_right
Vec3D normal_
Normal unit vector of both maser walls. Points in the flowing direction.
Mdouble distanceLeft_
position of left boundary wall, s.t. normal*x=position_left
bool SubcriticalMaserBoundary::isMaserParticle ( BaseParticle p) const

Returns true if the particle is a Maser particle, and false otherwise.

One checks if the particle is in the Maser, by checking whether its species is found in the list of maser particle species

Definition at line 351 of file SubcriticalMaserBoundary.cc.

References BaseInteractable::getSpecies(), and speciesConversionMaserToNormal_.

Referenced by checkBoundaryAfterParticleMoved(), and createPeriodicParticle().

352 {
353  // Check if the particle is in the Maser, by checking whether its
354  // species is found in the list of maser particle species
355  auto positionMaserSpeciesInMap = speciesConversionMaserToNormal_.find(p->getSpecies());
356  return (positionMaserSpeciesInMap != speciesConversionMaserToNormal_.end()); //Test if it is a maser particle
357 }
const ParticleSpecies * getSpecies() const
Returns a pointer to the species of this BaseInteractable.
std::map< const ParticleSpecies *, const ParticleSpecies * > speciesConversionMaserToNormal_
List of 'maser' particles' species, and their normal counterparts.
bool SubcriticalMaserBoundary::isNormalParticle ( BaseParticle p) const

Returns true if the particle is a Normal particle, and false otherwise.

One checks if the particle is a normal particle, by checking whether the species changes when we do speciesConversionNormalToMaser_().

Definition at line 363 of file SubcriticalMaserBoundary.cc.

References BaseInteractable::getSpecies(), and speciesConversionNormalToMaser_.

364 {
365  auto toFindOutflowSpecies = speciesConversionNormalToMaser_.find(p->getSpecies());
366  return (toFindOutflowSpecies != speciesConversionNormalToMaser_.end());
367 }
const ParticleSpecies * getSpecies() const
Returns a pointer to the species of this BaseInteractable.
std::map< const ParticleSpecies *, const ParticleSpecies * > speciesConversionNormalToMaser_
List of 'normal' particles' species, and their maser counterparts.
void SubcriticalMaserBoundary::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

Implements BaseBoundary.

Definition at line 94 of file SubcriticalMaserBoundary.cc.

References DEBUG, distanceLeft_, distanceRight_, BaseHandler< T >::getDPMBase(), BaseBoundary::getHandler(), BaseHandler< T >::getObject(), constants::i, logger, maserIsActivated_, normal_, BaseBoundary::read(), shift_, speciesConversionMaserToNormal_, speciesConversionNormalToMaser_, and DPMBase::speciesHandler.

95 {
97  std::string dummy;
98  is >> dummy >> normal_
99  >> dummy >> distanceLeft_
100  >> dummy >> distanceRight_
101  >> dummy >> shift_
102  >> dummy >> maserIsActivated_;
103  unsigned int n;
104  is >> dummy >> n;
105  const SpeciesHandler& speciesHandler = getHandler()->getDPMBase()->speciesHandler;
106  for (unsigned int i = 0; i < n; ++i)
107  {
108  unsigned int key;
109  unsigned int value;
110  is >> dummy >> key >> dummy >> value;
111  speciesConversionNormalToMaser_[speciesHandler.getObject(key)] = speciesHandler.getObject(value);
112  speciesConversionMaserToNormal_[speciesHandler.getObject(value)] = speciesHandler.getObject(key);
113  }
114  logger(DEBUG, "Finished reading SubcriticalMaserBoundary. \nNormal: % \nDistanceLeft: % \nDistanceRight: % "
115  ": % \nMaserIsActivated: %", normal_, distanceLeft_, distanceRight_, maserIsActivated_);
116 }
Container to store all ParticleSpecies.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Vec3D shift_
Direction in which particles are to be shifted when they cross the boundary.
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
void read(std::istream &is) override=0
Reads the object's id_ from given istream NB: purely virtual function, overriding the version of Base...
Definition: BaseBoundary.cc:61
bool maserIsActivated_
Flag whether or not the gap is created and particles transformed already.
Mdouble distanceRight_
position of right boundary wall, s.t. normal*x=position_right
Vec3D normal_
Normal unit vector of both maser walls. Points in the flowing direction.
std::map< const ParticleSpecies *, const ParticleSpecies * > speciesConversionNormalToMaser_
List of 'normal' particles' species, and their maser counterparts.
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:613
BoundaryHandler * getHandler() const
Returns the boundary's BoundaryHandler.
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1319
std::map< const ParticleSpecies *, const ParticleSpecies * > speciesConversionMaserToNormal_
List of 'maser' particles' species, and their normal counterparts.
Mdouble distanceLeft_
position of left boundary wall, s.t. normal*x=position_left
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725
void SubcriticalMaserBoundary::removeParticleFromMaser ( BaseParticle p)

Convert a maser particle into a 'normal' particle.

Definition at line 341 of file SubcriticalMaserBoundary.cc.

References BaseInteractable::getSpecies(), BaseParticle::setSpecies(), and speciesConversionMaserToNormal_.

Referenced by deactivateMaser().

342 {
343  auto conversion = speciesConversionMaserToNormal_.find(p->getSpecies());
344  p->setSpecies(conversion->second);
345 }
const ParticleSpecies * getSpecies() const
Returns a pointer to the species of this BaseInteractable.
void setSpecies(const ParticleSpecies *species)
std::map< const ParticleSpecies *, const ParticleSpecies * > speciesConversionMaserToNormal_
List of 'maser' particles' species, and their normal counterparts.
void SubcriticalMaserBoundary::set ( Vec3D  normal,
Mdouble  distanceLeft,
Mdouble  distanceRight 
)

Sets all boundary properties at once and adds particles of the handler to the maser.

Set all the properties of the boundary at once.

Parameters
[in]normalNormal unit vector of the (parallel) boundary walls
[in]distanceLeftThe distance of the left wall to the origin
[in]distanceRightThe distance of the right wall to the origin

Definition at line 79 of file SubcriticalMaserBoundary.cc.

References distanceLeft_, distanceRight_, Vec3D::dot(), maserIsActivated_, normal_, and shift_.

80 {
81  // factor is used to set normal to unit length
82  Mdouble scaleFactor_ = 1. / std::sqrt(Vec3D::dot(normal, normal));
83  normal_ = normal * scaleFactor_;
84  distanceLeft_ = distanceLeft * scaleFactor_;
85  distanceRight_ = distanceRight * scaleFactor_;
87  maserIsActivated_ = false;
88 }
double Mdouble
Definition: GeneralDefine.h:34
Vec3D shift_
Direction in which particles are to be shifted when they cross the boundary.
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:76
bool maserIsActivated_
Flag whether or not the gap is created and particles transformed already.
Mdouble distanceRight_
position of right boundary wall, s.t. normal*x=position_right
Vec3D normal_
Normal unit vector of both maser walls. Points in the flowing direction.
Mdouble distanceLeft_
position of left boundary wall, s.t. normal*x=position_left
void SubcriticalMaserBoundary::shiftPosition ( BaseParticle p) const
private

Shifts the particle to its 'periodic' position.

Shifts the particle (using the closestToLeftBoundary_ value)

Parameters
[in]pA pointer to the particle which will be shifted.

Definition at line 150 of file SubcriticalMaserBoundary.cc.

References isClosestToRightBoundary(), BaseInteractable::move(), and shift_.

Referenced by checkBoundaryAfterParticleMoved(), and createPeriodicParticle().

151 {
153  {
154  p->move(-shift_);
155  }
156  else // if closest to right boundary
157  {
158  p->move(shift_);
159  }
160 }
Vec3D shift_
Direction in which particles are to be shifted when they cross the boundary.
bool isClosestToRightBoundary(const BaseParticle *const p) const
Returns whether the given particle is closer to the right boundary of the periodic part...
virtual void move(const Vec3D &move)
Moves this BaseInteractable by adding an amount to the position.
void SubcriticalMaserBoundary::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

Implements BaseBoundary.

Definition at line 122 of file SubcriticalMaserBoundary.cc.

References distanceLeft_, distanceRight_, maserIsActivated_, normal_, shift_, speciesConversionMaserToNormal_, speciesConversionNormalToMaser_, and BaseBoundary::write().

123 {
125  os << " normal " << normal_
126  << " distanceLeft " << distanceLeft_
127  << " distanceRight " << distanceRight_
128  << " shift " << shift_
129  << " maserIsActivated " << maserIsActivated_
130  << " numberOfMaserSpecies " << speciesConversionMaserToNormal_.size();
131  for (auto p : speciesConversionNormalToMaser_)
132  {
133  os << " outflowSpeciesIndex " << p.first->getIndex() << " maserSpeciesIndex " << p.second->getIndex();
134  }
135 }
Vec3D shift_
Direction in which particles are to be shifted when they cross the boundary.
bool maserIsActivated_
Flag whether or not the gap is created and particles transformed already.
Mdouble distanceRight_
position of right boundary wall, s.t. normal*x=position_right
Vec3D normal_
Normal unit vector of both maser walls. Points in the flowing direction.
std::map< const ParticleSpecies *, const ParticleSpecies * > speciesConversionNormalToMaser_
List of 'normal' particles' species, and their maser counterparts.
void write(std::ostream &os) const override=0
Adds object's id_ to given ostream NB: purely virtual function, overriding the version of BaseObject...
Definition: BaseBoundary.cc:70
std::map< const ParticleSpecies *, const ParticleSpecies * > speciesConversionMaserToNormal_
List of 'maser' particles' species, and their normal counterparts.
Mdouble distanceLeft_
position of left boundary wall, s.t. normal*x=position_left

Member Data Documentation

Mdouble SubcriticalMaserBoundary::distanceLeft_
private

position of left boundary wall, s.t. normal*x=position_left

Definition at line 218 of file SubcriticalMaserBoundary.h.

Referenced by getDistance(), getDistanceLeft(), isClosestToRightBoundary(), read(), set(), SubcriticalMaserBoundary(), and write().

Mdouble SubcriticalMaserBoundary::distanceRight_
private

position of right boundary wall, s.t. normal*x=position_right

Definition at line 223 of file SubcriticalMaserBoundary.h.

Referenced by getDistance(), getDistanceRight(), isClosestToRightBoundary(), read(), set(), SubcriticalMaserBoundary(), and write().

bool SubcriticalMaserBoundary::maserIsActivated_
private

Flag whether or not the gap is created and particles transformed already.

Definition at line 245 of file SubcriticalMaserBoundary.h.

Referenced by activateMaser(), checkBoundaryAfterParticleMoved(), createPeriodicParticle(), deactivateMaser(), read(), set(), SubcriticalMaserBoundary(), and write().

Vec3D SubcriticalMaserBoundary::normal_
private

Normal unit vector of both maser walls. Points in the flowing direction.

Definition at line 213 of file SubcriticalMaserBoundary.h.

Referenced by getDistance(), isClosestToRightBoundary(), read(), set(), SubcriticalMaserBoundary(), and write().

Vec3D SubcriticalMaserBoundary::shift_
private

Direction in which particles are to be shifted when they cross the boundary.

I.e., the vector pointing from a point the left boundary wall to the equivalent point on the right one.

Definition at line 230 of file SubcriticalMaserBoundary.h.

Referenced by read(), set(), shiftPosition(), SubcriticalMaserBoundary(), and write().

std::map<const ParticleSpecies*, const ParticleSpecies*> SubcriticalMaserBoundary::speciesConversionMaserToNormal_
private

List of 'maser' particles' species, and their normal counterparts.

Definition at line 240 of file SubcriticalMaserBoundary.h.

Referenced by addParticleToMaser(), checkBoundaryAfterParticleMoved(), isMaserParticle(), read(), removeParticleFromMaser(), and write().

std::map<const ParticleSpecies*, const ParticleSpecies*> SubcriticalMaserBoundary::speciesConversionNormalToMaser_
private

List of 'normal' particles' species, and their maser counterparts.

Definition at line 235 of file SubcriticalMaserBoundary.h.

Referenced by addParticleToMaser(), isNormalParticle(), read(), and write().


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