MercuryDPM  Alpha
 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-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 #include <Logger.h>
28 #include "Logger.h"
29 #include "SphericalWall.h"
30 #include "Particles/BaseParticle.h"
31 #include "InteractionHandler.h"
32 #include "WallHandler.h"
33 #include "DPMBase.h"
34 
36 {
37  radius_ = std::numeric_limits<double>::quiet_NaN();
38  logger(DEBUG, "SphericalWall::SphericalWall ) finished");
39 }
40 
47  : BaseWall(w)
48 {
49  radius_ = w.radius_;
50  logger(DEBUG, "SphericalWall::SphericalWall(const SphericalWall &p) finished");
51 }
52 
54 {
55  setRadius(radius);
56 }
57 
59 {
60  logger(DEBUG, "SphericalWall::~SphericalWall finished");
61 }
62 
67 {
68  return new SphericalWall(*this);
69 }
70 
71 /*
72  * \param[in] normal A Vec3D that represents the normal to the wall.
73  * \param[in] point A Vec3D which is a point on the wall.
74  * \details Sets the wall such that for all points x on the wall it holds that
75  * normal*x=normal*point.
76  */
78 {
79  logger.assert(radius>=0,"radius=% cannot be negative",radius);
80  radius_=radius;
81 }
82 
87 Mdouble SphericalWall::getDistance(const Vec3D& otherPosition) const
88 {
89  return Vec3D::getLength(getPosition()-otherPosition);
90 }
91 
96 {
97  return radius_;
98 }
99 
112 bool SphericalWall::getDistanceAndNormal(const BaseParticle& p, Mdouble& distance, Vec3D& normal_return) const
113 {
114  normal_return = p.getPosition()-getPosition();
115  distance = Vec3D::getLength(normal_return)-radius_;
116  if (distance >= p.getWallInteractionRadius())
117  return false;
118  normal_return/=distance+radius_;
119  //logger(WARN,"p% q% q% q% q%", getPosition(), p.getPosition(), normal_return, distance, p.getWallInteractionRadius());
120  return true;
121 }
122 
126 void SphericalWall::read(std::istream& is)
127 {
128  BaseWall::read(is);
129  std::string dummy;
130  is >> dummy >> radius_;
131 }
132 
136 void SphericalWall::write(std::ostream& os) const
137 {
138  BaseWall::write(os);
139  os << " radius " << radius_;
140 }
141 
145 std::string SphericalWall::getName() const
146 {
147  return "SphericalWall";
148 }
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.
This is a class defining walls.
Definition: SphericalWall.h:47
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
SphericalWall()
Default constructor, the normal is infinitely long.
double Mdouble
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Mdouble getWallInteractionRadius() const
Returns the interaction radius for interaction with walls. See also BaseParticle::getInteractionRadiu...
void setRadius(Mdouble radius)
Defines a spherical wall with radius r.
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:44
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:403
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
virtual ~SphericalWall()
Default destructor.
void write(std::ostream &os) const
Function that writes a BaseWall to an output stream, usually a restart file.
Definition: BaseWall.cc:68
Mdouble getDistance(const Vec3D &otherPosition) 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
void read(std::istream &is) override
Reads SphericalWall from a restart file.