Flow123d  release_2.2.0-33-g759111d
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 
26 
27 
28 using namespace arma;
29 using namespace std;
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 template<unsigned int dim, unsigned int spacedim>
41 void FEValuesData<dim,spacedim>::allocate(unsigned int size, UpdateFlags flags, bool is_scalar)
42 {
43  update_flags = flags;
44 
45  // resize the arrays of computed quantities
46  if (update_flags & update_jacobians)
47  jacobians.resize(size);
48 
49  if (update_flags & update_volume_elements)
50  determinants.resize(size);
51 
52  if ((update_flags & update_JxW_values) |
53  (update_flags & update_side_JxW_values))
54  JxW_values.resize(size);
55 
56  if (update_flags & update_inverse_jacobians)
57  inverse_jacobians.resize(size);
58 
59  if (update_flags & update_values)
60  {
61  if (is_scalar)
62  {
63  shape_values.resize(size);
64  }
65  else
66  {
67  shape_vectors.resize(size);
68  }
69  }
70 
71  if (update_flags & update_gradients)
72  {
73  if (is_scalar)
74  {
75  shape_gradients.resize(size);
76  }
77  else
78  {
79  shape_grad_vectors.resize(size);
80  }
81  }
82 
83  if (update_flags & update_quadrature_points)
84  points.resize(size);
85 
86  if (update_flags & update_normal_vectors)
87  normal_vectors.resize(size);
88 }
89 
90 
91 
92 
93 
94 template<unsigned int dim,unsigned int spacedim>
96 : mapping(NULL), quadrature(NULL), fe(NULL), mapping_data(NULL), fe_data(NULL)
97 {
98 }
99 
100 
101 
102 template<unsigned int dim,unsigned int spacedim>
104  if (mapping_data) delete mapping_data;
105  if (fe_data) delete fe_data;
106 }
107 
108 
109 
110 template<unsigned int dim, unsigned int spacedim>
112  Quadrature<dim> & _quadrature,
114  UpdateFlags _flags)
115 
116 {
117  mapping = &_mapping;
118  quadrature = &_quadrature;
119  fe = &_fe;
120 
121  // add flags required by the finite element or mapping
122  data.allocate(quadrature->size(), update_each(_flags), fe->is_scalar());
123 }
124 
125 
126 
127 template<unsigned int dim, unsigned int spacedim>
129 {
130  UpdateFlags f = flags | fe->update_each(flags);
131  f |= mapping->update_each(f);
132  return f;
133 }
134 
135 
136 
137 
138 
139 
140 template<unsigned int dim, unsigned int spacedim>
142  Quadrature<dim> &_quadrature,
144  UpdateFlags _flags)
145 :FEValuesBase<dim, spacedim>()
146 {
147  this->allocate(_mapping, _quadrature, _fe, _flags);
148 
149  // precompute the maping data and finite element data
150  this->mapping_data = this->mapping->initialize(*this->quadrature, this->data.update_flags);
151  this->fe_data = this->fe->initialize(*this->quadrature, this->data.update_flags);
152 }
153 
154 
155 
156 template<unsigned int dim,unsigned int spacedim>
158 {
159  OLD_ASSERT_EQUAL( dim, cell->dim() );
160  this->data.present_cell = &cell;
161 
162  // calculate Jacobian of mapping, JxW, inverse Jacobian, normal vector(s)
163  this->mapping->fill_fe_values(cell,
164  *this->quadrature,
165  *this->mapping_data,
166  this->data);
167 
168  this->fe->fill_fe_values(*this->quadrature,
169  *this->fe_data,
170  this->data);
171 }
172 
173 
174 
175 
176 
177 
178 
179 
180 
181 template<unsigned int dim,unsigned int spacedim>
183  Quadrature<dim-1> & _sub_quadrature,
185  const UpdateFlags _flags)
186 :FEValuesBase<dim,spacedim>()
187 {
188  sub_quadrature = &_sub_quadrature;
189  Quadrature<dim> *q = new Quadrature<dim>(_sub_quadrature.size());
190  this->allocate(_mapping, *q, _fe, _flags);
191 
192  for (unsigned int sid = 0; sid < RefElement<dim>::n_sides; sid++)
193  {
194  for (unsigned int pid = 0; pid < RefElement<dim>::n_side_permutations; pid++)
195  {
196  // transform the side quadrature points to the cell quadrature points
197  this->mapping->transform_subquadrature(sid, pid, *sub_quadrature, side_quadrature[sid][pid]);
198  side_mapping_data[sid][pid] = this->mapping->initialize(side_quadrature[sid][pid], this->data.update_flags);
199  side_fe_data[sid][pid] = this->fe->initialize(side_quadrature[sid][pid], this->data.update_flags);
200  }
201  }
202 }
203 
204 
205 
206 template<unsigned int dim,unsigned int spacedim>
208 {
209  for (unsigned int sid=0; sid<RefElement<dim>::n_sides; sid++)
210  {
211  for (unsigned int pid=0; pid<RefElement<dim>::n_side_permutations; pid++)
212  {
213  delete side_mapping_data[sid][pid];
214  delete side_fe_data[sid][pid];
215  }
216  }
217 
218  // Since quadrature is an auxiliary internal variable allocated
219  // by the constructor, it must be destroyed here.
220  delete this->quadrature;
221 }
222 
223 
224 template<unsigned int dim,unsigned int spacedim>
226  unsigned int sid)
227 {
228  this->data.present_cell = &cell;
229 
230  unsigned int pid = cell->permutation_idx_[sid];
231 
232  // calculate Jacobian of mapping, JxW, inverse Jacobian, normal vector(s)
233  this->mapping->fill_fe_side_values(cell,
234  sid,
235  side_quadrature[sid][pid],
236  *side_mapping_data[sid][pid],
237  this->data);
238 
239  // calculation of finite element data
240  this->fe->fill_fe_values(side_quadrature[sid][pid],
241  *side_fe_data[sid][pid],
242  this->data);
243 }
244 
245 
246 
247 
248 
249 
250 
251 template class FEValuesBase<0,3>;
252 template class FEValuesBase<1,3>;
253 template class FEValuesBase<2,3>;
254 template class FEValuesBase<3,3>;
255 
256 template class FEValues<0,3>;
257 template class FEValues<1,3>;
258 template class FEValues<2,3>;
259 template class FEValues<3,3>;
260 
261 template class FESideValues<1,3>;
262 template class FESideValues<2,3>;
263 template class FESideValues<3,3>;
264 
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.
Determinant of the Jacobian.
MappingInternalData * mapping_data
Precomputed mapping data.
Definition: fe_values.hh:388
UpdateFlags update_each(UpdateFlags flags)
Determine quantities to be recomputed on each cell.
Definition: fe_values.cc:128
virtual ~FEValuesBase()
Definition: fe_values.cc:103
FEValuesBase()
Default constructor.
Definition: fe_values.cc:95
Class FEValues calculates finite element data on the actual cells such as shape function values...
FEValuesData< dim, spacedim > data
Data computed by the mapping and finite element.
Definition: fe_values.hh:398
FEInternalData * fe_data
Precomputed finite element data.
Definition: fe_values.hh:393
Base class for quadrature rules on simplices in arbitrary dimensions.
Definition: fe_values.hh:31
Volume element.
virtual ~FESideValues()
Destructor.
Definition: fe_values.cc:207
Transformed quadrature points.
Abstract class for the mapping between reference and actual cell.
Definition: fe_values.hh:33
FiniteElement< dim, spacedim > * fe
The used finite element.
Definition: fe_values.hh:383
Basic definitions of numerical quadrature rules.
const Quadrature< dim-1 > * sub_quadrature
Quadrature for the integration on the element sides.
Definition: fe_values.hh:501
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:505
Quadrature< dim > side_quadrature[RefElement< dim >::n_sides][RefElement< dim >::n_side_permutations]
Definition: fe_values.hh:503
Quadrature< dim > * quadrature
The quadrature rule used to calculate integrals.
Definition: fe_values.hh:378
Class Mapping calculates data related to the mapping of the reference cell to the actual cell...
Normal vectors.
void allocate(unsigned int size, UpdateFlags flags, bool is_scalar=true)
Resize the data arrays.
Definition: fe_values.cc:41
FEInternalData * side_fe_data[RefElement< dim >::n_sides][RefElement< dim >::n_side_permutations]
Definition: fe_values.hh:507
FEValues(Mapping< dim, spacedim > &_mapping, Quadrature< dim > &_quadrature, FiniteElement< dim, spacedim > &_fe, UpdateFlags _flags)
Constructor.
Definition: fe_values.cc:141
void reinit(ElementFullIter &cell, unsigned int sid)
Update cell-dependent data (gradients, Jacobians etc.)
Definition: fe_values.cc:225
Mapping< dim, spacedim > * mapping
The mapping from the reference cell to the actual cell.
Definition: fe_values.hh:373
const unsigned int size() const
Returns number of quadrature points.
Definition: quadrature.hh:125
void reinit(ElementFullIter &cell)
Update cell-dependent data (gradients, Jacobians etc.)
Definition: fe_values.cc:157
Calculates finite element data on the actual cell.
Definition: fe_values.hh:416
#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:182
Abstract class for the description of a general finite element on a reference simplex in dim dimensio...
Definition: dofhandler.hh:29
Base class for FEValues and FESideValues.
Definition: fe_values.hh:32
void allocate(Mapping< dim, spacedim > &_mapping, Quadrature< dim > &_quadrature, FiniteElement< dim, spacedim > &_fe, UpdateFlags flags)
Allocates space for computed data.
Definition: fe_values.cc:111
Transformed quadrature weights.
Calculates finite element data on a side.
Definition: fe_values.hh:461