GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Body.hpp
Go to the documentation of this file.
1 // This file is part of GranOO, a workbench for DEM simulation.
2 //
3 // Author(s) : - Damien Andre IRCER/UNILIM, Limoges France
4 // <damien.andre@unilim.fr>
5 // - Jean-luc Charles Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
6 // <jean-luc.charles@ensam.eu>
7 // - Jeremie Girardot Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
8 // <jeremie.girardot@ensam.eu>
9 // - Cedric Hubert LAMIH/UPHF, Valenciennes France
10 // <cedric.hubert@uphf.fr>
11 // - Ivan Iordanoff Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
12 // <ivan.iordanoff@ensam.eu>
13 //
14 // Copyright (C) 2008-2019 D. Andre, JL. Charles, J. Girardot, C. Hubert, I. Iordanoff
15 //
16 // This program is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 // This program is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License
27 // along with this program. If not, see <http://www.gnu.org/licenses/>.
28 
29 
30 #ifndef _LibPhysic_Body_H
31 #define _LibPhysic_Body_H
32 
33 #include "GranOO3/Physic/Node.hpp"
34 #include "GranOO3/Physic/ExtendedSetOf/Body.hpp"
35 #include "GranOO3/Shape/Volume.hpp"
36 #include "GranOO3/Shape/Sphere.hpp"
38 
39 namespace GranOO3
40 {
41  namespace Physic
42  {
43  class Body : public Node, public Core::PropClass<Body>, public Core::Register<Body> {
44 
45  GRANOO_CLASS(Physic::Body, Node);
46 
47  public:
48  // Constructors and destructor
49  Body(Shape::Volume& shape, const Geom::Point& p, const Geom::Quaternion& q, double mass, const Geom::Tensor& inertia);
50  Body(Shape::Volume& shape, const Geom::Point& p);
51  Body(Shape::Volume& shape);
52 
53  virtual ~Body() = 0;
54 
55  // Accessor
56  GRANOO_ACCESS_GET(inertia_tensor , Geom::Tensor, _inertia_tensor );
57  GRANOO_ACCESS_GET(inverse_inertia_tensor, Geom::Tensor, _inverse_inertia_tensor );
58  GRANOO_ACCESS_GET(density , double , _density );
59 
60  void set_inertia_tensor(const Geom::Tensor& inertia);
61  void set_density(double density);
62 
63  // Kinematic parameters
65  double get_kinetic_energy() const;
66 
67  // MASS
68  double get_mass() const;
69 
70  //FORCE COMPUTATION
71  void apply_force_at(const Geom::Vector&, const Geom::Point&);
72 
73  // VOLUME SHAPE CASTING AND CO
74  const Shape::Volume& to_volume_shape() const;
76  double get_volume() const;
77  double get_bounding_radius() const;
78 
79  // COLLISION
80  AABB aabb() const;
81  bool collide(const Body& other, Collision::Data& col);
82  bool collide(const Body& other);
83 
84  // CLONING
85  void make_equal_to(const Body& other);
86 
87  // SOME INFO
88  std::string info() const;
89 
90  // IO
91  virtual std::ostream& write_ascii (std::ostream& out) const;
92  virtual std::istream& read_ascii (std::istream& in);
93  virtual std::ostream& export_to_povray (std::ostream& out) const;
94 
95  private:
97 
98  private:
99  Body(const Body&) = delete;
100  Body & operator=(const Body &) = delete;
101 
102  //SERIALIZATION
104  template<class Archive> void save(Archive&, const unsigned int ) const;
105  template<class Archive> void load(Archive&, const unsigned int);
107 
108  private:
110 
111  protected:
112  double _density;
113  double _mass;
116  };
117 
118  inline
119  Body::Body(Shape::Volume& shape, const Geom::Point & p, const Geom::Quaternion& q, double mass, const Geom::Tensor& tensor)
120  : Node(p),
121  _volume_shape(shape),
122  _density(0.),
123  _mass(mass),
124  _inertia_tensor(tensor),
125  _inverse_inertia_tensor(tensor.inverse()) {
126 
127  }
128 
129  inline
130  Body::Body(Shape::Volume& shape, const Geom::Point & p) :
131  Body(shape, p, Geom::global::quaternion, 0., Geom::global::tensor) {
132  }
133 
134  inline
136  Body(shape, Geom::global::center, Geom::global::quaternion, 0., Geom::global::tensor) {
137  }
138 
139  inline
141  }
142 
143  inline const Shape::Volume&
145  return _volume_shape;
146  }
147 
148  inline Shape::Volume&
150  return _volume_shape;
151  }
152 
153 
154  inline void
155  Body::apply_force_at(const Geom::Vector& force, const Geom::Point& applicationPoint) {
156  Node::apply_force(force);
157  torque() += Geom::Vector(get_center(),applicationPoint) ^ force;
158  }
159 
160  inline AABB
161  Body::aabb() const {
162  return to_volume_shape().aabb();
163  }
164 
165  inline void
168  }
169 
170  inline void
172  _inertia_tensor = t;
174  }
175 
176  inline void
177  Body::set_density(double d) {
178  _density = d;
182  }
183 
184  inline Geom::Vector
186  return torque() + (Geom::Vector(A, get_center())^force());
187  }
188 
189  inline double
191  return _volume_shape.get_volume();
192  }
193 
194  inline double
196  return _volume_shape.get_bounding_radius();
197  }
198 
199  inline double
201  const Geom::Quaternion & q = quaternion();
202  const Geom::Quaternion & dq = quaternion_velocity();
203  const Geom::Vector w = (2*(q.conjugate()*dq)).to_vector();
204  const Geom::Tensor& I = _inertia_tensor;
205  const double K = 0.5*(I.xx()*w.x()*w.x() + I.yy()*w.y()*w.y() + I.zz()*w.z()*w.z());
206  const double V = get_linear_velocity().norm();
207  return(K + 0.5*(get_mass()*V*V));
208  }
209 
210  inline bool
212  return to_volume_shape().collide(b.to_volume_shape(), c);
213  }
214 
215  inline bool
216  Body::collide(const Body& b) {
218  }
219 
220 
221  template<class Archive> void
222  Body::save(Archive& ar, const unsigned int v) const {
223  ar << boost::serialization::base_object<Node>(*this);
224  ar << _density;
225  ar << _inertia_tensor;
226  ar << _mass;
227 
228  }
229 
230  template<class Archive> void
231  Body::load(Archive& ar, const unsigned int v) {
232  ar >> boost::serialization::base_object<Node>(*this);
233  ar >> _density;
234  ar >> _inertia_tensor;
235  ar >> _mass;
237  }
238 
239  }
240 }
241 
242 #include <boost/serialization/version.hpp>
244 
245 namespace GranOO3 {
246  GRANOO_CLASS_DECLARE_TPL(Physic::Body);
247 }
248 
249 #endif
250 
BOOST_CLASS_VERSION(GranOO3::Physic::Body, 0) namespace GranOO3
Definition: Body.hpp:243
Definition: PropClass.hpp:47
Definition: SetOf.hpp:346
Definition: Point.hpp:62
Definition: Quaternion.hpp:54
Quaternion conjugate() const
Definition: Tensor.hpp:62
Tensor inverse() const
Definition: Vector.hpp:75
a class that represents a body
Definition: Body.hpp:43
double get_kinetic_energy() const
Definition: Body.hpp:200
double get_mass() const
get the current mass value of the body
Definition: Body.cpp:58
virtual std::ostream & export_to_povray(std::ostream &out) const
exporting to povray format
Definition: Body.cpp:85
Geom::Vector compute_torque_at(const Geom::Point &A) const
Definition: Body.hpp:185
AABB aabb() const
get the aabb tree the body
Definition: Body.hpp:161
void apply_force_at(const Geom::Vector &, const Geom::Point &)
Definition: Body.hpp:155
double _density
the density value of the body
Definition: Body.hpp:112
void set_density(double density)
set the density value
Definition: Body.hpp:177
void save(Archive &, const unsigned int) const
complete serializing of the element in the *.gdd format
Definition: Body.hpp:222
double get_volume() const
get the current volume of the body
Definition: Body.hpp:190
Geom::Tensor _inertia_tensor
the inertia tensor of the body
Definition: Body.hpp:114
bool collide(const Body &other, Collision::Data &col)
collision detection with another body
Definition: Body.hpp:211
void make_equal_to(const Body &other)
for equalizing two bodies
Definition: Body.cpp:47
void set_inertia_tensor(const Geom::Tensor &inertia)
set the inertia tensor value
Definition: Body.hpp:171
Body & operator=(const Body &)=delete
Geom::Tensor _inverse_inertia_tensor
the inverse of the inertia tensor of the body
Definition: Body.hpp:115
Body(Shape::Volume &shape, const Geom::Point &p, const Geom::Quaternion &q, double mass, const Geom::Tensor &inertia)
constructor
Definition: Body.hpp:119
double get_bounding_radius() const
get the current bounding radius of the body
Definition: Body.hpp:195
double _mass
the mass value of the body
Definition: Body.hpp:113
friend class boost::serialization::access
Definition: Body.hpp:103
void load(Archive &, const unsigned int)
complete serializing of the element in the *.gdd format
Definition: Body.hpp:231
virtual std::istream & read_ascii(std::istream &in)
update the current state of the body from an ascii file format *.lgdd
Definition: Body.cpp:79
virtual ~Body()=0
destructor
Definition: Body.hpp:140
std::string info() const
Display some useful info in the terminal
Definition: Body.cpp:63
virtual std::ostream & write_ascii(std::ostream &out) const
dump the current state of the bodyt in a ascii file (standard *.lgdd format)
Definition: Body.cpp:72
void update_inverse_inertia_tensor()
update the current value of Body::_inverse_inertia_tensor from the Body::_inertia_tensor value
Definition: Body.hpp:166
Body(const Body &)=delete
Shape::Volume & _volume_shape
Definition: Body.hpp:109
const Shape::Volume & to_volume_shape() const
cast the current object to Shape::Volume
Definition: Body.hpp:144
Definition: Node.hpp:58
void apply_force(const Geom::Vector &)
Definition: Node.hpp:462
Definition: Volume.hpp:103
virtual AABB aabb() const =0
virtual bool collide(const Volume &, Collision::Data &) const =0
virtual double get_volume() const =0
virtual void compute_inertia_tensor(double density, Geom::Tensor &) const =0
Definition: Common.hpp:198
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t t(t+t)") define_sfop3(16
Definition: StaticAABBTree.hpp:38
Definition: Data.hpp:43
static Data main
Definition: Data.hpp:45