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::transport {
60
61using openswmm::RxToken;
62using openswmm::RxExprSpan;
65
68struct RxSymbols {
69 const std::vector<std::string>* species = nullptr;
70 const std::vector<std::string>* coefs = nullptr;
71 const std::vector<std::string>* terms = nullptr;
76 const std::vector<std::string>* pollutants = nullptr;
77 int max_term = 0;
78};
79
81struct RxEvalEnv {
82 const double* species = nullptr;
83 const double* coefs = nullptr;
84 const double* terms = nullptr;
85 const double* hydvar = nullptr;
86 const double* pollutants = nullptr;
87};
88
95std::string compileReactionExpression(const std::string& src,
96 const RxSymbols& symbols,
97 std::vector<RxToken>& pool,
98 RxExprSpan& out,
99 int& error_col);
100
101// ---------------------------------------------------------------------------
102// Vocabulary discovery (E-C1) — served from the compiler's OWN tables so the
103// GUI completer/highlighter (swmm_reaction_hydvar_* / swmm_reaction_
104// function_*) cannot drift from what actually compiles. Returned pointers
105// are static storage.
106// ---------------------------------------------------------------------------
107
111bool reactionFunctionInfo(int idx, const char** name, int* arity);
115bool reactionHydVarInfo(int idx, const char** name, const char** description);
116
118double evalReactionExpression(const std::vector<RxToken>& pool,
119 const RxExprSpan& span,
120 const RxEvalEnv& env) noexcept;
121
122} // namespace openswmm::transport
123
124#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:52
int reactionHydVarCount()
Number of built-in hydraulic variables.
Definition ReactionExpression.cpp:521
bool reactionFunctionInfo(int idx, const char **name, int *arity)
Name + arity of function idx; false when out of range.
Definition ReactionExpression.cpp:514
bool reactionHydVarInfo(int idx, const char **name, const char **description)
Name + one-line description of hydraulic variable idx.
Definition ReactionExpression.cpp:525
double evalReactionExpression(const std::vector< RxToken > &pool, const RxExprSpan &span, const RxEvalEnv &env) noexcept
Tier-1 evaluation: one pass, fixed-depth stack, allocation-free.
Definition ReactionExpression.cpp:456
int reactionFunctionCount()
Number of built-in functions.
Definition ReactionExpression.cpp:510
std::string compileReactionExpression(const std::string &src, const RxSymbols &symbols, std::vector< RxToken > &pool, RxExprSpan &out, int &error_col)
Compile src into the shared pool.
Definition ReactionExpression.cpp:191
constexpr int kRxMaxStackDepth
Definition ReactionTokens.hpp:84
RxHydVar
Definition ReactionTokens.hpp:41
Compiled expression = span into the shared pool. len 0 ⇒ no expression.
Definition ReactionTokens.hpp:77
Evaluation environment: pre-gathered pointers, no lookups.
Definition ReactionExpression.hpp:81
const double * pollutants
element pollutant conc (R4, read-only)
Definition ReactionExpression.hpp:86
const double * coefs
coefficient values
Definition ReactionExpression.hpp:83
const double * species
local species concentrations
Definition ReactionExpression.hpp:82
const double * terms
term values (evaluated in-order)
Definition ReactionExpression.hpp:84
const double * hydvar
RxHydVar::COUNT_ entries.
Definition ReactionExpression.hpp:85
Definition ReactionExpression.hpp:68
const std::vector< std::string > * coefs
Definition ReactionExpression.hpp:70
const std::vector< std::string > * pollutants
Definition ReactionExpression.hpp:76
const std::vector< std::string > * terms
Definition ReactionExpression.hpp:71
const std::vector< std::string > * species
local slots
Definition ReactionExpression.hpp:69
int max_term
forward-only rule: terms below this index only
Definition ReactionExpression.hpp:77