Reference documentation for deal.II version 9.1.0-pre
fe_poly.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2004 - 2018 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_fe_poly_h
17 #define dealii_fe_poly_h
18 
19 
20 #include <deal.II/base/quadrature.h>
21 #include <deal.II/base/std_cxx14/memory.h>
22 
23 #include <deal.II/fe/fe.h>
24 
25 DEAL_II_NAMESPACE_OPEN
26 
29 
69 template <class PolynomialType,
70  int dim = PolynomialType::dimension,
71  int spacedim = dim>
72 class FE_Poly : public FiniteElement<dim, spacedim>
73 {
74 public:
78  FE_Poly(const PolynomialType & poly_space,
79  const FiniteElementData<dim> & fe_data,
80  const std::vector<bool> & restriction_is_additive_flags,
81  const std::vector<ComponentMask> &nonzero_components);
82 
87  unsigned int
88  get_degree() const;
89 
90  // for documentation, see the FiniteElement base class
91  virtual UpdateFlags
92  requires_update_flags(const UpdateFlags update_flags) const override;
93 
99  std::vector<unsigned int>
100  get_poly_space_numbering() const;
101 
106  std::vector<unsigned int>
108 
114  virtual double
115  shape_value(const unsigned int i, const Point<dim> &p) const override;
116 
127  virtual double
128  shape_value_component(const unsigned int i,
129  const Point<dim> & p,
130  const unsigned int component) const override;
131 
137  virtual Tensor<1, dim>
138  shape_grad(const unsigned int i, const Point<dim> &p) const override;
139 
150  virtual Tensor<1, dim>
151  shape_grad_component(const unsigned int i,
152  const Point<dim> & p,
153  const unsigned int component) const override;
154 
160  virtual Tensor<2, dim>
161  shape_grad_grad(const unsigned int i, const Point<dim> &p) const override;
162 
173  virtual Tensor<2, dim>
174  shape_grad_grad_component(const unsigned int i,
175  const Point<dim> & p,
176  const unsigned int component) const override;
177 
183  virtual Tensor<3, dim>
184  shape_3rd_derivative(const unsigned int i,
185  const Point<dim> & p) const override;
186 
197  virtual Tensor<3, dim>
198  shape_3rd_derivative_component(const unsigned int i,
199  const Point<dim> & p,
200  const unsigned int component) const override;
201 
207  virtual Tensor<4, dim>
208  shape_4th_derivative(const unsigned int i,
209  const Point<dim> & p) const override;
210 
221  virtual Tensor<4, dim>
222  shape_4th_derivative_component(const unsigned int i,
223  const Point<dim> & p,
224  const unsigned int component) const override;
225 
226 protected:
227  /*
228  * NOTE: The following function has its definition inlined into the class
229  * declaration because we otherwise run into a compiler error with MS Visual
230  * Studio.
231  */
232 
233 
234  virtual std::unique_ptr<
237  const UpdateFlags update_flags,
238  const Mapping<dim, spacedim> & /*mapping*/,
239  const Quadrature<dim> &quadrature,
241  spacedim>
242  &output_data) const override
243  {
244  // generate a new data object and
245  // initialize some fields
246  auto data = std_cxx14::make_unique<InternalData>();
247  data->update_each = requires_update_flags(update_flags);
248 
249  const unsigned int n_q_points = quadrature.size();
250 
251  // initialize some scratch arrays. we need them for the underlying
252  // polynomial to put the values and derivatives of shape functions
253  // to put there, depending on what the user requested
254  std::vector<double> values(
255  update_flags & update_values ? this->dofs_per_cell : 0);
256  std::vector<Tensor<1, dim>> grads(
257  update_flags & update_gradients ? this->dofs_per_cell : 0);
258  std::vector<Tensor<2, dim>> grad_grads(
259  update_flags & update_hessians ? this->dofs_per_cell : 0);
260  std::vector<Tensor<3, dim>> third_derivatives(
261  update_flags & update_3rd_derivatives ? this->dofs_per_cell : 0);
262  std::vector<Tensor<4, dim>>
263  fourth_derivatives; // won't be needed, so leave empty
264 
265  // now also initialize fields the fields of this class's own
266  // temporary storage, depending on what we need for the given
267  // update flags.
268  //
269  // there is one exception from the rule: if we are dealing with
270  // cells (i.e., if this function is not called via
271  // get_(sub)face_data()), then we can already store things in the
272  // final location where FEValues::reinit() later wants to see
273  // things. we then don't need the intermediate space. we determine
274  // whether we are on a cell by asking whether the number of
275  // elements in the output array equals the number of quadrature
276  // points (yes, it's a cell) or not (because in that case the
277  // number of quadrature points we use here equals the number of
278  // quadrature points summed over *all* faces or subfaces, whereas
279  // the number of output slots equals the number of quadrature
280  // points on only *one* face)
281  if ((update_flags & update_values) &&
282  !((output_data.shape_values.n_rows() > 0) &&
283  (output_data.shape_values.n_cols() == n_q_points)))
284  data->shape_values.reinit(this->dofs_per_cell, n_q_points);
285 
286  if (update_flags & update_gradients)
287  data->shape_gradients.reinit(this->dofs_per_cell, n_q_points);
288 
289  if (update_flags & update_hessians)
290  data->shape_hessians.reinit(this->dofs_per_cell, n_q_points);
291 
292  if (update_flags & update_3rd_derivatives)
293  data->shape_3rd_derivatives.reinit(this->dofs_per_cell, n_q_points);
294 
295  // next already fill those fields of which we have information by
296  // now. note that the shape gradients are only those on the unit
297  // cell, and need to be transformed when visiting an actual cell
298  if (update_flags & (update_values | update_gradients | update_hessians |
299  update_3rd_derivatives))
300  for (unsigned int i = 0; i < n_q_points; ++i)
301  {
302  poly_space.compute(quadrature.point(i),
303  values,
304  grads,
305  grad_grads,
306  third_derivatives,
307  fourth_derivatives);
308 
309  // the values of shape functions at quadrature points don't change.
310  // consequently, write these values right into the output array if
311  // we can, i.e., if the output array has the correct size. this is
312  // the case on cells. on faces, we already precompute data on *all*
313  // faces and subfaces, but we later on copy only a portion of it
314  // into the output object; in that case, copy the data from all
315  // faces into the scratch object
316  if (update_flags & update_values)
317  if (output_data.shape_values.n_rows() > 0)
318  {
319  if (output_data.shape_values.n_cols() == n_q_points)
320  for (unsigned int k = 0; k < this->dofs_per_cell; ++k)
321  output_data.shape_values[k][i] = values[k];
322  else
323  for (unsigned int k = 0; k < this->dofs_per_cell; ++k)
324  data->shape_values[k][i] = values[k];
325  }
326 
327  // for everything else, derivatives need to be transformed,
328  // so we write them into our scratch space and only later
329  // copy stuff into where FEValues wants it
330  if (update_flags & update_gradients)
331  for (unsigned int k = 0; k < this->dofs_per_cell; ++k)
332  data->shape_gradients[k][i] = grads[k];
333 
334  if (update_flags & update_hessians)
335  for (unsigned int k = 0; k < this->dofs_per_cell; ++k)
336  data->shape_hessians[k][i] = grad_grads[k];
337 
338  if (update_flags & update_3rd_derivatives)
339  for (unsigned int k = 0; k < this->dofs_per_cell; ++k)
340  data->shape_3rd_derivatives[k][i] = third_derivatives[k];
341  }
342  return std::move(data);
343  }
344 
345  virtual void
346  fill_fe_values(
347  const typename Triangulation<dim, spacedim>::cell_iterator &cell,
348  const CellSimilarity::Similarity cell_similarity,
349  const Quadrature<dim> & quadrature,
350  const Mapping<dim, spacedim> & mapping,
351  const typename Mapping<dim, spacedim>::InternalDataBase &mapping_internal,
352  const ::internal::FEValuesImplementation::MappingRelatedData<dim,
353  spacedim>
354  & mapping_data,
355  const typename FiniteElement<dim, spacedim>::InternalDataBase &fe_internal,
357  spacedim>
358  &output_data) const override;
359 
360  virtual void
361  fill_fe_face_values(
362  const typename Triangulation<dim, spacedim>::cell_iterator &cell,
363  const unsigned int face_no,
364  const Quadrature<dim - 1> & quadrature,
365  const Mapping<dim, spacedim> & mapping,
366  const typename Mapping<dim, spacedim>::InternalDataBase &mapping_internal,
367  const ::internal::FEValuesImplementation::MappingRelatedData<dim,
368  spacedim>
369  & mapping_data,
370  const typename FiniteElement<dim, spacedim>::InternalDataBase &fe_internal,
372  spacedim>
373  &output_data) const override;
374 
375  virtual void
376  fill_fe_subface_values(
377  const typename Triangulation<dim, spacedim>::cell_iterator &cell,
378  const unsigned int face_no,
379  const unsigned int sub_no,
380  const Quadrature<dim - 1> & quadrature,
381  const Mapping<dim, spacedim> & mapping,
382  const typename Mapping<dim, spacedim>::InternalDataBase &mapping_internal,
383  const ::internal::FEValuesImplementation::MappingRelatedData<dim,
384  spacedim>
385  & mapping_data,
386  const typename FiniteElement<dim, spacedim>::InternalDataBase &fe_internal,
388  spacedim>
389  &output_data) const override;
390 
397  class InternalData : public FiniteElement<dim, spacedim>::InternalDataBase
398  {
399  public:
410 
421 
432 
443  };
444 
467  void
470  &output_data,
472  & mapping_data,
473  const unsigned int n_q_points,
474  const unsigned int dof) const;
475 
480  PolynomialType poly_space;
481 };
482 
485 DEAL_II_NAMESPACE_CLOSE
486 
487 #endif
Shape function values.
virtual double shape_value(const unsigned int i, const Point< dim > &p) const override
Table< 2, Tensor< 2, dim > > shape_hessians
Definition: fe_poly.h:431
void correct_third_derivatives(internal::FEValuesImplementation::FiniteElementRelatedData< dim, spacedim > &output_data, const internal::FEValuesImplementation::MappingRelatedData< dim, spacedim > &mapping_data, const unsigned int n_q_points, const unsigned int dof) const
virtual Tensor< 4, dim > shape_4th_derivative(const unsigned int i, const Point< dim > &p) const override
virtual Tensor< 1, dim > shape_grad(const unsigned int i, const Point< dim > &p) const override
virtual Tensor< 2, dim > shape_grad_grad(const unsigned int i, const Point< dim > &p) const override
virtual std::unique_ptr< typename FiniteElement< dim, spacedim >::InternalDataBase > get_data(const UpdateFlags update_flags, const Mapping< dim, spacedim > &, const Quadrature< dim > &quadrature,::internal::FEValuesImplementation::FiniteElementRelatedData< dim, spacedim > &output_data) const override
Definition: fe_poly.h:236
const Point< dim > & point(const unsigned int i) const
virtual Tensor< 2, dim > shape_grad_grad_component(const unsigned int i, const Point< dim > &p, const unsigned int component) const override
Table< 2, Tensor< 1, dim > > shape_gradients
Definition: fe_poly.h:420
FE_Poly(const PolynomialType &poly_space, const FiniteElementData< dim > &fe_data, const std::vector< bool > &restriction_is_additive_flags, const std::vector< ComponentMask > &nonzero_components)
unsigned int size() const
Third derivatives of shape functions.
UpdateFlags
Abstract base class for mapping classes.
Definition: dof_tools.h:57
Table< 2, Tensor< 3, dim > > shape_3rd_derivatives
Definition: fe_poly.h:442
unsigned int get_degree() const
Second derivatives of shape functions.
const unsigned int dofs_per_cell
Definition: fe_base.h:297
std::vector< unsigned int > get_poly_space_numbering_inverse() const
virtual Tensor< 3, dim > shape_3rd_derivative_component(const unsigned int i, const Point< dim > &p, const unsigned int component) const override
Table< 2, double > shape_values
Definition: fe_poly.h:409
std::vector< unsigned int > get_poly_space_numbering() const
virtual UpdateFlags requires_update_flags(const UpdateFlags update_flags) const override
virtual Tensor< 4, dim > shape_4th_derivative_component(const unsigned int i, const Point< dim > &p, const unsigned int component) const override
Shape function gradients.
virtual Tensor< 3, dim > shape_3rd_derivative(const unsigned int i, const Point< dim > &p) const override
const std::vector< ComponentMask > nonzero_components
Definition: fe.h:2595
virtual double shape_value_component(const unsigned int i, const Point< dim > &p, const unsigned int component) const override
PolynomialType poly_space
Definition: fe_poly.h:480
const std::vector< bool > restriction_is_additive_flags
Definition: fe.h:2586
virtual Tensor< 1, dim > shape_grad_component(const unsigned int i, const Point< dim > &p, const unsigned int component) const override