GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Manager.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 
31 #ifndef _LibCollision_Manager_H
32 #define _LibCollision_Manager_H
33 
34 #include <array>
35 
38 #include "GranOO3/Core/Doc.hpp"
39 
40 #include "GranOO3/Physic/Body.hpp"
43 
44 namespace GranOO3
45 {
46  namespace Collision
47  {
48 
49  template<class T1, class T2> class BroadPhase;
50  template<class T1, class T2> class UpdateStrategy;
51  template<class T1, class T2> class NarrowPhase;
52  template<class T1, class T2> class CallBack;
53 
54 
55  // The main class that manages contact that manage contacts between T1 class and T2 class..
56  template<class T1, class T2>
57  class Manager
58  {
59  public:
60  static std::string class_ID() {return "Manager<" + T1::class_ID() + ", " + T2::class_ID() + ">";}
61 
62  private:
63  static int _current_iteration_step; // useful for detecting if this is the first time that Manager<T1,T2> is launched
64 
65  public:
68 
69  void init();
70  void parse_xml();
71  void run();
72 
75 
77 
82 
83  GRANOO_ACCESS_GET_COPY(broad_phase, Broad, _broad_phase);
84  GRANOO_ACCESS_SET_COPY(broad_phase, Broad, _broad_phase);
85 
86  GRANOO_ACCESS_GET_COPY(update_strategy, Update, _update_strategy);
87  GRANOO_ACCESS_SET_COPY(update_strategy, Update, _update_strategy);
88 
89  GRANOO_ACCESS_GET_COPY(narrow_phase, Narrow, _narrow_phase);
90  GRANOO_ACCESS_SET_COPY(narrow_phase, Narrow, _narrow_phase);
91 
92  GRANOO_ACCESS_GET_COPY(callback, Call, _callback);
93  GRANOO_ACCESS_SET_COPY(callback, Call, _callback);
94 
95  GRANOO_ACCESS(persistent_contact, bool, _persistent_contact);
96 
97  GRANOO_ACCESS(data, Data, _info);
98 
99 
100  public:
106  std::vector<std::pair<T1*, T2*>> _record;
110  };
111 
112 
113  // The pure virtual BroadPhase class model a BroadPhase algorithm
114  // to detect contact. The BroadPhase approach allows to pre-select
115  // possible contact pairs.
116  template<class T1, class T2>
118  {
119  public:
120  static std::string class_ID() {return "BroadPhase<" + T1::class_ID() + ", " + T2::class_ID() + ">";}
121 
122  protected:
124  virtual ~BroadPhase();
125 
126  public:
127  virtual void parse_xml();
128  virtual void init();
129  virtual void detect_contact(std::function<void(T1&,T2&)>&) = 0;
130 
132  GRANOO_ACCESS_GET_COPY(manager, Man*, manager_);
133  GRANOO_ACCESS_SET_COPY(manager, Man*, manager_);
134 
135  private:
136  BroadPhase(const BroadPhase&) = delete;
137  BroadPhase& operator=(const BroadPhase&) = delete;
138 
139  private:
141  };
142 
143 
144  // The pure virtual UpdateStrategy class model a strategy to updateStrategy
145  // the update of the BroadPhase method. This is generally non required.
146  template<class T1, class T2>
148  {
149  public:
150  static std::string class_ID() {return "UpdateStrategy<" + T1::class_ID() + ", " + T2::class_ID() + ">";}
151 
152  protected:
154  virtual ~UpdateStrategy();
155 
156  public:
157  virtual void parse_xml();
158  virtual void init();
159  virtual bool trigger_update() = 0;
160 
162  GRANOO_ACCESS_GET_COPY(manager, Man*, manager_);
163  GRANOO_ACCESS_SET_COPY(manager, Man*, manager_);
164 
165  private:
166  UpdateStrategy(const UpdateStrategy&) = delete;
168 
169  private:
171  };
172 
173 
174 
175 
176  // The pure virtual NarrowPhase class model a NarrowPhase algorithm
177  // to exactly detect contact between pairs and compute contact information
178  // such as normal, penetration depth and contact info.
179  template<class T1, class T2>
181  {
182 
183  public:
184  static std::string class_ID() {return "NarrowPhase<" + T1::class_ID() + ", " + T2::class_ID() + ">";}
185 
186  protected:
187  //CONSTRUCTORS & DESTRUCTORS
189  virtual ~NarrowPhase();
190 
191  public:
193  GRANOO_ACCESS_GET_COPY(manager, Man*, manager_);
194  GRANOO_ACCESS_SET_COPY(manager, Man*, manager_);
195 
196  public:
197  //USEFULL
198  virtual void parse_xml();
199  virtual void init();
200  virtual bool is_collide(T1&, T2&, Data&) = 0;
201 
202  private:
203  NarrowPhase(const NarrowPhase&) = delete;
204  NarrowPhase& operator=(const NarrowPhase&) = delete;
205 
206  private:
208 
209  protected:
211  };
212 
213 
214 
215  // What to do when a contact pair is detected ?
216  // Use the CallBack class to model the behavior of a contact pair .
217  // Usually, a contact response is computed in therms of force and torque.
218  template<class T1, class T2>
220  {
221 
222  public:
223  static std::string class_ID() {return "CallBack<" + T1::class_ID() + ", " + T2::class_ID()+ ">";}
224 
225  protected:
227  virtual ~CallBack();
228 
229  public:
230  //USEFULL
231  virtual void parse_xml();
232  virtual void init();
233  virtual void manage_collision(T1&, T2&, const Data&) = 0;
234  virtual double compute_critical_time_step() const = 0;
235 
237  GRANOO_ACCESS_GET_COPY(manager, Man*, manager_);
238  GRANOO_ACCESS_SET_COPY(manager, Man*, manager_);
239 
240  private:
241  CallBack(const CallBack&) = delete;
242  CallBack& operator=(const CallBack&) = delete;
243 
244  private:
246  };
247 
248 
249 
250  }
251 }
252 
253 
254 #include "GranOO3/Collision/Manager.tpp"
255 #include "GranOO3/Collision/BroadPhase.tpp"
256 #include "GranOO3/Collision/UpdateStrategy.tpp"
257 #include "GranOO3/Collision/NarrowPhase.tpp"
258 #include "GranOO3/Collision/CallBack.tpp"
259 
260 
261 #endif
Definition: Manager.hpp:118
BroadPhase & operator=(const BroadPhase &)=delete
BroadPhase(const BroadPhase &)=delete
static std::string class_ID()
Definition: Manager.hpp:120
virtual void detect_contact(std::function< void(T1 &, T2 &)> &)=0
Manager< T1, T2 > * manager_
Definition: Manager.hpp:140
Manager< T1, T2 > Man
Definition: Manager.hpp:131
Definition: Manager.hpp:220
virtual double compute_critical_time_step() const =0
a pure virtual method able to return the critical time step value
static std::string class_ID()
Definition: Manager.hpp:223
virtual void manage_collision(T1 &, T2 &, const Data &)=0
Manager< T1, T2 > * manager_
Definition: Manager.hpp:245
CallBack(const CallBack &)=delete
CallBack & operator=(const CallBack &)=delete
Manager< T1, T2 > Man
Definition: Manager.hpp:236
Definition: Manager.hpp:58
BroadPhase< T1, T2 > * Broad
Definition: Manager.hpp:78
static std::string class_ID()
Definition: Manager.hpp:60
bool _persistent_contact
Definition: Manager.hpp:108
Data _info
Definition: Manager.hpp:105
bool has_persistent_contact_option() const
bool has_build_contact_bond_option() const
CallBack< T1, T2 > * _callback
Definition: Manager.hpp:104
void broad_phase_callback(T1 &, T2 &)
bool _exclude_interaction
Definition: Manager.hpp:107
CallBack< T1, T2 > * Call
Definition: Manager.hpp:81
BroadPhase< T1, T2 > * _broad_phase
Definition: Manager.hpp:101
UpdateStrategy< T1, T2 > * _update_strategy
Definition: Manager.hpp:102
NarrowPhase< T1, T2 > * Narrow
Definition: Manager.hpp:80
std::vector< std::pair< T1 *, T2 * > > _record
Definition: Manager.hpp:106
bool _build_contact_bond
Definition: Manager.hpp:109
NarrowPhase< T1, T2 > * _narrow_phase
Definition: Manager.hpp:103
static int _current_iteration_step
Definition: Manager.hpp:63
UpdateStrategy< T1, T2 > * Update
Definition: Manager.hpp:79
Definition: Manager.hpp:181
NarrowPhase & operator=(const NarrowPhase &)=delete
virtual bool is_collide(T1 &, T2 &, Data &)=0
static std::string class_ID()
Definition: Manager.hpp:184
double maxPenetrationWithsurface_
Definition: Manager.hpp:210
Manager< T1, T2 > * manager_
Definition: Manager.hpp:207
Manager< T1, T2 > Man
Definition: Manager.hpp:192
NarrowPhase(const NarrowPhase &)=delete
Definition: Manager.hpp:148
UpdateStrategy(const UpdateStrategy &)=delete
Manager< T1, T2 > Man
Definition: Manager.hpp:161
Manager< T1, T2 > * manager_
Definition: Manager.hpp:170
static std::string class_ID()
Definition: Manager.hpp:150
UpdateStrategy & operator=(const UpdateStrategy &)=delete
pure virtual class for modeling classes able to compute a critical time step
Definition: CriticalTimeStep.hpp:50
Definition: Common.hpp:198
const T1
Definition: Exprtk.hpp:16489
const T1 const T2
Definition: Exprtk.hpp:16511
static std::string data()
Definition: Exprtk.hpp:44228
Definition: Data.hpp:43