GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
SupportShapeT.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_SupportShapeT_tpp_
31 #define _libDEM_SupportShapeT_tpp_
32 
33 #include <string>
34 
37 #include "GranOO3/Shape/Box.hpp"
38 #include "GranOO3/Shape/Sphere.hpp"
40 #include "GranOO3/Shape/Cone.hpp"
42 
44 
45 
46 //SupportShapeT: class for constraining spacially a domain
47 
48 namespace GranOO3
49 {
50  namespace DEM
51  {
52 
53  template<typename shape>
54  class SupportShapeT : public SupportShape,
55  public shape,
56  public Core::Register< SupportShapeT<shape> >,
57  public Core::ObjectFactoryInterface<SupportShape, SupportShapeT<shape> >
58  {
59  GRANOO_CLASS_T(DEM::SupportShapeT, shape, SupportShape);
60  GRANOO_OBJECT_FACTORY(SupportShapeT);
61 
62  public:
63  static SupportShapeT<shape>& get(const std::string& ID);
64  static bool exist(const std::string& ID);
65 
66  public:
67  //CONSTRUCTORS & DESTRUCTORS
68  SupportShapeT(const std::string& ID, const Geom::Frame &f, const shape& sh);
69  SupportShapeT(const std::string& ID, const shape& sh);
70  virtual ~SupportShapeT();
71  SupportShapeT();
72 
73  //USEFULL
74  virtual std::string info() const;
75  void read_xml_element(const TiXmlElement* el);
76 
77  //ACCESSORS
78  const Shape::Base& to_base_shape() const;
80  const Shape::Volume& to_volume_shape() const;
82  std::string shape_class_ID() const;
83 
84  //BOUNDARY & LOCAL FRAME
85  void attach_to(Core::SetOf<DiscreteElement> &set, bool update = true, double dist_factor = 1.);
86  void recoverer_boundary();
87  void update();
88 
89  // IO
90  virtual std::ostream& write_ascii(std::ostream& out) const;
91  virtual std::istream& read_ascii(std::istream& in);
92  virtual std::ostream& write_ascii_shape(std::ostream& out) const; // for .agdd compatibility
93  virtual std::istream& read_ascii_shape(std::istream& in); // for .agdd compatibility
94 
95  private:
98 
99  //BOOST SERIALIZATION
101  template<class Archive> void serialize(Archive & ar, const unsigned int );
102 
103  private:
105  };
106 
107 
108  template<typename shape> SupportShapeT<shape>&
109  SupportShapeT<shape>::get(const std::string& id) {
111  for (unsigned int i = 0; i<set.size(); ++i) {
112  if (set[i]->SupportShape::get_ID()==id)
113  return *set[i];
114  }
115  UserAssert(0, "can't find discrete shape " + id);
116  return set(0);
117  }
118 
119  template<typename shape> bool
120  SupportShapeT<shape>::exist(const std::string& id) {
122  for (unsigned int i = 0; i<set.size(); ++i) {
123  if (set[i]->SupportShape::get_ID()==id)
124  return true;
125  }
126  return false;
127  }
128 
129  template<typename shape>
130  SupportShapeT<shape>::SupportShapeT(const std::string& id, const Geom::Frame &f, const shape& s)
131  : SupportShape(id, f),
132  shape(s, SupportShape::local_frame()) {
134  "shape must be a descendant of the Shape::Base<T>");
135  }
136 
137  template<typename shape>
138  SupportShapeT<shape>::SupportShapeT(const std::string& id, const shape& s)
139  : SupportShape(id, s.local_frame()),
140  shape(s, SupportShape::local_frame()) {
142  "shape must be a descendant of the Shape::Base<T>");
143  }
144 
145  template<typename shape>
147  : SupportShape(),
148  shape(SupportShape::local_frame()) {
150  "shape must be a descendant of the Shape::Base<T>");
151  }
152 
153  template<typename shape>
155  }
156 
157  template<typename shape> std::string
159  std::ostringstream os;
160  os << SupportShape::info() << '\n'
161  << shape::info() << '\n';
162  return os.str();
163  }
164 
165  template<typename shape> void
166  SupportShapeT<shape>::read_xml_element(const TiXmlElement* el) {
168  shape::read_xml_element(el);
169  }
170 
171  //ACCESSORS
172  template<class shape> const Shape::Base&
174  return *this;
175  }
176 
177  template<class shape> Shape::Base&
179  return *this;
180  }
181 
182  template<typename shape> const Shape::Volume&
184  return *static_cast<const shape*>(this);
185  }
186 
187  template<typename shape>
190  return *static_cast<shape*>(this);
191  }
192 
193  template<typename shape> std::string
195  return shape::class_ID();
196  }
197 
198  template<typename shape> void
199  SupportShapeT<shape>::attach_to(Core::SetOf<DiscreteElement> &set, bool do_update, double dist_factor) {
200 
201  SupportShape::attach_to(set, do_update);
202  get_boundary().init_setof();
203  get_boundary().new_setof();
204  init_boundary(*this, set);
206  if (do_update)
207  update();
208  }
209 
210  template<typename shape> void
213  get_boundary().init_setof();
214  get_boundary().recover_setof();
216  }
217 
218  template<class shape> std::ostream&
219  SupportShapeT<shape>::write_ascii (std::ostream& out) const {
221  shape::write_ascii(out);
222  return out;
223  }
224 
225  template<class shape> std::istream&
226  SupportShapeT<shape>::read_ascii (std::istream& in) {
228  shape::read_ascii(in);
229  return in;
230  }
231 
232  template<class shape> std::ostream&
233  SupportShapeT<shape>::write_ascii_shape(std::ostream& out) const {
234  shape::write_ascii(out);
235  return out;
236  }
237 
238  template<class shape> std::istream&
240  shape::read_ascii(in);
241  return in;
242  }
243 
244  template<typename shape> template<class Archive> void
245  SupportShapeT<shape>::serialize(Archive & ar, const unsigned int ) {
246  ar & boost::serialization::base_object<shape>(*this);
247  ar & boost::serialization::base_object<SupportShape>(*this);
248  }
249 
250  }
251 }
252 
253 
254 
255 
256 
257 namespace GranOO3
258 {
259  namespace Core
260  {
261 
262  template<class shape>
263  struct Read<DEM::SupportShapeT<shape> >
264  {
265  static Base* new_object(const std::string& classID, std::istream& in) {
267  pt->read_ascii(in);
268  return pt;
269  }
270  };
271 
272  }
273 }
274 
275 
276 
277 namespace GranOO3
278 {
279  GRANOO_CLASS_DECLARE_TPL(DEM::SupportShapeT<Shape::Sphere>);
280  GRANOO_CLASS_DECLARE_TPL(DEM::SupportShapeT<Shape::Box>);
281  GRANOO_CLASS_DECLARE_TPL(DEM::SupportShapeT<Shape::Cylinder>);
282  GRANOO_CLASS_DECLARE_TPL(DEM::SupportShapeT<Shape::Cone>);
283  GRANOO_CLASS_DECLARE_TPL(DEM::SupportShapeT<Shape::Polyhedron>);
284 }
285 
286 
287 #endif
#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 pure virtual class that represents a perfect shape associated with a collection of discrete element
Definition: SupportShape.hpp:54
void update_average_discrete_element_radius()
update the value of the mean radius
Definition: SupportShape.cpp:85
virtual std::ostream & write_ascii(std::ostream &out) const
dump the current state of the support shape in a ascii file (standard *.lgdd format)
Definition: SupportShape.cpp:146
virtual std::istream & read_ascii(std::istream &in)
update the current state of the element from an ascii file format *.lgdd
Definition: SupportShape.cpp:153
virtual void read_xml_element(const TiXmlElement *el)
read an xml element
virtual void attach_to(Core::SetOf< DiscreteElement > &set, bool update=true, double dist_factor=1.)
attach the support shape to a collection of discrete element
Definition: SupportShape.cpp:65
virtual std::string info() const
Display some useful info in the terminal
Definition: SupportShape.hpp:146
virtual void recoverer_boundary()
recover the boundaries of the support shape
Definition: SupportShape.cpp:73
a class that represents a perfect shape associated with a collection of discrete element
Definition: SupportShapeT.hpp:58
std::string shape_class_ID() const
get the class ID of the support shape ("Cylinder", "Cone", etc...)
Definition: SupportShapeT.hpp:194
void recoverer_boundary()
recover the boundaries of the support shape
Definition: SupportShapeT.hpp:211
SupportShapeT()
default constructor, for internal usage only (serialization)
Definition: SupportShapeT.hpp:146
void init_boundary(const shape &, Core::SetOf< DiscreteElement > &)
initialize the boundaries of the support shape
virtual std::istream & read_ascii_shape(std::istream &in)
for internal use only (.agdd compatibility)
Definition: SupportShapeT.hpp:239
void serialize(Archive &ar, const unsigned int)
complete serializing of the element in the *.gdd format
Definition: SupportShapeT.hpp:245
virtual std::ostream & write_ascii(std::ostream &out) const
dump the current state of the support shape in a ascii file (standard *.lgdd format)
Definition: SupportShapeT.hpp:219
SupportShapeT(const SupportShapeT< shape > &)=delete
const Shape::Base & to_base_shape() const
cast the current SupportShape to the corresponding Shape::Base
Definition: SupportShapeT.hpp:173
const Shape::Volume & to_volume_shape() const
cast the current SupportShape to the corresponding Shape::Volume
Definition: SupportShapeT.hpp:183
void read_xml_element(const TiXmlElement *el)
read an xml element
Definition: SupportShapeT.hpp:166
void update()
update the support shape length, position and orientation
virtual std::istream & read_ascii(std::istream &in)
update the current state of the element from an ascii file format *.lgdd
Definition: SupportShapeT.hpp:226
virtual std::ostream & write_ascii_shape(std::ostream &out) const
for internal use only (.agdd compatibility)
Definition: SupportShapeT.hpp:233
static bool exist(const std::string &ID)
check if the support shape with the ID exists
Definition: SupportShapeT.hpp:120
virtual std::string info() const
Display some useful info in the terminal
Definition: SupportShapeT.hpp:158
friend class boost::serialization::access
Definition: SupportShapeT.hpp:100
SupportShapeT & operator=(const SupportShapeT< shape > &)=delete
virtual ~SupportShapeT()
destructor (that does nothing particular)
Definition: SupportShapeT.hpp:154
static SupportShapeT< shape > & get(const std::string &ID)
retrieve a support shape with a given ID
Definition: SupportShapeT.hpp:109
void attach_to(Core::SetOf< DiscreteElement > &set, bool update=true, double dist_factor=1.)
attach the support shape to a collection of discrete element
Definition: SupportShapeT.hpp:199
Definition: Frame.hpp:68
Definition: Base.hpp:97
Definition: Volume.hpp:103
Definition: Common.hpp:198
T value(details::expression_node< T > *n)
Definition: Exprtk.hpp:15070
static Base * new_object(const std::string &classID, std::istream &in)
Definition: SupportShapeT.hpp:265
Definition: SetOfManager.hpp:63