GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Tool.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_Tool_tpp_
31 #define _libDEM_Tool_tpp_
32 
33 #include <string>
34 
35 #include "GranOO3/Core/SetOf.hpp"
36 #include "GranOO3/Core/Base.hpp"
37 
39 #include "GranOO3/DEM/Element.hpp"
40 #include "GranOO3/Physic/Body.hpp"
41 #include "GranOO3/Shape/Volume.hpp"
43 
44 
45 namespace GranOO3
46 {
47  namespace DEM
48  {
49 
50  class Tool : public Physic::Body,
51  public Core::Register<Tool>
52  {
53 
54  GRANOO_CLASS(DEM::Tool, Physic::Body);
55  GRANOO_CLASS_DEFAULT_COLOR(.235, .729, .918, 1.);
56 
57  public:
58  static Tool& get(const std::string& ID);
59  static bool exist(const std::string& ID);
60  static Tool& glob(const std::string& ID);
61  static Tool* new_object(const TiXmlElement* el);
62 
63  public:
64  //CONSTRUCTORS & DESTRUCTORS
65  Tool(Shape::Volume& shape, const std::string& ID, const Geom::Point& p, const Geom::Quaternion& q, double mass,
66  const Geom::Tensor& inertia);
67  Tool(Shape::Volume& shape);
68  virtual ~Tool() = 0;
69 
70  //INTERNAL USE (Not documented)
71  virtual void read_xml_element(const TiXmlElement* el);
72  virtual void add_glob(const std::string&) = 0;
73 
74  //USEFULL
75  virtual void draw() = 0;
76  virtual std::string info() const;
77  virtual std::string shape_class_ID() const = 0;
78 
79 
80  //ACCESSORS
81  GRANOO_ACCESS(ID, std::string, _ID);
82 
83  // IO
84  virtual std::ostream& write_ascii(std::ostream& out) const;
85  virtual std::istream& read_ascii(std::istream& in);
86  virtual std::ostream& write_ascii_shape(std::ostream& out) const = 0; // for .agdd compatibility
87  virtual std::istream& read_ascii_shape(std::istream& in) = 0; // for .agdd compatibility
88 
89  private:
90  Tool(const Tool &) = delete; // Not allowed
91  Tool & operator=(const Tool &) = delete; // Not allowed
92 
93  //SERIALIZATION
95  template<class Archive> void save(Archive&, const unsigned int ) const;
96  template<class Archive> void load(Archive&, const unsigned int);
98 
99  protected:
100  Tool();
101 
102  private:
103  std::string _ID;
104  };
105 
106 
107  inline bool
108  Tool::exist(const std::string& id) {
110  for (auto &aTool : toolsSet) {
111  if (aTool->get_ID() == id)
112  return true;
113  }
114 
115  return false;
116  }
117 
118  inline Tool&
119  Tool::get(const std::string& id) {
121  for (unsigned int i = 0; i<set.size(); ++i) {
122  if (set[i]->get_ID()==id)
123  return *set[i];
124  }
125  UserAssert(0, "can't find Tool named " + id);
126  return *set[0];
127  }
128 
129  inline std::string
130  Tool::info() const {
131  std::ostringstream os;
132  os << Body::info() << "User Id : " << _ID << '\n';
133  return os.str();
134  }
135 
136  template<class Archive> void
137  Tool::save(Archive& ar, const unsigned int) const {
138  ar << boost::serialization::base_object<Physic::Body>(*this);
139  ar << _ID;
140  }
141 
142  template<class Archive> void
143  Tool::load(Archive& ar, const unsigned int) {
144  ar >> boost::serialization::base_object<Physic::Body>(*this);
145  ar >> _ID;
146 
150  }
151 
152  }
153 }
154 
155 namespace GranOO3
156 {
157  GRANOO_CLASS_DECLARE_TPL(DEM::Tool);
158 }
159 
160 
161 
162 #endif
#define UserAssert(condition, message)
Definition: Macro.hpp:54
virtual const std::string & get_ID() const
Definition: Base.hpp:144
Definition: SetOf.hpp:346
Definition: SetOf.hpp:236
static SetOf< type > & get_global_set()
const std::string & get_SerializationPrefix()
Definition: SetOfManager.cpp:74
const std::string & get_SerializationSuffix()
Definition: SetOfManager.cpp:89
static SetOfManager & get()
Definition: Singleton.hpp:127
a base class that represents a rigid body with various shape into a discrete element simulation
Definition: Tool.hpp:52
void load(Archive &, const unsigned int)
complete serializing of the element in the *.gdd format
Definition: Tool.hpp:143
void save(Archive &, const unsigned int) const
complete serializing of the element in the *.gdd format
Definition: Tool.hpp:137
static Tool * new_object(const TiXmlElement *el)
instantiate a new tool from the xml input file
Tool & operator=(const Tool &)=delete
Tool(const Tool &)=delete
virtual void read_xml_element(const TiXmlElement *el)
read an xml element
virtual void add_glob(const std::string &)=0
util method for reading an xml element
std::string _ID
the unique ID of the tool
Definition: Tool.hpp:103
static bool exist(const std::string &ID)
check if the tool with the ID exists
Definition: Tool.hpp:108
Tool()
default constructor (for internal use only with seriaization)
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
static Tool & glob(const std::string &ID)
similar as get(const std::string& ID)
friend class boost::serialization::access
Definition: Tool.hpp:94
virtual std::string shape_class_ID() const =0
get the class ID of the tool ("Cylinder", "Cone", etc...)
virtual std::ostream & write_ascii_shape(std::ostream &out) const =0
for internal use only (.agdd compatibility)
virtual std::string info() const
Definition: Tool.hpp:130
virtual void draw()=0
OpenGL draw of the bond
virtual ~Tool()=0
destructor
Definition: Tool.cpp:53
virtual std::istream & read_ascii_shape(std::istream &in)=0
for internal use only (.agdd compatibility)
void update_glMatrix()
Definition: Frame.cpp:94
Definition: Point.hpp:62
Definition: Quaternion.hpp:54
Definition: Tensor.hpp:62
a class that represents a body
Definition: Body.hpp:43
const Geom::Frame & local_frame() const
Definition: Node.hpp:262
Definition: Volume.hpp:103
Definition: Common.hpp:198