OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
ISurfaceSolver.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
38
39#ifndef OPENSWMM_ENGINE_2D_I_SURFACE_SOLVER_HPP
40#define OPENSWMM_ENGINE_2D_I_SURFACE_SOLVER_HPP
41
42#include <vector>
43
44namespace openswmm::twoD {
45
46// Forward declarations — passed by reference, no definitions needed here.
47struct MeshData;
48struct SurfaceStateData;
49struct SolverOptions2D;
50
62public:
69 virtual ~ISurfaceSolver() = default;
70
85 virtual void initialize(MeshData& mesh, SurfaceStateData& state, SolverOptions2D& opts) = 0;
86
100 virtual double advance(double t_current, double t_target) = 0;
101
111 virtual double completedSourceTime() const noexcept { return -1.0; }
112
122 virtual void reinitialize(double t0) = 0;
123
136 virtual void resyncFromVolumes(double t0) { reinitialize(t0); }
137
146 virtual void finalize() = 0;
147
155 virtual long last_num_steps() const noexcept = 0;
156
164 virtual double last_step_size() const noexcept = 0;
165
178 virtual const std::vector<double>& last_coupling_exchange() const noexcept {
179 static const std::vector<double> kEmpty;
180 return kEmpty;
181 }
182
185 struct RunStats {
186 long nsteps = 0;
187 long nrhs = 0;
188 double last_h = 0.0;
189 double avg_h = 0.0;
190
191 // Marcher telemetry. Guarded: n_tiers == 0 and negative fractions
192 // mean "not populated".
193 double active_frac_min = -1.0;
194 double active_frac_mean = -1.0;
195 double active_frac_max = -1.0;
196 long tier_cells[8] = {0};
197 int n_tiers = 0;
198 };
199
208 virtual RunStats run_stats() const noexcept { return {}; }
209
217 virtual bool is_initialized() const noexcept = 0;
218};
219
220} // namespace openswmm::twoD
221
222#endif // OPENSWMM_ENGINE_2D_I_SURFACE_SOLVER_HPP
Abstract time integrator for the 2D surface-routing ODE system.
Definition ISurfaceSolver.hpp:61
virtual void initialize(MeshData &mesh, SurfaceStateData &state, SolverOptions2D &opts)=0
One-time setup. mesh and state must outlive the solver.
virtual bool is_initialized() const noexcept=0
True once initialize() has completed and the solver is ready.
virtual double advance(double t_current, double t_target)=0
Advance the solution from t_current to t_target (s).
virtual void reinitialize(double t0)=0
Reinitialize the integrator at t0 after external state edits.
virtual RunStats run_stats() const noexcept
Read cumulative statistics. Default: zeros (backend has no counters).
Definition ISurfaceSolver.hpp:208
virtual double completedSourceTime() const noexcept
Horizon through which ALL cell sources have actually landed, including lazy inactive cells and LTS ac...
Definition ISurfaceSolver.hpp:111
virtual void resyncFromVolumes(double t0)
Re-time the integrator at t0 keeping the SIGNED cell volumes from state.volume. Used by the failed-wi...
Definition ISurfaceSolver.hpp:136
virtual void finalize()=0
Release all backend resources.
virtual const std::vector< double > & last_coupling_exchange() const noexcept
Per-point ∫Q dt (m³) from the live node-coupling macro-step path. Default returns empty for backends ...
Definition ISurfaceSolver.hpp:178
virtual long last_num_steps() const noexcept=0
Number of internal integrator steps in the last advance() call.
virtual ~ISurfaceSolver()=default
Destroy a backend solver through its polymorphic interface.
virtual double last_step_size() const noexcept=0
Last internal step size used by the integrator.
Definition ExchangeLaw.hpp:60
Definition ISurfaceSolver.hpp:185
double active_frac_mean
mean active-cell fraction
Definition ISurfaceSolver.hpp:194
int n_tiers
populated tier count (≤ 8)
Definition ISurfaceSolver.hpp:197
double last_h
last accepted internal step (s)
Definition ISurfaceSolver.hpp:188
long nsteps
internal (marcher) substeps
Definition ISurfaceSolver.hpp:186
double active_frac_min
min active-cell fraction (rebuild samples)
Definition ISurfaceSolver.hpp:193
double active_frac_max
max active-cell fraction
Definition ISurfaceSolver.hpp:195
long nrhs
face-kernel evaluations
Definition ISurfaceSolver.hpp:187
double avg_h
sim-time / nsteps (s), filled by the caller
Definition ISurfaceSolver.hpp:189
long tier_cells[8]
cumulative rebuild-sampled cells per LTS tier
Definition ISurfaceSolver.hpp:196
SoA storage for 2D mixed triangle/quad mesh geometry and topology.
Definition MeshData.hpp:65
Definition SolverOptions2D.hpp:257
Definition SurfaceStateData.hpp:64