OGS
FunctionEvaluation.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <map>
7#include <memory>
8#include <span>
9#include <string>
10#include <vector>
11
12#include "ExprtkUtils.h"
13#include "SpatialPosition.h"
14
15namespace ParameterLib
16{
17
21{
22public:
23 using Expression = exprtk::expression<double>;
24 using SymbolTable = exprtk::symbol_table<double>;
25
34 int num_threads,
35 std::vector<std::string> const& variables,
36 std::vector<std::string> const& expression_strings,
37 std::map<std::string,
38 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
39 curves);
40
47 std::vector<double> evaluate(SpatialPosition const& pos, double t) const;
48
56 void evaluate(SpatialPosition const& pos, double t,
57 std::span<double> result) const;
58
60 int getNumberOfComponents() const;
61
62 bool isTimeDependent() const { return true; }
63
64private:
69 {
71 std::vector<std::string> const& variables,
72 bool spatial_position_is_required,
73 std::vector<std::string> const& used_curve_names,
74 std::map<
75 std::string,
76 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
77 curves,
78 std::vector<std::string> const& expression_strings);
79
81 PerThreadData& operator=(PerThreadData&& other) noexcept = delete;
82 PerThreadData(PerThreadData const&) = delete;
84
86 std::map<std::string, CurveWrapper> curve_wrappers;
91 std::vector<Expression> value_expressions;
94 };
95
97 std::vector<PerThreadData> per_thread_data_;
98};
99
100} // namespace ParameterLib
std::vector< double > evaluate(SpatialPosition const &pos, double t) const
exprtk::symbol_table< double > SymbolTable
exprtk::expression< double > Expression
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)
int getNumberOfComponents() const
Number of components (number of compiled value expressions).
std::vector< PerThreadData > per_thread_data_
Per-thread evaluation context; indexed by omp_get_thread_num().
std::map< std::string, CurveWrapper > curve_wrappers
Curve wrappers owned by this thread; must outlive symbol_table.
PerThreadData(std::vector< std::string > const &variables, bool spatial_position_is_required, std::vector< std::string > const &used_curve_names, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves, std::vector< std::string > const &expression_strings)
SymbolTableCache symbol_table_cache
Cached pointers to t, x, y, z inside symbol_table.
PerThreadData(PerThreadData const &)=delete
std::vector< Expression > value_expressions
Compiled value expressions. Must be destroyed before symbol_table.
PerThreadData & operator=(PerThreadData const &)=delete
PerThreadData & operator=(PerThreadData &&other) noexcept=delete