Flow123d  release_2.1.0-84-g6a13a75
finite_element.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 finite_element.hh
15  * @brief Abstract class for description of finite elements.
16  * @author Jan Stebel
17  */
18 
19 #ifndef FINITE_ELEMENT_HH_
20 #define FINITE_ELEMENT_HH_
21 
22 #include <armadillo>
23 #include <map>
24 #include <vector>
25 #include <boost/assign/list_of.hpp>
26 #include "fem/update_flags.hh"
27 
28 
29 
30 template<unsigned int dim, unsigned int spacedim> class FEValuesData;
31 template<unsigned int dim> class Quadrature;
32 
33 
34 
35 
36 
37 /**
38  * @brief Multiplicity of finite element dofs.
39  *
40  * Multiplicities describe groups of dofs whose order changes with
41  * the configuration (e.g. the rotation or orientation) of
42  * the geometrical entity relative to the actual cell.
43  *
44  * In each spatial dimension we accept the following dof multiplicities:
45  *
46  * 0) Point (1 configuration):
47  * - single dofs
48  *
49  * 1) Line (2 possible configurations=orientations):
50  * - single dofs
51  * - pairs
52  *
53  * 2) Triangle (2 orientations and 3 rotations=6 configurations):
54  * - single dofs
55  * - pairs
56  * - triples
57  * - sextuples
58  *
59  * 3) Tetrahedron (1 configuration, since it is always the cell):
60  * - single dofs
61  */
64 };
65 
66 const std::vector<DofMultiplicity> dof_multiplicities = boost::assign::list_of(
68 
69 /**
70  * @brief Structure for storing the precomputed finite element data.
71  */
73 {
74 public:
75  /**
76  * @brief Precomputed values of basis functions at the quadrature points.
77  */
79 
80  /**
81  * @brief Precomputed gradients of basis functions at the quadrature points.
82  */
84 
85 
86  /**
87  * @brief Precomputed values of basis functions at the quadrature points.
88  *
89  * For vectorial finite elements.
90  */
92 
93  /**
94  * @brief Precomputed gradients of basis functions at the quadrature points.
95  *
96  * For vectorial finite elements:
97  */
99 };
100 
101 
102 /**
103  * @brief Abstract class for the description of a general finite element on
104  * a reference simplex in @p dim dimensions.
105  *
106  * Description of dofs:
107  *
108  * The reference cell consists of lower dimensional entities (points,
109  * lines, triangles). Each dof is associated to one of these
110  * entities. This means that if the entity is shared by 2 or more
111  * neighbouring cells in the mesh then this dof is shared by the
112  * finite elements on all of these cells. If a dof is associated
113  * to the cell itself then it is not shared with neighbouring cells.
114  * The ordering of nodes in the entity may not be appropriate for the
115  * finite elements on the neighbouring cells, hence we need to
116  * describe how the order of dofs changes with the relative
117  * configuration of the entity with respect to the actual cell.
118  * For this reason we define the dof multiplicity which allows to
119  * group the dofs as described in \ref DofMultiplicity.
120  *
121  * Support points:
122  *
123  * Sometimes it is convenient to describe the function space using
124  * a basis (called the raw basis) that is different from the set of
125  * shape functions for the finite element (the actual basis). For
126  * this reason we define the support points which play the role of
127  * nodal functionals associated to the particular dofs. To convert
128  * between the two bases one can use the @p node_matrix, which is
129  * constructed by the method compute_node_matrix(). In the case of
130  * non-Lagrangean finite elements the dofs are not associated to
131  * nodal functionals but e.g. to derivatives or averages. For that
132  * reason we distinguish between the unit support points which are
133  * uniquely associated to the dofs and the generalized support
134  * points that are auxiliary for the calculation of the dof
135  * functionals.
136  *
137  *
138  */
139 template<unsigned int dim, unsigned int spacedim>
140 class FiniteElement {
141 public:
142 
143  /**
144  * @brief Constructor.
145  */
146  FiniteElement();
147 
148  /**
149  * @brief Clears all internal structures.
150  */
151  void init();
152 
153  /**
154  * @brief Returns the number of degrees of freedom needed by the finite
155  * element.
156  */
157  const unsigned int n_dofs() const;
158 
159  /**
160  * @brief Returns the number of single dofs/dof pairs/triples/sextuples
161  * that lie on a single geometric entity of the dimension
162  * @p object_dim.
163  *
164  * @param object_dim Dimension of the geometric entity.
165  * @param multiplicity Multiplicity of dofs.
166  */
167  const unsigned int n_object_dofs(unsigned int object_dim,
168  DofMultiplicity multiplicity);
169 
170  /**
171  * @brief Calculates the value of the @p i-th raw basis function at the
172  * point @p p on the reference element.
173  *
174  * @param i Number of the basis function.
175  * @param p Point of evaluation.
176  */
177  virtual double basis_value(const unsigned int i,
178  const arma::vec::fixed<dim> &p) const = 0;
179 
180  /**
181  * @brief Variant of basis_value() for vectorial finite elements.
182  *
183  * Calculates the value @p i-th vector-valued raw basis function
184  * at the point @p p on the reference element.
185  *
186  * @param i Number of the basis function.
187  * @param p Point of evaluation.
188  */
189  virtual arma::vec::fixed<dim> basis_vector(const unsigned int i,
190  const arma::vec::fixed<dim> &p) const = 0;
191 
192  /**
193  * @brief Calculates the gradient of the @p i-th raw basis function at the
194  * point @p p on the reference element.
195  *
196  * The gradient components
197  * are relative to the reference cell coordinate system.
198  *
199  * @param i Number of the basis function.
200  * @param p Point of evaluation.
201  */
202  virtual arma::vec::fixed<dim> basis_grad(const unsigned int i,
203  const arma::vec::fixed<dim> &p) const = 0;
204 
205  /**
206  * @brief Variant of basis_grad() for vectorial finite elements.
207  *
208  * Calculates the gradient of the @p i-th vector-valued raw basis
209  * function at the point @p p on the reference element. The gradient
210  * components are relative to the reference cell coordinate system.
211  *
212  * @param i Number of the basis function.
213  * @param p Point of evaluation.
214  */
215  virtual arma::mat::fixed<dim,dim> basis_grad_vector(const unsigned int i,
216  const arma::vec::fixed<dim> &p) const = 0;
217 
218  /**
219  * @brief Initializes the @p node_matrix for computing the coefficients
220  * of the raw basis functions from values at support points.
221  *
222  * The method is implemented for the case of Langrangean finite
223  * element. In other cases it may be reimplemented.
224  */
225  virtual void compute_node_matrix();
226 
227  /**
228  * @brief Calculates the data on the reference cell.
229  *
230  * @param q Quadrature rule.
231  * @param flags Update flags.
232  */
233  virtual FEInternalData *initialize(const Quadrature<dim> &q, UpdateFlags flags);
234 
235  /**
236  * @brief Decides which additional quantities have to be computed
237  * for each cell.
238  *
239  * @param flags Computed update flags.
240  */
241  virtual UpdateFlags update_each(UpdateFlags flags);
242 
243  /**
244  * @brief Computes the shape function values and gradients on the actual cell
245  * and fills the FEValues structure.
246  *
247  * @param q Quadrature rule.
248  * @param data Precomputed finite element data.
249  * @param fv_data Data to be computed.
250  */
251  virtual void fill_fe_values(const Quadrature<dim> &q,
252  FEInternalData &data,
253  FEValuesData<dim,spacedim> &fv_data);
254 
255  /**
256  * @brief Returns the maximum degree of
257  * space of polynomials contained in the finite element space.
258  *
259  * For possible use in hp methods.
260  */
261  virtual const unsigned int polynomial_order() const {
262  return order;
263  };
264 
265  /**
266  * @brief Indicates whether the finite element function space is scalar
267  * or vectorial.
268  */
269  const bool is_scalar() const {
270  return is_scalar_fe;
271  };
272 
273  /**
274  * @brief Returns either the generalized support points (if they are defined)
275  * or the unit support points.
276  */
277  const std::vector<arma::vec::fixed<dim> > &get_generalized_support_points();
278 
279  /**
280  * @brief Destructor.
281  */
282  virtual ~FiniteElement();
283 
284 protected:
285 
286  /**
287  * @brief Total number of degrees of freedom at one finite element.
288  */
289  unsigned int number_of_dofs;
290 
291  /**
292  * @brief Number of single dofs at one geometrical entity of the given
293  * dimension (point, line, triangle, tetrahedron).
294  */
295  unsigned int number_of_single_dofs[dim + 1];
296 
297  /**
298  * @brief Number of pairs of dofs at one geometrical entity of the given
299  * dimension (applicable to lines and triangles).
300  */
301  unsigned int number_of_pairs[dim + 1];
302 
303  /**
304  * @brief Number of triples of dofs associated to one triangle.
305  */
306  unsigned int number_of_triples[dim + 1];
307 
308  /**
309  * @brief Number of sextuples of dofs associated to one triangle.
310  */
311  unsigned int number_of_sextuples[dim + 1];
312 
313  /**
314  * @brief Polynomial order - to be possibly used in hp methods.
315  */
316  unsigned int order;
317 
318  /**
319  * @brief Indicator of scalar versus vectorial finite element.
320  */
322 
323  /**
324  * @brief Matrix that determines the coefficients of the raw basis
325  * functions from the values at the support points.
326  */
327  arma::mat node_matrix;
328 
329  /**
330  * @brief Support points for Lagrangean finite elements.
331  *
332  * Support points are points in the reference element where
333  * function values determine the dofs. In case of Lagrangean
334  * finite elements the dof values are precisely the function
335  * values at @p unit_support_points.
336  *
337  */
339 
340  /**
341  * @brief Support points for non-Lagrangean finite elements.
342  *
343  * In case of non-Lagrangean finite elements the meaning of the
344  * support points is different, hence we denote the structure
345  * as @p generalized_support_points.
346  */
348 };
349 
350 
351 
352 
353 #endif /* FINITE_ELEMENT_HH_ */
UpdateFlags
Enum type UpdateFlags indicates which quantities are to be recomputed on each finite element cell...
Definition: update_flags.hh:67
std::vector< arma::mat > basis_grads
Precomputed gradients of basis functions at the quadrature points.
std::vector< std::vector< arma::vec > > basis_vectors
Precomputed values of basis functions at the quadrature points.
bool is_scalar_fe
Indicator of scalar versus vectorial finite element.
const std::vector< DofMultiplicity > dof_multiplicities
unsigned int number_of_dofs
Total number of degrees of freedom at one finite element.
Enum type UpdateFlags indicates which quantities are to be recomputed on each finite element cell...
Base class for quadrature rules on simplices in arbitrary dimensions.
Definition: fe_values.hh:31
std::vector< arma::vec::fixed< dim > > generalized_support_points
Support points for non-Lagrangean finite elements.
const bool is_scalar() const
Indicates whether the finite element function space is scalar or vectorial.
std::vector< std::vector< arma::mat > > basis_grad_vectors
Precomputed gradients of basis functions at the quadrature points.
unsigned int order
Polynomial order - to be possibly used in hp methods.
Class FEValuesData holds the arrays of data computed by Mapping and FiniteElement.
Definition: fe_values.hh:46
std::vector< arma::vec > basis_values
Precomputed values of basis functions at the quadrature points.
DofMultiplicity
Multiplicity of finite element dofs.
Structure for storing the precomputed finite element data.
std::vector< arma::vec::fixed< dim > > unit_support_points
Support points for Lagrangean finite elements.
Abstract class for the description of a general finite element on a reference simplex in dim dimensio...
Definition: dofhandler.hh:29
arma::mat node_matrix
Matrix that determines the coefficients of the raw basis functions from the values at the support poi...
virtual const unsigned int polynomial_order() const
Returns the maximum degree of space of polynomials contained in the finite element space...