Flow123d  JS_before_hm-896-g486f41f
discrete_space.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file discrete_space.hh
15  * @brief Declaration of class which provides the finite element for every mesh cell.
16  * @author Jan Stebel
17  */
18 
19 #ifndef DISCRETE_SPACE_HH_
20 #define DISCRETE_SPACE_HH_
21 
22 #include "mesh/accessors.hh"
23 #include "tools/mixed.hh"
24 #include "mesh/duplicate_nodes.h"
25 #include "fem/finite_element.hh"
26 template<unsigned int dim> class FiniteElement;
27 template<IntDim dim>
28 using FEPtr = std::shared_ptr<FiniteElement<dim>>;
29 class Mesh;
30 
31 
32 /**
33  * Abstract class for definition of finite element functions on the mesh.
34  * This should include
35  * - simple FE spaces using the same finite element on
36  * all mesh elements with the same dimension,
37  * - p-refined spaces using variable FE order,
38  * - XFEM with arbitrary shape functions on every element.
39  *
40  */
42 public:
43 
44  /// Number of dofs associated to node. @p nid is the node index in the mesh tree.
45  virtual unsigned int n_node_dofs(unsigned int nid) const = 0;
46 
47  /// Number of dofs associated to edge.
48  virtual unsigned int n_edge_dofs(const Edge &edge) const = 0;
49 
50  /// Number of dofs associated to element (not shared by adjacent elements).
51  virtual unsigned int n_elem_dofs(const ElementAccessor<3> &cell) const = 0;
52 
53  /// Number of dofs associated to generalized n-face (node, line, triangle or tetrahedron).
54  template<unsigned int dim>
55  unsigned int n_face_dofs(unsigned int face_id)
56  {
57  ASSERT(false).error("Not implemented.");
58  return 0;
59  }
60 
61  /// Return Mixed of finite element objects.
62  virtual MixedPtr<FiniteElement> fe(const ElementAccessor<3> &) const = 0;
63 
64  /// Destructor.
65  virtual ~DiscreteSpace() {};
66 
67 
68 protected:
69 
70  /// Constructor.
72  : mesh_(mesh) {}
73 
75 
76 };
77 
78 
79 
80 /**
81  * Implementation of DiscreteSpace when all elements have the same FiniteElement.
82  */
84 public:
86  : DiscreteSpace(mesh), fe_(fe),
87  _n_elem_dofs(4, 0),
88  _n_edge_dofs(4, 0),
89  _n_node_dofs(4, 0)
90  {
91  _init_n_dofs<0>();
92  _init_n_dofs<1>();
93  _init_n_dofs<2>();
94  _init_n_dofs<3>();
95  }
96 
97  unsigned int n_elem_dofs(const ElementAccessor<3> &cell) const override
98  {return _n_elem_dofs[cell.dim()];}
99 
100  unsigned int n_edge_dofs(const Edge &edge) const override
101  {return _n_edge_dofs[edge.side(0)->dim() + 1];}
102 
103  unsigned int n_node_dofs(unsigned int nid) const override
104  {return _n_node_dofs[mesh_->tree->node_dim()[nid]];}
105 
106  MixedPtr<FiniteElement> fe(const ElementAccessor<3> &cell) const override;
107 
108 
109 private:
110  template<IntDim dim>
111  void _init_n_dofs() {
112  auto fe_ptr = fe_[Dim<dim>{}];
113  for (unsigned int d=0; d < fe_ptr->n_dofs(); d++) {
114  if (fe_ptr->dof(d).dim == 0)
115  _n_elem_dofs[dim]++;
116  if (fe_ptr->dof(d).dim == dim-1 && fe_ptr->dof(d).n_face_idx == 0)
117  _n_edge_dofs[dim]++;
118  if (fe_ptr->dof(d).dim == 0 && fe_ptr->dof(d).n_face_idx == 0)
119  _n_node_dofs[dim]++;
120  }
121  }
122 
127 
128 
129 };
130 
131 
132 
133 
134 
135 
136 
137 #endif /* DISCRETE_SPACE_HH_ */
unsigned int n_face_dofs(unsigned int face_id)
Number of dofs associated to generalized n-face (node, line, triangle or tetrahedron).
Definition: mixed.hh:25
const std::vector< unsigned int > & node_dim() const
DuplicateNodes * tree
Definition: mesh.h:255
virtual unsigned int n_node_dofs(unsigned int nid) const =0
Number of dofs associated to node. nid is the node index in the mesh tree.
Definition: mesh.h:78
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
Definition: asserts.hh:347
EqualOrderDiscreteSpace(Mesh *mesh, MixedPtr< FiniteElement > fe)
unsigned int n_elem_dofs(const ElementAccessor< 3 > &cell) const override
Number of dofs associated to element (not shared by adjacent elements).
std::vector< unsigned int > _n_edge_dofs
unsigned int dim() const
Returns dimension of the side, that is dimension of the element minus one.
virtual ~DiscreteSpace()
Destructor.
DiscreteSpace(Mesh *mesh)
Constructor.
unsigned int n_node_dofs(unsigned int nid) const override
Number of dofs associated to node. nid is the node index in the mesh tree.
std::shared_ptr< FiniteElement< dim >> FEPtr
unsigned int n_edge_dofs(const Edge &edge) const override
Number of dofs associated to edge.
std::vector< unsigned int > _n_elem_dofs
MixedPtr< FiniteElement > fe_
virtual MixedPtr< FiniteElement > fe(const ElementAccessor< 3 > &) const =0
Return Mixed of finite element objects.
Abstract class for description of finite elements.
Abstract class for the description of a general finite element on a reference simplex in dim dimensio...
unsigned int dim() const
Definition: accessors.hh:157
virtual unsigned int n_elem_dofs(const ElementAccessor< 3 > &cell) const =0
Number of dofs associated to element (not shared by adjacent elements).
virtual unsigned int n_edge_dofs(const Edge &edge) const =0
Number of dofs associated to edge.
SideIter side(const unsigned int i) const
Gets side iterator of the i -th side.
std::vector< unsigned int > _n_node_dofs