![]() |
OGS
|
|
Shared implementation for mathematical function evaluation using exprtk. Provides per-thread storage for thread-safe evaluation under OpenMP.
Definition at line 20 of file FunctionEvaluation.h.
#include <FunctionEvaluation.h>
Classes | |
| struct | PerThreadData |
Public Types | |
| using | Expression = exprtk::expression<double> |
| using | SymbolTable = exprtk::symbol_table<double> |
Public Member Functions | |
| FunctionEvaluation (int num_threads, std::vector< std::string > const &variables, std::vector< std::string > const &expression_strings, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves) | |
| std::vector< double > | evaluate (SpatialPosition const &pos, double t) const |
| void | evaluate (SpatialPosition const &pos, double t, std::span< double > result) const |
| int | getNumberOfComponents () const |
| Number of components (number of compiled value expressions). | |
| bool | isTimeDependent () const |
Private Attributes | |
| std::vector< PerThreadData > | per_thread_data_ |
| Per-thread evaluation context; indexed by omp_get_thread_num(). | |
| using ParameterLib::FunctionEvaluation::Expression = exprtk::expression<double> |
Definition at line 23 of file FunctionEvaluation.h.
| using ParameterLib::FunctionEvaluation::SymbolTable = exprtk::symbol_table<double> |
Definition at line 24 of file FunctionEvaluation.h.
| ParameterLib::FunctionEvaluation::FunctionEvaluation | ( | int | num_threads, |
| std::vector< std::string > const & | variables, | ||
| std::vector< std::string > const & | expression_strings, | ||
| std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const & | curves ) |
| num_threads | Number of threads for per-thread storage. |
| variables | Variable names to register in the symbol table. Spatial variables (x, y, z) are created only when they appear here. |
| expression_strings | Expression strings to compile. |
| curves | Named piecewise-linear curves available to expressions. |
Definition at line 18 of file FunctionEvaluation.cpp.
References ParameterLib::collectUsedCurveNames(), ParameterLib::collectVariables(), ParameterLib::hasSpatialVariables(), and per_thread_data_.
| std::vector< double > ParameterLib::FunctionEvaluation::evaluate | ( | SpatialPosition const & | pos, |
| double | t ) const |
Evaluate all value expressions at the given spatial position and time.
Although marked const, this method writes to per-thread symbol-table slots through cached pointers. Each OpenMP thread writes exclusively to its own slot, so concurrent calls from different threads do not race. The mathematical function itself is immutable after construction.
Definition at line 120 of file FunctionEvaluation.cpp.
References evaluate(), and per_thread_data_.
Referenced by evaluate().
| void ParameterLib::FunctionEvaluation::evaluate | ( | SpatialPosition const & | pos, |
| double | t, | ||
| std::span< double > | result ) const |
Evaluate all value expressions into a caller-provided output buffer.
No heap allocation is performed. Thread-safety is identical to the vector-returning overload.
| pos | Spatial position for evaluation. |
| t | Time for evaluation. |
| result | Must have size equal to getNumberOfComponents(). |
Definition at line 89 of file FunctionEvaluation.cpp.
References OGS_FATAL, and per_thread_data_.
| int ParameterLib::FunctionEvaluation::getNumberOfComponents | ( | ) | const |
Number of components (number of compiled value expressions).
Definition at line 129 of file FunctionEvaluation.cpp.
References per_thread_data_.
|
inline |
Definition at line 62 of file FunctionEvaluation.h.
|
private |
Per-thread evaluation context; indexed by omp_get_thread_num().
Definition at line 97 of file FunctionEvaluation.h.
Referenced by FunctionEvaluation(), evaluate(), evaluate(), and getNumberOfComponents().