OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
Treatment.hpp
Go to the documentation of this file.
1
32#ifndef OPENSWMM_TREATMENT_HPP
33#define OPENSWMM_TREATMENT_HPP
34
35#include <string>
36#include <vector>
37
38namespace openswmm {
39
40namespace treatment {
41
42// ============================================================================
43// Expression token types
44// ============================================================================
45
46enum class TokenType : int {
47 NUMBER = 0,
48 VARIABLE = 1,
49 ADD = 2,
50 SUB = 3,
51 MUL = 4,
52 DIV = 5,
53 POW = 6,
54 NEG = 7,
55 FUNC_EXP = 8,
56 FUNC_LOG = 9,
57 FUNC_SQRT = 10,
58 FUNC_MIN = 11,
59 FUNC_MAX = 12,
60 FUNC_ABS = 13,
61 FUNC_SGN = 14,
62 FUNC_STEP = 15,
63 LPAREN = 16,
64 RPAREN = 17,
65 COMMA = 18
66};
67
68enum class TreatVar : int {
69 C = 0,
70 R = 1,
71 DT = 2,
72 HRT = 3,
73 Q = 4,
74 V = 5,
75 D = 6
76};
77
78// ============================================================================
79// Expression token
80// ============================================================================
81
87
88// ============================================================================
89// Treatment expression (parsed, ready to evaluate)
90// ============================================================================
91
92struct TreatExpr {
93 std::vector<Token> tokens;
94 int pollutant_idx = -1;
95 bool is_removal = false;
96};
97
98// ============================================================================
99// Functions
100// ============================================================================
101
119int parse(const std::string& expr_str, TreatExpr& result);
120
133double evaluate(const TreatExpr& expr, double c, double dt,
134 double hrt, double q, double v, double d);
135
154double applyTreatment(const TreatExpr& expr, double c_in, double dt,
155 double hrt, double q, double v, double d);
156
157} // namespace treatment
158} // namespace openswmm
159
160#endif // OPENSWMM_TREATMENT_HPP
double applyTreatment(const TreatExpr &expr, double c_in, double dt, double hrt, double q, double v, double d)
Apply treatment at a node for one pollutant.
Definition Treatment.cpp:427
TokenType
Definition Treatment.hpp:46
@ LPAREN
Left parenthesis (parser internal, never in output)
@ COMMA
Comma separator for min/max (parser internal)
@ RPAREN
Right parenthesis (parser internal, never in output)
TreatVar
Definition Treatment.hpp:68
@ C
Current concentration.
@ HRT
Hydraulic residence time (hours, per legacy convention)
@ R
Removal fraction target.
int parse(const std::string &expr_str, TreatExpr &result)
Parse a treatment expression string into postfix tokens.
Definition Treatment.cpp:260
double evaluate(const TreatExpr &expr, double c, double dt, double hrt, double q, double v, double d)
Evaluate a treatment expression with given variable values.
Definition Treatment.cpp:315
Definition Controls.cpp:24
Definition Treatment.hpp:82
double value
For NUMBER tokens.
Definition Treatment.hpp:84
TokenType type
Definition Treatment.hpp:83
TreatVar var
For VARIABLE tokens.
Definition Treatment.hpp:85
Definition Treatment.hpp:92
bool is_removal
True if expression computes R (removal), false if C.
Definition Treatment.hpp:95
std::vector< Token > tokens
Postfix (RPN) token list.
Definition Treatment.hpp:93
int pollutant_idx
Which pollutant this expression applies to.
Definition Treatment.hpp:94