![]() |
OpenSWMM Engine
6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
|
C API implementation — landuse, buildup, washoff, treatment. More...
#include "openswmm_api_common.hpp"#include "../../../include/openswmm/engine/openswmm_quality.h"#include "../quality/Treatment.hpp"#include "../quality/MsxSurfaceQuality.hpp"#include <cstring>Functions | |
| SWMM_ENGINE_API int | swmm_landuse_count (SWMM_Engine engine) |
| Count land-use definitions in the current model. | |
| SWMM_ENGINE_API int | swmm_landuse_index (SWMM_Engine engine, const char *id) |
| Resolve a land-use identifier to its row index. | |
| SWMM_ENGINE_API const char * | swmm_landuse_id (SWMM_Engine engine, int idx) |
| Borrow a land-use identifier from the model name index. | |
| SWMM_ENGINE_API int | swmm_landuse_add (SWMM_Engine engine, const char *id) |
| Append a land use while preserving existing model parameter columns. | |
| SWMM_ENGINE_API int | swmm_landuse_rename (SWMM_Engine engine, int idx, const char *new_id) |
| Rename a land use in place. | |
| SWMM_ENGINE_API int | swmm_landuse_set_sweep_interval (SWMM_Engine engine, int idx, double days) |
| Assign the configured interval between street sweeps. | |
| SWMM_ENGINE_API int | swmm_landuse_get_sweep_interval (SWMM_Engine engine, int idx, double *days) |
| Read the configured interval between street sweeps. | |
| SWMM_ENGINE_API int | swmm_landuse_set_sweep_removal (SWMM_Engine engine, int idx, double frac) |
| Assign the land-use sweep-removal fraction. | |
| SWMM_ENGINE_API int | swmm_landuse_get_sweep_removal (SWMM_Engine engine, int idx, double *frac) |
| Read the land-use sweep-removal fraction. | |
| SWMM_ENGINE_API int | swmm_buildup_set (SWMM_Engine engine, int lu_idx, int pollut_idx, int func_type, double c1, double c2, double c3, int normalizer) |
| Set buildup function parameters for a (landuse, pollutant) pair. | |
| SWMM_ENGINE_API int | swmm_buildup_get (SWMM_Engine engine, int lu_idx, int pollut_idx, int *func_type, double *c1, double *c2, double *c3, int *normalizer) |
| Get buildup function parameters for a (landuse, pollutant) pair. | |
| SWMM_ENGINE_API int | swmm_washoff_set (SWMM_Engine engine, int lu_idx, int pollut_idx, int func_type, double coeff, double expon, double sweep_effic, double bmp_effic) |
| Set washoff function parameters for a (landuse, pollutant) pair. | |
| SWMM_ENGINE_API int | swmm_washoff_get (SWMM_Engine engine, int lu_idx, int pollut_idx, int *func_type, double *coeff, double *expon, double *sweep_effic, double *bmp_effic) |
| Get washoff function parameters for a (landuse, pollutant) pair. | |
| SWMM_ENGINE_API int | swmm_treatment_set (SWMM_Engine engine, int node_idx, int pollut_idx, const char *expression) |
| Set a treatment expression for a (node, pollutant) pair. | |
| SWMM_ENGINE_API int | swmm_treatment_get (SWMM_Engine engine, int node_idx, int pollut_idx, char *buf, int buflen) |
| Get a treatment expression for a (node, pollutant) pair. | |
| SWMM_ENGINE_API int | swmm_treatment_clear (SWMM_Engine engine, int node_idx, int pollut_idx) |
| Clear a treatment expression for a (node, pollutant) pair. | |
| SWMM_ENGINE_API int | swmm_treatment_validate_expression (SWMM_Engine engine, const char *expr, char *errbuf, int buflen, int *col_out) |
| Validate a treatment expression WITHOUT modifying engine state. | |
C API implementation — landuse, buildup, washoff, treatment.
| SWMM_ENGINE_API int swmm_buildup_get | ( | SWMM_Engine | engine, |
| int | lu_idx, | ||
| int | pollut_idx, | ||
| int * | func_type, | ||
| double * | c1, | ||
| double * | c2, | ||
| double * | c3, | ||
| int * | normalizer ) |
Get buildup function parameters for a (landuse, pollutant) pair.
| [in] | engine | Engine handle. |
| [in] | lu_idx | Landuse index. |
| [in] | pollut_idx | Surface-species index: a pollutant index, or n_pollutants + m for the reactions component's m-th species (BW-MSX, 2026-09-19 — MSX species build up and wash off by the same relations). |
| [out] | func_type | Buildup function type (0=NONE, 1=POW, 2=EXP, 3=SAT, 4=EXT). |
| [out] | c1 | Coefficient 1. |
| [out] | c2 | Coefficient 2. |
| [out] | c3 | Coefficient 3. |
| [out] | normalizer | Normalizer (0=PER_AREA, 1=PER_CURB). |
| SWMM_ENGINE_API int swmm_buildup_set | ( | SWMM_Engine | engine, |
| int | lu_idx, | ||
| int | pollut_idx, | ||
| int | func_type, | ||
| double | c1, | ||
| double | c2, | ||
| double | c3, | ||
| int | normalizer ) |
Set buildup function parameters for a (landuse, pollutant) pair.
| [in] | engine | Engine handle. |
| [in] | lu_idx | Landuse index. |
| [in] | pollut_idx | Surface-species index: pollutant, or n_pollutants + reaction species index. |
| [in] | func_type | Buildup function type (0=NONE, 1=POW, 2=EXP, 3=SAT, 4=EXT). |
| [in] | c1 | Coefficient 1. |
| [in] | c2 | Coefficient 2. |
| [in] | c3 | Coefficient 3. |
| [in] | normalizer | Normalizer (0=PER_AREA, 1=PER_CURB). |
| SWMM_ENGINE_API int swmm_landuse_add | ( | SWMM_Engine | engine, |
| const char * | id ) |
Append a land use while preserving existing model parameter columns.
Grows sweeping and buildup/washoff rows and repacks subcatchment land-use coverage when its existing dimensions match. New rows default to zero. Configure parameters/coverage before initialization.
| [in] | engine | Non-null live engine; caller provides exclusive access. |
| [in] | id | Non-null copied identifier; an existing land-use ID is refused. |
| SWMM_ENGINE_API int swmm_landuse_count | ( | SWMM_Engine | engine | ) |
Count land-use definitions in the current model.
| [in] | engine | Non-null live engine; caller provides exclusive access. |
| SWMM_ENGINE_API int swmm_landuse_get_sweep_interval | ( | SWMM_Engine | engine, |
| int | idx, | ||
| double * | days ) |
Read the configured interval between street sweeps.
| [in] | engine | Non-null live engine; caller provides exclusive access. |
| [in] | idx | Zero-based existing land-use index. |
| [out] | days | Optional destination in days. |
| SWMM_ENGINE_API int swmm_landuse_get_sweep_removal | ( | SWMM_Engine | engine, |
| int | idx, | ||
| double * | frac ) |
Read the land-use sweep-removal fraction.
| [in] | engine | Non-null live engine; caller provides exclusive access. |
| [in] | idx | Zero-based existing land-use index. |
| [out] | frac | Optional destination for the stored dimensionless fraction. |
| SWMM_ENGINE_API const char * swmm_landuse_id | ( | SWMM_Engine | engine, |
| int | idx ) |
Borrow a land-use identifier from the model name index.
| [in] | engine | Non-null live engine; caller provides exclusive access. |
| [in] | idx | Zero-based existing land-use index. |
| SWMM_ENGINE_API int swmm_landuse_index | ( | SWMM_Engine | engine, |
| const char * | id ) |
Resolve a land-use identifier to its row index.
| [in] | engine | Non-null live engine; caller provides exclusive access. |
| [in] | id | Non-null NUL-terminated identifier, borrowed for the lookup. |
| SWMM_ENGINE_API int swmm_landuse_rename | ( | SWMM_Engine | engine, |
| int | idx, | ||
| const char * | new_id ) |
Rename a land use in place.
Land uses are referenced positionally (matrix dimensions), so the rename only touches the name registry — buildup/washoff rows and subcatchment coverages follow automatically.
| [in] | engine | Engine handle. |
| [in] | idx | Land use index. |
| [in] | new_id | New unique name (non-empty). |
| SWMM_ENGINE_API int swmm_landuse_set_sweep_interval | ( | SWMM_Engine | engine, |
| int | idx, | ||
| double | days ) |
Assign the configured interval between street sweeps.
No lifecycle guard is imposed. This stores the parameter without rescheduling a previously completed sweep.
| [in] | engine | Non-null live engine; caller provides exclusive access. |
| [in] | idx | Zero-based existing land-use index. |
| [in] | days | Interval in days; stored without finite/nonnegative validation. |
| SWMM_ENGINE_API int swmm_landuse_set_sweep_removal | ( | SWMM_Engine | engine, |
| int | idx, | ||
| double | frac ) |
Assign the land-use sweep-removal fraction.
No lifecycle guard is imposed.
| [in] | engine | Non-null live engine; caller provides exclusive access. |
| [in] | idx | Zero-based existing land-use index. |
| [in] | frac | Dimensionless removal fraction, conventionally [0,1]; stored without clamping/finite/range checks. |
| SWMM_ENGINE_API int swmm_treatment_clear | ( | SWMM_Engine | engine, |
| int | node_idx, | ||
| int | pollut_idx ) |
Clear a treatment expression for a (node, pollutant) pair.
| [in] | engine | Engine handle. |
| [in] | node_idx | Node index. |
| [in] | pollut_idx | Pollutant index. |
| SWMM_ENGINE_API int swmm_treatment_get | ( | SWMM_Engine | engine, |
| int | node_idx, | ||
| int | pollut_idx, | ||
| char * | buf, | ||
| int | buflen ) |
Get a treatment expression for a (node, pollutant) pair.
| [in] | engine | Engine handle. |
| [in] | node_idx | Node index. |
| [in] | pollut_idx | Pollutant index. |
| [out] | buf | Buffer to receive the expression string. |
| [in] | buflen | Size of buf. |
| SWMM_ENGINE_API int swmm_treatment_set | ( | SWMM_Engine | engine, |
| int | node_idx, | ||
| int | pollut_idx, | ||
| const char * | expression ) |
Set a treatment expression for a (node, pollutant) pair.
| [in] | engine | Engine handle. |
| [in] | node_idx | Node index. |
| [in] | pollut_idx | Pollutant index. |
| [in] | expression | Treatment expression string (e.g. "R = 0.5 * exp(-0.1 * DT)"). |
| SWMM_ENGINE_API int swmm_treatment_validate_expression | ( | SWMM_Engine | engine, |
| const char * | expr, | ||
| char * | errbuf, | ||
| int | buflen, | ||
| int * | col_out ) |
Validate a treatment expression WITHOUT modifying engine state.
Editor-support peer of swmm_control_validate_rule: parses expr through the production treatment grammar and reports a human-readable diagnostic plus the 0-based character offset of the error. Unlike swmm_treatment_set (which recompiles the node's treatment on success), this call never mutates the engine, so it is safe to invoke per keystroke. Note the validator is deliberately stricter than the tokenizer in one way: unknown characters are an error rather than silently skipped. Co-pollutant references (R_name/C_name) are reported as unsupported.
| [in] | engine | Engine handle (grammar only; no model data is read). |
| [in] | expr | Expression string ("R = ..." or "C = ..."). |
| [out] | errbuf | Receives the diagnostic on failure ("" on success). May be NULL. |
| [in] | buflen | Size of errbuf in bytes. |
| [out] | col_out | Receives the 0-based character offset of the error, or -1 when not attributable. May be NULL. |
| SWMM_ENGINE_API int swmm_washoff_get | ( | SWMM_Engine | engine, |
| int | lu_idx, | ||
| int | pollut_idx, | ||
| int * | func_type, | ||
| double * | coeff, | ||
| double * | expon, | ||
| double * | sweep_effic, | ||
| double * | bmp_effic ) |
Get washoff function parameters for a (landuse, pollutant) pair.
| [in] | engine | Engine handle. |
| [in] | lu_idx | Landuse index. |
| [in] | pollut_idx | Surface-species index: pollutant, or n_pollutants + reaction species index. |
| [out] | func_type | Washoff function type (0=NONE, 1=EXP, 2=RC, 3=EMC). |
| [out] | coeff | Washoff coefficient. |
| [out] | expon | Washoff exponent. |
| [out] | sweep_effic | Sweep efficiency (0-100). |
| [out] | bmp_effic | BMP efficiency (0-100). |
| SWMM_ENGINE_API int swmm_washoff_set | ( | SWMM_Engine | engine, |
| int | lu_idx, | ||
| int | pollut_idx, | ||
| int | func_type, | ||
| double | coeff, | ||
| double | expon, | ||
| double | sweep_effic, | ||
| double | bmp_effic ) |
Set washoff function parameters for a (landuse, pollutant) pair.
| [in] | engine | Engine handle. |
| [in] | lu_idx | Landuse index. |
| [in] | pollut_idx | Surface-species index (pollutant, or n_pollutants + m for the m-th reactions-component species — BW-MSX). |
| [in] | func_type | Washoff function type (0=NONE, 1=EXP, 2=RC, 3=EMC). |
| [in] | coeff | Washoff coefficient. |
| [in] | expon | Washoff exponent. |
| [in] | sweep_effic | Sweep efficiency (0-100). |
| [in] | bmp_effic | BMP efficiency (0-100). |