PolydisperseInsertionBoundary Class Reference

Like an InsertionBoundary but generates particles of multiple types. Note that, as a child of InsertionBoundary, this class has a member called particleToCopy_, which is a pointer to a particle. This pointer needs to point to something arbitrary but it doesn't matter what the value is. More...

#include <PolydisperseInsertionBoundary.h>

+ Inheritance diagram for PolydisperseInsertionBoundary:

Public Member Functions

 PolydisperseInsertionBoundary ()
 Constructor; sets everything to 0. More...
 
 PolydisperseInsertionBoundary (const PolydisperseInsertionBoundary &other)
 Copy constructor with deep copy. More...
 
 ~PolydisperseInsertionBoundary () override
 Destructor: default destructor. More...
 
PolydisperseInsertionBoundarycopy () const override
 Creates a copy on the heap and returns a pointer. More...
 
void setGeometry (int maxFailed, Vec3D posMin, Vec3D posMax, Vec3D velMin, Vec3D velMax)
 Set position and velocity of inserted particles. More...
 
BaseParticlegetGenerandum (unsigned int spec) const
 Get the particles that need to be copied. More...
 
void addGenerandum (BaseParticle *generandum, double probability, double sizeDispersity)
 Add a new prototype of particle to be copied. More...
 
void setGenerandum (unsigned int spec, BaseParticle *generandum, double probability, double sizeDispersity)
 Change a particle to be copied. More...
 
BaseParticlegenerateParticle (RNG &random) override
 Generates a particle from the possible species. More...
 
void placeParticle (BaseParticle *p, RNG &random) override
 Places the particle in a random position with a random velocity. 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...
 
- Public Member Functions inherited from InsertionBoundary
 InsertionBoundary ()
 
 InsertionBoundary (const InsertionBoundary &other)
 Copy constructor (with deep copy) More...
 
 ~InsertionBoundary () override
 Destructor: delete the particle that has to be copied at every insertion. More...
 
void checkBoundaryBeforeTimeStep (DPMBase *md) override
 Fills the boundary with particles. More...
 
void insertParticles (DPMBase *md)
 Fill a certain domain with particles. More...
 
unsigned int getNumberOfParticlesInserted () const
 Gets the number of particles inserted by the boundary. More...
 
Mdouble getMassOfParticlesInserted () const
 Gets the mass of particles inserted by the boundary. More...
 
Mdouble getVolumeOfParticlesInserted () const
 Gets the volume of particles inserted by the boundary. More...
 
void reset ()
 resets particle property counter variables. More...
 
void activate ()
 Turns on the InsertionBoundary. More...
 
void deactivate ()
 Turns off the InsertionBoundary. More...
 
bool isActivated ()
 Returns whether the InsertionBoundary is activated. More...
 
unsigned int getMaxFailed () const
 Gets the number of times that the boundary may fail to insert a particle. More...
 
void setParticleToCopy (std::vector< BaseParticle * > particleToCopy)
 Sets multiple different particles that will be inserted through the insertion boundary. More...
 
void setParticleToCopy (BaseParticle *particleToCopy)
 Sets the particle that will be inserted through the insertion boundary. More...
 
std::vector< BaseParticle * > getParticleToCopy ()
 Gets the particles that will be inserted through the insertion boundary. More...
 
Mdouble getVolumeFlowRate () const
 Gets the volume flow rate of the insertion routine. More...
 
void setVolumeFlowRate (Mdouble volumeFlowRate_)
 Sets the volume flow rate of the insertion routine. More...
 
Mdouble getInitialVolume () const
 Gets the initialVolume() . More...
 
void setInitialVolume (Mdouble initialVolume)
 Gets the Volume which should be inserted by the insertion routine. More...
 
void setPSD (const PSD psd)
 Sets the range of particle radii that may be generated from a user defined PSD. More...
 
void setPSD (std::vector< PSD > psd, std::vector< Mdouble > probability)
 Sets the ranges of particle radii that may be generated from user defined PSDs. More...
 
std::vector< PSDgetPSD ()
 Gets the particle size distributions set by the user. More...
 
void setVariableVolumeFlowRate (const std::vector< Mdouble > &variableCumulativeVolumeFlowRate, Mdouble samplingInterval)
 Sets a variable volume flow rate. More...
 
bool insertParticle (Mdouble time)
 Checks the inserted total volume and returns if a particle is still allowed to be inserted. More...
 
bool getCheckParticleForInteraction () const
 Gets the variable that checks if a particle has an interaction. More...
 
void setCheckParticleForInteraction (bool checkParticleForInteraction)
 Sets the variable that checks if a particle has an interaction. More...
 
void setManualInsertion (bool manualInsertion)
 Set the flag for a manual PSD insertion routine. More...
 
- Public Member Functions inherited from BaseBoundary
 BaseBoundary ()
 default constructor. More...
 
 BaseBoundary (const BaseBoundary &b)
 copy constructor More...
 
 ~BaseBoundary () override
 destructor More...
 
virtual void createPeriodicParticle (BaseParticle *p UNUSED, ParticleHandler &pH UNUSED)
 Creates a periodic particle in case of periodic boundaries in serial build. More...
 
virtual void createPeriodicParticles (ParticleHandler &pH UNUSED)
 Creates periodic copies of given particle in case of periodic boundaries. More...
 
virtual void checkBoundaryAfterParticlesMove (ParticleHandler &pH)
 Virtual function that does things to particles, each time step after particles have moved. More...
 
virtual void actionsBeforeTimeLoop ()
 Virtual function that does something after DPMBase::setupInitialConditions but before the first time step. More...
 
virtual void modifyGhostAfterCreation (BaseParticle *particle, int i)
 
virtual void writeVTK (std::fstream &file)
 
void setHandler (BoundaryHandler *handler)
 Sets the boundary's BoundaryHandler. More...
 
BoundaryHandlergetHandler () const
 Returns the boundary's BoundaryHandler. More...
 
- Public Member Functions inherited from BaseObject
 BaseObject ()=default
 Default constructor. More...
 
 BaseObject (const BaseObject &p)=default
 Copy constructor, copies all the objects BaseObject contains. More...
 
virtual ~BaseObject ()=default
 virtual destructor More...
 
virtual void moveInHandler (unsigned int index)
 Except that it is virtual, it does the same thing as setIndex() does. More...
 
void setIndex (unsigned int index)
 Allows one to assign an index to an object in the handler/container. More...
 
void setId (unsigned long id)
 Assigns a unique identifier to each object in the handler (container) which remains constant even after the object is deleted from the container/handler. More...
 
unsigned int getIndex () const
 Returns the index of the object in the handler. More...
 
unsigned int getId () const
 Returns the unique identifier of any particular object. More...
 
void setGroupId (unsigned groupId)
 
unsigned getGroupId () const
 

Public Attributes

std::vector< BaseParticle * > generanda_
 Prototypes of the particles that can be generated. More...
 
std::vector< Mdoubleprobabilitates_
 The probabilities of generating each type of particle. These probabilities are not normalised. More...
 
std::vector< MdoublesizeDispersities_
 The dispersity allowed in the particle size. More...
 
Vec3D posMin_
 As in CubeInsertionBoundary. JMFT: TODO: Later we should completely separate InsertionBoundary geometry from their 'intrinsics', so that the code from CubeInsertionBoundary can be recycled. More...
 
Vec3D posMax_
 
Vec3D velMin_
 
Vec3D velMax_
 
std::vector< unsigned int > numbersInserted_
 For keeping track of how much of each prototype we have inserted. More...
 
std::vector< MdoublemassesInserted_
 
std::vector< MdoublevolumesInserted_
 
- Public Attributes inherited from InsertionBoundary
std::vector< BaseParticle * > particleToCopy_
 read Distribution class from file. ‍/ friend std::istream& operator>>(std::istream& is, InsertionBoundary::Distribution& type); More...
 
unsigned int maxFailed_
 Number of times that the wall may fail to insert a particle. More...
 
unsigned int numberOfParticlesInserted_
 Number of particles that are already inserted. More...
 
Mdouble massInserted_
 Total mass of particles inserted. More...
 
Mdouble volumeInserted_
 Total volume of particles inserted. More...
 
bool isActivated_
 The InsertionBoundary is activated by default. If the InsertionBoundary is deactivated, then it introduces no particles (useful for trying to maintain a certain insertion rate). More...
 
Mdouble volumeFlowRate_
 
Mdouble initialVolume_
 
std::vector< MdoublevariableCumulativeVolumeFlowRate_
 
Mdouble samplingInterval_
 
bool checkParticleForInteraction_
 Checks if a particle has an interaction with a wall or other particles. More...
 
std::vector< PSDparticleSizeDistributionVector_
 Defines a particle size distribution as an object of the PSD class; if particleSizeDistributionVector_ is empty, distribution_ is used instead. More...
 
Vec3D velMin_
 Minimum and maximum velocity of the particles to be inserted. More...
 
Vec3D velMax_
 
bool isManuallyInserting_
 A flag to enable a top-down class-by-class manual insertion of a PSD; default is FALSE. More...
 
std::vector< Mdoubleprobability_
 vector of probabilities in range [0,1] which determine the mixing ratio of partice size distributions. More...
 
int chosenSpecies_
 stores the chosen species for each timestep. More...
 

Detailed Description

Like an InsertionBoundary but generates particles of multiple types. Note that, as a child of InsertionBoundary, this class has a member called particleToCopy_, which is a pointer to a particle. This pointer needs to point to something arbitrary but it doesn't matter what the value is.

Constructor & Destructor Documentation

◆ PolydisperseInsertionBoundary() [1/2]

PolydisperseInsertionBoundary::PolydisperseInsertionBoundary ( )

Constructor; sets everything to 0.

Deprecated boundary which was used to insert PSDs into Mercury.

Deprecated:
Should be gone by Mercury 2.0. Instead, use the PSD class.
37 {
38  logger(INFO, "In PolydisperseInsertionBoundary constructor");
39  /* std::vector does all the memory allocation for you.
40  * By default, these are vectors of zero length. */
41  logger(INFO, "About to leave PolydisperseInsertionBoundary copy constructor");
42 }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ INFO

References INFO, and logger.

Referenced by copy().

◆ PolydisperseInsertionBoundary() [2/2]

PolydisperseInsertionBoundary::PolydisperseInsertionBoundary ( const PolydisperseInsertionBoundary other)

Copy constructor with deep copy.

46  : InsertionBoundary(other)
47 {
48  /* The new PolydisperseInsertionBoundary's generanda_ vector should point to
49  * its own copies of each of the generanda_, so we need to copy those
50  * across. */
51  for (int i = 0; i < generanda_.size(); i++)
52  generanda_[i] = other.generanda_[i]->copy();
53 
54  posMin_ = other.posMin_;
55  posMax_ = other.posMax_;
56  velMin_ = other.velMin_;
57  velMax_ = other.velMax_;
63 }
InsertionBoundary()
Definition: InsertionBoundary.cc:38
std::vector< Mdouble > sizeDispersities_
The dispersity allowed in the particle size.
Definition: PolydisperseInsertionBoundary.h:130
std::vector< Mdouble > massesInserted_
Definition: PolydisperseInsertionBoundary.h:144
std::vector< Mdouble > volumesInserted_
Definition: PolydisperseInsertionBoundary.h:145
Vec3D velMax_
Definition: PolydisperseInsertionBoundary.h:138
Vec3D posMin_
As in CubeInsertionBoundary. JMFT: TODO: Later we should completely separate InsertionBoundary geomet...
Definition: PolydisperseInsertionBoundary.h:138
std::vector< unsigned int > numbersInserted_
For keeping track of how much of each prototype we have inserted.
Definition: PolydisperseInsertionBoundary.h:143
std::vector< BaseParticle * > generanda_
Prototypes of the particles that can be generated.
Definition: PolydisperseInsertionBoundary.h:119
Vec3D posMax_
Definition: PolydisperseInsertionBoundary.h:138
std::vector< Mdouble > probabilitates_
The probabilities of generating each type of particle. These probabilities are not normalised.
Definition: PolydisperseInsertionBoundary.h:125
Vec3D velMin_
Definition: PolydisperseInsertionBoundary.h:138
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51

References generanda_, constants::i, massesInserted_, numbersInserted_, posMax_, posMin_, probabilitates_, sizeDispersities_, velMax_, velMin_, and volumesInserted_.

◆ ~PolydisperseInsertionBoundary()

PolydisperseInsertionBoundary::~PolydisperseInsertionBoundary ( )
override

Destructor: default destructor.

67 {
68  // JMFT: Do we need to delete the elements of generanda_?
69  for (auto p : generanda_)
70 
71  delete p;
72 }

References generanda_.

Member Function Documentation

◆ addGenerandum()

void PolydisperseInsertionBoundary::addGenerandum ( BaseParticle generandum,
double  probability,
double  sizeDispersity 
)

Add a new prototype of particle to be copied.

92 {
93  // Give the PolydisperseInsertionBoundary its own copy of the generandum.
94  generanda_.push_back(generandum->copy());
95  probabilitates_.push_back(probability);
96  sizeDispersities_.push_back(sizeDispersity);
97  numbersInserted_.push_back(0);
98  massesInserted_.push_back(0);
99  volumesInserted_.push_back(0);
100  logger(INFO, "PolydisperseInsertionBoundary: added a new generandum, now have %. New generandum has weighting %",
101  generanda_.size(), probability);
102 }
virtual BaseParticle * copy() const =0
Particle copy method. It calls to copy constructor of this Particle, useful for polymorphism.

References BaseParticle::copy(), generanda_, INFO, logger, massesInserted_, numbersInserted_, probabilitates_, sizeDispersities_, and volumesInserted_.

◆ copy()

PolydisperseInsertionBoundary * PolydisperseInsertionBoundary::copy ( ) const
overridevirtual

Creates a copy on the heap and returns a pointer.

Implements BaseBoundary.

75 {
76 #ifdef DEBUG_CONSTRUCTOR
77  logger(INFO, "PolydisperseInsertionBoundary::copy() const finished");
78 #endif
79  return new PolydisperseInsertionBoundary(*this);
80 }
PolydisperseInsertionBoundary()
Constructor; sets everything to 0.
Definition: PolydisperseInsertionBoundary.cc:36

References INFO, logger, and PolydisperseInsertionBoundary().

◆ generateParticle()

BaseParticle * PolydisperseInsertionBoundary::generateParticle ( RNG random)
overridevirtual

Generates a particle from the possible species.

Reimplemented from InsertionBoundary.

130 {
131  /* First choose what particle species to generate. */
132  Mdouble totalprob = 0;
133  for (auto p : probabilitates_)
134  totalprob += p;
135 
136  Mdouble check = random.getRandomNumber(0, totalprob);
137  unsigned int spec = generanda_.size();
138  logger(VERBOSE, "PolydisperseInsertionBoundary: check = % out of %",
139  check, totalprob);
140  for (int i = 0; i < generanda_.size(); i++)
141  {
142  if (check >= probabilitates_[i])
143  check -= probabilitates_[i];
144  else
145  {
146  spec = i;
147  break;
148  }
149  }
150  logger.assert_debug(spec<generanda_.size(),"spec set wrongly");
151 
152  auto P = generanda_[spec]->copy();
153 
154  /* The 'reference' particle for this species has a radius, but we allow some
155  * sizeDispersity. */
156  double radius = P->getRadius()
157  * random.getRandomNumber(1 - sizeDispersities_[spec], 1 + sizeDispersities_[spec]);
158  P->setRadius(radius);
159 
160  /* JMFT: TODO: These do *not* give the correct values!
161  * They give the number &c. of each species that the
162  * PolydisperseInsertionBoundary has _attempted_ to place, not the number
163  * that have actually been placed successfully. */
164  numbersInserted_[spec]++;
165  massesInserted_[spec] += P->getMass();
166  // volumesInserted_[spec] += P->getVolume();
167 
168  return P;
169 }
@ VERBOSE
Mdouble getRandomNumber()
This is a random generating routine can be used for initial positions.
Definition: RNG.cc:143
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:73
void check(double real, double ideal, double error, std::string errorMessage)
Definition: TestHelpers.cc:37

References helpers::check(), generanda_, RNG::getRandomNumber(), constants::i, logger, massesInserted_, numbersInserted_, Global_Physical_Variables::P, probabilitates_, sizeDispersities_, and VERBOSE.

◆ getGenerandum()

BaseParticle* PolydisperseInsertionBoundary::getGenerandum ( unsigned int  spec) const

Get the particles that need to be copied.

◆ getName()

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

Returns the name of the object.

Implements BaseObject.

228 {
229  return "PolydisperseInsertionBoundary";
230 }

◆ placeParticle()

void PolydisperseInsertionBoundary::placeParticle ( BaseParticle p,
RNG random 
)
overridevirtual

Places the particle in a random position with a random velocity.

Implements InsertionBoundary.

174 {
175  Vec3D pos, vel;
176  pos.X = random.getRandomNumber(posMin_.X, posMax_.X);
177  pos.Y = random.getRandomNumber(posMin_.Y, posMax_.Y);
178  pos.Z = random.getRandomNumber(posMin_.Z, posMax_.Z);
179  vel.X = random.getRandomNumber(velMin_.X, velMax_.X);
180  vel.Y = random.getRandomNumber(velMin_.Y, velMax_.Y);
181  vel.Z = random.getRandomNumber(velMin_.Z, velMax_.Z);
182  P->setPosition(pos);
183  P->setVelocity(vel);
184 }
Definition: Vector.h:51
Mdouble Y
Definition: Vector.h:66
Mdouble Z
Definition: Vector.h:66
Mdouble X
the vector components
Definition: Vector.h:66

References RNG::getRandomNumber(), Global_Physical_Variables::P, posMax_, posMin_, velMax_, velMin_, Vec3D::X, Vec3D::Y, and Vec3D::Z.

◆ read()

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

reads boundary properties from istream

Reimplemented from InsertionBoundary.

188 {
190  /*
191  for (int i = 0; i < generanda_.size(); i++)
192  {
193  BaseParticle* particleToCopy = new SphericalParticle;
194  // BaseParticle::write writes the extra word 'BaseParticle', which will be
195  // ignored by BaseParticle::read. To avoid an off-by-one error, we need to
196  // get rid of this extra word first...
197  std::string dummy;
198  is >> dummy;
199 
200  // Now read the particleToCopy.
201  particleToCopy->read(is);
202  generanda_[i] = particleToCopy->copy();
203  delete particleToCopy;
204  generanda_[i]->setSpecies(getHandler()->getDPMBase()->speciesHandler.getObject(
205  particleToCopy_->getIndSpecies()
206  ));
207  }
208  */
209 }
void read(std::istream &is) override
Reads the boundary's id_ and maxFailed_.
Definition: InsertionBoundary.cc:471

References InsertionBoundary::read().

◆ setGenerandum()

void PolydisperseInsertionBoundary::setGenerandum ( unsigned int  spec,
BaseParticle generandum,
double  probability,
double  sizeDispersity 
)

Change a particle to be copied.

107 {
108  if (spec < generanda_.size())
109  logger(INFO, "Setting the %-th species of a PolydisperseInsertionBoundary that so far has % species",
110  spec, generanda_.size());
111  else
112  logger(ERROR,
113  "Setting the %-th species of a PolydiserseInsertionBoundary with only % species is illegal. Use addGenerandum instead.",
114  spec, generanda_.size());
115 
116  if (probability == 0)
117  logger(WARN, "PolydisperseInsertionBoundary: Are you sure you want to set the probability to be 0?");
118 
119  generanda_[spec] = generandum->copy();
120  probabilitates_[spec] = probability;
121  sizeDispersities_[spec] = sizeDispersity;
122 
123  // Reset the counters for number, mass and volume
124  numbersInserted_[spec] = 0;
125  massesInserted_[spec] = 0;
126  volumesInserted_[spec] = 0;
127 }
@ WARN
@ ERROR

References BaseParticle::copy(), ERROR, generanda_, INFO, logger, massesInserted_, numbersInserted_, probabilitates_, sizeDispersities_, volumesInserted_, and WARN.

◆ setGeometry()

void PolydisperseInsertionBoundary::setGeometry ( int  maxFailed,
Vec3D  posMin,
Vec3D  posMax,
Vec3D  velMin,
Vec3D  velMax 
)

Set position and velocity of inserted particles.

83 {
84  maxFailed_ = maxFailed;
85  posMin_ = posMin;
86  posMax_ = posMax;
87  velMin_ = velMin;
88  velMax_ = velMax;
89 }
unsigned int maxFailed_
Number of times that the wall may fail to insert a particle.
Definition: InsertionBoundary.h:270

References InsertionBoundary::maxFailed_, posMax_, posMin_, velMax_, and velMin_.

◆ write()

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

writes boundary properties to ostream

Reimplemented from InsertionBoundary.

213 {
214  logger(VERBOSE, "In PolydisperseInsertionBoundary::write");
216  os << " numberOfGeneranda " << generanda_.size() << " ";
217  for (int i = 0; i < generanda_.size(); i++)
218  {
219  generanda_[i]->write(os);
220  os << " weight " << probabilitates_[i] << " sizeDispersity " << sizeDispersities_[i] << " ";
221  }
222  os << "posMin " << posMin_ << " posMax " << posMax_
223  << " velMin " << velMin_ << " velMax " << velMax_
224  << " ";
225 }
void write(std::ostream &os) const override
Writes the boundary's id_ and maxFailed_.
Definition: InsertionBoundary.cc:559

References generanda_, constants::i, logger, posMax_, posMin_, probabilitates_, sizeDispersities_, velMax_, velMin_, VERBOSE, and InsertionBoundary::write().

Member Data Documentation

◆ generanda_

std::vector<BaseParticle*> PolydisperseInsertionBoundary::generanda_

Prototypes of the particles that can be generated.

Referenced by addGenerandum(), generateParticle(), PolydisperseInsertionBoundary(), setGenerandum(), write(), and ~PolydisperseInsertionBoundary().

◆ massesInserted_

std::vector<Mdouble> PolydisperseInsertionBoundary::massesInserted_

◆ numbersInserted_

std::vector<unsigned int> PolydisperseInsertionBoundary::numbersInserted_

For keeping track of how much of each prototype we have inserted.

Referenced by addGenerandum(), generateParticle(), PolydisperseInsertionBoundary(), and setGenerandum().

◆ posMax_

Vec3D PolydisperseInsertionBoundary::posMax_

◆ posMin_

Vec3D PolydisperseInsertionBoundary::posMin_

As in CubeInsertionBoundary. JMFT: TODO: Later we should completely separate InsertionBoundary geometry from their 'intrinsics', so that the code from CubeInsertionBoundary can be recycled.

Referenced by placeParticle(), PolydisperseInsertionBoundary(), setGeometry(), and write().

◆ probabilitates_

std::vector<Mdouble> PolydisperseInsertionBoundary::probabilitates_

The probabilities of generating each type of particle. These probabilities are not normalised.

Referenced by addGenerandum(), generateParticle(), PolydisperseInsertionBoundary(), setGenerandum(), and write().

◆ sizeDispersities_

std::vector<Mdouble> PolydisperseInsertionBoundary::sizeDispersities_

The dispersity allowed in the particle size.

Referenced by addGenerandum(), generateParticle(), PolydisperseInsertionBoundary(), setGenerandum(), and write().

◆ velMax_

Vec3D PolydisperseInsertionBoundary::velMax_

◆ velMin_

Vec3D PolydisperseInsertionBoundary::velMin_

◆ volumesInserted_

std::vector<Mdouble> PolydisperseInsertionBoundary::volumesInserted_

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