GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Bond.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 #ifndef _DEM_Bond_hpp_
30 #define _DEM_Bond_hpp_
31 
32 #include "GranOO3/3rdParty/Eigen/Dense"
33 
34 #include "GranOO3/Core/Prop.hpp"
35 #include "GranOO3/Core/SetOf.hpp"
38 
40 
41 namespace GranOO3
42 {
43  namespace DEM
44  {
45  class Element;
46 
47  class Bond : public Physic::BodyInteraction,
48  public Core::PropClass<Bond>,
49  public Core::Register<Bond> {
50 
51  GRANOO_CLASS(DEM::Bond, Physic::BodyInteraction);
52  GRANOO_CLASS_DEFAULT_COLOR(.8,.0, .1, 1.);
53 
54  public:
55  static double get_disabled_cumulative_surface();
56  static double epsilon;
57  static double draw_solid_factor;
58 
60  enum DrawMode {SOLID, LINE, NO};
62 
63  public:
64  // for signal management
66 
67  private:
69 
70  public:
71  // Constructors and destructor
72  Bond(Element& el1, Element& el2, bool contact = false); // use contact == true for bond that comes from contact
73  virtual ~Bond() = 0;
74 
75  // Usefull for internal use only, NOT DOCUMENTED !
76  virtual void draw();
77  virtual std::string info() const;
78 
79  GRANOO_ACCESS (linear_damping_factor , double , _linear_damping_factor );
80  GRANOO_ACCESS (angular_damping_factor, double , _angular_damping_factor );
81  GRANOO_ACCESS (relaxed_length , double , _relaxed_length );
82  GRANOO_ACCESS (initial_length , double , _initial_length );
83  GRANOO_ACCESS (current_length , double , _current_length );
84  GRANOO_ACCESS (max_relative_elongation , double , _max_relative_elongation );
85  GRANOO_ACCESS (surface , double , _surface );
86  GRANOO_ACCESS (failure_mode , FailureMode, _failure_mode );
87 
88  GRANOO_ACCESS_GET_COPY(current_relative_elongation, double, (_current_length - _initial_length)/_initial_length);
89 
90  GRANOO_ACCESS_GET(initial_pos1, Geom::Point, _initial_pos1);
91  GRANOO_ACCESS_GET(initial_pos2, Geom::Point, _initial_pos2);
92  GRANOO_ACCESS_GET(Q1, Geom::Quaternion, _quat_element1);
93  GRANOO_ACCESS_GET(Q2, Geom::Quaternion, _quat_element2);
94  GRANOO_ACCESS_GET(Q , Geom::Quaternion, _local_quat );
95  GRANOO_ACCESS_GET(F , Geom::Frame , _local_frame );
96  GRANOO_ACCESS_REF(local_frame , Geom::Frame, _local_frame );
97  GRANOO_ACCESS_REF(local_frame_element1, Geom::Frame, _local_frame_element1);
98  GRANOO_ACCESS_REF(local_frame_element2, Geom::Frame, _local_frame_element2);
99 
100  // Accessing to discrete elements
101  GRANOO_ACCESS_GET_PTR (element1, Element, _element1);
102  GRANOO_ACCESS_REF_PTR (element1, Element, _element1);
103  GRANOO_ACCESS_REF_CONST_PTR(element1, Element, _element1);
104 
105  GRANOO_ACCESS_GET_PTR (element2, Element, _element2);
106  GRANOO_ACCESS_REF_PTR (element2, Element, _element2);
107  GRANOO_ACCESS_REF_CONST_PTR(element2, Element, _element2);
108 
109  // for compatibility with ElementPair
110  Element& get_item1();
111  const Element& get_item1() const;
112  Element& get_item2();
113  const Element& get_item2() const;
114 
115  Element& item1();
116  Element& item2();
117 
118  // force
119  double get_normal_force_intensity() const;
120  double get_tangential_force_intensity() const;
121 
122  // Access to bonded element
123  Element & bonded_element(const Element &);
124  const Element & get_bonded_element(const Element &) const;
125 
126  // Loading management
127  virtual void compute_load();
128  virtual double get_linear_stiffness() const;
129  virtual double get_angular_stiffness() const;
130 
133  void apply_load();
134 
135  // Enabled-disabled management
136  void disable(bool manage_slave = true);
137  void disable_fast_mode(bool manage_slave = true);
138  void enable(bool manage_slave = true);
139  bool is_disabled() const;
140 
141  // Enabled-disabled management
142  void crack(bool manage_slave = true);
143  void uncrack(bool manage_slave = true);
144  bool is_cracked() const;
145 
146 
147 
148  // local frame management (must be triggered by child class)
149  void init_local_frame(bool update_initial_param = false);
150  void update_local_frame();
151  void update_current_length();
152 
153  // Voronoi bond management
154  void build_voronoi_bond();
155 
156  // Update FEM/DEM connection
157  virtual void stiffness_matrix(Eigen::MatrixXd &kMatrix) { AssertMsg(0, "Method 'stiffness_matrix()' is not implemented."); };
158  virtual void update_dof() { AssertMsg(0, "Method 'update_dof()' is not implemented."); };
159  const std::vector<unsigned int>& get_dof() const;
160 
161  // Compute local displacement
162  const Geom::Point& initial_pos(const Element& ) const;
163  Geom::Vector get_disp(const Element& ) const;
164  Geom::Vector get_disp1() const;
165  Geom::Vector get_disp2() const;
166 
167  // swap element
168  void swap(Element& from, Element& to);
169  void add_slave(Bond& b);
170 
171  // IO
172  virtual std::ostream& export_to_povray(std::ostream& out) const;
173 
174  protected:
175  //SERIALIZATION
177  template<class Archive> void save(Archive&, const unsigned int ) const;
178  template<class Archive> void load(Archive&, const unsigned int);
180 
181  private:
182  Bond() = delete;
183  Bond(const Bond&) = delete;
184  Bond & operator=(const Bond &) = delete;
185 
186  protected:
189 
190  private:
191  bool _disabled;
192  bool _cracked;
197  //Geom Data
198  Geom::Quaternion _quat_element1; // express in de1 local frame
199  Geom::Quaternion _quat_element2; // express in de2 local frame
200  Geom::Quaternion _local_quat; // express in global frame
201  Geom::Frame _local_frame; // local frame (expressed from global frame)
202  Geom::Point _local_center_element1; // express in de1 local frame
203  Geom::Frame _local_frame_element1; // from (P1, Q1, de1.local_frame)
204  Geom::Point _local_center_element2; // express in de1 local frame
205  Geom::Frame _local_frame_element2; // from (P1, Q1, de1.local_frame)
206  protected:
212  double _surface;
214  std::vector<unsigned int> _dofs;
215 
216  };
217 
218  inline Element &
220  if (&de == _element1)
221  return *_element2;
222 
223  SafeModeAssert(&de == _element2, "can't find de");
224 
225  return *_element1;
226  }
227 
228  inline const Element &
229  Bond::get_bonded_element(const Element & de) const {
230  if (&de == _element1)
231  return *_element2;
232 
233  SafeModeAssert(&de == _element2, "can't find de");
234 
235  return *_element1;
236  }
237 
238  inline bool
240  return _disabled;
241  }
242 
243  inline bool
245  return _cracked;
246  }
247 
248 
249  inline const std::vector<unsigned int> &
250  Bond::get_dof() const {
251  return _dofs;
252  }
253 
254 
255  // for compatibility with ElementPair
257  return *_element1;
258  }
259 
260  inline const Element& Bond::get_item1() const {
261  return *_element1;
262  }
263 
265  return *_element2;
266  }
267 
268  inline const Element& Bond::get_item2() const {
269  return *_element2;
270  }
271 
272  inline Element& Bond::item1() {
273  return *_element1;
274  }
275 
276  inline Element& Bond::item2() {
277  return *_element2;
278  }
279 
280  //BOOST SERIALIZATION
281  template<class Archive> void
282  Bond::save(Archive & ar, const unsigned int version) const{
283  ar << boost::serialization::base_object<Physic::BodyInteraction>(*this);
284  ar << boost::serialization::base_object<Core::PropClass<Bond> >(*this);
285  ar << _initial_length;
286 
287  ar << _initial_pos1;
288  ar << _initial_pos2;
289  ar << _quat_element1;
290  ar << _quat_element2;
291  ar << _local_quat;
293 
296  ar << _relaxed_length;
297  ar << _current_length;
299  ar << _surface;
300 
301  if (version >= 1)
302  ar << _failure_mode;
303 
304  if (version >= 2)
305  ar << _cracked;
306  }
307 
308  template<class Archive> void
309  Bond::load(Archive & ar, const unsigned int version) {
310  ar >> boost::serialization::base_object<Physic::BodyInteraction>(*this);
311  ar >> boost::serialization::base_object<Core::PropClass<Bond> >(*this);
312  ar >> _initial_length;
313 
314  ar >> _initial_pos1;
315  ar >> _initial_pos2;
316  ar >> _quat_element1;
317  ar >> _quat_element2;
318  ar >> _local_quat;
320 
323  ar >> _relaxed_length;
324  ar >> _current_length;
326  ar >> _surface;
327 
328  if (version >= 1)
329  ar >> _failure_mode;
330 
331  if (version >= 2)
332  ar >> _cracked;
333 
335  }
336 
337  }
338 }
339 
340 #include <boost/serialization/version.hpp>
342 
343 namespace GranOO3
344 {
345  GRANOO_CLASS_DECLARE_TPL(DEM::Bond);
346  extern template class Core::PropClass< DEM::Bond >;
347 }
348 
349 #endif
BOOST_CLASS_VERSION(GranOO3::DEM::Bond, 2) namespace GranOO3
Definition: Bond.hpp:341
#define SafeModeAssert(condition, message)
Definition: Macro.hpp:47
#define AssertMsg(condition, message)
Definition: Macro.hpp:67
Definition: PropClass.hpp:47
Definition: SetOf.hpp:346
Definition: SetOf.hpp:153
Definition: Signal.hpp:53
the base class for all bonds between discrete elements.
Definition: Bond.hpp:49
void apply_angular_damping_factor()
similar as apply_linear_damping_factor() for rotation
Definition: Bond.cpp:294
bool _cracked
Definition: Bond.hpp:192
Geom::Vector get_disp2() const
similar as get_disp1()
Definition: Bond.cpp:345
void add_slave(Bond &b)
add a slave bond (useful for periodic simulation)
Definition: Bond.cpp:389
virtual void draw()
OpenGL draw of the bond
Definition: Bond.cpp:428
Element & bonded_element(const Element &)
get the bonded element
Definition: Bond.hpp:219
std::vector< unsigned int > _dofs
a vector that stores the dof of the bond
Definition: Bond.hpp:214
const std::vector< unsigned int > & get_dof() const
get the dof vector
Definition: Bond.hpp:250
Geom::Quaternion _quat_element1
the quaternion used for building the bond local frame (expressed in the _element1 local frame)
Definition: Bond.hpp:198
double _linear_damping_factor
the linear damping factor of the bond
Definition: Bond.hpp:207
Element & get_item1()
Definition: Bond.hpp:256
virtual double get_linear_stiffness() const
compute the linear stiffness of the bond
Definition: Bond.cpp:350
void crack(bool manage_slave=true)
Definition: Bond.cpp:218
bool is_disabled() const
check if the bond is enable or not
Definition: Bond.hpp:239
FailureMode _failure_mode
Definition: Bond.hpp:193
Geom::Vector get_disp1() const
get the displacement of the first bonded element (_element1)
Definition: Bond.cpp:340
Bond(const Bond &)=delete
Bond & operator=(const Bond &)=delete
double _surface
this attribute stores the corresponding normal surface of the bond
Definition: Bond.hpp:212
DrawMode
Definition: Bond.hpp:60
@ NO
Definition: Bond.hpp:60
@ LINE
Definition: Bond.hpp:60
@ SOLID
Definition: Bond.hpp:60
Geom::Frame _local_frame_element2
Definition: Bond.hpp:205
bool is_cracked() const
Definition: Bond.hpp:244
Geom::Quaternion _local_quat
this the quaternion that must be updated for updating the _local_frame
Definition: Bond.hpp:200
void enable(bool manage_slave=true)
simply enable the bond by switching the _disabled attribute to false
Definition: Bond.cpp:207
Geom::Quaternion _quat_element2
same as the _quat_element1 but expressed in the _element2 local frame)
Definition: Bond.hpp:199
void apply_linear_damping_factor()
compute and apply the linear (translation) damping factor of the bond
Definition: Bond.cpp:272
void swap(Element &from, Element &to)
swap the bond from the Element from to to
Definition: Bond.cpp:369
double _max_relative_elongation
a threshold corresponding to a maximal admissible relative elongation (the longitudinal strain)
Definition: Bond.hpp:211
void init_local_frame(bool update_initial_param=false)
initialize the bond local frame
Definition: Bond.cpp:110
Geom::Point _initial_pos1
the initial position of the _element1 expressed in the _element2 local frame
Definition: Bond.hpp:195
static double _disabled_cumulative_surface
the attribute where the total disabled surface is stored
Definition: Bond.hpp:68
void save(Archive &, const unsigned int) const
Definition: Bond.hpp:282
virtual double get_angular_stiffness() const
similar as get_linear_stiffness() for rotation
Definition: Bond.cpp:355
FailureMode
Definition: Bond.hpp:59
@ TENSION
Definition: Bond.hpp:59
@ COMPRESSION
Definition: Bond.hpp:59
@ SHEAR
Definition: Bond.hpp:59
@ NONE
Definition: Bond.hpp:59
void update_current_length()
update the current value of the bond length (see _current_length attribute)
Definition: Bond.cpp:241
void uncrack(bool manage_slave=true)
Definition: Bond.cpp:232
double get_normal_force_intensity() const
Definition: Bond.cpp:396
Geom::Frame _local_frame_element1
this the frame that corresponds to the local _element1 frame expressed in the _local_frame
Definition: Bond.hpp:203
virtual void compute_load()
compute the reaction force and torque of the bond
Definition: Bond.cpp:262
virtual std::ostream & export_to_povray(std::ostream &out) const
exporting to povray format
Definition: Bond.cpp:470
Element & item1()
Definition: Bond.hpp:272
void disable(bool manage_slave=true)
disable the bond
Definition: Bond.cpp:176
Element & item2()
Definition: Bond.hpp:276
void apply_load()
apply the computed reaction force and torque to the bonded Element (_element1 and _element2)
Definition: Bond.cpp:247
static Core::Signal< Bond & > disable_signal
get the signal when a bond is disabled
Definition: Bond.hpp:65
void update_local_frame()
update the bond local frame
Definition: Bond.cpp:151
static DrawMode draw_mode
Definition: Bond.hpp:61
double _current_length
the current length of the bond that correspond to the norm of the vector between the center of the bo...
Definition: Bond.hpp:210
virtual void update_dof()
update the bond dof
Definition: Bond.hpp:158
static double get_disabled_cumulative_surface()
get the total surface disabled surface
Definition: Bond.cpp:63
virtual std::string info() const
Display some useful info in the terminal
Definition: Bond.cpp:415
Geom::Point _local_center_element2
Definition: Bond.hpp:204
double get_tangential_force_intensity() const
Definition: Bond.cpp:405
Geom::Point _local_center_element1
the center of _element1 expressed in the local frame. It is always equal to (0,0,0)
Definition: Bond.hpp:202
void build_voronoi_bond()
build a voronoi bond from the current bond
Definition: Bond.cpp:361
void load(Archive &, const unsigned int)
Definition: Bond.hpp:309
Geom::Vector get_disp(const Element &) const
get the displacement of the el element
Definition: Bond.cpp:328
virtual ~Bond()=0
Destructor.
Definition: Bond.cpp:101
double _initial_length
an attribute that stores the bond initial length
Definition: Bond.hpp:194
friend class boost::serialization::access
Definition: Bond.hpp:176
static double draw_solid_factor
Definition: Bond.hpp:57
void disable_fast_mode(bool manage_slave=true)
simply disable the bond by switching the _disabled attribute to true without doing the lot of things ...
Definition: Bond.cpp:198
const Geom::Point & initial_pos(const Element &) const
get the initial position of the el element
Definition: Bond.cpp:317
const Element & get_bonded_element(const Element &) const
same as bonded_element(const Element&) (provided for convenience)
Definition: Bond.hpp:229
Element & get_item2()
Definition: Bond.hpp:264
Core::SetOfBase< Bond > _slave
a container that list the slave bond
Definition: Bond.hpp:213
Element * _element1
the first of the two bonded Element
Definition: Bond.hpp:187
double _relaxed_length
the relaxed length of the bond.
Definition: Bond.hpp:209
Element * _element2
the second of the two bonded Element
Definition: Bond.hpp:188
virtual void stiffness_matrix(Eigen::MatrixXd &kMatrix)
assemble a stiffness matrix
Definition: Bond.hpp:157
Geom::Point _initial_pos2
the initial position of the _element2 expressed in the _element1 local frame
Definition: Bond.hpp:196
double _angular_damping_factor
the angular damping factor of the bond
Definition: Bond.hpp:208
Geom::Frame _local_frame
the bond local frame, useful for making computation
Definition: Bond.hpp:201
bool _disabled
an attribute that stores the enable/disable state
Definition: Bond.hpp:191
static double epsilon
a very small value used as a threshold
Definition: Bond.hpp:56
a base class that represents an element
Definition: Element.hpp:55
Definition: Frame.hpp:68
void update_glMatrix()
Definition: Frame.cpp:94
Definition: Point.hpp:62
Definition: Quaternion.hpp:54
Definition: Vector.hpp:75
a class that represents a generic physical interaction between two bodies
Definition: BodyInteraction.hpp:44
Definition: Common.hpp:198
static char_cptr version
Definition: Exprtk.hpp:44221