Reference documentation for deal.II version 9.1.0-pre
fe_poly_tensor.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 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_tensor_h
17 #define dealii_fe_poly_tensor_h
18 
19 
20 #include <deal.II/base/config.h>
21 
22 #include <deal.II/base/derivative_form.h>
23 #include <deal.II/base/quadrature.h>
24 #include <deal.II/base/std_cxx14/memory.h>
25 #include <deal.II/base/thread_management.h>
26 
27 #include <deal.II/fe/fe.h>
28 
29 #include <deal.II/lac/full_matrix.h>
30 
31 
32 DEAL_II_NAMESPACE_OPEN
33 
143 template <class PolynomialType, int dim, int spacedim = dim>
144 class FE_PolyTensor : public FiniteElement<dim, spacedim>
145 {
146 public:
153  FE_PolyTensor(const unsigned int degree,
154  const FiniteElementData<dim> & fe_data,
155  const std::vector<bool> & restriction_is_additive_flags,
156  const std::vector<ComponentMask> &nonzero_components);
157 
158  // for documentation, see the FiniteElement base class
159  virtual UpdateFlags
160  requires_update_flags(const UpdateFlags update_flags) const override;
161 
168  virtual double
169  shape_value(const unsigned int i, const Point<dim> &p) const override;
170 
171  // documentation inherited from the base class
172  virtual double
173  shape_value_component(const unsigned int i,
174  const Point<dim> & p,
175  const unsigned int component) const override;
176 
183  virtual Tensor<1, dim>
184  shape_grad(const unsigned int i, const Point<dim> &p) const override;
185 
186  // documentation inherited from the base class
187  virtual Tensor<1, dim>
188  shape_grad_component(const unsigned int i,
189  const Point<dim> & p,
190  const unsigned int component) const override;
191 
198  virtual Tensor<2, dim>
199  shape_grad_grad(const unsigned int i, const Point<dim> &p) const override;
200 
201  // documentation inherited from the base class
202  virtual Tensor<2, dim>
203  shape_grad_grad_component(const unsigned int i,
204  const Point<dim> & p,
205  const unsigned int component) const override;
206 
207 protected:
213 
214 
215  /* NOTE: The following function has its definition inlined into the class
216  declaration because we otherwise run into a compiler error with MS Visual
217  Studio. */
218  virtual std::unique_ptr<
221  const UpdateFlags update_flags,
222  const Mapping<dim, spacedim> & /*mapping*/,
223  const Quadrature<dim> &quadrature,
225  spacedim>
226  & /*output_data*/) const override
227  {
228  // generate a new data object and
229  // initialize some fields
230  auto data = std_cxx14::make_unique<InternalData>();
231  data->update_each = requires_update_flags(update_flags);
232 
233  const unsigned int n_q_points = quadrature.size();
234 
235  // some scratch arrays
236  std::vector<Tensor<1, dim>> values(0);
237  std::vector<Tensor<2, dim>> grads(0);
238  std::vector<Tensor<3, dim>> grad_grads(0);
239  std::vector<Tensor<4, dim>> third_derivatives(0);
240  std::vector<Tensor<5, dim>> fourth_derivatives(0);
241 
242  if (update_flags & (update_values | update_gradients | update_hessians))
243  data->sign_change.resize(this->dofs_per_cell);
244 
245  // initialize fields only if really
246  // necessary. otherwise, don't
247  // allocate memory
248  if (update_flags & update_values)
249  {
250  values.resize(this->dofs_per_cell);
251  data->shape_values.reinit(this->dofs_per_cell, n_q_points);
252  if (mapping_type != mapping_none)
253  data->transformed_shape_values.resize(n_q_points);
254  }
255 
256  if (update_flags & update_gradients)
257  {
258  grads.resize(this->dofs_per_cell);
259  data->shape_grads.reinit(this->dofs_per_cell, n_q_points);
260  data->transformed_shape_grads.resize(n_q_points);
261 
262  if ((mapping_type == mapping_raviart_thomas) ||
263  (mapping_type == mapping_piola) ||
264  (mapping_type == mapping_nedelec) ||
265  (mapping_type == mapping_contravariant))
266  data->untransformed_shape_grads.resize(n_q_points);
267  }
268 
269  if (update_flags & update_hessians)
270  {
271  grad_grads.resize(this->dofs_per_cell);
272  data->shape_grad_grads.reinit(this->dofs_per_cell, n_q_points);
273  data->transformed_shape_hessians.resize(n_q_points);
274  if (mapping_type != mapping_none)
275  data->untransformed_shape_hessian_tensors.resize(n_q_points);
276  }
277 
278  // Compute shape function values
279  // and derivatives and hessians on
280  // the reference cell.
281  // Make sure, that for the
282  // node values N_i holds
283  // N_i(v_j)=\delta_ij for all basis
284  // functions v_j
285  if (update_flags & (update_values | update_gradients))
286  for (unsigned int k = 0; k < n_q_points; ++k)
287  {
288  poly_space.compute(quadrature.point(k),
289  values,
290  grads,
291  grad_grads,
292  third_derivatives,
293  fourth_derivatives);
294 
295  if (update_flags & update_values)
296  {
297  if (inverse_node_matrix.n_cols() == 0)
298  for (unsigned int i = 0; i < this->dofs_per_cell; ++i)
299  data->shape_values[i][k] = values[i];
300  else
301  for (unsigned int i = 0; i < this->dofs_per_cell; ++i)
302  {
303  Tensor<1, dim> add_values;
304  for (unsigned int j = 0; j < this->dofs_per_cell; ++j)
305  add_values += inverse_node_matrix(j, i) * values[j];
306  data->shape_values[i][k] = add_values;
307  }
308  }
309 
310  if (update_flags & update_gradients)
311  {
312  if (inverse_node_matrix.n_cols() == 0)
313  for (unsigned int i = 0; i < this->dofs_per_cell; ++i)
314  data->shape_grads[i][k] = grads[i];
315  else
316  for (unsigned int i = 0; i < this->dofs_per_cell; ++i)
317  {
318  Tensor<2, dim> add_grads;
319  for (unsigned int j = 0; j < this->dofs_per_cell; ++j)
320  add_grads += inverse_node_matrix(j, i) * grads[j];
321  data->shape_grads[i][k] = add_grads;
322  }
323  }
324 
325  if (update_flags & update_hessians)
326  {
327  if (inverse_node_matrix.n_cols() == 0)
328  for (unsigned int i = 0; i < this->dofs_per_cell; ++i)
329  data->shape_grad_grads[i][k] = grad_grads[i];
330  else
331  for (unsigned int i = 0; i < this->dofs_per_cell; ++i)
332  {
333  Tensor<3, dim> add_grad_grads;
334  for (unsigned int j = 0; j < this->dofs_per_cell; ++j)
335  add_grad_grads +=
336  inverse_node_matrix(j, i) * grad_grads[j];
337  data->shape_grad_grads[i][k] = add_grad_grads;
338  }
339  }
340  }
341  return std::move(data);
342  }
343 
344  virtual void
345  fill_fe_values(
346  const typename Triangulation<dim, spacedim>::cell_iterator &cell,
347  const CellSimilarity::Similarity cell_similarity,
348  const Quadrature<dim> & quadrature,
349  const Mapping<dim, spacedim> & mapping,
350  const typename Mapping<dim, spacedim>::InternalDataBase &mapping_internal,
351  const ::internal::FEValuesImplementation::MappingRelatedData<dim,
352  spacedim>
353  & mapping_data,
354  const typename FiniteElement<dim, spacedim>::InternalDataBase &fe_internal,
356  spacedim>
357  &output_data) const override;
358 
359  virtual void
360  fill_fe_face_values(
361  const typename Triangulation<dim, spacedim>::cell_iterator &cell,
362  const unsigned int face_no,
363  const Quadrature<dim - 1> & quadrature,
364  const Mapping<dim, spacedim> & mapping,
365  const typename Mapping<dim, spacedim>::InternalDataBase &mapping_internal,
366  const ::internal::FEValuesImplementation::MappingRelatedData<dim,
367  spacedim>
368  & mapping_data,
369  const typename FiniteElement<dim, spacedim>::InternalDataBase &fe_internal,
371  spacedim>
372  &output_data) const override;
373 
374  virtual void
375  fill_fe_subface_values(
376  const typename Triangulation<dim, spacedim>::cell_iterator &cell,
377  const unsigned int face_no,
378  const unsigned int sub_no,
379  const Quadrature<dim - 1> & quadrature,
380  const Mapping<dim, spacedim> & mapping,
381  const typename Mapping<dim, spacedim>::InternalDataBase &mapping_internal,
382  const ::internal::FEValuesImplementation::MappingRelatedData<dim,
383  spacedim>
384  & mapping_data,
385  const typename FiniteElement<dim, spacedim>::InternalDataBase &fe_internal,
387  spacedim>
388  &output_data) const override;
389 
399  class InternalData : public FiniteElement<dim, spacedim>::InternalDataBase
400  {
401  public:
407 
414 
421 
425  mutable std::vector<double> sign_change;
426  mutable std::vector<Tensor<1, spacedim>> transformed_shape_values;
427  // for shape_gradient computations
428  mutable std::vector<Tensor<2, spacedim>> transformed_shape_grads;
429  mutable std::vector<Tensor<2, dim>> untransformed_shape_grads;
430  // for shape_hessian computations
431  mutable std::vector<Tensor<3, spacedim>> transformed_shape_hessians;
432  mutable std::vector<Tensor<3, dim>> untransformed_shape_hessian_tensors;
433  };
434 
435 
436 
441  PolynomialType poly_space;
442 
455 
460 
467 
471  mutable std::vector<Tensor<1, dim>> cached_values;
472 
476  mutable std::vector<Tensor<2, dim>> cached_grads;
477 
482  mutable std::vector<Tensor<3, dim>> cached_grad_grads;
483 };
484 
485 DEAL_II_NAMESPACE_CLOSE
486 
487 #endif
Shape function values.
Threads::Mutex cache_mutex
Point< dim > cached_point
MappingType
Definition: mapping.h:61
MappingType mapping_type
const unsigned int degree
Definition: fe_base.h:313
FE_PolyTensor(const unsigned int degree, const FiniteElementData< dim > &fe_data, const std::vector< bool > &restriction_is_additive_flags, const std::vector< ComponentMask > &nonzero_components)
std::vector< Tensor< 1, dim > > cached_values
const Point< dim > & point(const unsigned int i) const
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 > &) const override
std::vector< Tensor< 2, dim > > cached_grads
PolynomialType poly_space
unsigned int size() const
virtual Tensor< 2, dim > shape_grad_grad_component(const unsigned int i, const Point< dim > &p, const unsigned int component) const override
virtual Tensor< 1, dim > shape_grad(const unsigned int i, const Point< dim > &p) const override
UpdateFlags
virtual Tensor< 1, dim > shape_grad_component(const unsigned int i, const Point< dim > &p, const unsigned int component) const override
virtual double shape_value_component(const unsigned int i, const Point< dim > &p, const unsigned int component) const override
Abstract base class for mapping classes.
Definition: dof_tools.h:57
virtual double shape_value(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
std::vector< double > sign_change
std::vector< Tensor< 3, dim > > cached_grad_grads
Second derivatives of shape functions.
virtual UpdateFlags requires_update_flags(const UpdateFlags update_flags) const override
const unsigned int dofs_per_cell
Definition: fe_base.h:297
Table< 2, Tensor< 1, dim > > shape_values
Shape function gradients.
const std::vector< ComponentMask > nonzero_components
Definition: fe.h:2595
Definition: table.h:37
Table< 2, DerivativeForm< 1, dim, spacedim > > shape_grads
FullMatrix< double > inverse_node_matrix
const std::vector< bool > restriction_is_additive_flags
Definition: fe.h:2586
Table< 2, DerivativeForm< 2, dim, spacedim > > shape_grad_grads