MercuryDPM  Trunk
 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-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 <random>
27 #include "CubeInsertionBoundary.h"
28 #include "Particles/BaseParticle.h"
29 #include "Math/RNG.h"
30 
35 {
36  posMin_ = Vec3D(0.0, 0.0, 0.0);
37  posMax_ = Vec3D(0.0, 0.0, 0.0);
38  velMin_ = Vec3D(0.0, 0.0, 0.0);
39  velMax_ = Vec3D(0.0, 0.0, 0.0);
40 }
41 
46  : InsertionBoundary(other)
47 {
48  posMin_ = other.posMin_;
49  posMax_ = other.posMax_;
50  velMin_ = other.velMin_;
51  velMax_ = other.velMax_;
52 }
53 
59 = default;
60 
66 {
67 #ifdef DEBUG_CONSTRUCTOR
68  std::cout << "CubeInsertionBoundary::copy() const finished" << std::endl;
69 #endif
70  return new CubeInsertionBoundary(*this);
71 }
72 
89 void CubeInsertionBoundary::set(BaseParticle* particleToCopy, unsigned int maxFailed, Vec3D posMin, Vec3D posMax,
90  Vec3D velMin, Vec3D velMax, double radMin, double radMax)
91 {
92  setParticleToCopy(particleToCopy);
93  setRadiusRange(radMin, radMax);
94 
95  setMaxFailed(maxFailed);
96  setGeometry(posMin, posMax, velMin, velMax);
97 }
98 
99 void
100 CubeInsertionBoundary::set(BaseParticle& particleToCopy, unsigned int maxFailed, Vec3D posMin, Vec3D posMax, Vec3D velMin, Vec3D velMax,
101  double radMin, double radMax) {
102  set(&particleToCopy, maxFailed, posMin, posMax, velMin, velMax, radMin, radMax);
103 }
104 
105 
107 {
108  radMin_ = radMin;
109  radMax_ = radMax;
110 }
111 
112 void CubeInsertionBoundary::setGeometry(Vec3D posMin, Vec3D posMax, Vec3D velMin, Vec3D velMax)
113 {
114  posMin_ = posMin;
115  posMax_ = posMax;
116  velMin_ = velMin;
117  velMax_ = velMax;
118 }
119 
125 // Irana: where is the delete of P? There is a new in copy()
126 // Bram: @Irana: The Particle is only CREATED in the InsertionBoundary. Deletion
127 // is done either by a DeletionBoundary, or at the end of a program (in that case,
128 // ~ParticleHandler -> ~BaseHandler -> BaseHandler::clear(), where first the individual
129 // objects are deleted, followed by the clearance of the std::vector with object pointers).
130 //
131 // JMFT: @Irana, @Bram: As of 2549, the delete is done in InsertionBoundary.
132 // The InsertionBoundary calls generateParticle and placeParticle, which are
133 // geometry-specific and implemented by the child classes, such as
134 // CubeInsertionBoundary. If the particle is wanted then it is copied into the
135 // particleHandler. In any case, the InsertionBoundary's version of the
136 // particle (created here) gets deleted by the InsertionBoundary.
137 //
138 // TP: Generate Particle is not geometry specific (but sometimes distribution-modality/species specific; in that case
139 // it can be overriden) and therefore moved to the Parent class.
140 
142 {
143  Vec3D pos, vel;
144  pos.X = random.getRandomNumber(posMin_.X, posMax_.X);
145  pos.Y = random.getRandomNumber(posMin_.Y, posMax_.Y);
146  pos.Z = random.getRandomNumber(posMin_.Z, posMax_.Z);
147  vel.X = random.getRandomNumber(velMin_.X, velMax_.X);
148  vel.Y = random.getRandomNumber(velMin_.Y, velMax_.Y);
149  vel.Z = random.getRandomNumber(velMin_.Z, velMax_.Z);
150  p->setPosition(pos);
151  p->setVelocity(vel);
152 }
153 
158 void CubeInsertionBoundary::read(std::istream& is)
159 {
161  std::string dummy;
162  is >> dummy >> posMin_
163  >> dummy >> posMax_;
164  is >> dummy >> velMin_
165  >> dummy >> velMax_;
166  is >> dummy >> radMin_
167  >> dummy >> radMax_;
168 }
169 
174 void CubeInsertionBoundary::oldRead(std::istream& is)
175 {
176  unsigned int maxFailed;
177  std::string dummy;
178  is >> dummy >> maxFailed
179  >> dummy >> posMin_
180  >> dummy >> posMax_
181  >> dummy >> velMin_
182  >> dummy >> velMax_
183  >> dummy >> radMin_
184  >> dummy >> radMax_;
185  setMaxFailed(maxFailed);
186 }
187 
192 void CubeInsertionBoundary::write(std::ostream& os) const
193 {
195  os << " posMin " << posMin_
196  << " posMax " << posMax_
197  << " velMin " << velMin_
198  << " velMax " << velMax_
199  << " radMin " << radMin_
200  << " radMax " << radMax_;
201 }
202 
208 {
209  return "CubeInsertionBoundary";
210 }
CubeInsertionBoundary()
Constructor; sets everything to 0.
Mdouble X
the vector components
Definition: Vector.h:65
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.
double Mdouble
Definition: GeneralDefine.h:34
void setGeometry(Vec3D posMin, Vec3D posMax, Vec3D velMin, Vec3D velMax)
Sets the geometry (position and velocity distribution) of the CubeInsertionBoundary.
Mdouble radMin_
Minimum and maximum radii of the generated particles.
void setMaxFailed(unsigned int maxFailed)
Sets the number of times that the wall may fail to insert a particle.
Mdouble getRandomNumber()
This is a random generating routine can be used for initial positions.
Definition: RNG.cc:143
~CubeInsertionBoundary() override
Destructor: default destructor.
Boundary structure for boundaries used for insertion of particles.
void placeParticle(BaseParticle *p, RNG &random) override
Generates a random position, velocity for the particle p.
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.
void set(BaseParticle *particleToCopy, unsigned int maxFailed, Vec3D posMin, Vec3D posMax, Vec3D velMin, Vec3D velMax, double radMin, double radMax)
Sets the properties of the CubeInsertionBoundary.
It's an insertion boundary which has cuboidal shape (yes, 'CuboidalInsertionBoundary' would have been...
CubeInsertionBoundary * copy() const override
Creates a copy on the heap and returns a pointer.
void write(std::ostream &os) const override
writes boundary properties to ostream
void write(std::ostream &os) const override
Writes the boundary's id_ and maxFailed_.
void setRadiusRange(Mdouble radMin, Mdouble radMax)
Sets the range of particle radii that may be generated.
Mdouble Y
Definition: Vector.h:65
void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
void read(std::istream &is) override
reads boundary properties from istream
Definition: Vector.h:49
MERCURY_DEPRECATED void oldRead(std::istream &is)
deprecated version of CubeInsertionBoundary::read().
Mdouble Z
Definition: Vector.h:65
void read(std::istream &is) override
Reads the boundary's id_ and maxFailed_.