Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
function.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2019 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 
22 #include <deal.II/base/exceptions.h>
23 #include <deal.II/base/function_time.h>
24 #include <deal.II/base/point.h>
25 #include <deal.II/base/subscriptor.h>
27 #include <deal.II/base/tensor.h>
28 
29 #include <functional>
30 #include <vector>
31 
32 DEAL_II_NAMESPACE_OPEN
33 
34 
35 template <typename number>
36 class Vector;
37 template <int rank, int dim, typename Number>
39 
147 template <int dim, typename RangeNumberType = double>
148 class Function : public FunctionTime<
149  typename numbers::NumberTraits<RangeNumberType>::real_type>,
150  public Subscriptor
151 {
152 public:
157  static const unsigned int dimension = dim;
158 
162  const unsigned int n_components;
163 
167  using time_type = typename FunctionTime<
169 
175  Function(const unsigned int n_components = 1,
176  const time_type initial_time = 0.0);
177 
199  virtual ~Function() override = 0;
200 
207  Function &
208  operator=(const Function &f);
209 
216  virtual RangeNumberType
217  value(const Point<dim> &p, const unsigned int component = 0) const;
218 
226  virtual void
227  vector_value(const Point<dim> &p, Vector<RangeNumberType> &values) const;
228 
238  virtual void
239  value_list(const std::vector<Point<dim>> &points,
240  std::vector<RangeNumberType> & values,
241  const unsigned int component = 0) const;
242 
253  virtual void
254  vector_value_list(const std::vector<Point<dim>> & points,
255  std::vector<Vector<RangeNumberType>> &values) const;
256 
265  virtual void
266  vector_values(const std::vector<Point<dim>> & points,
267  std::vector<std::vector<RangeNumberType>> &values) const;
268 
274  gradient(const Point<dim> &p, const unsigned int component = 0) const;
275 
279  virtual void
281  const Point<dim> & p,
282  std::vector<Tensor<1, dim, RangeNumberType>> &gradients) const;
283 
290  virtual void
291  gradient_list(const std::vector<Point<dim>> & points,
292  std::vector<Tensor<1, dim, RangeNumberType>> &gradients,
293  const unsigned int component = 0) const;
294 
303  virtual void
305  const std::vector<Point<dim>> & points,
306  std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients) const;
307 
317  virtual void
319  const std::vector<Point<dim>> & points,
320  std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients) const;
321 
325  virtual RangeNumberType
326  laplacian(const Point<dim> &p, const unsigned int component = 0) const;
327 
332  virtual void
333  vector_laplacian(const Point<dim> &p, Vector<RangeNumberType> &values) const;
334 
338  virtual void
339  laplacian_list(const std::vector<Point<dim>> &points,
340  std::vector<RangeNumberType> & values,
341  const unsigned int component = 0) const;
342 
346  virtual void
347  vector_laplacian_list(const std::vector<Point<dim>> & points,
348  std::vector<Vector<RangeNumberType>> &values) const;
349 
355  hessian(const Point<dim> &p, const unsigned int component = 0) const;
356 
361  virtual void
363  const Point<dim> & p,
364  std::vector<SymmetricTensor<2, dim, RangeNumberType>> &values) const;
365 
369  virtual void
370  hessian_list(const std::vector<Point<dim>> & points,
371  std::vector<SymmetricTensor<2, dim, RangeNumberType>> &values,
372  const unsigned int component = 0) const;
373 
377  virtual void
379  const std::vector<Point<dim>> & points,
380  std::vector<std::vector<SymmetricTensor<2, dim, RangeNumberType>>> &values)
381  const;
382 
383 
389  std::size_t
390  memory_consumption() const;
391 };
392 
393 
394 namespace Functions
395 {
403  template <int dim, typename RangeNumberType = double>
404  class ConstantFunction : public Function<dim, RangeNumberType>
405  {
406  public:
411  ConstantFunction(const RangeNumberType value,
412  const unsigned int n_components = 1);
413 
419  ConstantFunction(const std::vector<RangeNumberType> &values);
420 
427 
432  ConstantFunction(const RangeNumberType *begin_ptr,
433  const unsigned int n_components);
434 
435  virtual RangeNumberType
436  value(const Point<dim> &p, const unsigned int component = 0) const override;
437 
438  virtual void
439  vector_value(const Point<dim> & p,
440  Vector<RangeNumberType> &return_value) const override;
441 
442  virtual void
443  value_list(const std::vector<Point<dim>> &points,
444  std::vector<RangeNumberType> & return_values,
445  const unsigned int component = 0) const override;
446 
447  virtual void
449  const std::vector<Point<dim>> & points,
450  std::vector<Vector<RangeNumberType>> &return_values) const override;
451 
453  gradient(const Point<dim> & p,
454  const unsigned int component = 0) const override;
455 
456  virtual void
458  const Point<dim> & p,
459  std::vector<Tensor<1, dim, RangeNumberType>> &gradients) const override;
460 
461  virtual void
462  gradient_list(const std::vector<Point<dim>> & points,
463  std::vector<Tensor<1, dim, RangeNumberType>> &gradients,
464  const unsigned int component = 0) const override;
465 
466  virtual void
468  const std::vector<Point<dim>> & points,
469  std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients)
470  const override;
471 
472  std::size_t
473  memory_consumption() const;
474 
475  protected:
479  std::vector<RangeNumberType> function_value_vector;
480  };
481 
482 
483 
496  template <int dim, typename RangeNumberType = double>
497  class ZeroFunction : public ConstantFunction<dim, RangeNumberType>
498  {
499  public:
503  ZeroFunction(const unsigned int n_components = 1);
504  };
505 
506 } // namespace Functions
507 
514 template <int dim, typename RangeNumberType = double>
515 using ConstantFunction DEAL_II_DEPRECATED =
517 
523 template <int dim, typename RangeNumberType = double>
524 using ZeroFunction DEAL_II_DEPRECATED =
526 
527 
528 
543 template <int dim, typename RangeNumberType = double>
544 class ComponentSelectFunction : public ConstantFunction<dim, RangeNumberType>
545 {
546 public:
552  ComponentSelectFunction(const unsigned int selected,
553  const RangeNumberType value,
554  const unsigned int n_components);
555 
560  ComponentSelectFunction(const unsigned int selected,
561  const unsigned int n_components);
562 
570  ComponentSelectFunction(const std::pair<unsigned int, unsigned int> &selected,
571  const unsigned int n_components);
572 
573 
587  virtual void
590 
594  virtual void
595  vector_value(const Point<dim> & p,
596  Vector<RangeNumberType> &return_value) const override;
597 
604  virtual void
606  const std::vector<Point<dim>> & points,
607  std::vector<Vector<RangeNumberType>> &values) const override;
608 
614  std::size_t
615  memory_consumption() const;
616 
617 protected:
621  const std::pair<unsigned int, unsigned int> selected_components;
622 };
623 
624 
625 
710 template <int dim, typename RangeNumberType = double>
711 class ScalarFunctionFromFunctionObject : public Function<dim, RangeNumberType>
712 {
713 public:
720  const std::function<RangeNumberType(const Point<dim> &)> &function_object);
721 
726  virtual RangeNumberType
727  value(const Point<dim> &p, const unsigned int component = 0) const override;
728 
729 private:
734  const std::function<RangeNumberType(const Point<dim> &)> function_object;
735 };
736 
737 
738 
778 template <int dim, typename RangeNumberType = double>
780  : public Function<dim, RangeNumberType>
781 {
782 public:
796  const std::function<RangeNumberType(const Point<dim> &)> &function_object,
797  const unsigned int selected_component,
798  const unsigned int n_components);
799 
804  virtual RangeNumberType
805  value(const Point<dim> &p, const unsigned int component = 0) const override;
806 
812  virtual void
813  vector_value(const Point<dim> & p,
814  Vector<RangeNumberType> &values) const override;
815 
816 private:
821  const std::function<RangeNumberType(const Point<dim> &)> function_object;
822 
827  const unsigned int selected_component;
828 };
829 
830 
868 template <int dim, typename RangeNumberType = double>
869 class FunctionFromFunctionObjects : public Function<dim, RangeNumberType>
870 {
871 public:
880  explicit FunctionFromFunctionObjects(const unsigned int n_components = 1,
881  const double initial_time = 0);
882 
892  const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
893  & values,
894  const double initial_time = 0.0);
895 
905  const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
906  &values,
907  const std::vector<
908  std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
909  & gradients,
910  const double initial_time = 0.0);
911 
912 
919  virtual RangeNumberType
920  value(const Point<dim> &p, const unsigned int component = 0) const override;
921 
929  gradient(const Point<dim> & p,
930  const unsigned int component = 0) const override;
931 
937  void
939  const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
940  &values);
941 
947  void
949  const std::vector<
950  std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
951  &gradients);
952 
953 private:
957  std::vector<std::function<RangeNumberType(const Point<dim> &)>>
959 
963  std::vector<
964  std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
966 };
967 
968 
1005 template <int dim, typename RangeNumberType = double>
1006 class VectorFunctionFromTensorFunction : public Function<dim, RangeNumberType>
1007 {
1008 public:
1027  const unsigned int selected_component = 0,
1028  const unsigned int n_components = dim);
1029 
1034  virtual ~VectorFunctionFromTensorFunction() override = default;
1035 
1039  virtual RangeNumberType
1040  value(const Point<dim> &p, const unsigned int component = 0) const override;
1041 
1047  virtual void
1048  vector_value(const Point<dim> & p,
1049  Vector<RangeNumberType> &values) const override;
1050 
1058  virtual void
1060  const std::vector<Point<dim>> & points,
1061  std::vector<Vector<RangeNumberType>> &value_list) const override;
1062 
1063 private:
1069 
1076  const unsigned int selected_component;
1077 };
1078 
1079 
1080 #ifndef DOXYGEN
1081 // icc 2018 complains about an undefined reference
1082 // if we put this in the templates.h file
1083 //
1084 // The destructor is pure virtual so we can't default it
1085 // in the declaration.
1086 template <int dim, typename RangeNumberType>
1088 #endif
1089 
1090 
1091 DEAL_II_NAMESPACE_CLOSE
1092 
1093 #endif
virtual void vector_gradient_list(const std::vector< Point< dim >> &points, std::vector< std::vector< Tensor< 1, dim, RangeNumberType >>> &gradients) const override
Function(const unsigned int n_components=1, const time_type initial_time=0.0)
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &return_value) const override
void set_function_gradients(const std::vector< std::function< Tensor< 1, dim, RangeNumberType >(const Point< dim > &)>> &gradients)
const unsigned int n_components
Definition: function.h:162
virtual void vector_hessian_list(const std::vector< Point< dim >> &points, std::vector< std::vector< SymmetricTensor< 2, dim, RangeNumberType >>> &values) const
virtual void gradient_list(const std::vector< Point< dim >> &points, std::vector< Tensor< 1, dim, RangeNumberType >> &gradients, const unsigned int component=0) const override
virtual void vector_gradient_list(const std::vector< Point< dim >> &points, std::vector< std::vector< Tensor< 1, dim, RangeNumberType >>> &gradients) const
virtual ~VectorFunctionFromTensorFunction() override=default
VectorFunctionFromTensorFunction(const TensorFunction< 1, dim, RangeNumberType > &tensor_function, const unsigned int selected_component=0, const unsigned int n_components=dim)
static const unsigned int dimension
Definition: function.h:157
virtual void vector_laplacian(const Point< dim > &p, Vector< RangeNumberType > &values) const
virtual void vector_hessian(const Point< dim > &p, std::vector< SymmetricTensor< 2, dim, RangeNumberType >> &values) const
FunctionFromFunctionObjects(const unsigned int n_components=1, const double initial_time=0)
virtual void vector_gradients(const std::vector< Point< dim >> &points, std::vector< std::vector< Tensor< 1, dim, RangeNumberType >>> &gradients) const
LinearAlgebra::distributed::Vector< Number > Vector
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
const std::function< RangeNumberType(const Point< dim > &)> function_object
Definition: function.h:821
ComponentSelectFunction(const unsigned int selected, const RangeNumberType value, const unsigned int n_components)
Function & operator=(const Function &f)
virtual void vector_value_list(const std::vector< Point< dim >> &points, std::vector< Vector< RangeNumberType >> &value_list) const override
typename FunctionTime< typename numbers::NumberTraits< RangeNumberType >::real_type >::time_type time_type
Definition: function.h:168
virtual void vector_value_list(const std::vector< Point< dim >> &points, std::vector< Vector< RangeNumberType >> &values) const
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &return_value) const override
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const override
const std::function< RangeNumberType(const Point< dim > &)> function_object
Definition: function.h:734
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
virtual Tensor< 1, dim, RangeNumberType > gradient(const Point< dim > &p, const unsigned int component=0) const override
virtual void vector_values(const std::vector< Point< dim >> &points, std::vector< std::vector< RangeNumberType >> &values) const
virtual SymmetricTensor< 2, dim, RangeNumberType > hessian(const Point< dim > &p, const unsigned int component=0) const
std::vector< std::function< Tensor< 1, dim, RangeNumberType >const Point< dim > &)> > function_gradients
Definition: function.h:965
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
std::size_t memory_consumption() const
virtual void value_list(const std::vector< Point< dim >> &points, std::vector< RangeNumberType > &return_values, const unsigned int component=0) const override
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const
virtual void vector_value_list(const std::vector< Point< dim >> &points, std::vector< Vector< RangeNumberType >> &return_values) const override
virtual void hessian_list(const std::vector< Point< dim >> &points, std::vector< SymmetricTensor< 2, dim, RangeNumberType >> &values, const unsigned int component=0) const
const TensorFunction< 1, dim, RangeNumberType > & tensor_function
Definition: function.h:1068
virtual void vector_laplacian_list(const std::vector< Point< dim >> &points, std::vector< Vector< RangeNumberType >> &values) const
std::vector< std::function< RangeNumberType(const Point< dim > &)> > function_values
Definition: function.h:958
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
virtual Tensor< 1, dim, RangeNumberType > gradient(const Point< dim > &p, const unsigned int component=0) const
ZeroFunction(const unsigned int n_components=1)
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const override
virtual void vector_gradient(const Point< dim > &p, std::vector< Tensor< 1, dim, RangeNumberType >> &gradients) const override
Number time_type
const std::pair< unsigned int, unsigned int > selected_components
Definition: function.h:621
virtual void substitute_function_value_with(const Functions::ConstantFunction< dim, RangeNumberType > &f)
virtual RangeNumberType laplacian(const Point< dim > &p, const unsigned int component=0) const
Definition: mpi.h:90
ConstantFunction(const RangeNumberType value, const unsigned int n_components=1)
void set_function_values(const std::vector< std::function< RangeNumberType(const Point< dim > &)>> &values)
virtual void value_list(const std::vector< Point< dim >> &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const
virtual ~Function() override=0
const unsigned int selected_component
Definition: function.h:1076
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
const unsigned int selected_component
Definition: function.h:827
ScalarFunctionFromFunctionObject(const std::function< RangeNumberType(const Point< dim > &)> &function_object)
virtual void vector_value_list(const std::vector< Point< dim >> &points, std::vector< Vector< RangeNumberType >> &values) const override
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
std::size_t memory_consumption() const
virtual void gradient_list(const std::vector< Point< dim >> &points, std::vector< Tensor< 1, dim, RangeNumberType >> &gradients, const unsigned int component=0) const
virtual void vector_gradient(const Point< dim > &p, std::vector< Tensor< 1, dim, RangeNumberType >> &gradients) const
std::vector< RangeNumberType > function_value_vector
Definition: function.h:479
virtual void laplacian_list(const std::vector< Point< dim >> &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const
VectorFunctionFromScalarFunctionObject(const std::function< RangeNumberType(const Point< dim > &)> &function_object, const unsigned int selected_component, const unsigned int n_components)
virtual Tensor< 1, dim, RangeNumberType > gradient(const Point< dim > &p, const unsigned int component=0) const override