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
75SWMM_ENGINE_API int swmm_ext_inflow_add(SWMM_Engine engine, int node_idx, const char* constituent,
76 const char* ts_name, const char* type, double m_factor,
77 double s_factor, double baseline, const char* pattern);
78
108SWMM_ENGINE_API int swmm_ext_inflow_get(SWMM_Engine engine, int entry_idx, int* node_idx,
109 char* constituent_buf, int constituent_buflen, char* ts_buf,
110 int ts_buflen, char* type_buf, int type_buflen,
111 double* m_factor, double* s_factor, double* baseline,
112 char* pattern_buf, int pattern_buflen);
113
131SWMM_ENGINE_API int swmm_ext_inflow_remove(SWMM_Engine engine, int entry_idx);
132
146SWMM_ENGINE_API int swmm_ext_inflow_set_scale(SWMM_Engine engine, int entry_idx, double scale);
147
162 double baseline);
163
164/* =========================================================================
165 * Dry weather flow
166 * ========================================================================= */
167
190SWMM_ENGINE_API int swmm_dwf_add(SWMM_Engine engine, int node_idx, const char* constituent,
191 double avg_value, const char* pat1, const char* pat2,
192 const char* pat3, const char* pat4);
193
219SWMM_ENGINE_API int swmm_dwf_get(SWMM_Engine engine, int entry_idx, int* node_idx,
220 char* constituent_buf, int constituent_buflen, double* avg_value,
221 char* pat1_buf, int pat1_buflen, char* pat2_buf, int pat2_buflen,
222 char* pat3_buf, int pat3_buflen, char* pat4_buf, int pat4_buflen);
223
236SWMM_ENGINE_API int swmm_dwf_remove(SWMM_Engine engine, int entry_idx);
237
251SWMM_ENGINE_API int swmm_dwf_set_baseline(SWMM_Engine engine, int entry_idx, double avg_value);
252
253/* =========================================================================
254 * RDII (Rainfall-Dependent Infiltration/Inflow)
255 * ========================================================================= */
256
274SWMM_ENGINE_API int swmm_rdii_add(SWMM_Engine engine, int node_idx, const char* uh_name,
275 double area);
276
295SWMM_ENGINE_API int swmm_rdii_get(SWMM_Engine engine, int entry_idx, int* node_idx, char* uh_buf,
296 int buflen, double* area);
297
308SWMM_ENGINE_API int swmm_rdii_remove(SWMM_Engine engine, int entry_idx);
309
310/* =========================================================================
311 * Unit hydrographs ([HYDROGRAPHS] section)
312 * =========================================================================
313 *
314 * A unit hydrograph group is identified by name and has two kinds of input
315 * lines:
316 * - A gage assignment line: "UHname RainGage"
317 * - One or more parameter lines: "UHname Month Response R T K [Dmax Drecov Dinit]"
318 *
319 * Both kinds are added separately. `swmm_hydrograph_add` adds a parameter
320 * line, `swmm_hydrograph_add_gage` adds the gage assignment. Counts and
321 * getters are also separated.
322 *
323 * `response` is encoded as: 0 = SHORT, 1 = MEDIUM, 2 = LONG.
324 * `month` is encoded as: 0..11 = JAN..DEC, or -1 = ALL.
325 * ========================================================================= */
326
351SWMM_ENGINE_API int swmm_hydrograph_add(SWMM_Engine engine, const char* uh_name, int month,
352 int response, double r, double t, double k, double dmax,
353 double drecov, double dinit);
354
378SWMM_ENGINE_API int swmm_hydrograph_get(SWMM_Engine engine, int entry_idx, char* uh_buf, int buflen,
379 int* month, int* response, double* r, double* t, double* k,
380 double* dmax, double* drecov, double* dinit);
381
389
403SWMM_ENGINE_API int swmm_hydrograph_add_gage(SWMM_Engine engine, const char* uh_name,
404 const char* gage_name);
405
423SWMM_ENGINE_API int swmm_hydrograph_get_gage(SWMM_Engine engine, int entry_idx, char* uh_buf,
424 int uh_buflen, char* gage_buf, int gage_buflen);
425
433
448
468SWMM_ENGINE_API int swmm_hydrograph_group_id(SWMM_Engine engine, int idx, char* buf, int buflen);
469
470/* =========================================================================
471 * Mutation surface (BS-02) — upsert + key-based remove + rename
472 * =========================================================================
473 *
474 * The legacy `swmm_hydrograph_add` / `swmm_hydrograph_add_gage` surface above
475 * is append-only, which prevents in-place edits from a UI. The following
476 * setters/removers support the `HydrographGroupEditor` MVC layer in
477 * openswmm.gui: every mutation in the editor routes through one of these
478 * symbols, and the GUI's `SWMMModelLayer` emits a `hydrographChanged(uhName)`
479 * signal so all subscribed views (Object Browser, property panel, picker
480 * combos, etc.) refresh in lock-step.
481 *
482 * Upsert contract (set_rtk, set_ia, decay_set):
483 * - If an entry matching the supplied key exists, update only the fields
484 * this setter owns and leave the rest untouched.
485 * - Otherwise append a new entry with the supplied fields set and the
486 * unspecified fields zeroed (so set_rtk followed by set_ia on the same
487 * key composes correctly).
488 *
489 * Remove contract (remove_entry, remove_group, decay_remove):
490 * - Key-based, not index-based — indices shift as entries are removed and
491 * a UI cannot keep them in sync. Idempotent: returns SWMM_OK if no
492 * match is found.
493 *
494 * Group remove cascades to: [HYDROGRAPHS] parameter rows, gage assignments,
495 * [RDII_DECAY] rows, AND any [RDII] node assignments referencing the group
496 * (so the engine never sees a dangling UH-name reference after a delete).
497 * ========================================================================= */
498
517SWMM_ENGINE_API int swmm_hydrograph_set_rtk(SWMM_Engine engine, const char* uh_name, int month,
518 int response, double r, double t, double k);
519
538SWMM_ENGINE_API int swmm_hydrograph_set_ia(SWMM_Engine engine, const char* uh_name, int month,
539 int response, double dmax, double drecov, double dinit);
540
555SWMM_ENGINE_API int swmm_hydrograph_remove_entry(SWMM_Engine engine, const char* uh_name, int month,
556 int response);
557
570SWMM_ENGINE_API int swmm_hydrograph_remove_group(SWMM_Engine engine, const char* uh_name);
571
584SWMM_ENGINE_API int swmm_hydrograph_clear_group_months(SWMM_Engine engine, const char* uh_name);
585
600SWMM_ENGINE_API int swmm_hydrograph_set_gage(SWMM_Engine engine, const char* uh_name,
601 const char* gage_name);
602
619SWMM_ENGINE_API int swmm_hydrograph_group_rename(SWMM_Engine engine, int idx, const char* new_id);
620
644SWMM_ENGINE_API int swmm_rdii_decay_set(SWMM_Engine engine, const char* uh_name, int response,
645 double k_dep, double k_0, double k_T, double T_ref,
646 double theta_rec, double T_freeze, int snow_on,
647 double snow_T, double snow_ddf);
648
661SWMM_ENGINE_API int swmm_rdii_decay_remove(SWMM_Engine engine, const char* uh_name, int response);
662
663/* =========================================================================
664 * Exponential IA decay ([RDII_DECAY] section)
665 * =========================================================================
666 *
667 * Physics-based replacement for the legacy linear IA recovery. When a row
668 * is present for a (UH group, response) pair, the exponential depletion /
669 * temperature-dependent recovery model is used in place of the linear
670 * `drecov` rate from the corresponding [HYDROGRAPHS] entry.
671 *
672 * @see docs/RDII_ExpDecay_Implementation.md
673 * ========================================================================= */
674
698SWMM_ENGINE_API int swmm_rdii_decay_add(SWMM_Engine engine, const char* uh_name, int response,
699 double k_dep, double k_0, double k_T, double T_ref,
700 double theta_rec, double T_freeze, int snow_on,
701 double snow_T, double snow_ddf);
702
728SWMM_ENGINE_API int swmm_rdii_decay_get(SWMM_Engine engine, int entry_idx, char* uh_buf, int buflen,
729 int* response, double* k_dep, double* k_0, double* k_T,
730 double* T_ref, double* theta_rec, double* T_freeze,
731 int* snow_on, double* snow_T, double* snow_ddf);
732
740
741/* =========================================================================
742 * Count queries
743 * ========================================================================= */
744
751
758
765
766#ifdef __cplusplus
767} /* extern "C" */
768#endif
769
770#endif /* OPENSWMM_INFLOWS_H */
#define SWMM_ENGINE_API
Definition openswmm_2d.h:62
void * SWMM_Engine
Opaque handle to an OpenSWMM Engine instance.
Definition openswmm_callbacks.h:55
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:425
SWMM_ENGINE_API int swmm_ext_inflow_count(SWMM_Engine engine)
Get the total number of external inflows defined.
Definition openswmm_inflows_impl.cpp:789
SWMM_ENGINE_API int swmm_hydrograph_gage_count(SWMM_Engine engine)
Count stored hydrograph-to-gage assignment rows.
Definition openswmm_inflows_impl.cpp:366
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:795
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:200
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:654
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:259
SWMM_ENGINE_API int swmm_rdii_count(SWMM_Engine engine)
Get the total number of RDII entries defined.
Definition openswmm_inflows_impl.cpp:801
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:680
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:286
SWMM_ENGINE_API int swmm_dwf_set_baseline(SWMM_Engine engine, int entry_idx, double avg_value)
Replace one dry-weather-flow average value.
Definition openswmm_inflows_impl.cpp:233
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:246
SWMM_ENGINE_API int swmm_ext_inflow_set_baseline(SWMM_Engine engine, int entry_idx, double baseline)
Replace one external-inflow baseline.
Definition openswmm_inflows_impl.cpp:135
SWMM_ENGINE_API int swmm_hydrograph_clear_group_months(SWMM_Engine engine, const char *uh_name)
Remove a group's month-specific parameter rows while retaining ALL rows.
Definition openswmm_inflows_impl.cpp:638
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:171
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:351
SWMM_ENGINE_API int swmm_rdii_decay_remove(SWMM_Engine engine, const char *uh_name, int response)
Remove the first exponential-decay row matching a group and response.
Definition openswmm_inflows_impl.cpp:769
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:538
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:145
SWMM_ENGINE_API int swmm_hydrograph_remove_group(SWMM_Engine engine, const char *uh_name)
Remove all authoring rows and RDII assignments for a hydrograph group.
Definition openswmm_inflows_impl.cpp:627
SWMM_ENGINE_API int swmm_hydrograph_remove_entry(SWMM_Engine engine, const char *uh_name, int month, int response)
Remove the first matching hydrograph parameter row.
Definition openswmm_inflows_impl.cpp:608
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:224
SWMM_ENGINE_API int swmm_ext_inflow_set_scale(SWMM_Engine engine, int entry_idx, double scale)
Replace an external-inflow timeseries scale factor.
Definition openswmm_inflows_impl.cpp:126
SWMM_ENGINE_API int swmm_rdii_decay_count(SWMM_Engine engine)
Count stored exponential-decay rows.
Definition openswmm_inflows_impl.cpp:451
SWMM_ENGINE_API int swmm_hydrograph_group_count(SWMM_Engine engine)
Count the unique unit-hydrograph group names defined.
Definition openswmm_inflows_impl.cpp:372
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:312
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)
Append an exponential-depletion and temperature-dependent IA-recovery row.
Definition openswmm_inflows_impl.cpp:394
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:379
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:274
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:110
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 an exponential-depletion and temperature-dependent IA-recovery row.
Definition openswmm_inflows_impl.cpp:722
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:184
SWMM_ENGINE_API int swmm_hydrograph_count(SWMM_Engine engine)
Count stored hydrograph parameter rows, including duplicate keys.
Definition openswmm_inflows_impl.cpp:335
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:341
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:573