Reference documentation for deal.II version Git 7baca85e57 2019-08-23 17:29:05 -0400
\(\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 // 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 
201  virtual ~Function() override = 0;
202 
209  Function &
210  operator=(const Function &f);
211 
218  virtual RangeNumberType
219  value(const Point<dim> &p, const unsigned int component = 0) const;
220 
228  virtual void
229  vector_value(const Point<dim> &p, Vector<RangeNumberType> &values) const;
230 
240  virtual void
241  value_list(const std::vector<Point<dim>> &points,
242  std::vector<RangeNumberType> & values,
243  const unsigned int component = 0) const;
244 
255  virtual void
256  vector_value_list(const std::vector<Point<dim>> & points,
257  std::vector<Vector<RangeNumberType>> &values) const;
258 
267  virtual void
268  vector_values(const std::vector<Point<dim>> & points,
269  std::vector<std::vector<RangeNumberType>> &values) const;
270 
276  gradient(const Point<dim> &p, const unsigned int component = 0) const;
277 
281  virtual void
283  const Point<dim> & p,
284  std::vector<Tensor<1, dim, RangeNumberType>> &gradients) const;
285 
292  virtual void
293  gradient_list(const std::vector<Point<dim>> & points,
294  std::vector<Tensor<1, dim, RangeNumberType>> &gradients,
295  const unsigned int component = 0) const;
296 
305  virtual void
307  const std::vector<Point<dim>> & points,
308  std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients) const;
309 
319  virtual void
321  const std::vector<Point<dim>> & points,
322  std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients) const;
323 
327  virtual RangeNumberType
328  laplacian(const Point<dim> &p, const unsigned int component = 0) const;
329 
334  virtual void
335  vector_laplacian(const Point<dim> &p, Vector<RangeNumberType> &values) const;
336 
340  virtual void
341  laplacian_list(const std::vector<Point<dim>> &points,
342  std::vector<RangeNumberType> & values,
343  const unsigned int component = 0) const;
344 
348  virtual void
349  vector_laplacian_list(const std::vector<Point<dim>> & points,
350  std::vector<Vector<RangeNumberType>> &values) const;
351 
357  hessian(const Point<dim> &p, const unsigned int component = 0) const;
358 
363  virtual void
365  const Point<dim> & p,
366  std::vector<SymmetricTensor<2, dim, RangeNumberType>> &values) const;
367 
371  virtual void
372  hessian_list(const std::vector<Point<dim>> & points,
373  std::vector<SymmetricTensor<2, dim, RangeNumberType>> &values,
374  const unsigned int component = 0) const;
375 
379  virtual void
381  const std::vector<Point<dim>> & points,
382  std::vector<std::vector<SymmetricTensor<2, dim, RangeNumberType>>> &values)
383  const;
384 
385 
391  std::size_t
392  memory_consumption() const;
393 };
394 
395 
396 namespace Functions
397 {
405  template <int dim, typename RangeNumberType = double>
406  class ConstantFunction : public Function<dim, RangeNumberType>
407  {
408  public:
413  ConstantFunction(const RangeNumberType value,
414  const unsigned int n_components = 1);
415 
421  ConstantFunction(const std::vector<RangeNumberType> &values);
422 
429 
434  ConstantFunction(const RangeNumberType *begin_ptr,
435  const unsigned int n_components);
436 
437  virtual RangeNumberType
438  value(const Point<dim> &p, const unsigned int component = 0) const override;
439 
440  virtual void
441  vector_value(const Point<dim> & p,
442  Vector<RangeNumberType> &return_value) const override;
443 
444  virtual void
445  value_list(const std::vector<Point<dim>> &points,
446  std::vector<RangeNumberType> & return_values,
447  const unsigned int component = 0) const override;
448 
449  virtual void
451  const std::vector<Point<dim>> & points,
452  std::vector<Vector<RangeNumberType>> &return_values) const override;
453 
455  gradient(const Point<dim> & p,
456  const unsigned int component = 0) const override;
457 
458  virtual void
460  const Point<dim> & p,
461  std::vector<Tensor<1, dim, RangeNumberType>> &gradients) const override;
462 
463  virtual void
464  gradient_list(const std::vector<Point<dim>> & points,
465  std::vector<Tensor<1, dim, RangeNumberType>> &gradients,
466  const unsigned int component = 0) const override;
467 
468  virtual void
470  const std::vector<Point<dim>> & points,
471  std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients)
472  const override;
473 
474  std::size_t
475  memory_consumption() const;
476 
477  protected:
481  std::vector<RangeNumberType> function_value_vector;
482  };
483 
484 
485 
498  template <int dim, typename RangeNumberType = double>
499  class ZeroFunction : public ConstantFunction<dim, RangeNumberType>
500  {
501  public:
505  ZeroFunction(const unsigned int n_components = 1);
506  };
507 
508 } // namespace Functions
509 
516 template <int dim, typename RangeNumberType = double>
517 using ConstantFunction DEAL_II_DEPRECATED =
519 
525 template <int dim, typename RangeNumberType = double>
526 using ZeroFunction DEAL_II_DEPRECATED =
528 
529 
530 
545 template <int dim, typename RangeNumberType = double>
546 class ComponentSelectFunction : public ConstantFunction<dim, RangeNumberType>
547 {
548 public:
554  ComponentSelectFunction(const unsigned int selected,
555  const RangeNumberType value,
556  const unsigned int n_components);
557 
562  ComponentSelectFunction(const unsigned int selected,
563  const unsigned int n_components);
564 
572  ComponentSelectFunction(const std::pair<unsigned int, unsigned int> &selected,
573  const unsigned int n_components);
574 
575 
589  virtual void
590  substitute_function_value_with(
592 
596  virtual void
597  vector_value(const Point<dim> & p,
598  Vector<RangeNumberType> &return_value) const override;
599 
606  virtual void
608  const std::vector<Point<dim>> & points,
609  std::vector<Vector<RangeNumberType>> &values) const override;
610 
616  std::size_t
617  memory_consumption() const;
618 
619 protected:
623  const std::pair<unsigned int, unsigned int> selected_components;
624 };
625 
626 
627 
712 template <int dim, typename RangeNumberType = double>
713 class ScalarFunctionFromFunctionObject : public Function<dim, RangeNumberType>
714 {
715 public:
722  const std::function<RangeNumberType(const Point<dim> &)> &function_object);
723 
728  virtual RangeNumberType
729  value(const Point<dim> &p, const unsigned int component = 0) const override;
730 
731 private:
736  const std::function<RangeNumberType(const Point<dim> &)> function_object;
737 };
738 
739 
740 
780 template <int dim, typename RangeNumberType = double>
782  : public Function<dim, RangeNumberType>
783 {
784 public:
798  const std::function<RangeNumberType(const Point<dim> &)> &function_object,
799  const unsigned int selected_component,
800  const unsigned int n_components);
801 
806  virtual RangeNumberType
807  value(const Point<dim> &p, const unsigned int component = 0) const override;
808 
814  virtual void
815  vector_value(const Point<dim> & p,
816  Vector<RangeNumberType> &values) const override;
817 
818 private:
823  const std::function<RangeNumberType(const Point<dim> &)> function_object;
824 
829  const unsigned int selected_component;
830 };
831 
832 
870 template <int dim, typename RangeNumberType = double>
871 class FunctionFromFunctionObjects : public Function<dim, RangeNumberType>
872 {
873 public:
882  explicit FunctionFromFunctionObjects(const unsigned int n_components = 1,
883  const double initial_time = 0);
884 
894  const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
895  & values,
896  const double initial_time = 0.0);
897 
907  const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
908  &values,
909  const std::vector<
910  std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
911  & gradients,
912  const double initial_time = 0.0);
913 
914 
921  virtual RangeNumberType
922  value(const Point<dim> &p, const unsigned int component = 0) const override;
923 
931  gradient(const Point<dim> & p,
932  const unsigned int component = 0) const override;
933 
939  void
940  set_function_values(
941  const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
942  &values);
943 
949  void
950  set_function_gradients(
951  const std::vector<
952  std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
953  &gradients);
954 
955 private:
959  std::vector<std::function<RangeNumberType(const Point<dim> &)>>
960  function_values;
961 
965  std::vector<
966  std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
967  function_gradients;
968 };
969 
970 
1007 template <int dim, typename RangeNumberType = double>
1008 class VectorFunctionFromTensorFunction : public Function<dim, RangeNumberType>
1009 {
1010 public:
1028  const TensorFunction<1, dim, RangeNumberType> &tensor_function,
1029  const unsigned int selected_component = 0,
1030  const unsigned int n_components = dim);
1031 
1036  virtual ~VectorFunctionFromTensorFunction() override = default;
1037 
1041  virtual RangeNumberType
1042  value(const Point<dim> &p, const unsigned int component = 0) const override;
1043 
1049  virtual void
1050  vector_value(const Point<dim> & p,
1051  Vector<RangeNumberType> &values) const override;
1052 
1060  virtual void
1062  const std::vector<Point<dim>> & points,
1063  std::vector<Vector<RangeNumberType>> &value_list) const override;
1064 
1065 private:
1071 
1078  const unsigned int selected_component;
1079 };
1080 
1081 
1082 #ifndef DOXYGEN
1083 // icc 2018 complains about an undefined reference
1084 // if we put this in the templates.h file
1085 //
1086 // The destructor is pure virtual so we can't default it
1087 // in the declaration.
1088 template <int dim, typename RangeNumberType>
1090 #endif
1091 
1092 
1093 DEAL_II_NAMESPACE_CLOSE
1094 
1095 #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:1070
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:623
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:1078
const unsigned int selected_component
Definition: function.h:829
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:481
virtual void laplacian_list(const std::vector< Point< dim >> &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const