MercuryDPM  Alpha
 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_;
47 
48  if (other.particleToCopy_!=nullptr)
50  else
51  {
52  particleToCopy_ = nullptr;
53  }
54 }
55 
61 {
62  if (particleToCopy_!=nullptr)
63  delete particleToCopy_;
64 }
65 
72 void InsertionBoundary::set(BaseParticle* particleToCopy, unsigned int maxFailed)
73 {
74  if (particleToCopy!=nullptr)
75  particleToCopy_ = particleToCopy->copy();
76  maxFailed_ = maxFailed;
77 }
78 
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 }
111 
117 {
119 }
120 
126 void InsertionBoundary::setMaxFailed(unsigned int maxFailed)
127 {
128  maxFailed_=maxFailed;
129 }
130 
136 {
137  return maxFailed_;
138 }
139 
145 {
146  if (particleToCopy!=nullptr)
147  particleToCopy_ = particleToCopy->copy();
148 }
149 
154 {
156  //if (particleToCopy_==nullptr)
157  // std::cerr << "Error: particleToCopy not set" << std::endl;
158  return particleToCopy_;
159 }
160 
165 void InsertionBoundary::read(std::istream& is)
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 }
176 
181 void InsertionBoundary::write(std::ostream& os) const
182 {
184  os << " maxFailed " << maxFailed_;
185  os << " numberOfParticlesInserted " << numberOfParticlesInserted_;
186  os << " particleToCopy " << particleToCopy_->getName();
187 }
188 
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:65
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, overriding the version of BaseObject...
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.
virtual std::string getName() const
Returns the name of the object.
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:2632
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:1001
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...
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
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_.
static BaseParticle * getNewObject(const std::string &type)
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, overriding the version of Base...
Definition: BaseBoundary.cc:67