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
44
45#ifndef OPENSWMM_ENGINE_FV_I_NETWORK_SOLVER_HPP
46#define OPENSWMM_ENGINE_FV_I_NETWORK_SOLVER_HPP
47
48namespace openswmm::fv {
49
50// Forward declarations — passed by reference, no definitions needed here.
51struct NetworkMeshData;
52struct NetworkStateData;
53struct FvOptions;
54
66 const double* node_lateral = nullptr;
67
71 const double* node_fixed_head = nullptr;
72
75 const double* node_source_max = nullptr;
76
85 const double* structure_flow = nullptr;
86
92 const double* link_q_cap = nullptr;
93
96 const double* conduit_loss = nullptr;
97
111 void (*refresh)(void* user, double t_elapsed) = nullptr;
112 void* refresh_user = nullptr;
113
114 int n_nodes = 0;
115 int n_links = 0;
119 const double* node_withdrawal = nullptr;
120
121};
122
136public:
143 virtual ~INetworkSolver() = default;
144
158 virtual void initialize(NetworkMeshData& mesh, NetworkStateData& state,
159 const FvOptions& opts) = 0;
160
174 virtual double advance(double t_current, double t_target, const FvStepForcing& forcing) = 0;
175
185 virtual void reinitialize(double t0) = 0;
186
188 virtual void finalize() = 0;
189
191 virtual long last_num_steps() const noexcept = 0;
192
194 virtual double last_step_size() const noexcept = 0;
195
201 virtual double suggested_step() const noexcept = 0;
202
205 struct RunStats {
206 long nsteps = 0;
207 long nflux = 0;
208 double last_h = 0.0;
209 double avg_h = 0.0;
210 double min_h = 0.0;
211
212 // Work-list compaction telemetry. Negative fractions mean "not
213 // populated" (compaction disabled or never sampled).
214 double active_frac_min = -1.0;
215 double active_frac_mean = -1.0;
216 double active_frac_max = -1.0;
217
218 long tier_cells[8] = {0};
219 int n_tiers = 0;
220
221 // dt-argmin attribution (slot program R0): which regime owned the
222 // binding CFL element, counted once per census (global path) or
223 // re-tier (LTS path). Answers "who sets the step" without a trace.
225 long dt_argmin_band = 0;
226 long dt_argmin_free = 0;
227 long dt_argmin_node = 0;
228
229 // LTS macro cycles that ran vs were rejected. The tier histogram
230 // above is filled by assignTiers whether or not a cycle ever fires,
231 // so these are what say tiering ENGAGED rather than was assigned.
234 };
235
237 virtual RunStats run_stats() const noexcept { return {}; }
238
246 struct Divergence {
247 int link = -1;
248 double value = 0.0;
249 const char* what = nullptr;
250 };
251
262 virtual bool divergence(Divergence& d) const noexcept {
263 (void)d;
264 return false;
265 }
266
268 virtual bool is_initialized() const noexcept = 0;
269};
270
271} // namespace openswmm::fv
272
273#endif // OPENSWMM_ENGINE_FV_I_NETWORK_SOLVER_HPP
Abstract time integrator for the explicit FV 1D network.
Definition INetworkSolver.hpp:135
virtual void reinitialize(double t0)=0
Refresh backend state after caller edits the bound hydraulic arrays.
virtual ~INetworkSolver()=default
Destroy a concrete backend through the network-solver interface.
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
Read the next CFL step suggestion from the latest backend census.
virtual void finalize()=0
Release all backend resources.
virtual bool divergence(Divergence &d) const noexcept
Report the last advance's worst physical-bound/nonfinite offender when supported.
Definition INetworkSolver.hpp:262
virtual RunStats run_stats() const noexcept
Read cumulative statistics. Default: zeros (backend has no counters).
Definition INetworkSolver.hpp:237
virtual double advance(double t_current, double t_target, const FvStepForcing &forcing)=0
Advance bound network state across one requested routing window.
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
Bind and initialize a concrete backend for one network model.
Definition AcceptedWaterVolumes.hpp:8
Knobs for FLOW_ROUTING FV.
Definition FvOptions.hpp:123
Definition INetworkSolver.hpp:58
const double * node_withdrawal
Definition INetworkSolver.hpp:119
const double * conduit_loss
Definition INetworkSolver.hpp:96
const double * node_source_max
Definition INetworkSolver.hpp:75
int n_nodes
Definition INetworkSolver.hpp:114
const double * node_lateral
Definition INetworkSolver.hpp:66
int n_links
Definition INetworkSolver.hpp:115
void * refresh_user
Definition INetworkSolver.hpp:112
const double * node_fixed_head
Definition INetworkSolver.hpp:71
void(* refresh)(void *user, double t_elapsed)
Definition INetworkSolver.hpp:111
const double * link_q_cap
Definition INetworkSolver.hpp:92
const double * structure_flow
Definition INetworkSolver.hpp:85
Definition INetworkSolver.hpp:246
double value
offending magnitude (internal units)
Definition INetworkSolver.hpp:248
const char * what
"velocity (ft/s)" | "depth (ft)"
Definition INetworkSolver.hpp:249
int link
engine link index of the offender
Definition INetworkSolver.hpp:247
Definition INetworkSolver.hpp:205
long dt_argmin_pressurized
h ≥ y_full (slot celerity)
Definition INetworkSolver.hpp:224
long n_macro_cycles
Definition INetworkSolver.hpp:232
double min_h
smallest substep taken (s)
Definition INetworkSolver.hpp:210
long dt_argmin_free
open-channel cell
Definition INetworkSolver.hpp:226
long nflux
face flux evaluations
Definition INetworkSolver.hpp:207
long dt_argmin_node
node storage / feedback bound
Definition INetworkSolver.hpp:227
double avg_h
sim-time / nsteps (s)
Definition INetworkSolver.hpp:209
long tier_cells[8]
cumulative rebuild-sampled cells per LTS tier
Definition INetworkSolver.hpp:218
long nsteps
explicit substeps
Definition INetworkSolver.hpp:206
int n_tiers
populated tier count (≤ 8)
Definition INetworkSolver.hpp:219
double last_h
last substep (s)
Definition INetworkSolver.hpp:208
double active_frac_mean
Definition INetworkSolver.hpp:215
long n_macro_rejected
Definition INetworkSolver.hpp:233
long dt_argmin_band
y_crown ≤ h < y_full (mouth)
Definition INetworkSolver.hpp:225
double active_frac_max
Definition INetworkSolver.hpp:216
double active_frac_min
Definition INetworkSolver.hpp:214
SoA mesh geometry and topology for the FV network solver.
Definition NetworkMeshData.hpp:123
Mutable solver state — the conserved variables and the node volumes.
Definition NetworkMeshData.hpp:519