OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
INetworkSolver.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
39
40#ifndef OPENSWMM_ENGINE_FV_I_NETWORK_SOLVER_HPP
41#define OPENSWMM_ENGINE_FV_I_NETWORK_SOLVER_HPP
42
43namespace openswmm::fv {
44
45// Forward declarations — passed by reference, no definitions needed here.
46struct NetworkMeshData;
47struct NetworkStateData;
48struct FvOptions;
49
61 const double* node_lateral = nullptr;
62
66 const double* node_fixed_head = nullptr;
67
76 const double* structure_flow = nullptr;
77
83 const double* link_q_cap = nullptr;
84
87 const double* conduit_loss = nullptr;
88
102 void (*refresh)(void* user, double t_elapsed) = nullptr;
103 void* refresh_user = nullptr;
104
105 int n_nodes = 0;
106 int n_links = 0;
107};
108
122public:
123 virtual ~INetworkSolver() = default;
124
126 virtual void initialize(NetworkMeshData& mesh, NetworkStateData& state,
127 const FvOptions& opts) = 0;
128
131 virtual double advance(double t_current, double t_target,
132 const FvStepForcing& forcing) = 0;
133
135 virtual void reinitialize(double t0) = 0;
136
138 virtual void finalize() = 0;
139
141 virtual long last_num_steps() const noexcept = 0;
142
144 virtual double last_step_size() const noexcept = 0;
145
149 virtual double suggested_step() const noexcept = 0;
150
153 struct RunStats {
154 long nsteps = 0;
155 long nflux = 0;
156 double last_h = 0.0;
157 double avg_h = 0.0;
158 double min_h = 0.0;
159
160 // Work-list compaction telemetry. Negative fractions mean "not
161 // populated" (compaction disabled or never sampled).
162 double active_frac_min = -1.0;
163 double active_frac_mean = -1.0;
164 double active_frac_max = -1.0;
165
166 long tier_cells[8] = {0};
167 int n_tiers = 0;
168
169 // dt-argmin attribution (slot program R0): which regime owned the
170 // binding CFL element, counted once per census (global path) or
171 // re-tier (LTS path). Answers "who sets the step" without a trace.
173 long dt_argmin_band = 0;
174 long dt_argmin_free = 0;
175 long dt_argmin_node = 0;
176 };
177
179 virtual RunStats run_stats() const noexcept { return {}; }
180
188 struct Divergence {
189 int link = -1;
190 double value = 0.0;
191 const char* what = nullptr;
192 };
193
197 virtual bool divergence(Divergence& d) const noexcept {
198 (void)d;
199 return false;
200 }
201
203 virtual bool is_initialized() const noexcept = 0;
204};
205
206} // namespace openswmm::fv
207
208#endif // OPENSWMM_ENGINE_FV_I_NETWORK_SOLVER_HPP
Abstract time integrator for the explicit FV 1D network.
Definition INetworkSolver.hpp:121
virtual void reinitialize(double t0)=0
Reinitialize at t0 after external state edits (hot start, API writes).
virtual ~INetworkSolver()=default
virtual long last_num_steps() const noexcept=0
Substep count used by the last advance() call.
virtual double last_step_size() const noexcept=0
Last internal substep size (s).
virtual double suggested_step() const noexcept=0
virtual void finalize()=0
Release all backend resources.
virtual bool divergence(Divergence &d) const noexcept
Definition INetworkSolver.hpp:197
virtual RunStats run_stats() const noexcept
Read cumulative statistics. Default: zeros (backend has no counters).
Definition INetworkSolver.hpp:179
virtual double advance(double t_current, double t_target, const FvStepForcing &forcing)=0
virtual bool is_initialized() const noexcept=0
True once initialize() has completed and the solver is ready.
virtual void initialize(NetworkMeshData &mesh, NetworkStateData &state, const FvOptions &opts)=0
One-time setup. mesh, state and opts must outlive the solver.
Definition ExplicitFvSolver.cpp:25
Knobs for FLOW_ROUTING FV.
Definition FvOptions.hpp:123
Definition INetworkSolver.hpp:53
const double * conduit_loss
Definition INetworkSolver.hpp:87
int n_nodes
Definition INetworkSolver.hpp:105
const double * node_lateral
Definition INetworkSolver.hpp:61
int n_links
Definition INetworkSolver.hpp:106
void * refresh_user
Definition INetworkSolver.hpp:103
const double * node_fixed_head
Definition INetworkSolver.hpp:66
void(* refresh)(void *user, double t_elapsed)
Definition INetworkSolver.hpp:102
const double * link_q_cap
Definition INetworkSolver.hpp:83
const double * structure_flow
Definition INetworkSolver.hpp:76
Definition INetworkSolver.hpp:188
double value
offending magnitude (internal units)
Definition INetworkSolver.hpp:190
const char * what
"velocity (ft/s)" | "depth (ft)"
Definition INetworkSolver.hpp:191
int link
engine link index of the offender
Definition INetworkSolver.hpp:189
Definition INetworkSolver.hpp:153
long dt_argmin_pressurized
h ≥ y_full (slot celerity)
Definition INetworkSolver.hpp:172
double min_h
smallest substep taken (s)
Definition INetworkSolver.hpp:158
long dt_argmin_free
open-channel cell
Definition INetworkSolver.hpp:174
long nflux
face flux evaluations
Definition INetworkSolver.hpp:155
long dt_argmin_node
node storage / feedback bound
Definition INetworkSolver.hpp:175
double avg_h
sim-time / nsteps (s)
Definition INetworkSolver.hpp:157
long tier_cells[8]
cumulative rebuild-sampled cells per LTS tier
Definition INetworkSolver.hpp:166
long nsteps
explicit substeps
Definition INetworkSolver.hpp:154
int n_tiers
populated tier count (≤ 8)
Definition INetworkSolver.hpp:167
double last_h
last substep (s)
Definition INetworkSolver.hpp:156
double active_frac_mean
Definition INetworkSolver.hpp:163
long dt_argmin_band
y_crown ≤ h < y_full (mouth)
Definition INetworkSolver.hpp:173
double active_frac_max
Definition INetworkSolver.hpp:164
double active_frac_min
Definition INetworkSolver.hpp:162
SoA mesh geometry and topology for the FV network solver.
Definition NetworkMeshData.hpp:176
Mutable solver state — the conserved variables and the node volumes.
Definition NetworkMeshData.hpp:489