MercuryDPM  Beta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HopperInsertionBoundary.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 
27 #include "Particles/BaseParticle.h"
28 #include "Math/RNG.h"
29 
35 {
36  yMin_ = 0.0;
37  yMax_ = 0.0;
38  radMin_ = 0.0;
39  radMax_ = 0.0;
40  chuteAngle_ = 0.0;
42  isHopperCentred__ = true;
43  hopperDim_ = 0;
44  hopperAngle_ = 0.0;
45  hopperLength_ = 0.0;
46  hopperExitLength_ = 0.0;
47  hopperHeight_ = 0.0;
48  lift_ = 0.0;
49  fillPercent_ = 0.0;
50 }
51 
56  : InsertionBoundary(other)
57 {
58  yMin_ = other.yMin_;
59  yMax_ = other.yMax_;
60  radMin_ = other.radMin_;
61  radMax_ = other.radMax_;
62  chuteAngle_ = other.chuteAngle_;
65  hopperDim_ = other.hopperDim_;
66  hopperAngle_ = other.hopperAngle_;
70  lift_ = other.lift_;
71  fillPercent_ = other.fillPercent_;
72 }
73 
79 {
80 #ifdef DEBUG_CONSTRUCTOR
81  std::cout << "HopperInsertionBoundary::copy() const finished" << std::endl;
82 #endif
83  return new HopperInsertionBoundary(*this);
84 }
85 
123 void HopperInsertionBoundary::set(BaseParticle* particleToCopy, int maxFailed, double yMin,
124  double yMax, double radMin, double radMax, double chuteAngle, double fixedParticleRadius,
125  bool isHopperCentred_, int hopperDim, double hopperAngle, double hopperLength,
126  double hopperExitLength, double hopperHeight, double lift, double fillPercent)
127 {
128  setParticleToCopy(particleToCopy);
129  setMaxFailed(maxFailed);
130  yMin_ = yMin;
131  yMax_ = yMax;
132  radMin_ = radMin;
133  radMax_ = radMax;
134  chuteAngle_ = chuteAngle;
135  fixedParticleRadius_ = fixedParticleRadius;
136  isHopperCentred__ = isHopperCentred_;
137  hopperDim_ = hopperDim;
138  hopperAngle_ = hopperAngle;
139  hopperLength_ = hopperLength;
140  hopperExitLength_ = hopperExitLength;
141  hopperHeight_ = hopperHeight;
142  lift_ = lift;
143  fillPercent_ = fillPercent;
144 }
145 
180 {
181  // create particle and assign a random radius
184 
185  //Define an orthogonal coordinate system this is useful in the hopper, see
186  //diagram in html documentation for details.
187  static Mdouble s = sin(chuteAngle_);
188  static Mdouble c = cos(chuteAngle_);
189  static Mdouble Ht = tan(hopperAngle_);
190  static Mdouble Hc = cos(hopperAngle_);
191  static Vec3D AB = Vec3D(c, 0.0, s);
192  static Vec3D AC = Vec3D(-s, 0.0, c);
193  static Vec3D AD = Vec3D(0.0, 1.0, 0.0);
194 
195  //Point A is located in the centre of the hopper.
196  static Vec3D A = Vec3D(isHopperCentred__ ? 40 : 0.0,
197  (yMax_ - yMin_) / 2.0,
198  s * (-0.5 * (hopperLength_ - hopperExitLength_)) + c * hopperHeight_)
199  + AB * 0.5 * hopperLength_
200  + AC * (-0.5 * hopperLength_ / Ht);
201 
202  Mdouble gamma = random.getRandomNumber((100.0 - fillPercent_) / 100.0, 1.0);
203  //std::cout<<"gamma="<<gamma<<"fillPercent="<<fillPercent_<<std::endl;
204 
205  Mdouble delta;
206 
207  if (hopperDim_ == 1)
208  {
216  delta = random.getRandomNumber(-0.5, 0.5) * (yMax_ - yMin_ - 2.0 * P->getRadius());
222 
223  }
224  else
225  {
234  delta = (random.getRandomNumber(-1.0, 1.0) * (0.5 * gamma * hopperLength_ - P->getRadius() / Hc));
235  }
236  //std::cout<<A<<" "<<AC<<" "<<AB<<" "<<AD<<" "<<Hc<<" "<<Ht<<"gamma="<<gamma<<" "<<hopperLength_<<" "<<delta<<std::endl;
237  P->setPosition(A
238  + AC * (gamma * 0.5 * hopperLength_ / Ht)
239  + AB * (random.getRandomNumber(-1.0, 1.0) * (0.5 * gamma * hopperLength_ - P->getRadius() / Hc))
240  + AD * delta);
241 
242  P->move(Vec3D(0.0, 0.0, lift_));
243  P->setVelocity(Vec3D(0.0, 0.0, 0.0));
244 
245  return P;
246 }
247 
252 void HopperInsertionBoundary::read(std::istream& is)
253 {
255  std::string dummy;
256  is >> dummy >> yMin_
257  >> dummy >> yMax_
258  >> dummy >> radMin_
259  >> dummy >> radMax_
260  >> dummy >> chuteAngle_
261  >> dummy >> fixedParticleRadius_
262  >> dummy >> isHopperCentred__
263  >> dummy >> hopperDim_
264  >> dummy >> hopperAngle_
265  >> dummy >> hopperLength_
266  >> dummy >> hopperExitLength_
267  >> dummy >> hopperHeight_
268  >> dummy >> lift_
269  >> dummy >> fillPercent_;
270 }
271 
276 void HopperInsertionBoundary::oldRead(std::istream& is)
277 {
278  int maxFailed;
279  std::string dummy;
280  is >> dummy >> maxFailed
281  >> dummy >> yMin_
282  >> dummy >> yMax_
283  >> dummy >> radMin_
284  >> dummy >> radMax_
285  >> dummy >> chuteAngle_
286  >> dummy >> fixedParticleRadius_
287  >> dummy >> isHopperCentred__
288  >> dummy >> hopperDim_
289  >> dummy >> hopperAngle_
290  >> dummy >> hopperLength_
291  >> dummy >> hopperExitLength_
292  >> dummy >> hopperHeight_
293  >> dummy >> lift_
294  >> dummy >> fillPercent_;
295  setMaxFailed(maxFailed);
296 }
297 
302 void HopperInsertionBoundary::write(std::ostream& os) const
303  {
305  os << " yMin " << yMin_
306  << " yMax " << yMax_
307  << " radMin " << radMin_
308  << " radMax " << radMax_
309  << " chuteAngle " << chuteAngle_
310  << " fixedParticleRadius " << fixedParticleRadius_
311  << " isHopperCentred_ " << isHopperCentred__
312  << " hopperDim " << hopperDim_
313  << " hopperAngle " << hopperAngle_
314  << " hopperLength " << hopperLength_
315  << " hopperExitLength " << hopperExitLength_
316  << " hopperHeight " << hopperHeight_
317  << " lift " << lift_
318  << " fillPercent " << fillPercent_;
319 }
320 
326 {
327  return "HopperInsertionBoundary";
328 }
329 
double hopperExitLength_
The horizontal (AB-direction) width at the square exit of the hopper.
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
double radMin_
Minimum and maximum radii of the inserted particles.
virtual std::string getName() const
Returns the name of the object.
MERCURY_DEPRECATED void oldRead(std::istream &is)
deprecated version of CubeInsertionBoundary::read().
double Mdouble
double hopperHeight_
The vertical (AC-direction) height of the hopper, measured from the top of the hopper to the start of...
double hopperLength_
The horizontal (AB-direction) width at the top of the hopper.
void setMaxFailed(unsigned int maxFailed)
Sets the number of times that the wall may fail to insert a particle.
int hopperDim_
Either 1 or 2. If 1, the insertion boundary has vertical walls in the y extrema. This is used e...
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
HopperInsertionBoundary()
Default constructor. Sets all properties to 0.
void write(std::ostream &os) const
writes boundary properties to ostream
virtual HopperInsertionBoundary * copy() const
copy method, returns a pointer to a copy.
double hopperAngle_
Angle of the hopper as compared to the vertical plane.
BaseParticle * getParticleToCopy() const
Gets the particle that will be inserted through the insertion boundary.
Mdouble getRadius() const
Returns the particle's radius_.
double chuteAngle_
Angle of the chute as compared to the horizontal plane.
void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
Inherits from InsertionBoundary Some images are useful to better understand the structure of both the...
Mdouble gamma(Mdouble gamma_in)
This is the gamma function returns the true value for the half integer value.
Definition: ExtendedMath.cc:47
void set(BaseParticle *particleToCopy, int maxFailed, double yMin, double yMax, double radMin, double radMax, double chuteAngle, double fixedParticleRadius, bool isHopperCentred_, int hopperDim, double hopperAngle, double hopperLength, double hopperExitLength, double hopperHeight, double lift, double fillPercent)
Sets all boundary properties at once.
void read(std::istream &is)
Reads the boundary's id_ and maxFailed_.
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
virtual void move(const Vec3D &move)
Moves this BaseInteractable by adding an amount to the position.
double yMin_
The minimum and maximum y-positions of the particle for a hopper with vertical walls in the y-directi...
void read(std::istream &is)
reads boundary properties from istream
void write(std::ostream &os) const
Writes the boundary's id_ and maxFailed_.
double fillPercent_
Percentage of the height of the insertion boundary up to which it should be filled. The part to be filled reaches from the top of the hopper down to {fillPercent * (top - 'position A')}.
virtual BaseParticle * generateParticle(RNG &random)
This creates an inflow particle in the top 50% of the hopper i.e. between gamma=0.5 and gamma=1.0.
Mdouble getRandomNumber(Mdouble min, Mdouble max)
This is a random generating routine can be used for initial positions.
Definition: RNG.cc:69
virtual BaseParticle * copy() const
Particle copy method. It calls to copy constructor of this Particle, useful for polymorfism.