From: Jean-Paul Pelteret Date: Wed, 24 Oct 2018 12:10:28 +0000 (+0200) Subject: Add guarentee that wrapper resets time state of wrapped class X-Git-Tag: v9.1.0-rc1~588^2~5 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3fc4805f92b555ea587ddcb6f5c5481612c54df9;p=dealii.git Add guarentee that wrapper resets time state of wrapped class --- diff --git a/include/deal.II/base/incremental_function.h b/include/deal.II/base/incremental_function.h index a69af70e00..abd963e423 100644 --- a/include/deal.II/base/incremental_function.h +++ b/include/deal.II/base/incremental_function.h @@ -62,6 +62,9 @@ namespace Functions * @note This class stores a non-constant reference to @p base * and will call base.set_time() during evaluation * in order to evaluate the @p base class at any arbitrary time. + * It is guaranteed that the temporal state of @p base is returned + * to its original settings after each function evaluation in this + * class. */ IncrementalFunction(Function &base); diff --git a/source/base/incremental_function.cc b/source/base/incremental_function.cc index 027424e6d9..f5e23b1c40 100644 --- a/source/base/incremental_function.cc +++ b/source/base/incremental_function.cc @@ -43,6 +43,30 @@ namespace Functions + template + RangeNumberType + IncrementalFunction::value(const Point &p, + unsigned int comp) const + { + // Cache the time state of the base class in case it has been changed + // within the user code. We reset the wrapped function to the original + // state once we're done with our own evaluations. + const auto orig_time = base.get_time(); + + base.set_time(this->get_time()); + const RangeNumberType current = base.value(p, comp); + + base.set_time(this->get_time() - delta_t); + const RangeNumberType old = base.value(p, comp); + + // Reset wrapped function time setting + base.set_time(orig_time); + + return current - old; + } + + + template void IncrementalFunction::vector_value( @@ -53,6 +77,11 @@ namespace Functions // the data via a mutex std::lock_guard lock(mutex); + // Cache the time state of the base class in case it has been changed + // within the user code. We reset the wrapped function to the original + // state once we're done with our own evaluations. + const auto orig_time = base.get_time(); + base.set_time(this->get_time()); base.vector_value(p, values); @@ -60,22 +89,9 @@ namespace Functions base.vector_value(p, values_old); values -= values_old; - } - - - template - RangeNumberType - IncrementalFunction::value(const Point &p, - unsigned int comp) const - { - base.set_time(this->get_time()); - const RangeNumberType current = base.value(p, comp); - - base.set_time(this->get_time() - delta_t); - const RangeNumberType old = base.value(p, comp); - - return current - old; + // Reset wrapped function time setting + base.set_time(orig_time); }