OpenSWMM Engine  6.0.0-alpha.3
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.3)
Loading...
Searching...
No Matches
Treatment.hpp
Go to the documentation of this file.
1
31
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,
49 ADD = 2,
50 SUB = 3,
51 MUL = 4,
52 DIV = 5,
53 POW = 6,
54 NEG = 7,
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,
78 AREA = 9
79};
80
81// ============================================================================
82// Expression token
83// ============================================================================
84
91
92// ============================================================================
93// Treatment expression (parsed, ready to evaluate)
94// ============================================================================
95
96struct TreatExpr {
97 std::vector<Token> tokens;
98 int pollutant_idx = -1;
99 bool is_removal = false;
100};
101
102// ============================================================================
103// Functions
104// ============================================================================
105
123int parse(const std::string& expr_str, TreatExpr& result);
124
133int parse(const std::string& expr_str, TreatExpr& result,
134 int (*pollut_lookup)(const std::string& name));
135
148double evaluate(const TreatExpr& expr, double c, double dt,
149 double hrt, double q, double v, double d, double area = 0.0);
150
167double evaluate(const TreatExpr& expr, double c, double dt,
168 double hrt, double q, double v, double d,
169 const double* cin, const double* removal, int n_pollut,
170 double area = 0.0);
171
190double applyTreatment(const TreatExpr& expr, double c_in, double dt,
191 double hrt, double q, double v, double d, double area = 0.0);
192
193} // namespace treatment
194} // namespace openswmm
195
196#endif // OPENSWMM_TREATMENT_HPP
Definition Treatment.cpp:26
double applyTreatment(const TreatExpr &expr, double c_in, double dt, double hrt, double q, double v, double d, double area)
Apply treatment at a node for one pollutant.
Definition Treatment.cpp:445
TokenType
Definition Treatment.hpp:46
@ POW
Definition Treatment.hpp:53
@ SUB
Definition Treatment.hpp:50
@ DIV
Definition Treatment.hpp:52
@ MUL
Definition Treatment.hpp:51
@ NUMBER
Definition Treatment.hpp:47
@ LPAREN
Left parenthesis (parser internal, never in output)
Definition Treatment.hpp:63
@ FUNC_SQRT
Definition Treatment.hpp:57
@ COMMA
Comma separator for min/max (parser internal)
Definition Treatment.hpp:65
@ NEG
Unary negation.
Definition Treatment.hpp:54
@ FUNC_MIN
Definition Treatment.hpp:58
@ FUNC_SGN
Definition Treatment.hpp:61
@ FUNC_MAX
Definition Treatment.hpp:59
@ FUNC_LOG
Definition Treatment.hpp:56
@ FUNC_STEP
Heaviside step.
Definition Treatment.hpp:62
@ ADD
Definition Treatment.hpp:49
@ FUNC_EXP
Definition Treatment.hpp:55
@ VARIABLE
Definition Treatment.hpp:48
@ FUNC_ABS
Definition Treatment.hpp:60
@ RPAREN
Right parenthesis (parser internal, never in output)
Definition Treatment.hpp:64
double evaluate(const TreatExpr &expr, double c, double dt, double hrt, double q, double v, double d, double area)
Evaluate a treatment expression with given variable values.
Definition Treatment.cpp:330
TreatVar
Definition Treatment.hpp:68
@ C
Current concentration (this pollutant)
Definition Treatment.hpp:69
@ R_POLLUT
Removal fraction of another pollutant (uses pollut_ref, co-treatment)
Definition Treatment.hpp:77
@ C_POLLUT
Concentration of another pollutant (uses pollut_ref)
Definition Treatment.hpp:76
@ HRT
Hydraulic residence time (hours, per legacy convention)
Definition Treatment.hpp:72
@ DT
Timestep (sec)
Definition Treatment.hpp:71
@ V
Volume (ft3 or m3)
Definition Treatment.hpp:74
@ AREA
Node surface area in user units² ((a1+a2)/2*UCF(LENGTH)², matching legacy pvAREA)
Definition Treatment.hpp:78
@ R
Removal fraction (this pollutant, unused in expressions)
Definition Treatment.hpp:70
@ Q
Flow rate in user units (Q*UCF(FLOW), matching legacy pvFLOW)
Definition Treatment.hpp:73
@ D
Depth in user units (y*UCF(LENGTH), matching legacy pvDEPTH)
Definition Treatment.hpp:75
int parse(const std::string &expr_str, TreatExpr &result)
Parse a treatment expression string into postfix tokens.
Definition Treatment.cpp:275
Definition NodeCoupling.cpp:15
Definition Treatment.hpp:85
double value
For NUMBER tokens.
Definition Treatment.hpp:87
int pollut_ref
Pollutant index for C_POLLUT/R_POLLUT.
Definition Treatment.hpp:89
TokenType type
Definition Treatment.hpp:86
TreatVar var
For VARIABLE tokens.
Definition Treatment.hpp:88
Definition Treatment.hpp:96
bool is_removal
True if expression computes R (removal), false if C.
Definition Treatment.hpp:99
std::vector< Token > tokens
Postfix (RPN) token list.
Definition Treatment.hpp:97
int pollutant_idx
Which pollutant this expression applies to.
Definition Treatment.hpp:98