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