Manicore
Library to implement schemes on n-dimensionnal manifolds.
dofspace.hpp
Go to the documentation of this file.
1 #ifndef DOFSPACE_HPP_INCLUDED
2 #define DOFSPACE_HPP_INCLUDED
3 
4 #include "mesh.hpp"
5 
10 namespace Manicore {
13 
15 
18  template<size_t dimension>
19  class DOFSpace {
20  public:
22  DOFSpace() {;}
24  DOFSpace(Mesh<dimension> const * mesh ,std::array<size_t,dimension+1> nb_local_dof )
25  : _mesh(mesh), _nb_local_dofs(nb_local_dof) {;}
26 
28  size_t numLocalDofs(size_t d ) const {return _nb_local_dofs[d];}
30  size_t dimensionMesh() const;
32  size_t dimensionCell(size_t d ,
33  size_t i_cell ) const;
35 
36  size_t localOffset(size_t d ,
37  size_t i_cell ) const;
39 
40  size_t localOffset(size_t d_boundary ,
41  size_t d ,
42  size_t i_bd_rel ,
43  size_t i_cell ) const;
45  size_t globalOffset(size_t d ,
46  size_t i_cell ) const;
47 
49 
50  Eigen::VectorXd restrict(size_t d ,
51  size_t i_cell ,
52  const Eigen::VectorXd & vh ) const;
54 
55  Eigen::MatrixXd extendOperator(size_t d_boundary ,
56  size_t d ,
57  size_t i_bd_global ,
58  size_t i_cell ,
59  const Eigen::MatrixXd & op ) const;
60 
61  private:
62  const Mesh<dimension>* _mesh;
63  std::array<size_t,dimension+1> _nb_local_dofs;
64  };
66 
67  // ---------------------------------------------------------------------------------------------------------
68  // Implementation
69  // ---------------------------------------------------------------------------------------------------------
70  template<size_t dimension>
72  {
73  size_t rv = _mesh->n_cells(0)*_nb_local_dofs[0];
74  for (size_t i = 1; i <= dimension; ++i) {
75  rv += _mesh->n_cells(i)*_nb_local_dofs[i];
76  }
77  return rv;
78  }
79 
80  template<size_t dimension>
81  size_t DOFSpace<dimension>::dimensionCell(size_t d, size_t i_cell) const
82  {
83  size_t rv = _nb_local_dofs[d];
84  for (size_t i = 0; i < d; ++i) {
85  rv += _mesh->get_boundary(i,d,i_cell).size()*_nb_local_dofs[i];
86  }
87  return rv;
88  }
89 
90  template<size_t dimension>
91  size_t DOFSpace<dimension>::localOffset(size_t d, size_t i_cell) const
92  {
93  size_t rv = 0;
94  for (size_t i = 0; i < d; ++i) {
95  rv += _mesh->get_boundary(i,d,i_cell).size()*_nb_local_dofs[i];
96  }
97  return rv;
98  }
99 
100  template<size_t dimension>
101  size_t DOFSpace<dimension>::localOffset(size_t d_boundary, size_t d, size_t i_bd_rel, size_t i_cell) const
102  {
103  assert(d_boundary < d || i_bd_rel == 0);
104  size_t rv = i_bd_rel*_nb_local_dofs[d_boundary];
105  for (size_t i = 0; i < d_boundary; ++i) {
106  rv += _mesh->get_boundary(i,d,i_cell).size()*_nb_local_dofs[i];
107  }
108  return rv;
109  }
110 
111  template<size_t dimension>
112  size_t DOFSpace<dimension>::globalOffset(size_t d, size_t i_cell) const
113  {
114  size_t rv = i_cell*_nb_local_dofs[d];
115  for (size_t i = 0; i < d; ++i) {
116  rv += _mesh->n_cells(i)*_nb_local_dofs[i];
117  }
118  return rv;
119  }
120 
121 } // end namespace
122 
123 #endif
124 
125 
Convert between local and global data.
Definition: dofspace.hpp:19
size_t globalOffset(size_t d, size_t i_cell) const
Return the global offset of the unknown attached the i-th cell of dimension d.
Definition: dofspace.hpp:112
size_t numLocalDofs(size_t d) const
Return the number of Degree Of Freedoms on a d-cell.
Definition: dofspace.hpp:28
Eigen::VectorXd restrict(size_t d, size_t i_cell, const Eigen::VectorXd &vh) const
Restrict the vector vh to the i-th cell of dimension d (including its boundary).
Definition: dofspace.cpp:23
size_t localOffset(size_t d, size_t i_cell) const
Return the local offset of the unknown attached the i-th cell of dimension d.
Definition: dofspace.hpp:91
Eigen::MatrixXd extendOperator(size_t d_boundary, size_t d, size_t i_bd_global, size_t i_cell, const Eigen::MatrixXd &op) const
Extend operator op from a cell on the boundary to the i_cell-th cell.
Definition: dofspace.cpp:44
DOFSpace()
Empty space.
Definition: dofspace.hpp:22
size_t dimensionMesh() const
Return the total number of Degree Of Freedoms.
Definition: dofspace.hpp:71
DOFSpace(Mesh< dimension > const *mesh, std::array< size_t, dimension+1 > nb_local_dof)
Definition: dofspace.hpp:24
size_t dimensionCell(size_t d, size_t i_cell) const
Return the number of Degree Of Freedoms of the unknown attached the i-th cell of dimension d (includi...
Definition: dofspace.hpp:81
Main data structure for the mesh.
Definition: mesh.hpp:54
Compute and store the topological and geometrical data of the mesh.
Definition: maxwell.hpp:21