Reference documentation for deal.II version Git a73d35cdfe 2020-05-28 10:34:58 +0200
\(\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 
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
604  substitute_function_value_with(
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
954  set_function_values(
955  const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
956  &values);
957 
963  void
964  set_function_gradients(
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> &)>>
974  function_values;
975 
979  std::vector<
980  std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
981  function_gradients;
982 };
983 
984 
1021 template <int dim, typename RangeNumberType = double>
1022 class VectorFunctionFromTensorFunction : public Function<dim, RangeNumberType>
1023 {
1024 public:
1042  const TensorFunction<1, dim, RangeNumberType> &tensor_function,
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(const unsigned int n_components=1, const time_type initial_time=0.0)
const unsigned int n_components
Definition: function.h:165
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:160
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:171
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
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:362
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:1084
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:637
Functions::ZeroFunction< dim, RangeNumberType > ZeroFunction
Definition: function.h:541
virtual RangeNumberType laplacian(const Point< dim > &p, const unsigned int component=0) const
Definition: tensor.h:450
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:361
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:1092
Functions::ConstantFunction< dim, RangeNumberType > ConstantFunction
Definition: function.h:532
const unsigned int selected_component
Definition: function.h:843
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
std::size_t memory_consumption() const
#define DEAL_II_DEPRECATED
Definition: config.h:151
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:495
virtual void laplacian_list(const std::vector< Point< dim >> &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const