OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
HotStartManager.hpp
Go to the documentation of this file.
1
63#ifndef OPENSWMM_ENGINE_HOT_START_MANAGER_HPP
64#define OPENSWMM_ENGINE_HOT_START_MANAGER_HPP
65
66#include <cstdint>
67#include <functional>
68#include <string>
69#include <vector>
70
71namespace openswmm {
72
73struct SimulationContext;
74namespace runoff { class RunoffSolver; }
75namespace groundwater { class GWSolver; }
76
77// ============================================================================
78// Per-object state records
79// ============================================================================
80
83 std::string id;
84 double depth = 0.0;
85 double head = 0.0;
86 double volume = 0.0;
87};
88
91 std::string id;
92 double flow = 0.0;
93 double depth = 0.0;
94 double volume = 0.0;
95};
96
99 std::string id;
100 double runoff = 0.0;
101 double gwater = 0.0;
102
103 // Gap #54: infiltration model state (V2 only; -1 = not present / V1 file)
104 int infil_model = -1;
105 double infil[6] = {0, 0, 0, 0, 0, 0};
106
107 // Gap #54: groundwater zone state (V2 only; gw_theta < 0 = not present)
108 double gw_theta = -1.0;
109 double gw_lower_depth = 0.0;
110};
111
112// ============================================================================
113// File header (in-memory mirror of the on-disk header)
114// ============================================================================
115
118 uint32_t version = 1;
119 int64_t timestamp = 0;
120 double sim_time = 0.0;
121 double start_date = 0.0;
122 double end_date = 0.0;
123 std::string crs;
124};
125
126// ============================================================================
127// HotStartFile — opaque handle (cast to void* in C API)
128// ============================================================================
129
140 std::vector<HotStartNodeRecord> nodes;
141 std::vector<HotStartLinkRecord> links;
142 std::vector<HotStartSubcatchRecord> subcatches;
143
144 std::string path;
145 bool dirty = false;
146
147 std::vector<std::string> warnings;
148
149 // -----------------------------------------------------------------------
150 // Modification helpers
151 // -----------------------------------------------------------------------
152
154 bool set_node_depth (const std::string& id, double v);
156 bool set_node_head (const std::string& id, double v);
158 bool set_link_flow (const std::string& id, double v);
160 bool set_link_depth (const std::string& id, double v);
162 bool set_subcatch_runoff(const std::string& id, double v);
163};
164
165// ============================================================================
166// HotStartManager — static methods (no state; acts as a utility namespace)
167// ============================================================================
168
179public:
180 HotStartManager() = delete;
181
182 // -----------------------------------------------------------------------
183 // Save
184 // -----------------------------------------------------------------------
185
194 static HotStartFile* save(const SimulationContext& ctx,
195 const std::string& path);
196
209 static HotStartFile* save(const SimulationContext& ctx,
210 const runoff::RunoffSolver* runoff,
211 const groundwater::GWSolver* gw,
212 const std::string& path);
213
214 // -----------------------------------------------------------------------
215 // Open
216 // -----------------------------------------------------------------------
217
227 static HotStartFile* open(const std::string& path);
228
229 // -----------------------------------------------------------------------
230 // Apply
231 // -----------------------------------------------------------------------
232
245 static int apply(HotStartFile& hs,
247 std::function<void(const std::string&)> warn_cb = {});
248
262 static int apply(HotStartFile& hs,
264 runoff::RunoffSolver* runoff,
266 std::function<void(const std::string&)> warn_cb = {});
267
268 // -----------------------------------------------------------------------
269 // Flush (write-back modifications)
270 // -----------------------------------------------------------------------
271
277 static bool flush(HotStartFile& hs);
278
279 // -----------------------------------------------------------------------
280 // Last I/O error (thread-local; for error reporting to C API layer)
281 // -----------------------------------------------------------------------
282
284 static const std::string& last_io_error() noexcept;
285
286private:
287 // -----------------------------------------------------------------------
288 // Binary I/O helpers
289 // -----------------------------------------------------------------------
290
291 static bool write_file(const HotStartFile& hs, const std::string& path);
292 static bool read_file (HotStartFile& hs, const std::string& path);
293
294 // -----------------------------------------------------------------------
295 // CRC32 (IEEE 802.3 polynomial, no external dependency)
296 // -----------------------------------------------------------------------
297
298 static uint32_t crc32(const uint8_t* data, std::size_t len) noexcept;
299};
300
301} /* namespace openswmm */
302
303#endif /* OPENSWMM_ENGINE_HOT_START_MANAGER_HPP */
const double * data
Definition XSectBatch.cpp:567
Static utility class for hot start file operations.
Definition HotStartManager.hpp:178
static const std::string & last_io_error() noexcept
Description of the most recent I/O error (empty = none).
Definition HotStartManager.cpp:46
static int apply(HotStartFile &hs, SimulationContext &ctx, std::function< void(const std::string &)> warn_cb={})
Apply hot start records to a simulation context.
Definition HotStartManager.cpp:513
static HotStartFile * save(const SimulationContext &ctx, const std::string &path)
Capture current engine state and write to a hot start file (V1 format).
Definition HotStartManager.cpp:345
static HotStartFile * open(const std::string &path)
Read and validate a hot start file.
Definition HotStartManager.cpp:498
static bool flush(HotStartFile &hs)
If the file is dirty, rewrite it to disk.
Definition HotStartManager.cpp:619
Definition Groundwater.hpp:124
Definition Runoff.hpp:98
Definition NodeCoupling.cpp:15
In-memory hot start file data.
Definition HotStartManager.hpp:138
bool set_link_depth(const std::string &id, double v)
Set depth for a stored link. Returns false if id not found.
Definition HotStartManager.cpp:327
bool set_node_depth(const std::string &id, double v)
Set depth for a stored node. Returns false if id not found.
Definition HotStartManager.cpp:306
HotStartHeader header
Definition HotStartManager.hpp:139
bool set_subcatch_runoff(const std::string &id, double v)
Set runoff for a stored subcatchment. Returns false if id not found.
Definition HotStartManager.cpp:334
bool dirty
True if set_*() was called.
Definition HotStartManager.hpp:145
std::vector< std::string > warnings
Populated by HotStartManager::apply()
Definition HotStartManager.hpp:147
bool set_node_head(const std::string &id, double v)
Set head for a stored node. Returns false if id not found.
Definition HotStartManager.cpp:313
std::vector< HotStartNodeRecord > nodes
Definition HotStartManager.hpp:140
std::string path
File path (for flush-on-close)
Definition HotStartManager.hpp:144
std::vector< HotStartLinkRecord > links
Definition HotStartManager.hpp:141
std::vector< HotStartSubcatchRecord > subcatches
Definition HotStartManager.hpp:142
bool set_link_flow(const std::string &id, double v)
Set flow for a stored link. Returns false if id not found.
Definition HotStartManager.cpp:320
In-memory representation of the OPENSWMM_HS_V1 header.
Definition HotStartManager.hpp:117
double start_date
options.start_date (OADate (days since 12/30/1899))
Definition HotStartManager.hpp:121
double end_date
options.end_date (OADate (days since 12/30/1899))
Definition HotStartManager.hpp:122
int64_t timestamp
Unix epoch seconds at save time.
Definition HotStartManager.hpp:119
double sim_time
Simulation elapsed time (decimal days)
Definition HotStartManager.hpp:120
uint32_t version
Definition HotStartManager.hpp:118
std::string crs
CRS string (may be empty)
Definition HotStartManager.hpp:123
Node hydraulic state at hot-start save time.
Definition HotStartManager.hpp:82
double volume
Definition HotStartManager.hpp:86
std::string id
Definition HotStartManager.hpp:83
double depth
Definition HotStartManager.hpp:84
double head
Definition HotStartManager.hpp:85
Subcatchment state at hot-start save time.
Definition HotStartManager.hpp:98
double gw_lower_depth
lower zone depth (ft)
Definition HotStartManager.hpp:109
double infil[6]
flat 6-elem state (model-dependent)
Definition HotStartManager.hpp:105
double runoff
Definition HotStartManager.hpp:100
int infil_model
Definition HotStartManager.hpp:104
double gw_theta
upper zone moisture content
Definition HotStartManager.hpp:108
double gwater
Definition HotStartManager.hpp:101
std::string id
Definition HotStartManager.hpp:99
Central, reentrant simulation context.
Definition SimulationContext.hpp:274