MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SphericalWall.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 #include "Logger.h"
28 #include "SphericalWall.h"
29 #include "Particles/BaseParticle.h"
30 #include "InteractionHandler.h"
31 #include "WallHandler.h"
32 #include "DPMBase.h"
33 
35 {
36  radius_ = std::numeric_limits<double>::quiet_NaN();
37  logger(DEBUG, "SphericalWall::SphericalWall ) finished");
38 }
39 
46  : BaseWall(w)
47 {
48  radius_ = w.radius_;
49  logger(DEBUG, "SphericalWall::SphericalWall(const SphericalWall &p) finished");
50 }
51 
53 {
54  setRadius(radius);
55 }
56 
58 {
59  logger(DEBUG, "SphericalWall::~SphericalWall finished");
60 }
61 
66 {
67  return new SphericalWall(*this);
68 }
69 
70 /*
71  * \param[in] normal A Vec3D that represents the normal to the wall.
72  * \param[in] point A Vec3D which is a point on the wall.
73  * \details Sets the wall such that for all points x on the wall it holds that
74  * normal*x=normal*point.
75  */
77 {
78  logger.assert(radius >= 0, "radius=% cannot be negative", radius);
79  radius_ = radius;
80 }
81 
86 Mdouble SphericalWall::getDistance(const Vec3D& otherPosition) const
87 {
88  return Vec3D::getLength(getPosition() - otherPosition);
89 }
90 
95 {
96  return radius_;
97 }
98 
111 bool SphericalWall::getDistanceAndNormal(const BaseParticle& p, Mdouble& distance, Vec3D& normal_return) const
112 {
113  normal_return = p.getPosition() - getPosition();
114  distance = Vec3D::getLength(normal_return) - radius_;
115  if (distance >= p.getWallInteractionRadius(this))
116  return false;
117  normal_return /= distance + radius_;
118  //logger(WARN,"p% q% q% q% q%", getPosition(), p.getPosition(), normal_return, distance, p.getWallInteractionRadius(this));
119  return true;
120 }
121 
125 void SphericalWall::read(std::istream& is)
126 {
127  BaseWall::read(is);
128  std::string dummy;
129  is >> dummy >> radius_;
130 }
131 
135 void SphericalWall::write(std::ostream& os) const
136 {
137  BaseWall::write(os);
138  os << " radius " << radius_;
139 }
140 
144 std::string SphericalWall::getName() const
145 {
146  return "SphericalWall";
147 }
SphericalWall * copy() const override
Wall copy method. It calls the copy constructor of this Wall, useful for polymorphism.
void write(std::ostream &os) const override
Writes the SphericalWall to an output stream, usually a restart file.
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
This is a class defining walls.
Definition: SphericalWall.h:47
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Definition: GeneralDefine.h:34
SphericalWall()
Default constructor, the normal is infinitely long.
void write(std::ostream &os) const override
Function that writes a BaseWall to an output stream, usually a restart file.
Definition: BaseWall.cc:102
~SphericalWall() override
Default destructor.
void setRadius(Mdouble radius)
Defines a spherical wall with radius r.
Mdouble getWallInteractionRadius(const BaseWall *wall) const
returns the radius plus the interactionDistance
Definition: BaseParticle.h:383
std::string getName() const override
Returns the name of the object, in this case the string "SphericalWall".
Mdouble getRadius() const
Returns the distance of the wall to the particle.
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
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...
Mdouble getLength() const
Calculates the length of this Vec3D: .
Definition: Vector.cc:320
Definition: Vector.h:49
Mdouble getDistance(const Vec3D &otherPosition) const
Returns the distance of the wall to the particle.
void read(std::istream &is) override
Reads SphericalWall from a restart file.