Cantera 2.6.0

Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
ValueCache Class Reference

`#include <ValueCache.h>`

## Public Member Functions
int | getId ()
| Get a unique id for a cached value. More...
CachedScalar | getScalar (int id)
| Get a reference to a CachedValue object representing a scalar (doublereal) with the given id. More...
CachedArray | getArray (int id)
| Get a reference to a CachedValue object representing an array (vector_fp) with the given id. More...
void | clear ()
| Clear all cached values. More...

## Protected Attributes
std::map< int, CachedValue< double > > | m_scalarCache
| Cached scalar values. More...
std::map< int, CachedValue< vector_fp > > | m_arrayCache
| Cached array values. More...

## Static Protected Attributes
static int | m_last_id = 0
| The last assigned id. Automatically incremented by the getId() method. More...

## Detailed Description

Storage for cached values

Stores cached values of properties evaluated at a particular thermodynamic state. A class that needs cached values can have a ValueCache as a member variable.

Each method in the class that implements caching behavior needs a unique id for its cached value. This id should be obtained by using the getId() function to initialize a static variable within the function.

For cases where the property is a scalar or vector, the cached value can be stored in the CachedValue object. If the data type of the cached value is more complex, then it can be stored in the calling class, and the value attribute of the CachedScalar object can be ignored.

An example use of class ValueCache:

class Example {
ValueCache m_cache;
doublereal get_property(doublereal T, doublereal P) {
const static int cacheId = m_cache.getId();
CachedScalar cached = m_cache.getScalar(cacheId);
if (T != cached.state1 || P != cached.state2) {
cached.value = some_expensive_function(T,P);
cached.state1 = T;
cached.state2 = P;
}
return cached.value;
}
};
Cantera::ValueCache
Definition: ValueCache.h:157
Cantera::ValueCache::getScalar
CachedScalar getScalar(int id)
Get a reference to a CachedValue object representing a scalar (doublereal) with the given id.
Definition: ValueCache.h:165
Cantera::ValueCache::getId
int getId()
Get a unique id for a cached value.
Definition: ValueCache.cpp:21
Cantera::CachedValue
Definition: ValueCache.h:32
Cantera::CachedValue::state2
double state2
Value of the second state variable for the state at which value was evaluated, for example density or...
Definition: ValueCache.h:111
Cantera::CachedValue::value
T value
The value of the cached property.
Definition: ValueCache.h:118
Cantera::CachedValue::state1
double state1
Value of the first state variable for the state at which value was evaluated, for example temperature...
Definition: ValueCache.h:107

Definition at line 156 of file ValueCache.h.

## Member Function Documentation

## ◆ getId()

int getId | ( |  | ) |

Get a unique id for a cached value.

Must be called exactly once for each method that implements caching behavior.

Definition at line 21 of file ValueCache.cpp.

References ValueCache::m_last_id.

Referenced by HMWSoln::calcDensity(), HMWSoln::s_update_d2lnMolalityActCoeff_dT2(), HMWSoln::s_update_dlnMolalityActCoeff_dP(), HMWSoln::s_update_dlnMolalityActCoeff_dT(), IdealGasPhase::updateThermo(), and PlasmaPhase::updateThermo().

## ◆ getScalar()

CachedScalar getScalar | ( | int | id | ) |
| inline

Get a reference to a CachedValue object representing a scalar (doublereal) with the given id.

Definition at line 165 of file ValueCache.h.

References ValueCache::m_scalarCache.

Referenced by HMWSoln::calcDensity(), HMWSoln::s_update_d2lnMolalityActCoeff_dT2(), HMWSoln::s_update_dlnMolalityActCoeff_dP(), HMWSoln::s_update_dlnMolalityActCoeff_dT(), IdealGasPhase::updateThermo(), and PlasmaPhase::updateThermo().

## ◆ getArray()

CachedArray getArray | ( | int | id | ) |
| inline

Get a reference to a CachedValue object representing an array (vector_fp) with the given id.

Definition at line 171 of file ValueCache.h.

References ValueCache::m_arrayCache.

## ◆ clear()

void clear | ( |  | ) |

Clear all cached values.

This method should be called if the cached values may be invalidated in a way that is not represented by the state variables alone, such as a change to the constants defining a species thermodynamics as a function of temperature.

Definition at line 27 of file ValueCache.cpp.

References ValueCache::m_arrayCache, and ValueCache::m_scalarCache.

Referenced by Phase::invalidateCache().

## Member Data Documentation

## ◆ m_scalarCache

std::map<int, CachedValue<double> > m_scalarCache
| protected

Cached scalar values.

Definition at line 183 of file ValueCache.h.

Referenced by ValueCache::clear(), and ValueCache::getScalar().

## ◆ m_arrayCache

std::map<int, CachedValue<vector_fp> > m_arrayCache
| protected

Cached array values.

Definition at line 186 of file ValueCache.h.

Referenced by ValueCache::clear(), and ValueCache::getArray().

## ◆ m_last_id

int m_last_id = 0
| static protected

The last assigned id. Automatically incremented by the getId() method.

Definition at line 189 of file ValueCache.h.

Referenced by ValueCache::getId().

The documentation for this class was generated from the following files:

- ValueCache.h
- ValueCache.cpp