MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InsertionBoundary Class Referenceabstract

Boundary structure for boundaries used for insertion of particles. More...

#include <InsertionBoundary.h>

+ Inheritance diagram for InsertionBoundary:

Public Member Functions

 InsertionBoundary ()
 Default constructor: set everything to 0/nullptr. More...
 
 InsertionBoundary (const InsertionBoundary &other)
 Copy constructor (with deep copy) More...
 
virtual ~InsertionBoundary ()
 Destructor: delete the particle that has to be copied at every insertion. More...
 
void set (BaseParticle *particleToCopy, unsigned int maxFailed)
 Sets the particle that will be inserted and the maximum number of times for which insertion may fail. More...
 
virtual BaseParticlegenerateParticle (RNG &random)=0
 Purely virtual function that generates one particle. More...
 
virtual void checkBoundaryBeforeTimeStep (DPMBase *md)
 Fills the boundary with particles. More...
 
unsigned int getNumberOfParticlesInserted () const
 Gets the number of particles inserted by the boundary. More...
 
void setMaxFailed (unsigned int maxFailed)
 Sets the number of times that the wall may fail to insert a particle. More...
 
unsigned int getMaxFailed () const
 Gets the number of times that the boundary may fail to insert a particle. More...
 
void setParticleToCopy (BaseParticle *particleToCopy)
 Sets the particle that will be inserted through the insertion boundary. More...
 
BaseParticlegetParticleToCopy () const
 Gets the particle that will be inserted through the insertion boundary. More...
 
void read (std::istream &is)
 Reads the boundary's id_ and maxFailed_. More...
 
void write (std::ostream &os) const
 Writes the boundary's id_ and maxFailed_. More...
 
- Public Member Functions inherited from BaseBoundary
 BaseBoundary ()
 default constructor. More...
 
 BaseBoundary (const BaseBoundary &b)
 copy constructor More...
 
virtual ~BaseBoundary ()
 destructor More...
 
virtual BaseBoundarycopy () const =0
 Used to create a copy of the object NB: purely virtual function. More...
 
virtual void createPeriodicParticles (BaseParticle *P UNUSED, ParticleHandler &pH UNUSED)
 Creates periodic copies of given particle in case of periodic boundaries. More...
 
virtual bool checkBoundaryAfterParticleMoved (BaseParticle *P UNUSED, ParticleHandler &pH UNUSED)
 Checks if given particle passed the boundary. More...
 
virtual void checkBoundaryBeforeTimeStep (DPMBase *md UNUSED)
 Fills a (3D) boundary with particles. More...
 
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 constructor. More...
 
 BaseObject (const BaseObject &p)
 Copy constructor, copies all the objects BaseObject contains. More...
 
virtual ~BaseObject ()
 virtual destructor More...
 
virtual std::string getName () const =0
 A purely virtual function. More...
 
virtual void moveInHandler (const unsigned int index)
 Except that it is virtual, it does the same thing as setIndex() does. More...
 
void setIndex (const unsigned int index)
 Allows one to assign an index to an object in the handler/container. More...
 
void setId (const unsigned int 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...
 

Protected Attributes

BaseParticleparticleToCopy_
 Particle that will be inserted through the insertion boundary. 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...
 

Detailed Description

Boundary structure for boundaries used for insertion of particles.

Todo:
IFCD: Should operator= be implemented here and in the derived classes?

Definition at line 39 of file InsertionBoundary.h.

Constructor & Destructor Documentation

InsertionBoundary::InsertionBoundary ( )

Default constructor: set everything to 0/nullptr.

Default constructor, sets all data members to 0 or nullptr.

Definition at line 33 of file InsertionBoundary.cc.

References maxFailed_, numberOfParticlesInserted_, and particleToCopy_.

34 {
36  particleToCopy_ = nullptr;
37  maxFailed_ = 0;
38 }
BaseParticle * particleToCopy_
Particle that will be inserted through the insertion boundary.
unsigned int maxFailed_
Number of times that the wall may fail to insert a particle.
unsigned int numberOfParticlesInserted_
Number of particles that are already inserted.
InsertionBoundary::InsertionBoundary ( const InsertionBoundary other)

Copy constructor (with deep copy)

Copy constructor

Definition at line 43 of file InsertionBoundary.cc.

References BaseParticle::copy(), maxFailed_, numberOfParticlesInserted_, and particleToCopy_.

44 {
46  maxFailed_ = other.maxFailed_;
47 
48  if (other.particleToCopy_!=nullptr)
50  else
51  {
52  particleToCopy_ = nullptr;
53  }
54 }
BaseParticle * particleToCopy_
Particle that will be inserted through the insertion boundary.
unsigned int maxFailed_
Number of times that the wall may fail to insert a particle.
unsigned int numberOfParticlesInserted_
Number of particles that are already inserted.
virtual BaseParticle * copy() const
Particle copy method. It calls to copy constructor of this Particle, useful for polymorfism.
InsertionBoundary::~InsertionBoundary ( )
virtual

Destructor: delete the particle that has to be copied at every insertion.

Destructor that deletes the BaseParticle that is copied and inserted at every insertion.

Definition at line 60 of file InsertionBoundary.cc.

References particleToCopy_.

61 {
62  if (particleToCopy_!=nullptr)
63  delete particleToCopy_;
64 }
BaseParticle * particleToCopy_
Particle that will be inserted through the insertion boundary.

Member Function Documentation

void InsertionBoundary::checkBoundaryBeforeTimeStep ( DPMBase md)
virtual

Fills the boundary with particles.

Is used to fill the insides of the boundary with particles until it is filled up.

Parameters
[in,out]mdthe problem's DPMBase object
Todo:
rename to something like "insertUntilMaxFailed"?

Definition at line 85 of file InsertionBoundary.cc.

References DPMBase::checkParticleForInteraction(), BaseHandler< T >::copyAndAddObject(), generateParticle(), maxFailed_, numberOfParticlesInserted_, DPMBase::particleHandler, and DPMBase::random.

86 {
87  unsigned int failed = 0;
88  BaseParticle* p0;
89  //try max_failed times to find new insertable particle
90  while (failed <= maxFailed_)
91  {
92  p0 = generateParticle(md->random);
93  //std::cout<<"Trying "<<*p0<<std::endl;
94 
95  if (md->checkParticleForInteraction(*p0))
96  {
98  failed = 0;
100  //std::cout<<"succes"<<std::endl;
101  }
102  else
103  {
104  failed++;
105  //std::cout<<"failure"<<std::endl;
106  }
107  //Irana: got rid of the delete, since it is not made with new (particle on stack instead of heap)
108  //delete p0;
109  }
110 }
unsigned int maxFailed_
Number of times that the wall may fail to insert a particle.
virtual bool checkParticleForInteraction(const BaseParticle &P)
Checks if the particle having any interaction with walls or other particles.
Definition: DPMBase.cc:2632
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created...
Definition: DPMBase.h:1001
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:295
virtual BaseParticle * generateParticle(RNG &random)=0
Purely virtual function that generates one particle.
RNG random
This is a random generator, often used for setting up the initial conditions etc...
Definition: DPMBase.h:996
unsigned int numberOfParticlesInserted_
Number of particles that are already inserted.
virtual BaseParticle* InsertionBoundary::generateParticle ( RNG random)
pure virtual

Purely virtual function that generates one particle.

Parameters
[in]randomRandom number generator that can be used for initial positions and velocities
Todo:
(AT) think about implementation of this method here instead of in the children, since the checkBoundaryBeforeTimeStep (i.e., the actual insertion of particles) is also defined here. Current problem with this: boundary dimensions, which are needed for the particle placement, are now defined in the children, and depend heavily on its shape.

Implemented in HopperInsertionBoundary, CubeInsertionBoundary, and ChuteInsertionBoundary.

Referenced by checkBoundaryBeforeTimeStep().

unsigned int InsertionBoundary::getMaxFailed ( ) const

Gets the number of times that the boundary may fail to insert a particle.

Return maxFailed_ (see InsertionBoundary::setMaxFailed).

Returns
the maximum number of particle insertion trials

Definition at line 135 of file InsertionBoundary.cc.

References maxFailed_.

136 {
137  return maxFailed_;
138 }
unsigned int maxFailed_
Number of times that the wall may fail to insert a particle.
unsigned int InsertionBoundary::getNumberOfParticlesInserted ( ) const

Gets the number of particles inserted by the boundary.

Returns the number of particles inserted in the boundary

Returns
the number of particles inserted

Definition at line 116 of file InsertionBoundary.cc.

References numberOfParticlesInserted_.

Referenced by Chute::write().

117 {
119 }
unsigned int numberOfParticlesInserted_
Number of particles that are already inserted.
BaseParticle * InsertionBoundary::getParticleToCopy ( ) const

Gets the particle that will be inserted through the insertion boundary.

returns pointer to the particle copies of which are to be inserted

Todo:
make this a debug check

Definition at line 153 of file InsertionBoundary.cc.

References particleToCopy_.

Referenced by ChuteInsertionBoundary::generateParticle(), CubeInsertionBoundary::generateParticle(), and HopperInsertionBoundary::generateParticle().

154 {
156  //if (particleToCopy_==nullptr)
157  // std::cerr << "Error: particleToCopy not set" << std::endl;
158  return particleToCopy_;
159 }
BaseParticle * particleToCopy_
Particle that will be inserted through the insertion boundary.
void InsertionBoundary::read ( std::istream &  is)
virtual

Reads the boundary's id_ and maxFailed_.

reads the boundary's id_ and maxFailed_ from the given istream

Parameters
[in,out]isstream the data members are read from

Implements BaseBoundary.

Definition at line 165 of file InsertionBoundary.cc.

References ParticleHandler::getNewObject(), maxFailed_, numberOfParticlesInserted_, particleToCopy_, and BaseBoundary::read().

Referenced by ChuteInsertionBoundary::read(), CubeInsertionBoundary::read(), and HopperInsertionBoundary::read().

166 {
167  BaseBoundary::read(is);
168  std::string dummy, type;
169  is >> dummy >> maxFailed_;
170  is >> dummy >> numberOfParticlesInserted_;
171  is >> dummy >> type;
172  if (particleToCopy_!=nullptr)
173  delete particleToCopy_;
175 }
BaseParticle * particleToCopy_
Particle that will be inserted through the insertion boundary.
unsigned int maxFailed_
Number of times that the wall may fail to insert a particle.
unsigned int numberOfParticlesInserted_
Number of particles that are already inserted.
static BaseParticle * getNewObject(const std::string &type)
void read(std::istream &is)=0
Reads the object's id_ from given istream NB: purely virtual function, overriding the version of Base...
Definition: BaseBoundary.cc:67
void InsertionBoundary::set ( BaseParticle particleToCopy,
unsigned int  maxFailed 
)

Sets the particle that will be inserted and the maximum number of times for which insertion may fail.

Sets the particle that will be inserted and the maximum number of times for which insertion may fail.

Parameters
[in]particleToCopyParticle that will be copied and inserted in the domain
[in]maxFailedNumber of times that the wall may fail to insert a particle

Definition at line 72 of file InsertionBoundary.cc.

References BaseParticle::copy(), maxFailed_, and particleToCopy_.

73 {
74  if (particleToCopy!=nullptr)
75  particleToCopy_ = particleToCopy->copy();
76  maxFailed_ = maxFailed;
77 }
BaseParticle * particleToCopy_
Particle that will be inserted through the insertion boundary.
unsigned int maxFailed_
Number of times that the wall may fail to insert a particle.
virtual BaseParticle * copy() const
Particle copy method. It calls to copy constructor of this Particle, useful for polymorfism.
void InsertionBoundary::setMaxFailed ( unsigned int  maxFailed)

Sets the number of times that the wall may fail to insert a particle.

Sets the maximum number of times InsertionBoundary::checkBoundaryBeforeTimeStep() may try to insert a particle and fail, before the insertion of particles stops.

Parameters
[in]maxFailedthe maximum number of particle insertion trials

Definition at line 126 of file InsertionBoundary.cc.

References maxFailed_.

Referenced by ChuteInsertionBoundary::oldRead(), CubeInsertionBoundary::oldRead(), HopperInsertionBoundary::oldRead(), ChuteInsertionBoundary::set(), CubeInsertionBoundary::set(), and HopperInsertionBoundary::set().

127 {
128  maxFailed_=maxFailed;
129 }
unsigned int maxFailed_
Number of times that the wall may fail to insert a particle.
void InsertionBoundary::setParticleToCopy ( BaseParticle particleToCopy)

Sets the particle that will be inserted through the insertion boundary.

Sets the pointer to the particle, copies of which are inserted

Parameters
[in]particleToCopypointer to the particle to be inserted

Definition at line 144 of file InsertionBoundary.cc.

References BaseParticle::copy(), and particleToCopy_.

Referenced by ChuteInsertionBoundary::set(), CubeInsertionBoundary::set(), and HopperInsertionBoundary::set().

145 {
146  if (particleToCopy!=nullptr)
147  particleToCopy_ = particleToCopy->copy();
148 }
BaseParticle * particleToCopy_
Particle that will be inserted through the insertion boundary.
virtual BaseParticle * copy() const
Particle copy method. It calls to copy constructor of this Particle, useful for polymorfism.
void InsertionBoundary::write ( std::ostream &  os) const
virtual

Writes the boundary's id_ and maxFailed_.

adds the boundary's id_ and maxFailed_ to the given ostream

Parameters
[in,out]isstream the data members are to be added to

Implements BaseBoundary.

Definition at line 181 of file InsertionBoundary.cc.

References BaseParticle::getName(), maxFailed_, numberOfParticlesInserted_, particleToCopy_, and BaseBoundary::write().

Referenced by ChuteInsertionBoundary::write(), CubeInsertionBoundary::write(), and HopperInsertionBoundary::write().

182 {
184  os << " maxFailed " << maxFailed_;
185  os << " numberOfParticlesInserted " << numberOfParticlesInserted_;
186  os << " particleToCopy " << particleToCopy_->getName();
187 }
void write(std::ostream &os) const =0
Adds object's id_ to given ostream NB: purely virtual function, overriding the version of BaseObject...
Definition: BaseBoundary.cc:76
BaseParticle * particleToCopy_
Particle that will be inserted through the insertion boundary.
unsigned int maxFailed_
Number of times that the wall may fail to insert a particle.
virtual std::string getName() const
Returns the name of the object.
unsigned int numberOfParticlesInserted_
Number of particles that are already inserted.

Member Data Documentation

unsigned int InsertionBoundary::maxFailed_
protected

Number of times that the wall may fail to insert a particle.

Definition at line 122 of file InsertionBoundary.h.

Referenced by checkBoundaryBeforeTimeStep(), getMaxFailed(), InsertionBoundary(), read(), set(), setMaxFailed(), and write().

unsigned int InsertionBoundary::numberOfParticlesInserted_
protected

Number of particles that are already inserted.

Definition at line 127 of file InsertionBoundary.h.

Referenced by checkBoundaryBeforeTimeStep(), getNumberOfParticlesInserted(), InsertionBoundary(), read(), and write().

BaseParticle* InsertionBoundary::particleToCopy_
protected

Particle that will be inserted through the insertion boundary.

Definition at line 117 of file InsertionBoundary.h.

Referenced by getParticleToCopy(), InsertionBoundary(), read(), set(), setParticleToCopy(), write(), and ~InsertionBoundary().


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