MercuryDPM  Alpha
 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 #include "Particles/BaseParticle.h"
32 
33 
34 class BaseParticle;
35 class BaseInteractable;
36 
38 {
39  density_ = 0.0;
40 #ifdef DEBUG_CONSTRUCTOR
41  std::cout<<"ParticleSpecies::ParticleSpecies() finished"<<std::endl;
42 #endif
43 }
44 
49 {
51 #ifdef DEBUG_CONSTRUCTOR
52  std::cout<<"ParticleSpecies::ParticleSpecies(const ParticleSpecies &p) finished"<<std::endl;
53 #endif
54 }
55 
57 {
58 #ifdef DEBUG_DESTRUCTOR
59  std::cout<<"ParticleSpecies::~ParticleSpecies() finished"<<std::endl;
60 #endif
61 }
62 
66 void ParticleSpecies::write(std::ostream& os) const
67 {
68  //note we inherit from BaseObject, not BaseParticle
70  os << " density " << density_;
71 }
72 
76 void ParticleSpecies::read(std::istream& is)
77 {
79  std::string dummy;
80  is >> dummy >> density_;
81 }
82 
86 std::string ParticleSpecies::getBaseName() const
87 {
88  return "Particle";
89 }
90 
95 {
96  logger.assert_always(density>=0,"[ParticleSpecies::setDensity(%)] value cannot be negative",density);
97  density_ = density;
99 }
100 
105 {
106  return density_;
107 }
108 
110 {
111  return getDensity()*getVolumeFromRadius(radius);
112 }
113 
116 {
117  if (getHandler() == nullptr)
118  {
119  logger(ERROR, "[Species::VolumeFromRadius()] No handler has been set, therefore, I can't figure out the dimensions.");
120  return 0;
121  }
122 
123  unsigned int particleDimensions = getHandler()->getDPMBase()->getParticleDimensions();
124  if (particleDimensions == 3)
125  {
126  return 4.0 / 3.0 * constants::pi * radius * radius * radius;
127  }
128  else if (particleDimensions == 2)
129  {
130  return constants::pi * radius * radius;
131  }
132  else if (particleDimensions == 1)
133  {
134  return 2.0 * radius;
135  }
136  else
137  {
138  logger(ERROR, "[Species::VolumeFromRadius()] the dimension of the particle is wrongly set to %",particleDimensions);
139  return 0.0;
140  }
141 }
142 
146 {
147  if (!p->isFixed())
148  {
149  switch (p->getParticleDimensions())
150  {
151  case 3:
152  {
153  p->mass_ = (4.0 / 3.0 * constants::pi * p->getRadius() * p->getRadius() * p->getRadius() * getDensity());
154  p->invMass_ = 1.0 / (p->mass_);
155  p->inertia_ = (.4 * p->getMass() * mathsFunc::square(p->getRadius()));
156  p->invInertia_ = 1.0 / (p->inertia_);
157  break;
158  }
159  case 2:
160  {
161  p->mass_ = (constants::pi * p->getRadius() * p->getRadius() * getDensity());
162  p->invMass_ = 1.0 / (p->mass_);
163  p->inertia_ = (.5 * p->getMass() * mathsFunc::square(p->getRadius()));
164  p->invInertia_ = 1.0 / (p->inertia_);
165  break;
166  }
167  case 1:
168  {
169  p->mass_ = (2.0 * p->getRadius() * getDensity());
170  p->invMass_ = 1.0/p->mass_;
171  p->inertia_ = 0.0;
172  p->invInertia_ = std::numeric_limits<Mdouble>::quiet_NaN();
173  break;
174  }
175  default:
176  {
177  logger(ERROR, "ParticleSpecies::computeMass()] the dimension of the particle is not set");
178  }
179  }
180  }
181 }
182 
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.cc:108
Mdouble invInertia_
Particle inertia_.
Definition: BaseParticle.h:409
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
unsigned int getParticleDimensions() const
Returns the particle dimensions.
Definition: DPMBase.cc:599
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:406
Mdouble invMass_
Particle mass_.
Definition: BaseParticle.h:407
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 getVolumeFromRadius(const Mdouble radius) const
Mdouble inertia_
Inverse Particle mass (for computation optimization)
Definition: BaseParticle.h:408
Mdouble getMassFromRadius(const Mdouble radius) const
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:1001
void setDensity(Mdouble density)
Allows 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:124
void read(std::istream &is)
Reads the species properties from an input stream.
Mdouble density_
The mass density.
Defines the basic properties that a interactable object can have.
Mdouble getDensity() const
Allows density_ to be accessed.
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:543
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:133