MercuryDPM  Beta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MaserBoundary.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 
27 #include "MaserBoundary.h"
28 #include "DPMBase.h"
29 #include "BoundaryHandler.h"
30 #include "ParticleHandler.h"
31 #include "Particles/BaseParticle.h"
33 #include <Logger.h>
34 
41 {
42  return new MaserBoundary(*this);
43 }
44 
51 void MaserBoundary::set(Vec3D normal, Mdouble distanceLeft, Mdouble distanceRight)
52 {
53  // factor is used to set normal to unit length
54  normal_ = normal;
55  distanceLeft_ = distanceLeft;
56  distanceRight_ = distanceRight;
58 }
59 
64 void MaserBoundary::read(std::istream& is)
65 {
67 }
68 
73 void MaserBoundary::write(std::ostream& os) const
74 {
76 }
77 
82 std::string MaserBoundary::getName() const
83 {
84  return "MaserBoundary";
85 }
86 
94 {
95  return getDistance(p.getPosition());
96 }
97 
105 {
106  Mdouble distance = Vec3D::dot(position, normal_);
107 
108  if (distance - distanceLeft_ < distanceRight_ - distance)
109  {
110  closestToLeftBoundary_ = true;
111  return distance - distanceLeft_;
112  }
113  else
114  {
115  closestToLeftBoundary_ = false;
116  return distanceRight_ - distance;
117  }
118 }
119 
139 {
141  {
142  p->move(shift_);
143  closestToLeftBoundary_ = false;
144  }
145  else
146  {
147  p->move(-shift_);
148  closestToLeftBoundary_ = true;
149  }
150 }
151 
165 {
166  // check if particle is close to either of the boundary walls
168  {
169  auto conversion = speciesConversionMaserToNormal_.find(P->getSpecies());
170  if (conversion != speciesConversionMaserToNormal_.end()) //Test if it is a maser particle
171  {
172  // Copy the particle if it IS a maser particle
173  BaseParticle* F0 = P->copy();
175 
176  // shift to the periodic location
177  shiftPosition(F0);
178 
179  //Set the 'from' particle. If Particle is multiply shifted, get correct original particle
180  BaseParticle* From = P;
181  while (From->getPeriodicFromParticle() != nullptr)
182  {
183  From = From->getPeriodicFromParticle();
184  }
185  F0->setPeriodicFromParticle(From);
186 
187  // add the periodic particle to the handler
188  pH.addObject(F0);
189 
202  {
203  }
204  else
205  {
206  }
207  }
208  }
209 }
210 
236 {
237  // check if particle passed either of the boundary walls
238  if (getDistance(*P) < 0)
239  {
240  // check if species is found in the list of maser particle species
241  auto conversion = speciesConversionMaserToNormal_.find(P->getSpecies());
242  if (conversion != speciesConversionMaserToNormal_.end()) //Test if it is a maser particle
243  {
244  // yes: shift it periodically!
245  shiftPosition(P);
246 
247  /*
248  // check if to be shifted leftward or rightward. Now done by MaserBoundary::shiftPosition().
249  if (closestToLeftBoundary_)
250  {
251  P->move(shift_);
252  closestToLeftBoundary_ = false;
253  }
254  else
255  {
256  P->move(-shift_);
257  closestToLeftBoundary_ = true;
258  //BaseParticle* pCopy = pH.copyAndAddObject(P);
259  //pCopy->setIndSpecies(conversion->second);
260  }
261  */
262  }
263  }
264  return false;
265 }
266 
278 {
279  // check if particle species already known by the maser
280  auto conversion = speciesConversionNormalToMaser_.find(P->getSpecies());
281  if (conversion == speciesConversionNormalToMaser_.end())
282  {
283  // nope: species has to be added to the list
285  speciesConversionNormalToMaser_.insert(std::pair<const ParticleSpecies*, const ParticleSpecies*>(P->getSpecies(), newSpecies));
286  speciesConversionMaserToNormal_.insert(std::pair<const ParticleSpecies*, const ParticleSpecies*>(newSpecies, P->getSpecies()));
287  logger(INFO,"[MaserBoundary::addParticleToMaser()] New species conversion created");
288 
289  // now the species IS added, so flag (convert) it!
290  P->setSpecies(newSpecies);
291  }
292  else
293  {
294  // yep: species known and flagged (i.e. 'converted')
295  logger(INFO,"[MaserBoundary::addParticleToMaser()] Species conversion already present");
296  P->setSpecies(conversion->second);
297  }
298 }
299 
Mdouble distanceLeft_
position of left boundary wall, s.t. normal*x=position_left
Vec3D normal_
Normal unit vector of both maser walls. Points in the flowing direction.
BaseParticle * getLargestParticle() const
Gets a pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
void addParticleToMaser(BaseParticle *P)
Converts a 'normal' particle into a maser particle.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Mdouble getDistance(BaseParticle &p)
Returns the distance of the wall to the particle.
const ParticleSpecies * getSpecies() const
Returns a pointer to the species of this BaseInteractable.
void write(std::ostream &os) const =0
Adds object's id_ to given ostream NB: purely virtual function.
Definition: BaseBoundary.cc:76
double Mdouble
void setPeriodicFromParticle(BaseParticle *p)
Assigns the pointer to the 'original' particle this one's a periodic copy of.
void setSpecies(const ParticleSpecies *species)
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:187
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
void write(std::ostream &os) const
writes boundary properties to ostream
Mdouble distanceRight_
position of right boundary wall, s.t. normal*x=position_right
BaseParticle * getPeriodicFromParticle() const
Returns the 'original' particle this one's a periodic copy of.
void shiftPosition(BaseParticle *p)
shifts the particle to its 'periodic' position
U * copyAndAddObject(const U &O)
Creates a copy of a Object and adds it to the BaseHandler.
Definition: BaseHandler.h:268
std::map< const ParticleSpecies *, const ParticleSpecies * > speciesConversionNormalToMaser_
List of 'normal' particles' species, and their maser counterparts.
virtual void addObject(BaseParticle *P)
Adds a BaseParticle to the ParticleHandler.
std::map< const ParticleSpecies *, const ParticleSpecies * > speciesConversionMaserToNormal_
List of 'maser' particles' species, and their normal counterparts.
void read(std::istream &is)
reads boundary properties from istream
#define UNUSED
Definition: GeneralDefine.h:37
BoundaryHandler * getHandler() const
Returns the boundary's BoundaryHandler.
bool checkBoundaryAfterParticleMoved(BaseParticle *p, ParticleHandler &pH UNUSED)
Shifts the particle to its 'periodic' position if it is a maser particle and has crossed either of th...
void copyInteractionsForPeriodicParticles(const BaseInteractable &p)
Copies interactions to this BaseInteractable whenever a periodic copy made.
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. elastic, linear visco-elastic... et cetera...
Definition: DPMBase.h:868
void set(Vec3D normal, Mdouble distanceLeft, Mdouble distanceRight)
Sets all boundary properties at once.
Container to store all BaseParticle.
virtual std::string getName() const
Returns the name of the object.
Variation on the PeriodicBoundary with maser-like properties.
Definition: MaserBoundary.h:44
bool closestToLeftBoundary_
Dummy variable used when checking the proximity of particles to the boundary walls. TRUE if closest wall is the left boundary wall.
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
void createPeriodicParticles(BaseParticle *p, ParticleHandler &pH)
Creates periodic particle when the particle is a maser particle and is sufficiently close to one of t...
virtual void move(const Vec3D &move)
Moves this BaseInteractable by adding an amount to the position.
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:512
MaserBoundary * copy() const
Creates a copy on the heap.
Mdouble getInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e.g., when dealing with wet particles)
Vec3D shift_
Direction in which particles are to be shifted when they cross the boundary.
virtual ParticleSpecies * copy() const =0
Creates a deep copy of the object from which it is called.
virtual BaseParticle * copy() const
Particle copy method. It calls to copy constructor of this Particle, useful for polymorfism.
void read(std::istream &is)=0
Reads the object's id_ from given istream NB: purely virtual function.
Definition: BaseBoundary.cc:67