MercuryDPM  Beta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParticleSpecies.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<cmath>
27 #include <Logger.h>
28 #include "ParticleSpecies.h"
30 #include "DPMBase.h"
31 
32 
33 class BaseParticle;
34 class BaseInteractable;
35 
37 {
38  density_ = 0.0;
39 #ifdef DEBUG_CONSTRUCTOR
40  std::cout<<"ParticleSpecies::ParticleSpecies() finished"<<std::endl;
41 #endif
42 }
43 
48 {
50 #ifdef DEBUG_CONSTRUCTOR
51  std::cout<<"ParticleSpecies::ParticleSpecies(const ParticleSpecies &p) finished"<<std::endl;
52 #endif
53 }
54 
56 {
57 #ifdef DEBUG_DESTRUCTOR
58  std::cout<<"ParticleSpecies::~ParticleSpecies() finished"<<std::endl;
59 #endif
60 }
61 
65 void ParticleSpecies::write(std::ostream& os) const
66 {
67  //note we inherit from BaseObject, not BaseParticle
69  os << " density " << density_;
70 }
71 
75 void ParticleSpecies::read(std::istream& is)
76 {
78  std::string dummy;
79  is >> dummy >> density_;
80 }
81 
85 std::string ParticleSpecies::getBaseName() const
86 {
87  return "Particle";
88 }
89 
94 {
95  if (density >= 0)
96  {
97  density_ = density;
98  if (getHandler())
100  }
101  else
102  {
103  logger(ERROR, "[ParticleSpecies::setDensity()] Error in the density to be set: % ", density);
104  exit(-1);
105  }
106 }
107 
112 {
113  return density_;
114 }
115 
117 {
118  if (getHandler() == nullptr)
119  {
120  logger(ERROR, "[Species::MassFromRadius()] No handler has been set, therefore, I can't figure out the dimensions.");
121  return 0;
122  }
123 
124  unsigned int particleDimensions = getHandler()->getDPMBase()->getParticleDimensions();
125  if (particleDimensions == 3)
126  {
127  return 4.0 / 3.0 * constants::pi * radius * radius * radius * getDensity();
128  }
129  else if (particleDimensions == 2)
130  {
131  return constants::pi * radius * radius * getDensity();
132  }
133  else if (particleDimensions == 1)
134  {
135  return 2.0 * radius * getDensity();
136  }
137  else
138  {
139  logger(ERROR, "[Species::MassFromRadius()] the dimension of the particle is wrongly set to %",particleDimensions);
140  return 0.0;
141  }
142 }
143 
147 {
148  if (!p->isFixed())
149  {
150  switch (p->getParticleDimensions())
151  {
152  case 3:
153  {
154  p->mass_ = (4.0 / 3.0 * constants::pi * p->getRadius() * p->getRadius() * p->getRadius() * getDensity());
155  p->invMass_ = 1.0 / (p->mass_);
156  p->inertia_ = (.4 * p->getMass() * mathsFunc::square(p->getRadius()));
157  p->invInertia_ = 1.0 / (p->inertia_);
158  break;
159  }
160  case 2:
161  {
162  p->mass_ = (constants::pi * p->getRadius() * p->getRadius() * getDensity());
163  p->invMass_ = 1.0 / (p->mass_);
164  p->inertia_ = (.5 * p->getMass() * mathsFunc::square(p->getRadius()));
165  p->invInertia_ = 1.0 / (p->inertia_);
166  break;
167  }
168  case 1:
169  {
170  p->mass_ = (2.0 * p->getRadius() * getDensity());
171  p->invMass_ = 1.0/p->mass_;
172  p->inertia_ = 0.0;
173  p->invInertia_ = std::numeric_limits<Mdouble>::quiet_NaN();
174  break;
175  }
176  default:
177  {
178  logger(ERROR, "ParticleSpecies::computeMass()] the dimension of the particle is not set");
179  }
180  }
181  }
182 }
183 
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.cc:106
Mdouble invInertia_
Particle inertia_.
Definition: BaseParticle.h:397
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Mdouble getMassFromRadius(const Mdouble radius)
unsigned int getParticleDimensions() const
Returns the particle dimensions.
Definition: DPMBase.cc:492
void computeAllMasses(unsigned int indSpecies)
Computes the mass for all BaseParticle of the given species in this ParticleHandler.
double Mdouble
Mdouble mass_
Pointer to the previous Particle in the same HGrid cell.
Definition: BaseParticle.h:394
Mdouble invMass_
Particle mass_.
Definition: BaseParticle.h:395
virtual void computeMass(BaseParticle *p) const
Compute Particle mass function, which required a reference to the Species vector. It computes the Par...
T square(T val)
squares a number
Definition: ExtendedMath.h:91
SpeciesHandler * getHandler() const
Returns the pointer to the handler to which this species belongs.
Definition: BaseSpecies.cc:74
std::string getBaseName() const
Used in Species::getName to obtain a unique name for each Species.
Mdouble inertia_
Inverse Particle mass (for computation optimization)
Definition: BaseParticle.h:396
Mdouble getMass() const
Returns the particle's mass_.
const Mdouble pi
Definition: ExtendedMath.h:42
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created...
Definition: DPMBase.h:878
void setDensity(Mdouble density)
Allows the density to be changed.
void write(std::ostream &os) const
Writes the species properties to an output stream.
Mdouble getRadius() const
Returns the particle's radius_.
ParticleSpecies()
The default constructor.
virtual void read(std::istream &is)=0
A purely virtual method with an implementation which reads the index from the stream and assigns it t...
Definition: BaseObject.cc:120
void read(std::istream &is)
Reads the species properties from an input stream.
Mdouble density_
The particle mass density.
Defines the basic properties that a interactable object can have.
Mdouble getDensity() const
Allows the density to be accessed.
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:512
unsigned int getParticleDimensions() const
Returns the particle's dimensions (either 2 or 3).
bool isFixed() const
Is fixed Particle function. It returns whether a Particle is fixed or not, by checking its inverse Ma...
virtual ~ParticleSpecies()
The default destructor.
virtual void write(std::ostream &os) const =0
A purely virtual function which has an implementation which writes the name and the object id_ to the...
Definition: BaseObject.cc:128