Flow123d  JS_before_hm-1601-gc6ac32d
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  /**
62  * Return Mixed of finite element objects.
63  *
64  * TODO:
65  * The function should be in foem fe(const ElementAccessor<3> &). But we do not in fact depend
66  * on the element accessor now. This is temporary solution, which would work only if its type is
67  * EqualOrderDiscreteSpace. Otherwise, the general way would require a new "element FE handler"
68  * that would manage FEValues for all FE types within a given DiscreteSpace.
69  *
70  */
71  virtual MixedPtr<FiniteElement> fe() const = 0;
72 
73  /// Destructor.
74  virtual ~DiscreteSpace() {};
75 
76 
77 protected:
78 
79  /// Constructor.
81  : mesh_(mesh) {}
82 
84 
85 };
86 
87 
88 
89 /**
90  * Implementation of DiscreteSpace when all elements have the same FiniteElement.
91  */
93 public:
95  : DiscreteSpace(mesh), fe_(fe),
96  _n_elem_dofs(4, 0),
97  _n_edge_dofs(4, 0),
98  _n_node_dofs(4, 0)
99  {
100  _init_n_dofs<0>();
101  _init_n_dofs<1>();
102  _init_n_dofs<2>();
103  _init_n_dofs<3>();
104  }
105 
106  unsigned int n_elem_dofs(const ElementAccessor<3> &cell) const override
107  {return _n_elem_dofs[cell.dim()];}
108 
109  unsigned int n_edge_dofs(const Edge &edge) const override
110  {return _n_edge_dofs[edge.side(0)->dim() + 1];}
111 
112  unsigned int n_node_dofs(unsigned int nid) const override
113  {return _n_node_dofs[mesh_->tree->node_dim()[nid]];}
114 
115  MixedPtr<FiniteElement> fe() const override;
116 
117 
118 private:
119  template<IntDim dim>
120  void _init_n_dofs() {
121  auto fe_ptr = fe_[Dim<dim>{}];
122  for (unsigned int d=0; d < fe_ptr->n_dofs(); d++) {
123  if (fe_ptr->dof(d).dim == 0)
124  _n_elem_dofs[dim]++;
125  if (fe_ptr->dof(d).dim == dim-1 && fe_ptr->dof(d).n_face_idx == 0)
126  _n_edge_dofs[dim]++;
127  if (fe_ptr->dof(d).dim == 0 && fe_ptr->dof(d).n_face_idx == 0)
128  _n_node_dofs[dim]++;
129  }
130  }
131 
136 
137 
138 };
139 
140 
141 
142 
143 
144 
145 
146 #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:261
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:77
#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
virtual MixedPtr< FiniteElement > fe() const =0
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_
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