GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
ToolT.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 _LibDEM_ToolT_T
31 #define _LibDEM_ToolT_T
32 
33 #include <boost/serialization/version.hpp>
34 #include <boost/serialization/map.hpp>
35 
37 #include "GranOO3/DEM/Tool.hpp"
38 #include "GranOO3/Shape/Sphere.hpp"
39 #include "GranOO3/Shape/Box.hpp"
41 #include "GranOO3/Shape/Cone.hpp"
43 
44 
45 namespace GranOO3
46 {
47  namespace DEM
48  {
49 
50  template<class shape>
51  class ToolT : public Tool,
52  public shape,
53  public Core::ObjectFactoryInterface<Tool, ToolT<shape> >,
54  public Core::Register<ToolT<shape> >
55  {
56 
57  GRANOO_CLASS_T(DEM::ToolT, shape, Tool);
58  GRANOO_OBJECT_FACTORY(ToolT);
59 
60  public:
61  static ToolT<shape>& get(const std::string& ID);
62  static bool exist(const std::string& ID);
63 
64  public:
65  //CONSTRUCTORS & DESTRUCTORS
66  ToolT(const std::string& ID, const Geom::Point& p, const Geom::Quaternion& q, double mass, const Geom::Tensor& inertia);
67  ToolT();
68  virtual ~ToolT();
69 
70  //USEFULL
71  virtual std::string info() const;
72  void read_xml_element(const TiXmlElement* el);
73  virtual void draw();
74  virtual void draw_edge();
75  std::string shape_class_ID() const;
76 
77 
78  //ACCESSORS
79  const Geom::Frame& local_frame() const;
80 
81  // IO
82  virtual std::ostream& write_ascii (std::ostream& out) const;
83  virtual std::istream& read_ascii (std::istream& in);
84  virtual std::ostream& write_ascii_shape (std::ostream& out) const; // for .agdd compatibility
85  virtual std::istream& read_ascii_shape (std::istream& in); // for .agdd compatibility
86 
87  private:
88  ToolT(const ToolT&) = delete;
89  ToolT & operator=(const ToolT &) = delete;
90 
91  //BOOST SERIALIZATION
93  template<class Archive> void serialize(Archive&, const unsigned int);
94  };
95 
96  template<typename shape> ToolT<shape>&
97  ToolT<shape>::get(const std::string& id) {
98  Core::SetOf< ToolT<shape> >& set = Core::SetOf< ToolT<shape> >::get_global_set();
99  for (unsigned int i = 0; i<set.size(); ++i) {
100  if (set[i]->Tool::get_ID()==id)
101  return *set[i];
102  }
103  UserAssert(0, "can't find discrete shape " + id);
104  return set(0);
105  }
106 
107  template<typename shape> bool
108  ToolT<shape>::exist(const std::string& id) {
109  Core::SetOf< ToolT<shape> >& set = Core::SetOf< ToolT<shape> >::get_global_set();
110  for (unsigned int i = 0; i<set.size(); ++i) {
111  if (set[i]->Tool::get_ID()==id)
112  return true;
113  }
114  return false;
115  }
116 
117  // Constructors
118  template<class shape>
119  ToolT<shape>::ToolT(const std::string& id, const Geom::Point & p, const Geom::Quaternion& q,
120  double mass, const Geom::Tensor& tensor)
121  : Tool(*this, id, p, q, mass, tensor),
122  shape(Tool::local_frame()) {
123  }
124 
125  template<class shape>
127  : ToolT("", Geom::global::center, Geom::global::quaternion, 0., Geom::null::tensor) {
128  }
129 
130  template<class shape>
132  }
133 
134  template<class shape> const Geom::Frame &
136  return Node::local_frame();
137  }
138 
139 
140  template<class shape> std::string
142  std::ostringstream os;
143  os << Tool::info() << '\n'
144  << shape::info();
145  return os.str();
146  }
147 
148  template<class shape> void
149  ToolT<shape>::read_xml_element(const TiXmlElement* el) {
151  shape::read_xml_element(el);
152  }
153 
154  template<class shape> std::string
156  return shape::class_ID();
157  }
158 
159  template<class shape> std::ostream&
160  ToolT<shape>::write_ascii (std::ostream& out) const {
161  Tool::write_ascii(out);
162  shape::write_ascii(out);
163  return out;
164  }
165 
166  template<class shape> std::istream&
167  ToolT<shape>::read_ascii (std::istream& in) {
168  Tool::read_ascii(in);
169  shape::read_ascii(in);
170  return in;
171  }
172 
173  template<class shape> std::ostream&
174  ToolT<shape>::write_ascii_shape (std::ostream& out) const {
175  shape::write_ascii(out);
176  return out;
177  }
178 
179  template<class shape> std::istream&
180  ToolT<shape>::read_ascii_shape (std::istream& in) {
181  shape::read_ascii(in);
182  return in;
183  }
184 
185  template<class shape> template<class Archive> void
186  ToolT<shape>::serialize(Archive & ar, const unsigned int version) {
187  ar & boost::serialization::base_object<Tool>(*this);
188  ar & boost::serialization::base_object<shape>(*this);
189  }
190 
191  template<class shape> void
193 #ifndef SERVER
194  Drawable::apply_color();
195  glPushMatrix();
196  glMultMatrixd(local_frame().get_glMatrix());
197  shape::draw_gl();
198  glPopMatrix();
199 #endif
200  }
201 
202  template<class shape> void
204 #ifndef SERVER
205  Drawable::apply_color();
206  glPushMatrix();
207  glMultMatrixd(local_frame().get_glMatrix());
208  shape::draw_gl_edge();
209  glPopMatrix();
210 #endif
211  }
212 
213  }
214 }
215 
216 
217 
218 
219 namespace GranOO3
220 {
221  namespace Core
222  {
223 
224  template<class shape>
225  struct Read<DEM::ToolT<shape> >
226  {
227  static Base* new_object(const std::string& classID, std::istream& in) {
229  pt->read_ascii(in);
230  return pt;
231  }
232  };
233 
234  }
235 }
236 
237 
238 namespace GranOO3
239 {
240  GRANOO_CLASS_DECLARE_TPL(DEM::ToolT<Shape::Sphere>);
241  GRANOO_CLASS_DECLARE_TPL(DEM::ToolT<Shape::Box>);
242  GRANOO_CLASS_DECLARE_TPL(DEM::ToolT<Shape::Cylinder>);
243  GRANOO_CLASS_DECLARE_TPL(DEM::ToolT<Shape::Cone>);
244  GRANOO_CLASS_DECLARE_TPL(DEM::ToolT<Shape::Polyhedron>);
245 }
246 
247 
248 #endif
249 
#define UserAssert(condition, message)
Definition: Macro.hpp:54
Definition: Base.hpp:61
virtual const std::string & get_ID() const
Definition: Base.hpp:144
Definition: ObjectFactory.hpp:235
Definition: SetOf.hpp:346
Definition: SetOf.hpp:236
a base class that represents a rigid body with various shape into a discrete element simulation
Definition: Tool.hpp:52
virtual void read_xml_element(const TiXmlElement *el)
read an xml element
virtual std::ostream & write_ascii(std::ostream &out) const
dump the current state of the tool in a ascii file (standard *.lgdd format)
Definition: Tool.cpp:57
virtual std::istream & read_ascii(std::istream &in)
update the current state of the element from an ascii file format *.lgdd
Definition: Tool.cpp:63
virtual std::string info() const
Definition: Tool.hpp:130
a class that represents a rigid body with various shape into a discrete element simulation
Definition: ToolT.hpp:55
ToolT(const ToolT &)=delete
virtual std::istream & read_ascii_shape(std::istream &in)
for internal use only (.agdd compatibility)
Definition: ToolT.hpp:180
ToolT & operator=(const ToolT &)=delete
virtual ~ToolT()
destructor
Definition: ToolT.hpp:131
std::string shape_class_ID() const
get the class ID of the tool ("Cylinder", "Cone", etc...)
Definition: ToolT.hpp:155
ToolT()
default constructor, for internal usage only (serialization)
Definition: ToolT.hpp:126
virtual void draw()
OpenGL draw of the bond
Definition: ToolT.hpp:192
static bool exist(const std::string &ID)
check if the tool with the ID exists
Definition: ToolT.hpp:108
void read_xml_element(const TiXmlElement *el)
read an xml element
Definition: ToolT.hpp:149
virtual std::string info() const
Display some useful info in the terminal
Definition: ToolT.hpp:141
virtual void draw_edge()
Definition: ToolT.hpp:203
virtual std::ostream & write_ascii(std::ostream &out) const
dump the current state of the tool in a ascii file (standard *.lgdd format)
Definition: ToolT.hpp:160
virtual std::ostream & write_ascii_shape(std::ostream &out) const
for internal use only (.agdd compatibility)
Definition: ToolT.hpp:174
const Geom::Frame & local_frame() const
get the local frame of the tool
Definition: ToolT.hpp:135
void serialize(Archive &, const unsigned int)
complete serializing of the element in the *.gdd format
Definition: ToolT.hpp:186
friend class boost::serialization::access
Definition: ToolT.hpp:92
virtual std::istream & read_ascii(std::istream &in)
update the current state of the element from an ascii file format *.lgdd
Definition: ToolT.hpp:167
Definition: Frame.hpp:68
Definition: Point.hpp:62
Definition: Quaternion.hpp:54
Definition: Tensor.hpp:62
Definition: Common.hpp:198
static char_cptr version
Definition: Exprtk.hpp:44221
static Base * new_object(const std::string &classID, std::istream &in)
Definition: ToolT.hpp:227
Definition: SetOfManager.hpp:63