Flow123d  jenkins-Flow123d-linux-release-multijob-282
fe_values.cc
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 Class FEValues calculates finite element data on the actual
27  * cells such as shape function values, gradients, Jacobian of
28  * the mapping from the reference cell etc.
29  * @author Jan Stebel
30  */
31 
32 
33 #include "fem/mapping.hh"
34 #include "quadrature/quadrature.hh"
35 #include "fem/finite_element.hh"
36 #include "fem/fe_values.hh"
37 
38 
39 
40 using namespace arma;
41 using namespace std;
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 template<unsigned int dim, unsigned int spacedim> inline
53 void FEValuesData<dim,spacedim>::allocate(unsigned int size, UpdateFlags flags, bool is_scalar)
54 {
55  update_flags = flags;
56 
57  // resize the arrays of computed quantities
58  if (update_flags & update_jacobians)
59  jacobians.resize(size);
60 
61  if (update_flags & update_volume_elements)
62  determinants.resize(size);
63 
64  if ((update_flags & update_JxW_values) |
65  (update_flags & update_side_JxW_values))
66  JxW_values.resize(size);
67 
68  if (update_flags & update_inverse_jacobians)
69  inverse_jacobians.resize(size);
70 
71  if (update_flags & update_values)
72  {
73  if (is_scalar)
74  {
75  shape_values.resize(size);
76  }
77  else
78  {
79  shape_vectors.resize(size);
80  }
81  }
82 
83  if (update_flags & update_gradients)
84  {
85  if (is_scalar)
86  {
87  shape_gradients.resize(size);
88  }
89  else
90  {
91  shape_grad_vectors.resize(size);
92  }
93  }
94 
95  if (update_flags & update_quadrature_points)
96  points.resize(size);
97 
98  if (update_flags & update_normal_vectors)
99  normal_vectors.resize(size);
100 }
101 
102 
103 
104 
105 
106 template<unsigned int dim,unsigned int spacedim> inline
108 : mapping(NULL), quadrature(NULL), fe(NULL), mapping_data(NULL), fe_data(NULL)
109 {
110 }
111 
112 
113 
114 template<unsigned int dim,unsigned int spacedim> inline
116  if (mapping_data) delete mapping_data;
117  if (fe_data) delete fe_data;
118 }
119 
120 
121 
122 template<unsigned int dim, unsigned int spacedim>
124  Quadrature<dim> & _quadrature,
126  UpdateFlags _flags)
127 
128 {
129  mapping = &_mapping;
130  quadrature = &_quadrature;
131  fe = &_fe;
132 
133  // add flags required by the finite element or mapping
134  data.allocate(quadrature->size(), update_each(_flags), fe->is_scalar());
135 }
136 
137 
138 
139 template<unsigned int dim, unsigned int spacedim> inline
141 {
142  UpdateFlags f = flags | fe->update_each(flags);
143  f |= mapping->update_each(f);
144  return f;
145 }
146 
147 template<unsigned int dim, unsigned int spacedim> inline
148 const double FEValuesBase<dim,spacedim>::shape_value(const unsigned int function_no, const unsigned int point_no)
149 {
150  return data.shape_values[point_no][function_no];
151 }
152 
153 template<unsigned int dim, unsigned int spacedim> inline
154 const vec::fixed<spacedim> FEValuesBase<dim,spacedim>::shape_grad(const unsigned int function_no, const unsigned int point_no)
155 {
156  return trans(data.shape_gradients[point_no].row(function_no));
157 }
158 
159 template<unsigned int dim, unsigned int spacedim> inline
160 const vec::fixed<spacedim> FEValuesBase<dim,spacedim>::shape_vector(const unsigned int function_no, const unsigned int point_no)
161 {
162  return data.shape_vectors[point_no][function_no];
163 }
164 
165 template<unsigned int dim, unsigned int spacedim> inline
166 const mat::fixed<spacedim,spacedim> FEValuesBase<dim,spacedim>::shape_grad_vector(const unsigned int function_no, const unsigned int point_no)
167 {
168  return data.shape_grad_vectors[point_no][function_no];
169 }
170 
171 template<unsigned int dim, unsigned int spacedim> inline
172 const double FEValuesBase<dim,spacedim>::determinant(const unsigned int point_no)
173 {
174  return data.determinants[point_no];
175 }
176 
177 template<unsigned int dim, unsigned int spacedim> inline
178 const double FEValuesBase<dim,spacedim>::JxW(const unsigned int point_no)
179 {
180  return data.JxW_values[point_no];
181 }
182 
183 template<unsigned int dim, unsigned int spacedim> inline
184 const vec::fixed<spacedim> FEValuesBase<dim,spacedim>::point(const unsigned int point_no)
185 {
186  return data.points[point_no];
187 }
188 
189 template<unsigned int dim, unsigned int spacedim> inline
191 {
192  return data.points;
193 }
194 
195 template<unsigned int dim,unsigned int spacedim> inline
196 const vec::fixed<spacedim> FEValuesBase<dim,spacedim>::normal_vector(unsigned int point_no)
197 {
198  return data.normal_vectors[point_no];
199 }
200 
201 template<unsigned int dim, unsigned int spacedim> inline
203 {
204  return quadrature->size();
205 }
206 
207 template<unsigned int dim, unsigned int spacedim> inline
209 {
210  return fe->n_dofs();
211 }
212 
213 template<unsigned int dim, unsigned int spacedim> inline
215 {
216  return quadrature;
217 }
218 
219 
220 
221 
222 
223 
224 
225 
226 
227 template<unsigned int dim, unsigned int spacedim>
229  Quadrature<dim> &_quadrature,
231  UpdateFlags _flags)
232 :FEValuesBase<dim, spacedim>()
233 {
234  this->allocate(_mapping, _quadrature, _fe, _flags);
235 
236  // precompute the maping data and finite element data
237  this->mapping_data = this->mapping->initialize(*this->quadrature, this->data.update_flags);
238  this->fe_data = this->fe->initialize(*this->quadrature, this->data.update_flags);
239 }
240 
241 
242 
243 template<unsigned int dim,unsigned int spacedim> inline
245 {
246  ASSERT_EQUAL( dim, cell->dim() );
247  this->data.present_cell = &cell;
248 
249  // calculate Jacobian of mapping, JxW, inverse Jacobian, normal vector(s)
250  this->mapping->fill_fe_values(cell,
251  *this->quadrature,
252  *this->mapping_data,
253  this->data);
254 
255  this->fe->fill_fe_values(*this->quadrature,
256  *this->fe_data,
257  this->data);
258 }
259 
260 
261 
262 
263 
264 
265 
266 
267 
268 template<unsigned int dim,unsigned int spacedim> inline
270  Quadrature<dim-1> & _sub_quadrature,
272  const UpdateFlags _flags)
273 :FEValuesBase<dim,spacedim>()
274 {
275  sub_quadrature = &_sub_quadrature;
276  Quadrature<dim> *q = new Quadrature<dim>(_sub_quadrature.size());
277  this->allocate(_mapping, *q, _fe, _flags);
278 
279  for (unsigned int sid = 0; sid < RefElement<dim>::n_sides; sid++)
280  {
281  for (unsigned int pid = 0; pid < RefElement<dim>::n_side_permutations; pid++)
282  {
283  // transform the side quadrature points to the cell quadrature points
284  this->mapping->transform_subquadrature(sid, pid, *sub_quadrature, side_quadrature[sid][pid]);
285  side_mapping_data[sid][pid] = this->mapping->initialize(side_quadrature[sid][pid], this->data.update_flags);
286  side_fe_data[sid][pid] = this->fe->initialize(side_quadrature[sid][pid], this->data.update_flags);
287  }
288  }
289 }
290 
291 
292 
293 template<unsigned int dim,unsigned int spacedim>
295 {
296  for (unsigned int sid=0; sid<RefElement<dim>::n_sides; sid++)
297  {
298  for (unsigned int pid=0; pid<RefElement<dim>::n_side_permutations; pid++)
299  {
300  delete side_mapping_data[sid][pid];
301  delete side_fe_data[sid][pid];
302  }
303  }
304 
305  // Since quadrature is an auxiliary internal variable allocated
306  // by the constructor, it must be destroyed here.
307  delete this->quadrature;
308 }
309 
310 
311 template<unsigned int dim,unsigned int spacedim> inline
313  unsigned int sid)
314 {
315  this->data.present_cell = &cell;
316 
317  unsigned int pid = cell->permutation_idx_[sid];
318 
319  // calculate Jacobian of mapping, JxW, inverse Jacobian, normal vector(s)
320  this->mapping->fill_fe_side_values(cell,
321  sid,
322  side_quadrature[sid][pid],
323  *side_mapping_data[sid][pid],
324  this->data);
325 
326  // calculation of finite element data
327  this->fe->fill_fe_values(side_quadrature[sid][pid],
328  *side_fe_data[sid][pid],
329  this->data);
330 }
331 
332 
333 
334 
335 
336 
337 
338 template class FEValuesBase<0,3>;
339 template class FEValuesBase<1,3>;
340 template class FEValuesBase<2,3>;
341 template class FEValuesBase<3,3>;
342 
343 template class FEValues<0,3>;
344 template class FEValues<1,3>;
345 template class FEValues<2,3>;
346 template class FEValues<3,3>;
347 
348 template class FESideValues<1,3>;
349 template class FESideValues<2,3>;
350 template class FESideValues<3,3>;
351 
Shape function values.
Definition: update_flags.hh:98
UpdateFlags
Enum type UpdateFlags indicates which quantities are to be recomputed on each finite element cell...
Definition: update_flags.hh:78
const Quadrature< dim > * get_quadrature() const
Returns the quadrature in use.
Definition: fe_values.cc:214
Transformed quadrature weight for cell sides.
const arma::vec::fixed< spacedim > point(const unsigned int point_no)
Return coordinates of the quadrature point in the actual cell system.
Definition: fe_values.cc:184
Determinant of the Jacobian.
MappingInternalData * mapping_data
Precomputed mapping data.
Definition: fe_values.hh:342
UpdateFlags update_each(UpdateFlags flags)
Determine quantities to be recomputed on each cell.
Definition: fe_values.cc:140
const double JxW(const unsigned int point_no)
Return the product of Jacobian determinant and the quadrature weight at given quadrature point...
Definition: fe_values.cc:178
const arma::vec::fixed< spacedim > normal_vector(unsigned int point_no)
Returns the normal vector to a side at given quadrature point.
Definition: fe_values.cc:196
virtual ~FEValuesBase()
Definition: fe_values.cc:115
const double determinant(const unsigned int point_no)
Return the relative volume change of the cell (Jacobian determinant).
Definition: fe_values.cc:172
FEValuesBase()
Default constructor.
Definition: fe_values.cc:107
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:352
FEInternalData * fe_data
Precomputed finite element data.
Definition: fe_values.hh:347
const 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:154
Base class for quadrature rules on simplices in arbitrary dimensions.
Definition: fe_values.hh:42
Volume element.
virtual ~FESideValues()
Destructor.
Definition: fe_values.cc:294
const unsigned int n_points()
Returns the number of quadrature points.
Definition: fe_values.cc:202
Transformed quadrature points.
Abstract class for the mapping between reference and actual cell.
Definition: fe_values.hh:44
#define ASSERT_EQUAL(a, b)
Definition: global_defs.h:136
FiniteElement< dim, spacedim > * fe
The used finite element.
Definition: fe_values.hh:337
Basic definitions of numerical quadrature rules.
const Quadrature< dim-1 > * sub_quadrature
Quadrature for the integration on the element sides.
Definition: fe_values.hh:455
Shape function gradients.
MappingInternalData * side_mapping_data[RefElement< dim >::n_sides][RefElement< dim >::n_side_permutations]
Definition: fe_values.hh:459
Quadrature< dim > side_quadrature[RefElement< dim >::n_sides][RefElement< dim >::n_side_permutations]
Definition: fe_values.hh:457
Quadrature< dim > * quadrature
The quadrature rule used to calculate integrals.
Definition: fe_values.hh:332
Class Mapping calculates data related to the mapping of the reference cell to the actual cell...
Normal vectors.
const vector< arma::vec::fixed< spacedim > > & point_list()
Return coordinates of all quadrature points in the actual cell system.
Definition: fe_values.cc:190
void allocate(unsigned int size, UpdateFlags flags, bool is_scalar=true)
Resize the data arrays.
Definition: fe_values.cc:53
const arma::vec::fixed< spacedim > shape_vector(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:160
FEInternalData * side_fe_data[RefElement< dim >::n_sides][RefElement< dim >::n_side_permutations]
Definition: fe_values.hh:461
FEValues(Mapping< dim, spacedim > &_mapping, Quadrature< dim > &_quadrature, FiniteElement< dim, spacedim > &_fe, UpdateFlags _flags)
Constructor.
Definition: fe_values.cc:228
void reinit(ElementFullIter &cell, unsigned int sid)
Update cell-dependent data (gradients, Jacobians etc.)
Definition: fe_values.cc:312
const 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:148
Mapping< dim, spacedim > * mapping
The mapping from the reference cell to the actual cell.
Definition: fe_values.hh:327
const unsigned int size() const
Returns number of quadrature points.
Definition: quadrature.hh:136
void reinit(ElementFullIter &cell)
Update cell-dependent data (gradients, Jacobians etc.)
Definition: fe_values.cc:244
Calculates finite element data on the actual cell.
Definition: fe_values.hh:370
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:269
Abstract class for the description of a general finite element on a reference simplex in dim dimensio...
Definition: dofhandler.hh:40
Base class for FEValues and FESideValues.
Definition: fe_values.hh:43
void allocate(Mapping< dim, spacedim > &_mapping, Quadrature< dim > &_quadrature, FiniteElement< dim, spacedim > &_fe, UpdateFlags flags)
Allocates space for computed data.
Definition: fe_values.cc:123
const unsigned int n_dofs()
Returns the number of shape functions.
Definition: fe_values.cc:208
const arma::mat::fixed< spacedim, spacedim > shape_grad_vector(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:166
Transformed quadrature weights.
Calculates finite element data on a side.
Definition: fe_values.hh:415