MercuryDPM  0.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ChuteBottom.h
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 #ifndef CHUTEBOTTOM_H
27 #define CHUTEBOTTOM_H
28 #include "Chute.h"
29 
36 class ChuteBottom : public Chute {
37 
38 public:
41 
43  ChuteBottom(MD& other) : MD(other), Chute(other) {constructor();}
44  ChuteBottom(HGRID_base& other) : MD(other), Chute(other) {constructor();}
45  ChuteBottom(HGRID_3D& other) : MD(other), Chute(other) {constructor();}
46  ChuteBottom(Chute& other) : MD(other), Chute(other) {constructor();}
47 
49  void constructor(){
50  set_name("roughbottom");
51  set_options_fstat(0); //set to 0 for no data creation
54  set_thickness(2.4);
55  set_periodicbottom(true);
56  }
57 
58  void make_rough_bottom(ParticleHandler& ChuteParticleHandler)
59  {
60  // set all parameters that should be different from the original chute
61  set_ChuteAngle(0.0);
63  //~ set_InflowHeight(45.*get_InflowParticleRadius()); note: Changing the Inflow height was an attempt to make the bottom density homogeneous, but it did not have the desired effect
66 
68  set_mu(0);
69 
70  set_dt();
71  set_dt(get_dt()*10.0);
72  set_tmax(get_dt()*2e3);
73  //set_number_of_saves(2);
74  set_savecount(100);
75 
76  //solve
77  solve();
78 
79  //create_bottom
80  Mdouble height = 0;
81  for (std::vector<BaseParticle*>::iterator it=getParticleHandler().begin(); it!=getParticleHandler().end(); it++) {
82  height = std::max(height,(*it)->get_Position().Z);
83  }
84 
85  std::cout << "Thickness" << thickness << std::endl;
87  //now cut a slice of width 2*MaxInflowParticleRadius
88  for (std::vector<BaseParticle*>::iterator it=getParticleHandler().begin(); it!=getParticleHandler().end();)
89  {
90  if ((*it)->get_Position().Z < height - (1.0+thickness)*MaxInflowParticleRadius || (*it)->get_Position().Z > height - MaxInflowParticleRadius) {
91  //delete particles outside the given range
92  //*it = getParticleHandler().back();
93  //getParticleHandler().removeLastObject();
94  getParticleHandler().removeObject((*it)->get_Index());
95  } else {
96  //fix the remaining particles on the floor
97 
98  //(*it)->get_Position().Z -= height - MaxInflowParticleRadius;
99  (*it)->move(Vec3D(0.0,0.0,MaxInflowParticleRadius-height));
100 
101  (*it)->fixParticle();
102  it++;
103  }
104  }
105 
106  //copy the rough bottom over
107  ChuteParticleHandler.setStorageCapacity(getParticleHandler().getNumberOfObjects());
108  std::cout << "Chute bottom finished, consisting of " << getParticleHandler().getNumberOfObjects() << " Particles" << std::endl;
109 
110  ChuteParticleHandler = getParticleHandler();
111  }
112 
114 
115 
117 
118 
119  create_bottom();
120 
122  getWallHandler().clear();
124  if (periodicbottom) {
125  InfiniteWall w0;
126  w0.set(Vec3D(0.0, 0.0, -1.0), -get_zmin()+get_InflowParticleRadius());
128  PeriodicBoundary b0;
129  b0.set(Vec3D( 1.0, 0.0, 0.0), get_xmin(), get_xmax());
131  b0.set(Vec3D( 0.0, 1.0, 0.0), get_ymin(), get_ymax());
133  } else {
134  InfiniteWall w0;
135  w0.set(Vec3D(0.0, 0.0, -1.0), -get_zmin()+get_InflowParticleRadius());
137  w0.set(Vec3D(-1.0, 0.0, 0.0), -get_xmin());
139  w0.set(Vec3D( 1.0, 0.0, 0.0), get_xmax());
141  w0.set(Vec3D( 0.0,-1.0, 0.0), -get_ymin());
143  w0.set(Vec3D( 0.0, 1.0, 0.0), get_ymax());
145  }
146 
147  //add particles
149  int failed = 0, max_failed = 500;
150  //try max_failed times to find new insertable particle
151  while (failed<=max_failed){
154 
155  //The position components are first stored in a Vec3D, because if you pass them directly into set_Position the compiler is allowed to change the order in which the numbers are generated
156  Vec3D position;
157  position.X=random.get_RN( P0.get_Radius(), get_xmax()-P0.get_Radius());
158  position.Y=random.get_RN( P0.get_Radius(), get_ymax()-P0.get_Radius());
159  position.Z=random.get_RN(2*P0.get_Radius(), get_zmax()-P0.get_Radius());
160  P0.set_Position(position);
161  P0.set_Velocity(Vec3D(0.0,0.0,0.0));
162 
163  if (IsInsertable(P0))
164  {
165  failed = 0;
167  /*if (Particles.capacity()==Particles.size())
168  {
169 
170  std::cerr << "Error in creating bottom; exceeded capacity: " << Particles.size() << std::endl; exit(-1);
171  }*/
172  //Particles.push_back (P0);
173  //Undate the link list so this particle is back in the grid
174  //grid->objectBucket[Particles[Particles.size()-1].bucket] = Particles.size()-1;
175  //grid->objectBucket[Particles[Particles.size()-1].bucket] = &Particles[Particles.size()-1];
176  num_created++;
177  }
178  else failed++;
179  }
180  //set_Nmax(getParticleHandler().getNumberOfObjects());
181  std::cout << "N=" << getParticleHandler().getNumberOfObjects() << std::endl;
182 
183  //fix hgrid (there is still an issue when particles are polydispersed)
184  //assume 1-2 levels are optimal (which is the case for mono and bidispersed) and set the cell size to min and max
185  // !this is not optimal for polydispersed
188  if ((minCell==maxCell)|(minCell==0.)) setHGridMaxLevels(1);
189  else setHGridMaxLevels(2);
190 // set_HGRID_cell_to_cell_ratio (1.0000000001*maxCell/minCell);
191  //optimize number of buckets
192  set_HGRID_num_buckets_to_power(getParticleHandler().getNumberOfObjects()*1.5);
193  //end: fix hgrid
194 
195  //~ info();
196  }
197 
199 
201  void set_thickness(Mdouble new_){
202  if (new_>0.0) thickness=new_;
203  else {std::cerr<<"Error: thickness " << new_ << " negative"<<std::endl; exit(-1);}
204  }
206  void set_periodicbottom(bool new_){periodicbottom=new_;}
207 
208 private:
211 };
212 #endif
Mdouble get_zmin()
Gets zmin.
Definition: MD.h:313
This is the base class for both HGRID_2D and HGRID_3D.
Definition: HGRID_base.h:43
Mdouble X
Definition: Vector.h:44
ChuteBottom()
This is the default constructor. All it does is set sensible defaults.
Definition: ChuteBottom.h:40
void set_HGRID_num_buckets_to_power()
set number of buckets to the smallest power of two bigger than the number of particles ...
Definition: HGRID_base.cc:84
void compute_particle_mass(std::vector< CSpecies > &Species)
Compute Particle mass function, which required a reference to the Species vector. It copmuters the Pa...
Mdouble get_dt()
Allows the time step dt to be accessed.
Definition: MD.h:339
void copyAndAddObject(const T &O)
Creates a copy of a Object and adds it to the BaseHandler.
Definition: BaseHandler.h:93
ChuteBottom(HGRID_3D &other)
Definition: ChuteBottom.h:45
void setStorageCapacity(const unsigned int N)
Sets the storage capacity of this BaseHandler.
Definition: BaseHandler.h:213
void set_options_data(unsigned int new_)
Definition: STD_save.h:161
void set_options_restart(unsigned int new_)
Definition: STD_save.h:167
void set_savecount(int new_)
Allows the number of time steps between saves to be changed, see also set_number_of_saves.
Definition: MD.h:155
const std::vector< T * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
Definition: BaseHandler.h:220
Used by Chute::create_bottom to create an unordered particle layer.
Definition: ChuteBottom.h:36
Mdouble get_RN(Mdouble min, Mdouble max)
This is a random generating routine can be used for initial positions.
Definition: RNG.cc:32
void setHGridMaxLevels(int HGridMaxLevels)
Definition: HGRID_base.cc:328
int max_failed
Definition: Chute.h:259
void make_rough_bottom(ParticleHandler &ChuteParticleHandler)
Definition: ChuteBottom.h:58
Mdouble get_MinInflowParticleRadius()
Allows radius of inflow particles to be accessed.
Definition: Chute.h:134
void set_tmax(Mdouble new_tmax)
Allows the upper time limit to be changed.
Definition: MD.h:142
ChuteBottom(MD &other)
Copy-constructor for creates an HGRID problem from an existing MD problem.
Definition: ChuteBottom.h:43
void set_ChuteAngle(Mdouble new_)
Sets gravity vector according to chute angle (in degrees)
Definition: Chute.h:102
std::vector< CSpecies > Species
These are the particle parameters like dissipation etc.
Definition: MD.h:655
void solve()
The work horse of the code.
Definition: MD.cc:2266
#define cubic(a)
Definition: ExtendedMath.h:37
void set_periodicbottom(bool new_)
Definition: ChuteBottom.h:206
void set_InflowHeight(Mdouble new_)
Changes inflow height.
Definition: Chute.h:139
ChuteBottom(HGRID_base &other)
Definition: ChuteBottom.h:44
RNG random
Definition: MD.h:515
Mdouble get_ymax()
Gets ymax.
Definition: MD.h:311
Mdouble get_periodicbottom()
Definition: ChuteBottom.h:205
void set_dt()
Sets dt to 1/50-th of the collision time for two particles of mass P.
Definition: Chute.h:202
Mdouble thickness
Definition: ChuteBottom.h:209
Mdouble get_Radius() const
Defines a pair of periodic walls. The particles are in {x: position_left<=normal*x
int num_created
Definition: Chute.h:260
void constructor()
This is the actual constructor it is called do both constructors above.
Definition: ChuteBottom.h:49
void set_options_fstat(unsigned int new_)
set and get for file options
Definition: STD_save.h:158
bool periodicbottom
Definition: ChuteBottom.h:210
Chute adds three new effects to the HGrid: the gravity direction can be set using the ChuteAngle vari...
Definition: Chute.h:34
This adds on the hierarchical grid code for 3D problems.
Definition: HGRID_3D.h:35
virtual void create_bottom()
Create the bottom of chute out of particles.
Definition: Chute.cc:254
WallHandler & getWallHandler()
Definition: MD.h:148
Mdouble get_ymin()
Gets ymin.
Definition: MD.h:309
Mdouble get_MaxInflowParticleRadius()
Allows radius of inflow particles to be accessed.
Definition: Chute.h:136
void set_RandomizedBottom(int new_)
Changes RandomizedBottom.
Definition: Chute.h:97
Mdouble get_xmin()
Get xmin.
Definition: MD.h:305
void copyAndAddWall(const BaseWall &B)
Creates a copy of a BaseWall and adds it to the WallHandler.
Definition: WallHandler.cc:84
double Mdouble
Definition: ExtendedMath.h:33
virtual bool IsInsertable(BaseParticle &P)
here, CheckObjects is called; returns true is the particle should be added
Definition: Chute.cc:388
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:233
void set_thickness(Mdouble new_)
Definition: ChuteBottom.h:201
TangentialSpringParticle P0
Definition: Chute.h:262
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
Definition: BaseHandler.h:199
void set_mu(Mdouble new_, unsigned int indSpecies=0)
Allows the Coulomb friction coefficient to be changed.
Definition: MD.h:245
void set(Vec3D normal_, Mdouble position_)
Defines a standard wall, given an outward normal vector s. t. normal*x=position.
Definition: InfiniteWall.h:75
Container to store all BaseParticle.
Mdouble Y
Definition: Vector.h:44
void actions_before_time_step()
This is action before the time step is started.
Definition: ChuteBottom.h:198
void set_Radius(const Mdouble _new)
void set_Velocity(const Vec3D &_new)
A class that defines and solves a MD problem.
Definition: MD.h:70
void set_name(const char *name)
Sets the name of the problem, used for the same data files.
Definition: MD.h:342
Mdouble FixedParticleRadius
Definition: Chute.h:250
Mdouble get_InflowParticleRadius()
Allows radius of inflow particles to be accessed.
Definition: Chute.h:132
Mdouble get_collision_time()
Calculates collision time of two inflow particles.
Definition: Chute.cc:165
BoundaryHandler & getBoundaryHandler()
Definition: MD.h:149
This is a class defining walls.
Definition: InfiniteWall.h:42
Mdouble MaxInflowParticleRadius
Definition: Chute.h:255
ParticleHandler & getParticleHandler()
Definition: MD.h:147
void set(Vec3D normal_, Mdouble position_left_, Mdouble position_right_)
Defines a periodic wall, given a normal vector s.t.
void setup_particles_initial_conditions()
initialize particle position, velocity, radius
Definition: ChuteBottom.h:113
Mdouble get_xmax()
Get xmax.
Definition: MD.h:307
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:40
virtual void removeObject(unsigned const int id)
Removes a Object from the BaseHandler.
Definition: BaseHandler.h:122
void set_Position(const Vec3D &_new)
void HGRID_actions_before_time_loop()
This sets up the broad phase information, has to be done at this stage becuase it requires the partcl...
Definition: HGRID_base.cc:66
Mdouble Z
Definition: Vector.h:44
ChuteBottom(Chute &other)
Definition: ChuteBottom.h:46
Mdouble get_zmax()
Gets zmax.
Definition: MD.h:315
void clear()
Empties the whole WallHandler by removing all BaseWall.
Definition: WallHandler.cc:127
void set_FixedParticleRadius(Mdouble new_)
Allows radius of fixed particles to be changed.
Definition: Chute.h:92
Mdouble get_thickness()
Definition: ChuteBottom.h:200
void set_collision_time_and_restitution_coefficient(Mdouble tc, Mdouble eps)
Sets k, disp such that it matches a given tc and eps for a collision of two inflow particles...
Definition: Chute.cc:157
void clear()
Empties the whole BaseHandler by removing all Object.
Definition: BaseHandler.h:162
Mdouble get_FixedParticleRadius()
Allows radius of fixed particles to be accessed.
Definition: Chute.h:94