GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Particle.hpp
Go to the documentation of this file.
1 //
2 // Author(s) : - Jean-luc CHARLES I2M-DuMAS/ENSAM Talence France
3 // <jean-luc.charles@ensam.eu>
4 // - Damien ANDRE SPCTS/ENS Ceramique industrielle, Limoges France
5 // <damien.andre@unilim.fr>
6 // - Jeremie GIRARDOT I2M-DuMAS/ENSAM Talence France
7 // <jeremie.girardot@ensam.eu>
8 // - Cedric Hubert LAMIH/UVHC Valenciennes France
9 // <cedric.hubert@univ-valenciennes.fr>
10 // - Ivan IORDANOFF I2M-DuMAS-MPI/ENSAM Talence France
11 // <ivan.iordanoff@ensam.eu>
12 //
13 // Copyright (C) 2008-2016 JL. CHARLES, D. ANDRE, I. IORDANOFF, J. GIRARDOT
14 //
15 //
16 //
17 //
18 //
19 // This program is free software: you can redistribute it and/or modify
20 // it under the terms of the GNU General Public License as published by
21 // the Free Software Foundation, either version 3 of the License, or
22 // (at your option) any later version.
23 //
24 // This program is distributed in the hope that it will be useful,
25 // but WITHOUT ANY WARRANTY; without even the implied warranty of
26 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 // GNU General Public License for more details.
28 //
29 // You should have received a copy of the GNU General Public License
30 // along with this program. If not, see <http://www.gnu.org/licenses/>.
31 
32 
33 
34 
35 #ifndef GranOO_SPH_Particle_hpp
36 #define GranOO_SPH_Particle_hpp
37 
38 
39 
40 #include "GranOO3/Physic/Node.hpp"
42 
43 
44 namespace GranOO3
45 {
46  namespace SPH
47  {
48 
49  class Particle : public Physic::Node, public Core::PropClass<Particle>, public Core::Register<Particle> {
50 
51  GRANOO_CLASS(SPH::Particle, Physic::Node);
52  GRANOO_CLASS_DEFAULT_COLOR(.8, .0, .1, 1.);
53 
54  public:
55  Particle(const Geom::Point&, double radius);
56  Particle();
57  virtual ~Particle();
58 
59 
60  GRANOO_ACCESS(h, double, _h);
61  GRANOO_ACCESS(radius , double, _radius );
62  GRANOO_ACCESS(density , double, _density );
63  GRANOO_ACCESS(pressure , double, _pressure );
64  GRANOO_ACCESS(viscosity, double, _viscosity);
65 
66  void set_mass(double);
67  double get_mass() const ;
68 
69  double get_bounding_radius() const;
70 
71  size_t neighbour_number() const;
72  std::vector<Interaction>& get_interaction();
73  void clear_interaction();
74  void add_interaction(Particle& part);
75 
76  // UPDATE LOCAL PARAM
77  template<class Kernel> void update_density();
78  void update_pressure(const double gazStiffness, const double gazdensity);
79  template<class Kernel> void apply_pressure_force();
80  template<class Kernel> void apply_viscous_force();
81 
82  // USEFULL
83  virtual std::string info() const;
84  virtual void draw();
85 
86  // IO
87  virtual std::ostream& write_ascii (std::ostream& out) const;
88  virtual std::istream& read_ascii (std::istream& in);
89 
90  private:
91  //BOOST SERIALIZATION
93  template<class Archive> void serialize(Archive&, const unsigned int);
94 
95  private:
96  double _mass;
97  double _h;
98  double _radius;
99  double _density;
100  double _pressure;
101  double _viscosity;
102  std::vector<Interaction> interaction_;
103  };
104 
105  inline size_t
107  return interaction_.size();
108  }
109 
110  inline std::vector<Interaction>&
112  return interaction_;
113  }
114 
115  inline void
117  interaction_.clear();
118  }
119 
120  inline void
122  interaction_.emplace_back(&part, part.get_position() - get_position());
123  }
124 
125  template<class Kernel> void
127  const Geom::Vector vecnull(0., 0., 0.);
128  _density = 0.;
129  _density += _mass * Kernel::k_def(_h, vecnull);
130 
131  for (auto& inter: interaction_) {
132  const SPH::Particle* part2 = inter.neighbour;
133  const Geom::Vector& vec = inter.distance;
134  const double hh = part2->get_h();
135  _density += part2->get_mass()* Kernel::k_def(hh, vec);
136  }
137  }
138 
139  inline void
140  Particle::update_pressure(const double gazStiffness, const double gazdensity) {
141  _pressure = gazStiffness * (_density - gazdensity);
142  }
143 
144  template<class Kernel> void
146  const double pressure1 = _pressure;
147  for (auto& inter: interaction_) {
148  SPH::Particle* part2 = inter.neighbour;
149  const Geom::Vector& vec = inter.distance;
150 
151  const double pressure2 = part2->get_pressure();
152  const double mass2 = part2->get_mass();
153  const double rho2 = part2->get_density();
154 
155  const double h = part2->get_h();
156  const Geom::Vector n = Kernel::gk_pres(h, vec);
157  force() -= ((pressure1 + pressure2) / 2.) * (mass2/rho2) * n;
158  }
159  }
160 
161  template<class Kernel> void
163  const Geom::Vector& u1 = linear_velocity();
164  for (auto& inter: interaction_) {
165  SPH::Particle* part2 = inter.neighbour;
166  const Geom::Vector& vec = inter.distance;
167 
168  const double h = get_h();
169  const double mu = part2->get_viscosity();
170  const Geom::Vector& u2 = part2->linear_velocity();
171  const double mass = part2->get_mass();
172  const double rho = part2->get_density();
173  force() += mu*(u2-u1)*(mass/rho)* Kernel::lk_visc(h, vec);
174  }
175  }
176 
177  template<class Archive>
178  void
179  Particle::serialize(Archive& ar, const unsigned int version) {
180  ar & boost::serialization::base_object<Physic::Node>(*this);
181  ar & _h;
182  ar & _radius;
183  ar & _density;
184  ar & _pressure;
185  ar & _viscosity;
186  }
187 
188  }
189 }
190 
191 
192 namespace GranOO3
193 {
194  GRANOO_CLASS_DECLARE_TPL(SPH::Particle);
195 }
196 
197 
198 #endif
199 
Definition: PropClass.hpp:47
Definition: SetOf.hpp:346
Definition: Point.hpp:62
Definition: Vector.hpp:75
Definition: Node.hpp:58
Definition: Particle.hpp:49
void update_density()
Definition: Particle.hpp:126
virtual std::ostream & write_ascii(std::ostream &out) const
Definition: Particle.cpp:102
std::vector< Interaction > interaction_
Definition: Particle.hpp:102
double _pressure
Definition: Particle.hpp:100
size_t neighbour_number() const
Definition: Particle.hpp:106
double _h
Definition: Particle.hpp:97
double _viscosity
Definition: Particle.hpp:101
void update_pressure(const double gazStiffness, const double gazdensity)
Definition: Particle.hpp:140
std::vector< Interaction > & get_interaction()
Definition: Particle.hpp:111
void clear_interaction()
Definition: Particle.hpp:116
void apply_pressure_force()
Definition: Particle.hpp:145
double _radius
Definition: Particle.hpp:98
void add_interaction(Particle &part)
Definition: Particle.hpp:121
Particle()
Definition: Particle.cpp:65
virtual ~Particle()
Definition: Particle.cpp:69
virtual void draw()
Definition: Particle.cpp:116
virtual std::string info() const
Definition: Particle.cpp:88
void set_mass(double)
Definition: Particle.cpp:78
friend class boost::serialization::access
Definition: Particle.hpp:92
double _mass
Definition: Particle.hpp:96
double get_bounding_radius() const
Definition: Particle.cpp:83
double get_mass() const
Definition: Particle.cpp:73
void serialize(Archive &, const unsigned int)
Definition: Particle.hpp:179
double _density
Definition: Particle.hpp:99
void apply_viscous_force()
Definition: Particle.hpp:162
virtual std::istream & read_ascii(std::istream &in)
Definition: Particle.cpp:109
Definition: Common.hpp:198
static char_cptr version
Definition: Exprtk.hpp:44221