OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
TimeDependenceCache.h
Go to the documentation of this file.
1//
2// Class TimeDependenceCache
3// A class that accesses a time dependence through a short cache
4// The cache should be just long enough so that the Runge-Kutta calls
5// for a single step fit inside.
6// The cache consists of an array of values used in a circular buffer
7// manner, so the last few calls for a time are stored.
8// The cache is short to keep search times very low.
9//
10// Copyright (c) 2025, Jon Thompson, STFC Rutherford Appleton Laboratory, Didcot, UK
11//
12// This file is part of OPAL.
13//
14// OPAL is free software: you can redistribute it and/or modify
15// it under the terms of the GNU General Public License as published by
16// the Free Software Foundation, either version 3 of the License, or
17// (at your option) any later version.
18//
19// You should have received a copy of the GNU General Public License
20// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
21//
22
23#ifndef OPAL_TIMEDEPENDENCECACHE_H
24#define OPAL_TIMEDEPENDENCECACHE_H
25
27#include <array>
28
30public:
31 static constexpr size_t CacheSize = 6;
32
33 struct Item {
34 double time_m;
35 double value_m;
36 double integral_m;
37 };
38
39 void setTimeDependence(AbstractTimeDependence* timeDependence);
40 double getValue(double time);
41 double getIntegral(double time);
42 void reset();
43 size_t getHead() const { return head_m; }
47
48private:
50
51 std::array<Item, CacheSize> cache_m{};
52 size_t head_m{};
53
54 const Item& placeInCache(double time);
55};
56
57#endif // OPAL_TIMEDEPENDENCECACHE_H
std::string::iterator iterator
Definition: MSLang.h:15
Time dependence abstraction for field parameters that vary slowly with time; for example,...
std::array< Item, CacheSize > cache_m
const Item & placeInCache(double time)
double getIntegral(double time)
std::array< Item, CacheSize >::iterator find(double time)
static constexpr size_t CacheSize
AbstractTimeDependence * timeDependence_m
std::array< Item, CacheSize >::iterator begin()
std::array< Item, CacheSize >::iterator end()
void setTimeDependence(AbstractTimeDependence *timeDependence)
double getValue(double time)