Reference documentation for deal.II version 9.2.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
function.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2020 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_function_h
17 #define dealii_function_h
18 
19 
20 #include <deal.II/base/config.h>
21 
24 #include <deal.II/base/point.h>
27 #include <deal.II/base/tensor.h>
28 
29 #include <functional>
30 #include <vector>
31 
33 
34 // Forward declarations
35 #ifndef DOXYGEN
36 template <typename number>
37 class Vector;
38 template <int rank, int dim, typename Number>
39 class TensorFunction;
40 #endif
41 
150 template <int dim, typename RangeNumberType = double>
151 class Function : public FunctionTime<
152  typename numbers::NumberTraits<RangeNumberType>::real_type>,
153  public Subscriptor
154 {
155 public:
160  static const unsigned int dimension = dim;
161 
165  const unsigned int n_components;
166 
170  using time_type = typename FunctionTime<
172 
178  Function(const unsigned int n_components = 1,
179  const time_type initial_time = 0.0);
180 
184  Function(const Function &f) = default;
185 
207  virtual ~Function() override = 0;
208 
215  Function &
216  operator=(const Function &f);
217 
224  virtual RangeNumberType
225  value(const Point<dim> &p, const unsigned int component = 0) const;
226 
234  virtual void
235  vector_value(const Point<dim> &p, Vector<RangeNumberType> &values) const;
236 
246  virtual void
247  value_list(const std::vector<Point<dim>> &points,
248  std::vector<RangeNumberType> & values,
249  const unsigned int component = 0) const;
250 
261  virtual void
262  vector_value_list(const std::vector<Point<dim>> & points,
263  std::vector<Vector<RangeNumberType>> &values) const;
264 
273  virtual void
274  vector_values(const std::vector<Point<dim>> & points,
275  std::vector<std::vector<RangeNumberType>> &values) const;
276 
282  gradient(const Point<dim> &p, const unsigned int component = 0) const;
283 
287  virtual void
289  const Point<dim> & p,
290  std::vector<Tensor<1, dim, RangeNumberType>> &gradients) const;
291 
298  virtual void
299  gradient_list(const std::vector<Point<dim>> & points,
300  std::vector<Tensor<1, dim, RangeNumberType>> &gradients,
301  const unsigned int component = 0) const;
302 
311  virtual void
313  const std::vector<Point<dim>> & points,
314  std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients) const;
315 
325  virtual void
327  const std::vector<Point<dim>> & points,
328  std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients) const;
329 
333  virtual RangeNumberType
334  laplacian(const Point<dim> &p, const unsigned int component = 0) const;
335 
340  virtual void
341  vector_laplacian(const Point<dim> &p, Vector<RangeNumberType> &values) const;
342 
346  virtual void
347  laplacian_list(const std::vector<Point<dim>> &points,
348  std::vector<RangeNumberType> & values,
349  const unsigned int component = 0) const;
350 
354  virtual void
355  vector_laplacian_list(const std::vector<Point<dim>> & points,
356  std::vector<Vector<RangeNumberType>> &values) const;
357 
363  hessian(const Point<dim> &p, const unsigned int component = 0) const;
364 
369  virtual void
371  const Point<dim> & p,
372  std::vector<SymmetricTensor<2, dim, RangeNumberType>> &values) const;
373 
377  virtual void
378  hessian_list(const std::vector<Point<dim>> & points,
379  std::vector<SymmetricTensor<2, dim, RangeNumberType>> &values,
380  const unsigned int component = 0) const;
381 
385  virtual void
387  const std::vector<Point<dim>> & points,
388  std::vector<std::vector<SymmetricTensor<2, dim, RangeNumberType>>> &values)
389  const;
390 
391 
397  std::size_t
398  memory_consumption() const;
399 };
400 
401 
402 namespace Functions
403 {
411  template <int dim, typename RangeNumberType = double>
412  class ConstantFunction : public Function<dim, RangeNumberType>
413  {
414  public:
419  ConstantFunction(const RangeNumberType value,
420  const unsigned int n_components = 1);
421 
427  ConstantFunction(const std::vector<RangeNumberType> &values);
428 
434  ConstantFunction(const Vector<RangeNumberType> &values);
435 
440  ConstantFunction(const RangeNumberType *begin_ptr,
441  const unsigned int n_components);
442 
443  virtual RangeNumberType
444  value(const Point<dim> &p, const unsigned int component = 0) const override;
445 
446  virtual void
447  vector_value(const Point<dim> & p,
448  Vector<RangeNumberType> &return_value) const override;
449 
450  virtual void
451  value_list(const std::vector<Point<dim>> &points,
452  std::vector<RangeNumberType> & return_values,
453  const unsigned int component = 0) const override;
454 
455  virtual void
457  const std::vector<Point<dim>> & points,
458  std::vector<Vector<RangeNumberType>> &return_values) const override;
459 
461  gradient(const Point<dim> & p,
462  const unsigned int component = 0) const override;
463 
464  virtual void
466  const Point<dim> & p,
467  std::vector<Tensor<1, dim, RangeNumberType>> &gradients) const override;
468 
469  virtual void
470  gradient_list(const std::vector<Point<dim>> & points,
471  std::vector<Tensor<1, dim, RangeNumberType>> &gradients,
472  const unsigned int component = 0) const override;
473 
474  virtual void
476  const std::vector<Point<dim>> & points,
477  std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients)
478  const override;
479 
481  hessian(const Point<dim> & point,
482  const unsigned int component = 0) const override;
483 
484  virtual RangeNumberType
485  laplacian(const Point<dim> & point,
486  const unsigned int component = 0) const override;
487 
488  std::size_t
489  memory_consumption() const;
490 
491  protected:
495  std::vector<RangeNumberType> function_value_vector;
496  };
497 
498 
499 
512  template <int dim, typename RangeNumberType = double>
513  class ZeroFunction : public ConstantFunction<dim, RangeNumberType>
514  {
515  public:
519  ZeroFunction(const unsigned int n_components = 1);
520  };
521 
522 } // namespace Functions
523 
530 template <int dim, typename RangeNumberType = double>
533 
539 template <int dim, typename RangeNumberType = double>
542 
543 
544 
559 template <int dim, typename RangeNumberType = double>
560 class ComponentSelectFunction : public ConstantFunction<dim, RangeNumberType>
561 {
562 public:
568  ComponentSelectFunction(const unsigned int selected,
569  const RangeNumberType value,
570  const unsigned int n_components);
571 
576  ComponentSelectFunction(const unsigned int selected,
577  const unsigned int n_components);
578 
586  ComponentSelectFunction(const std::pair<unsigned int, unsigned int> &selected,
587  const unsigned int n_components);
588 
589 
603  virtual void
606 
610  virtual void
611  vector_value(const Point<dim> & p,
612  Vector<RangeNumberType> &return_value) const override;
613 
620  virtual void
622  const std::vector<Point<dim>> & points,
623  std::vector<Vector<RangeNumberType>> &values) const override;
624 
630  std::size_t
631  memory_consumption() const;
632 
633 protected:
637  const std::pair<unsigned int, unsigned int> selected_components;
638 };
639 
640 
641 
726 template <int dim, typename RangeNumberType = double>
727 class ScalarFunctionFromFunctionObject : public Function<dim, RangeNumberType>
728 {
729 public:
736  const std::function<RangeNumberType(const Point<dim> &)> &function_object);
737 
742  virtual RangeNumberType
743  value(const Point<dim> &p, const unsigned int component = 0) const override;
744 
745 private:
750  const std::function<RangeNumberType(const Point<dim> &)> function_object;
751 };
752 
753 
754 
794 template <int dim, typename RangeNumberType = double>
796  : public Function<dim, RangeNumberType>
797 {
798 public:
812  const std::function<RangeNumberType(const Point<dim> &)> &function_object,
813  const unsigned int selected_component,
814  const unsigned int n_components);
815 
820  virtual RangeNumberType
821  value(const Point<dim> &p, const unsigned int component = 0) const override;
822 
828  virtual void
829  vector_value(const Point<dim> & p,
830  Vector<RangeNumberType> &values) const override;
831 
832 private:
837  const std::function<RangeNumberType(const Point<dim> &)> function_object;
838 
843  const unsigned int selected_component;
844 };
845 
846 
884 template <int dim, typename RangeNumberType = double>
885 class FunctionFromFunctionObjects : public Function<dim, RangeNumberType>
886 {
887 public:
896  explicit FunctionFromFunctionObjects(const unsigned int n_components = 1,
897  const double initial_time = 0);
898 
908  const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
909  & values,
910  const double initial_time = 0.0);
911 
921  const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
922  &values,
923  const std::vector<
924  std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
925  & gradients,
926  const double initial_time = 0.0);
927 
928 
935  virtual RangeNumberType
936  value(const Point<dim> &p, const unsigned int component = 0) const override;
937 
945  gradient(const Point<dim> & p,
946  const unsigned int component = 0) const override;
947 
953  void
955  const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
956  &values);
957 
963  void
965  const std::vector<
966  std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
967  &gradients);
968 
969 private:
973  std::vector<std::function<RangeNumberType(const Point<dim> &)>>
975 
979  std::vector<
980  std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
982 };
983 
984 
1021 template <int dim, typename RangeNumberType = double>
1022 class VectorFunctionFromTensorFunction : public Function<dim, RangeNumberType>
1023 {
1024 public:
1043  const unsigned int selected_component = 0,
1044  const unsigned int n_components = dim);
1045 
1050  virtual ~VectorFunctionFromTensorFunction() override = default;
1051 
1055  virtual RangeNumberType
1056  value(const Point<dim> &p, const unsigned int component = 0) const override;
1057 
1063  virtual void
1064  vector_value(const Point<dim> & p,
1065  Vector<RangeNumberType> &values) const override;
1066 
1074  virtual void
1076  const std::vector<Point<dim>> & points,
1077  std::vector<Vector<RangeNumberType>> &value_list) const override;
1078 
1079 private:
1085 
1092  const unsigned int selected_component;
1093 };
1094 
1095 
1096 #ifndef DOXYGEN
1097 // icc 2018 complains about an undefined reference
1098 // if we put this in the templates.h file
1099 //
1100 // The destructor is pure virtual so we can't default it
1101 // in the declaration.
1102 template <int dim, typename RangeNumberType>
1104 #endif
1105 
1106 
1108 
1109 #endif
Function::vector_value_list
virtual void vector_value_list(const std::vector< Point< dim >> &points, std::vector< Vector< RangeNumberType >> &values) const
FunctionFromFunctionObjects::gradient
virtual Tensor< 1, dim, RangeNumberType > gradient(const Point< dim > &p, const unsigned int component=0) const override
VectorFunctionFromScalarFunctionObject::function_object
const std::function< RangeNumberType(const Point< dim > &)> function_object
Definition: function.h:837
Functions::ConstantFunction::gradient_list
virtual void gradient_list(const std::vector< Point< dim >> &points, std::vector< Tensor< 1, dim, RangeNumberType >> &gradients, const unsigned int component=0) const override
Functions
Definition: flow_function.h:28
LinearAlgebraDealII::Vector
Vector< double > Vector
Definition: generic_linear_algebra.h:43
Functions::ConstantFunction::vector_gradient
virtual void vector_gradient(const Point< dim > &p, std::vector< Tensor< 1, dim, RangeNumberType >> &gradients) const override
Function::vector_laplacian
virtual void vector_laplacian(const Point< dim > &p, Vector< RangeNumberType > &values) const
Function::operator=
Function & operator=(const Function &f)
FunctionFromFunctionObjects::set_function_gradients
void set_function_gradients(const std::vector< std::function< Tensor< 1, dim, RangeNumberType >(const Point< dim > &)>> &gradients)
SymmetricTensor
Definition: symmetric_tensor.h:611
ScalarFunctionFromFunctionObject
Definition: function.h:727
function_time.h
VectorFunctionFromTensorFunction::VectorFunctionFromTensorFunction
VectorFunctionFromTensorFunction(const TensorFunction< 1, dim, RangeNumberType > &tensor_function, const unsigned int selected_component=0, const unsigned int n_components=dim)
FunctionFromFunctionObjects::function_values
std::vector< std::function< RangeNumberType(const Point< dim > &)> > function_values
Definition: function.h:974
FunctionFromFunctionObjects::value
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
Functions::ConstantFunction::vector_gradient_list
virtual void vector_gradient_list(const std::vector< Point< dim >> &points, std::vector< std::vector< Tensor< 1, dim, RangeNumberType >>> &gradients) const override
VectorFunctionFromScalarFunctionObject::value
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
VectorFunctionFromScalarFunctionObject::vector_value
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const override
Function::vector_hessian
virtual void vector_hessian(const Point< dim > &p, std::vector< SymmetricTensor< 2, dim, RangeNumberType >> &values) const
Function::Function
Function(const unsigned int n_components=1, const time_type initial_time=0.0)
FunctionFromFunctionObjects
Definition: function.h:885
Function::vector_gradient
virtual void vector_gradient(const Point< dim > &p, std::vector< Tensor< 1, dim, RangeNumberType >> &gradients) const
Functions::ConstantFunction::value
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
ScalarFunctionFromFunctionObject::value
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
ComponentSelectFunction::vector_value
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &return_value) const override
Functions::ConstantFunction
Definition: function.h:412
Function::n_components
const unsigned int n_components
Definition: function.h:165
VectorFunctionFromTensorFunction::~VectorFunctionFromTensorFunction
virtual ~VectorFunctionFromTensorFunction() override=default
ScalarFunctionFromFunctionObject::function_object
const std::function< RangeNumberType(const Point< dim > &)> function_object
Definition: function.h:750
Function::value_list
virtual void value_list(const std::vector< Point< dim >> &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const
VectorFunctionFromTensorFunction::value
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
Function::hessian
virtual SymmetricTensor< 2, dim, RangeNumberType > hessian(const Point< dim > &p, const unsigned int component=0) const
Function::gradient
virtual Tensor< 1, dim, RangeNumberType > gradient(const Point< dim > &p, const unsigned int component=0) const
Functions::ConstantFunction::vector_value_list
virtual void vector_value_list(const std::vector< Point< dim >> &points, std::vector< Vector< RangeNumberType >> &return_values) const override
Function::laplacian_list
virtual void laplacian_list(const std::vector< Point< dim >> &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const
OpenCASCADE::point
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
Definition: utilities.cc:188
Subscriptor
Definition: subscriptor.h:62
VectorFunctionFromTensorFunction::vector_value_list
virtual void vector_value_list(const std::vector< Point< dim >> &points, std::vector< Vector< RangeNumberType >> &value_list) const override
FunctionFromFunctionObjects::FunctionFromFunctionObjects
FunctionFromFunctionObjects(const unsigned int n_components=1, const double initial_time=0)
FunctionTime
Definition: function_time.h:73
Functions::ConstantFunction::laplacian
virtual RangeNumberType laplacian(const Point< dim > &point, const unsigned int component=0) const override
Function::vector_laplacian_list
virtual void vector_laplacian_list(const std::vector< Point< dim >> &points, std::vector< Vector< RangeNumberType >> &values) const
tensor.h
Function< dim, double >::time_type
typename FunctionTime< typename numbers::NumberTraits< double >::real_type >::time_type time_type
Definition: function.h:171
Functions::ConstantFunction::ConstantFunction
ConstantFunction(const RangeNumberType value, const unsigned int n_components=1)
VectorFunctionFromTensorFunction::vector_value
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const override
Function::memory_consumption
std::size_t memory_consumption() const
subscriptor.h
Tensor
Definition: tensor.h:450
ComponentSelectFunction
Definition: function.h:560
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
Function::gradient_list
virtual void gradient_list(const std::vector< Point< dim >> &points, std::vector< Tensor< 1, dim, RangeNumberType >> &gradients, const unsigned int component=0) const
VectorFunctionFromTensorFunction::tensor_function
const TensorFunction< 1, dim, RangeNumberType > & tensor_function
Definition: function.h:1084
DEAL_II_DEPRECATED
#define DEAL_II_DEPRECATED
Definition: config.h:98
numbers::NumberTraits::real_type
number real_type
Definition: numbers.h:437
ComponentSelectFunction::selected_components
const std::pair< unsigned int, unsigned int > selected_components
Definition: function.h:637
FunctionFromFunctionObjects::function_gradients
std::vector< std::function< Tensor< 1, dim, RangeNumberType >const Point< dim > &)> > function_gradients
Definition: function.h:981
Function::value
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
Functions::ConstantFunction::gradient
virtual Tensor< 1, dim, RangeNumberType > gradient(const Point< dim > &p, const unsigned int component=0) const override
ComponentSelectFunction::ComponentSelectFunction
ComponentSelectFunction(const unsigned int selected, const RangeNumberType value, const unsigned int n_components)
exceptions.h
ComponentSelectFunction::vector_value_list
virtual void vector_value_list(const std::vector< Point< dim >> &points, std::vector< Vector< RangeNumberType >> &values) const override
TensorFunction
Definition: tensor_function.h:57
Function::vector_hessian_list
virtual void vector_hessian_list(const std::vector< Point< dim >> &points, std::vector< std::vector< SymmetricTensor< 2, dim, RangeNumberType >>> &values) const
symmetric_tensor.h
ComponentSelectFunction::memory_consumption
std::size_t memory_consumption() const
Functions::ConstantFunction::memory_consumption
std::size_t memory_consumption() const
VectorFunctionFromTensorFunction::selected_component
const unsigned int selected_component
Definition: function.h:1092
ScalarFunctionFromFunctionObject::ScalarFunctionFromFunctionObject
ScalarFunctionFromFunctionObject(const std::function< RangeNumberType(const Point< dim > &)> &function_object)
Function::laplacian
virtual RangeNumberType laplacian(const Point< dim > &p, const unsigned int component=0) const
Function::vector_value
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const
Point< dim >
Functions::ZeroFunction
Definition: function.h:513
VectorFunctionFromScalarFunctionObject::VectorFunctionFromScalarFunctionObject
VectorFunctionFromScalarFunctionObject(const std::function< RangeNumberType(const Point< dim > &)> &function_object, const unsigned int selected_component, const unsigned int n_components)
Functions::ConstantFunction::function_value_vector
std::vector< RangeNumberType > function_value_vector
Definition: function.h:495
config.h
Function
Definition: function.h:151
FunctionFromFunctionObjects::set_function_values
void set_function_values(const std::vector< std::function< RangeNumberType(const Point< dim > &)>> &values)
VectorFunctionFromScalarFunctionObject::selected_component
const unsigned int selected_component
Definition: function.h:843
Function::vector_values
virtual void vector_values(const std::vector< Point< dim >> &points, std::vector< std::vector< RangeNumberType >> &values) const
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
ComponentSelectFunction::substitute_function_value_with
virtual void substitute_function_value_with(const Functions::ConstantFunction< dim, RangeNumberType > &f)
Functions::ConstantFunction::value_list
virtual void value_list(const std::vector< Point< dim >> &points, std::vector< RangeNumberType > &return_values, const unsigned int component=0) const override
Function::vector_gradient_list
virtual void vector_gradient_list(const std::vector< Point< dim >> &points, std::vector< std::vector< Tensor< 1, dim, RangeNumberType >>> &gradients) const
Function::vector_gradients
virtual void vector_gradients(const std::vector< Point< dim >> &points, std::vector< std::vector< Tensor< 1, dim, RangeNumberType >>> &gradients) const
Functions::ZeroFunction::ZeroFunction
ZeroFunction(const unsigned int n_components=1)
Functions::ConstantFunction::vector_value
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &return_value) const override
Function::dimension
static const unsigned int dimension
Definition: function.h:160
Function::~Function
virtual ~Function() override=0
VectorFunctionFromScalarFunctionObject
Definition: function.h:795
VectorFunctionFromTensorFunction
Definition: function.h:1022
Functions::ConstantFunction::hessian
virtual SymmetricTensor< 2, dim, RangeNumberType > hessian(const Point< dim > &point, const unsigned int component=0) const override
Function::hessian_list
virtual void hessian_list(const std::vector< Point< dim >> &points, std::vector< SymmetricTensor< 2, dim, RangeNumberType >> &values, const unsigned int component=0) const
point.h