GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Surface.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 #ifndef _libFEM_Surface_hpp_
30 #define _libFEM_Surface_hpp_
31 
32 #include <string>
33 #include <utility>
34 #include <vector>
35 
36 #include "GranOO3/Core/Base.hpp"
39 #include "GranOO3/Core/SetOf.hpp"
40 
41 namespace GranOO3 {
42 
43  namespace FEM {
44 
45  class Element;
46 
47  class Surface : public Core::Base, public Core::Register<Surface> {
48 
49  GRANOO_CLASS(FEM::Surface, Core::Base);
50 
51  public:
52  static Surface &get(std::string);
53  static bool exist(std::string);
54  static Surface &glob(const std::string& id);
55 
56  public:
57  //CONSTRUCTORS & DESTRUCTORS
58  Surface(const std::string &id);
59  Surface(const std::string &id, std::vector<std::pair<Element *, unsigned int> > facets);
60  virtual ~Surface();
61 
62  //ACCESSORS
63  GRANOO_ACCESS(ID, std::string, _ID);
64  const Geom::Frame& local_frame() const;
65  const Geom::Quaternion& get_quaternion() const;
66  const Geom::Point& get_center() const;
67 
68  private:
69  Surface(const Surface &); //Not allowed
70  Surface &operator=(const Surface &); //Not allowed
71 
72  //SERIALIZATION
74  template<class Archive> void save(Archive&, const unsigned int ) const;
75  template<class Archive> void load(Archive&, const unsigned int);
77 
78  protected:
79  Surface();
80 
81  private:
82  std::string _ID;
83  std::vector<std::pair<Element *, unsigned int> > _facet;
84  };
85 
86  // -------------------------------------------------------------------------------
87  // -------------------------------------------------------------------------------
88  inline bool Surface::exist(std::string id) {
89 
91  for (auto &Surface : SurfacesSet) {
92 
93  if (Surface->get_ID() == id) return true;
94  }
95 
96  return false;
97  }
98 
99  // -------------------------------------------------------------------------------
100  // -------------------------------------------------------------------------------
101  inline Surface &Surface::get(std::string id) {
102 
104  for (unsigned int i = 0; i<set.size(); ++i) {
105 
106  if (set[i]->get_ID() == id) return *set[i];
107  }
108 
109  UserAssert(0, "can't find Surface named " + id);
110  return *set[0];
111  }
112 
113  // -------------------------------------------------------------------------------
114  // -------------------------------------------------------------------------------
115  template<class Archive>
116  void Surface::save(Archive& ar, const unsigned int) const {
117  ar << boost::serialization::base_object<Core::Base>(*this);
118  ar << _ID;
119  }
120 
121  // -------------------------------------------------------------------------------
122  // -------------------------------------------------------------------------------
123  template<class Archive>
124  inline void Surface::load(Archive& ar, const unsigned int) {
125 
126  ar >> boost::serialization::base_object<Core::Base>(*this);
127  ar >> _ID;
128  }
129  }
130 }
131 
132 namespace GranOO3 {
133 
134  GRANOO_CLASS_DECLARE_TPL(FEM::Surface);
135 }
136 
137 #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: SetOf.hpp:346
Definition: SetOf.hpp:236
static SetOf< type > & get_global_set()
Definition: Surface.hpp:47
void load(Archive &, const unsigned int)
Definition: Surface.hpp:124
Surface & operator=(const Surface &)
std::vector< std::pair< Element *, unsigned int > > _facet
Definition: Surface.hpp:83
static bool exist(std::string)
Definition: Surface.hpp:88
const Geom::Point & get_center() const
Definition: Surface.cpp:75
const Geom::Quaternion & get_quaternion() const
Definition: Surface.cpp:70
virtual ~Surface()
Definition: Surface.cpp:61
void save(Archive &, const unsigned int) const
Definition: Surface.hpp:116
Surface()
Definition: Surface.cpp:55
Surface(const Surface &)
std::string _ID
Definition: Surface.hpp:82
const Geom::Frame & local_frame() const
Definition: Surface.cpp:65
static Surface & glob(const std::string &id)
friend class boost::serialization::access
Definition: Surface.hpp:73
static Surface & get(std::string)
Definition: Surface.hpp:101
Definition: Frame.hpp:68
Definition: Point.hpp:62
Definition: Quaternion.hpp:54
Definition: Common.hpp:198