Reference documentation for deal.II version Git a0b41b6d0f 2020-02-26 20:08:13 -0600
\(\newcommand{\vcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\vcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
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 // 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  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
234  vector_value(const Point<dim> &p, Vector<RangeNumberType> &values) const;
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,
299  std::vector<Tensor<1, dim, RangeNumberType>> &gradients,
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
340  vector_laplacian(const Point<dim> &p, Vector<RangeNumberType> &values) const;
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,
371  std::vector<SymmetricTensor<2, dim, RangeNumberType>> &values) const;
372 
376  virtual void
377  hessian_list(const std::vector<Point<dim>> & points,
378  std::vector<SymmetricTensor<2, dim, RangeNumberType>> &values,
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  std::size_t
397  memory_consumption() const;
398 };
399 
400 
401 namespace Functions
402 {
410  template <int dim, typename RangeNumberType = double>
411  class ConstantFunction : public Function<dim, RangeNumberType>
412  {
413  public:
418  ConstantFunction(const RangeNumberType value,
419  const unsigned int n_components = 1);
420 
426  ConstantFunction(const std::vector<RangeNumberType> &values);
427 
434 
439  ConstantFunction(const RangeNumberType *begin_ptr,
440  const unsigned int n_components);
441 
442  virtual RangeNumberType
443  value(const Point<dim> &p, const unsigned int component = 0) const override;
444 
445  virtual void
446  vector_value(const Point<dim> & p,
447  Vector<RangeNumberType> &return_value) const override;
448 
449  virtual void
450  value_list(const std::vector<Point<dim>> &points,
451  std::vector<RangeNumberType> & return_values,
452  const unsigned int component = 0) const override;
453 
454  virtual void
456  const std::vector<Point<dim>> & points,
457  std::vector<Vector<RangeNumberType>> &return_values) const override;
458 
460  gradient(const Point<dim> & p,
461  const unsigned int component = 0) const override;
462 
463  virtual void
465  const Point<dim> & p,
466  std::vector<Tensor<1, dim, RangeNumberType>> &gradients) const override;
467 
468  virtual void
469  gradient_list(const std::vector<Point<dim>> & points,
470  std::vector<Tensor<1, dim, RangeNumberType>> &gradients,
471  const unsigned int component = 0) const override;
472 
473  virtual void
475  const std::vector<Point<dim>> & points,
476  std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients)
477  const override;
478 
479  std::size_t
480  memory_consumption() const;
481 
482  protected:
486  std::vector<RangeNumberType> function_value_vector;
487  };
488 
489 
490 
503  template <int dim, typename RangeNumberType = double>
504  class ZeroFunction : public ConstantFunction<dim, RangeNumberType>
505  {
506  public:
510  ZeroFunction(const unsigned int n_components = 1);
511  };
512 
513 } // namespace Functions
514 
521 template <int dim, typename RangeNumberType = double>
522 using ConstantFunction DEAL_II_DEPRECATED =
524 
530 template <int dim, typename RangeNumberType = double>
531 using ZeroFunction DEAL_II_DEPRECATED =
533 
534 
535 
550 template <int dim, typename RangeNumberType = double>
551 class ComponentSelectFunction : public ConstantFunction<dim, RangeNumberType>
552 {
553 public:
559  ComponentSelectFunction(const unsigned int selected,
560  const RangeNumberType value,
561  const unsigned int n_components);
562 
567  ComponentSelectFunction(const unsigned int selected,
568  const unsigned int n_components);
569 
577  ComponentSelectFunction(const std::pair<unsigned int, unsigned int> &selected,
578  const unsigned int n_components);
579 
580 
594  virtual void
595  substitute_function_value_with(
597 
601  virtual void
602  vector_value(const Point<dim> & p,
603  Vector<RangeNumberType> &return_value) const override;
604 
611  virtual void
613  const std::vector<Point<dim>> & points,
614  std::vector<Vector<RangeNumberType>> &values) const override;
615 
621  std::size_t
622  memory_consumption() const;
623 
624 protected:
628  const std::pair<unsigned int, unsigned int> selected_components;
629 };
630 
631 
632 
717 template <int dim, typename RangeNumberType = double>
718 class ScalarFunctionFromFunctionObject : public Function<dim, RangeNumberType>
719 {
720 public:
727  const std::function<RangeNumberType(const Point<dim> &)> &function_object);
728 
733  virtual RangeNumberType
734  value(const Point<dim> &p, const unsigned int component = 0) const override;
735 
736 private:
741  const std::function<RangeNumberType(const Point<dim> &)> function_object;
742 };
743 
744 
745 
785 template <int dim, typename RangeNumberType = double>
787  : public Function<dim, RangeNumberType>
788 {
789 public:
803  const std::function<RangeNumberType(const Point<dim> &)> &function_object,
804  const unsigned int selected_component,
805  const unsigned int n_components);
806 
811  virtual RangeNumberType
812  value(const Point<dim> &p, const unsigned int component = 0) const override;
813 
819  virtual void
820  vector_value(const Point<dim> & p,
821  Vector<RangeNumberType> &values) const override;
822 
823 private:
828  const std::function<RangeNumberType(const Point<dim> &)> function_object;
829 
834  const unsigned int selected_component;
835 };
836 
837 
875 template <int dim, typename RangeNumberType = double>
876 class FunctionFromFunctionObjects : public Function<dim, RangeNumberType>
877 {
878 public:
887  explicit FunctionFromFunctionObjects(const unsigned int n_components = 1,
888  const double initial_time = 0);
889 
899  const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
900  & values,
901  const double initial_time = 0.0);
902 
912  const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
913  &values,
914  const std::vector<
915  std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
916  & gradients,
917  const double initial_time = 0.0);
918 
919 
926  virtual RangeNumberType
927  value(const Point<dim> &p, const unsigned int component = 0) const override;
928 
936  gradient(const Point<dim> & p,
937  const unsigned int component = 0) const override;
938 
944  void
945  set_function_values(
946  const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
947  &values);
948 
954  void
955  set_function_gradients(
956  const std::vector<
957  std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
958  &gradients);
959 
960 private:
964  std::vector<std::function<RangeNumberType(const Point<dim> &)>>
965  function_values;
966 
970  std::vector<
971  std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
972  function_gradients;
973 };
974 
975 
1012 template <int dim, typename RangeNumberType = double>
1013 class VectorFunctionFromTensorFunction : public Function<dim, RangeNumberType>
1014 {
1015 public:
1033  const TensorFunction<1, dim, RangeNumberType> &tensor_function,
1034  const unsigned int selected_component = 0,
1035  const unsigned int n_components = dim);
1036 
1041  virtual ~VectorFunctionFromTensorFunction() override = default;
1042 
1046  virtual RangeNumberType
1047  value(const Point<dim> &p, const unsigned int component = 0) const override;
1048 
1054  virtual void
1055  vector_value(const Point<dim> & p,
1056  Vector<RangeNumberType> &values) const override;
1057 
1065  virtual void
1067  const std::vector<Point<dim>> & points,
1068  std::vector<Vector<RangeNumberType>> &value_list) const override;
1069 
1070 private:
1076 
1083  const unsigned int selected_component;
1084 };
1085 
1086 
1087 #ifndef DOXYGEN
1088 // icc 2018 complains about an undefined reference
1089 // if we put this in the templates.h file
1090 //
1091 // The destructor is pure virtual so we can't default it
1092 // in the declaration.
1093 template <int dim, typename RangeNumberType>
1095 #endif
1096 
1097 
1098 DEAL_II_NAMESPACE_CLOSE
1099 
1100 #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
LinearAlgebra::distributed::Vector< Number > Vector
Function & operator=(const Function &f)
typename FunctionTime< typename numbers::NumberTraits< double >::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 void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const
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:1075
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
const std::pair< unsigned int, unsigned int > selected_components
Definition: function.h:628
virtual RangeNumberType laplacian(const Point< dim > &p, const unsigned int component=0) const
Definition: tensor.h:422
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:1083
const unsigned int selected_component
Definition: function.h:834
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:486
virtual void laplacian_list(const std::vector< Point< dim >> &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const