OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
ReactionExpression.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2//
3// Copyright 2026 Caleb Buahin
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
50
51#ifndef OPENSWMM_ENGINE_TRANSPORT_REACTION_EXPRESSION_HPP
52#define OPENSWMM_ENGINE_TRANSPORT_REACTION_EXPRESSION_HPP
53
54#include <string>
55#include <vector>
56
58
59namespace openswmm {
60struct ReactionData;
61}
62namespace openswmm::transport {
63
65std::string reactionContextDiagnostic(const ReactionData&, const std::vector<RxToken>&,
66 const RxExprSpan&, int context);
67
68using openswmm::RxToken;
69using openswmm::RxExprSpan;
72
75struct RxSymbols {
76 const std::vector<std::string>* species = nullptr;
77 const std::vector<std::string>* coefs = nullptr;
78 const std::vector<std::string>* terms = nullptr;
83 const std::vector<std::string>* pollutants = nullptr;
84 int max_term = 0;
85};
86
88struct RxEvalEnv {
89 const double* species = nullptr;
90 const double* coefs = nullptr;
91 const double* terms = nullptr;
92 const double* hydvar = nullptr;
93 const double* pollutants = nullptr;
94};
95
102std::string compileReactionExpression(const std::string& src, const RxSymbols& symbols,
103 std::vector<RxToken>& pool, RxExprSpan& out, int& error_col);
104
105// ---------------------------------------------------------------------------
106// Vocabulary discovery (E-C1) — served from the compiler's OWN tables so the
107// GUI completer/highlighter (swmm_reaction_hydvar_* / swmm_reaction_
108// function_*) cannot drift from what actually compiles. Returned pointers
109// are static storage.
110// ---------------------------------------------------------------------------
111
115bool reactionFunctionInfo(int idx, const char** name, int* arity);
119bool reactionHydVarInfo(int idx, const char** name, const char** description);
120
124bool reactionHydVarPopulated(int idx);
125
130std::string unpopulatedHydVarDiagnostic(const std::string& src, const std::vector<RxToken>& pool,
131 const RxExprSpan& span, int& error_col);
132
134double evalReactionExpression(const std::vector<RxToken>& pool, const RxExprSpan& span,
135 const RxEvalEnv& env) noexcept;
136
137} // namespace openswmm::transport
138
139#endif // OPENSWMM_ENGINE_TRANSPORT_REACTION_EXPRESSION_HPP
POD reaction-VM instruction + span types (phase R2, D-L3 flat pool). Data-layer header: no dependenci...
Definition ExplicitFvSolver.hpp:53
int reactionHydVarCount()
Read number of declared hydraulic/thermal/groundwater expression variables.
Definition ReactionExpression.cpp:724
std::string unpopulatedHydVarDiagnostic(const std::string &src, const std::vector< RxToken > &pool, const RxExprSpan &span, int &error_col)
Report first compiled hydraulic variable not in the network-populated range.
Definition ReactionExpression.cpp:826
bool reactionFunctionInfo(int idx, const char **name, int *arity)
Read name and argument count of one supported expression function.
Definition ReactionExpression.cpp:709
std::string reactionContextDiagnostic(const ReactionData &rx, const std::vector< RxToken > &pool, const RxExprSpan &span, int context)
Recursively reject hydraulic/species/pollutant references unavailable in one reactor context.
Definition ReactionExpression.cpp:763
bool reactionHydVarInfo(int idx, const char **name, const char **description)
Read canonical variable name and description including its declared units/support.
Definition ReactionExpression.cpp:737
double evalReactionExpression(const std::vector< RxToken > &pool, const RxExprSpan &span, const RxEvalEnv &env) noexcept
Evaluate a validated compiled reaction span with stack-local scratch.
Definition ReactionExpression.cpp:591
bool reactionHydVarPopulated(int idx)
Test the network-quality variable range currently populated by native routing.
Definition ReactionExpression.cpp:809
int reactionFunctionCount()
Read number of supported compiled scalar function entries.
Definition ReactionExpression.cpp:697
std::string compileReactionExpression(const std::string &src, const RxSymbols &symbols, std::vector< RxToken > &pool, RxExprSpan &out, int &error_col)
Compile an infix scalar reaction expression into appended stack-machine tokens.
Definition ReactionExpression.cpp:294
Definition ExchangeLaw.hpp:60
constexpr int kRxMaxStackDepth
Definition ReactionTokens.hpp:102
RxHydVar
Definition ReactionTokens.hpp:41
Definition ReactionData.hpp:58
Compiled expression = span into the shared pool. len 0 ⇒ no expression.
Definition ReactionTokens.hpp:95
Evaluation environment: pre-gathered pointers, no lookups.
Definition ReactionExpression.hpp:88
const double * pollutants
element pollutant conc (R4, read-only)
Definition ReactionExpression.hpp:93
const double * coefs
coefficient values
Definition ReactionExpression.hpp:90
const double * species
local species concentrations
Definition ReactionExpression.hpp:89
const double * terms
term values (evaluated in-order)
Definition ReactionExpression.hpp:91
const double * hydvar
RxHydVar::COUNT_ entries.
Definition ReactionExpression.hpp:92
Definition ReactionExpression.hpp:75
const std::vector< std::string > * coefs
Definition ReactionExpression.hpp:77
const std::vector< std::string > * pollutants
Definition ReactionExpression.hpp:83
const std::vector< std::string > * terms
Definition ReactionExpression.hpp:78
const std::vector< std::string > * species
local slots
Definition ReactionExpression.hpp:76
int max_term
forward-only rule: terms below this index only
Definition ReactionExpression.hpp:84