MercuryDPM  Alpha
 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 // if closest to right boundary
146  {
147  p->move(-shift_);
148  closestToLeftBoundary_ = true;
149 
150  }
151 }
152 
166 {
167  // check if particle is close to either of the boundary walls
169  {
170  auto conversion = speciesConversionMaserToNormal_.find(p->getSpecies());
171  if (conversion != speciesConversionMaserToNormal_.end()) //Test if it is a maser particle
172  {
173  // Copy the particle if it IS a maser particle
174  BaseParticle* F0 = p->copy();
176 
177  // shift to the periodic location
178  shiftPosition(F0);
179 
180  //Set the 'from' particle. If Particle is multiply shifted, get correct original particle
181  BaseParticle* From = p;
182  while (From->getPeriodicFromParticle() != nullptr)
183  {
184  From = From->getPeriodicFromParticle();
185  }
186  F0->setPeriodicFromParticle(From);
187 
188  // add the periodic particle to the handler
189  pH.addObject(F0);
190 
203  {
204  }
205  else
206  {
207  }
208  }
209  }
210 }
211 
237 {
238  // check if particle passed either of the boundary walls
239  if (getDistance(*p) < 0)
240  {
241  // check if species is found in the list of maser particle species
242  auto conversion = speciesConversionMaserToNormal_.find(p->getSpecies());
243  if (conversion != speciesConversionMaserToNormal_.end()) //Test if it is a maser particle
244  {
245 
246  // If particle is closest to the right particle, create a 'real' equivalent
248  {
249  //std::cout << "bleep!" << std::endl;
250  BaseParticle pCopy = *p;
251  //pCopy.setId(pCopy->getIndex());
252 
253  pCopy.setSpecies(conversion->second);
254 
255  pH.copyAndAddObject(pCopy);
256 // std::cout << "new particle pos: " << pCopy->getPosition() << std::endl;
257 // std::cout << "new particle vel: " << pCopy->getVelocity() << std::endl;
258 // std::cout << "new particle forces: " << pCopy->getForce() << std::endl;
259 // std::cout << "original particle id: " << P->getId() << std::endl;
260 //
261 // std::cout << "new particle idx: " << pCopy->getIndex() << std::endl;
262 // std::cout << "new particle ine: " << pCopy->getInertia() << std::endl;
263 // std::cout << "new particle mas: " << pCopy->getMass() << std::endl;
264  logger(DEBUG, "size of ParticleHandler: %", pH.getNumberOfObjects());
265 
266 
267 // std::cout << "new particle id: " << pCopy->getId() << std::endl;
268 
269  //std::cout << "last particle pos: " << pH.getLastObject()->getPosition() << std::endl;
270  //shiftPosition(pCopy);
271  }
272 
273  // if maserparticle: shift it periodically!
274  shiftPosition(p);
275 
276  /*
277  // check if to be shifted leftward or rightward. Now done by MaserBoundary::shiftPosition().
278  if (closestToLeftBoundary_)
279  {
280  P->move(shift_);
281  closestToLeftBoundary_ = false;
282  }
283  else
284  {
285  P->move(-shift_);
286  closestToLeftBoundary_ = true;
287  //BaseParticle* pCopy = pH.copyAndAddObject(P);
288  //pCopy->setIndSpecies(conversion->second);
289  }
290  */
291 
292  }
293  }
294  return false;
295 }
296 
308 {
309  // check if particle species already known by the maser
310  auto conversion = speciesConversionNormalToMaser_.find(p->getSpecies());
311  if (conversion == speciesConversionNormalToMaser_.end())
312  {
313  // nope: species has to be added to the list
315  speciesConversionNormalToMaser_.insert(std::pair<const ParticleSpecies*, const ParticleSpecies*>(p->getSpecies(), newSpecies));
316  speciesConversionMaserToNormal_.insert(std::pair<const ParticleSpecies*, const ParticleSpecies*>(newSpecies, p->getSpecies()));
317  logger(INFO,"[MaserBoundary::addParticleToMaser()] New species conversion created");
318  logger(INFO, "Original species ID: %", p->getSpecies()->getId());
319 
320  // now the species IS added, so flag (convert) it!
321  p->setSpecies(newSpecies);
322  }
323  else
324  {
325  // yep: species known and flagged (i.e. 'converted')
326  logger(VERBOSE,"[MaserBoundary::addParticleToMaser()] Species conversion already present");
327  p->setSpecies(conversion->second);
328  }
329 }
330 
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.
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.cc:116
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.
bool checkBoundaryAfterParticleMoved(BaseParticle *p, ParticleHandler &pH)
Shifts the particle to its 'periodic' position if it is a maser particle and has crossed either of th...
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, overriding the version of BaseObject...
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:167
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
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
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddObject(const U &object)
Creates a copy of a Object and adds it to the BaseHandler.
Definition: BaseHandler.h:295
BoundaryHandler * getHandler() const
Returns the boundary's BoundaryHandler.
void copyInteractionsForPeriodicParticles(const BaseInteractable &p)
Copies interactions to this BaseInteractable whenever a periodic copy made.
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
Definition: BaseHandler.h:487
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. elastic, linear visco-elastic... et cetera...
Definition: DPMBase.h:991
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:543
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, overriding the version of Base...
Definition: BaseBoundary.cc:67