Flow123d  DF_variant_benchmark_asm-8560e52
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 MeshBase;
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 duplicate_nodes object.
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_PERMANENT(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_->duplicate_nodes()->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_ */
#define ASSERT_PERMANENT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
Definition: asserts.hh:348
MeshBase * mesh_
virtual ~DiscreteSpace()
Destructor.
virtual unsigned int n_elem_dofs(const ElementAccessor< 3 > &cell) const =0
Number of dofs associated to element (not shared by adjacent elements).
unsigned int n_face_dofs(unsigned int face_id)
Number of dofs associated to generalized n-face (node, line, triangle or tetrahedron).
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 duplicate_nodes object.
virtual MixedPtr< FiniteElement > fe() const =0
virtual unsigned int n_edge_dofs(const Edge &edge) const =0
Number of dofs associated to edge.
DiscreteSpace(MeshBase *mesh)
Constructor.
const std::vector< unsigned int > & node_dim() const
unsigned int dim() const
Definition: accessors.hh:188
std::vector< unsigned int > _n_node_dofs
unsigned int n_node_dofs(unsigned int nid) const override
Number of dofs associated to node. nid is the node index in the mesh duplicate_nodes object.
unsigned int n_edge_dofs(const Edge &edge) const override
Number of dofs associated to edge.
EqualOrderDiscreteSpace(MeshBase *mesh, MixedPtr< FiniteElement > fe)
std::vector< unsigned int > _n_elem_dofs
std::vector< unsigned int > _n_edge_dofs
MixedPtr< FiniteElement > fe() const override
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).
Abstract class for the description of a general finite element on a reference simplex in dim dimensio...
Base class for Mesh and BCMesh.
Definition: mesh.h:96
const DuplicateNodes * duplicate_nodes() const
Definition: mesh.h:147
std::shared_ptr< FiniteElement< dim > > FEPtr
Abstract class for description of finite elements.
@ edge
Definition: mixed.hh:25