MercuryDPM  0.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParticleHandler.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 <limits>
27 
28 #include "ParticleHandler.h"
29 #include "Particles/BaseParticle.h"
32 
35 {
36  species_=0;
39  #ifdef CONSTUCTOR_OUTPUT
40  std::cerr << "ParticleHandler() finished" << std::endl;
41  #endif
42 }
43 
46 {
47  species_=PH.species_;
48  clear();
49  for (std::vector<BaseParticle*>::const_iterator it=PH.begin();it!=PH.end();it++)
50  {
51  addObject((*it)->copy());
52  }
53  #ifdef CONSTUCTOR_OUTPUT
54  std::cerr << "ParticleHandler(const ParticleHandler &PH) finished" << std::endl;
55  #endif
56 }
57 
60 {
61  if (this != &rhs)
62  {
63  clear();
64  for (std::vector<BaseParticle*>::const_iterator it=rhs.begin();it!=rhs.end();it++)
65  {
66  addObject((*it)->copy());
67  }
68  }
69  #ifdef CONSTUCTOR_OUTPUT
70  std::cerr << "ParticleHandler operator = (const ParticleHandler& rhs) finished" << std::endl;
71  #endif
72  return *this;
73 }
74 
76 {
77  #ifdef DESTRUCTOR_OUTPUT
78  std::cout << "WallHandler::~WallHandler() finished" << std::endl;
79  #endif
80 }
81 
85 {
86  //Puts the particle in the Particle list
88  //Check if this particle has new extrema
90  //set the particleHandler pointer
91  getLastObject()->setHandler(this);
92 }
93 
96  if (!smallestParticle_)
97  {
98  std::cerr << "Warning: No particles to set get_SmallestParticle()" << std::endl;
99  }
100  return smallestParticle_;
101 }
102 
105 {
106  if (!getNumberOfObjects())
107  {
108  std::cerr << "Warning: No particles to set get_FastestParticle()" << std::endl;
109  }
110  BaseParticle* p = 0;
111  Mdouble maxSpeed = -std::numeric_limits<Mdouble>::max();
112  for (std::vector<BaseParticle*>::const_iterator it=begin();it!=end();it++)
113  {
114  if ((*it)->get_Velocity().GetLength()>maxSpeed)
115  {
116  maxSpeed=(*it)->get_Velocity().GetLength();
117  p = (*it);
118  }
119  }
120  return p;
121 }
122 
124 {
125  if (!getNumberOfObjects())
126  {
127  std::cerr << "Warning: No getLowestPositionComponentParticle(cons int i)" << std::endl;
128  }
129  BaseParticle* p = 0;
130  Mdouble min = std::numeric_limits<Mdouble>::max();
131  for (std::vector<BaseParticle*>::const_iterator it=begin();it!=end();it++)
132  {
133  if ((*it)->get_Position().getComponent(i)<min) {
134  min=(*it)->get_Position().getComponent(i);
135  p = (*it);
136  }
137  }
138  return p;
139 }
141 {
142  if (!getNumberOfObjects())
143  {
144  std::cerr << "Warning: No getHighestPositionComponentParticle(cons int i)" << std::endl;
145  }
146  BaseParticle* p = 0;
147  Mdouble max = -std::numeric_limits<Mdouble>::max();
148  for (std::vector<BaseParticle*>::const_iterator it=begin();it!=end();it++)
149  {
150  if ((*it)->get_Position().getComponent(i)>max) {
151  max=(*it)->get_Position().getComponent(i);
152  p = (*it);
153  }
154  }
155  return p;
156 }
158 {
159  if (!getNumberOfObjects())
160  {
161  std::cerr << "Warning: No getLowestVelocityComponentParticle(cons int i)" << std::endl;
162  }
163  BaseParticle* p = 0;
164  Mdouble min = std::numeric_limits<Mdouble>::max();
165  for (std::vector<BaseParticle*>::const_iterator it=begin();it!=end();it++)
166  {
167  if ((*it)->get_Velocity().getComponent(i)<min) {
168  min=(*it)->get_Velocity().getComponent(i);
169  p = (*it);
170  }
171  }
172  return p;
173 }
175 {
176  if (!getNumberOfObjects())
177  {
178  std::cerr << "Warning: No getHighestVelocityComponentParticle(cons int i)" << std::endl;
179  }
180  BaseParticle* p = 0;
181  Mdouble max = -std::numeric_limits<Mdouble>::max();
182  for (std::vector<BaseParticle*>::const_iterator it=begin();it!=end();it++)
183  {
184  if ((*it)->get_Velocity().getComponent(i)>max) {
185  max=(*it)->get_Velocity().getComponent(i);
186  p = (*it);
187  }
188  }
189  return p;
190 }
191 
194  if (!getNumberOfObjects())
195  {
196  std::cerr << "Warning: No particles to set getLightestParticle()" << std::endl;
197  throw;
198  }
199  BaseParticle* p = 0;
200  Mdouble minMass = std::numeric_limits<Mdouble>::max();
201  for (std::vector<BaseParticle*>::const_iterator it=begin();it!=end();it++)
202  {
203  if ((*it)->get_Mass()<minMass)
204  {
205  minMass=(*it)->get_Mass();
206  p = (*it);
207  }
208  }
209  return p;
210 }
211 
214  if (!largestParticle_)
215  {
216  std::cerr << "Warning: No particles to set get_LargestParticle()" << std::endl;
217  throw;
218  }
219  return largestParticle_;
220 }
221 
223 {
227 }
228 
230 void ParticleHandler::readObject(std::istream& is)
231 {
232  std::string type;
233  is >> type;
234  if(type.compare("BP")==0)
235  {
236  BaseParticle baseParticle;
237  is>>baseParticle;
238  copyAndAddObject(baseParticle);
239  }
240  else if(type.compare("TSP")==0)
241  {
242  TangentialSpringParticle tangentialSpringParticle;
243  is>>tangentialSpringParticle;
244  copyAndAddObject(tangentialSpringParticle);
245  }
246  else if(type.compare("DMP")==0)
247  {
248  DeltaMaxsParticle deltaMaxsParticle;
249  is>>deltaMaxsParticle;
250  copyAndAddObject(deltaMaxsParticle);
251  }
252  else if(isdigit(type[0]))
253  {
254  TangentialSpringParticle tangentialSpringParticle;
255  tangentialSpringParticle.oldRead(is,type);
256  copyAndAddObject(tangentialSpringParticle);
257  }
258  else
259  {
260  std::cerr<<"Particle type: "<<type<<" not understood in restart file"<<std::endl;
261  exit(-1);
262  }
263 }
264 
267 {
269  {
271  }
273  {
275  }
276 }
277 
280 {
281  if(P==largestParticle_)
282  {
284  Mdouble maxRadius = -std::numeric_limits<Mdouble>::max();
285  for (std::vector<BaseParticle*>::const_iterator it=begin();it!=end();it++)
286  {
287  if ((*it)->get_InteractionRadius()>maxRadius&&P!=(*it))
288  {
289  maxRadius = (*it)->get_InteractionRadius();
290  largestParticle_ = (*it);
291  }
292  }
293  }
294  if(P==smallestParticle_)
295  {
297  Mdouble minRadius = std::numeric_limits<Mdouble>::max();
298  for (std::vector<BaseParticle*>::const_iterator it=begin();it!=end();it++)
299  {
300  if ((*it)->get_InteractionRadius()<minRadius&&P!=(*it))
301  {
302  minRadius = (*it)->get_InteractionRadius();
303  smallestParticle_ = (*it);
304  }
305  }
306  }
307 }
308 
310  if (!species_) std::cerr << "B" << species_ << std::endl;
311  return (*species_)[i]; }
312 void ParticleHandler::setSpecies(std::vector<CSpecies>* species) {species_ = species;}
313 
virtual void addObject(T *O)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:106
BaseParticle * getLargestParticle() const
Gets a pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
void checkExtremaOnDelete(BaseParticle *P)
Checks if the extrema of this ParticleHandler needs updating when a particle is deleted.
Mdouble get_InteractionRadius() const
void checkExtrema(BaseParticle *P)
Checks if the extrema of this ParticleHandler needs updating.
BaseParticle * getLowestVelocityComponentParticle(const int i) const
void copyAndAddObject(const BaseParticle &O)
Creates a copy of a Object and adds it to the BaseHandler.
Definition: BaseHandler.h:93
std::vector< CSpecies > * species_
BaseParticle * getLastObject() const
Gets a pointer to the last Object in this BaseHandler.
Definition: BaseHandler.h:192
const std::vector< T * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
Definition: BaseHandler.h:220
void setHandler(ParticleHandler *handler)
BaseParticle * getLightestParticle() const
Gets a pointer to the lightest BaseParticle (by mass) in this ParticleHandler.
void readObject(std::istream &is)
Reads BaseParticle into the ParticleHandler from restart data.
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
void clear()
Empties the whole ParticleHandler by removing all BaseParticle.
void oldRead(std::istream &is, std::string &x)
BaseParticle * getSmallestParticle() const
Gets a pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
double Mdouble
Definition: ExtendedMath.h:33
void setSpecies(std::vector< CSpecies > *)
virtual void addObject(BaseParticle *P)
Adds a BaseParticle to the ParticleHandler.
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:233
ParticleHandler()
Default constructor, it simply creates an empty ParticleHandler.
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
~ParticleHandler()
Destructor, it simply destructs the ParticleHandler and all BaseParticle it contains.
BaseParticle * getHighestVelocityComponentParticle(const int i) const
Container to store all Object.
Definition: BaseHandler.h:38
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
Definition: BaseHandler.h:199
Container to store all BaseParticle.
CSpecies & getSpecies(const int i)
BaseParticle * getHighestPositionComponentParticle(const int i) const
Stores properties of the particles and the contact models such as the elastic modulus.
Definition: CSpecies.h:56
BaseParticle * getLowestPositionComponentParticle(const int i) const
ParticleHandler operator=(const ParticleHandler &rhs)
Assignment operator.
void clear()
Empties the whole BaseHandler by removing all Object.
Definition: BaseHandler.h:162
BaseParticle * getFastestParticle() const
Gets a pointer to the fastests BaseParticle in this ParticleHandler.