Reference documentation for deal.II version GIT relicensing-1262-g480f56a2fa 2024-07-23 19:40:02+00:00
\(\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// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 1998 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_function_h
16#define dealii_function_h
17
18
19#include <deal.II/base/config.h>
20
23#include <deal.II/base/point.h>
26#include <deal.II/base/tensor.h>
27
28#include <functional>
29#include <vector>
30
32
33// Forward declarations
34#ifndef DOXYGEN
35template <typename number>
36class Vector;
37template <int rank, int dim, typename Number>
38class TensorFunction;
39#endif
40
148template <int dim, typename RangeNumberType = double>
149class Function : public FunctionTime<
150 typename numbers::NumberTraits<RangeNumberType>::real_type>,
151 public Subscriptor
152{
153public:
158 static constexpr unsigned int dimension = dim;
159
163 const unsigned int n_components;
164
168 using time_type = typename FunctionTime<
170
176 explicit Function(const unsigned int n_components = 1,
177 const time_type initial_time = 0.0);
178
182 Function(const Function &f) = default;
183
205 virtual ~Function() override = 0;
206
213 Function &
215
222 virtual RangeNumberType
223 value(const Point<dim> &p, const unsigned int component = 0) const;
224
232 virtual void
234
244 virtual void
245 value_list(const std::vector<Point<dim>> &points,
246 std::vector<RangeNumberType> &values,
247 const unsigned int component = 0) const;
248
259 virtual void
260 vector_value_list(const std::vector<Point<dim>> &points,
261 std::vector<Vector<RangeNumberType>> &values) const;
262
271 virtual void
272 vector_values(const std::vector<Point<dim>> &points,
273 std::vector<std::vector<RangeNumberType>> &values) const;
274
280 gradient(const Point<dim> &p, const unsigned int component = 0) const;
281
285 virtual void
287 const Point<dim> &p,
288 std::vector<Tensor<1, dim, RangeNumberType>> &gradients) const;
289
296 virtual void
297 gradient_list(const std::vector<Point<dim>> &points,
298 std::vector<Tensor<1, dim, RangeNumberType>> &gradients,
299 const unsigned int component = 0) const;
300
309 virtual void
311 const std::vector<Point<dim>> &points,
312 std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients) const;
313
323 virtual void
325 const std::vector<Point<dim>> &points,
326 std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients) const;
327
331 virtual RangeNumberType
332 laplacian(const Point<dim> &p, const unsigned int component = 0) const;
333
338 virtual void
340
344 virtual void
345 laplacian_list(const std::vector<Point<dim>> &points,
346 std::vector<RangeNumberType> &values,
347 const unsigned int component = 0) const;
348
352 virtual void
353 vector_laplacian_list(const std::vector<Point<dim>> &points,
354 std::vector<Vector<RangeNumberType>> &values) const;
355
361 hessian(const Point<dim> &p, const unsigned int component = 0) const;
362
367 virtual void
369 const Point<dim> &p,
370 std::vector<SymmetricTensor<2, dim, RangeNumberType>> &values) const;
371
375 virtual void
376 hessian_list(const std::vector<Point<dim>> &points,
377 std::vector<SymmetricTensor<2, dim, RangeNumberType>> &values,
378 const unsigned int component = 0) const;
379
383 virtual void
385 const std::vector<Point<dim>> &points,
386 std::vector<std::vector<SymmetricTensor<2, dim, RangeNumberType>>> &values)
387 const;
388
389
395 virtual std::size_t
397};
398
399
400namespace Functions
401{
408 template <int dim, typename RangeNumberType = double>
409 class ConstantFunction : public Function<dim, RangeNumberType>
410 {
411 public:
416 explicit ConstantFunction(const RangeNumberType value,
417 const unsigned int n_components = 1);
418
424 explicit ConstantFunction(const std::vector<RangeNumberType> &values);
425
432
437 ConstantFunction(const RangeNumberType *begin_ptr,
438 const unsigned int n_components);
439
440 virtual RangeNumberType
441 value(const Point<dim> &p, const unsigned int component = 0) const override;
442
443 virtual void
445 Vector<RangeNumberType> &return_value) const override;
446
447 virtual void
448 value_list(const std::vector<Point<dim>> &points,
449 std::vector<RangeNumberType> &return_values,
450 const unsigned int component = 0) const override;
451
452 virtual void
454 const std::vector<Point<dim>> &points,
455 std::vector<Vector<RangeNumberType>> &return_values) const override;
456
459 const unsigned int component = 0) const override;
460
461 virtual void
463 const Point<dim> &p,
464 std::vector<Tensor<1, dim, RangeNumberType>> &gradients) const override;
465
466 virtual void
467 gradient_list(const std::vector<Point<dim>> &points,
468 std::vector<Tensor<1, dim, RangeNumberType>> &gradients,
469 const unsigned int component = 0) const override;
470
471 virtual void
473 const std::vector<Point<dim>> &points,
474 std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients)
475 const override;
476
478 hessian(const Point<dim> &point,
479 const unsigned int component = 0) const override;
480
481 virtual RangeNumberType
482 laplacian(const Point<dim> &point,
483 const unsigned int component = 0) const override;
484
485 virtual std::size_t
486 memory_consumption() const override;
487
488 protected:
492 std::vector<RangeNumberType> function_value_vector;
493 };
494
495
496
508 template <int dim, typename RangeNumberType = double>
509 class ZeroFunction : public ConstantFunction<dim, RangeNumberType>
510 {
511 public:
515 explicit ZeroFunction(const unsigned int n_components = 1);
516 };
517
528 template <int dim, typename RangeNumberType = double>
529 class IdentityFunction : public Function<dim, RangeNumberType>
530 {
531 public:
536
540 virtual RangeNumberType
541 value(const Point<dim> &p, const unsigned int component = 0) const override;
542
548 const unsigned int component = 0) const override;
549
553 virtual RangeNumberType
555 const unsigned int component = 0) const override;
556
562 const unsigned int component = 0) const override;
563 };
564} // namespace Functions
565
579template <int dim, typename RangeNumberType = double>
581 : public Functions::ConstantFunction<dim, RangeNumberType>
582{
583public:
589 ComponentSelectFunction(const unsigned int selected,
590 const RangeNumberType value,
591 const unsigned int n_components);
592
597 ComponentSelectFunction(const unsigned int selected,
598 const unsigned int n_components);
599
607 ComponentSelectFunction(const std::pair<unsigned int, unsigned int> &selected,
608 const unsigned int n_components);
609
610
624 virtual void
627
631 virtual void
633 Vector<RangeNumberType> &return_value) const override;
634
641 virtual void
643 const std::vector<Point<dim>> &points,
644 std::vector<Vector<RangeNumberType>> &values) const override;
645
649 virtual std::size_t
650 memory_consumption() const override;
651
652protected:
656 const std::pair<unsigned int, unsigned int> selected_components;
657};
658
659
660
801template <int dim, typename RangeNumberType = double>
802class ScalarFunctionFromFunctionObject : public Function<dim, RangeNumberType>
803{
804public:
811 const std::function<RangeNumberType(const Point<dim> &)> &function_object);
812
817 virtual RangeNumberType
818 value(const Point<dim> &p, const unsigned int component = 0) const override;
819
820private:
825 const std::function<RangeNumberType(const Point<dim> &)> function_object;
826};
827
828
829
868template <int dim, typename RangeNumberType = double>
870 : public Function<dim, RangeNumberType>
871{
872public:
886 const std::function<RangeNumberType(const Point<dim> &)> &function_object,
887 const unsigned int selected_component,
888 const unsigned int n_components);
889
894 virtual RangeNumberType
895 value(const Point<dim> &p, const unsigned int component = 0) const override;
896
902 virtual void
904 Vector<RangeNumberType> &values) const override;
905
906private:
911 const std::function<RangeNumberType(const Point<dim> &)> function_object;
912
917 const unsigned int selected_component;
918};
919
920
956template <int dim, typename RangeNumberType = double>
957class FunctionFromFunctionObjects : public Function<dim, RangeNumberType>
958{
959public:
968 explicit FunctionFromFunctionObjects(const unsigned int n_components = 1,
969 const double initial_time = 0);
970
980 const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
981 &values,
982 const double initial_time = 0.0);
983
993 const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
994 &values,
995 const std::vector<
996 std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
997 &gradients,
998 const double initial_time = 0.0);
999
1000
1007 virtual RangeNumberType
1008 value(const Point<dim> &p, const unsigned int component = 0) const override;
1009
1018 const unsigned int component = 0) const override;
1019
1025 void
1027 const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
1028 &values);
1029
1035 void
1037 const std::vector<
1038 std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
1039 &gradients);
1040
1041private:
1045 std::vector<std::function<RangeNumberType(const Point<dim> &)>>
1047
1051 std::vector<
1052 std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
1054};
1055
1056
1092template <int dim, typename RangeNumberType = double>
1093class VectorFunctionFromTensorFunction : public Function<dim, RangeNumberType>
1094{
1095public:
1114 const unsigned int selected_component = 0,
1115 const unsigned int n_components = dim);
1116
1121 virtual ~VectorFunctionFromTensorFunction() override = default;
1122
1126 virtual RangeNumberType
1127 value(const Point<dim> &p, const unsigned int component = 0) const override;
1128
1134 virtual void
1136 Vector<RangeNumberType> &values) const override;
1137
1145 virtual void
1147 const std::vector<Point<dim>> &points,
1148 std::vector<Vector<RangeNumberType>> &value_list) const override;
1149
1156 const unsigned int component = 0) const override;
1157
1161 virtual void
1163 const Point<dim> &p,
1164 std::vector<Tensor<1, dim, RangeNumberType>> &gradients) const override;
1165
1172 virtual void
1173 gradient_list(const std::vector<Point<dim>> &points,
1174 std::vector<Tensor<1, dim, RangeNumberType>> &gradients,
1175 const unsigned int component = 0) const override;
1176
1185 virtual void
1186 vector_gradients(const std::vector<Point<dim>> &points,
1187 std::vector<std::vector<Tensor<1, dim, RangeNumberType>>>
1188 &gradients) const override;
1189
1199 virtual void
1200 vector_gradient_list(const std::vector<Point<dim>> &points,
1201 std::vector<std::vector<Tensor<1, dim, RangeNumberType>>>
1202 &gradients) const override;
1203
1204private:
1210
1217 const unsigned int selected_component;
1218};
1219
1220
1221#ifndef DOXYGEN
1222// icc 2018 complains about an undefined reference
1223// if we put this in the templates.h file
1224//
1225// The destructor is pure virtual so we can't default it
1226// in the declaration.
1227template <int dim, typename RangeNumberType>
1229#endif
1230
1231
1233
1234#endif
const std::pair< unsigned int, unsigned int > selected_components
Definition function.h:656
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:1053
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:1046
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:158
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:169
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:163
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:492
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:111
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:825
ScalarFunctionFromFunctionObject(const std::function< RangeNumberType(const Point< dim > &)> &function_object)
const std::function< RangeNumberType(const Point< dim > &)> function_object
Definition function.h:911
const unsigned int selected_component
Definition function.h:917
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 Tensor< 1, dim, RangeNumberType > gradient(const Point< dim > &p, 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 RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
virtual void vector_gradients(const std::vector< Point< dim > > &points, std::vector< std::vector< Tensor< 1, dim, RangeNumberType > > > &gradients) const override
virtual void vector_gradient_list(const std::vector< Point< dim > > &points, std::vector< std::vector< Tensor< 1, dim, RangeNumberType > > > &gradients) const override
const TensorFunction< 1, dim, RangeNumberType > & tensor_function
Definition function.h:1209
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_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:1217
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:503
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:504