MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CubeInsertionBoundary.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 "CubeInsertionBoundary.h"
27 #include "Particles/BaseParticle.h"
28 #include "Math/RNG.h"
29 
34 {
35  posMin_ = Vec3D(0.0, 0.0, 0.0);
36  posMax_ = Vec3D(0.0, 0.0, 0.0);
37  velMin_ = Vec3D(0.0, 0.0, 0.0);
38  velMax_ = Vec3D(0.0, 0.0, 0.0);
39  radMin_ = 0;
40  radMax_ = 0;
41 }
42 
47  : InsertionBoundary(other)
48 {
49  posMin_ = other.posMin_;
50  posMax_ = other.posMax_;
51  velMin_ = other.velMin_;
52  velMax_ = other.velMax_;
53  radMin_ = other.radMin_;
54  radMax_ = other.radMax_;
55 }
56 
62 {
63 }
64 
70 {
71 #ifdef DEBUG_CONSTRUCTOR
72  std::cout << "CubeInsertionBoundary::copy() const finished" << std::endl;
73 #endif
74  return new CubeInsertionBoundary(*this);
75 }
76 
93 void CubeInsertionBoundary::set(BaseParticle* particleToCopy, int maxFailed, Vec3D posMin, Vec3D posMax, Vec3D velMin, Vec3D velMax, double radMin, double radMax)
94 {
95  setParticleToCopy(particleToCopy);
96  setMaxFailed(maxFailed);
97  posMin_ = posMin;
98  posMax_ = posMax;
99  velMin_ = velMin;
100  velMax_ = velMax;
101  radMin_ = radMin;
102  radMax_ = radMax;
103 }
104 
110 // Irana: where is the delete of P? There is a new in copy()
111 // Bram: @Irana: The Particle is only CREATED in the InsertionBoundary. Deletion
112 // is done either by a DeletionBoundary, or at the end of a program (in that case,
113 // ~ParticleHandler -> ~BaseHandler -> BaseHandler::clear(), where first the individual
114 // objects are deleted, followed by the clearance of the std::vector with object pointers).
116 {
118  Vec3D pos, vel;
119  double radius;
120  pos.X = random.getRandomNumber(posMin_.X, posMax_.X);
121  pos.Y = random.getRandomNumber(posMin_.Y, posMax_.Y);
122  pos.Z = random.getRandomNumber(posMin_.Z, posMax_.Z);
123  vel.X = random.getRandomNumber(velMin_.X, velMax_.X);
124  vel.Y = random.getRandomNumber(velMin_.Y, velMax_.Y);
125  vel.Z = random.getRandomNumber(velMin_.Z, velMax_.Z);
126  radius = random.getRandomNumber(radMin_, radMax_);
127  P->setPosition(pos);
128  P->setVelocity(vel);
129  P->setRadius(radius);
130  return P;
131 }
132 
137 void CubeInsertionBoundary::read(std::istream& is)
138 {
140  std::string dummy;
141  is >> dummy >> posMin_
142  >> dummy >> posMax_
143  >> dummy >> velMin_
144  >> dummy >> velMax_
145  >> dummy >> radMin_
146  >> dummy >> radMax_;
147 }
148 
153 void CubeInsertionBoundary::oldRead(std::istream& is)
154 {
155  int maxFailed;
156  std::string dummy;
157  is >> dummy >> maxFailed
158  >> dummy >> posMin_
159  >> dummy >> posMax_
160  >> dummy >> velMin_
161  >> dummy >> velMax_
162  >> dummy >> radMin_
163  >> dummy >> radMax_;
164  setMaxFailed(maxFailed);
165 }
166 
171 void CubeInsertionBoundary::write(std::ostream& os) const
172 {
174  os << " posMin " << posMin_
175  << " posMax " << posMax_
176  << " velMin " << velMin_
177  << " velMax " << velMax_
178  << " radMin " << radMin_
179  << " radMax " << radMax_;
180 }
181 
187 {
188  return "CubeInsertionBoundary";
189 }
190 
CubeInsertionBoundary()
Constructor; sets everything to 0.
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D posMin_
Minimal and maximal positions defining the boundary's boundaries, and minimum and maximum velocity of...
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
void setMaxFailed(unsigned int maxFailed)
Sets the number of times that the wall may fail to insert a particle.
void setRadius(const Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species) ...
Boundary structure for boundaries used for insertion of particles.
void set(BaseParticle *particleToCopy, int maxFailed, Vec3D posMin, Vec3D posMax, Vec3D velMin, Vec3D velMax, double radMin, double radMax)
Sets the properties of the cuboidal insertion boundary.
void setParticleToCopy(BaseParticle *particleToCopy)
Sets the particle that will be inserted through the insertion boundary.
This is a class that generates random numbers i.e. named the Random Number Generator (RNG)...
Definition: RNG.h:52
std::string getName() const override
Returns the name of the object.
It's an insertion boundary which has cuboidal shape (yes, 'CuboidalInsertionBoundary' would have been...
virtual CubeInsertionBoundary * copy() const override
Creates a copy on the heap and returns a pointer.
BaseParticle * getParticleToCopy() const
Gets the particle that will be inserted through the insertion boundary.
void write(std::ostream &os) const override
writes boundary properties to ostream
Mdouble Y
Definition: Vector.h:52
void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
void read(std::istream &is) override
reads boundary properties from istream
~CubeInsertionBoundary()
Destructor: default destructor.
void read(std::istream &is)
Reads the boundary's id_ and maxFailed_.
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
MERCURY_DEPRECATED void oldRead(std::istream &is)
deprecated version of CubeInsertionBoundary::read().
double radMin_
minimum and maximum radii of the particles to be inserted
Mdouble Z
Definition: Vector.h:52
void write(std::ostream &os) const
Writes the boundary's id_ and maxFailed_.
Mdouble getRandomNumber(Mdouble min, Mdouble max)
This is a random generating routine can be used for initial positions.
Definition: RNG.cc:101
virtual BaseParticle * copy() const
Particle copy method. It calls to copy constructor of this Particle, useful for polymorfism.
virtual BaseParticle * generateParticle(RNG &random) override
Generates a particle with random position, radius and velocity.