MercuryDPM  Trunk
 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-2020, 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 
72 void InfiniteWallWithHole::set(Vec3D normal, Mdouble position, Mdouble holeRadius)
73 {
74  //factor is used to set n to unit length
75  factor_ = 1. / sqrt(Vec3D::dot(normal, normal));
76  normal_ = normal * factor_;
77  position_ = position * factor_;
78  holeRadius_ = holeRadius;
79 }
80 
83 {
84  position_ = position * factor_;
85 }
86 
89 //void InfiniteWallWithHole::move(Vec3D velocity, Mdouble dt)
90 //{
91 // setVelocity(velocity);
92 // position_ += Vec3D::dot(getVelocity(), normal_) * dt;
93 //}
94 
98 {
100 }
101 
104 {
105  return position_ - Vec3D::dot(position, normal_);
106 }
107 
109 {
110  return holeRadius_ - sqrt(pow(position.X, 2) + pow(position.Y, 2));
111 }
112 
114 bool InfiniteWallWithHole::getDistanceAndNormal(const BaseParticle& P, Mdouble& distance, Vec3D& normal_return) const
115 {
116  double wallDistance = getWallDistance(P.getPosition());
117  if (wallDistance >= P.getRadius())
118  return false;
119 
120  double holeDistance = getHoleDistance(P.getPosition());
121  if (holeDistance >= P.getRadius())
122  return false;
123 
124  if (wallDistance > 0 && holeDistance > 0)
125  {
126  distance = sqrt(pow(wallDistance, 2) + pow(holeDistance, 2));
127  Vec3D ContactPoint;
128  double alpha = atan2(P.getPosition().Y, P.getPosition().X);
129  ContactPoint.X = holeRadius_ * cos(alpha);
130  ContactPoint.Y = holeRadius_ * sin(alpha);
131  ContactPoint.Z = position_;
132  //std::cout<<"ContactPoint="<<ContactPoint<<" Particle position="<<P.getPosition()<<std::endl;
133  normal_return = ContactPoint - P.getPosition();
134  normal_return /= normal_return.getLength();
135  //std::cout<<"Corner collision normal="<<normal_return<<std::endl;
136  return true;
137  }
138  else if (wallDistance > holeDistance)
139  {
140  distance = wallDistance;
141  normal_return = normal_;
142  //std::cout<<"Wall collision normal="<<normal_return<<std::endl;
143  return true;
144  }
145  else
146  {
147  distance = holeDistance;
148  normal_return.X = P.getPosition().X / (holeRadius_ - holeDistance);
149  normal_return.Y = P.getPosition().Y / (holeRadius_ - holeDistance);
150  normal_return.Z = 0;
151  //std::cout<<"Hole collision normal="<<normal_return<<std::endl;
152  return true;
153  }
154 }
155 
156 void InfiniteWallWithHole::read(std::istream& is)
157 {
158  BaseWall::read(is);
159  std::string dummy;
160  is >> dummy >> normal_
161  >> dummy >> factor_
162  >> dummy >> position_
163  >> dummy >> holeRadius_;
164 }
165 
167 void InfiniteWallWithHole::oldRead(std::istream& is)
168 {
169  std::string dummy;
170  Vec3D velocity;
171  is >> dummy >> normal_ >> dummy >> position_ >> dummy >> velocity;
172  setVelocity(velocity);
173 }
174 
176 void InfiniteWallWithHole::write(std::ostream& os) const
177 {
178  BaseWall::write(os);
179  os << " normal " << normal_
180  << " factor " << factor_
181  << " position " << position_
182  << " holeRadius " << holeRadius_;
183 }
184 
185 std::string InfiniteWallWithHole::getName() const
186 {
187  return "InfiniteWallWithHole";
188 }
189 
192 {
193  return normal_;
194 }
195 
198 {
199  return position_;
200 }
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Mdouble X
the vector components
Definition: Vector.h:65
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
void write(std::ostream &os) const override
outputs wall
double Mdouble
Definition: GeneralDefine.h:34
std::string getName() const override
Returns the name of the object.
void write(std::ostream &os) const override
Function that writes a BaseWall to an output stream, usually a restart file.
Definition: BaseWall.cc:102
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:76
void oldRead(std::istream &is)
reads wall
Vec3D normal_
Outward normal vector, does not have to be a unit vector.
InfiniteWallWithHole()
default constructor
static Mdouble getLength(const Vec3D &a)
Calculates the length of a Vec3D: .
Definition: Vector.cc:331
Mdouble cos(Mdouble x)
Definition: ExtendedMath.cc:64
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
InfiniteWallWithHole * copy() const override
Wall copy method. It calls the copy contrustor of this Wall, usefull for polymorfism.
Mdouble sin(Mdouble x)
Definition: ExtendedMath.cc:44
bool getDistanceAndNormal(const BaseParticle &P, Mdouble &distance, Vec3D &normal_return) const override
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.
Mdouble position_
position n*x=p
Mdouble getRadius() const
Returns the particle's radius.
Definition: BaseParticle.h:345
Basic class for walls.
Definition: BaseWall.h:47
void read(std::istream &is) override
Function that reads a BaseWall from an input stream, usually a restart file.
Definition: BaseWall.cc:80
Vec3D getNormal()
access function for normal
Mdouble Y
Definition: Vector.h:65
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.
Definition: Vector.h:49
void moveTo(Mdouble position)
Allows the wall to be moved to a new position.
void read(std::istream &is) override
reads wall
Mdouble Z
Definition: Vector.h:65
Mdouble getWallDistance(const Vec3D &position) const
Returns the distance of the wall to the particle.