MercuryDPM  0.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InsertionBoundary.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 BOUNDARIES_INSERTIONBOUNDARY_H
27 #define BOUNDARIES_INSERTIONBOUNDARY_H
28 
29 #include "../BaseWall.h"
30 
32 {
33  public:
34  virtual InsertionBoundary* copy() const
35  {
36  #ifdef CONSTUCTOR_OUTPUT
37  cerr << "virtual InsertionBoundary* copy() const finished" << endl;
38  #endif
39  return new InsertionBoundary(*this);
40  }
41 
42  void set(Vec3D posMin, Vec3D posMax, Vec3D velMin, Vec3D velMax, Mdouble radMin, Mdouble radMax, int maxFailed)
43  {
44  posMin_=posMin;
45  posMax_=posMax;
46  velMin_=velMin;
47  velMax_=velMax;
48  radMin_=radMin;
49  radMax_=radMax;
50  maxFailed_=maxFailed;
51  }
52 
54  {
55  int failed = 0;
56  BaseParticle p0;
57  bool isInsertable;
58  Mdouble distance;
59  Vec3D normal;
60  //try max_failed times to find new insertable particle
61  while (failed<=maxFailed_)
62  {
63  std::cout << "I" << std::endl;
64  //Set random radius, position and velocity
65  p0.set_Radius(random.get_RN(radMin_,radMax_));
66  p0.set_Mass(1.0);
67  p0.set_inertia(1.0);
68  Vec3D position;
69  position.X = random.get_RN(posMin_.X,posMax_.X);
70  position.Y = random.get_RN(posMin_.Y,posMax_.Y);
71  position.Z = random.get_RN(posMin_.Z,posMax_.Z);
72  Vec3D velocity;
73  velocity.X = random.get_RN(velMin_.X,velMax_.X);
74  velocity.Y = random.get_RN(velMin_.Y,velMax_.Y);
75  velocity.Z = random.get_RN(velMin_.Z,velMax_.Z);
76  p0.set_Position(position);
77  p0.set_Velocity(velocity);
78  // p0.set_Position(Vec3D(random.get_RN(posMin_.X,posMax_.X),random.get_RN(posMin_.Y,posMax_.Y),random.get_RN(posMin_.Z,posMax_.Z)));
79  // p0.set_Velocity(Vec3D(random.get_RN(velMin_.X,velMax_.X),random.get_RN(velMin_.Y,velMax_.Y),random.get_RN(velMin_.Z,velMax_.Z)));
80 
81  isInsertable=true;
82 
83 // cout<<"Particle to insert "<<p0<<endl;
84  //Check if it has no collision with walls
85  for(std::vector<BaseWall*>::iterator it=wH.begin();isInsertable&&it!=wH.end();it++)
86  {
87  (*it)->get_distance_and_normal(p0,distance,normal);
88  if(distance<p0.get_Radius())
89  {
90  // cout<<"Collision with wall "<<**it<<endl;
91  isInsertable=false;
92  }
93  else
94  {
95 // cout<<"No collision with wall "<<**it<<endl;
96  }
97  }
98  //Check if it has no collision with other particles
99  for(std::vector<BaseParticle*>::iterator it=pH.begin();isInsertable&&it!=pH.end();it++)
100  {
101  if(GetDistance2(p0.get_Position(),(*it)->get_Position())<sqr(p0.get_Radius()+(*it)->get_Radius()))
102  {
103  // cout<<"Collision with particle "<<**it<<endl;
104  isInsertable=false;
105  }
106  else
107  {
108 // cout<<"No collision with particle "<<**it<<endl;
109  }
110  }
111 
112  if (isInsertable)
113  {
114  //Still needs to set a lot of things like mass and HGRID stuff
115  // cout<<"Inserting particle"<<endl;
116  pH.copyAndAddObject(p0);
117  failed = 0;
118  }
119  else
120  {
121 // cout<<"Not inserting particle"<<endl;
122  failed++;
123  }
124  }
125  };
126 
128  void read(std::istream& is) {
129  std::string dummy;
130  is >> dummy >> posMin_ >> dummy >> posMax_ >> dummy >> velMin_ >> dummy >> velMax_ >> dummy >> radMin_ >> dummy >> radMax_ >> dummy >> maxFailed_;
131  }
132 
134  void print(std::ostream& os) const {
135  os << "InsertionBoundary posMin " << posMin_
136  << " posMax " << posMax_
137  << " velMin " << velMin_
138  << " velMax " << velMax_
139  << " radMin " << radMin_
140  << " radMax " << radMax_
141  << " maxFailed " << maxFailed_;
142  }
143 
144 
149 };
150 
151 #endif
void set_inertia(const Mdouble _new)
Mdouble X
Definition: Vector.h:44
void set(Vec3D posMin, Vec3D posMax, Vec3D velMin, Vec3D velMax, Mdouble radMin, Mdouble radMax, int maxFailed)
void copyAndAddObject(const T &O)
Creates a copy of a Object and adds it to the BaseHandler.
Definition: BaseHandler.h:93
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
Mdouble get_RN(Mdouble min, Mdouble max)
This is a random generating routine can be used for initial positions.
Definition: RNG.cc:32
#define sqr(a)
Definition: ExtendedMath.h:36
Mdouble get_Radius() const
This is a class that generates random numbers i.e.
Definition: RNG.h:38
const std::vector< BaseWall * >::const_iterator begin() const
Gets the begin of the const_iterator over all BaseWall in this WallHandler.
Definition: WallHandler.cc:242
const std::vector< BaseWall * >::const_iterator end() const
Gets the end of the const_iterator over all BaseWall in this WallHandler.
Definition: WallHandler.cc:254
double Mdouble
Definition: ExtendedMath.h:33
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
const Vec3D & get_Position() const
Container to store all BaseParticle.
Mdouble Y
Definition: Vector.h:44
void set_Radius(const Mdouble _new)
Container to store all BaseWall.
Definition: WallHandler.h:36
void set_Velocity(const Vec3D &_new)
virtual InsertionBoundary * copy() const
BaseBoundary copy method.
void print(std::ostream &os) const
outputs wall
void read(std::istream &is)
reads wall
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:40
void set_Position(const Vec3D &_new)
Mdouble Z
Definition: Vector.h:44
virtual void checkBoundaryActionsBeforeTimeStep(ParticleHandler &pH, WallHandler &wH, RNG &random)
void set_Mass(const Mdouble _new)