Reference documentation for deal.II version Git 87130829be 2021-04-14 12:03:57 -0400
\(\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 
149 template <int dim, typename RangeNumberType = double>
150 class Function : public FunctionTime<
151  typename numbers::NumberTraits<RangeNumberType>::real_type>,
152  public Subscriptor
153 {
154 public:
159  static const unsigned int dimension = dim;
160 
164  const unsigned int n_components;
165 
169  using time_type = typename FunctionTime<
171 
177  explicit Function(const unsigned int n_components = 1,
178  const time_type initial_time = 0.0);
179 
183  Function(const Function &f) = default;
184 
206  virtual ~Function() override = 0;
207 
214  Function &
215  operator=(const Function &f);
216 
223  virtual RangeNumberType
224  value(const Point<dim> &p, const unsigned int component = 0) const;
225 
233  virtual void
235 
245  virtual void
246  value_list(const std::vector<Point<dim>> &points,
247  std::vector<RangeNumberType> & values,
248  const unsigned int component = 0) const;
249 
260  virtual void
261  vector_value_list(const std::vector<Point<dim>> & points,
262  std::vector<Vector<RangeNumberType>> &values) const;
263 
272  virtual void
273  vector_values(const std::vector<Point<dim>> & points,
274  std::vector<std::vector<RangeNumberType>> &values) const;
275 
281  gradient(const Point<dim> &p, const unsigned int component = 0) const;
282 
286  virtual void
288  const Point<dim> & p,
289  std::vector<Tensor<1, dim, RangeNumberType>> &gradients) const;
290 
297  virtual void
298  gradient_list(const std::vector<Point<dim>> & points,
300  const unsigned int component = 0) const;
301 
310  virtual void
312  const std::vector<Point<dim>> & points,
313  std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients) const;
314 
324  virtual void
326  const std::vector<Point<dim>> & points,
327  std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients) const;
328 
332  virtual RangeNumberType
333  laplacian(const Point<dim> &p, const unsigned int component = 0) const;
334 
339  virtual void
341 
345  virtual void
346  laplacian_list(const std::vector<Point<dim>> &points,
347  std::vector<RangeNumberType> & values,
348  const unsigned int component = 0) const;
349 
353  virtual void
354  vector_laplacian_list(const std::vector<Point<dim>> & points,
355  std::vector<Vector<RangeNumberType>> &values) const;
356 
362  hessian(const Point<dim> &p, const unsigned int component = 0) const;
363 
368  virtual void
370  const Point<dim> & p,
372 
376  virtual void
377  hessian_list(const std::vector<Point<dim>> & points,
379  const unsigned int component = 0) const;
380 
384  virtual void
386  const std::vector<Point<dim>> & points,
387  std::vector<std::vector<SymmetricTensor<2, dim, RangeNumberType>>> &values)
388  const;
389 
390 
396  virtual std::size_t
397  memory_consumption() const;
398 };
399 
400 
401 namespace Functions
402 {
409  template <int dim, typename RangeNumberType = double>
410  class ConstantFunction : public Function<dim, RangeNumberType>
411  {
412  public:
417  explicit ConstantFunction(const RangeNumberType value,
418  const unsigned int n_components = 1);
419 
425  explicit ConstantFunction(const std::vector<RangeNumberType> &values);
426 
432  explicit ConstantFunction(const Vector<RangeNumberType> &values);
433 
438  ConstantFunction(const RangeNumberType *begin_ptr,
439  const unsigned int n_components);
440 
441  virtual RangeNumberType
442  value(const Point<dim> &p, const unsigned int component = 0) const override;
443 
444  virtual void
445  vector_value(const Point<dim> & p,
446  Vector<RangeNumberType> &return_value) const override;
447 
448  virtual void
449  value_list(const std::vector<Point<dim>> &points,
450  std::vector<RangeNumberType> & return_values,
451  const unsigned int component = 0) const override;
452 
453  virtual void
455  const std::vector<Point<dim>> & points,
456  std::vector<Vector<RangeNumberType>> &return_values) const override;
457 
459  gradient(const Point<dim> & p,
460  const unsigned int component = 0) const override;
461 
462  virtual void
464  const Point<dim> & p,
465  std::vector<Tensor<1, dim, RangeNumberType>> &gradients) const override;
466 
467  virtual void
468  gradient_list(const std::vector<Point<dim>> & points,
470  const unsigned int component = 0) const override;
471 
472  virtual void
474  const std::vector<Point<dim>> & points,
475  std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients)
476  const override;
477 
479  hessian(const Point<dim> & point,
480  const unsigned int component = 0) const override;
481 
482  virtual RangeNumberType
483  laplacian(const Point<dim> & point,
484  const unsigned int component = 0) const override;
485 
486  virtual std::size_t
487  memory_consumption() const override;
488 
489  protected:
493  std::vector<RangeNumberType> function_value_vector;
494  };
495 
496 
497 
509  template <int dim, typename RangeNumberType = double>
510  class ZeroFunction : public ConstantFunction<dim, RangeNumberType>
511  {
512  public:
516  explicit ZeroFunction(const unsigned int n_components = 1);
517  };
518 
529  template <int dim, typename RangeNumberType = double>
530  class IdentityFunction : public Function<dim, RangeNumberType>
531  {
532  public:
537 
541  virtual RangeNumberType
542  value(const Point<dim> &p, const unsigned int component = 0) const override;
543 
548  gradient(const Point<dim> & p,
549  const unsigned int component = 0) const override;
550 
554  virtual RangeNumberType
555  laplacian(const Point<dim> & p,
556  const unsigned int component = 0) const override;
557 
562  hessian(const Point<dim> & p,
563  const unsigned int component = 0) const override;
564  };
565 } // namespace Functions
566 
567 
568 
582 template <int dim, typename RangeNumberType = double>
584  : public Functions::ConstantFunction<dim, RangeNumberType>
585 {
586 public:
592  ComponentSelectFunction(const unsigned int selected,
593  const RangeNumberType value,
594  const unsigned int n_components);
595 
600  ComponentSelectFunction(const unsigned int selected,
601  const unsigned int n_components);
602 
610  ComponentSelectFunction(const std::pair<unsigned int, unsigned int> &selected,
611  const unsigned int n_components);
612 
613 
627  virtual void
628  substitute_function_value_with(
630 
634  virtual void
635  vector_value(const Point<dim> & p,
636  Vector<RangeNumberType> &return_value) const override;
637 
644  virtual void
646  const std::vector<Point<dim>> & points,
647  std::vector<Vector<RangeNumberType>> &values) const override;
648 
652  virtual std::size_t
653  memory_consumption() const override;
654 
655 protected:
659  const std::pair<unsigned int, unsigned int> selected_components;
660 };
661 
662 
663 
747 template <int dim, typename RangeNumberType = double>
748 class ScalarFunctionFromFunctionObject : public Function<dim, RangeNumberType>
749 {
750 public:
757  const std::function<RangeNumberType(const Point<dim> &)> &function_object);
758 
763  virtual RangeNumberType
764  value(const Point<dim> &p, const unsigned int component = 0) const override;
765 
766 private:
771  const std::function<RangeNumberType(const Point<dim> &)> function_object;
772 };
773 
774 
775 
814 template <int dim, typename RangeNumberType = double>
816  : public Function<dim, RangeNumberType>
817 {
818 public:
832  const std::function<RangeNumberType(const Point<dim> &)> &function_object,
833  const unsigned int selected_component,
834  const unsigned int n_components);
835 
840  virtual RangeNumberType
841  value(const Point<dim> &p, const unsigned int component = 0) const override;
842 
848  virtual void
849  vector_value(const Point<dim> & p,
850  Vector<RangeNumberType> &values) const override;
851 
852 private:
857  const std::function<RangeNumberType(const Point<dim> &)> function_object;
858 
863  const unsigned int selected_component;
864 };
865 
866 
902 template <int dim, typename RangeNumberType = double>
903 class FunctionFromFunctionObjects : public Function<dim, RangeNumberType>
904 {
905 public:
914  explicit FunctionFromFunctionObjects(const unsigned int n_components = 1,
915  const double initial_time = 0);
916 
926  const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
927  & values,
928  const double initial_time = 0.0);
929 
939  const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
940  &values,
941  const std::vector<
942  std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
943  & gradients,
944  const double initial_time = 0.0);
945 
946 
953  virtual RangeNumberType
954  value(const Point<dim> &p, const unsigned int component = 0) const override;
955 
963  gradient(const Point<dim> & p,
964  const unsigned int component = 0) const override;
965 
971  void
972  set_function_values(
973  const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
974  &values);
975 
981  void
982  set_function_gradients(
983  const std::vector<
984  std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
985  &gradients);
986 
987 private:
991  std::vector<std::function<RangeNumberType(const Point<dim> &)>>
992  function_values;
993 
997  std::vector<
998  std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
999  function_gradients;
1000 };
1001 
1002 
1038 template <int dim, typename RangeNumberType = double>
1039 class VectorFunctionFromTensorFunction : public Function<dim, RangeNumberType>
1040 {
1041 public:
1059  const TensorFunction<1, dim, RangeNumberType> &tensor_function,
1060  const unsigned int selected_component = 0,
1061  const unsigned int n_components = dim);
1062 
1067  virtual ~VectorFunctionFromTensorFunction() override = default;
1068 
1072  virtual RangeNumberType
1073  value(const Point<dim> &p, const unsigned int component = 0) const override;
1074 
1080  virtual void
1081  vector_value(const Point<dim> & p,
1082  Vector<RangeNumberType> &values) const override;
1083 
1091  virtual void
1093  const std::vector<Point<dim>> & points,
1094  std::vector<Vector<RangeNumberType>> &value_list) const override;
1095 
1096 private:
1102 
1109  const unsigned int selected_component;
1110 };
1111 
1112 
1113 #ifndef DOXYGEN
1114 // icc 2018 complains about an undefined reference
1115 // if we put this in the templates.h file
1116 //
1117 // The destructor is pure virtual so we can't default it
1118 // in the declaration.
1119 template <int dim, typename RangeNumberType>
1121 #endif
1122 
1123 
1125 
1126 #endif
Function(const unsigned int n_components=1, const time_type initial_time=0.0)
const unsigned int n_components
Definition: function.h:164
virtual void vector_hessian_list(const std::vector< Point< dim >> &points, std::vector< std::vector< SymmetricTensor< 2, dim, RangeNumberType >>> &values) const
virtual void vector_gradient_list(const std::vector< Point< dim >> &points, std::vector< std::vector< Tensor< 1, dim, RangeNumberType >>> &gradients) const
static const unsigned int dimension
Definition: function.h:159
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
virtual void vector_gradients(const std::vector< Point< dim >> &points, std::vector< std::vector< Tensor< 1, dim, RangeNumberType >>> &gradients) const
Function & operator=(const Function &f)
typename FunctionTime< typename numbers::NumberTraits< RangeNumberType >::real_type >::time_type time_type
Definition: function.h:170
virtual void vector_value_list(const std::vector< Point< dim >> &points, std::vector< Vector< RangeNumberType >> &values) const
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
virtual std::size_t memory_consumption() const
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:396
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
Definition: utilities.cc:188
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:1101
virtual void vector_laplacian_list(const std::vector< Point< dim >> &points, std::vector< Vector< RangeNumberType >> &values) const
virtual Tensor< 1, dim, RangeNumberType > gradient(const Point< dim > &p, const unsigned int component=0) const
Number time_type
const std::pair< unsigned int, unsigned int > selected_components
Definition: function.h:659
virtual RangeNumberType laplacian(const Point< dim > &p, const unsigned int component=0) const
Definition: tensor.h:449
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:395
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:1109
const unsigned int selected_component
Definition: function.h:863
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) 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:493
virtual void laplacian_list(const std::vector< Point< dim >> &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const