GranOO 3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Loading...
Searching...
No Matches
ElementT.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_ElementT_TPP
31#define _LibDEM_ElementT_TPP
32
33
34
35#include <boost/serialization/version.hpp>
36#include <boost/serialization/map.hpp>
37
38
40
42#include "GranOO3/Shape/Box.hpp"
47
48
49namespace GranOO3
50{
51 namespace DEM
52 {
53
54 template<class shape>
55 class ElementT : public Element,
56 public shape,
57 public Core::PropClass< ElementT<shape> >,
58 public Core::Register< ElementT<shape> >
59 {
60
61 GRANOO_CLASS_T(DEM::ElementT, shape, Element);
62
63 public:
64 // Constructors and destructor
65 ElementT(const Geom::Point& pos, double radius, double density); //Just for spherical DE
66 ElementT(const Geom::Point& pos, double density);
67 ElementT(const Geom::Point& pos);
68 ElementT();
69
70 virtual ~ElementT();
71
72 GRANOO_ACCESS_REF_CONST(local_frame, Geom::Frame, Node::local_frame());
73 GRANOO_ACCESS_GET (center , Geom::Point , Node::get_center() );
74 GRANOO_ACCESS (quaternion , Geom::Quaternion, Node::quaternion() );
75
76 virtual void draw();
77 virtual void draw_edge();
78 virtual std::string info() const;
79 std::string shape_class_ID() const;
80
81
82 // For avoiding confusion with base classes
83 double get_volume() const;
84 const Geom::Vector& get_position() const;
85
86 // cloning
87 virtual Core::Base& clone();
88 void make_equal_to(const ElementT& el);
89
90 // Shape casting
91 virtual bool is_spherical_element() const;
92 virtual bool is_polyhedral_element() const;
93
94 // IO
95 virtual std::ostream& write_ascii (std::ostream& os) const;
96 virtual std::istream& read_ascii (std::istream& is);
97
98
99 private:
100 ElementT(const ElementT&) = delete;
101 ElementT & operator=(const ElementT &) = delete;
102
103 //BOOST SERIALIZATION
105 template<class Archive> void serialize(Archive&, const unsigned int);
106
107 };
108
109
110 template<class shape>
111 ElementT<shape>::ElementT(const Geom::Point& pos, double density)
112 : Element(*this, pos),
113 shape(Element::local_frame()) {
114 //neighbour_(*this)
116 Body::set_density(density);
117 }
118
119 template<class shape>
121 : Element(*this, pos),
122 shape(Element::local_frame()) {
123 //neighbour_(*this)
124 }
125
126 template<class shape>
128 : ElementT<shape>(Geom::global::center) {
129 }
130
131 template<class shape>
134
135 template<class shape> std::string
137 return shape::class_ID();
138 }
139
140 template<class shape>
142 return shape::get_volume();
143 }
144
145 template<class shape> const Geom::Vector&
147 return Physic::Node::get_position();
148 }
149
150
151 template<class shape>
154 el->make_equal_to(*this);
155 return *el;
156 }
157
158 template<class shape>
160 this->shape::make_equal_to(el);
162 }
163
164 template<class shape> void
166#ifndef SERVER
167 Drawable::apply_color();
168 glPushMatrix();
169 glMultMatrixd(local_frame().get_glMatrix());
170 shape::draw_gl();
171 glPopMatrix();
172#endif
173 }
174
175 template<class shape> void
177#ifndef SERVER
178 Drawable::apply_edge_color();
179 glPushMatrix();
180 glMultMatrixd(local_frame().get_glMatrix());
181 shape::draw_gl_edge();
182 glPopMatrix();
183#endif
184 }
185
186 template<class shape> std::string
188 std::ostringstream os;
189 os << Element::info() << '\n'
190 << Body::info() << '\n'
191 << shape::info();
192 return os.str();
193 }
194
195 template<class shape> std::ostream&
196 ElementT<shape>::write_ascii (std::ostream& out) const {
198 shape::write_ascii(out);
199 return out;
200 }
201
202 template<class shape> std::istream&
203 ElementT<shape>::read_ascii (std::istream& in) {
205 shape::read_ascii(in);
206 set_density(1000.);
207 return in;
208 }
209
210
211 template<class shape> bool
213 return false;
214 }
215
216 template<class shape> bool
218 return false;
219 }
220
221
222 template<class shape> template<class Archive> void
223 ElementT<shape>::serialize(Archive & ar, const unsigned int version) {
224 ar & boost::serialization::base_object<Element>(*this);
225 ar & boost::serialization::base_object<shape>(*this);
226 }
227
228 }
229}
230
231namespace GranOO3
232{
233 namespace Core
234 {
235
236 template<class shape>
237 struct Read<DEM::ElementT<shape> >
238 {
239 static Base* new_object(const std::string& classID, std::istream& in) {
241 pt->read_ascii(in);
242 return pt;
243 }
244
245 };
246
247 }
248}
249
250
251
252namespace GranOO3
253{
254 GRANOO_CLASS_DECLARE_TPL(DEM::ElementT<Shape::Sphere>);
255 GRANOO_CLASS_DECLARE_TPL(DEM::ElementT<Shape::Box>);
256 GRANOO_CLASS_DECLARE_TPL(DEM::ElementT<Shape::Cylinder>);
257 GRANOO_CLASS_DECLARE_TPL(DEM::ElementT<Shape::Cone>);
258 GRANOO_CLASS_DECLARE_TPL(DEM::ElementT<Shape::Polyhedron>);
259
260 extern template class Core::PropClass<DEM::ElementT<Shape::Sphere> >;
261 extern template class Core::PropClass<DEM::ElementT<Shape::Box> >;
263 extern template class Core::PropClass<DEM::ElementT<Shape::Cone> >;
265}
266
267
268#endif
269
Definition Base.hpp:61
bool is() const
Definition Base.hpp:150
Definition PropClass.hpp:47
Definition SetOf.hpp:346
virtual std::ostream & write_ascii(std::ostream &os) const
dump the current state of the element in a ascii file (standard *.lgdd format)
Definition Element.cpp:218
void make_equal_to(const Element &el)
for equalizing two elements
Definition Element.cpp:205
virtual std::string info() const
get some info on a given element
Definition Element.cpp:210
virtual std::istream & read_ascii(std::istream &is)
update the current state of the element from an ascii file format *.lgdd
Definition Element.cpp:224
Element(Shape::Volume &shape, const Geom::Point &point)
constructor
Definition Element.cpp:70
a template class that model an element with a given shape
Definition ElementT.hpp:59
void serialize(Archive &, const unsigned int)
complete serializing of the element in the *.gdd format
Definition ElementT.hpp:223
virtual ~ElementT()
destructor
Definition ElementT.hpp:132
virtual bool is_polyhedral_element() const
util method for knowing if the element is polyhedral or not
Definition ElementT.hpp:217
void make_equal_to(const ElementT &el)
for equalizing two elements
Definition ElementT.hpp:159
double get_volume() const
get the volume the element
Definition ElementT.hpp:141
virtual std::ostream & write_ascii(std::ostream &os) const
dump the current state of the element in a ascii file (standard *.lgdd format)
Definition ElementT.hpp:196
virtual void draw_edge()
Definition ElementT.hpp:176
std::string shape_class_ID() const
get the related shape classID
Definition ElementT.hpp:136
virtual std::istream & read_ascii(std::istream &is)
update the current state of the element from an ascii file format *.lgdd
Definition ElementT.hpp:203
const Geom::Vector & get_position() const
get the current position vector of the element
Definition ElementT.hpp:146
ElementT()
default constructor
Definition ElementT.hpp:127
virtual std::string info() const
get some info on a given element
Definition ElementT.hpp:187
virtual Core::Base & clone()
clone the current ElementT
Definition ElementT.hpp:152
ElementT & operator=(const ElementT &)=delete
ElementT(const ElementT &)=delete
ElementT(const Geom::Point &pos, double radius, double density)
constructor mainly used for spherical element
virtual bool is_spherical_element() const
util method for knowing if the element is spherical or not
Definition ElementT.hpp:212
friend class boost::serialization::access
Definition ElementT.hpp:104
ElementT(const Geom::Point &p, double radius, double density)
Definition ElementT.cpp:68
virtual void draw()
util method for GL drawing the element (used by granoo-viewer)
Definition ElementT.hpp:165
Definition Frame.hpp:68
Definition Point.hpp:62
Definition Quaternion.hpp:54
Definition Vector.hpp:75
void set_density(double density)
set the density value
Definition Body.hpp:177
const Geom::Frame & local_frame() const
Definition Node.hpp:262
void update_bounding_shape()
Definition Volume.cpp:96
This namespace group the entire DEM library.
This namespace group the entire Geom library.
Definition Common.hpp:198
static Base * new_object(const std::string &classID, std::istream &in)
Definition ElementT.hpp:239
Definition SetOfManager.hpp:63