Flow123d  release_2.2.0-914-gf1a3a4f
fe_values.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 fe_values.cc
15  * @brief Class FEValues calculates finite element data on the actual
16  * cells such as shape function values, gradients, Jacobian of
17  * the mapping from the reference cell etc.
18  * @author Jan Stebel
19  */
20 
21 #include "fem/mapping.hh"
22 #include "quadrature/quadrature.hh"
23 #include "fem/finite_element.hh"
24 #include "fem/fe_values.hh"
25 #include "fem/fe_system.hh"
26 
27 
28 
29 using namespace arma;
30 using namespace std;
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 template<unsigned int dim, unsigned int spacedim>
42 void FEValuesData<dim,spacedim>::allocate(unsigned int size, UpdateFlags flags, unsigned int n_comp)
43 {
44  update_flags = flags;
45 
46  // resize the arrays of computed quantities
47  if (update_flags & update_jacobians)
48  jacobians.resize(size);
49 
50  if (update_flags & update_volume_elements)
51  determinants.resize(size);
52 
53  if ((update_flags & update_JxW_values) |
54  (update_flags & update_side_JxW_values))
55  JxW_values.resize(size);
56 
57  if (update_flags & update_inverse_jacobians)
58  inverse_jacobians.resize(size);
59 
60  if (update_flags & update_values)
61  {
62  shape_values.resize(size, vector<double>(n_comp));
63  }
64 
65  if (update_flags & update_gradients)
66  {
67  shape_gradients.resize(size, vector<arma::vec::fixed<spacedim> >(n_comp));
68  }
69 
70  if (update_flags & update_quadrature_points)
71  points.resize(size);
72 
73  if (update_flags & update_normal_vectors)
74  normal_vectors.resize(size);
75 }
76 
77 
78 template<unsigned int dim, unsigned int spacedim>
80 {
81  scalars.clear();
82  vectors.clear();
83  switch (fv.get_fe()->type_) {
84  case FEType::FEScalar:
85  scalars.push_back(FEValuesViews::Scalar<dim,spacedim>(fv, 0));
86  break;
89  vectors.push_back(FEValuesViews::Vector<dim,spacedim>(fv, 0));
90  break;
91  case FEType::FETensor:
92  OLD_ASSERT(false, "Not Implemented.");
93  break;
95  FESystem<dim,spacedim> *fe = dynamic_cast<FESystem<dim,spacedim>*>(fv.get_fe());
96  OLD_ASSERT(fe != nullptr, "Mixed system must be represented by FESystem.");
99  for (auto si : sc)
100  scalars.push_back(FEValuesViews::Scalar<dim,spacedim>(fv,si));
101  for (auto vi : vc)
102  vectors.push_back(FEValuesViews::Vector<dim,spacedim>(fv,vi));
103  break;
104  }
105 }
106 
107 
108 
109 template<unsigned int dim,unsigned int spacedim>
111 : mapping(NULL), quadrature(NULL), fe(NULL), mapping_data(NULL), fe_data(NULL)
112 {
113 }
114 
115 
116 
117 template<unsigned int dim,unsigned int spacedim>
119  if (mapping_data) delete mapping_data;
120  if (fe_data) delete fe_data;
121 }
122 
123 
124 
125 template<unsigned int dim, unsigned int spacedim>
127  Quadrature<dim> & _quadrature,
129  UpdateFlags _flags)
130 
131 {
132  mapping = &_mapping;
133  quadrature = &_quadrature;
134  fe = &_fe;
135 
136  switch (fe->type_) {
137  case FEScalar:
138  n_components_ = 1;
139  break;
141  case FEVectorPiola:
142  n_components_ = spacedim;
143  break;
144  case FETensor:
145  n_components_ = spacedim*spacedim;
146  break;
147  case FEMixedSystem:
148  n_components_ = fe->n_components();
149  break;
150  }
151  // add flags required by the finite element or mapping
152  data.allocate(quadrature->size(), update_each(_flags), fe->n_dofs()*n_components_);
153 
154  views_cache_.resize(*this, fe->n_components());
155 }
156 
157 
158 
159 template<unsigned int dim, unsigned int spacedim>
161 {
162  UpdateFlags f = flags | fe->update_each(flags);
163  f |= mapping->update_each(f);
164  return f;
165 }
166 
167 
168 template<unsigned int dim, unsigned int spacedim>
169 double FEValuesBase<dim,spacedim>::shape_value(const unsigned int function_no, const unsigned int point_no)
170 {
171  ASSERT_LT_DBG(function_no, fe->n_dofs());
172  ASSERT_LT_DBG(point_no, quadrature->size());
173  return data.shape_values[point_no][function_no];
174 }
175 
176 
177 template<unsigned int dim, unsigned int spacedim>
178 arma::vec::fixed<spacedim> FEValuesBase<dim,spacedim>::shape_grad(const unsigned int function_no, const unsigned int point_no)
179 {
180  ASSERT_LT_DBG(function_no, fe->n_dofs());
181  ASSERT_LT_DBG(point_no, quadrature->size());
182  return data.shape_gradients[point_no][function_no];
183 }
184 
185 
186 template<unsigned int dim, unsigned int spacedim>
187 double FEValuesBase<dim,spacedim>::shape_value_component(const unsigned int function_no,
188  const unsigned int point_no,
189  const unsigned int comp) const
190 {
191  ASSERT_LT_DBG(function_no, fe->n_dofs());
192  ASSERT_LT_DBG(point_no, quadrature->size());
194  return data.shape_values[point_no][function_no*n_components_+comp];
195 }
196 
197 
198 template<unsigned int dim, unsigned int spacedim>
199 arma::vec::fixed<spacedim> FEValuesBase<dim,spacedim>::shape_grad_component(const unsigned int function_no,
200  const unsigned int point_no,
201  const unsigned int comp) const
202 {
203  ASSERT_LT_DBG(function_no, fe->n_dofs());
204  ASSERT_LT_DBG(point_no, quadrature->size());
206  return data.shape_gradients[point_no][function_no*n_components_+comp];
207 }
208 
209 
210 
211 
212 
213 
214 
215 
216 template<unsigned int dim, unsigned int spacedim>
218  Quadrature<dim> &_quadrature,
220  UpdateFlags _flags)
221 :FEValuesBase<dim, spacedim>()
222 {
223  this->allocate(_mapping, _quadrature, _fe, _flags);
224 
225  // precompute the maping data and finite element data
226  this->mapping_data = this->mapping->initialize(*this->quadrature, this->data.update_flags);
227  this->fe_data = this->fe->initialize(*this->quadrature);
228 }
229 
230 
231 
232 template<unsigned int dim,unsigned int spacedim>
234 {
235  OLD_ASSERT_EQUAL( dim, cell->dim() );
236  this->data.present_cell = &cell;
237 
238  // calculate Jacobian of mapping, JxW, inverse Jacobian, normal vector(s)
239  this->mapping->fill_fe_values(cell,
240  *this->quadrature,
241  *this->mapping_data,
242  this->data);
243 
244  this->fe->fill_fe_values(*this->quadrature,
245  *this->fe_data,
246  this->data);
247 }
248 
249 
250 
251 
252 
253 
254 
255 
256 
257 template<unsigned int dim,unsigned int spacedim>
259  Quadrature<dim-1> & _sub_quadrature,
261  const UpdateFlags _flags)
262 :FEValuesBase<dim,spacedim>()
263 {
264  sub_quadrature = &_sub_quadrature;
265  Quadrature<dim> *q = new Quadrature<dim>(_sub_quadrature.size());
266  this->allocate(_mapping, *q, _fe, _flags);
267 
268  for (unsigned int sid = 0; sid < RefElement<dim>::n_sides; sid++)
269  {
270  for (unsigned int pid = 0; pid < RefElement<dim>::n_side_permutations; pid++)
271  {
272  // transform the side quadrature points to the cell quadrature points
273  side_quadrature[sid][pid] = Quadrature<dim>(_sub_quadrature, sid, pid);
274  side_mapping_data[sid][pid] = this->mapping->initialize(side_quadrature[sid][pid], this->data.update_flags);
275  side_fe_data[sid][pid] = this->fe->initialize(side_quadrature[sid][pid]);
276  }
277  }
278 }
279 
280 
281 
282 template<unsigned int dim,unsigned int spacedim>
284 {
285  for (unsigned int sid=0; sid<RefElement<dim>::n_sides; sid++)
286  {
287  for (unsigned int pid=0; pid<RefElement<dim>::n_side_permutations; pid++)
288  {
289  delete side_mapping_data[sid][pid];
290  delete side_fe_data[sid][pid];
291  }
292  }
293 
294  // Since quadrature is an auxiliary internal variable allocated
295  // by the constructor, it must be destroyed here.
296  delete this->quadrature;
297 }
298 
299 
300 template<unsigned int dim,unsigned int spacedim>
302  unsigned int sid)
303 {
304  ASSERT_LT_DBG( sid, cell->n_sides());
305  ASSERT_EQ_DBG(dim, cell->dim());
306  this->data.present_cell = &cell;
307 
308  unsigned int pid = cell->permutation_idx_[sid];
310  // calculate Jacobian of mapping, JxW, inverse Jacobian, normal vector(s)
311  this->mapping->fill_fe_side_values(cell,
312  sid,
313  side_quadrature[sid][pid],
314  *side_mapping_data[sid][pid],
315  this->data);
316 
317  // calculation of finite element data
318  this->fe->fill_fe_values(side_quadrature[sid][pid],
319  *side_fe_data[sid][pid],
320  this->data);
321 }
322 
323 
324 
325 
326 
327 
328 
329 template class FEValuesBase<0,3>;
330 template class FEValuesBase<1,3>;
331 template class FEValuesBase<2,3>;
332 template class FEValuesBase<3,3>;
333 
334 template class FEValues<0,3>;
335 template class FEValues<1,3>;
336 template class FEValues<2,3>;
337 template class FEValues<3,3>;
338 
339 template class FESideValues<1,3>;
340 template class FESideValues<2,3>;
341 template class FESideValues<3,3>;
342 
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
Transformed quadrature weight for cell sides.
#define ASSERT_EQ_DBG(a, b)
Definition of comparative assert macro (EQual) only for debug mode.
Definition: asserts.hh:331
arma::vec::fixed< spacedim > shape_grad_component(const unsigned int function_no, const unsigned int point_no, const unsigned int comp) const
Return the gradient of the function_no-th shape function at the point_no-th quadrature point...
Definition: fe_values.cc:199
Determinant of the Jacobian.
MappingInternalData * mapping_data
Precomputed mapping data.
Definition: fe_values.hh:416
UpdateFlags update_each(UpdateFlags flags)
Determine quantities to be recomputed on each cell.
Definition: fe_values.cc:160
virtual ~FEValuesBase()
Definition: fe_values.cc:118
FiniteElement< dim, spacedim > * get_fe() const
Returns the finite element in use.
Definition: fe_values.hh:383
FEValuesBase()
Default constructor.
Definition: fe_values.cc:110
Class FEValues calculates finite element data on the actual cells such as shape function values...
std::vector< unsigned int > get_vector_components() const
Definition: fe_system.hh:63
FEValuesData< dim, spacedim > data
Data computed by the mapping and finite element.
Definition: fe_values.hh:426
Class FESystem for compound finite elements.
FEInternalData * fe_data
Precomputed finite element data.
Definition: fe_values.hh:421
void allocate(unsigned int size, UpdateFlags flags, unsigned n_comp)
Resize the data arrays.
Definition: fe_values.cc:42
Base class for quadrature rules on simplices in arbitrary dimensions.
Definition: fe_values.hh:32
Volume element.
unsigned int n_components_
Number of components of the FE.
Definition: fe_values.hh:429
virtual ~FESideValues()
Destructor.
Definition: fe_values.cc:283
#define OLD_ASSERT(...)
Definition: global_defs.h:131
Transformed quadrature points.
Abstract class for the mapping between reference and actual cell.
Definition: fe_values.hh:35
Compound finite element on dim dimensional simplex.
Definition: fe_system.hh:36
FiniteElement< dim, spacedim > * fe
The used finite element.
Definition: fe_values.hh:411
Basic definitions of numerical quadrature rules.
const Quadrature< dim-1 > * sub_quadrature
Quadrature for the integration on the element sides.
Definition: fe_values.hh:535
Shape function gradients.
Definition: update_flags.hh:95
MappingInternalData * side_mapping_data[RefElement< dim >::n_sides][RefElement< dim >::n_side_permutations]
Definition: fe_values.hh:539
Quadrature< dim > side_quadrature[RefElement< dim >::n_sides][RefElement< dim >::n_side_permutations]
Definition: fe_values.hh:537
Quadrature< dim > * quadrature
The quadrature rule used to calculate integrals.
Definition: fe_values.hh:406
double shape_value(const unsigned int function_no, const unsigned int point_no)
Return the value of the function_no-th shape function at the point_no-th quadrature point...
Definition: fe_values.cc:169
Class Mapping calculates data related to the mapping of the reference cell to the actual cell...
Normal vectors.
FEInternalData * side_fe_data[RefElement< dim >::n_sides][RefElement< dim >::n_side_permutations]
Definition: fe_values.hh:541
ViewsCache views_cache_
Auxiliary storage of FEValuesViews accessors.
Definition: fe_values.hh:432
FEValues(Mapping< dim, spacedim > &_mapping, Quadrature< dim > &_quadrature, FiniteElement< dim, spacedim > &_fe, UpdateFlags _flags)
Constructor.
Definition: fe_values.cc:217
void reinit(ElementFullIter &cell, unsigned int sid)
Update cell-dependent data (gradients, Jacobians etc.)
Definition: fe_values.cc:301
Mapping< dim, spacedim > * mapping
The mapping from the reference cell to the actual cell.
Definition: fe_values.hh:401
const unsigned int size() const
Returns number of quadrature points.
Definition: quadrature.hh:139
double shape_value_component(const unsigned int function_no, const unsigned int point_no, const unsigned int comp) const
Return the value of the function_no-th shape function at the point_no-th quadrature point...
Definition: fe_values.cc:187
void reinit(ElementFullIter &cell)
Update cell-dependent data (gradients, Jacobians etc.)
Definition: fe_values.cc:233
arma::vec::fixed< spacedim > shape_grad(const unsigned int function_no, const unsigned int point_no)
Return the gradient of the function_no-th shape function at the point_no-th quadrature point...
Definition: fe_values.cc:178
Calculates finite element data on the actual cell.
Definition: fe_values.hh:450
#define OLD_ASSERT_EQUAL(a, b)
Definition: global_defs.h:133
Abstract class for description of finite elements.
FESideValues(Mapping< dim, spacedim > &_mapping, Quadrature< dim-1 > &_sub_quadrature, FiniteElement< dim, spacedim > &_fe, UpdateFlags flags)
Constructor.
Definition: fe_values.cc:258
Abstract class for the description of a general finite element on a reference simplex in dim dimensio...
Definition: dofhandler.hh:30
Base class for FEValues and FESideValues.
Definition: fe_values.hh:34
void allocate(Mapping< dim, spacedim > &_mapping, Quadrature< dim > &_quadrature, FiniteElement< dim, spacedim > &_fe, UpdateFlags flags)
Allocates space for computed data.
Definition: fe_values.cc:126
std::vector< unsigned int > get_scalar_components() const
Definition: fe_system.hh:60
void resize(FEValuesBase &fv, unsigned int size)
Definition: fe_values.cc:79
Transformed quadrature weights.
Calculates finite element data on a side.
Definition: fe_values.hh:495
#define ASSERT_LT_DBG(a, b)
Definition of comparative assert macro (Less Than) only for debug mode.
Definition: asserts.hh:299