MercuryDPM  Trunk
 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-2020, 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);
40  inflowVelocity_ = 0.0;
42 }
43 
48  : InsertionBoundary(other)
49 {
50  posMax_ = other.posMax_;
51  posMin_ = other.posMin_;
55 }
56 
62 {
63 #ifdef DEBUG_CONSTRUCTOR
64  std::cout << "ChuteInsertionBoundary::copy() const finished" << std::endl;
65 #endif
66  return new ChuteInsertionBoundary(*this);
67 }
68 
91 void ChuteInsertionBoundary::set(BaseParticle* particleToCopy, unsigned int maxFailed, Vec3D posMin, Vec3D posMax,
92  double radMin, double radMax, double fixedParticleRadius, double inflowVelocity,
93  double inflowVelocityVariance)
94 {
95  if (particleToCopy != nullptr)
96  {
97  setParticleToCopy(particleToCopy);
98  }
99  setMaxFailed(maxFailed);
100  posMin_ = posMin;
101  posMax_ = posMax;
102  radMin_ = radMin;
103  radMax_ = radMax;
104  fixedParticleRadius_ = fixedParticleRadius;
105  inflowVelocity_ = inflowVelocity;
106  inflowVelocityVariance_ = inflowVelocityVariance;
107 }
108 
123 {
124  Vec3D position, velocity;
125 
126  position.X = posMin_.X + p->getRadius();
127 
128  if (mathsFunc::isEqual(posMax_.Y - posMin_.Y, 2.0 * radMax_, 1e-10))
129  {
130  position.Y = posMin_.Y + p->getRadius();
131  }
132  else
133  {
134  position.Y = random.getRandomNumber(posMin_.Y - p->getRadius(), posMax_.Y + p->getRadius());
135  }
136  position.Z = random.getRandomNumber(posMin_.Z - p->getRadius(), posMax_.Z + p->getRadius() + fixedParticleRadius_);
137 
138  // The velocity components are first stored in a Vec3D, because if you pass them
139  // directly into setVelocity the compiler is allowed to change the order in
140  // which the numbers are generated
145 
146  p->setPosition(position);
147  p->setVelocity(velocity);
148 
149 
150 }
151 
156 void ChuteInsertionBoundary::read(std::istream& is)
157 {
159  std::string dummy;
160  is >> dummy >> posMin_
161  >> dummy >> posMax_
162  >> dummy >> radMin_
163  >> dummy >> radMax_
164  >> dummy >> fixedParticleRadius_
165  >> dummy >> inflowVelocity_
166  >> dummy >> inflowVelocityVariance_;
167 }
168 
173 void ChuteInsertionBoundary::oldRead(std::istream& is)
174 {
175  unsigned int maxFailed;
176  std::string dummy;
177  is >> dummy >> maxFailed
178  >> dummy >> posMin_
179  >> dummy >> posMax_
180  >> dummy >> radMin_
181  >> dummy >> radMax_
182  >> dummy >> fixedParticleRadius_
183  >> dummy >> inflowVelocity_
184  >> dummy >> inflowVelocityVariance_;
185  setMaxFailed(maxFailed);
186 }
187 
192 void ChuteInsertionBoundary::write(std::ostream& os) const
193 {
195  os << " posMin " << posMin_
196  << " posMax " << posMax_
197  << " radMin " << radMin_
198  << " radMax " << radMax_
199  << " fixedParticleRadius " << fixedParticleRadius_
200  << " inflowVelocity " << inflowVelocity_
201  << " inflowVelocityVariance " << inflowVelocityVariance_;
202 
203 }
204 
210 {
211  return "ChuteInsertionBoundary";
212 }
213 
std::string getName() const override
Returns the name of the object.
Mdouble X
the vector components
Definition: Vector.h:65
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
ChuteInsertionBoundary()
Default constructor.
Mdouble radMin_
Minimum and maximum radii of the generated particles.
void setMaxFailed(unsigned int maxFailed)
Sets the number of times that the wall may fail to insert a particle.
Mdouble getRandomNumber()
This is a random generating routine can be used for initial positions.
Definition: RNG.cc:143
bool isEqual(Mdouble v1, Mdouble v2, Mdouble absError)
Compares the difference of two Mdouble with an absolute error, useful in UnitTests.
Boundary structure for boundaries used for insertion of particles.
void read(std::istream &is) override
reads boundary properties from istream
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 placeParticle(BaseParticle *p, RNG &random) override
double fixedParticleRadius_
radius of the fixed bottom particles, mean particle velocity in X-direction, and allowed maximum rand...
Vec3D posMin_
The two extremal corners of the cuboidal insertion boundary.
void write(std::ostream &os) const override
Writes the boundary's id_ and maxFailed_.
Mdouble getRadius() const
Returns the particle's radius.
Definition: BaseParticle.h:345
Mdouble Y
Definition: Vector.h:65
ChuteInsertionBoundary * copy() const override
Copy method; creates a copy on the heap.
void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
Used for modeling chute inflow. Inherits from InsertionBoundary.
void write(std::ostream &os) const override
writes boundary properties to ostream
Definition: Vector.h:49
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:65
MERCURY_DEPRECATED void oldRead(std::istream &is)
deprecated version of CubeInsertionBoundary::read().
void read(std::istream &is) override
Reads the boundary's id_ and maxFailed_.