OGS
ParameterLib::SymbolTableCache Struct Reference

Detailed Description

Cached pointers to the t, x, y, z symbol-table variables per thread. Eliminates string-based lookups during evaluation.

Definition at line 39 of file ExprtkUtils.h.

#include <ExprtkUtils.h>

Public Member Functions

 SymbolTableCache ()=default
 SymbolTableCache (exprtk::symbol_table< double > &symbol_table, bool spatial_position_is_required)
void reinitialize (exprtk::symbol_table< double > &symbol_table)
 Re-caches pointers from a (possibly moved) symbol_table.
void setTimeAndPosition (double t, SpatialPosition const &pos) const

Private Attributes

bool spatial_position_is_required_ = false
double * t_ptr = nullptr
double * x_ptr = nullptr
double * y_ptr = nullptr
double * z_ptr = nullptr

Constructor & Destructor Documentation

◆ SymbolTableCache() [1/2]

ParameterLib::SymbolTableCache::SymbolTableCache ( )
default

◆ SymbolTableCache() [2/2]

ParameterLib::SymbolTableCache::SymbolTableCache ( exprtk::symbol_table< double > & symbol_table,
bool spatial_position_is_required )

Caches pointers to t and, if spatial_position_is_required, to x, y, z from symbol_table. The invariant x_ptr/y_ptr/z_ptr are non-null iff spatial_position_is_required is true is established here.

Definition at line 99 of file ExprtkUtils.cpp.

101 : spatial_position_is_required_(spatial_position_is_required)
102{
103 reinitialize(symbol_table);
104}
void reinitialize(exprtk::symbol_table< double > &symbol_table)
Re-caches pointers from a (possibly moved) symbol_table.

References reinitialize(), and spatial_position_is_required_.

Member Function Documentation

◆ reinitialize()

void ParameterLib::SymbolTableCache::reinitialize ( exprtk::symbol_table< double > & symbol_table)

Re-caches pointers from a (possibly moved) symbol_table.

Definition at line 106 of file ExprtkUtils.cpp.

107{
108 t_ptr = &(symbol_table.get_variable("t")->ref());
110 {
111 x_ptr = &(symbol_table.get_variable("x")->ref());
112 y_ptr = &(symbol_table.get_variable("y")->ref());
113 z_ptr = &(symbol_table.get_variable("z")->ref());
114 }
115 else
116 {
117 x_ptr = nullptr;
118 y_ptr = nullptr;
119 z_ptr = nullptr;
120 }
121}

References spatial_position_is_required_, t_ptr, x_ptr, y_ptr, and z_ptr.

Referenced by SymbolTableCache().

◆ setTimeAndPosition()

void ParameterLib::SymbolTableCache::setTimeAndPosition ( double t,
SpatialPosition const & pos ) const

Sets t and, when spatial variables were registered (x/y/z_ptr != nullptr), also sets x, y, z from pos.

Definition at line 13 of file ExprtkUtils.cpp.

15{
16 // t_ptr is null only on a default-constructed cache, which exists solely
17 // to satisfy compilation of PerThreadData's (forbidden, OGS_FATAL) move
18 // ctor and is never evaluated against.
19 assert(t_ptr != nullptr);
20 *t_ptr = t;
21 // x_ptr is non-null iff the constructor was called with
22 // spatial_position_is_required=true; use it as the sentinel.
23 if (x_ptr != nullptr)
24 {
25 // Invariant: all three spatial pointers are set together.
26 assert(y_ptr != nullptr && z_ptr != nullptr);
27 if (!pos.getCoordinates())
28 {
30 "An expression requires spatial position (x, y, z), "
31 "but no coordinates have been set.");
32 }
33 auto const coords = pos.getCoordinates().value();
34 *x_ptr = coords[0];
35 *y_ptr = coords[1];
36 *z_ptr = coords[2];
37 }
38}
#define OGS_FATAL(...)
Definition Error.h:10
constexpr ranges::views::view_closure coords
Definition Mesh.h:230

References ParameterLib::SpatialPosition::getCoordinates(), OGS_FATAL, t_ptr, x_ptr, y_ptr, and z_ptr.

Member Data Documentation

◆ spatial_position_is_required_

bool ParameterLib::SymbolTableCache::spatial_position_is_required_ = false
private

Definition at line 57 of file ExprtkUtils.h.

Referenced by SymbolTableCache(), and reinitialize().

◆ t_ptr

double* ParameterLib::SymbolTableCache::t_ptr = nullptr
private

Definition at line 58 of file ExprtkUtils.h.

Referenced by reinitialize(), and setTimeAndPosition().

◆ x_ptr

double* ParameterLib::SymbolTableCache::x_ptr = nullptr
private

Definition at line 59 of file ExprtkUtils.h.

Referenced by reinitialize(), and setTimeAndPosition().

◆ y_ptr

double* ParameterLib::SymbolTableCache::y_ptr = nullptr
private

Definition at line 60 of file ExprtkUtils.h.

Referenced by reinitialize(), and setTimeAndPosition().

◆ z_ptr

double* ParameterLib::SymbolTableCache::z_ptr = nullptr
private

Definition at line 61 of file ExprtkUtils.h.

Referenced by reinitialize(), and setTimeAndPosition().


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