Reference documentation for deal.II version 9.5.0
\(\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\}}\)
Loading...
Searching...
No Matches
function.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 1998 - 2022 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
36template <typename number>
37class Vector;
38template <int rank, int dim, typename Number>
39class TensorFunction;
40#endif
41
149template <int dim, typename RangeNumberType = double>
150class Function : public FunctionTime<
151 typename numbers::NumberTraits<RangeNumberType>::real_type>,
152 public Subscriptor
153{
154public:
159 static constexpr 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 &
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,
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
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 virtual std::size_t
398};
399
400
401namespace 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
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
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
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,
469 std::vector<Tensor<1, dim, RangeNumberType>> &gradients,
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
549 const unsigned int component = 0) const override;
550
554 virtual RangeNumberType
556 const unsigned int component = 0) const override;
557
563 const unsigned int component = 0) const override;
564 };
565} // namespace Functions
566
580template <int dim, typename RangeNumberType = double>
582 : public Functions::ConstantFunction<dim, RangeNumberType>
583{
584public:
590 ComponentSelectFunction(const unsigned int selected,
591 const RangeNumberType value,
592 const unsigned int n_components);
593
598 ComponentSelectFunction(const unsigned int selected,
599 const unsigned int n_components);
600
608 ComponentSelectFunction(const std::pair<unsigned int, unsigned int> &selected,
609 const unsigned int n_components);
610
611
625 virtual void
628
632 virtual void
634 Vector<RangeNumberType> &return_value) const override;
635
642 virtual void
644 const std::vector<Point<dim>> & points,
645 std::vector<Vector<RangeNumberType>> &values) const override;
646
650 virtual std::size_t
651 memory_consumption() const override;
652
653protected:
657 const std::pair<unsigned int, unsigned int> selected_components;
658};
659
660
661
802template <int dim, typename RangeNumberType = double>
803class ScalarFunctionFromFunctionObject : public Function<dim, RangeNumberType>
804{
805public:
812 const std::function<RangeNumberType(const Point<dim> &)> &function_object);
813
818 virtual RangeNumberType
819 value(const Point<dim> &p, const unsigned int component = 0) const override;
820
821private:
826 const std::function<RangeNumberType(const Point<dim> &)> function_object;
827};
828
829
830
869template <int dim, typename RangeNumberType = double>
871 : public Function<dim, RangeNumberType>
872{
873public:
887 const std::function<RangeNumberType(const Point<dim> &)> &function_object,
888 const unsigned int selected_component,
889 const unsigned int n_components);
890
895 virtual RangeNumberType
896 value(const Point<dim> &p, const unsigned int component = 0) const override;
897
903 virtual void
905 Vector<RangeNumberType> &values) const override;
906
907private:
912 const std::function<RangeNumberType(const Point<dim> &)> function_object;
913
918 const unsigned int selected_component;
919};
920
921
957template <int dim, typename RangeNumberType = double>
958class FunctionFromFunctionObjects : public Function<dim, RangeNumberType>
959{
960public:
969 explicit FunctionFromFunctionObjects(const unsigned int n_components = 1,
970 const double initial_time = 0);
971
981 const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
982 & values,
983 const double initial_time = 0.0);
984
994 const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
995 &values,
996 const std::vector<
997 std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
998 & gradients,
999 const double initial_time = 0.0);
1000
1001
1008 virtual RangeNumberType
1009 value(const Point<dim> &p, const unsigned int component = 0) const override;
1010
1019 const unsigned int component = 0) const override;
1020
1026 void
1028 const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
1029 &values);
1030
1036 void
1038 const std::vector<
1039 std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
1040 &gradients);
1041
1042private:
1046 std::vector<std::function<RangeNumberType(const Point<dim> &)>>
1048
1052 std::vector<
1053 std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
1055};
1056
1057
1093template <int dim, typename RangeNumberType = double>
1094class VectorFunctionFromTensorFunction : public Function<dim, RangeNumberType>
1095{
1096public:
1115 const unsigned int selected_component = 0,
1116 const unsigned int n_components = dim);
1117
1122 virtual ~VectorFunctionFromTensorFunction() override = default;
1123
1127 virtual RangeNumberType
1128 value(const Point<dim> &p, const unsigned int component = 0) const override;
1129
1135 virtual void
1137 Vector<RangeNumberType> &values) const override;
1138
1146 virtual void
1148 const std::vector<Point<dim>> & points,
1149 std::vector<Vector<RangeNumberType>> &value_list) const override;
1150
1151private:
1157
1164 const unsigned int selected_component;
1165};
1166
1167
1168#ifndef DOXYGEN
1169// icc 2018 complains about an undefined reference
1170// if we put this in the templates.h file
1171//
1172// The destructor is pure virtual so we can't default it
1173// in the declaration.
1174template <int dim, typename RangeNumberType>
1176#endif
1177
1178
1180
1181#endif
const std::pair< unsigned int, unsigned int > selected_components
Definition function.h:657
virtual std::size_t memory_consumption() const override
ComponentSelectFunction(const std::pair< unsigned int, unsigned int > &selected, const unsigned int n_components)
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &return_value) const override
ComponentSelectFunction(const unsigned int selected, const unsigned int n_components)
virtual void substitute_function_value_with(const Functions::ConstantFunction< dim, RangeNumberType > &f)
virtual void vector_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< RangeNumberType > > &values) const override
ComponentSelectFunction(const unsigned int selected, const RangeNumberType value, const unsigned int n_components)
std::vector< std::function< Tensor< 1, dim, RangeNumberType >(const Point< dim > &)> > function_gradients
Definition function.h:1054
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
FunctionFromFunctionObjects(const std::vector< std::function< RangeNumberType(const Point< dim > &)> > &values, const std::vector< std::function< Tensor< 1, dim, RangeNumberType >(const Point< dim > &)> > &gradients, const double initial_time=0.0)
FunctionFromFunctionObjects(const std::vector< std::function< RangeNumberType(const Point< dim > &)> > &values, const double initial_time=0.0)
void set_function_values(const std::vector< std::function< RangeNumberType(const Point< dim > &)> > &values)
FunctionFromFunctionObjects(const unsigned int n_components=1, const double initial_time=0)
void set_function_gradients(const std::vector< std::function< Tensor< 1, dim, RangeNumberType >(const Point< dim > &)> > &gradients)
std::vector< std::function< RangeNumberType(const Point< dim > &)> > function_values
Definition function.h:1047
virtual void vector_gradient(const Point< dim > &p, std::vector< Tensor< 1, dim, RangeNumberType > > &gradients) const
virtual void vector_laplacian_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
static constexpr unsigned int dimension
Definition function.h:159
virtual void vector_laplacian(const Point< dim > &p, Vector< RangeNumberType > &values) const
virtual SymmetricTensor< 2, dim, RangeNumberType > hessian(const Point< dim > &p, const unsigned int component=0) const
typename FunctionTime< typename numbers::NumberTraits< RangeNumberType >::real_type >::time_type time_type
Definition function.h:170
Function & operator=(const Function &f)
virtual 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 Tensor< 1, dim, RangeNumberType > gradient(const Point< dim > &p, const unsigned int component=0) const
virtual void vector_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< RangeNumberType > > &values) const
const unsigned int n_components
Definition function.h:164
virtual RangeNumberType laplacian(const Point< dim > &p, const unsigned int component=0) const
virtual ~Function() override=0
Function(const unsigned int n_components=1, const time_type initial_time=0.0)
virtual void laplacian_list(const std::vector< Point< dim > > &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const
virtual void vector_hessian_list(const std::vector< Point< dim > > &points, std::vector< std::vector< SymmetricTensor< 2, dim, RangeNumberType > > > &values) const
virtual void value_list(const std::vector< Point< dim > > &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const
virtual void vector_gradient_list(const std::vector< Point< dim > > &points, std::vector< std::vector< Tensor< 1, dim, RangeNumberType > > > &gradients) const
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) 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
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
Function(const Function &f)=default
virtual std::size_t memory_consumption() const override
virtual void value_list(const std::vector< Point< dim > > &points, std::vector< RangeNumberType > &return_values, const unsigned int component=0) const override
ConstantFunction(const RangeNumberType *begin_ptr, const unsigned int n_components)
virtual RangeNumberType laplacian(const Point< dim > &point, const unsigned int component=0) const override
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(const Point< dim > &p, std::vector< Tensor< 1, dim, RangeNumberType > > &gradients) const override
virtual SymmetricTensor< 2, dim, RangeNumberType > hessian(const Point< dim > &point, const unsigned int component=0) const override
ConstantFunction(const RangeNumberType value, const unsigned int n_components=1)
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_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< RangeNumberType > > &return_values) const override
ConstantFunction(const std::vector< RangeNumberType > &values)
virtual void vector_gradient_list(const std::vector< Point< dim > > &points, std::vector< std::vector< Tensor< 1, dim, RangeNumberType > > > &gradients) const override
std::vector< RangeNumberType > function_value_vector
Definition function.h:493
ConstantFunction(const Vector< RangeNumberType > &values)
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &return_value) const override
virtual SymmetricTensor< 2, dim, RangeNumberType > hessian(const Point< dim > &p, const unsigned int component=0) const override
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
virtual RangeNumberType laplacian(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
ZeroFunction(const unsigned int n_components=1)
Definition point.h:112
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:826
ScalarFunctionFromFunctionObject(const std::function< RangeNumberType(const Point< dim > &)> &function_object)
const std::function< RangeNumberType(const Point< dim > &)> function_object
Definition function.h:912
const unsigned int selected_component
Definition function.h:918
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const override
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
VectorFunctionFromScalarFunctionObject(const std::function< RangeNumberType(const Point< dim > &)> &function_object, const unsigned int selected_component, const unsigned int n_components)
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
const TensorFunction< 1, dim, RangeNumberType > & tensor_function
Definition function.h:1156
virtual void vector_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< RangeNumberType > > &value_list) const override
VectorFunctionFromTensorFunction(const TensorFunction< 1, dim, RangeNumberType > &tensor_function, const unsigned int selected_component=0, const unsigned int n_components=dim)
virtual ~VectorFunctionFromTensorFunction() override=default
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const override
const unsigned int selected_component
Definition function.h:1164
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473