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