OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
PluginSurfaceSolver.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2
11
12#pragma once
13#include "GpuExecutionOwner.hpp"
14#include "ISurfaceSolver.hpp"
15#include <cstdio>
16
17namespace openswmm::twoD {
18// The core owns this adapter. The matched plugin owns its implementation and
19// destroys it on the same controlling thread that created it.
20class PluginSurfaceSolver final : public ISurfaceSolver {
21public:
22 using Destroy = void (*)(void*);
36 std::shared_ptr<GpuExecutionOwner> owner)
37 : solver_(solver), destroy_(destroy), owner_(std::move(owner)) {}
38
46 try {
47 owner_->invoke([&] { destroy_(solver_); });
48 } catch (...) {
49 std::fprintf(stderr, "[openswmm 2D] plugin teardown failed\n");
50 }
51 }
52
64 owner_->invoke([&] {
65 solver_->initialize(m, s, o);
66
67 refresh();
68 });
69 }
70
79 double advance(double from, double to) override {
80 return owner_->invoke([&] {
81 const double t = solver_->advance(from, to);
82 refresh();
83 return t;
84 });
85 }
86
94 void reinitialize(double t) override {
95 owner_->invoke([&] {
96 solver_->reinitialize(t);
97 refresh();
98 });
99 }
100
109 void resyncFromVolumes(double t) override {
110 owner_->invoke([&] {
111 solver_->resyncFromVolumes(t);
112 refresh();
113 });
114 }
115
122 void finalize() override {
123 owner_->invoke([&] {
124 solver_->finalize();
125 refresh();
126 });
127 }
128
134 double completedSourceTime() const noexcept override { return completed_; }
141 long last_num_steps() const noexcept override { return steps_; }
148 double last_step_size() const noexcept override { return step_; }
156 const std::vector<double>& last_coupling_exchange() const noexcept override {
157 return exchange_;
158 }
159
165 RunStats run_stats() const noexcept override { return stats_; }
172 bool is_initialized() const noexcept override { return initialized_; }
173
174private:
183 void refresh() {
184 steps_ = solver_->last_num_steps();
185 step_ = solver_->last_step_size();
186 completed_ = solver_->completedSourceTime();
187 stats_ = solver_->run_stats();
188 exchange_ = solver_->last_coupling_exchange();
189 initialized_ = solver_->is_initialized();
190 }
191 ISurfaceSolver* solver_;
192 Destroy destroy_;
193 std::shared_ptr<GpuExecutionOwner> owner_;
194 long steps_ = 0;
195 double step_ = 0, completed_ = -1;
196 bool initialized_ = false;
197 RunStats stats_{};
198 std::vector<double> exchange_;
199};
200}
Host-thread ownership checks for core-controlled Kokkos operations.
Backend-neutral interface for the 2D surface-routing time integrator.
Abstract time integrator for the 2D surface-routing ODE system.
Definition ISurfaceSolver.hpp:61
virtual bool is_initialized() const noexcept=0
True once initialize() has completed and the solver is ready.
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 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 double last_step_size() const noexcept=0
Last internal step size used by the integrator.
void resyncFromVolumes(double t) override
Resynchronize backend time while preserving its volume-owner semantics.
Definition PluginSurfaceSolver.hpp:109
const std::vector< double > & last_coupling_exchange() const noexcept override
Borrow the most recently refreshed coupling-volume snapshot.
Definition PluginSurfaceSolver.hpp:156
void reinitialize(double t) override
Reseed the plugin backend after external state edits.
Definition PluginSurfaceSolver.hpp:94
double completedSourceTime() const noexcept override
Read the adapter's last synchronized backend status.
Definition PluginSurfaceSolver.hpp:134
RunStats run_stats() const noexcept override
Read the adapter's last synchronized backend status.
Definition PluginSurfaceSolver.hpp:165
void(*)(void *) Destroy
Definition PluginSurfaceSolver.hpp:22
void initialize(MeshData &m, SurfaceStateData &s, SolverOptions2D &o) override
Initialize the plugin backend synchronously and cache its status.
Definition PluginSurfaceSolver.hpp:63
double last_step_size() const noexcept override
Read the adapter's last synchronized backend status.
Definition PluginSurfaceSolver.hpp:148
~PluginSurfaceSolver() override
Destroy the plugin implementation synchronously on its execution owner.
Definition PluginSurfaceSolver.hpp:45
double advance(double from, double to) override
Advance the plugin backend synchronously to a requested endpoint.
Definition PluginSurfaceSolver.hpp:79
bool is_initialized() const noexcept override
Read the adapter's last synchronized backend status.
Definition PluginSurfaceSolver.hpp:172
void finalize() override
Release plugin backend resources on the execution-owner thread.
Definition PluginSurfaceSolver.hpp:122
long last_num_steps() const noexcept override
Read the adapter's last synchronized backend status.
Definition PluginSurfaceSolver.hpp:141
PluginSurfaceSolver(ISurfaceSolver *solver, Destroy destroy, std::shared_ptr< GpuExecutionOwner > owner)
Take ownership of a matched plugin solver and its destruction route.
Definition PluginSurfaceSolver.hpp:35
Definition ExchangeLaw.hpp:60
Definition ISurfaceSolver.hpp:185
SoA storage for 2D mixed triangle/quad mesh geometry and topology.
Definition MeshData.hpp:65
Definition SolverOptions2D.hpp:257
Definition SurfaceStateData.hpp:64