MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DeletionBoundary.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 
28 #include "DeletionBoundary.h"
29 #include "ParticleHandler.h"
30 #include "Particles/BaseParticle.h"
31 #include <algorithm>
32 #include "Domain.h"
33 #include "BoundaryHandler.h"
34 #include "DPMBase.h"
35 
40  : BaseBoundary()
41 {
42  distance_ = std::numeric_limits<double>::quiet_NaN();
43  scaleFactor_ = std::numeric_limits<double>::quiet_NaN();
44  isActivated_ = true;
45  trackOutflow_ = false;
47  massDeleted_ = 0;
48  volumeDeleted_ = 0;
49 
50  logger(DEBUG, "DeletionBoundary::DeletionBoundary() finished");
51 }
52 
57 {
58  logger(DEBUG, "DeletionBoundary::~DeletionBoundary() finished");
59 }
60 
67 {
68  return new DeletionBoundary(*this);
69 }
70 
85 void DeletionBoundary::set(const Vec3D& normal, Mdouble distance)
86 {
87  scaleFactor_ = 1. / std::sqrt(Vec3D::dot(normal, normal));
88  normal_ = normal * scaleFactor_;
89  distance_ = distance * scaleFactor_;
90 }
91 
98 {
99  distance_ = distance * scaleFactor_;
100 }
101 
109 {
110  return distance_ - Vec3D::dot(position, normal_);
111 }
112 
124 {
125  if (getDistance(p->getPosition()) < 0)
126  {
127  if (trackOutflow_) {
128  auto dpm = getHandler()->getDPMBase();
129  trackMassDeleted_ += p->getMass();
130  if (!tracker.is_open()) {
131  std::string name = dpm->getName()
134  logger(INFO,"Open file %",name);
135  tracker.open(name);
136  tracker << std::setw(13) << "Time "
137  << std::setw(8) << "Species "
138  << std::setw(8) << "ID "
139  << std::setw(13) << "Position_x "
140  << std::setw(13) << "Position_y "
141  << std::setw(13) << "Position_z "
142  << std::setw(13) << "Velocity_x "
143  << std::setw(13) << "Velocity_y "
144  << std::setw(13) << "Velocity_z "
145  << std::setw(13) << "Radius "
146  << std::setw(13) << "AnVelocity_x "
147  << std::setw(13) << "AnVelocity_y "
148  << std::setw(13) << "AnVelocity_z "
149  << std::setw(13) << "Mass "
150  << std::setw(13) << "TotalMass"
151  << '\n';
152  }
153  tracker << std::setw(12) << dpm->getTime() << ' '
154  << std::setw(8) << p->getIndSpecies() << ' '
155  << std::setw(8) << p->getId() << ' '
156  << std::setw(12) << p->getPosition().X << ' '
157  << std::setw(12) << p->getPosition().Y << ' '
158  << std::setw(12) << p->getPosition().Z << ' '
159  << std::setw(12) << p->getVelocity().X << ' '
160  << std::setw(12) << p->getVelocity().Y << ' '
161  << std::setw(12) << p->getVelocity().Z << ' '
162  << std::setw(12) << p->getRadius() << ' '
163  << std::setw(12) << p->getAngularVelocity().X << ' '
164  << std::setw(12) << p->getAngularVelocity().Y << ' '
165  << std::setw(12) << p->getAngularVelocity().Z << ' '
166  << std::setw(12) << p->getMass() << ' '
167  << std::setw(12) << trackMassDeleted_ << '\n';
168  }
169 
170  #ifdef MERCURY_USE_MPI
171  //Check if the particle is in the mpi communication zone
172  if(p->isInMPIDomain())
173  {
174  //Add the particle to a list so we can flush it later on
175  //The particles are not deleted yet. This is done in dpmBase after this function is called
176  particlesToBeDeleted_.insert(p);
177  return false;
178  }
179  else
180  {
181  pH.removeGhostObject(p->getIndex());
182  return true;
183  }
184  #else
186  massDeleted_ += p->getMass();
187  volumeDeleted_ += p->getVolume();
188  pH.removeObject(p->getIndex());
191  return true;
192  #endif
193  }
194  else
195  {
196  return false;
197  }
198 }
199 
201 {
202  if (!isActivated_)
203  return;
204 
205 #ifdef MERCURY_USE_MPI
206  particlesToBeDeleted_.clear();
207 #endif
208  for (unsigned int i = 0; i < pH.getSize(); i++)
209  {
210  //If the particle is deleted, change the iterator
212  {
213  i--;
214  }
215  }
216 }
217 
219 {
220  return massDeleted_;
221 }
222 
224 {
225  return volumeDeleted_;
226 }
227 
229 {
231  massDeleted_ = 0;
232  volumeDeleted_ = 0;
233 }
234 
239 void DeletionBoundary::read(std::istream& is)
240 {
241  BaseBoundary::read(is);
242  std::string dummy;
243  is >> dummy >> normal_
244  >> dummy >> scaleFactor_
245  >> dummy >> distance_
246  >> dummy >> numberOfParticlesDeleted_
247  >> dummy >> massDeleted_
248  >> dummy >> volumeDeleted_
249  >> dummy >> isActivated_
250  >> dummy >> trackOutflow_;
251 }
252 
258 void DeletionBoundary::oldRead(std::istream& is)
259 {
260  std::string dummy;
261  is >> dummy >> normal_ >> dummy >> scaleFactor_ >> dummy >> distance_;
262 }
263 
268 void DeletionBoundary::write(std::ostream& os) const
269 {
271  os << " normal " << normal_
272  << " scaleFactor " << scaleFactor_
273  << " distance " << distance_
274  << " numberOfParticlesDeleted " << numberOfParticlesDeleted_
275  << " massDeleted " << massDeleted_
276  << " volumeDeleted " << volumeDeleted_
277  << " isActivated " << isActivated_
278  << " trackOutflow " << trackOutflow_;
279 }
280 
285 std::string DeletionBoundary::getName() const
286 {
287  return "DeletionBoundary";
288 }
289 
296 {
298 }
299 
301 {
302  isActivated_ = true;
303 }
304 
306 {
307  isActivated_ = false;
308 }
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.h:125
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.h:118
Vec3D normal_
outward unit normal vector
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Mdouble X
the vector components
Definition: Vector.h:65
void removeObject(unsigned int index) override
Removes a BaseParticle from the ParticleHandler.
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
void read(std::istream &is) override
Reads some boundary properties from an std::istream.
virtual Mdouble getVolume() const
Get Particle volume function, which required a reference to the Species vector. It returns the volume...
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Definition: GeneralDefine.h:34
bool checkBoundaryAfterParticleMoved(BaseParticle *p, ParticleHandler &pH)
Checks if particle is inside the boundary, and deletes the particle if so.
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
Used for removing particles from the problem. Inherits from BaseBoundary. By default, a plane that deletes everything past it, but there are derived classes such as CubeDeletionBoundary.
Mdouble scaleFactor_
This is the factor to rescale the given normal vector to a unit vectors.
virtual const Vec3D & getAngularVelocity() const
Returns the angular velocity of this interactable.
void read(std::istream &is) override=0
Reads the object's id_ from given istream NB: purely virtual function, overriding the version of Base...
Definition: BaseBoundary.cc:61
void deactivate()
Turns off the DeletionBoundary.
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:76
std::ofstream tracker
double getMassOfParticlesDeleted() const
DeletionBoundary * copy() const override
Copy method; creates copy on the heap and returns a pointer to it.
void activate()
Turns on the DeletionBoundary.
bool isInMPIDomain()
Indicates if the particle is in the communication zone of the mpi domain.
Mdouble getMass() const
Returns the particle's mass.
Definition: BaseParticle.h:322
DeletionBoundary()
default constructor
virtual Mdouble getDistance(const Vec3D &position) const
Returns a negative value if and only if the particle is inside the boundary (and therefore to be dele...
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:613
MERCURY_DEPRECATED void oldRead(std::istream &is)
Deprecated read method. use DeletionBoundary::read() instead.
Mdouble distance_
The boundary's distance from the origin.
#define PROCESSOR_ID
Definition: GeneralDefine.h:63
void write(std::ostream &os) const override=0
Adds object's id_ to given ostream NB: purely virtual function, overriding the version of BaseObject...
Definition: BaseBoundary.cc:70
BoundaryHandler * getHandler() const
Returns the boundary's BoundaryHandler.
~DeletionBoundary() override
destructor
void write(std::ostream &os) const override
Writes the boundary properties to an std::ostream.
Mdouble getRadius() const
Returns the particle's radius.
Definition: BaseParticle.h:345
void removeGhostObject(unsigned int index)
Removes a BaseParticle from the ParticleHandler without a global check, this is only to be done for m...
Container to store all BaseParticle.
#define NUMBER_OF_PROCESSORS
For the MPI communication routines this quantity is often required. defining this macro makes the cod...
Definition: GeneralDefine.h:62
Mdouble Y
Definition: Vector.h:65
void checkBoundaryAfterParticlesMove(ParticleHandler &pH) override
std::string to_string(const T &n)
Definition: Helpers.h:227
void computeSmallestParticle()
Computes the smallest particle (by interaction radius) and sets it in smallestParticle_.
void computeLargestParticle()
Computes the largest particle (by interaction radius) and sets it in largestParticle_.
unsigned int getNumberOfParticlesDeleted() const
Gets the number of particles deleted by the boundary.
double getVolumeOfParticlesDeleted() const
unsigned int getIndSpecies() const
Returns the index of the species associated with the interactable object.
virtual const Vec3D & getVelocity() const
Returns the velocity of this interactable.
Definition: Vector.h:49
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725
bool isActivated_
The DeletionBoundary is activated by default. If the DeletionBoundary is deactivated, then it deletes no particles.
unsigned int numberOfParticlesDeleted_
Number of particles that have been deleted by this boundary.
Mdouble Z
Definition: Vector.h:65
std::string getName() const override
Returns the name of the object.
void move(Mdouble position)
Sets the boundary's distance property to the given one.
virtual void set(const Vec3D &normal, Mdouble distance)
Sets boundary position based on a normal and distance.