MercuryDPM  Alpha
 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 #include "WallHandler.h"
32 #include "DPMBase.h"
33 
35 {
36  factor_ = std::numeric_limits<double>::quiet_NaN();
37  logger(DEBUG, "InfiniteWall::InfiniteWall ) finished");
38 }
39 
46  : BaseWall(w)
47 {
48  normal_ = w.normal_;
49  factor_ = w.factor_;
50  logger(DEBUG, "InfiniteWall::InfiniteWall(const InfiniteWall &p) finished");
51 }
52 
53 InfiniteWall::InfiniteWall(Vec3D normal, Vec3D point, const ParticleSpecies* species)
54 {
55  setNormal(normal);
56  setPosition(point);
57  setSpecies(species);
58 }
59 
61 {
62  logger(DEBUG, "InfiniteWall::~InfiniteWall finished");
63 }
64 
69 {
70  return new InfiniteWall(*this);
71 }
72 
73 /*
74  * \param[in] normal A Vec3D that represents the normal to the wall.
75  * \param[in] point A Vec3D which is a point on the wall.
76  * \details Sets the wall such that for all points x on the wall it holds that
77  * normal*x=normal*point.
78  */
79 void InfiniteWall::set(Vec3D normal, Vec3D point)
80 {
81  setNormal(normal);
82  setPosition(point);
83 }
84 
88 void InfiniteWall::setNormal(const Vec3D normal)
89 {
90  factor_ = 1. / Vec3D::getLength(normal);
91  normal_ = normal * factor_;
92 }
93 
100 void InfiniteWall::set(Vec3D normal, Mdouble positionInNormalDirection)
101 {
102  logger(WARN, "InfiniteWall::set(Vec3D, Mdouble) is deprecated. Use set(Vec3D, Vec3D) instead.");
103  set(normal, positionInNormalDirection*normal);
104 }
105 
110 void InfiniteWall::move(Mdouble positionInNormalDirection)
111 {
112  logger(WARN, "InfiniteWall::move(Mdouble) is deprecated. Use move(Vec3D) instead.");
113  setPosition(positionInNormalDirection * normal_ / factor_);
114 }
115 
120 Mdouble InfiniteWall::getDistance(const Vec3D& otherPosition) const
121 {
122  return Vec3D::dot(getPosition()-otherPosition, normal_);
123 }
124 
137 bool InfiniteWall::getDistanceAndNormal(const BaseParticle& p, Mdouble& distance, Vec3D& normal_return) const
138 {
139  distance = getDistance(p.getPosition());
140  if (distance >= p.getWallInteractionRadius())
141  return false;
142  normal_return = normal_;
143  return true;
144 }
145 
149 void InfiniteWall::read(std::istream& is)
150 {
151  BaseWall::read(is);
152  std::string dummy;
153  is >> dummy >> normal_;
154  is >> dummy >> factor_;
155 }
156 
160 void InfiniteWall::oldRead(std::istream& is)
161 {
162  std::string dummy;
163  Vec3D velocity;
164  Vec3D position;
165  is >> dummy >> normal_ >> dummy >> position >> dummy >> velocity;
166  setPosition(position);
167  setVelocity(velocity);
168 }
169 
173 void InfiniteWall::write(std::ostream& os) const
174 {
175  BaseWall::write(os);
176  os << " normal " << normal_
177  << " factor "<< factor_;
178 }
179 
183 std::string InfiniteWall::getName() const
184 {
185  return "InfiniteWall";
186 }
187 
192 {
193  return normal_;
194 }
195 
202 void InfiniteWall::createVTK (std::vector<Vec3D>& myPoints) const
203 {
204  Vec3D max = getHandler()->getDPMBase()->getMax();
205  Vec3D min = getHandler()->getDPMBase()->getMin();
206  createVTK (myPoints, min, max);
207 }
208 
209 void InfiniteWall::createVTK (std::vector<Vec3D>& myPoints, const Vec3D min, const Vec3D max) const
210 {
211  const Vec3D& n = normal_;
212  const Vec3D& p = getPosition();
213 
214  if (fabs(n.X)>0.5) {
215  // If the wall normal has a nonzero x-component,
216  // We first find four intersection points with the four domain edges pointing in x-direction.
217  // Because these points might be outside the domain in x-direction, we use the intersection function have points in the domain
218  myPoints.push_back(Vec3D(p.X-((min.Y-p.Y)*n.Y+(min.Z-p.Z)*n.Z)/n.X,min.Y,min.Z));
219  myPoints.push_back(Vec3D(p.X-((min.Y-p.Y)*n.Y+(max.Z-p.Z)*n.Z)/n.X,min.Y,max.Z));
220  myPoints.push_back(Vec3D(p.X-((max.Y-p.Y)*n.Y+(max.Z-p.Z)*n.Z)/n.X,max.Y,max.Z));
221  myPoints.push_back(Vec3D(p.X-((max.Y-p.Y)*n.Y+(min.Z-p.Z)*n.Z)/n.X,max.Y,min.Z));
222  intersectVTK(myPoints, Vec3D(+1, 0, 0), Vec3D(max.X, 0, 0));
223  intersectVTK(myPoints, Vec3D(-1, 0, 0), Vec3D(min.X, 0, 0));
224  } else if (fabs(n.Y)>0.5) {
225  // Else, if the wall normal has a nonzero y-component ...
226  myPoints.push_back(Vec3D(min.X,p.Y-((min.X-p.X)*n.X+(min.Z-p.Z)*n.Z)/n.Y,min.Z));
227  myPoints.push_back(Vec3D(min.X,p.Y-((min.X-p.X)*n.X+(max.Z-p.Z)*n.Z)/n.Y,max.Z));
228  myPoints.push_back(Vec3D(max.X,p.Y-((max.X-p.X)*n.X+(max.Z-p.Z)*n.Z)/n.Y,max.Z));
229  myPoints.push_back(Vec3D(max.X,p.Y-((max.X-p.X)*n.X+(min.Z-p.Z)*n.Z)/n.Y,min.Z));
230  intersectVTK(myPoints, Vec3D(0, +1, 0), Vec3D(0, max.Y, 0));
231  intersectVTK(myPoints, Vec3D(0, -1, 0), Vec3D(0, min.Y, 0));
232  } else {
233  // Else, the wall normal has to have a a nonzero z-component ...
234  myPoints.push_back(Vec3D(min.X,min.Y,p.Z-((min.Y-p.Y)*n.Y+(min.X-p.X)*n.X)/n.Z));
235  myPoints.push_back(Vec3D(min.X,max.Y,p.Z-((max.Y-p.Y)*n.Y+(min.X-p.X)*n.X)/n.Z));
236  myPoints.push_back(Vec3D(max.X,max.Y,p.Z-((max.Y-p.Y)*n.Y+(max.X-p.X)*n.X)/n.Z));
237  myPoints.push_back(Vec3D(max.X,min.Y,p.Z-((min.Y-p.Y)*n.Y+(max.X-p.X)*n.X)/n.Z));
238  intersectVTK(myPoints, Vec3D(0, 0, +1), Vec3D(0, 0, max.Z));
239  intersectVTK(myPoints, Vec3D(0, 0, -1), Vec3D(0, 0, min.Z));
240  }
241 }
242 
244 {
245  std::vector<Vec3D> points;
246  createVTK (points);
247  addToVTK (points, vtk);
248 }
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...
Mdouble X
the vector components
Definition: Vector.h:52
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:165
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Mdouble getDistance(const Vec3D &otherPosition) const
Returns the distance of the wall to the particle.
void createVTK(std::vector< Vec3D > &myPoints) const
Vec3D getMin() const
Return the "bottom left" corner of the domain, a vector with xMin_, yMin_ and zMin_.
Definition: DPMBase.h:330
double Mdouble
Vec3D getNormal() const
Access function for normal.
static void addToVTK(const std::vector< Vec3D > &points, VTKContainer &vtk)
Definition: BaseWall.cc:289
void intersectVTK(std::vector< Vec3D > &points, const Vec3D normal, const Vec3D position) const
Definition: BaseWall.cc:163
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:167
void oldRead(std::istream &is)
Reads InfiniteWall from an old-style restart file.
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
void writeVTK(VTKContainer &vtk) const override
Mdouble getWallInteractionRadius() const
Returns the interaction radius for interaction with walls. See also BaseParticle::getInteractionRadiu...
WallHandler * getHandler() const
A function which returns the WallHandler that handles this BaseWall.
Definition: BaseWall.cc:85
InfiniteWall()
Default constructor, the normal is infinitely long.
Definition: InfiniteWall.cc:34
InfiniteWall * copy() const override
Wall copy method. It calls the copy constructor of this Wall, useful for polymorphism.
Definition: InfiniteWall.cc:68
Basic class for walls.
Definition: BaseWall.h:44
Vec3D getMax() const
Return the "upper right" corner of the domain, a vector with xMin_, yMin_ and zMin_.
Definition: DPMBase.h:335
void setNormal(const Vec3D normal)
Changes the normal of the InfiniteWall.
Definition: InfiniteWall.cc:88
Mdouble Y
Definition: Vector.h:52
void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
Mdouble getLength() const
Calculates the length of this Vec3D: .
Definition: Vector.cc:403
void read(std::istream &is) override
Reads InfiniteWall from a restart file.
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:79
This is a class defining walls.
Definition: InfiniteWall.h:47
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
void write(std::ostream &os) const override
Writes the InfiniteWall to an output stream, usually a restart file.
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:543
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 ~InfiniteWall()
Default destructor.
Definition: InfiniteWall.cc:60
void setSpecies(const ParticleSpecies *species)
Define the species of this wall.
Definition: BaseWall.cc:113