![]() |
OpenSWMM Engine
6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
|
Public C API implementation for snow models and meteorology. More...
#include "openswmm_api_common.hpp"#include "../../../include/openswmm/engine/openswmm_snow.h"#include "../../../include/openswmm/engine/openswmm_snow2d.h"#include "../input/Tokenizer.hpp"#include "PathResolver.hpp"#include "UnitConversion.hpp"#include <iomanip>#include <sstream>#include <cmath>#include <limits>Functions | |
| SWMM_ENGINE_API int | swmm_snow_get_model (SWMM_Engine engine, int *model) |
| Read the global snow-process model. | |
| SWMM_ENGINE_API int | swmm_snow_set_model (SWMM_Engine engine, int model) |
| Select the global snow-process model. | |
| SWMM_ENGINE_API int | swmm_snow_get_step (SWMM_Engine engine, double *seconds) |
| Read the snow-process cadence in seconds. | |
| SWMM_ENGINE_API int | swmm_snow_set_step (SWMM_Engine engine, double seconds) |
| Configure the snow-process cadence in seconds. | |
| SWMM_ENGINE_API int | swmm_ueb_option_get (SWMM_Engine engine, const char *key, char *out, int size) |
| Read a recognized UEB option in its input-section text format. | |
| SWMM_ENGINE_API int | swmm_ueb_option_set (SWMM_Engine engine, const char *key, const char *value) |
| Parse and assign one UEB option from a textual value. | |
| SWMM_ENGINE_API int | swmm_ueb_get_monthly_ranges (SWMM_Engine engine, double *values) |
| Read twelve authored UEB monthly daily-temperature-range overrides. | |
| SWMM_ENGINE_API int | swmm_ueb_set_monthly_ranges (SWMM_Engine engine, const double *values) |
| Replace twelve UEB monthly daily-temperature-range overrides. | |
| SWMM_ENGINE_API int | swmm_snowpack_get_ueb (SWMM_Engine engine, int pack, SWMM_UebSnowpack *value) |
| Read a named pack's UEB/model overrides. | |
| SWMM_ENGINE_API int | swmm_snowpack_set_ueb (SWMM_Engine engine, int pack, const SWMM_UebSnowpack *value) |
| Replace a named pack's UEB/model overrides. | |
| SWMM_ENGINE_API int | swmm_snowpack_apply (SWMM_Engine engine, const SWMM_SnowpackEdit *edits, int count, char *diagnostic, int capacity) |
| Validate and upsert a batch of named snowpacks as one atomic edit. | |
| SWMM_ENGINE_API int | swmm_subcatch_get_snow_process_state (SWMM_Engine engine, int sc, int surface, SWMM_SnowState *value) |
| Snapshot one subcatchment snow surface's accepted process state. | |
| SWMM_ENGINE_API int | swmm_snow_get_ueb_ledger (SWMM_Engine engine, SWMM_SnowLedger *value) |
| Aggregate the active UEB subcatchment water and energy inventory. | |
| SWMM_ENGINE_API int | swmm_climate_get_radiation (SWMM_Engine engine, SWMM_RadiationConfig *value) |
| Read the shared radiation site and source selectors. | |
| SWMM_ENGINE_API int | swmm_climate_set_radiation (SWMM_Engine engine, const SWMM_RadiationConfig *value) |
| Replace the shared radiation site and source selectors. | |
| SWMM_ENGINE_API int | swmm_climate_get_radiation_source (SWMM_Engine engine, int channel, char *value, int capacity) |
| Read one radiation source name or meteorology path. | |
| SWMM_ENGINE_API int | swmm_climate_set_radiation_source (SWMM_Engine engine, int channel, const char *value) |
| Bind one radiation source name or meteorology path. | |
| SWMM_ENGINE_API int | swmm_snow_apply_configuration (SWMM_Engine engine, const char *temperature_rows, const char *ueb_rows, char *diagnostic, int capacity) |
| Atomically replace global snow/radiation section configuration. | |
| SWMM_ENGINE_API int | swmm_climate_preview_meteorology (SWMM_Engine engine, const char *path, SWMM_ClimateMetSummary *result, char *diagnostic, int capacity) |
| Read and validate hourly meteorology without changing the model binding. | |
| SWMM_ENGINE_API int | swmm_climate_get_cloud (SWMM_Engine engine, SWMM_ClimateCloudConfig *config, char *series, int capacity) |
| Snapshot the shared heat/climatology cloud configuration and series name. | |
| SWMM_ENGINE_API int | swmm_snow_apply_configuration_with_cloud (SWMM_Engine engine, const char *temperature_rows, const char *ueb_rows, const SWMM_ClimateCloudConfig *cloud, const char *cloud_series, char *diagnostic, int capacity) |
| Atomically replace global snow/radiation section configuration, optionally including clouds. | |
| SWMM_ENGINE_API int | swmm_snow2d_get_options (SWMM_Engine engine, int *mode, double *step) |
| Read mesh snow enable mode and authored cadence. | |
| SWMM_ENGINE_API int | swmm_snow2d_defaults_count (SWMM_Engine engine) |
| Count authored mesh-snow default/tag rows. | |
| SWMM_ENGINE_API int | swmm_snow2d_cells_count (SWMM_Engine engine) |
| Count authored mesh-snow explicit cell rows. | |
| SWMM_ENGINE_API int | swmm_snow2d_get_configuration (SWMM_Engine engine, int section, char *buffer, int capacity, int *required) |
| Serialize one mesh-snow section body and report its required capacity. | |
| SWMM_ENGINE_API int | swmm_snow2d_apply_configuration (SWMM_Engine engine, const char *options, const char *defaults, const char *cells, char *diagnostic, int capacity) |
| Validate and atomically replace all mesh-snow authored section bodies. | |
| SWMM_ENGINE_API int | swmm_snow2d_get_row (SWMM_Engine engine, int section, int index, int *cell, char *tag, int tag_capacity, char *pack, int pack_capacity, SWMM_MeshSnowOverrides *values) |
| Read an authored mesh-snow assignment without resolving inherited overrides. | |
| SWMM_ENGINE_API int | swmm_snow2d_get_states (SWMM_Engine engine, int first, int count, SWMM_SnowState *output) |
| Snapshot a contiguous range of accepted mesh-snow states. | |
| SWMM_ENGINE_API int | swmm_snow2d_get_ledgers (SWMM_Engine engine, int first, int count, SWMM_MeshSnowLedger *output) |
| Snapshot a contiguous range of accepted mesh-snow ledgers. | |
| SWMM_ENGINE_API int | swmm_snow2d_get_geometry_energy (SWMM_Engine engine, int first, int count, double *output) |
| Read accumulated UEB geometry-remapping energy for a cell range. | |
Public C API implementation for snow models and meteorology.
| SWMM_ENGINE_API int swmm_climate_get_cloud | ( | SWMM_Engine | engine, |
| SWMM_ClimateCloudConfig * | config, | ||
| char * | series, | ||
| int | capacity ) |
Snapshot the shared heat/climatology cloud configuration and series name.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [out] | config | Non-null configuration: mode 0 default, 1 constant or 2 series, fraction dimensionless and attenuation coefficients in their authored convention. |
| [out] | series | Non-null writable name buffer; empty when no valid series binding exists. |
| [in] | capacity | Positive byte capacity including the terminator; a short buffer returns SWMM_ERR_BUFSIZE and writes nothing. |
| SWMM_ENGINE_API int swmm_climate_get_radiation | ( | SWMM_Engine | engine, |
| SWMM_RadiationConfig * | value ) |
Read the shared radiation site and source selectors.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [out] | value | Non-null configuration. Site latitude/longitude are degrees, timezone hours and elevation m. Modes are 0 computed, 1 time series, 2 met file; authored flags control legacy-alias preservation. |
| SWMM_ENGINE_API int swmm_climate_get_radiation_source | ( | SWMM_Engine | engine, |
| int | channel, | ||
| char * | value, | ||
| int | capacity ) |
Read one radiation source name or meteorology path.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [in] | channel | 0 shortwave time series, 1 longwave time series, 2 met-file path. |
| [out] | value | Non-null writable string buffer. |
| [in] | capacity | Positive byte capacity including the terminator; insufficient capacity returns SWMM_ERR_BUFSIZE and writes nothing. |
| SWMM_ENGINE_API int swmm_climate_preview_meteorology | ( | SWMM_Engine | engine, |
| const char * | path, | ||
| SWMM_ClimateMetSummary * | result, | ||
| char * | diagnostic, | ||
| int | capacity ) |
Read and validate hourly meteorology without changing the model binding.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [in] | path | Non-null filename; relative paths resolve from the input file's parent directory. |
| [out] | result | Non-null summary with record count, half-open SWMM-date coverage, and min/max columns in degrees C, relative-humidity percent, m/s, and W/m2 radiation. |
| [out] | diagnostic | Non-null writable text buffer; empty on success. |
| [in] | capacity | Positive byte capacity; an error message may be safely truncated. |
| SWMM_ENGINE_API int swmm_climate_set_radiation | ( | SWMM_Engine | engine, |
| const SWMM_RadiationConfig * | value ) |
Replace the shared radiation site and source selectors.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [in] | value | Non-null configuration. Site latitude/longitude are degrees, timezone hours and elevation m. Modes are 0 computed, 1 time series, 2 met file; authored flags control legacy-alias preservation. |
| SWMM_ENGINE_API int swmm_climate_set_radiation_source | ( | SWMM_Engine | engine, |
| int | channel, | ||
| const char * | value ) |
Bind one radiation source name or meteorology path.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [in] | channel | 0 shortwave time series, 1 longwave time series, 2 met-file path. |
| [in] | value | Non-null null-terminated source text; newline and quote characters are rejected. |
| SWMM_ENGINE_API int swmm_snow2d_apply_configuration | ( | SWMM_Engine | engine, |
| const char * | options, | ||
| const char * | defaults, | ||
| const char * | cells, | ||
| char * | diagnostic, | ||
| int | capacity ) |
Validate and atomically replace all mesh-snow authored section bodies.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [in] | options | Non-null options text without a section header. |
| [in] | defaults | Non-null whole-mesh/tag rows; precedence is cell > tag > whole mesh. |
| [in] | cells | Non-null explicit-cell rows; section text uses one-based cell keys. Empty section strings clear their section. NONE explicitly disables a scope. |
| [out] | diagnostic | Non-null writable diagnostic text; empty on success. |
| [in] | capacity | Positive byte capacity; failure text is safely truncated if necessary. |
| SWMM_ENGINE_API int swmm_snow2d_cells_count | ( | SWMM_Engine | engine | ) |
Count authored mesh-snow explicit cell rows.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| SWMM_ENGINE_API int swmm_snow2d_defaults_count | ( | SWMM_Engine | engine | ) |
Count authored mesh-snow default/tag rows.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| SWMM_ENGINE_API int swmm_snow2d_get_configuration | ( | SWMM_Engine | engine, |
| int | section, | ||
| char * | buffer, | ||
| int | capacity, | ||
| int * | required ) |
Serialize one mesh-snow section body and report its required capacity.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [in] | section | 0 options, 1 defaults/tags, 2 explicit cells. |
| [out] | buffer | Writable text buffer, or NULL with capacity == 0 for a size query. |
| [in] | capacity | Nonnegative byte capacity; must include the terminal NUL for copying. |
| [out] | required | Non-null slot for exact required bytes including NUL, set before a short-buffer failure when section serialization succeeds. |
| SWMM_ENGINE_API int swmm_snow2d_get_geometry_energy | ( | SWMM_Engine | engine, |
| int | first, | ||
| int | count, | ||
| double * | energy_kj ) |
Read accumulated UEB geometry-remapping energy for a cell range.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [in] | first | First zero-based mesh cell, at most cell count. |
| [in] | count | Nonnegative number of cells; the full range must fit the mesh. |
| [out] | energy_kj | Borrowed count-element destination in kJ; NULL allowed for zero count. |
| SWMM_ENGINE_API int swmm_snow2d_get_ledgers | ( | SWMM_Engine | engine, |
| int | first, | ||
| int | count, | ||
| SWMM_MeshSnowLedger * | output ) |
Snapshot a contiguous range of accepted mesh-snow ledgers.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [in] | first | First zero-based cell index, at most the mesh cell count. |
| [in] | count | Nonnegative range length; first + count must fit the mesh. |
| [out] | output | Borrowed writable array of count SWMM_MeshSnowLedger entries; may be NULL for count == 0. Values use seconds, m3 water inventories and kJ energy inventories. |
| SWMM_ENGINE_API int swmm_snow2d_get_options | ( | SWMM_Engine | engine, |
| int * | mode, | ||
| double * | step_s ) |
Read mesh snow enable mode and authored cadence.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [out] | mode | Non-null slot: 0 AUTO, 1 YES, 2 NO. |
| [out] | step_s | Non-null authored seconds; zero inherits the shared cadence. |
| SWMM_ENGINE_API int swmm_snow2d_get_row | ( | SWMM_Engine | engine, |
| int | section, | ||
| int | row, | ||
| int * | cell, | ||
| char * | tag, | ||
| int | tag_capacity, | ||
| char * | pack, | ||
| int | pack_capacity, | ||
| SWMM_MeshSnowOverrides * | values ) |
Read an authored mesh-snow assignment without resolving inherited overrides.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [in] | section | 1 for default/tag rows, 2 for explicit cell rows. |
| [in] | row | Zero-based position in that section's current map iteration order. |
| [out] | cell | Non-null slot; -1 for defaults or the zero-based cell for explicit rows. |
| [out] | tag | Non-null writable tag buffer; empty for explicit cell rows. |
| [in] | tag_capacity | Positive capacity including the terminator; short buffers fail. |
| [out] | pack | Non-null writable pack-name buffer; NONE explicitly disables snow. |
| [in] | pack_capacity | Positive pack-name capacity including the terminator. |
| [out] | values | Non-null override structure, with NaN for inherited fields. SI values use W/m2 and m; slope/aspect are degrees and fraction/drift dimensionless. |
| SWMM_ENGINE_API int swmm_snow2d_get_states | ( | SWMM_Engine | engine, |
| int | first, | ||
| int | count, | ||
| SWMM_SnowState * | output ) |
Snapshot a contiguous range of accepted mesh-snow states.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [in] | first | First zero-based cell index, at most the mesh cell count. |
| [in] | count | Nonnegative range length; first + count must fit the mesh. |
| [out] | output | Borrowed writable array of count SWMM_SnowState entries; may be NULL for count == 0. Values use m SWE, m/s water rates, degrees C temperatures, kJ/m2 energy and dimensionless fractions/age. |
| SWMM_ENGINE_API int swmm_snow_apply_configuration | ( | SWMM_Engine | engine, |
| const char * | temperature_rows, | ||
| const char * | ueb_rows, | ||
| char * | diagnostic, | ||
| int | capacity ) |
Atomically replace global snow/radiation section configuration.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [in] | temperature_rows | Non-null null-terminated TEMPERATURE section body without headers. |
| [in] | ueb_rows | Non-null null-terminated UEB section body without headers. Empty bodies restore defaults; existing named-pack assignments are preserved. |
| [out] | diagnostic | Non-null writable buffer, empty on success or a validation message on failure. |
| [in] | capacity | Positive byte capacity; diagnostics are truncated safely to fit. |
| SWMM_ENGINE_API int swmm_snow_apply_configuration_with_cloud | ( | SWMM_Engine | engine, |
| const char * | temperature_rows, | ||
| const char * | ueb_rows, | ||
| const SWMM_ClimateCloudConfig * | cloud, | ||
| const char * | cloud_series, | ||
| char * | diagnostic, | ||
| int | capacity ) |
Atomically replace global snow/radiation section configuration, optionally including clouds.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [in] | temperature_rows | Non-null null-terminated TEMPERATURE section body without headers. |
| [in] | ueb_rows | Non-null null-terminated UEB section body without headers. Empty bodies restore defaults; existing named-pack assignments are preserved. |
| [in] | cloud | Optional shared cloud configuration; NULL preserves it. Mode is 0 default, 1 constant or 2 time series; fraction is [0, 1] and attenuation coefficients/exponents are finite nonnegative values. |
| [in] | cloud_series | Required existing series name for cloud mode 2; ignored when cloud is NULL or a non-series mode is selected. |
| [out] | diagnostic | Non-null writable buffer, empty on success or a validation message on failure. |
| [in] | capacity | Positive byte capacity; diagnostics are truncated safely to fit. |
| SWMM_ENGINE_API int swmm_snow_get_model | ( | SWMM_Engine | engine, |
| int * | model ) |
Read the global snow-process model.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [out] | model | Non-null result slot: SWMM_SNOW_DEGREE_DAY (0) or SWMM_SNOW_UEB (1). |
| SWMM_ENGINE_API int swmm_snow_get_step | ( | SWMM_Engine | engine, |
| double * | seconds ) |
Read the snow-process cadence in seconds.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [out] | seconds | Non-null result slot for the authored cadence. |
| SWMM_ENGINE_API int swmm_snow_get_ueb_ledger | ( | SWMM_Engine | engine, |
| SWMM_SnowLedger * | value ) |
Aggregate the active UEB subcatchment water and energy inventory.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [out] | value | Non-null caller-owned ledger: elapsed_s in seconds, water categories in m3, and energy categories in kJ. Transfers are signed into the inventory; inactive duplicate native columns are excluded. |
| SWMM_ENGINE_API int swmm_snow_set_model | ( | SWMM_Engine | engine, |
| int | model ) |
Select the global snow-process model.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [in] | model | SWMM_SNOW_DEGREE_DAY (0) or SWMM_SNOW_UEB (1). |
| SWMM_ENGINE_API int swmm_snow_set_step | ( | SWMM_Engine | engine, |
| double | seconds ) |
Configure the snow-process cadence in seconds.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [in] | seconds | Finite cadence in [1, 21600] seconds, validated by the SNOW_STEP parser. |
| SWMM_ENGINE_API int swmm_snowpack_apply | ( | SWMM_Engine | engine, |
| const SWMM_SnowpackEdit * | edits, | ||
| int | count, | ||
| char * | diagnostic, | ||
| int | capacity ) |
Validate and upsert a batch of named snowpacks as one atomic edit.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [in] | edits | Borrowed count-element edit array; may be NULL only for count == 0. Pack names must be nonempty, unique case-insensitively within the batch, and contain no newline/quote characters. Surface/removal units follow the existing three snowpack rows; UEB fields use SI units from SWMM_UebSnowpack. |
| [in] | count | Nonnegative number of pack edits; omitted existing packs are preserved. |
| [out] | diagnostic | Non-null writable diagnostic buffer; empty on successful validation. |
| [in] | capacity | Positive diagnostic byte capacity; error text may be truncated with a terminator. |
| SWMM_ENGINE_API int swmm_snowpack_get_ueb | ( | SWMM_Engine | engine, |
| int | pack, | ||
| SWMM_UebSnowpack * | value ) |
Read a named pack's UEB/model overrides.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [in] | pack | Zero-based snowpack index, in [0, snowpack count). |
| [out] | value | Non-null destination structure. Forest/drift are dimensionless, ground heat W/m2, extinction depth m and initial energy kJ/m2. An absent row returns SWMM_SNOW_DEFAULT with standard site defaults. |
| SWMM_ENGINE_API int swmm_snowpack_set_ueb | ( | SWMM_Engine | engine, |
| int | pack, | ||
| const SWMM_UebSnowpack * | value ) |
Replace a named pack's UEB/model overrides.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [in] | pack | Zero-based snowpack index, in [0, snowpack count). |
| [in] | value | Non-null configuration structure. Forest/drift are dimensionless, ground heat W/m2, extinction depth m and initial energy kJ/m2. SWMM_SNOW_DEFAULT removes the explicit override; other models and site values are validated by the snowpack parser. |
| SWMM_ENGINE_API int swmm_subcatch_get_snow_process_state | ( | SWMM_Engine | engine, |
| int | subcatch, | ||
| int | surface, | ||
| SWMM_SnowState * | value ) |
Snapshot one subcatchment snow surface's accepted process state.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [in] | subcatch | Zero-based valid subcatchment index. |
| [in] | surface | 0 plowable, 1 impervious, or 2 pervious. |
| [out] | value | Non-null caller-owned state. SWE/depth is subarea-averaged m, liquid/sublimation rates m/s, temperatures degrees C, covered-pack energy kJ/m2, water age seconds, and other fractions/age terms dimensionless. |
| SWMM_ENGINE_API int swmm_ueb_get_monthly_ranges | ( | SWMM_Engine | engine, |
| double * | values ) |
Read twelve authored UEB monthly daily-temperature-range overrides.
Writes range in degC, with zero representing inheritance from current climate DTR; does not compute the effective climate-derived monthly value. No allocation or clock advancement.
| [in] | engine | Live engine handle; no lifecycle-state guard beyond non-NULL handle. |
| [out] | values | Caller-owned writable array of at least twelve doubles in January..December order. |
| SWMM_ENGINE_API int swmm_ueb_option_get | ( | SWMM_Engine | engine, |
| const char * | key, | ||
| char * | value, | ||
| int | capacity ) |
Read a recognized UEB option in its input-section text format.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [in] | key | Non-null null-terminated UEB key, accepted by uebOptionValue(). |
| [out] | value | Non-null writable string buffer; receives the complete value and terminator. |
| [in] | capacity | Positive byte capacity including the terminator; insufficient capacity returns SWMM_ERR_BUFSIZE and writes nothing. |
| SWMM_ENGINE_API int swmm_ueb_option_set | ( | SWMM_Engine | engine, |
| const char * | key, | ||
| const char * | value ) |
Parse and assign one UEB option from a textual value.
| [in] | engine | Borrowed live engine handle; not retained by this call. |
| [in] | key | Non-null null-terminated UEB option key. |
| [in] | value | Non-null null-terminated value text, tokenized using input-file syntax. |
| SWMM_ENGINE_API int swmm_ueb_set_monthly_ranges | ( | SWMM_Engine | engine, |
| const double * | values ) |
Replace twelve UEB monthly daily-temperature-range overrides.
Validates all values before any assignment. Positive values set authored overrides, zero restores inheritance; no climate table mutation or simulation step.
| [in] | engine | Live editable engine handle in BUILDING or OPENED state. |
| [in] | values | Caller-owned readable array of twelve January..December values, each finite and within [0,100] degC. |