OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
openswmm_inflows.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
31
32#ifndef OPENSWMM_INFLOWS_H
33#define OPENSWMM_INFLOWS_H
34
35#include "openswmm_engine.h"
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41/* =========================================================================
42 * External inflows
43 * ========================================================================= */
44
68SWMM_ENGINE_API int swmm_ext_inflow_add(SWMM_Engine engine, int node_idx, const char* constituent,
69 const char* ts_name, const char* type,
70 double m_factor, double s_factor, double baseline,
71 const char* pattern);
72
96SWMM_ENGINE_API int swmm_ext_inflow_get(SWMM_Engine engine, int entry_idx,
97 int* node_idx,
98 char* constituent_buf, int constituent_buflen,
99 char* ts_buf, int ts_buflen,
100 char* type_buf, int type_buflen,
101 double* m_factor, double* s_factor, double* baseline,
102 char* pattern_buf, int pattern_buflen);
103
115SWMM_ENGINE_API int swmm_ext_inflow_remove(SWMM_Engine engine, int entry_idx);
116
123SWMM_ENGINE_API int swmm_ext_inflow_set_scale(SWMM_Engine engine, int entry_idx, double scale);
124
130SWMM_ENGINE_API int swmm_ext_inflow_set_baseline(SWMM_Engine engine, int entry_idx, double baseline);
131
132/* =========================================================================
133 * Dry weather flow
134 * ========================================================================= */
135
152SWMM_ENGINE_API int swmm_dwf_add(SWMM_Engine engine, int node_idx, const char* constituent,
153 double avg_value, const char* pat1, const char* pat2,
154 const char* pat3, const char* pat4);
155
175SWMM_ENGINE_API int swmm_dwf_get(SWMM_Engine engine, int entry_idx,
176 int* node_idx,
177 char* constituent_buf, int constituent_buflen,
178 double* avg_value,
179 char* pat1_buf, int pat1_buflen,
180 char* pat2_buf, int pat2_buflen,
181 char* pat3_buf, int pat3_buflen,
182 char* pat4_buf, int pat4_buflen);
183
190SWMM_ENGINE_API int swmm_dwf_remove(SWMM_Engine engine, int entry_idx);
191
198SWMM_ENGINE_API int swmm_dwf_set_baseline(SWMM_Engine engine, int entry_idx, double avg_value);
199
200/* =========================================================================
201 * RDII (Rainfall-Dependent Infiltration/Inflow)
202 * ========================================================================= */
203
216SWMM_ENGINE_API int swmm_rdii_add(SWMM_Engine engine, int node_idx, const char* uh_name, double area);
217
229SWMM_ENGINE_API int swmm_rdii_get(SWMM_Engine engine, int entry_idx,
230 int* node_idx, char* uh_buf, int buflen,
231 double* area);
232
239SWMM_ENGINE_API int swmm_rdii_remove(SWMM_Engine engine, int entry_idx);
240
241/* =========================================================================
242 * Unit hydrographs ([HYDROGRAPHS] section)
243 * =========================================================================
244 *
245 * A unit hydrograph group is identified by name and has two kinds of input
246 * lines:
247 * - A gage assignment line: "UHname RainGage"
248 * - One or more parameter lines: "UHname Month Response R T K [Dmax Drecov Dinit]"
249 *
250 * Both kinds are added separately. `swmm_hydrograph_add` adds a parameter
251 * line, `swmm_hydrograph_add_gage` adds the gage assignment. Counts and
252 * getters are also separated.
253 *
254 * `response` is encoded as: 0 = SHORT, 1 = MEDIUM, 2 = LONG.
255 * `month` is encoded as: 0..11 = JAN..DEC, or -1 = ALL.
256 * ========================================================================= */
257
274SWMM_ENGINE_API int swmm_hydrograph_add(SWMM_Engine engine, const char* uh_name,
275 int month, int response,
276 double r, double t, double k,
277 double dmax, double drecov, double dinit);
278
296SWMM_ENGINE_API int swmm_hydrograph_get(SWMM_Engine engine, int entry_idx,
297 char* uh_buf, int buflen,
298 int* month, int* response,
299 double* r, double* t, double* k,
300 double* dmax, double* drecov, double* dinit);
301
307
317 const char* uh_name,
318 const char* gage_name);
319
332 char* uh_buf, int uh_buflen,
333 char* gage_buf, int gage_buflen);
334
340
354
369 char* buf, int buflen);
370
371/* =========================================================================
372 * Mutation surface (BS-02) — upsert + key-based remove + rename
373 * =========================================================================
374 *
375 * The legacy `swmm_hydrograph_add` / `swmm_hydrograph_add_gage` surface above
376 * is append-only, which prevents in-place edits from a UI. The following
377 * setters/removers support the `HydrographGroupEditor` MVC layer in
378 * openswmm.gui: every mutation in the editor routes through one of these
379 * symbols, and the GUI's `SWMMModelLayer` emits a `hydrographChanged(uhName)`
380 * signal so all subscribed views (Object Browser, property panel, picker
381 * combos, etc.) refresh in lock-step.
382 *
383 * Upsert contract (set_rtk, set_ia, decay_set):
384 * - If an entry matching the supplied key exists, update only the fields
385 * this setter owns and leave the rest untouched.
386 * - Otherwise append a new entry with the supplied fields set and the
387 * unspecified fields zeroed (so set_rtk followed by set_ia on the same
388 * key composes correctly).
389 *
390 * Remove contract (remove_entry, remove_group, decay_remove):
391 * - Key-based, not index-based — indices shift as entries are removed and
392 * a UI cannot keep them in sync. Idempotent: returns SWMM_OK if no
393 * match is found.
394 *
395 * Group remove cascades to: [HYDROGRAPHS] parameter rows, gage assignments,
396 * [RDII_DECAY] rows, AND any [RDII] node assignments referencing the group
397 * (so the engine never sees a dangling UH-name reference after a delete).
398 * ========================================================================= */
399
412SWMM_ENGINE_API int swmm_hydrograph_set_rtk(SWMM_Engine engine, const char* uh_name,
413 int month, int response,
414 double r, double t, double k);
415
428SWMM_ENGINE_API int swmm_hydrograph_set_ia(SWMM_Engine engine, const char* uh_name,
429 int month, int response,
430 double dmax, double drecov, double dinit);
431
441SWMM_ENGINE_API int swmm_hydrograph_remove_entry(SWMM_Engine engine, const char* uh_name,
442 int month, int response);
443
450SWMM_ENGINE_API int swmm_hydrograph_remove_group(SWMM_Engine engine, const char* uh_name);
451
462SWMM_ENGINE_API int swmm_hydrograph_clear_group_months(SWMM_Engine engine, const char* uh_name);
463
473SWMM_ENGINE_API int swmm_hydrograph_set_gage(SWMM_Engine engine, const char* uh_name,
474 const char* gage_name);
475
486SWMM_ENGINE_API int swmm_hydrograph_group_rename(SWMM_Engine engine, int idx, const char* new_id);
487
501SWMM_ENGINE_API int swmm_rdii_decay_set(SWMM_Engine engine, const char* uh_name,
502 int response,
503 double k_dep, double k_0, double k_T,
504 double T_ref, double theta_rec, double T_freeze,
505 int snow_on, double snow_T, double snow_ddf);
506
514SWMM_ENGINE_API int swmm_rdii_decay_remove(SWMM_Engine engine, const char* uh_name, int response);
515
516/* =========================================================================
517 * Exponential IA decay ([RDII_DECAY] section)
518 * =========================================================================
519 *
520 * Physics-based replacement for the legacy linear IA recovery. When a row
521 * is present for a (UH group, response) pair, the exponential depletion /
522 * temperature-dependent recovery model is used in place of the linear
523 * `drecov` rate from the corresponding [HYDROGRAPHS] entry.
524 *
525 * @see docs/RDII_ExpDecay_Implementation.md
526 * ========================================================================= */
527
549SWMM_ENGINE_API int swmm_rdii_decay_add(SWMM_Engine engine, const char* uh_name,
550 int response,
551 double k_dep, double k_0, double k_T,
552 double T_ref, double theta_rec, double T_freeze,
553 int snow_on, double snow_T, double snow_ddf);
554
574SWMM_ENGINE_API int swmm_rdii_decay_get(SWMM_Engine engine, int entry_idx,
575 char* uh_buf, int buflen,
576 int* response,
577 double* k_dep, double* k_0, double* k_T,
578 double* T_ref, double* theta_rec, double* T_freeze,
579 int* snow_on, double* snow_T, double* snow_ddf);
580
586
587/* =========================================================================
588 * Count queries
589 * ========================================================================= */
590
597
604
611
612#ifdef __cplusplus
613} /* extern "C" */
614#endif
615
616#endif /* OPENSWMM_INFLOWS_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_rdii_decay_get(SWMM_Engine engine, int entry_idx, char *uh_buf, int buflen, int *response, double *k_dep, double *k_0, double *k_T, double *T_ref, double *theta_rec, double *T_freeze, int *snow_on, double *snow_T, double *snow_ddf)
Read back an exponential-decay parameter row by index.
Definition openswmm_inflows_impl.cpp:427
SWMM_ENGINE_API int swmm_ext_inflow_count(SWMM_Engine engine)
Get the total number of external inflows defined.
Definition openswmm_inflows_impl.cpp:723
SWMM_ENGINE_API int swmm_hydrograph_gage_count(SWMM_Engine engine)
Count UH-to-gage assignments.
Definition openswmm_inflows_impl.cpp:372
SWMM_ENGINE_API int swmm_dwf_count(SWMM_Engine engine)
Get the total number of dry weather flow entries defined.
Definition openswmm_inflows_impl.cpp:728
SWMM_ENGINE_API int swmm_dwf_get(SWMM_Engine engine, int entry_idx, int *node_idx, char *constituent_buf, int constituent_buflen, double *avg_value, char *pat1_buf, int pat1_buflen, char *pat2_buf, int pat2_buflen, char *pat3_buf, int pat3_buflen, char *pat4_buf, int pat4_buflen)
Read back a dry weather flow entry by index.
Definition openswmm_inflows_impl.cpp:199
SWMM_ENGINE_API int swmm_hydrograph_set_gage(SWMM_Engine engine, const char *uh_name, const char *gage_name)
Set, replace, or clear the rain gage assigned to a UH group.
Definition openswmm_inflows_impl.cpp:606
SWMM_ENGINE_API int swmm_rdii_get(SWMM_Engine engine, int entry_idx, int *node_idx, char *uh_buf, int buflen, double *area)
Read back an RDII assignment by entry index.
Definition openswmm_inflows_impl.cpp:265
SWMM_ENGINE_API int swmm_rdii_count(SWMM_Engine engine)
Get the total number of RDII entries defined.
Definition openswmm_inflows_impl.cpp:733
SWMM_ENGINE_API int swmm_hydrograph_group_rename(SWMM_Engine engine, int idx, const char *new_id)
Rename a UH group, propagating the new name to parameter rows, gage assignments, [RDII_DECAY] rows,...
Definition openswmm_inflows_impl.cpp:630
SWMM_ENGINE_API int swmm_hydrograph_add(SWMM_Engine engine, const char *uh_name, int month, int response, double r, double t, double k, double dmax, double drecov, double dinit)
Add a unit hydrograph parameter line.
Definition openswmm_inflows_impl.cpp:292
SWMM_ENGINE_API int swmm_dwf_set_baseline(SWMM_Engine engine, int entry_idx, double avg_value)
Set a DWF entry's average (baseline) value at runtime.
Definition openswmm_inflows_impl.cpp:240
SWMM_ENGINE_API int swmm_rdii_add(SWMM_Engine engine, int node_idx, const char *uh_name, double area)
Add RDII inflow to a node using a unit hydrograph.
Definition openswmm_inflows_impl.cpp:254
SWMM_ENGINE_API int swmm_ext_inflow_set_baseline(SWMM_Engine engine, int entry_idx, double baseline)
Set an external inflow entry's constant baseline at runtime.
Definition openswmm_inflows_impl.cpp:123
SWMM_ENGINE_API int swmm_hydrograph_clear_group_months(SWMM_Engine engine, const char *uh_name)
Bulk-clear every per-month parameter row for a group, leaving any existing month=-1 (ALL) row intact.
Definition openswmm_inflows_impl.cpp:590
SWMM_ENGINE_API int swmm_ext_inflow_remove(SWMM_Engine engine, int entry_idx)
Remove an external inflow entry by index.
Definition openswmm_inflows_impl.cpp:164
SWMM_ENGINE_API int swmm_hydrograph_get_gage(SWMM_Engine engine, int entry_idx, char *uh_buf, int uh_buflen, char *gage_buf, int gage_buflen)
Read back a UH-to-gage assignment by index.
Definition openswmm_inflows_impl.cpp:356
SWMM_ENGINE_API int swmm_rdii_decay_remove(SWMM_Engine engine, const char *uh_name, int response)
Remove the exponential-decay row for one (group, response) pair.
Definition openswmm_inflows_impl.cpp:705
SWMM_ENGINE_API int swmm_hydrograph_set_rtk(SWMM_Engine engine, const char *uh_name, int month, int response, double r, double t, double k)
Upsert R/T/K parameters for one (group, month, response) row.
Definition openswmm_inflows_impl.cpp:511
SWMM_ENGINE_API int swmm_ext_inflow_get(SWMM_Engine engine, int entry_idx, int *node_idx, char *constituent_buf, int constituent_buflen, char *ts_buf, int ts_buflen, char *type_buf, int type_buflen, double *m_factor, double *s_factor, double *baseline, char *pattern_buf, int pattern_buflen)
Read back an external inflow entry by index.
Definition openswmm_inflows_impl.cpp:133
SWMM_ENGINE_API int swmm_hydrograph_remove_group(SWMM_Engine engine, const char *uh_name)
Remove an entire UH group: parameter rows + gage assignment + [RDII_DECAY] rows + [RDII] node assignm...
Definition openswmm_inflows_impl.cpp:580
SWMM_ENGINE_API int swmm_hydrograph_remove_entry(SWMM_Engine engine, const char *uh_name, int month, int response)
Remove one parameter entry by (group, month, response).
Definition openswmm_inflows_impl.cpp:565
SWMM_ENGINE_API int swmm_dwf_remove(SWMM_Engine engine, int entry_idx)
Remove a DWF entry by index. Subsequent entries shift down.
Definition openswmm_inflows_impl.cpp:231
SWMM_ENGINE_API int swmm_ext_inflow_set_scale(SWMM_Engine engine, int entry_idx, double scale)
Set an external inflow entry's timeseries scale factor at runtime.
Definition openswmm_inflows_impl.cpp:113
SWMM_ENGINE_API int swmm_rdii_decay_count(SWMM_Engine engine)
Count exponential-decay parameter rows.
Definition openswmm_inflows_impl.cpp:457
SWMM_ENGINE_API int swmm_hydrograph_group_count(SWMM_Engine engine)
Count the unique unit-hydrograph group names defined.
Definition openswmm_inflows_impl.cpp:378
SWMM_ENGINE_API int swmm_hydrograph_get(SWMM_Engine engine, int entry_idx, char *uh_buf, int buflen, int *month, int *response, double *r, double *t, double *k, double *dmax, double *drecov, double *dinit)
Read back a hydrograph parameter entry by index.
Definition openswmm_inflows_impl.cpp:316
SWMM_ENGINE_API int swmm_rdii_decay_add(SWMM_Engine engine, const char *uh_name, int response, double k_dep, double k_0, double k_T, double T_ref, double theta_rec, double T_freeze, int snow_on, double snow_T, double snow_ddf)
Add an exponential-decay parameter row for a (UH, response) pair.
Definition openswmm_inflows_impl.cpp:399
SWMM_ENGINE_API int swmm_hydrograph_group_id(SWMM_Engine engine, int idx, char *buf, int buflen)
Read back the name of a unit-hydrograph group by its zero-based index.
Definition openswmm_inflows_impl.cpp:384
SWMM_ENGINE_API int swmm_rdii_remove(SWMM_Engine engine, int entry_idx)
Remove an RDII entry by index. Subsequent entries shift down.
Definition openswmm_inflows_impl.cpp:280
SWMM_ENGINE_API int swmm_ext_inflow_add(SWMM_Engine engine, int node_idx, const char *constituent, const char *ts_name, const char *type, double m_factor, double s_factor, double baseline, const char *pattern)
Add an external inflow to a node.
Definition openswmm_inflows_impl.cpp:89
SWMM_ENGINE_API int swmm_rdii_decay_set(SWMM_Engine engine, const char *uh_name, int response, double k_dep, double k_0, double k_T, double T_ref, double theta_rec, double T_freeze, int snow_on, double snow_T, double snow_ddf)
Upsert exponential-decay parameters for one (group, response) row.
Definition openswmm_inflows_impl.cpp:667
SWMM_ENGINE_API int swmm_dwf_add(SWMM_Engine engine, int node_idx, const char *constituent, double avg_value, const char *pat1, const char *pat2, const char *pat3, const char *pat4)
Add a dry weather flow component to a node.
Definition openswmm_inflows_impl.cpp:177
SWMM_ENGINE_API int swmm_hydrograph_count(SWMM_Engine engine)
Count parameter entries in the model.
Definition openswmm_inflows_impl.cpp:341
SWMM_ENGINE_API int swmm_hydrograph_add_gage(SWMM_Engine engine, const char *uh_name, const char *gage_name)
Assign a rain gage to a unit hydrograph group.
Definition openswmm_inflows_impl.cpp:346
SWMM_ENGINE_API int swmm_hydrograph_set_ia(SWMM_Engine engine, const char *uh_name, int month, int response, double dmax, double drecov, double dinit)
Upsert linear-IA parameters for one (group, month, response) row.
Definition openswmm_inflows_impl.cpp:538