deal.II version GIT relicensing-2289-g1e5549a87a 2024-12-21 21:30:00+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
24#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>,
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
819 const std::function<RangeNumberType(const double, const Point<dim> &)>
820 &function_object_t);
821
826 virtual RangeNumberType
827 value(const Point<dim> &p, const unsigned int component = 0) const override;
828
829private:
834 const std::function<RangeNumberType(const double, const Point<dim> &)>
836};
837
838
839
878template <int dim, typename RangeNumberType = double>
880 : public Function<dim, RangeNumberType>
881{
882public:
896 const std::function<RangeNumberType(const Point<dim> &)> &function_object,
897 const unsigned int selected_component,
898 const unsigned int n_components);
899
904 virtual RangeNumberType
905 value(const Point<dim> &p, const unsigned int component = 0) const override;
906
912 virtual void
914 Vector<RangeNumberType> &values) const override;
915
916private:
921 const std::function<RangeNumberType(const Point<dim> &)> function_object;
922
927 const unsigned int selected_component;
928};
929
930
966template <int dim, typename RangeNumberType = double>
967class FunctionFromFunctionObjects : public Function<dim, RangeNumberType>
968{
969public:
978 explicit FunctionFromFunctionObjects(const unsigned int n_components = 1,
979 const double initial_time = 0);
980
990 const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
991 &values,
992 const double initial_time = 0.0);
993
1003 const std::function<RangeNumberType(const Point<dim> &, const unsigned int)>
1004 &values,
1005 const unsigned int n_components,
1006 const double initial_time = 0.0);
1007
1017 const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
1018 &values,
1019 const std::vector<
1020 std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
1021 &gradients,
1022 const double initial_time = 0.0);
1023
1024
1031 virtual RangeNumberType
1032 value(const Point<dim> &p, const unsigned int component = 0) const override;
1033
1042 const unsigned int component = 0) const override;
1043
1049 void
1051 const std::vector<std::function<RangeNumberType(const Point<dim> &)>>
1052 &values);
1053
1059 void
1061 const std::vector<
1062 std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
1063 &gradients);
1064
1065private:
1069 std::function<RangeNumberType(const Point<dim> &, const unsigned int)>
1071
1075 std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &,
1076 const unsigned int)>
1078};
1079
1080
1116template <int dim, typename RangeNumberType = double>
1117class VectorFunctionFromTensorFunction : public Function<dim, RangeNumberType>
1118{
1119public:
1138 const unsigned int selected_component = 0,
1139 const unsigned int n_components = dim);
1140
1145 virtual ~VectorFunctionFromTensorFunction() override = default;
1146
1150 virtual RangeNumberType
1151 value(const Point<dim> &p, const unsigned int component = 0) const override;
1152
1158 virtual void
1160 Vector<RangeNumberType> &values) const override;
1161
1169 virtual void
1171 const std::vector<Point<dim>> &points,
1172 std::vector<Vector<RangeNumberType>> &value_list) const override;
1173
1180 const unsigned int component = 0) const override;
1181
1185 virtual void
1187 const Point<dim> &p,
1188 std::vector<Tensor<1, dim, RangeNumberType>> &gradients) const override;
1189
1196 virtual void
1197 gradient_list(const std::vector<Point<dim>> &points,
1198 std::vector<Tensor<1, dim, RangeNumberType>> &gradients,
1199 const unsigned int component = 0) const override;
1200
1209 virtual void
1210 vector_gradients(const std::vector<Point<dim>> &points,
1211 std::vector<std::vector<Tensor<1, dim, RangeNumberType>>>
1212 &gradients) const override;
1213
1223 virtual void
1224 vector_gradient_list(const std::vector<Point<dim>> &points,
1225 std::vector<std::vector<Tensor<1, dim, RangeNumberType>>>
1226 &gradients) const override;
1227
1228private:
1234
1241 const unsigned int selected_component;
1242};
1243
1244
1245#ifndef DOXYGEN
1246// icc 2018 complains about an undefined reference
1247// if we put this in the templates.h file
1248//
1249// The destructor is pure virtual so we can't default it
1250// in the declaration.
1251template <int dim, typename RangeNumberType>
1253#endif
1254
1255
1257
1258#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)
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
std::function< RangeNumberType(const Point< dim > &, const unsigned int)> function_values
Definition function.h:1070
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)
std::function< Tensor< 1, dim, RangeNumberType >(const Point< dim > &, const unsigned int)> function_gradients
Definition function.h:1077
FunctionFromFunctionObjects(const std::vector< std::function< RangeNumberType(const Point< dim > &)> > &values, const double initial_time=0.0)
FunctionFromFunctionObjects(const std::function< RangeNumberType(const Point< dim > &, const unsigned int)> &values, const unsigned int n_components, 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)
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
ScalarFunctionFromFunctionObject(const std::function< RangeNumberType(const double, const Point< dim > &)> &function_object_t)
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
const std::function< RangeNumberType(const double, const Point< dim > &)> function_object
Definition function.h:835
ScalarFunctionFromFunctionObject(const std::function< RangeNumberType(const Point< dim > &)> &function_object)
const std::function< RangeNumberType(const Point< dim > &)> function_object
Definition function.h:921
const unsigned int selected_component
Definition function.h:927
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:1233
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:1241
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:498
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:499