MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InfiniteWallWithHole.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 
26 #include <limits>
27 
28 #include "InfiniteWallWithHole.h"
29 #include "InteractionHandler.h"
30 #include "Particles/BaseParticle.h"
31 
33  : BaseWall()
34 {
35  factor_=std::numeric_limits<double>::quiet_NaN();
36  position_=std::numeric_limits<double>::quiet_NaN();
37  holeRadius_=std::numeric_limits<double>::quiet_NaN();
38 #ifdef DEBUG_CONSTRUCTOR
39  std::cout<<"InfiniteWall () finished"<<std::endl;
40 #endif
41 }
42 
44  : BaseWall()
45 {
46  set(normal, position, holeRadius);
47 #ifdef DEBUG_CONSTRUCTOR
48  std::cout<<"InfiniteWallWithHole(Vec3D normal, Mdouble position, Mdouble holeRadius) finished"<<std::endl;
49 #endif
50 }
51 
53  : BaseWall(p)
54 {
55  normal_ = p.normal_;
56  position_ = p.position_;
57  factor_ = p.factor_;
59 #ifdef DEBUG_CONSTRUCTOR
60  std::cout<<"InfiniteWall (const InfiniteWall &p) finished"<<std::endl;
61 #endif
62 }
63 
66 {
67  return new InfiniteWallWithHole(*this);
68 }
69 
71 {
72 }
73 
76 void InfiniteWallWithHole::set(Vec3D normal, Mdouble position, Mdouble holeRadius)
77 {
78  //factor is used to set n to unit length
79  factor_ = 1. / sqrt(Vec3D::dot(normal, normal));
80  normal_ = normal * factor_;
81  position_ = position * factor_;
82  holeRadius_ = holeRadius;
83 }
84 
87 {
88  position_ = position * factor_;
89 }
90 
93 //void InfiniteWallWithHole::move(Vec3D velocity, Mdouble dt)
94 //{
95 // setVelocity(velocity);
96 // position_ += Vec3D::dot(getVelocity(), normal_) * dt;
97 //}
98 
102 {
104 }
105 
108 {
109  return position_ - Vec3D::dot(position, normal_);
110 }
111 
113 {
114  return holeRadius_ - sqrt(pow(position.X, 2) + pow(position.Y, 2));
115 }
116 
118 bool InfiniteWallWithHole::getDistanceAndNormal(const BaseParticle &P, Mdouble &distance, Vec3D &normal_return) const
119 {
120  double wallDistance = getWallDistance(P.getPosition());
121  if (wallDistance >= P.getRadius())
122  return false;
123 
124  double holeDistance = getHoleDistance(P.getPosition());
125  if (holeDistance >= P.getRadius())
126  return false;
127 
128  if (wallDistance > 0 && holeDistance > 0)
129  {
130  distance = sqrt(pow(wallDistance, 2) + pow(holeDistance, 2));
131  Vec3D ContactPoint;
132  double alpha = atan2(P.getPosition().Y, P.getPosition().X);
133  ContactPoint.X = holeRadius_ * cos(alpha);
134  ContactPoint.Y = holeRadius_ * sin(alpha);
135  ContactPoint.Z = position_;
136  //std::cout<<"ContactPoint="<<ContactPoint<<" Particle position="<<P.getPosition()<<std::endl;
137  normal_return = ContactPoint - P.getPosition();
138  normal_return /= normal_return.getLength();
139  //std::cout<<"Corner collision normal="<<normal_return<<std::endl;
140  return true;
141  }
142  else if (wallDistance > holeDistance)
143  {
144  distance = wallDistance;
145  normal_return = normal_;
146  //std::cout<<"Wall collision normal="<<normal_return<<std::endl;
147  return true;
148  }
149  else
150  {
151  distance = holeDistance;
152  normal_return.X = P.getPosition().X / (holeRadius_ - holeDistance);
153  normal_return.Y = P.getPosition().Y / (holeRadius_ - holeDistance);
154  normal_return.Z = 0;
155  //std::cout<<"Hole collision normal="<<normal_return<<std::endl;
156  return true;
157  }
158 }
159 
160 void InfiniteWallWithHole::read(std::istream& is)
161 {
162  BaseWall::read(is);
163  std::string dummy;
164  is >> dummy >> normal_
165  >> dummy >> factor_
166  >> dummy >> position_
167  >> dummy >> holeRadius_;
168 }
169 
171 void InfiniteWallWithHole::oldRead(std::istream& is)
172 {
173  std::string dummy;
174  Vec3D velocity;
175  is >> dummy >> normal_ >> dummy >> position_ >> dummy >> velocity;
176  setVelocity(velocity);
177 }
178 
180 void InfiniteWallWithHole::write(std::ostream& os) const
181  {
182  BaseWall::write(os);
183  os << " normal " << normal_
184  << " factor " << factor_
185  << " position " << position_
186  << " holeRadius " << holeRadius_;
187 }
188 
189 std::string InfiniteWallWithHole::getName() const
190 {
191  return "InfiniteWallWithHole";
192 }
193 
196 {
197  return normal_;
198 }
199 
202 {
203  return position_;
204 }
void write(std::ostream &os) const
outputs wall
void read(std::istream &is)
reads wall
Mdouble X
the vector components
Definition: Vector.h:52
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
bool getDistanceAndNormal(const BaseParticle &P, Mdouble &distance, Vec3D &normal_return) const
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.
double Mdouble
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:167
void oldRead(std::istream &is)
reads wall
Vec3D normal_
Outward normal vector, does not have to be a unit vector.
virtual std::string getName() const
Returns the name of the object.
InfiniteWallWithHole()
default constructor
void clear()
A function that removes all data from this BaseWall, so sets handler_ to nullptr. ...
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
static Mdouble getLength(const Vec3D &a)
Calculates the length of a Vec3D: .
Definition: Vector.cc:414
Mdouble cos(Mdouble x)
Definition: ExtendedMath.cc:60
void set(Vec3D normal, Mdouble position, Mdouble holeRadius)
Defines a standard wall, given an outward normal vector s. t. normal*x=position.
Mdouble getHoleDistance(const Vec3D &position) const
Mdouble sin(Mdouble x)
Definition: ExtendedMath.cc:42
InfiniteWallWithHole * copy() const
Wall copy method. It calls the copy contrustor of this Wall, usefull for polymorfism.
Mdouble position_
position n*x=p
Mdouble getRadius() const
Returns the particle's radius_.
Basic class for walls.
Definition: BaseWall.h:44
Vec3D getNormal()
access function for normal
Mdouble Y
Definition: Vector.h:52
Mdouble getPosition()
access function for position
void move_time(Mdouble dt)
Allows the wall to be moved to a new position (also orthogonal to the normal), and setting the veloci...
virtual const Vec3D & getVelocity() const
Returns the velocity of this interactable.
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
void moveTo(Mdouble position)
Allows the wall to be moved to a new position.
void write(std::ostream &os) const
Function that writes a BaseWall to an output stream, usually a restart file.
Definition: BaseWall.cc:68
Mdouble Z
Definition: Vector.h:52
Mdouble getWallDistance(const Vec3D &position) const
Returns the distance of the wall to the particle.
void read(std::istream &is)
Function that reads a BaseWall from an input stream, usually a restart file.
Definition: BaseWall.cc:60