MercuryDPM  Beta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CylindricalWall.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 "CylindricalWall.h"
29 #include "InteractionHandler.h"
30 #include "Particles/BaseParticle.h"
31 
33  : BaseWall()
34 {
35  radius_ = std::numeric_limits<double>::quiet_NaN();
36 #ifdef DEBUG_CONSTRUCTOR
37  std::cout<<"CylindricalWall () finished"<<std::endl;
38 #endif
39 }
40 
42  : BaseWall(p)
43 {
44  radius_ = p.radius_;
45 #ifdef DEBUG_CONSTRUCTOR
46  std::cout<<"CylindricalWall (const CylindricalWall &p) finished"<<std::endl;
47 #endif
48 }
49 
51  : BaseWall()
52 {
53  this->radius_ = radius;
54 #ifdef DEBUG_CONSTRUCTOR
55  std::cout<<"CylindricalWall (double radius) finished"<<std::endl;
56 #endif
57 }
58 
61 {
62  return new CylindricalWall(*this);
63 }
64 
66 {
67 }
68 
71 {
72  this->radius_ = radius;
73 }
74 
76 bool CylindricalWall::getDistanceAndNormal(const BaseParticle &P, Mdouble &distance, Vec3D &normal_return) const
77  {
78  double R = sqrt(pow(P.getPosition().X, 2) + pow(P.getPosition().Y, 2));
79  distance = radius_ - R;
80  if (distance >= P.getRadius())
81  return false;
82 
83  normal_return.X = P.getPosition().X;
84  normal_return.Y = P.getPosition().Y;
85  normal_return.Z = 0.0;
86  normal_return /= normal_return.getLength();
87 
88  return true;
89 }
90 
92 void CylindricalWall::read(std::istream& is)
93 {
94  BaseWall::read(is);
95  std::string dummy;
96  is >> dummy >> radius_;
97 }
98 
99 void CylindricalWall::oldRead(std::istream& is)
100 {
101  std::string dummy;
102  is >> dummy >> radius_;
103 }
104 
106 void CylindricalWall::write(std::ostream& os) const
107  {
108  BaseWall::write(os);
109  os << " radius " << radius_;
110 }
111 
112 std::string CylindricalWall::getName() const
113 {
114  return "CylindricalWall";
115 }
116 
119 {
120  return radius_;
121 }
122 
124 {
125  Mdouble distance;
126  Vec3D normal;
127  if (getDistanceAndNormal(*P,distance,normal))
128  {
129  BaseInteraction* C = interactionHandler->getInteraction(P, this, timeStamp);
130  C->setNormal(-normal);
131  C->setDistance(distance);
132  C->setOverlap(P->getRadius() - distance);
134  C->setContactPoint(P->getPosition() - (P->getRadius() - 0.5 * C->getOverlap()) * C->getNormal());
135  return C;
136  }
137  else
138  {
139  return 0;
140  }
141 }
void setNormal(Vec3D normal)
Sets the normal vector between the two interacting objects.
Mdouble X
the vector components
Definition: Vector.h:52
void setOverlap(Mdouble overlap)
Set the overlap between the two interacting object.
BaseInteraction * getInteraction(BaseInteractable *P, BaseInteractable *I, Mdouble timeStamp)
Returns the Interaction between the BaseInteractable's P and I.
double Mdouble
void setContactPoint(Vec3D contactPoint)
Set the location of the contact point between the two interacting objects.
void setDistance(Mdouble distance)
Sets the interaction distance between the two interacting objects.
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Stores information about interactions between two interactable objects; often particles but could be ...
static Mdouble getLength(const Vec3D &a)
Calculates the length of a Vec3D: .
Definition: Vector.cc:427
void oldRead(std::istream &is)
Container to store Interaction objects.
const Vec3D & getNormal() const
Gets the normal vector between the two interacting objects.
Mdouble getRadius() const
Returns the particle's radius_.
Basic class for walls.
Definition: BaseWall.h:39
Mdouble getOverlap() const
Returns a Mdouble with the current overlap between the two interacting objects.
void clear()
A function that removes all data from this BaseWall, so sets handler_ to nullptr. ...
CylindricalWall * copy() const
Wall copy method. It calls the copy contrustor of this Wall, usefull for polymorfism.
Mdouble Y
Definition: Vector.h:52
void write(std::ostream &os) const
outputs wall
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.
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
BaseInteraction * getInteractionWith(BaseParticle *P, Mdouble timeStamp, InteractionHandler *interactionHandler)
Returns the interaction between this object and a given BaseParticle.
void set(Mdouble radius)
Defines a standard wall, given an outward normal vector s. t. normal*x=position.
void read(std::istream &is)
reads wall
double getRadius() const
access function for radius
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
void read(std::istream &is)
Function that reads a BaseWall from an input stream, usually a restart file.
Definition: BaseWall.cc:60
virtual std::string getName() const
Returns the name of the object.