Reference documentation for deal.II version GIT relicensing-233-g802318d791 2024-03-28 20:20: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
incremental_function.cc
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2018 - 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
17
18#include <deal.II/lac/vector.h>
19
21
22namespace Functions
23{
24 template <int dim, typename RangeNumberType>
27 : Function<dim, RangeNumberType>(base.n_components)
28 , base(base)
29 , delta_t(numbers::signaling_nan<time_type>())
30 , values_old(base.n_components)
31 {}
32
33
34
35 template <int dim, typename RangeNumberType>
36 void
38 const time_type delta)
39 {
40 Assert(delta >= 0.0,
41 ExcMessage("The decrement must be set to a non-negative value."));
42 delta_t = delta;
43 }
44
45
46
47 template <int dim, typename RangeNumberType>
48 RangeNumberType
50 const Point<dim> &p,
51 const unsigned int comp) const
52 {
53 // since we modify a mutable member variable, lock the
54 // the data via a mutex
55 std::lock_guard<std::mutex> lock(mutex);
56
57 // Cache the time state of the base class in case it has been changed
58 // within the user code. We reset the wrapped function to the original
59 // state once we're done with our own evaluations.
60 const auto orig_time = base.get_time();
61
62 base.set_time(this->get_time());
63 const RangeNumberType current = base.value(p, comp);
64
65 base.set_time(this->get_time() - delta_t);
66 const RangeNumberType old = base.value(p, comp);
67
68 // Reset wrapped function time setting
69 base.set_time(orig_time);
70
71 return current - old;
72 }
73
74
75
76 template <int dim, typename RangeNumberType>
77 void
79 const Point<dim> &p,
80 Vector<RangeNumberType> &values) const
81 {
82 // since we modify a mutable member variable, lock the
83 // the data via a mutex
84 std::lock_guard<std::mutex> lock(mutex);
85
86 // Cache the time state of the base class in case it has been changed
87 // within the user code. We reset the wrapped function to the original
88 // state once we're done with our own evaluations.
89 const auto orig_time = base.get_time();
90
91 base.set_time(this->get_time());
92 base.vector_value(p, values);
93
94 base.set_time(this->get_time() - delta_t);
95 base.vector_value(p, values_old);
96
97 values -= values_old;
98
99 // Reset wrapped function time setting
100 base.set_time(orig_time);
101 }
102
103
104// Explicit instantiations
105#include "incremental_function.inst"
106} // namespace Functions
void set_decrement(const time_type delta_t)
typename Function< dim, RangeNumberType >::time_type time_type
IncrementalFunction(Function< dim, RangeNumberType > &base)
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
Definition point.h:111
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
#define Assert(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)