OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
openswmm::mathexpr Namespace Reference

Classes

struct  Expression
 
struct  Token
 

Enumerations

enum class  TokenType : int {
  NUMBER = 0 ,
  VARIABLE = 1 ,
  ADD = 2 ,
  SUB = 3 ,
  MUL = 4 ,
  DIV = 5 ,
  POW = 6 ,
  NEG = 7 ,
  LPAREN = 8 ,
  RPAREN = 9 ,
  FUNC_ABS = 10 ,
  FUNC_SGN = 11 ,
  FUNC_SQRT = 12 ,
  FUNC_LOG = 13 ,
  FUNC_EXP = 14 ,
  FUNC_SIN = 15 ,
  FUNC_COS = 16 ,
  FUNC_TAN = 17 ,
  FUNC_ASIN = 18 ,
  FUNC_ACOS = 19 ,
  FUNC_ATAN = 20 ,
  FUNC_STEP = 21 ,
  FUNC_MIN = 22 ,
  FUNC_MAX = 23 ,
  COMMA = 24
}
 

Functions

int parse (const std::string &expr_str, Expression &result)
 Parse an infix expression string into a postfix Expression.
 
double evaluate (const Expression &expr, const std::function< double(const std::string &)> &var_lookup)
 Evaluate a compiled expression with named variable lookup.
 
double evaluate (const Expression &expr, const double *vars, int n_vars)
 Evaluate with a flat variable array (by index).
 

Enumeration Type Documentation

◆ TokenType

enum class openswmm::mathexpr::TokenType : int
strong
Enumerator
NUMBER 
VARIABLE 
ADD 
SUB 
MUL 
DIV 
POW 
NEG 
LPAREN 
RPAREN 
FUNC_ABS 
FUNC_SGN 
FUNC_SQRT 
FUNC_LOG 
FUNC_EXP 
FUNC_SIN 
FUNC_COS 
FUNC_TAN 
FUNC_ASIN 
FUNC_ACOS 
FUNC_ATAN 
FUNC_STEP 
FUNC_MIN 
FUNC_MAX 
COMMA 

Function Documentation

◆ evaluate() [1/2]

double openswmm::mathexpr::evaluate ( const Expression expr,
const double *  vars,
int  n_vars 
)

Evaluate with a flat variable array (by index).

Parameters
exprCompiled expression.
varsVariable values indexed by var_idx.
n_varsSize of vars array.
Returns
Expression result.
Here is the call graph for this function:

◆ evaluate() [2/2]

double openswmm::mathexpr::evaluate ( const Expression expr,
const std::function< double(const std::string &)> &  var_lookup 
)

Evaluate a compiled expression with named variable lookup.

Parameters
exprCompiled expression.
var_lookupFunction that maps variable name → value.
Returns
Expression result.
Here is the caller graph for this function:

◆ parse()

int openswmm::mathexpr::parse ( const std::string &  expr_str,
Expression result 
)

Parse an infix expression string into a postfix Expression.

Parameters
expr_strInfix expression (e.g., "x * exp(-k * t)").
result[out] Compiled postfix expression.
Returns
0 on success, -1 on parse error.
Here is the caller graph for this function: