Reference documentation for deal.II version 8.5.1
fe_poly_tensor.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 2017 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 at
12 // the top level of the deal.II distribution.
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 #include <deal.II/lac/full_matrix.h>
22 #include <deal.II/fe/fe.h>
23 #include <deal.II/base/derivative_form.h>
24 #include <deal.II/base/quadrature.h>
25 #include <deal.II/base/thread_management.h>
26 
27 
28 DEAL_II_NAMESPACE_OPEN
29 
138 template <class PolynomialType, int dim, int spacedim=dim>
139 class FE_PolyTensor : public FiniteElement<dim,spacedim>
140 {
141 public:
148  FE_PolyTensor (const unsigned int degree,
149  const FiniteElementData<dim> &fe_data,
150  const std::vector<bool> &restriction_is_additive_flags,
151  const std::vector<ComponentMask> &nonzero_components);
152 
153  // for documentation, see the FiniteElement base class
154  virtual
156  requires_update_flags (const UpdateFlags update_flags) const;
157 
164  virtual double shape_value (const unsigned int i,
165  const Point<dim> &p) const;
166 
167  // documentation inherited from the base class
168  virtual double shape_value_component (const unsigned int i,
169  const Point<dim> &p,
170  const unsigned int component) const;
171 
178  virtual Tensor<1,dim> shape_grad (const unsigned int i,
179  const Point<dim> &p) const;
180 
181  // documentation inherited from the base class
182  virtual Tensor<1,dim> shape_grad_component (const unsigned int i,
183  const Point<dim> &p,
184  const unsigned int component) const;
185 
192  virtual Tensor<2,dim> shape_grad_grad (const unsigned int i,
193  const Point<dim> &p) const;
194 
195  // documentation inherited from the base class
196  virtual Tensor<2,dim> shape_grad_grad_component (const unsigned int i,
197  const Point<dim> &p,
198  const unsigned int component) const;
199 
200 protected:
206 
207 
208  /* NOTE: The following function has its definition inlined into the class declaration
209  because we otherwise run into a compiler error with MS Visual Studio. */
210  virtual
212  get_data(const UpdateFlags update_flags,
213  const Mapping<dim,spacedim> &/*mapping*/,
214  const Quadrature<dim> &quadrature,
216  {
217  // generate a new data object and
218  // initialize some fields
219  InternalData *data = new InternalData;
220  data->update_each = requires_update_flags(update_flags);
221 
222  const unsigned int n_q_points = quadrature.size();
223 
224  // some scratch arrays
225  std::vector<Tensor<1,dim> > values(0);
226  std::vector<Tensor<2,dim> > grads(0);
227  std::vector<Tensor<3,dim> > grad_grads(0);
228  std::vector<Tensor<4,dim> > third_derivatives(0);
229  std::vector<Tensor<5,dim> > fourth_derivatives(0);
230 
231  if (update_flags & (update_values | update_gradients | update_hessians) )
232  data->sign_change.resize (this->dofs_per_cell);
233 
234  // initialize fields only if really
235  // necessary. otherwise, don't
236  // allocate memory
237  if (update_flags & update_values)
238  {
239  values.resize (this->dofs_per_cell);
240  data->shape_values.reinit (this->dofs_per_cell, n_q_points);
241  if (mapping_type != mapping_none)
242  data->transformed_shape_values.resize (n_q_points);
243  }
244 
245  if (update_flags & update_gradients)
246  {
247  grads.resize (this->dofs_per_cell);
248  data->shape_grads.reinit (this->dofs_per_cell, n_q_points);
249  data->transformed_shape_grads.resize (n_q_points);
250 
252  ||
254  ||
256  ||
258  data->untransformed_shape_grads.resize(n_q_points);
259  }
260 
261  if (update_flags & update_hessians)
262  {
263  grad_grads.resize (this->dofs_per_cell);
264  data->shape_grad_grads.reinit (this->dofs_per_cell, n_q_points);
265  data->transformed_shape_hessians.resize (n_q_points);
266  if ( mapping_type != mapping_none )
267  data->untransformed_shape_hessian_tensors.resize(n_q_points);
268  }
269 
270  // Compute shape function values
271  // and derivatives and hessians on
272  // the reference cell.
273  // Make sure, that for the
274  // node values N_i holds
275  // N_i(v_j)=\delta_ij for all basis
276  // functions v_j
277  if (update_flags & (update_values | update_gradients))
278  for (unsigned int k=0; k<n_q_points; ++k)
279  {
280  poly_space.compute(quadrature.point(k),
281  values, grads, grad_grads,
282  third_derivatives,
283  fourth_derivatives);
284 
285  if (update_flags & update_values)
286  {
287  if (inverse_node_matrix.n_cols() == 0)
288  for (unsigned int i=0; i<this->dofs_per_cell; ++i)
289  data->shape_values[i][k] = values[i];
290  else
291  for (unsigned int i=0; i<this->dofs_per_cell; ++i)
292  {
293  Tensor<1,dim> add_values;
294  for (unsigned int j=0; j<this->dofs_per_cell; ++j)
295  add_values += inverse_node_matrix(j,i) * values[j];
296  data->shape_values[i][k] = add_values;
297  }
298  }
299 
300  if (update_flags & update_gradients)
301  {
302  if (inverse_node_matrix.n_cols() == 0)
303  for (unsigned int i=0; i<this->dofs_per_cell; ++i)
304  data->shape_grads[i][k] = grads[i];
305  else
306  for (unsigned int i=0; i<this->dofs_per_cell; ++i)
307  {
308  Tensor<2,dim> add_grads;
309  for (unsigned int j=0; j<this->dofs_per_cell; ++j)
310  add_grads += inverse_node_matrix(j,i) * grads[j];
311  data->shape_grads[i][k] = add_grads;
312  }
313  }
314 
315  if (update_flags & update_hessians)
316  {
317  if (inverse_node_matrix.n_cols() == 0)
318  for (unsigned int i=0; i<this->dofs_per_cell; ++i)
319  data->shape_grad_grads[i][k] = grad_grads[i];
320  else
321  for (unsigned int i=0; i<this->dofs_per_cell; ++i)
322  {
323  Tensor<3,dim> add_grad_grads;
324  for (unsigned int j=0; j<this->dofs_per_cell; ++j)
325  add_grad_grads += inverse_node_matrix(j,i) * grad_grads[j];
326  data->shape_grad_grads[i][k] = add_grad_grads;
327  }
328  }
329 
330  }
331  return data;
332  }
333 
334  virtual
335  void
336  fill_fe_values (const typename Triangulation<dim,spacedim>::cell_iterator &cell,
337  const CellSimilarity::Similarity cell_similarity,
338  const Quadrature<dim> &quadrature,
339  const Mapping<dim,spacedim> &mapping,
340  const typename Mapping<dim,spacedim>::InternalDataBase &mapping_internal,
341  const ::internal::FEValues::MappingRelatedData<dim, spacedim> &mapping_data,
342  const typename FiniteElement<dim,spacedim>::InternalDataBase &fe_internal,
344 
345  virtual
346  void
347  fill_fe_face_values (const typename Triangulation<dim,spacedim>::cell_iterator &cell,
348  const unsigned int face_no,
349  const Quadrature<dim-1> &quadrature,
350  const Mapping<dim,spacedim> &mapping,
351  const typename Mapping<dim,spacedim>::InternalDataBase &mapping_internal,
352  const ::internal::FEValues::MappingRelatedData<dim, spacedim> &mapping_data,
353  const typename FiniteElement<dim,spacedim>::InternalDataBase &fe_internal,
355 
356  virtual
357  void
358  fill_fe_subface_values (const typename Triangulation<dim,spacedim>::cell_iterator &cell,
359  const unsigned int face_no,
360  const unsigned int sub_no,
361  const Quadrature<dim-1> &quadrature,
362  const Mapping<dim,spacedim> &mapping,
363  const typename Mapping<dim,spacedim>::InternalDataBase &mapping_internal,
364  const ::internal::FEValues::MappingRelatedData<dim, spacedim> &mapping_data,
365  const typename FiniteElement<dim,spacedim>::InternalDataBase &fe_internal,
367 
377  class InternalData : public FiniteElement<dim,spacedim>::InternalDataBase
378  {
379  public:
385 
392 
399 
403  mutable std::vector<double> sign_change;
404  mutable std::vector<Tensor<1, spacedim> > transformed_shape_values;
405  // for shape_gradient computations
406  mutable std::vector<Tensor<2, spacedim > > transformed_shape_grads;
407  mutable std::vector<Tensor<2, dim > > untransformed_shape_grads;
408  // for shape_hessian computations
409  mutable std::vector<Tensor<3, spacedim > > transformed_shape_hessians;
410  mutable std::vector<Tensor<3, dim > > untransformed_shape_hessian_tensors;
411  };
412 
413 
414 
419  PolynomialType poly_space;
420 
433 
438 
445 
449  mutable std::vector<Tensor<1,dim> > cached_values;
450 
454  mutable std::vector<Tensor<2,dim> > cached_grads;
455 
460  mutable std::vector<Tensor<3,dim> > cached_grad_grads;
461 };
462 
463 DEAL_II_NAMESPACE_CLOSE
464 
465 #endif
Shape function values.
std::vector< Tensor< 2, dim > > cached_grads
Threads::Mutex cache_mutex
Point< dim > cached_point
virtual Tensor< 1, dim > shape_grad_component(const unsigned int i, const Point< dim > &p, const unsigned int component) const
virtual Tensor< 1, dim > shape_grad(const unsigned int i, const Point< dim > &p) const
MappingType
Definition: mapping.h:50
MappingType mapping_type
const unsigned int degree
Definition: fe_base.h:311
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)
const Point< dim > & point(const unsigned int i) const
virtual FiniteElement< dim, spacedim >::InternalDataBase * get_data(const UpdateFlags update_flags, const Mapping< dim, spacedim > &, const Quadrature< dim > &quadrature, ::internal::FEValues::FiniteElementRelatedData< dim, spacedim > &) const
virtual Tensor< 2, dim > shape_grad_grad_component(const unsigned int i, const Point< dim > &p, const unsigned int component) const
virtual double shape_value(const unsigned int i, const Point< dim > &p) const
PolynomialType poly_space
Table< 2, Tensor< 1, dim > > shape_values
virtual UpdateFlags requires_update_flags(const UpdateFlags update_flags) const
UpdateFlags
Abstract base class for mapping classes.
Definition: dof_tools.h:46
Table< 2, DerivativeForm< 2, dim, spacedim > > shape_grad_grads
std::vector< double > sign_change
Second derivatives of shape functions.
unsigned int size() const
const unsigned int dofs_per_cell
Definition: fe_base.h:295
std::vector< Tensor< 1, dim > > cached_values
virtual Tensor< 2, dim > shape_grad_grad(const unsigned int i, const Point< dim > &p) const
std::vector< Tensor< 3, dim > > cached_grad_grads
Shape function gradients.
const std::vector< ComponentMask > nonzero_components
Definition: fe.h:2355
virtual double shape_value_component(const unsigned int i, const Point< dim > &p, const unsigned int component) const
Definition: table.h:33
FullMatrix< double > inverse_node_matrix
Table< 2, DerivativeForm< 1, dim, spacedim > > shape_grads
const std::vector< bool > restriction_is_additive_flags
Definition: fe.h:2346
UpdateFlags update_each
Definition: fe.h:638