MercuryDPM  Beta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InsertionBoundary.cc
Go to the documentation of this file.
1 //Copyright (c) 2013-2014, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #include "InsertionBoundary.h"
27 #include "DPMBase.h"
28 #include "Particles/BaseParticle.h"
29 
34 {
36  particleToCopy_ = nullptr;
37  maxFailed_ = 0;
38 }
39 
44 {
46  maxFailed_ = other.maxFailed_;
48 }
49 
55 {
56  delete particleToCopy_;
57 }
58 
65 void InsertionBoundary::set(BaseParticle* particleToCopy, unsigned int maxFailed)
66 {
67  particleToCopy_ = particleToCopy->copy();
68  maxFailed_ = maxFailed;
69 }
70 
78 {
79  unsigned int failed = 0;
80  BaseParticle* p0;
81  //try max_failed times to find new insertable particle
82  while (failed <= maxFailed_)
83  {
84  p0 = generateParticle(md->random);
85  //std::cout<<"Trying "<<*p0<<std::endl;
86 
87  if (md->checkParticleForInteraction(*p0))
88  {
90  failed = 0;
92  //std::cout<<"succes"<<std::endl;
93  }
94  else
95  {
96  failed++;
97  //std::cout<<"failure"<<std::endl;
98  }
99  //Irana: got rid of the delete, since it is not made with new (particle on stack instead of heap)
100  //delete p0;
101  }
102 }
103 
109 {
111 }
112 
118 void InsertionBoundary::setMaxFailed(unsigned int maxFailed)
119 {
120  maxFailed_=maxFailed;
121 }
122 
128 {
129  return maxFailed_;
130 }
131 
137 {
138  particleToCopy_ = particleToCopy->copy();
139 }
140 
145 {
146  return particleToCopy_;
147 }
148 
153 void InsertionBoundary::read(std::istream& is)
154 {
155  BaseBoundary::read(is);
156  std::string dummy;
157  is >> dummy >> maxFailed_;
158 }
159 
164 void InsertionBoundary::write(std::ostream& os) const
165 {
167  os << " maxFailed " << maxFailed_;
168 }
169 
virtual void checkBoundaryBeforeTimeStep(DPMBase *md)
Fills the boundary with particles.
The DPMBase header includes quite a few header files, defining all the handlers, which are essential...
Definition: DPMBase.h:61
InsertionBoundary()
Default constructor: set everything to 0/nullptr.
void write(std::ostream &os) const =0
Adds object's id_ to given ostream NB: purely virtual function.
Definition: BaseBoundary.cc:76
unsigned int getMaxFailed() const
Gets the number of times that the boundary may fail to insert a particle.
BaseParticle * particleToCopy_
Particle that will be inserted through the insertion boundary.
void setMaxFailed(unsigned int maxFailed)
Sets the number of times that the wall may fail to insert a particle.
unsigned int maxFailed_
Number of times that the wall may fail to insert a particle.
Boundary structure for boundaries used for insertion of particles.
void setParticleToCopy(BaseParticle *particleToCopy)
Sets the particle that will be inserted through the insertion boundary.
virtual bool checkParticleForInteraction(const BaseParticle &P)
Checks if the particle having any interaction with walls or other particles.
Definition: DPMBase.cc:2353
U * copyAndAddObject(const U &O)
Creates a copy of a Object and adds it to the BaseHandler.
Definition: BaseHandler.h:268
unsigned int getNumberOfParticlesInserted() const
Gets the number of particles inserted by the boundary.
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created...
Definition: DPMBase.h:878
BaseParticle * getParticleToCopy() const
Gets the particle that will be inserted through the insertion boundary.
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...
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:873
virtual ~InsertionBoundary()
Destructor: delete the particle that has to be copied at every insertion.
unsigned int numberOfParticlesInserted_
Number of particles that are already inserted.
void read(std::istream &is)
Reads the boundary's id_ and maxFailed_.
void write(std::ostream &os) const
Writes the boundary's id_ and maxFailed_.
virtual BaseParticle * copy() const
Particle copy method. It calls to copy constructor of this Particle, useful for polymorfism.
void read(std::istream &is)=0
Reads the object's id_ from given istream NB: purely virtual function.
Definition: BaseBoundary.cc:67