GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Dof.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 _LibPhysic_Dof_H
31 #define _LibPhysic_Dof_H
32 
33 #include <map>
34 #include <string>
35 
36 #include "GranOO3/Core/Macro.hpp"
37 #include "GranOO3/3rdParty/Eigen/Dense"
38 
39 namespace GranOO3
40 {
41 
42  namespace DOF
43  {
44  enum State{FREE=0, FIXED=1, PRESCRIBED=2};
45  enum Mecha{X=0, Y=1, Z=2, RX=3, RY=4, RZ=5};
46  }
47 
48 
49  namespace Physic
50  {
51 
52  template <int NUM>
53  class Dof
54  {
55  public:
56  static const int N = NUM;
57 
58  public:
59  Dof(const double*&);
60 
61  typedef std::array<int , NUM> DofArrayT;
62  typedef std::array<DOF::State, NUM> DofStateArrayT;
63 
64  GRANOO_ACCESS (global_index , int , _global_index ); // get, set for _global_index
65  GRANOO_ACCESS_GET(global_index_dof, DofArrayT , _global_index_for_dof ); // -> global_dof_id()
66  GRANOO_ACCESS_GET(bc_state , DofStateArrayT, _bc_state ); // -> bc()
67 
68  Eigen::Map<Eigen::Matrix<double, NUM, 1>> array() const;
69 
70  int get_global_index_for_dof(unsigned int) const; // -> global_dof_id(unsigned int dof)
71  void set_global_index_for_dof(unsigned int, unsigned int index); // -> set_global_dof_id(dof,value)
72 
73  unsigned int get_bc_state(unsigned int) const; // -> bc(unsigned int dof)
74  void set_bc_state(unsigned int, DOF::State); // -> set_bc(unsigned int dof, unsigned int value)
75  void set_bc_state(DOF::State); // -> set_bc(unsigned int value)
76  void clear_bc(); // -> reset_bc() (in granoo we use clear instead of reset)
77 
78  private:
79  const double*& _ptr; // to point to data
80  int _global_index; // -> _global_id
81  std::array<int, NUM> _global_index_for_dof; // -> _global_dofs_id
82  std::array<DOF::State ,NUM> _bc_state; // -> _bc
83 
84  };
85 
86  template <int NUM>
87  Dof<NUM>::Dof(const double*& p) :
88  _ptr(p),
89  _global_index(-1),
90  _global_index_for_dof(),
91  _bc_state() {
92  std::fill(_global_index_for_dof.begin(), _global_index_for_dof.end(), -1 );
93  std::fill(_bc_state.begin() , _bc_state.end() , DOF::FREE );
94  }
95 
96  template <int NUM> Eigen::Map<Eigen::Matrix<double, NUM, 1>>
97  Dof<NUM>::array() const {
98  return Eigen::Map<Eigen::Matrix<double, NUM, 1>>(_ptr, NUM);
99  }
100 
101  template <int NUM> int
102  Dof<NUM>::get_global_index_for_dof(unsigned int d) const {
103  return _global_index_for_dof[d];
104  }
105 
106  template <int NUM> void
107  Dof<NUM>::set_global_index_for_dof(unsigned int d, unsigned int index) {
108  _global_index_for_dof[d] = index;
109  }
110 
111  template <int NUM> unsigned int
112  Dof<NUM>::get_bc_state(unsigned int d) const {
113  return _bc_state[d];
114  }
115 
116  template <int NUM> void
117  Dof<NUM>::set_bc_state(unsigned int d, DOF::State s) {
118  _bc_state[d] = s;
119  }
120 
121  template <int NUM> void
123  std::fill(_bc_state.begin(), _bc_state.end(), s);
124  }
125 
126  template <int NUM> void
128  std::fill(_bc_state.begin(), _bc_state.end(), DOF::FREE);
129  }
130 
131  }
132 }
133 
134 
135 #endif
136 
Definition: Dof.hpp:54
int get_global_index_for_dof(unsigned int) const
Definition: Dof.hpp:102
std::array< int, NUM > _global_index_for_dof
Definition: Dof.hpp:81
std::array< DOF::State, NUM > DofStateArrayT
Definition: Dof.hpp:62
int _global_index
Definition: Dof.hpp:80
const double *& _ptr
Definition: Dof.hpp:79
void set_bc_state(unsigned int, DOF::State)
Definition: Dof.hpp:117
static const int N
Definition: Dof.hpp:56
unsigned int get_bc_state(unsigned int) const
Definition: Dof.hpp:112
void clear_bc()
Definition: Dof.hpp:127
std::array< int, NUM > DofArrayT
Definition: Dof.hpp:61
void set_global_index_for_dof(unsigned int, unsigned int index)
Definition: Dof.hpp:107
Eigen::Map< Eigen::Matrix< double, NUM, 1 > > array() const
Definition: Dof.hpp:97
std::array< DOF::State,NUM > _bc_state
Definition: Dof.hpp:82
Dof(const double *&)
Definition: Dof.hpp:87
Mecha
Definition: Dof.hpp:45
@ X
Definition: Dof.hpp:45
@ RX
Definition: Dof.hpp:45
@ Y
Definition: Dof.hpp:45
@ RZ
Definition: Dof.hpp:45
@ RY
Definition: Dof.hpp:45
@ Z
Definition: Dof.hpp:45
State
Definition: Dof.hpp:44
@ FIXED
Definition: Dof.hpp:44
@ PRESCRIBED
Definition: Dof.hpp:44
@ FREE
Definition: Dof.hpp:44
Definition: Common.hpp:198