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
48#ifndef OPENSWMM_ENGINE_HOT_START_MANAGER_HPP
49#define OPENSWMM_ENGINE_HOT_START_MANAGER_HPP
50
51#include <cstdint>
52#include <functional>
53#include <string>
54#include <vector>
55
56namespace openswmm {
57
58struct SimulationContext;
59
60// ============================================================================
61// Per-object state records
62// ============================================================================
63
66 std::string id;
67 double depth = 0.0;
68 double head = 0.0;
69 double volume = 0.0;
70};
71
74 std::string id;
75 double flow = 0.0;
76 double depth = 0.0;
77 double volume = 0.0;
78};
79
82 std::string id;
83 double runoff = 0.0;
84 double gwater = 0.0;
85};
86
87// ============================================================================
88// File header (in-memory mirror of the on-disk header)
89// ============================================================================
90
93 uint32_t version = 1;
94 int64_t timestamp = 0;
95 double sim_time = 0.0;
96 double start_date = 0.0;
97 double end_date = 0.0;
98 std::string crs;
99};
100
101// ============================================================================
102// HotStartFile — opaque handle (cast to void* in C API)
103// ============================================================================
104
115 std::vector<HotStartNodeRecord> nodes;
116 std::vector<HotStartLinkRecord> links;
117 std::vector<HotStartSubcatchRecord> subcatches;
118
119 std::string path;
120 bool dirty = false;
121
122 std::vector<std::string> warnings;
123
124 // -----------------------------------------------------------------------
125 // Modification helpers
126 // -----------------------------------------------------------------------
127
129 bool set_node_depth (const std::string& id, double v);
131 bool set_node_head (const std::string& id, double v);
133 bool set_link_flow (const std::string& id, double v);
135 bool set_link_depth (const std::string& id, double v);
137 bool set_subcatch_runoff(const std::string& id, double v);
138};
139
140// ============================================================================
141// HotStartManager — static methods (no state; acts as a utility namespace)
142// ============================================================================
143
154public:
155 HotStartManager() = delete;
156
157 // -----------------------------------------------------------------------
158 // Save
159 // -----------------------------------------------------------------------
160
169 static HotStartFile* save(const SimulationContext& ctx,
170 const std::string& path);
171
172 // -----------------------------------------------------------------------
173 // Open
174 // -----------------------------------------------------------------------
175
185 static HotStartFile* open(const std::string& path);
186
187 // -----------------------------------------------------------------------
188 // Apply
189 // -----------------------------------------------------------------------
190
203 static int apply(HotStartFile& hs,
205 std::function<void(const std::string&)> warn_cb = {});
206
207 // -----------------------------------------------------------------------
208 // Flush (write-back modifications)
209 // -----------------------------------------------------------------------
210
216 static bool flush(HotStartFile& hs);
217
218 // -----------------------------------------------------------------------
219 // Last I/O error (thread-local; for error reporting to C API layer)
220 // -----------------------------------------------------------------------
221
223 static const std::string& last_io_error() noexcept;
224
225private:
226 // -----------------------------------------------------------------------
227 // Binary I/O helpers
228 // -----------------------------------------------------------------------
229
230 static bool write_file(const HotStartFile& hs, const std::string& path);
231 static bool read_file (HotStartFile& hs, const std::string& path);
232
233 // -----------------------------------------------------------------------
234 // CRC32 (IEEE 802.3 polynomial, no external dependency)
235 // -----------------------------------------------------------------------
236
237 static uint32_t crc32(const uint8_t* data, std::size_t len) noexcept;
238};
239
240} /* namespace openswmm */
241
242#endif /* OPENSWMM_ENGINE_HOT_START_MANAGER_HPP */
const double * data
Definition XSectBatch.cpp:550
Static utility class for hot start file operations.
Definition HotStartManager.hpp:153
static const std::string & last_io_error() noexcept
Description of the most recent I/O error (empty = none).
Definition HotStartManager.cpp:44
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:396
static HotStartFile * save(const SimulationContext &ctx, const std::string &path)
Capture current engine state and write to a hot start file.
Definition HotStartManager.cpp:322
static HotStartFile * open(const std::string &path)
Read and validate a hot start file.
Definition HotStartManager.cpp:381
static bool flush(HotStartFile &hs)
If the file is dirty, rewrite it to disk.
Definition HotStartManager.cpp:454
Definition Controls.cpp:24
In-memory hot start file data.
Definition HotStartManager.hpp:113
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:304
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:283
HotStartHeader header
Definition HotStartManager.hpp:114
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:311
bool dirty
True if set_*() was called.
Definition HotStartManager.hpp:120
std::vector< std::string > warnings
Populated by HotStartManager::apply()
Definition HotStartManager.hpp:122
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:290
std::vector< HotStartNodeRecord > nodes
Definition HotStartManager.hpp:115
std::string path
File path (for flush-on-close)
Definition HotStartManager.hpp:119
std::vector< HotStartLinkRecord > links
Definition HotStartManager.hpp:116
std::vector< HotStartSubcatchRecord > subcatches
Definition HotStartManager.hpp:117
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:297
In-memory representation of the OPENSWMM_HS_V1 header.
Definition HotStartManager.hpp:92
double start_date
options.start_date (Julian date)
Definition HotStartManager.hpp:96
double end_date
options.end_date (Julian date)
Definition HotStartManager.hpp:97
int64_t timestamp
Unix epoch seconds at save time.
Definition HotStartManager.hpp:94
double sim_time
Simulation elapsed time (decimal days)
Definition HotStartManager.hpp:95
uint32_t version
Definition HotStartManager.hpp:93
std::string crs
CRS string (may be empty)
Definition HotStartManager.hpp:98
Node hydraulic state at hot-start save time.
Definition HotStartManager.hpp:65
double volume
Definition HotStartManager.hpp:69
std::string id
Definition HotStartManager.hpp:66
double depth
Definition HotStartManager.hpp:67
double head
Definition HotStartManager.hpp:68
Subcatchment state at hot-start save time.
Definition HotStartManager.hpp:81
double runoff
Definition HotStartManager.hpp:83
double gwater
Definition HotStartManager.hpp:84
std::string id
Definition HotStartManager.hpp:82
Central, reentrant simulation context.
Definition SimulationContext.hpp:141