MercuryDPM  0.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InfiniteWallWithHole.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 
30 
31 #ifndef INFINITEWALLWITHHOLE_H
32 #define INFINITEWALLWITHHOLE_H
33 
43 {
44  public:
46  {
48  #ifdef CONSTUCTOR_OUTPUT
49  std::cout<<"InfiniteWall () finished"<<std::endl;
50  #endif
51  }
52 
54  {
55  this->normal=normal;
56  this->position=position;
57  this->holeRadius=holeRadius;
59  #ifdef CONSTUCTOR_OUTPUT
60  std::cout<<"InfiniteWallWithHole(Vec3D normal, Mdouble position, Mdouble holeRadius) finished"<<std::endl;
61  #endif
62  }
63 
65  {
66  normal=p.normal;
68  factor=p.factor;
71  #ifdef CONSTUCTOR_OUTPUT
72  std::cout<<"InfiniteWall (const InfiniteWall &p) finished"<<std::endl;
73  #endif
74  }
75 
78  {
79  return new InfiniteWallWithHole(*this);
80  }
81 
82  void clear()
83  {
84  indSpecies = 0;
86  }
87 
89  void set(Vec3D normal_, Mdouble position_, Mdouble holeRadius_)
90  {
91  //factor is used to set n to unit length
92  factor = 1. / sqrt(Dot(normal_, normal_));
93  normal = normal_ * factor;
94  position = position_ * factor;
95  holeRadius=holeRadius_;
96  }
97 
99  void move(Mdouble position_) {
100  position=position_*factor;
101  }
102 
104  void move(Vec3D velocity_, Mdouble dt) {
105  velocity=velocity_;
106  position+=Dot(velocity,normal)*dt;
107  }
108 
110  void move_time(Mdouble dt) {
111  position+=Dot(velocity,normal)*dt;
112  }
113 
115  Mdouble get_wallDistance(const Vec3D &Position) {return position - Dot(Position, normal);}
116 
117  Mdouble get_holeDistance(const Vec3D &Position) {return holeRadius-sqrt(pow(Position.X,2)+pow(Position.Y,2));}
118 
120  bool get_distance_and_normal(BaseParticle &P, Mdouble &distance, Vec3D &normal_return)
121  {
122  double wallDistance = get_wallDistance(P.get_Position());
123  if (wallDistance>=P.get_Radius())
124  return false;
125 
126  double holeDistance=get_holeDistance(P.get_Position());
127  if (holeDistance>=P.get_Radius())
128  return false;
129 
130 
131  if(wallDistance>0&&holeDistance>0)
132  {
133  distance=sqrt(pow(wallDistance,2)+pow(holeDistance,2));
134  Vec3D ContactPoint;
135  double alpha=atan2(P.get_Position().Y,P.get_Position().X);
136  ContactPoint.X=holeRadius*cos(alpha);
137  ContactPoint.Y=holeRadius*sin(alpha);
138  ContactPoint.Z=position;
139  //std::cout<<"ContactPoint="<<ContactPoint<<" Particle position="<<P.get_Position()<<std::endl;
140  normal_return=ContactPoint-P.get_Position();
141  normal_return/=normal_return.GetLength();
142  //std::cout<<"Corner collision normal="<<normal_return<<std::endl;
143  return true;
144  }
145  else if(wallDistance>holeDistance)
146  {
147  distance=wallDistance;
148  normal_return = normal;
149  //std::cout<<"Wall collision normal="<<normal_return<<std::endl;
150  return true;
151  }
152  else
153  {
154  distance=holeDistance;
155  normal_return.X=P.get_Position().X/(holeRadius-holeDistance);
156  normal_return.Y=P.get_Position().Y/(holeRadius-holeDistance);;
157  normal_return.Z=0;
158  //std::cout<<"Hole collision normal="<<normal_return<<std::endl;
159  return true;
160  }
161  }
162 
164  void read(std::istream& is) {
165  std::string dummy;
166  is >> dummy >> normal >> dummy >> position >> dummy >> velocity;
167  }
168 
170  void print(std::ostream& os) const{
171  os << "InfiniteWallWithHole normal " << normal << " position " << position<< " holeRadius "<<holeRadius;
172  //optional output
173  if (velocity.GetLength2()) os << " velocity " << velocity;
174  }
175 
177  Vec3D get_Normal() {return normal;}
181  Vec3D get_Velocity() const {return velocity;}
183  void set_Velocity(Vec3D new_) {velocity = new_;}
184 
185 private:
186  Vec3D normal; //<outward unit normal vector
187  Mdouble position; //<position n*x=p
188  Mdouble factor; //<This is the normal to rescale to unit vectoers.
191 
192 };
193 
194 #endif
void read(std::istream &is)
reads wall
Mdouble X
Definition: Vector.h:44
void move(Vec3D velocity_, Mdouble dt)
Allows the wall to be moved to a new position (also orthogonal to the normal), and setting the veloci...
InfiniteWallWithHole(Vec3D normal, Mdouble position, Mdouble holeRadius)
Vec3D get_Velocity() const
access function for velocity
InfiniteWallWithHole * copy() const
Wall copy method. It calls the copy contrustor of this Wall, usefull for polymorfism.
friend Mdouble GetLength2(const Vec3D &A)
Definition: Vector.h:183
Mdouble get_Radius() const
void print(std::ostream &os) const
outputs wall
Mdouble get_Position()
access function for position
InfiniteWallWithHole(const InfiniteWallWithHole &p)
double Mdouble
Definition: ExtendedMath.h:33
Mdouble get_holeDistance(const Vec3D &Position)
void set_Velocity(Vec3D new_)
access function for velocity
const Vec3D & get_Position() const
Mdouble Y
Definition: Vector.h:44
bool get_distance_and_normal(BaseParticle &P, Mdouble &distance, Vec3D &normal_return)
Since this function should be called before calculating any Particle-Wall interactions, it can also be used to set the normal vector in case of curved walls.
void set_zero()
Definition: Vector.h:55
Vec3D velocity
velocity of the wall (used to calculate the relative velocity in the force calculation) ...
void move_time(Mdouble dt)
Allows the wall to be moved with time.
int indSpecies
Definition: BaseWall.h:36
Mdouble GetLength() const
Definition: Vector.h:248
Vec3D get_Normal()
access function for normal
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:40
void move(Mdouble position_)
Allows the wall to be moved to a new position.
Mdouble Z
Definition: Vector.h:44
This is a class defining walls.
void set(Vec3D normal_, Mdouble position_, Mdouble holeRadius_)
Defines a standard wall, given an outward normal vector s. t. normal*x=position.
Mdouble get_wallDistance(const Vec3D &Position)
Returns the distance of the wall to the particle.