GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
ContactBond.hpp
Go to the documentation of this file.
1 // This file is part of GranOO, a workbench for DEM simulation.
2 //
3 // Author(s) : - Jean-luc CHARLES I2M-DuMAS/ENSAM Talence France
4 // <jean-luc.charles@ensam.eu>
5 // - Damien ANDRE SPCTS/ENS Ceramique industrielle, Limoges France
6 // <damien.andre@unilim.fr>
7 // - Jeremie GIRARDOT I2M-DuMAS/ENSAM Talence France
8 // <jeremie.girardot@ensam.eu>
9 // - Cedric Hubert LAMIH/UVHC Valenciennes France
10 // <cedric.hubert@univ-valenciennes.fr>
11 // - Ivan IORDANOFF I2M-DuMAS-MPI/ENSAM Talence France
12 // <ivan.iordanoff@ensam.eu>
13 //
14 // Copyright (C) 2008-2016 JL. CHARLES, D. ANDRE, I. IORDANOFF, J. GIRARDOT
15 //
16 //
17 //
18 //
19 //
20 // This program is free software: you can redistribute it and/or modify
21 // it under the terms of the GNU General Public License as published by
22 // the Free Software Foundation, either version 3 of the License, or
23 // (at your option) any later version.
24 //
25 // This program is distributed in the hope that it will be useful,
26 // but WITHOUT ANY WARRANTY; without even the implied warranty of
27 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 // GNU General Public License for more details.
29 //
30 // You should have received a copy of the GNU General Public License
31 // along with this program. If not, see <http://www.gnu.org/licenses/>.
32 
33 
34 #ifndef _libDEM_ContactBond_hpp_
35 #define _libDEM_ContactBond_hpp_
36 
37 #include <string>
38 #include <vector>
39 
40 
41 
42 #include "GranOO3/DEM/Bond.hpp"
43 #include "GranOO3/Core/SetOf.hpp"
44 #include "GranOO3/DEM/Element.hpp"
46 
47 #include "GranOO3/Geom/Point.hpp"
49 
50 namespace GranOO3
51 {
52  namespace DEM
53  {
54 
55 
56  class ContactBond : public Bond,
57  public Core::Register<ContactBond >,
59  {
60 
61  GRANOO_CLASS(DEM::ContactBond, Bond);
62 
63  public:
64  template<class T1, class T2> static void init_contact_detection_step();
65  template<class T1, class T2> static void manage_contact(T1& t1, T2 &t2);
66  template<class T1, class T2> static void apply_contact_load(T1& t1, T2 &t2, const Geom::Vector& force, const Geom::Vector& torque, const Geom::Point& contact, const double surface=0.);
67 
68  private:
69  static std::map<unsigned long long int, ContactBond*> _all_map;
70 
71  public:
72  //CONSTRUCTORS & DESTRUCTORS
73  ContactBond(Element& el1, Element& el2);
74  virtual ~ContactBond();
75 
76  //USEFULL
77  void init();
78  virtual void update();
79  virtual void compute_load();
80  virtual double compute_critical_time_step() const;
81  virtual std::string info() const;
82 
83  private:
84  ContactBond() = delete;
85  ContactBond(const ContactBond&) = delete;
86  ContactBond & operator=(const ContactBond&) = delete;
87 
88  private:
89  //BOOST SERIALIZATION
91  template<class Archive> void serialize(Archive&, const unsigned int);
92 
93  private:
94  const unsigned long long int _numID;
95  };
96 
97  //BOOST SERIALIZATION
98 
99  template<class Archive> void
100  ContactBond::serialize(Archive & ar, const unsigned int version) {
101  ar &boost::serialization::base_object<Bond>(*this);
102  }
103 
104  template<class T1, class T2>
105  inline void
108  for (auto& b : ContactBond::all()) {
109  b->clear_force();
110  b->clear_torque();
111  b->disable_fast_mode();
112  }
113  }
114  }
115 
116  template<class T1, class T2>
117  inline void
120  const unsigned long long int numID = Collision::Contact<T1, T2>::compute_ID(t1,t2);
121  if (_all_map.count(numID) == 0) {
122  Element* el1 = dynamic_cast<Element*>(&t1);
123  Element* el2 = dynamic_cast<Element*>(&t2);
124  InternAssert(el1 != nullptr);
125  InternAssert(el2 != nullptr);
126 
127  ContactBond* b = new ContactBond(*el1, *el2);
128  b->clear_force();
129  b->clear_torque();
130  InternAssert(_all_map.count(numID) == 1);
131  } else {
132  InternAssert(_all_map.count(numID) == 1);
133  _all_map[numID]->enable();
134  }
135  }
136  }
137  template<class T1, class T2>
138  inline void
140  const Geom::Vector& torque, const Geom::Point& contact_point, const double surface) {
142  const unsigned long long int numID = Collision::Contact<T1, T2>::compute_ID(t1,t2);
143  InternAssert(_all_map.count(numID) == 1);
144  ContactBond* b = _all_map[numID];
145  InternAssert(b->is_disabled() == false);
146 
147  const DEM::Element& el1 = b->get_element1();
148  const DEM::Element& el2 = b->get_element2();
149  const bool inverse = !t1.is_same(b->get_element1());
150 
151  //Check
152  if (inverse)
153  InternAssert(t2.is_same(el1) && t1.is_same(el2));
154  else
155  InternAssert(t1.is_same(el1) && t2.is_same(el2));
156 
157  Geom::Vector f = (inverse == false) ? force : -force ;
158  Geom::Vector t = (inverse == false) ? torque : -torque;
159 
160  b->_force_on1 = f;
161  b->_force_on2 = -f;
162 
163  b->_torque_on1 = t + (Geom::Vector(b->get_element1().get_center(), contact_point) ^ f);
164  b->_torque_on2 = -t + (Geom::Vector(b->get_element2().get_center(), contact_point) ^ -f);
165 
166  b->set_surface(surface);
167 
168  }
169  }
170 
171  }
172 }
173 
174 
175 #include <boost/serialization/version.hpp>
177 
178 
179 // need placement new snippet because no default constructor exist
180 namespace boost
181 {
182  namespace serialization
183  {
184 
185  template<class Archive> void
186  save_construct_data(Archive & ar,
187  const GranOO3::DEM::ContactBond * t,
188  const unsigned int) {
189  const GranOO3::DEM::Element* de1 = &t->get_element1();
190  const GranOO3::DEM::Element* de2 = &t->get_element2();
191  ar << de1;
192  ar << de2;
193  }
194 
195 
196  template<class Archive> void
197  load_construct_data(Archive & ar,
199  const unsigned int) {
200  GranOO3::DEM::Element* de1 = nullptr;
201  GranOO3::DEM::Element* de2 = nullptr;
202  ar >> de1;
203  ar >> de2;
204  ::new(t)GranOO3::DEM::ContactBond(*de1,*de2);
205  }
206 
207  }
208 }
209 
210 
211 namespace GranOO3{
212  GRANOO_CLASS_DECLARE_TPL(DEM::ContactBond);
213 }
214 
215 
216 #endif
217 
218 
BOOST_CLASS_VERSION(GranOO3::DEM::ContactBond, 0) namespace boost
Definition: ContactBond.hpp:176
#define InternAssert(condition)
Definition: Macro.hpp:81
static unsigned long long int compute_ID(const T1 &t1, const T2 &t2)
size_t numID() const
Definition: Base.hpp:201
bool is_same(const Base &) const
Definition: Base.hpp:182
Definition: SetOf.hpp:346
the base class for all bonds between discrete elements.
Definition: Bond.hpp:49
bool is_disabled() const
check if the bond is enable or not
Definition: Bond.hpp:239
this class is able to transform a regular contact into a bond
Definition: ContactBond.hpp:59
void serialize(Archive &, const unsigned int)
complete serializing of the bond in the *.gdd format
Definition: ContactBond.hpp:100
void init()
a method that must be overridden from the Bond class. In this case, it does nothing.
Definition: ContactBond.cpp:74
virtual void compute_load()
a method that must be overridden from the Bond class. In this case, it just calls the Bond::compute_l...
Definition: ContactBond.cpp:82
ContactBond & operator=(const ContactBond &)=delete
const unsigned long long int _numID
a unique indentifier computed from the two element unique IDs.
Definition: ContactBond.hpp:94
static void init_contact_detection_step()
a static function that should be called just before running the Collision::Callback method
Definition: ContactBond.hpp:106
static void apply_contact_load(T1 &t1, T2 &t2, const Geom::Vector &force, const Geom::Vector &torque, const Geom::Point &contact, const double surface=0.)
a static function that should be called by the Collision::Callback method
Definition: ContactBond.hpp:139
static void manage_contact(T1 &t1, T2 &t2)
a static function that should be called by the Collision::Callback method
Definition: ContactBond.hpp:118
static std::map< unsigned long long int, ContactBond * > _all_map
a static private variable able to store all the contact bond with a unique ID
Definition: ContactBond.hpp:69
virtual void update()
a method that must be overridden from the Bond class. In this case, it does nothing.
Definition: ContactBond.cpp:78
friend class boost::serialization::access
Definition: ContactBond.hpp:90
virtual std::string info() const
Display some useful info in the terminal
Definition: ContactBond.cpp:95
virtual double compute_critical_time_step() const
this method is not implemented, it triggers an assertion if it is called.
Definition: ContactBond.cpp:88
virtual ~ContactBond()
destructor
Definition: ContactBond.cpp:67
ContactBond(const ContactBond &)=delete
a base class that represents an element
Definition: Element.hpp:55
Definition: Point.hpp:62
Definition: Vector.hpp:75
Geom::Vector _torque_on2
the current value of the applied torque on the body 2
Definition: BodyInteraction.hpp:87
void clear_torque()
set the torques to zero
Definition: BodyInteraction.cpp:87
Geom::Vector _torque_on1
the current value of the applied torque on the body 1
Definition: BodyInteraction.hpp:86
pure virtual class for modeling classes able to compute a critical time step
Definition: CriticalTimeStep.hpp:50
void clear_force()
Definition: NodeInteraction.cpp:95
Geom::Vector _force_on2
Definition: NodeInteraction.hpp:84
Geom::Vector _force_on1
Definition: NodeInteraction.hpp:83
Definition: Common.hpp:198
void save_construct_data(Archive &ar, const GranOO3::Core::Pair< type > *t, const unsigned int)
Definition: Pair.hpp:207
void load_construct_data(Archive &ar, GranOO3::Core::Pair< type > *t, const unsigned int)
Definition: Pair.hpp:217
Definition: Pair.hpp:202
const T1
Definition: Exprtk.hpp:16489
T value(details::expression_node< T > *n)
Definition: Exprtk.hpp:15070
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
const T1 const T2
Definition: Exprtk.hpp:16511
static char_cptr version
Definition: Exprtk.hpp:44221