MercuryDPM  Beta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InfiniteWall.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 "InfiniteWall.h"
29 #include "Particles/BaseParticle.h"
30 #include "InteractionHandler.h"
31 
33 {
34  factor_ = std::numeric_limits<double>::quiet_NaN();
35  logger(DEBUG, "InfiniteWall::InfiniteWall ) finished");
36 }
37 
44  : BaseWall(w)
45 {
46  normal_ = w.normal_;
47  factor_ = w.factor_;
48  logger(DEBUG, "InfiniteWall::InfiniteWall(const InfiniteWall &p) finished");
49 }
50 
52 {
53  logger(DEBUG, "InfiniteWall::~InfiniteWall finished");
54 }
55 
60 {
61  return new InfiniteWall(*this);
62 }
63 
64 /*
65  * \param[in] normal A Vec3D that represents the normal to the wall.
66  * \param[in] point A Vec3D which is a point on the wall.
67  * \details Sets the wall such that for all points x on the wall it holds that
68  * normal*x=normal*point.
69  */
70 void InfiniteWall::set(Vec3D normal, Vec3D point)
71 {
72  setNormal(normal);
73  setPosition(point);
74 }
75 
79 void InfiniteWall::setNormal(const Vec3D normal)
80 {
81  factor_ = 1. / Vec3D::getLength(normal);
82  normal_ = normal * factor_;
83 }
84 
91 void InfiniteWall::set(Vec3D normal, Mdouble positionInNormalDirection)
92 {
93  logger(WARN, "InfiniteWall::set(Vec3D, Mdouble) is deprecated. Use set(Vec3D, Vec3D) instead.");
94  set(normal, positionInNormalDirection*normal);
95 }
96 
101 void InfiniteWall::move(Mdouble positionInNormalDirection)
102 {
103  logger(WARN, "InfiniteWall::move(Mdouble) is deprecated. Use move(Vec3D) instead.");
104  setPosition(positionInNormalDirection * normal_ / factor_);
105 }
106 
111 Mdouble InfiniteWall::getDistance(const Vec3D& otherPosition) const
112 {
113  return Vec3D::dot(getPosition()-otherPosition, normal_);
114 }
115 
128 bool InfiniteWall::getDistanceAndNormal(const BaseParticle& p, Mdouble& distance, Vec3D& normal_return) const
129 {
130  distance = getDistance(p.getPosition());
131  if (distance >= p.getWallInteractionRadius())
132  return false;
133  normal_return = normal_;
134  return true;
135 }
136 
140 void InfiniteWall::read(std::istream& is)
141 {
142  BaseWall::read(is);
143  std::string dummy;
144  is >> dummy >> normal_;
145  is >> dummy >> factor_;
146 }
147 
151 void InfiniteWall::oldRead(std::istream& is)
152 {
153  std::string dummy;
154  Vec3D velocity;
155  Vec3D position;
156  is >> dummy >> normal_ >> dummy >> position >> dummy >> velocity;
157  setPosition(position);
158  setVelocity(velocity);
159 }
160 
164 void InfiniteWall::write(std::ostream& os) const
165 {
166  BaseWall::write(os);
167  os << " normal " << normal_
168  << " factor "<< factor_;
169 }
170 
174 std::string InfiniteWall::getName() const
175 {
176  return "InfiniteWall";
177 }
178 
183 {
184  return normal_;
185 }
186 
195 {
196  Mdouble distance = getDistance(p->getPosition());
197  if (distance < p->getWallInteractionRadius())
198  {
199  BaseInteraction* interaction = interactionHandler->getInteraction(p, this, timeStamp);
200  interaction->setNormal(-normal_);
201  interaction->setDistance(distance);
202  interaction->setOverlap(p->getRadius() - distance);
204 // interaction->setContactPoint(p->getPosition()-(p->getRadius()- 1.0 * interaction->getOverlap())*interaction->getNormal());
205  interaction->setContactPoint(p->getPosition()-(p->getRadius() - 0.5 * interaction->getOverlap())*interaction->getNormal());
206  return interaction;
207  }
208  else
209  {
210  return nullptr;
211  }
212 }
213 
void write(std::ostream &os) const
Writes the InfiniteWall to an output stream, usually a restart file.
MERCURY_DEPRECATED void move(Mdouble position)
Move the wall to a new position by giving the new position in the direction of the unit normal vector...
void read(std::istream &is)
Reads InfiniteWall from a restart file.
void setNormal(Vec3D normal)
Sets the normal vector between the two interacting objects.
bool getDistanceAndNormal(const BaseParticle &p, Mdouble &distance, Vec3D &normal_return) const override
Compute the distance from the wall for a given BaseParticle and return if there is a collision...
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
std::string getName() const override
Returns the name of the object, in this case the string "InfiniteWall".
Mdouble factor_
Definition: InfiniteWall.h:145
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
void setOverlap(Mdouble overlap)
Set the overlap between the two interacting object.
Mdouble getDistance(const Vec3D &otherPosition) const
Returns the distance of the wall to the particle.
BaseInteraction * getInteractionWith(BaseParticle *p, Mdouble timeStamp, InteractionHandler *interactionHandler)
Look up the interaction between this wall and a BaseParticle at a certain timeStamp.
BaseInteraction * getInteraction(BaseInteractable *P, BaseInteractable *I, Mdouble timeStamp)
Returns the Interaction between the BaseInteractable's P and I.
double Mdouble
Vec3D getNormal() const
Access function for normal.
void setContactPoint(Vec3D contactPoint)
Set the location of the contact point between the two interacting objects.
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:187
void oldRead(std::istream &is)
Reads InfiniteWall from an old-style restart file.
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 ...
Mdouble getWallInteractionRadius() const
Returns the interaction radius for interaction with walls. See also BaseParticle::getInteractionRadiu...
InfiniteWall()
Default constructor, the normal is infinitely long.
Definition: InfiniteWall.cc:32
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_.
InfiniteWall * copy() const override
Wall copy method. It calls the copy constructor of this Wall, useful for polymorphism.
Definition: InfiniteWall.cc:59
Basic class for walls.
Definition: BaseWall.h:39
Mdouble getOverlap() const
Returns a Mdouble with the current overlap between the two interacting objects.
void setNormal(const Vec3D normal)
Changes the normal of the InfiniteWall.
Definition: InfiniteWall.cc:79
void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
Mdouble getLength() const
Calculates the length of this Vec3D: .
Definition: Vector.cc:416
void set(Vec3D normal, Vec3D point)
Defines a standard wall, given an outward normal vector s.t. normal*x=normal*point for all x of the w...
Definition: InfiniteWall.cc:70
This is a class defining walls.
Definition: InfiniteWall.h:43
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
void write(std::ostream &os) const
Function that writes a BaseWall to an output stream, usually a restart file.
Definition: BaseWall.cc:68
void read(std::istream &is)
Function that reads a BaseWall from an input stream, usually a restart file.
Definition: BaseWall.cc:60
virtual ~InfiniteWall()
Default destructor.
Definition: InfiniteWall.cc:51