OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
openswmm_hotstart.h
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
73
74#ifndef OPENSWMM_ENGINE_HOTSTART_H
75#define OPENSWMM_ENGINE_HOTSTART_H
76
77#include "openswmm_engine.h"
78
79#ifdef __cplusplus
80extern "C" {
81#endif
82
84typedef void* SWMM_HotStart;
85
87#define OPENSWMM_HOTSTART_MAGIC "OPENSWMM_HS_V1\0"
88
90#define OPENSWMM_HOTSTART_VERSION 1
91
92/* =========================================================================
93 * [FILES] section — `SAVE HOTSTART` entry management (Slice BV-01)
94 *
95 * These functions manage the *static* list of scheduled hot-start save
96 * entries that live in the `[FILES]` section of an `.inp` file
97 * (`SimulationContext::hotstart_saves`). They are distinct from the
98 * runtime `swmm_hotstart_save()` function below, which writes a single
99 * hot-start file at the current sim time.
100 *
101 * Each entry is a `{path, datetime}` pair. A `datetime` of `0.0`
102 * means "no datetime — save at end of run" (matches legacy semantics).
103 *
104 * The legacy singular `swmm_files_set("HOTSTART_SAVE_PATH", …)` /
105 * `_DATETIME` keys remain as slot-0 sugar.
106 * ========================================================================= */
107
115
125 SWMM_Engine engine, int idx, char* buf, int buflen);
126
136 SWMM_Engine engine, int idx, double* datetime);
137
153 SWMM_Engine engine, int idx, const char* path);
154
164 SWMM_Engine engine, int idx, double datetime);
165
176 SWMM_Engine engine, const char* path, double datetime);
177
185
192
193/* =========================================================================
194 * Create / save
195 * ========================================================================= */
196
211SWMM_ENGINE_API int swmm_hotstart_save(SWMM_Engine engine, const char* path);
212
213/* =========================================================================
214 * Open / read
215 * ========================================================================= */
216
227SWMM_ENGINE_API int swmm_hotstart_open(const char* path, SWMM_HotStart* hs);
228
229/* =========================================================================
230 * Apply
231 * ========================================================================= */
232
251
252/* =========================================================================
253 * Modify hot start data
254 * ========================================================================= */
255
268 SWMM_HotStart hs,
269 const char* node_id,
270 double depth
271);
272
281 SWMM_HotStart hs,
282 const char* node_id,
283 double head
284);
285
294 SWMM_HotStart hs,
295 const char* link_id,
296 double flow
297);
298
307 SWMM_HotStart hs,
308 const char* link_id,
309 double depth
310);
311
320 SWMM_HotStart hs,
321 const char* subcatch_id,
322 double runoff
323);
324
325/* =========================================================================
326 * Query hot start metadata
327 * ========================================================================= */
328
336
344SWMM_ENGINE_API int swmm_hotstart_get_crs(SWMM_HotStart hs, char* buf, int buflen);
345
352
359
360/* =========================================================================
361 * Warning access (populated after swmm_hotstart_apply())
362 * ========================================================================= */
363
374
382SWMM_ENGINE_API const char* swmm_hotstart_warning(SWMM_HotStart hs, int index);
383
384/* =========================================================================
385 * Close
386 * ========================================================================= */
387
398
399#ifdef __cplusplus
400} /* extern "C" */
401#endif
402
403#endif /* OPENSWMM_ENGINE_HOTSTART_H */
#define SWMM_ENGINE_API
Definition openswmm_2d.h:53
void * SWMM_Engine
Opaque handle to an OpenSWMM Engine instance.
Definition openswmm_callbacks.h:51
OpenSWMM Engine — primary transparent C API (master header).
SWMM_ENGINE_API int swmm_hotstart_set_node_depth(SWMM_HotStart hs, const char *node_id, double depth)
Modify the stored depth for a node in the hot start file.
Definition openswmm_hotstart_impl.cpp:166
SWMM_ENGINE_API int swmm_hotstart_saves_set_datetime(SWMM_Engine engine, int idx, double datetime)
Replace the datetime of an existing SAVE HOTSTART entry.
Definition openswmm_model_impl.cpp:705
SWMM_ENGINE_API int swmm_hotstart_saves_get_datetime(SWMM_Engine engine, int idx, double *datetime)
Get the datetime (decimal day; 0.0 = "end of run") of the i-th SAVE HOTSTART entry.
Definition openswmm_model_impl.cpp:683
SWMM_ENGINE_API int swmm_hotstart_set_link_flow(SWMM_HotStart hs, const char *link_id, double flow)
Modify the stored flow for a link.
Definition openswmm_hotstart_impl.cpp:184
SWMM_ENGINE_API int swmm_hotstart_set_subcatch_runoff(SWMM_HotStart hs, const char *subcatch_id, double runoff)
Modify the stored runoff for a subcatchment.
Definition openswmm_hotstart_impl.cpp:202
SWMM_ENGINE_API int swmm_hotstart_set_link_depth(SWMM_HotStart hs, const char *link_id, double depth)
Modify the stored depth for a link.
Definition openswmm_hotstart_impl.cpp:193
SWMM_ENGINE_API int swmm_hotstart_set_node_head(SWMM_HotStart hs, const char *node_id, double head)
Modify the stored head for a node.
Definition openswmm_hotstart_impl.cpp:175
SWMM_ENGINE_API int swmm_hotstart_warning_count(SWMM_HotStart hs)
Get the number of warnings generated by the last swmm_hotstart_apply().
Definition openswmm_hotstart_impl.cpp:247
SWMM_ENGINE_API int swmm_hotstart_saves_add(SWMM_Engine engine, const char *path, double datetime)
Append a new SAVE HOTSTART entry.
Definition openswmm_model_impl.cpp:715
SWMM_ENGINE_API int swmm_hotstart_close(SWMM_HotStart hs)
Close and free the hot start handle.
Definition openswmm_hotstart_impl.cpp:263
SWMM_ENGINE_API int swmm_hotstart_save(SWMM_Engine engine, const char *path)
Save the current engine state to a new hot start file.
Definition openswmm_hotstart_impl.cpp:76
SWMM_ENGINE_API int swmm_hotstart_saves_clear(SWMM_Engine engine)
Remove all SAVE HOTSTART entries.
Definition openswmm_model_impl.cpp:734
void * SWMM_HotStart
Opaque handle to an open hot start file.
Definition openswmm_hotstart.h:84
SWMM_ENGINE_API int swmm_hotstart_open(const char *path, SWMM_HotStart *hs)
Open an existing hot start file for reading.
Definition openswmm_hotstart_impl.cpp:118
SWMM_ENGINE_API int swmm_hotstart_link_count(SWMM_HotStart hs)
Get the number of links stored in the hot start file.
Definition openswmm_hotstart_impl.cpp:238
SWMM_ENGINE_API const char * swmm_hotstart_warning(SWMM_HotStart hs, int index)
Get the i-th warning message from the last swmm_hotstart_apply().
Definition openswmm_hotstart_impl.cpp:252
SWMM_ENGINE_API int swmm_hotstart_saves_count(SWMM_Engine engine, int *count)
Get the number of SAVE HOTSTART entries currently in [FILES].
Definition openswmm_model_impl.cpp:664
SWMM_ENGINE_API int swmm_hotstart_saves_set_path(SWMM_Engine engine, int idx, const char *path)
Replace the path of an existing SAVE HOTSTART entry.
Definition openswmm_model_impl.cpp:694
SWMM_ENGINE_API int swmm_hotstart_node_count(SWMM_HotStart hs)
Get the number of nodes stored in the hot start file.
Definition openswmm_hotstart_impl.cpp:233
SWMM_ENGINE_API int swmm_hotstart_get_sim_time(SWMM_HotStart hs, double *sim_time)
Get the simulation timestamp stored in the hot start file.
Definition openswmm_hotstart_impl.cpp:215
SWMM_ENGINE_API int swmm_hotstart_get_crs(SWMM_HotStart hs, char *buf, int buflen)
Get the CRS string stored in the hot start file.
Definition openswmm_hotstart_impl.cpp:222
SWMM_ENGINE_API int swmm_hotstart_apply(SWMM_Engine engine, SWMM_HotStart hs)
Apply hot start state to an engine.
Definition openswmm_hotstart_impl.cpp:134
SWMM_ENGINE_API int swmm_hotstart_saves_get_path(SWMM_Engine engine, int idx, char *buf, int buflen)
Get the path of the i-th SAVE HOTSTART entry.
Definition openswmm_model_impl.cpp:672
SWMM_ENGINE_API int swmm_hotstart_saves_remove(SWMM_Engine engine, int idx)
Remove the i-th SAVE HOTSTART entry; subsequent slots shift down.
Definition openswmm_model_impl.cpp:725