MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ChuteInsertionBoundary.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 "ChuteInsertionBoundary.h"
27 #include "Particles/BaseParticle.h"
28 #include "Math/RNG.h"
29 #include "Math/ExtendedMath.h"
30 
34 //This is not the most beautiful code, but it works.
36 {
37  posMax_ = Vec3D(0.0, 0.0, 0.0);
38  posMin_ = Vec3D(0.0, 0.0, 0.0);
39  radMax_ = 0.0;
40  radMin_ = 0.0;
42  inflowVelocity_ = 0.0;
44 }
45 
50  : InsertionBoundary(other)
51 {
52  posMax_ = other.posMax_;
53  posMin_ = other.posMin_;
54  radMax_ = other.radMax_;
55  radMin_ = other.radMin_;
59 }
60 
66 {
67 #ifdef DEBUG_CONSTRUCTOR
68  std::cout << "ChuteInsertionBoundary::copy() const finished" << std::endl;
69 #endif
70  return new ChuteInsertionBoundary(*this);
71 }
72 
95 void ChuteInsertionBoundary::set(BaseParticle* particleToCopy, unsigned int maxFailed, Vec3D posMin, Vec3D posMax, double radMin, double radMax, double fixedParticleRadius, double inflowVelocity, double inflowVelocityVariance)
96 {
97  if (particleToCopy != nullptr)
98  {
99  setParticleToCopy(particleToCopy);
100  }
101  setMaxFailed(maxFailed);
102  posMin_ = posMin;
103  posMax_ = posMax;
104  radMin_ = radMin;
105  radMax_ = radMax;
106  fixedParticleRadius_ = fixedParticleRadius;
107  inflowVelocity_ = inflowVelocity;
108  inflowVelocityVariance_ = inflowVelocityVariance;
109 }
110 
125 {
127 
129 
130  Vec3D position, velocity;
131 
132  position.X = posMin_.X + P->getRadius();
133 
134  if (mathsFunc::isEqual(posMax_.Y - posMin_.Y , 2.0 * radMax_, 1e-10))
135  {
136  position.Y = posMin_.Y + P->getRadius();
137  }
138  else
139  {
140  position.Y = random.getRandomNumber(posMin_.Y + P->getRadius(), posMax_.Y - P->getRadius());
141  }
142  position.Z = random.getRandomNumber(posMin_.Z + fixedParticleRadius_ + P->getRadius(), posMax_.Z - P->getRadius());
143 
144  // The velocity components are first stored in a Vec3D, because if you pass them
145  // directly into setVelocity the compiler is allowed to change the order in
146  // which the numbers are generated
150 
151  P->setPosition(position);
152  P->setVelocity(velocity);
153 
154  return P;
155 }
156 
161 void ChuteInsertionBoundary::read(std::istream& is)
162 {
164  std::string dummy;
165  is >> dummy >> posMin_
166  >> dummy >> posMax_
167  >> dummy >> radMin_
168  >> dummy >> radMax_
169  >> dummy >> fixedParticleRadius_
170  >> dummy >> inflowVelocity_
171  >> dummy >> inflowVelocityVariance_;
172 }
173 
178 void ChuteInsertionBoundary::oldRead(std::istream& is)
179 {
180  unsigned int maxFailed;
181  std::string dummy;
182  is >> dummy >> maxFailed
183  >> dummy >> posMin_
184  >> dummy >> posMax_
185  >> dummy >> radMin_
186  >> dummy >> radMax_
187  >> dummy >> fixedParticleRadius_
188  >> dummy >> inflowVelocity_
189  >> dummy >> inflowVelocityVariance_;
190  setMaxFailed(maxFailed);
191 }
192 
197 void ChuteInsertionBoundary::write(std::ostream& os) const
198  {
200  os << " posMin " << posMin_
201  << " posMax " << posMax_
202  << " radMin " << radMin_
203  << " radMax " << radMax_
204  << " fixedParticleRadius " << fixedParticleRadius_
205  << " inflowVelocity " << inflowVelocity_
206  << " inflowVelocityVariance " << inflowVelocityVariance_;
207 
208 }
209 
215 {
216  return "ChuteInsertionBoundary";
217 }
218 
virtual ChuteInsertionBoundary * copy() const
Copy method; creates a copy on the heap.
Mdouble X
the vector components
Definition: Vector.h:52
double radMin_
Minimum and maximum radii of the generated particles.
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
ChuteInsertionBoundary()
Default constructor.
void setMaxFailed(unsigned int maxFailed)
Sets the number of times that the wall may fail to insert a particle.
bool isEqual(Mdouble v1, Mdouble v2, Mdouble absError)
Compares the difference of two Mdouble with an absolute error, useful in UnitTests.
void setRadius(const Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species) ...
Boundary structure for boundaries used for insertion of particles.
void setParticleToCopy(BaseParticle *particleToCopy)
Sets the particle that will be inserted through the insertion boundary.
This is a class that generates random numbers i.e. named the Random Number Generator (RNG)...
Definition: RNG.h:52
void read(std::istream &is)
reads boundary properties from istream
double fixedParticleRadius_
radius of the fixed bottom particles, mean particle velocity in X-direction, and allowed maximum rand...
virtual std::string getName() const
Returns the name of the object.
Vec3D posMin_
The two extremal corners of the cuboidal insertion boundary.
BaseParticle * getParticleToCopy() const
Gets the particle that will be inserted through the insertion boundary.
virtual BaseParticle * generateParticle(RNG &random)
Generates a random particle.
Mdouble getRadius() const
Returns the particle's radius_.
Mdouble Y
Definition: Vector.h:52
void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
void write(std::ostream &os) const
writes boundary properties to ostream
Used for modeling chute inflow. Inherits from InsertionBoundary.
void read(std::istream &is)
Reads the boundary's id_ and maxFailed_.
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
void set(BaseParticle *particleToCopy, unsigned int maxFailed, Vec3D posMin, Vec3D posMax, double radMin, double radMax, double fixedParticleRadius, double inflowVelocity, double inflowVelocityVariance)
Sets all boundary properties at once.
Mdouble Z
Definition: Vector.h:52
void write(std::ostream &os) const
Writes the boundary's id_ and maxFailed_.
MERCURY_DEPRECATED void oldRead(std::istream &is)
deprecated version of CubeInsertionBoundary::read().
Mdouble getRandomNumber(Mdouble min, Mdouble max)
This is a random generating routine can be used for initial positions.
Definition: RNG.cc:101
virtual BaseParticle * copy() const
Particle copy method. It calls to copy constructor of this Particle, useful for polymorfism.