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 }
39 
44  : InsertionBoundary(other)
45 {
46  posMin_ = other.posMin_;
47  posMax_ = other.posMax_;
48 }
49 
55 = default;
56 
62 {
63 #ifdef DEBUG_CONSTRUCTOR
64  std::cout << "CubeInsertionBoundary::copy() const finished" << std::endl;
65 #endif
66  return new CubeInsertionBoundary(*this);
67 }
68 
83 void CubeInsertionBoundary::set(std::vector<BaseParticle*> particleToCopy, unsigned int maxFailed, Vec3D posMin, Vec3D
84 posMax, Vec3D velMin, Vec3D velMax)
85 {
86  velMin_ = velMin;
87  velMax_ = velMax;
88  maxFailed_ = maxFailed;
89  setParticleToCopy(particleToCopy);
90  setGeometry(posMin, posMax);
91 }
92 
107 void CubeInsertionBoundary::set(BaseParticle* particleToCopy, unsigned int maxFailed, Vec3D posMin, Vec3D
108 posMax, Vec3D velMin, Vec3D velMax)
109 {
110  velMin_ = velMin;
111  velMax_ = velMax;
112  maxFailed_ = maxFailed;
113  setParticleToCopy(particleToCopy);
114  setGeometry(posMin, posMax);
115 }
116 
117 void CubeInsertionBoundary::set(BaseParticle& particleToCopy, unsigned int maxFailed, Vec3D posMin, Vec3D posMax,
118  Vec3D velMin, Vec3D velMax)
119 {
120  set(&particleToCopy, maxFailed, posMin, posMax, velMin, velMax);
121 }
122 
123 
125 {
126  posMin_ = posMin;
127  posMax_ = posMax;
128 }
129 
135 // Irana: where is the delete of P? There is a new in copy()
136 // Bram: @Irana: The Particle is only CREATED in the InsertionBoundary. Deletion
137 // is done either by a DeletionBoundary, or at the end of a program (in that case,
138 // ~ParticleHandler -> ~BaseHandler -> BaseHandler::clear(), where first the individual
139 // objects are deleted, followed by the clearance of the std::vector with object pointers).
140 //
141 // JMFT: @Irana, @Bram: As of 2549, the delete is done in InsertionBoundary.
142 // The InsertionBoundary calls generateParticle and placeParticle, which are
143 // geometry-specific and implemented by the child classes, such as
144 // CubeInsertionBoundary. If the particle is wanted then it is copied into the
145 // particleHandler. In any case, the InsertionBoundary's version of the
146 // particle (created here) gets deleted by the InsertionBoundary.
147 //
148 // TP: Generate Particle is not geometry specific (but sometimes distribution-modality/species specific; in that case
149 // it can be overriden) and therefore moved to the Parent class.
150 
152 {
153  Vec3D pos, vel;
154  pos.X = random.getRandomNumber(posMin_.X, posMax_.X);
155  pos.Y = random.getRandomNumber(posMin_.Y, posMax_.Y);
156  pos.Z = random.getRandomNumber(posMin_.Z, posMax_.Z);
157  vel.X = random.getRandomNumber(velMin_.X, velMax_.X);
158  vel.Y = random.getRandomNumber(velMin_.Y, velMax_.Y);
159  vel.Z = random.getRandomNumber(velMin_.Z, velMax_.Z);
160  p->setPosition(pos);
161  p->setVelocity(vel);
162 }
163 
168 void CubeInsertionBoundary::read(std::istream& is)
169 {
171  std::string dummy;
172  is >> dummy >> posMin_
173  >> dummy >> posMax_;
174  is >> dummy >> velMin_
175  >> dummy >> velMax_;
176 }
177 
182 void CubeInsertionBoundary::write(std::ostream& os) const
183 {
185  os << " posMin " << posMin_
186  << " posMax " << posMax_
187  << " velMin " << velMin_
188  << " velMax " << velMax_;
189 }
190 
196 {
197  return "CubeInsertionBoundary";
198 }
CubeInsertionBoundary()
Constructor; sets everything to 0.
Mdouble X
the vector components
Definition: Vector.h:65
void set(BaseParticle *particleToCopy, unsigned int maxFailed, Vec3D posMin, Vec3D posMax, Vec3D velMin, Vec3D velMax)
Sets the properties of the InsertionBoundary for mutliple different particle types.
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.
Mdouble getRandomNumber()
This is a random generating routine can be used for initial positions.
Definition: RNG.cc:143
Vec3D velMin_
Minimum and maximum velocity of the particles to be inserted.
unsigned int maxFailed_
Number of times that the wall may fail to insert a particle.
~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.
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...
CubeInsertionBoundary * copy() const override
Creates a copy on the heap and returns a pointer.
void setParticleToCopy(std::vector< BaseParticle * > particleToCopy)
Sets multiple different particles that will be inserted through the insertion boundary.
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_.
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
Mdouble Z
Definition: Vector.h:65
void setGeometry(Vec3D posMin, Vec3D posMax)
Sets the geometry (position and velocity distribution) of the CubeInsertionBoundary.
void read(std::istream &is) override
Reads the boundary's id_ and maxFailed_.