MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FluxBoundary.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 "FluxBoundary.h"
29 #include "ParticleHandler.h"
30 #include "Particles/BaseParticle.h"
31 
36  : BaseBoundary()
37 {
38  distance_ = std::numeric_limits<double>::quiet_NaN();
39  scaleFactor_ = std::numeric_limits<double>::quiet_NaN();
42  massCrossedForw_ = 0;
43  massCrossedBack_ = 0;
46 #ifdef DEBUG_CONSTRUCTOR
47  std::cout<<"FluxBoundary::FluxBoundary() finished"<<std::endl;
48 #endif
49 }
50 
55 {
56 #ifdef DEBUG_DESTRUCTOR
57  std::cout<<"FluxBoundary::~FluxBoundary() finished"<<std::endl;
58 #endif
59 }
60 
67 {
68  return new FluxBoundary(*this);
69 }
70 
85 void FluxBoundary::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 
96 {
99  massCrossedForw_ = 0;
100  massCrossedBack_ = 0;
101  volumeCrossedForw_ = 0;
102  volumeCrossedBack_ = 0;
103 }
104 
111 {
112  distance_ = distance * scaleFactor_;
113 }
114 
120 {
121  return distance_ - Vec3D::dot(position, normal_);
122 }
123 
125 {
126  for (auto p = pH.begin(); p != pH.end(); ++p)
128 }
129 
130 
138 {
139  if (getDistance(p->getPosition() - p->getDisplacement()) > 0 && getDistance(p->getPosition()) < 0)
140  {
142  massCrossedForw_ += p->getMass();
144  }
145  else if (getDistance(p->getPosition() - p->getDisplacement()) < 0 && getDistance(p->getPosition()) > 0)
146  {
148  massCrossedBack_ += p->getMass();
150  }
151 
152  return false;
153 }
154 
163 {
165 }
166 
168 {
169  return massCrossedForw_ * 0.5;
170 }
171 
173 {
174  return volumeCrossedForw_ * 0.5;
175 }
176 
178 {
180 }
181 
183 {
184  return massCrossedBack_ * 0.5;
185 }
186 
188 {
189  return volumeCrossedBack_ * 0.5;
190 }
191 
193 {
195 }
196 
198 {
199  return (massCrossedForw_ - massCrossedBack_) * 0.5;
200 }
201 
203 {
204  return (volumeCrossedForw_ - volumeCrossedBack_) * 0.5;
205 }
206 
211 void FluxBoundary::read(std::istream& is)
212 {
213  BaseBoundary::read(is);
214  std::string dummy;
215  is >> dummy >> normal_
216  >> dummy >> scaleFactor_
217  >> dummy >> distance_;
218 }
219 
225 void FluxBoundary::oldRead(std::istream& is)
226 {
227  std::string dummy;
228  is >> dummy >> normal_ >> dummy >> scaleFactor_ >> dummy >> distance_;
229 }
230 
235 void FluxBoundary::write(std::ostream& os) const
236 {
238  os << " normal " << normal_
239  << " scaleFactor " << scaleFactor_
240  << " distance " << distance_;
241 }
242 
247 std::string FluxBoundary::getName() const
248 {
249  return "FluxBoundary";
250 }
251 
Mdouble distance_
The boundary's distance from the origin.
Definition: FluxBoundary.h:148
void reset()
Resets the counts to zero.
Definition: FluxBoundary.cc:95
unsigned int getNumberOfParticlesCrossedBack() const
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
unsigned int numberOfParticlesCrossedBack_
Definition: FluxBoundary.h:154
MERCURY_DEPRECATED void oldRead(std::istream &is)
Deprecated read method. use FluxBoundary::read() instead.
virtual Mdouble getVolume() const
Get Particle volume function, which required a reference to the Species vector. It returns the volume...
double Mdouble
Definition: GeneralDefine.h:34
Vec3D normal_
outward unit normal vector
Definition: FluxBoundary.h:135
void write(std::ostream &os) const override
Writes the boundary properties to an std::ostream.
double getMassOfParticlesCrossedNet() const
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:704
~FluxBoundary() override
destructor
Definition: FluxBoundary.cc:54
unsigned int getNumberOfParticlesCrossedNet() const
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
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:76
double massCrossedForw_
Definition: FluxBoundary.h:155
const std::vector< T * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
Definition: BaseHandler.h:690
FluxBoundary()
default constructor
Definition: FluxBoundary.cc:35
std::string getName() const override
Returns the name of the object.
Used for measuring flow rates through a given plane; acts like a pair of scales Inherits from BaseBou...
Definition: FluxBoundary.h:41
Mdouble getMass() const
Returns the particle's mass.
Definition: BaseParticle.h:322
Mdouble getDistance(const Vec3D &position) const
Returns the shortest distance between the boundary and given position.
void checkBoundaryAfterParticlesMove(ParticleHandler &pH) override
Runs at the end of each time step.
Mdouble scaleFactor_
This is the factor to rescale the given normal vector to a unit vectors.
Definition: FluxBoundary.h:144
double getVolumeOfParticlesCrossedNet() const
double volumeCrossedBack_
Definition: FluxBoundary.h:158
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
void set(const Vec3D &normal, Mdouble distance)
Sets boundary position based on a normal and distance.
Definition: FluxBoundary.cc:85
double getMassOfParticlesCrossedForw() const
Container to store all BaseParticle.
double getVolumeOfParticlesCrossedForw() const
double getMassOfParticlesCrossedBack() const
const Vec3D & getDisplacement() const
Returns the particle's displacement relative to the previous time step.
Definition: BaseParticle.h:392
unsigned int getNumberOfParticlesCrossedForw() const
Gets the number of particles that have crossed the boundary.
double getVolumeOfParticlesCrossedBack() const
void read(std::istream &is) override
Reads some boundary properties from an std::istream.
Definition: Vector.h:49
void move(Mdouble position)
Sets the boundary's distance property to the given one.
double massCrossedBack_
Definition: FluxBoundary.h:156
double volumeCrossedForw_
Definition: FluxBoundary.h:157
bool checkBoundaryAfterParticleMoved(BaseParticle *p, ParticleHandler &pH)
Checks if particle has crossed the boundary and updates the scales if so.
unsigned int numberOfParticlesCrossedForw_
Number of particles that have been deleted by this boundary.
Definition: FluxBoundary.h:153
FluxBoundary * copy() const override
Copy method; creates copy on the heap and returns a pointer to it.
Definition: FluxBoundary.cc:66