Flow123d  release_2.2.0-26-ge868538
finite_element.cc
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.cc
15  * @brief Abstract class for description of finite elements.
16  * @author Jan Stebel
17  */
18 
19 #include "system/system.hh"
20 #include "quadrature/quadrature.hh"
21 #include "fem/dofhandler.hh"
22 #include "fem/finite_element.hh"
23 #include "fem/fe_values.hh"
24 
25 
26 
27 using namespace std;
28 
29 
30 
31 
32 template<unsigned int dim, unsigned int spacedim>
34 {
35  init();
36 }
37 
38 template<unsigned int dim, unsigned int spacedim>
40 {
41  number_of_dofs = 0;
42  is_scalar_fe = true;
43  for (unsigned int i = 0; i <= dim; i++)
44  {
45  number_of_single_dofs[i] = 0;
46  number_of_pairs[i] = 0;
47  number_of_triples[i] = 0;
48  number_of_sextuples[i] = 0;
49  }
50 }
51 
52 template<unsigned int dim, unsigned int spacedim> inline
53 const unsigned int FiniteElement<dim,spacedim>::n_dofs() const
54 {
55  return number_of_dofs;
56 }
57 
58 template<unsigned int dim, unsigned int spacedim> inline
60  unsigned int object_dim, DofMultiplicity multiplicity)
61 {
62  OLD_ASSERT(object_dim >= 0 && object_dim <= dim,
63  "Object type number is out of range.");
64  switch (multiplicity)
65  {
66  case DOF_SINGLE:
67  return number_of_single_dofs[object_dim];
68  case DOF_PAIR:
69  return number_of_pairs[object_dim];
70  case DOF_TRIPLE:
71  return number_of_triples[object_dim];
72  case DOF_SEXTUPLE:
73  return number_of_sextuples[object_dim];
74  }
75 
76  return 0;
77 }
78 
79 template<unsigned int dim, unsigned int spacedim> inline
81 {
82  OLD_ASSERT_EQUAL(get_generalized_support_points().size(), number_of_dofs);
83 
84  arma::mat M(number_of_dofs, number_of_dofs);
85 
86  for (unsigned int i = 0; i < number_of_dofs; i++)
87  for (unsigned int j = 0; j < number_of_dofs; j++) {
88  M(j, i) = basis_value(j, get_generalized_support_points()[i]);
89 
90  }
91  node_matrix = arma::inv(M);
92 }
93 
94 template<unsigned int dim, unsigned int spacedim>
96 {
97  FEInternalData *data = new FEInternalData;
98 
99  if (flags & update_values)
100  {
101  arma::vec values(number_of_dofs);
102  data->basis_values.resize(q.size());
103  for (unsigned int i=0; i<q.size(); i++)
104  {
105  for (unsigned int j=0; j<number_of_dofs; j++)
106  values[j] = basis_value(j, q.point(i));
107  data->basis_values[i] = node_matrix * values;
108  }
109  }
110 
111  if (flags & update_gradients)
112  {
113  arma::mat grads(number_of_dofs, dim);
114  data->basis_grads.resize(q.size());
115  for (unsigned int i=0; i<q.size(); i++)
116  {
117  for (unsigned int j=0; j<number_of_dofs; j++)
118  grads.row(j) = arma::trans(basis_grad(j, q.point(i)));
119  data->basis_grads[i] = node_matrix * grads;
120  }
121  }
122 
123  return data;
124 }
125 
126 template<unsigned int dim, unsigned int spacedim> inline
128 {
129  UpdateFlags f = flags;
130 
131  if (flags & update_gradients)
133 
134  return f;
135 }
136 
137 template<unsigned int dim, unsigned int spacedim> inline
139  const Quadrature<dim> &q,
140  FEInternalData &data,
142 {
143  // shape values
144  if (fv_data.update_flags & update_values)
145  {
146  for (unsigned int i = 0; i < q.size(); i++)
147  fv_data.shape_values[i] = data.basis_values[i];
148  }
149 
150  // shape gradients
151  if (fv_data.update_flags & update_gradients)
152  {
153  for (unsigned int i = 0; i < q.size(); i++)
154  {
155  fv_data.shape_gradients[i] = data.basis_grads[i] * fv_data.inverse_jacobians[i];
156  }
157  }
158 }
159 
160 template<unsigned int dim, unsigned int spacedim>
162 {
163  if (generalized_support_points.size() > 0)
164  {
165  return generalized_support_points;
166  }
167  else
168  {
169  return unit_support_points;
170  }
171 }
172 
173 
174 template<unsigned int dim, unsigned int spacedim>
176 {}
177 
178 
179 template class FiniteElement<0,3>;
180 template class FiniteElement<1,3>;
181 template class FiniteElement<2,3>;
182 template class FiniteElement<3,3>;
183 
184 
std::vector< arma::vec > shape_values
Shape functions evaluated at the quadrature points.
Definition: fe_values.hh:92
Shape function values.
Definition: update_flags.hh:87
UpdateFlags
Enum type UpdateFlags indicates which quantities are to be recomputed on each finite element cell...
Definition: update_flags.hh:67
Declaration of class which handles the ordering of degrees of freedom (dof) and mappings between loca...
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::fixed< dim, spacedim > > inverse_jacobians
Inverse Jacobians at the quadrature points.
Definition: fe_values.hh:82
UpdateFlags update_flags
Flags that indicate which finite element quantities are to be computed.
Definition: fe_values.hh:121
Class FEValues calculates finite element data on the actual cells such as shape function values...
std::vector< arma::mat > basis_grads
Precomputed gradients of basis functions at the quadrature points.
Base class for quadrature rules on simplices in arbitrary dimensions.
Definition: fe_values.hh:31
virtual UpdateFlags update_each(UpdateFlags flags)
Decides which additional quantities have to be computed for each cell.
#define OLD_ASSERT(...)
Definition: global_defs.h:131
virtual ~FiniteElement()
Destructor.
virtual void compute_node_matrix()
Initializes the node_matrix for computing the coefficients of the raw basis functions from values at ...
std::vector< arma::mat > shape_gradients
Gradients of shape functions evaluated at the quadrature points.
Definition: fe_values.hh:99
Basic definitions of numerical quadrature rules.
Shape function gradients.
Definition: update_flags.hh:95
Class FEValuesData holds the arrays of data computed by Mapping and FiniteElement.
Definition: fe_values.hh:46
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...
const unsigned int size() const
Returns number of quadrature points.
Definition: quadrature.hh:125
std::vector< arma::vec > basis_values
Precomputed values of basis functions at the quadrature points.
DofMultiplicity
Multiplicity of finite element dofs.
const arma::vec::fixed< dim > & point(const unsigned int i) const
Returns the ith quadrature point.
Definition: quadrature.hh:130
FiniteElement()
Constructor.
#define OLD_ASSERT_EQUAL(a, b)
Definition: global_defs.h:133
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.
Abstract class for description of 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:29