MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RestrictedWall.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 "RestrictedWall.h"
29 #include "Particles/BaseParticle.h"
30 #include "InteractionHandler.h"
31 #include "WallHandler.h"
32 #include "DPMBase.h"
33 
35 {
36  wall_ = nullptr;
37  restriction_ = nullptr;
38  logger(DEBUG, "RestrictedWall::RestrictedWall ) finished");
39 }
40 
47  : BaseWall(w)
48 {
49  wall_ = nullptr;
50  restriction_ = nullptr;
51  set(w.wall_, w.restriction_);
52  logger(DEBUG, "RestrictedWall::RestrictedWall(const RestrictedWall &p) finished");
53 }
54 
56 {
57  wall_ = nullptr;
58  restriction_ = nullptr;
59  set(wall, restriction);
60 }
61 
63 {
64  if (wall_!=nullptr) {
65  delete wall_;
66  wall_ = nullptr;
67  }
68  if (restriction_!=nullptr) {
69  delete restriction_;
70  restriction_ = nullptr;
71  }
72  logger(DEBUG, "RestrictedWall::~RestrictedWall finished");
73 }
74 
79 {
80  return new RestrictedWall(*this);
81 }
82 
83 /*
84  * \param[in] normal A Vec3D that represents the normal to the wall.
85  * \param[in] point A Vec3D which is a point on the wall.
86  * \details Sets the wall such that for all points x on the wall it holds that
87  * normal*x=normal*point.
88  */
90 void RestrictedWall::set(BaseWall* wall, InfiniteWall* restriction)
91 {
92  if (wall_!=nullptr) {
93  delete wall_;
94  wall_ = nullptr;
95  }
96  wall_ = wall->copy();
98 
99  if (restriction_!=nullptr) {
100  delete restriction_;
101  restriction_ = nullptr;
102  }
103  restriction_ = restriction->copy();
104 
105  // std::cout << *this << std::endl;
106 }
107 
120 bool RestrictedWall::getDistanceAndNormal(const BaseParticle& p, Mdouble& distance, Vec3D& normal_return) const
121 {
123  return wall_->getDistanceAndNormal(p, distance, normal_return);
124  else
125  return false;
126 }
127 
131 void RestrictedWall::read(std::istream& is)
132 {
133  wall_->read(is);
134  restriction_->read(is);
135 }
136 
140 void RestrictedWall::write(std::ostream& os) const
141 {
142  //todo check
143  os << getName() << ' ';
144  wall_->write(os);
145  os << ' ';
146  restriction_->write(os);
147 }
148 
152 std::string RestrictedWall::getName() const
153 {
154  return "RestrictedWall";
155 }
156 
164 std::vector<BaseInteraction*> RestrictedWall::getInteractionWith(BaseParticle* p, Mdouble timeStamp, InteractionHandler* interactionHandler) {
168  wall_->setIndex(getIndex());
169  return wall_->getInteractionWith(p, timeStamp, interactionHandler);
170  } else {
171  return std::vector<BaseInteraction*>();
172  }
173 }
174 
176 {
177  std::vector<std::vector<double>> myTriangleStrips;
178  wall_->writeVTK(vtk);
179 
180  // for (auto myTriangleStrip: myTriangleStrips) {
181  // triangleStrips.push_back(myTriangleStrip);
182  // }
183 
184  std::vector<double> cell;
185 
186  for (auto myTriangleStrip: myTriangleStrips) {
187  unsigned counter = 0;
188  for (const auto c: myTriangleStrip) {
189  Mdouble distance = restriction_->getDistance(vtk.points[c]);
190  if (distance < 0) {
191  //if the current point is in restriction, write it
192  cell.push_back(c);
193  counter=0;
194  } else {
195  if (counter>=2) {
196  //if the current point is not in restriction, don't write it and flush the cell into the cells array
197  if (cell.size()>2)
198  vtk.triangleStrips.push_back(cell);
199  cell.clear();
200  counter=0;
201  }
202  vtk.points[c] += distance*restriction_->getNormal();
203  cell.push_back(c);
204  counter++;
205  }
206  }
207  if (cell.size()>2) {
208  //if the current point is not in restriction, don't write it and flush the cell into the cells array
209  vtk.triangleStrips.push_back(cell);
210  cell.clear();
211  }
212  }
213 }
void setIndex(const unsigned int index)
Allows one to assign an index to an object in the handler/container.
Definition: BaseObject.cc:91
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.cc:108
std::vector< BaseInteraction * > getInteractionWith(BaseParticle *p, Mdouble timeStamp, InteractionHandler *interactionHandler) override
Look up the interaction between this wall and a BaseParticle at a certain timeStamp.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
virtual void writeVTK(VTKContainer &vtk) const
Definition: BaseWall.cc:284
Mdouble getDistance(const Vec3D &otherPosition) const
Returns the distance of the wall to the particle.
const ParticleSpecies * getSpecies() const
Returns a pointer to the species of this BaseInteractable.
double Mdouble
Vec3D getNormal() const
Access function for normal.
This is a class defining walls.
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
virtual std::vector< BaseInteraction * > getInteractionWith(BaseParticle *p, Mdouble timeStamp, InteractionHandler *interactionHandler)
Definition: BaseWall.cc:266
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 getWallInteractionRadius() const
Returns the interaction radius for interaction with walls. See also BaseParticle::getInteractionRadiu...
virtual ~RestrictedWall()
Default destructor.
void read(std::istream &is) override
Reads RestrictedWall from a restart file.
void write(std::ostream &os) const override
Writes the RestrictedWall to an output stream, usually a restart file.
virtual bool getDistanceAndNormal(const BaseParticle &P, Mdouble &distance, Vec3D &normal_return) const =0
Pure virtual function that computes the distance of a BaseParticle to this wall and returns the norma...
std::vector< std::vector< double > > triangleStrips
Definition: BaseWall.h:36
Container to store Interaction objects.
void set(BaseWall *wall, InfiniteWall *restriction)
Defines a standard wall, given an outward normal vector s.t. normal*x=normal*point for all x of the w...
RestrictedWall * copy() const override
Wall copy method. It calls the copy constructor of this Wall, useful for polymorphism.
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
BaseWall * wall_
std::vector< Vec3D > points
Definition: BaseWall.h:35
void read(std::istream &is) override
Reads InfiniteWall from a restart file.
InfiniteWall * restriction_
std::string getName() const override
Returns the name of the object, in this case the string "RestrictedWall".
This is a class defining walls.
Definition: InfiniteWall.h:47
RestrictedWall()
Default constructor, the normal is infinitely long.
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.
void writeVTK(VTKContainer &vtk) const override
void write(std::ostream &os) const
Function that writes a BaseWall to an output stream, usually a restart file.
Definition: BaseWall.cc:68
virtual BaseWall * copy() const =0
Pure virtual function that copies a BaseWall.
void read(std::istream &is)
Function that reads a BaseWall from an input stream, usually a restart file.
Definition: BaseWall.cc:60
void setSpecies(const ParticleSpecies *species)
Define the species of this wall.
Definition: BaseWall.cc:113