GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
SupportShape.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_SupportShape_tpp_
31 #define _libDEM_SupportShape_tpp_
32 
33 #include <string>
34 
35 #include "GranOO3/Core/SetOf.hpp"
37 
40 #include "GranOO3/Shape/Volume.hpp"
42 
43 
44 namespace GranOO3
45 {
46 
47  extern template class Core::SetOf<DEM::DiscreteElement>;
48 
49  namespace DEM
50  {
51 
52  class SupportShape : public Physic::Ground,
54  {
55 
56  GRANOO_CLASS(DEM::SupportShape, Physic::Ground);
57  GRANOO_CLASS_DEFAULT_COLOR(.2, .8, .4, .2);
58 
59  public:
60  static SupportShape& get(const std::string& ID);
61  static bool exist(const std::string& ID);
62  static SupportShape& glob(const std::string& ID);
63  static SupportShape* new_object(const TiXmlElement* el);
64 
65  public:
66  //CONSTRUCTORS & DESTRUCTORS
67  SupportShape(const std::string& ID, const Geom::Frame &f);
68  virtual ~SupportShape();
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();
76  void update_average_discrete_element_radius();
77  double get_continuous_volume() const;
78  double get_volumic_fraction() const;
79  double set_continuous_density(double density);
80  virtual std::string info() const;
81 
82  virtual const Shape::Volume& to_volume_shape() const = 0;
84  virtual std::string shape_class_ID() const = 0;
85 
86  //DISCRETE SHAPE MANAGEMENT
87  bool is_attach() const;
88  virtual void attach_to(Core::SetOf<DiscreteElement>& set, bool update = true, double dist_factor = 1.);
89  virtual void recoverer_boundary();
90  virtual void update() = 0;
91  double get_average_discrete_element_radius() const;
92  Core::SetOf< DiscreteElement >& get_all_discrete_element();
93  const Core::SetOf< DiscreteElement >& get_all_discrete_element() const;
94  double get_discrete_volume() const;
95 
96  SupportShapeBoundary& get_boundary();
97  const SupportShapeBoundary& get_boundary() const;
98 
99  // IO
100  virtual std::ostream& write_ascii (std::ostream& out) const;
101  virtual std::istream& read_ascii (std::istream& in);
102  virtual std::ostream& write_ascii_shape (std::ostream& out) const = 0; // for .agdd compatibility
103  virtual std::istream& read_ascii_shape (std::istream& in) = 0; // for .agdd compatibility
104 
105  private:
106  SupportShape(const SupportShape &) = delete; //Not allowed
107  SupportShape & operator=(const SupportShape &) = delete; //Not allowed
108 
109  //SERIALIZATION
110  friend class boost::serialization::access;
111  template<class Archive> void save(Archive&, const unsigned int ) const;
112  template<class Archive> void load(Archive&, const unsigned int);
114 
115  protected:
116  SupportShape();
117 
118  private:
119  bool _attached;
123  };
124 
125 
126  inline SupportShape& SupportShape::get(const std::string& id) {
128  for (unsigned int i = 0; i<set.size(); ++i) {
129  if (set[i]->get_ID()==id)
130  return *set[i];
131  }
132  UserAssert(0, "can't find SupportShape named " + id);
133  return *set[0];
134  }
135 
136  inline bool SupportShape::exist(const std::string& id) {
138  for (unsigned int i = 0; i<set.size(); ++i) {
139  if (set[i]->get_ID()==id)
140  return true;
141  }
142  return false;
143  }
144 
145  inline std::string
146  SupportShape::info() const {
147  std::ostringstream os;
148  os << Core::Base::info() << "User Id : " << _ID << '\n';
149  return os.str();
150  }
151 
152  inline SupportShapeBoundary&
153  SupportShape::get_boundary() {
154  AssertMsg(_attached == true, "The support shape must be attached first");
155  return _boundary;
156  }
157 
158  inline const SupportShapeBoundary&
159  SupportShape::get_boundary() const {
160  AssertMsg(_attached == true, "The support shape must be attached first");
161  return _boundary;
162  }
163 
164  template<class Archive>
165  void
166  SupportShape::save(Archive& ar, const unsigned int) const {
167  ar << boost::serialization::base_object<Physic::Ground>(*this);
168  ar << _attached;
169  ar << _average_discrete_element_radius;
170  ar << _all;
171  ar << _boundary;
172  }
173 
174  template<class Archive>
175  void
176  SupportShape::load(Archive& ar, const unsigned int) {
177  ar >> boost::serialization::base_object<Physic::Ground>(*this);
178  ar >> _attached;
179  ar >> _average_discrete_element_radius;
180  ar >> _all;
181  ar >> _boundary;
182  local_frame().update_glMatrix();
183  }
184 
185  }
186 }
187 
188 namespace GranOO3
189 {
190  GRANOO_CLASS_DECLARE_TPL(DEM::SupportShape);
191 }
192 
193 
194 
195 #endif
#define AssertMsg(condition, message)
Definition: Macro.hpp:67
#define UserAssert(condition, message)
Definition: Macro.hpp:54
virtual std::string info() const
Definition: Base.hpp:194
Definition: SetOf.hpp:236
static SetOf< type > & get_global_set()
a class that represents the discrete boundary of SupportShape
Definition: SupportShapeBoundary.hpp:56
a pure virtual class that represents a perfect shape associated with a collection of discrete element
Definition: SupportShape.hpp:54
virtual Shape::Volume & to_volume_shape()=0
cast the current SupportShape to the corresponding Shape::Volume
virtual void update()=0
update the support shape length, position and orientation
SupportShape(const SupportShape &)=delete
Core::SetOf< DiscreteElement > * _all
the whole collection of discrete element associated with the support shape
Definition: SupportShape.hpp:121
virtual std::string shape_class_ID() const =0
get the class ID of the support shape ("Cylinder", "Cone", etc...)
virtual const Shape::Volume & to_volume_shape() const =0
cast the current SupportShape to the corresponding Shape::Volume
static SupportShape * new_object(const TiXmlElement *el)
instantiate a new support shape from the xml input file
bool _attached
a flag to know if the support shape is attached or not
Definition: SupportShape.hpp:119
static SupportShape & glob(const std::string &ID)
similar as get(std::string ID)
SupportShape & operator=(const SupportShape &)=delete
SupportShapeBoundary _boundary
the SupportShapeBoundary associated to the support shape
Definition: SupportShape.hpp:122
virtual void add_glob(const std::string &)=0
util method for reading an xml element
virtual void read_xml_element(const TiXmlElement *el)
read an xml element
virtual std::istream & read_ascii_shape(std::istream &in)=0
for internal use only (.agdd compatibility)
double _average_discrete_element_radius
a variable that contains the average value of the discrete element collection attached to the support...
Definition: SupportShape.hpp:120
virtual std::ostream & write_ascii_shape(std::ostream &out) const =0
for internal use only (.agdd compatibility)
Definition: Frame.hpp:68
Definition: Ground.hpp:61
Definition: Volume.hpp:103
Definition: Common.hpp:198