https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MemoizedFunctionInterface.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#include <map>
13
14#include "Function.h"
15
16#include "Hashing.h"
17
24{
25public:
27
29
30 // Override from MeshChangedInterface
31 virtual void meshChanged() override;
32
36 void useCache(bool use);
37
38 using Function::value;
39 // Make this implementation of Function::value() final so derived classes cannot bypass the
40 // memoization functionality it implements. Instead, deriving classes should implement
41 // evaluateValue().
42 virtual Real value(Real time, const Point & point) const final;
43 virtual ADReal value(const ADReal & time, const ADPoint & point) const final;
44
45protected:
49 virtual Real evaluateValue(Real time, const Point & point) = 0;
50
54 void invalidateCache();
55
56private:
58 mutable std::unordered_map<hashing::HashValue, Real> _cache;
59
61 mutable Real _current_time;
62
65
68};
DualNumber< Real, DNDerivativeType, true > ADReal
virtual Real value(Real t, const Point &p) const
Implementation of Function that memoizes (caches) former evaluations in an unordered map using a hash...
virtual Real value(Real time, const Point &point) const final
bool _respect_time
Flag for whether changes in time invalidate the cache.
void invalidateCache()
Called by derived classes to invalidate the cache, perhaps due to a state change.
void useCache(bool use)
Enable/disable the cache.
virtual Real evaluateValue(Real time, const Point &point)=0
Used in derived classes, equivalent to Function::value()
Real _current_time
Stores the time evaluation of the cache.
virtual void meshChanged() override
bool _enable_cache
Flag for whether to cache values.
std::unordered_map< hashing::HashValue, Real > _cache
Cached evaluations for each point.
static InputParameters validParams()
const InputParameters & parameters() const