ConstantMassFlowMaserBoundary Class Reference

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

#include <ConstantMassFlowMaserBoundary.h>

+ Inheritance diagram for ConstantMassFlowMaserBoundary:

Public Member Functions

 ConstantMassFlowMaserBoundary ()
 MaserBoundary constructor. More...
 
 ConstantMassFlowMaserBoundary (const PeriodicBoundary &periodicBoundary)
 Maserboundary constructor that takes a periodic boundary, and converts it to a maser boundary. More...
 
ConstantMassFlowMaserBoundarycopy () const override
 Creates a copy of this maser on the heap. More...
 
void set (Vec3D normal, Vec3D planewiseShift, Mdouble distanceLeft, Mdouble distanceRight)
 Sets all boundary properties at once and adds particles of the handler to the maser. This deactivates the Maser. More...
 
void set (Vec3D normal, Mdouble distanceLeft, Mdouble distanceRight)
 Sets the Maser's normal and positions, and sets the planewise shift to zero. This deactivates the Maser. More...
 
void setPlanewiseShift (Vec3D planewiseShift)
 Sets a planewise direction to the shift. Doesn't change the normal or the positions. More...
 
void setShift (Vec3D shift)
 Sets the shift of the Maser. Usually don't use this directly, use set() or setPlanewiseShift() instead. 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)
 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 closeMaser ()
 Stops copying particles (and act merely as a chute) More...
 
bool isActivated () const
 Returns whether the Maser is activated or not. More...
 
void turnOnCopying ()
 Start copying particles. More...
 
void turnOffCopying ()
 Stop copying particles. More...
 
bool isCopying () const
 Returns whether the Maser is copying particles or not. More...
 
Mdouble getDistanceLeft () const
 
Mdouble getDistanceRight () const
 
Mdouble getGapSize () 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...
 
Mdouble gapSize_
 distance between the right side of the periodic domain and the start of the outflow domain. 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...
 
bool maserIsCopying_
 Flag whether or not the Maser is copying particles. 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, with a gap inbetween. 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 as if there were no gap. However, the outflow domain has no influence on the periodic domain. When an outflow particle tries to enter the gap between the periodic domain and the outflow domain, it gets removed.

There are two distinct properties of the state of the Maser. ‘Activated’ or ‘closed’ refer to whether the particles within the Maser have been set to the Maser species and whether they have been moved by the gapSize. Particles will be affected by the Maser (i.e. moved periodically) iff the Maser is activated. On the other hand, ‘copying’ refers to whether new particles are being produced by the Maser. Thus, a Maser that is activated but not copying behaves just as a periodic boundary.

By default, activateMaser() also turns on copying. And when a Maser is closed, the value of isCopying() is irrelevant, although it is set to false for housekeeping.

Todo:

Add functionality which allows for opening the maser boundary after a certain time, being a normal periodic boundary until then

Consider writing a destructor that closes the gap again

Consider splitting it in 2 DPMBase instances, one for the periodic domain and one for the outflow domain

Consider re-using the PeriodicBoundary by adding it as a data member

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 ConstantMassFlowMaserBoundary, please look at the output of ConstantMassFlowMaserSelfTest.

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.

Constructor & Destructor Documentation

◆ ConstantMassFlowMaserBoundary() [1/2]

ConstantMassFlowMaserBoundary::ConstantMassFlowMaserBoundary ( )

MaserBoundary constructor.

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

13 {
14 #ifdef MERCURYDPM_USE_MPI
15  logger(WARN,"Make sure the whole maser boundary is on one processor when using parallel code");
16 #endif
17  distanceLeft_ = std::numeric_limits<double>::quiet_NaN();
18  distanceRight_ = std::numeric_limits<double>::quiet_NaN();
19  gapSize_ = std::numeric_limits<double>::quiet_NaN();
20  maserIsActivated_ = false;
21 }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ WARN
Mdouble distanceLeft_
position of left boundary wall, s.t. normal*x=position_left
Definition: ConstantMassFlowMaserBoundary.h:243
Mdouble gapSize_
distance between the right side of the periodic domain and the start of the outflow domain.
Definition: ConstantMassFlowMaserBoundary.h:263
Mdouble distanceRight_
position of right boundary wall, s.t. normal*x=position_right
Definition: ConstantMassFlowMaserBoundary.h:248
bool maserIsActivated_
Flag whether or not the gap is created and particles transformed already.
Definition: ConstantMassFlowMaserBoundary.h:287

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

Referenced by copy().

◆ ConstantMassFlowMaserBoundary() [2/2]

ConstantMassFlowMaserBoundary::ConstantMassFlowMaserBoundary ( 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.
28  : BaseBoundary(
29  periodicBoundary)
30 {
31  logger(INFO, "Constructor ConstantMassFlowMaserBoundary(const PeriodicBoundary&) started\n", Flusher::NO_FLUSH);
32  distanceLeft_ = periodicBoundary.getDistanceLeft();
33  distanceRight_ = periodicBoundary.getDistanceRight();
34  normal_ = periodicBoundary.getNormal();
35  shift_ = periodicBoundary.getShift();
36  gapSize_ = std::numeric_limits<double>::quiet_NaN();
37  maserIsActivated_ = false;
38 
39  logger(INFO, "going to activate the maser");
40  //assume that the maser should be activated immediately when it gets constructed from a periodic boundary
41  activateMaser();
42 }
@ INFO
BaseBoundary()
default constructor.
Definition: BaseBoundary.cc:11
Vec3D shift_
Direction in which particles are to be shifted when they cross the boundary.
Definition: ConstantMassFlowMaserBoundary.h:272
Vec3D normal_
Normal unit vector of both maser walls. Points in the flowing direction.
Definition: ConstantMassFlowMaserBoundary.h:238
void activateMaser()
Opens the gap, and transforms particles to maser particles. Also calls turnOnCopying().
Definition: ConstantMassFlowMaserBoundary.cc:403
Vec3D getShift() const
Returns the vector going from the left to the right side of the periodic boundary.
Definition: PeriodicBoundary.cc:138
Mdouble getDistanceRight() const
Returns the distance of the right wall to the origin, in normal direction.
Definition: PeriodicBoundary.cc:130
Mdouble getDistanceLeft() const
Returns the distance of the left wall to the origin, in normal direction.
Definition: PeriodicBoundary.cc:122
Vec3D getNormal() const
returns the vector normal to the periodic boundary
Definition: PeriodicBoundary.cc:114

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

Member Function Documentation

◆ actionsBeforeTimeLoop()

void ConstantMassFlowMaserBoundary::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.

391 {
392  activateMaser();
393 }

References activateMaser().

◆ activateMaser()

void ConstantMassFlowMaserBoundary::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.

Todo:
JMFT: Would it be helpful to be able to set a custom gapSize ?
404 {
405  if (!maserIsActivated_)
406  {
407  logger(INFO, "Going to add particles to the maser and shift the periodic maser boundaries\n",
411  logger(INFO, "just before particle loop");
412  for (BaseParticle* const p: pH)
413  {
414  if (getDistance(p) > 0)
415  {
417  }
418  }
419 
420 
423  maserIsActivated_ = true;
424 
425  turnOnCopying();
426 
427  logger(INFO, "The Maser has been activated, and is now copying particles.");
428  }
429  else
430  {
431  logger(WARN, "Cannot activate the maser boundary twice!");
432  }
433 }
float * p
Definition: Tutorial_Map_using.cpp:9
BoundaryHandler * getHandler() const
Returns the boundary's BoundaryHandler.
Definition: BaseBoundary.cc:122
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:733
Definition: BaseParticle.h:33
Mdouble getRadius() const
Returns the particle's radius.
Definition: BaseParticle.h:331
Mdouble getDistance(BaseParticle *p) const
Returns the distance of the wall to the particle.
Definition: ConstantMassFlowMaserBoundary.h:229
void addParticleToMaser(BaseParticle *p)
Converts a 'normal' particle into a maser particle.
Definition: ConstantMassFlowMaserBoundary.cc:306
void turnOnCopying()
Start copying particles.
Definition: ConstantMassFlowMaserBoundary.cc:467
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
BaseParticle * getLargestParticleLocal() const
Gets a pointer to the largest BaseParticle (by interactionRadius) in the ParticleHandler of the local...
Definition: ParticleHandler.cc:520

References addParticleToMaser(), distanceLeft_, distanceRight_, gapSize_, getDistance(), BaseHandler< T >::getDPMBase(), BaseBoundary::getHandler(), ParticleHandler::getLargestParticleLocal(), BaseParticle::getRadius(), INFO, logger, maserIsActivated_, NO_FLUSH, p, DPMBase::particleHandler, turnOnCopying(), and WARN.

Referenced by actionsBeforeTimeLoop(), and ConstantMassFlowMaserBoundary().

◆ addParticleToMaser()

void ConstantMassFlowMaserBoundary::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.
307 {
308  // check if particle species already known by the maser
309  auto conversion = speciesConversionNormalToMaser_.find(p->getSpecies());
310  if (conversion != speciesConversionNormalToMaser_.end())
311  {
312  //species known and flagged (i.e. 'converted')
313  logger(VERBOSE, "[ConstantMassFlowMaserBoundary::addParticleToMaser()] Species conversion already present");
314  p->setSpecies(conversion->second);
315  }
316  else
317  {
318  SpeciesHandler& speciesHandler = (getHandler()->getDPMBase()->speciesHandler);
319  // species is not yet known by the maser, it has to be added to both maps
320  ParticleSpecies* newSpecies = speciesHandler.copyAndAddObject(*(p->getSpecies()));
322  std::pair<const ParticleSpecies*, const ParticleSpecies*>(p->getSpecies(), newSpecies));
324  std::pair<const ParticleSpecies*, const ParticleSpecies*>(newSpecies, p->getSpecies()));
325  logger(INFO, "[ConstantMassFlowMaserBoundary::addParticleToMaser()] New species conversion created\n",
327  logger(INFO, "Original species ID: %, new species ID: %", p->getSpecies()->getId(), newSpecies->getId());
328 
329  //Copy over the mixed species. The delete is necessary here since it is overwritten with a copy of the old mixed
330  //species, and otherwise the properties are not copied over correctly.
331  //
332  //setId and setIndex refer to the two different species which are present in this mixed species.
333  //The highest species-index should appear first andis therefore the ID, while the second species-index is the
334  //"index" of the mixed species.
335  for (const BaseSpecies* const s: speciesHandler)
336  {
337  if (s->getId() != newSpecies->getId() && s->getId() != p->getSpecies()->getId())
338  {
339  BaseSpecies* newMixed = speciesHandler.getMixedObject(s->getId(), newSpecies->getId());
340  const BaseSpecies* const oldMixed = speciesHandler.getMixedObject(s->getId(), p->getSpecies()->getId());
341  oldMixed->copyInto(newMixed);
342  newMixed->setId(newSpecies->getId());
343  newMixed->setIndex(s->getId());
344  logger(DEBUG, "mixed species of % and % is now \n %, should be \n %", s->getId(), newSpecies->getId(),
345  *newMixed, *oldMixed);
346  }
347  }
348 
349  // now the species IS added, so flag (convert) it!
350  p->setSpecies(newSpecies);
351  }
352  p->move(-normal_ * gapSize_);
353 }
@ DEBUG
@ VERBOSE
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:360
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.h:104
void setIndex(unsigned int index)
Allows one to assign an index to an object in the handler/container.
Definition: BaseObject.cc:42
void setId(unsigned long id)
Assigns a unique identifier to each object in the handler (container) which remains constant even aft...
Definition: BaseObject.cc:50
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:29
virtual void copyInto(BaseSpecies *s) const =0
std::map< const ParticleSpecies *, const ParticleSpecies * > speciesConversionMaserToNormal_
List of 'maser' particles' species, and their normal counterparts.
Definition: ConstantMassFlowMaserBoundary.h:282
std::map< const ParticleSpecies *, const ParticleSpecies * > speciesConversionNormalToMaser_
List of 'normal' particles' species, and their maser counterparts.
Definition: ConstantMassFlowMaserBoundary.h:277
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1433
Definition: ParticleSpecies.h:16
Container to store all ParticleSpecies.
Definition: SpeciesHandler.h:15
RealScalar s
Definition: level1_cplx_impl.h:130

References BaseHandler< T >::copyAndAddObject(), BaseSpecies::copyInto(), DEBUG, gapSize_, BaseHandler< T >::getDPMBase(), BaseBoundary::getHandler(), BaseObject::getId(), SpeciesHandler::getMixedObject(), INFO, logger, NO_FLUSH, normal_, p, s, BaseObject::setId(), BaseObject::setIndex(), speciesConversionMaserToNormal_, speciesConversionNormalToMaser_, DPMBase::speciesHandler, and VERBOSE.

Referenced by activateMaser().

◆ checkBoundaryAfterParticleMoved()

bool ConstantMassFlowMaserBoundary::checkBoundaryAfterParticleMoved ( BaseParticle p,
ParticleHandler pH 
)

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
253 {
254  // check if particle passed either of the boundary walls
255  if (isMaserParticle(p) && getDistance(p) < 0)
256  {
257  // Checks if the particle is closest to the right boundary.
258  // If so, and if the Maser is turned on, then create a 'real'
259  // equivalent and move it over to the outflow domain
261  {
262  BaseParticle* pCopy = p->copy();
263  pCopy->setSpecies(speciesConversionMaserToNormal_.find(p->getSpecies())->second);
264  pCopy->move(gapSize_ * normal_);
265  pH.addObject(pCopy);
266  }
267 
268  // If the (original) particle has crossed a boundary wall (be it left or right),
269  // then shift that particle periodically.
270  shiftPosition(p);
271  }
272  else //remove normal particles trying to enter the gap between the maser and the outflow domain
273  {
274  const Mdouble distance = Vec3D::dot(p->getPosition(), normal_);
275  if (distance < gapSize_ + distanceRight_ && isNormalParticle(p))
276  {
277  pH.removeObject(p->getIndex());
278  return true;
279  }
280  }
281  return false;
282 }
virtual void move(const Vec3D &move)
Moves this BaseInteractable by adding an amount to the position.
Definition: BaseInteractable.cc:193
virtual void setSpecies(const ParticleSpecies *species)
Definition: BaseParticle.cc:798
bool isClosestToRightBoundary(const BaseParticle *const p) const
Returns whether the given particle is closer to the right boundary of the periodic part.
Definition: ConstantMassFlowMaserBoundary.h:217
void shiftPosition(BaseParticle *p) const
Shifts the particle to its 'periodic' position.
Definition: ConstantMassFlowMaserBoundary.cc:157
bool isNormalParticle(BaseParticle *p) const
Returns true if the particle is a Normal particle, and false otherwise.
Definition: ConstantMassFlowMaserBoundary.cc:381
bool isMaserParticle(BaseParticle *p) const
Returns true if the particle is a Maser particle, and false otherwise.
Definition: ConstantMassFlowMaserBoundary.cc:369
bool isCopying() const
Returns whether the Maser is copying particles or not.
Definition: ConstantMassFlowMaserBoundary.cc:478
void addObject(BaseParticle *P) override
Adds a BaseParticle to the ParticleHandler.
Definition: ParticleHandler.cc:150
void removeObject(unsigned int index) override
Removes a BaseParticle from the ParticleHandler.
Definition: ParticleHandler.cc:388
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:56

References ParticleHandler::addObject(), distanceRight_, Vec3D::dot(), gapSize_, getDistance(), isClosestToRightBoundary(), isCopying(), isMaserParticle(), isNormalParticle(), BaseInteractable::move(), normal_, p, ParticleHandler::removeObject(), BaseParticle::setSpecies(), shiftPosition(), and speciesConversionMaserToNormal_.

Referenced by checkBoundaryAfterParticlesMove().

◆ checkBoundaryAfterParticlesMove()

void ConstantMassFlowMaserBoundary::checkBoundaryAfterParticlesMove ( ParticleHandler pH)
overridevirtual

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

Reimplemented from BaseBoundary.

285 {
286  for (auto p = pH.begin(); p != pH.end(); ++p)
287  {
288  //If the particle has interacted with the boundary, change the iterator
290  {
291  p--;
292  }
293  }
294 }
const std::vector< T * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
Definition: BaseHandler.h:698
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:712
bool checkBoundaryAfterParticleMoved(BaseParticle *p, ParticleHandler &pH)
Shifts the particle to its 'periodic' position if it is a maser particle and has crossed either of th...
Definition: ConstantMassFlowMaserBoundary.cc:252

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

◆ closeMaser()

void ConstantMassFlowMaserBoundary::closeMaser ( )

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.

438 {
439  if (maserIsActivated_)
440  {
441  for (BaseParticle* const p : getHandler()->getDPMBase()->particleHandler)
442  {
443  if (getDistance(p) > 0)
444  {
446  }
447  }
450  maserIsActivated_ = false;
451 
452  turnOffCopying();
453 
454  logger(INFO, "The Maser has been deactivated.");
455  }
456  else
457  {
458  logger(WARN, "Cannot close the maser if it is not active");
459  }
460 }
void turnOffCopying()
Stop copying particles.
Definition: ConstantMassFlowMaserBoundary.cc:472
void removeParticleFromMaser(BaseParticle *p)
Convert a maser particle into a 'normal' particle.
Definition: ConstantMassFlowMaserBoundary.cc:355

References distanceLeft_, distanceRight_, gapSize_, getDistance(), BaseBoundary::getHandler(), INFO, logger, maserIsActivated_, p, removeParticleFromMaser(), turnOffCopying(), and WARN.

◆ copy()

ConstantMassFlowMaserBoundary * ConstantMassFlowMaserBoundary::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.

50 {
51  return new ConstantMassFlowMaserBoundary(*this);
52 }
ConstantMassFlowMaserBoundary()
MaserBoundary constructor.
Definition: ConstantMassFlowMaserBoundary.cc:12

References ConstantMassFlowMaserBoundary().

◆ createGhostCopy()

BaseParticle * ConstantMassFlowMaserBoundary::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.

Parameters
[in]pParticle that needs to be copied
Returns
Copy of particle p, labeled as a ghost particle
228 {
229  // Copy the particle and its interactions
230  BaseParticle* pGhost = p->copy();
232 
233  //Set the 'last' particle. If Particle is multiply shifted, get correct original particle
234  BaseParticle* last = p;
235  while (last->getPeriodicFromParticle() != nullptr)
236  {
237  last = last->getPeriodicFromParticle();
238  }
239  pGhost->setPeriodicFromParticle(last);
240  return pGhost;
241 }
void copyInteractionsForPeriodicParticles(const BaseInteractable &p)
Copies interactions to this BaseInteractable whenever a periodic copy made.
Definition: BaseInteractable.cc:364
void setPeriodicFromParticle(BaseParticle *p)
Assigns the pointer to the 'original' particle this one's a periodic copy of (used in periodic bounda...
Definition: BaseParticle.h:416
static constexpr const last_t last
Definition: IndexedViewHelper.h:48

References BaseInteractable::copyInteractionsForPeriodicParticles(), Eigen::placeholders::last, p, and BaseParticle::setPeriodicFromParticle().

Referenced by createPeriodicParticle().

◆ createPeriodicParticle()

void ConstantMassFlowMaserBoundary::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 are periodic particles

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
183 {
184  if (isMaserParticle(p))
185  {
186  // check if particle is near the boundaries of the maser domain
187  if (getDistance(p) < p->getMaxInteractionRadius() + pH.getLargestParticleLocal()->getMaxInteractionRadius())
188  {
189  BaseParticle* pGhost = createGhostCopy(p);
190 
191  // shift to the periodic location
192  shiftPosition(pGhost);
193 
194  // add the periodic particle to the handler
195  pH.addObject(pGhost);
196 
197  //furthermore, if the particle is on the right it has to be copied over to the outflow domain
199  {
200  // Copy the particle and its interactions if it is a maser particle
201  BaseParticle* pGhostOut = createGhostCopy(p);
202 
203  // shift to the outflow location
204  pGhostOut->move(gapSize_ * normal_);
205  // add the periodic particle to the handler
206  pH.addObject(pGhostOut);
207  }
208  }
209  }
210 }
Mdouble getMaxInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e....
Definition: BaseParticle.h:345
BaseParticle * createGhostCopy(BaseParticle *p) const
Creates a copy of the input particle, that gets removed again in DPMBase::removeDuplicatePeriodicPart...
Definition: ConstantMassFlowMaserBoundary.cc:227

References ParticleHandler::addObject(), createGhostCopy(), gapSize_, getDistance(), ParticleHandler::getLargestParticleLocal(), BaseParticle::getMaxInteractionRadius(), isClosestToRightBoundary(), isMaserParticle(), maserIsActivated_, BaseInteractable::move(), normal_, p, and shiftPosition().

Referenced by createPeriodicParticles().

◆ createPeriodicParticles()

void ConstantMassFlowMaserBoundary::createPeriodicParticles ( ParticleHandler pH)
override
213 {
214  unsigned numberOfParticles = pH.getSize();
215  for (unsigned i = 0; i < numberOfParticles; i++)
216  {
218  }
219 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:663
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:621
void createPeriodicParticle(BaseParticle *p, ParticleHandler &pH) override
Creates periodic particles when the particle is a maser particle and is sufficiently close to one of ...
Definition: ConstantMassFlowMaserBoundary.cc:182

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

◆ getDistance()

Mdouble ConstantMassFlowMaserBoundary::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.
230  {
231  const Mdouble distance = Vec3D::dot(p->getPosition(), normal_);
232  return std::min(distance - distanceLeft_, distanceRight_ - distance);
233  }
#define min(a, b)
Definition: datatypes.h:22

References distanceLeft_, distanceRight_, Vec3D::dot(), min, normal_, and p.

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

◆ getDistanceLeft()

Mdouble ConstantMassFlowMaserBoundary::getDistanceLeft ( ) const
487 {
488  return distanceLeft_;
489 }

References distanceLeft_.

◆ getDistanceRight()

Mdouble ConstantMassFlowMaserBoundary::getDistanceRight ( ) const
492 {
493  return distanceRight_;
494 }

References distanceRight_.

◆ getGapSize()

Mdouble ConstantMassFlowMaserBoundary::getGapSize ( ) const
497 {
498  return gapSize_;
499 }

References gapSize_.

◆ getName()

std::string ConstantMassFlowMaserBoundary::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.

149 {
150  return "ConstantMassFlowMaserBoundary";
151 }

◆ isActivated()

bool ConstantMassFlowMaserBoundary::isActivated ( ) const

Returns whether the Maser is activated or not.

463 {
464  return maserIsActivated_;
465 }

References maserIsActivated_.

Referenced by isCopying().

◆ isClosestToRightBoundary()

bool ConstantMassFlowMaserBoundary::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
218  {
219  const Mdouble distance = Vec3D::dot(p->getPosition(), normal_);
220  return (distanceRight_ - distance < distance - distanceLeft_);
221  }

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

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

◆ isCopying()

bool ConstantMassFlowMaserBoundary::isCopying ( ) const

Returns whether the Maser is copying particles or not.

479 {
480  if (!isActivated())
481  logger(WARN, "The Maser is closed, so isCopying() is irrelevant.");
482 
483  return maserIsCopying_;
484 }
bool isActivated() const
Returns whether the Maser is activated or not.
Definition: ConstantMassFlowMaserBoundary.cc:462
bool maserIsCopying_
Flag whether or not the Maser is copying particles.
Definition: ConstantMassFlowMaserBoundary.h:292

References isActivated(), logger, maserIsCopying_, and WARN.

Referenced by checkBoundaryAfterParticleMoved().

◆ isMaserParticle()

bool ConstantMassFlowMaserBoundary::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

370 {
371  // Check if the particle is in the Maser, by checking whether its
372  // species is found in the list of maser particle species
373  auto positionMaserSpeciesInMap = speciesConversionMaserToNormal_.find(p->getSpecies());
374  return (positionMaserSpeciesInMap != speciesConversionMaserToNormal_.end()); //Test if it is a maser particle
375 }

References p, and speciesConversionMaserToNormal_.

Referenced by checkBoundaryAfterParticleMoved(), and createPeriodicParticle().

◆ isNormalParticle()

bool ConstantMassFlowMaserBoundary::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_().

382 {
383  auto toFindOutflowSpecies = speciesConversionNormalToMaser_.find(p->getSpecies());
384  return (toFindOutflowSpecies != speciesConversionNormalToMaser_.end());
385 }

References p, and speciesConversionNormalToMaser_.

Referenced by checkBoundaryAfterParticleMoved().

◆ read()

void ConstantMassFlowMaserBoundary::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.

99 {
100  BaseBoundary::read(is);
101  std::string dummy;
102  is >> dummy >> normal_
103  >> dummy >> distanceLeft_
104  >> dummy >> distanceRight_
105  >> dummy >> shift_
106  >> dummy >> gapSize_
107  >> dummy >> maserIsActivated_;
108  unsigned int n;
109  is >> dummy >> n;
110  const SpeciesHandler& speciesHandler = getHandler()->getDPMBase()->speciesHandler;
111  for (unsigned int i = 0; i < n; ++i)
112  {
113  unsigned int key;
114  unsigned int value;
115  is >> dummy >> key >> dummy >> value;
116  speciesConversionNormalToMaser_[speciesHandler.getObject(key)] = speciesHandler.getObject(value);
117  speciesConversionMaserToNormal_[speciesHandler.getObject(value)] = speciesHandler.getObject(key);
118  }
119  logger(DEBUG, "Finished reading ConstantMassFlowMaserBoundary. \nNormal: % \nDistanceLeft: % \nDistanceRight: % "
120  "\nGapsize: % \nMaserIsActivated: %",
122 }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
void read(std::istream &is) override=0
Reads the object's id_ from given istream NB: purely virtual function, overriding the version of Base...
Definition: BaseBoundary.cc:40
squared absolute value
Definition: GlobalFunctions.h:87
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286

References DEBUG, distanceLeft_, distanceRight_, gapSize_, BaseHandler< T >::getDPMBase(), BaseBoundary::getHandler(), BaseHandler< T >::getObject(), i, logger, maserIsActivated_, n, normal_, BaseBoundary::read(), shift_, speciesConversionMaserToNormal_, speciesConversionNormalToMaser_, DPMBase::speciesHandler, oomph::Global_string_for_annotation::string(), and Eigen::value.

◆ removeParticleFromMaser()

void ConstantMassFlowMaserBoundary::removeParticleFromMaser ( BaseParticle p)

Convert a maser particle into a 'normal' particle.

356 {
357  auto conversion = speciesConversionMaserToNormal_.find(p->getSpecies());
358  if (conversion != speciesConversionMaserToNormal_.end())
359  {
360  p->setSpecies(conversion->second);
361  p->move(normal_ * gapSize_);
362  }
363 }

References gapSize_, normal_, p, and speciesConversionMaserToNormal_.

Referenced by closeMaser().

◆ set() [1/2]

void ConstantMassFlowMaserBoundary::set ( Vec3D  normal,
Mdouble  distanceLeft,
Mdouble  distanceRight 
)

Sets the Maser's normal and positions, and sets the planewise shift to zero. This deactivates 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
68 {
69  // factor is used to set normal to unit length
70  Mdouble scaleFactor_ = 1. / std::sqrt(Vec3D::dot(normal, normal));
71  normal_ = normal * scaleFactor_;
72  distanceLeft_ = distanceLeft * scaleFactor_;
73  distanceRight_ = distanceRight * scaleFactor_;
75  maserIsActivated_ = false;
76 }
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
void normal(const Vector< double > &x, Vector< double > &normal)
Definition: free_surface_rotation.cc:65

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

◆ set() [2/2]

void ConstantMassFlowMaserBoundary::set ( Vec3D  normal,
Vec3D  planewiseShift,
Mdouble  distanceLeft,
Mdouble  distanceRight 
)

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

55 {
56  set(normal, distanceLeft, distanceRight);
57  setPlanewiseShift(planewiseShift);
58 }
void setPlanewiseShift(Vec3D planewiseShift)
Sets a planewise direction to the shift. Doesn't change the normal or the positions.
Definition: ConstantMassFlowMaserBoundary.cc:83
void set(Vec3D normal, Vec3D planewiseShift, Mdouble distanceLeft, Mdouble distanceRight)
Sets all boundary properties at once and adds particles of the handler to the maser....
Definition: ConstantMassFlowMaserBoundary.cc:54

References WallFunction::normal(), and setPlanewiseShift().

Referenced by ConstantMassFlowMaserBoundaryMixedSpeciesSelfTest::setupInitialConditions(), and ConstantMassFlowMaserSelfTest::setupInitialConditions().

◆ setPlanewiseShift()

void ConstantMassFlowMaserBoundary::setPlanewiseShift ( Vec3D  planewiseShift)

Sets a planewise direction to the shift. Doesn't change the normal or the positions.

Sets the shift_ vector through setting the planewise shift. We delete the component of planewiseShift that is parallel to normal_. Allows Lees–Edwards type Masers.

84 {
85  planewiseShift -= Vec3D::dot(planewiseShift, normal_) / Vec3D::dot(normal_, normal_) * normal_;
86  shift_ = normal_ * (distanceRight_ - distanceLeft_) + planewiseShift;
87 }

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

Referenced by set().

◆ setShift()

void ConstantMassFlowMaserBoundary::setShift ( Vec3D  shift)

Sets the shift of the Maser. Usually don't use this directly, use set() or setPlanewiseShift() instead.

90 {
91  shift_ = shift;
92 }

References shift_.

◆ shiftPosition()

void ConstantMassFlowMaserBoundary::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.
158 {
160  {
161  p->move(-shift_);
162  }
163  else // if closest to right boundary
164  {
165  p->move(shift_);
166  }
167 }

References isClosestToRightBoundary(), p, and shift_.

Referenced by checkBoundaryAfterParticleMoved(), and createPeriodicParticle().

◆ turnOffCopying()

void ConstantMassFlowMaserBoundary::turnOffCopying ( )

Stop copying particles.

473 {
474  maserIsCopying_ = false;
475 }

References maserIsCopying_.

Referenced by closeMaser().

◆ turnOnCopying()

void ConstantMassFlowMaserBoundary::turnOnCopying ( )

Start copying particles.

468 {
469  maserIsCopying_ = true;
470 }

References maserIsCopying_.

Referenced by activateMaser().

◆ write()

void ConstantMassFlowMaserBoundary::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.

129 {
131  os << " normal " << normal_
132  << " distanceLeft " << distanceLeft_
133  << " distanceRight " << distanceRight_
134  << " shift " << shift_
135  << " gapSize " << gapSize_
136  << " maserIsActivated " << maserIsActivated_
137  << " numberOfMaserSpecies " << speciesConversionMaserToNormal_.size();
139  {
140  os << " outflowSpeciesIndex " << p.first->getIndex() << " maserSpeciesIndex " << p.second->getIndex();
141  }
142 }
void write(std::ostream &os) const override=0
Adds object's id_ to given ostream NB: purely virtual function, overriding the version of BaseObject.
Definition: BaseBoundary.cc:49

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

Member Data Documentation

◆ distanceLeft_

Mdouble ConstantMassFlowMaserBoundary::distanceLeft_
private

◆ distanceRight_

Mdouble ConstantMassFlowMaserBoundary::distanceRight_
private

◆ gapSize_

Mdouble ConstantMassFlowMaserBoundary::gapSize_
private

distance between the right side of the periodic domain and the start of the outflow domain.

I.e., each particle in the maser is moved -distanceToOutflowDomain_ * normal when it becomes part of the maser, and moved distanceToOutflowDomain_ * normal when it is inserted in the outflow domain. Generally this is 6 times the radius of the largest particle, so that the ghost particles do not touch each other: the centre of the ghostparticle is at most 1 diameter (2 radii) away from the boundary, so a ghost particle can extend at most 3 particle radii away from the domain. Do this on both sides, and it follows that the gap should be at least 6 diameters wide.

Todo:
JMFT: Do you mean 6 radii?

Referenced by activateMaser(), addParticleToMaser(), checkBoundaryAfterParticleMoved(), closeMaser(), ConstantMassFlowMaserBoundary(), createPeriodicParticle(), getGapSize(), read(), removeParticleFromMaser(), and write().

◆ maserIsActivated_

bool ConstantMassFlowMaserBoundary::maserIsActivated_
private

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

Referenced by activateMaser(), closeMaser(), ConstantMassFlowMaserBoundary(), createPeriodicParticle(), isActivated(), read(), set(), and write().

◆ maserIsCopying_

bool ConstantMassFlowMaserBoundary::maserIsCopying_
private

Flag whether or not the Maser is copying particles.

Referenced by isCopying(), turnOffCopying(), and turnOnCopying().

◆ normal_

Vec3D ConstantMassFlowMaserBoundary::normal_
private

◆ shift_

Vec3D ConstantMassFlowMaserBoundary::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.

By default this is equal to normal_ * (distanceRight_ - distanceLeft_) but you can also set a planewise direction to the shift.

Referenced by ConstantMassFlowMaserBoundary(), read(), set(), setPlanewiseShift(), setShift(), shiftPosition(), and write().

◆ speciesConversionMaserToNormal_

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

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

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

◆ speciesConversionNormalToMaser_

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

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

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


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