OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
ReactionIntegrator.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
52
53#ifndef OPENSWMM_ENGINE_TRANSPORT_REACTION_INTEGRATOR_HPP
54#define OPENSWMM_ENGINE_TRANSPORT_REACTION_INTEGRATOR_HPP
55
56#include <string>
57#include <vector>
58
60
61namespace openswmm::transport {
62
67 bool ok = true;
68 int substeps = 0;
69 int newton_iters = 0;
70 std::string error;
71};
72
76public:
77 void init(const ReactionData& rx);
78 bool initialized() const noexcept { return n_ > 0 || terms_.capacity() > 0; }
79
80private:
81 friend class ReactionIntegrator;
82 int n_ = 0;
83 std::vector<double> terms_;
84 std::vector<double> y_, y0_, ytmp_, rates_, err_;
85 std::vector<double> k1_, k2_, k3_, k4_, k5_, k6_;
86 std::vector<double> jac_, lu_;
87 std::vector<int> piv_;
88 std::vector<int> rate_idx_, equil_idx_, formula_idx_;
89 std::vector<double> res_, res2_, dy_;
90 std::vector<double> grp_out_;
91
92 // FD-Jacobian / LU reuse across substeps. The Jacobian costs `gn` extra
93 // RHS evaluations, each of which re-evaluates every term and rate
94 // expression — the dominant per-substep cost once a system has more than
95 // a species or two. J depends on y (not on h), so it survives a step-size
96 // change; the FACTORED matrix I - c*h*J does not, hence the separate
97 // scale key.
98 bool jac_valid_ = false;
99 int jac_age_ = 0;
100 bool lu_valid_ = false;
101 double lu_scale_ = 0.0;
102};
103
105public:
117 static RxStepReport step(const ReactionData& rx, bool tank, double dt,
118 double* species, double* hydvar, RxWorkspace& ws,
119 const double* pollutants = nullptr);
120};
121
122} // namespace openswmm::transport
123
124#endif // OPENSWMM_ENGINE_TRANSPORT_REACTION_INTEGRATOR_HPP
Multispecies reaction system data (EPANET-MSX conventions) — SoA, hot/cold split per LARD plan §16 D-...
Definition ReactionIntegrator.hpp:104
static RxStepReport step(const ReactionData &rx, bool tank, double dt, double *species, double *hydvar, RxWorkspace &ws, const double *pollutants=nullptr)
One reaction step on one element's local species block.
Definition ReactionIntegrator.cpp:195
Definition ReactionIntegrator.hpp:75
friend class ReactionIntegrator
Definition ReactionIntegrator.hpp:81
void init(const ReactionData &rx)
Definition ReactionIntegrator.cpp:171
bool initialized() const noexcept
Definition ReactionIntegrator.hpp:78
Definition ExplicitFvSolver.hpp:52
Definition ReactionData.hpp:56
Definition ReactionIntegrator.hpp:66
int substeps
RATE substeps actually taken.
Definition ReactionIntegrator.hpp:68
bool ok
Definition ReactionIntegrator.hpp:67
std::string error
set when !ok
Definition ReactionIntegrator.hpp:70
int newton_iters
EQUIL + implicit-solver Newton iterations.
Definition ReactionIntegrator.hpp:69