![]() |
OpenSWMM Engine
6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
|
OpenSWMM Engine — primary transparent C API (master header). More...
#include "openswmm_callbacks.h"#include "openswmm_datetime.h"#include "openswmm_model.h"#include "openswmm_nodes.h"#include "openswmm_links.h"#include "openswmm_subcatchments.h"#include "openswmm_gages.h"#include "openswmm_massbalance.h"#include "openswmm_hotstart.h"#include "openswmm_spatial.h"#include "openswmm_pollutants.h"#include "openswmm_initial_quality.h"#include "openswmm_reactions.h"#include "openswmm_process_components.h"#include "openswmm_tables.h"#include "openswmm_inflows.h"#include "openswmm_controls.h"#include "openswmm_infrastructure.h"#include "openswmm_quality.h"#include "openswmm_statistics.h"#include "openswmm_forcing.h"#include "openswmm_climate.h"#include "openswmm_edit.h"#include "openswmm_checkpoint.h"Go to the source code of this file.
Classes | |
| struct | SWMM_ThreadInfo |
| struct | SWMM_TransportCell |
| struct | SWMM_TransportMatrix |
| struct | SWMM_TransportDraft |
Macros | |
| #define | SWMM_ENGINE_API __attribute__((visibility("default"))) |
| #define | SWMM_TRANSPORT_DOMAIN_RUNOFF 0 |
| #define | SWMM_TRANSPORT_DOMAIN_GROUNDWATER 1 |
| #define | SWMM_TRANSPORT_DOMAIN_NETWORK_1D 2 |
| #define | SWMM_TRANSPORT_DOMAIN_SURFACE_2D 3 |
| #define | SWMM_TRANSPORT_DOMAIN_COUNT 4 |
| #define | SWMM_TRANSPORT_CLASS_POLLUTANTS 0 |
| #define | SWMM_TRANSPORT_CLASS_MSX 1 |
| #define | SWMM_TRANSPORT_CLASS_AGE 2 |
| #define | SWMM_TRANSPORT_CLASS_TEMPERATURE 3 |
| #define | SWMM_TRANSPORT_CLASS_COUNT 4 |
| #define | SWMM_TRANSPORT_ENABLED 0 |
| #define | SWMM_TRANSPORT_DISABLED_BY_USER 1 |
| #define | SWMM_TRANSPORT_UNAVAILABLE 2 |
Typedefs | |
| typedef enum SWMM_ErrorCode | SWMM_ErrorCode |
| typedef enum SWMM_WarnCode | SWMM_WarnCode |
| typedef enum SWMM_EngineState | SWMM_EngineState |
| typedef enum SWMM_ObjectType | SWMM_ObjectType |
| typedef struct SWMM_TransportCell | SWMM_TransportCell |
| typedef struct SWMM_TransportMatrix | SWMM_TransportMatrix |
| typedef struct SWMM_TransportDraft | SWMM_TransportDraft |
Functions | |
| SWMM_ENGINE_API SWMM_Engine | swmm_engine_create (void) |
| Allocate an independent engine in SWMM_STATE_CREATED. | |
| SWMM_ENGINE_API const char * | swmm_engine_abi_tag (void) |
| Identify the public C ABI compiled into the running engine image. | |
| SWMM_ENGINE_API int | swmm_engine_open (SWMM_Engine engine, const char *inp, const char *rpt, const char *out, const char *input_plugin_lib) |
| Load a model and prepare its plugin configuration in SWMM_STATE_OPENED. | |
| SWMM_ENGINE_API int | swmm_engine_open_metadata (SWMM_Engine engine, const char *inp) |
| Open a model for configured metadata without preparing simulation plugins. | |
| SWMM_ENGINE_API int | swmm_engine_initialize (SWMM_Engine engine) |
| Allocate simulation modules and initial state, entering SWMM_STATE_INITIALIZED. | |
| SWMM_ENGINE_API int | swmm_engine_start (SWMM_Engine engine, int save_results) |
| Start an initialized simulation, entering SWMM_STATE_RUNNING. | |
| SWMM_ENGINE_API int | swmm_engine_advance_to (SWMM_Engine engine, double target_seconds, double *actual_seconds) |
| Advance to a specified elapsed-second exchange boundary without overshooting. | |
| SWMM_ENGINE_API int | swmm_engine_get_elapsed_seconds (SWMM_Engine engine, double *seconds) |
| Read the routing elapsed clock, including during step callbacks. | |
| SWMM_ENGINE_API int | swmm_engine_step (SWMM_Engine engine, double *elapsed_time) |
| Advance one physical simulation step and report elapsed days. | |
| SWMM_ENGINE_API int | swmm_engine_stride (SWMM_Engine engine, int n_steps, double *elapsed_time) |
| Perform up to a requested number of physical steps synchronously. | |
| SWMM_ENGINE_API int | swmm_engine_end (SWMM_Engine engine) |
| Finalize a running or completed simulation and enter SWMM_STATE_ENDED. | |
| SWMM_ENGINE_API int | swmm_engine_report (SWMM_Engine engine) |
| Write final model/simulation reports after ending the simulation. | |
| SWMM_ENGINE_API int | swmm_engine_close (SWMM_Engine engine) |
| Stop IO and release active model files, plugins and checkpoint attachments. | |
| SWMM_ENGINE_API void | swmm_engine_destroy (SWMM_Engine engine) |
| Delete an engine and all resources it owns. | |
| SWMM_ENGINE_API int | swmm_engine_get_state (SWMM_Engine engine, int *state) |
| Read the public lifecycle state of a live engine. | |
| SWMM_ENGINE_API int | swmm_engine_run (const char *inp, const char *rpt, const char *out, const char *input_plugin_lib) |
| Create an engine, run the full lifecycle synchronously, and destroy it. | |
| SWMM_ENGINE_API int | swmm_engine_run_with_callback (const char *inp, const char *rpt, const char *out, const char *input_plugin_lib, SWMM_ProgressCallback callback, void *user_data) |
| Run the full synchronous lifecycle with a borrowed progress callback. | |
| SWMM_ENGINE_API int | swmm_set_progress_callback (SWMM_Engine engine, SWMM_ProgressCallback callback, void *user_data) |
| Register, replace or disable pre-step progress. | |
| SWMM_ENGINE_API int | swmm_set_warning_callback (SWMM_Engine engine, SWMM_WarningCallback callback, void *user_data) |
| Register, replace or disable diagnostics. | |
| SWMM_ENGINE_API int | swmm_set_step_begin_callback (SWMM_Engine engine, SWMM_StepBeginCallback callback, void *user_data) |
| Register, replace or disable pre-physics step notifications. | |
| SWMM_ENGINE_API int | swmm_set_step_end_callback (SWMM_Engine engine, SWMM_StepEndCallback callback, void *user_data) |
| Register, replace or disable post-physics step notifications. | |
| SWMM_ENGINE_API int | swmm_get_last_error (SWMM_Engine engine) |
| Read the stored simulation error code without clearing it. | |
| SWMM_ENGINE_API const char * | swmm_get_last_error_msg (SWMM_Engine engine) |
| Borrow the stored simulation error text. | |
| SWMM_ENGINE_API const char * | swmm_error_message (int code) |
| Translate a known public error code to a static English description. | |
| SWMM_ENGINE_API void | swmm_engine_set_lenient_open (SWMM_Engine engine, int on) |
| Select permissive model validation for subsequent editor loads. | |
| SWMM_ENGINE_API int | swmm_get_error_count (SWMM_Engine engine) |
| Count accumulated error messages. | |
| SWMM_ENGINE_API const char * | swmm_get_error_at (SWMM_Engine engine, int index) |
| Borrow one accumulated error message. | |
| SWMM_ENGINE_API int | swmm_get_warning_count (SWMM_Engine engine) |
| Count accumulated warning messages. | |
| SWMM_ENGINE_API const char * | swmm_get_warning_at (SWMM_Engine engine, int index) |
| Borrow one accumulated warning message. | |
| SWMM_ENGINE_API int | swmm_get_thread_info (SWMM_ThreadInfo *out) |
| Query hardware and parallel-runtime limits without an engine. | |
| SWMM_ENGINE_API int | swmm_get_effective_threads (SWMM_Engine engine, int threads_option, int *global_threads, int *dw_threads, int *twod_threads) |
| Preview thread-team sizes for a request and the current model. | |
| SWMM_ENGINE_API int | swmm_get_transport_matrix (SWMM_Engine engine, SWMM_TransportMatrix *out) |
| Resolve planned transport classes for each configured model domain. | |
| SWMM_ENGINE_API int | swmm_preview_transport_matrix (SWMM_Engine engine, const SWMM_TransportDraft *draft, SWMM_TransportMatrix *out) |
| Resolve transport for a temporary draft without mutating the model. | |
| SWMM_ENGINE_API const char * | swmm_transport_domain_name (int domain) |
| Get the display name of a transport-domain axis value. | |
| SWMM_ENGINE_API const char * | swmm_transport_class_name (int species_class) |
| Get the display name of a transport-species class. | |
| SWMM_ENGINE_API int | swmm_get_start_time (SWMM_Engine engine, double *start) |
| Read the configured simulation start calendar date. | |
| SWMM_ENGINE_API int | swmm_get_end_time (SWMM_Engine engine, double *end) |
| Read the configured simulation end calendar date. | |
| SWMM_ENGINE_API int | swmm_get_current_time (SWMM_Engine engine, double *current) |
| Read the current elapsed physics time. | |
| SWMM_ENGINE_API int | swmm_get_routing_step (SWMM_Engine engine, double *dt) |
| Read the configured routing timestep limit. | |
| SWMM_ENGINE_API int | swmm_get_flow_units (SWMM_Engine engine, int *flow_units) |
| Read the project display-flow unit code. | |
| SWMM_ENGINE_API int | swmm_get_unit_system (SWMM_Engine engine, int *unit_system) |
| Read the unit system implied by project flow units. | |
| SWMM_ENGINE_API int | swmm_is_between_events (SWMM_Engine engine, int *is_between) |
| Read the current implementation event-list presence flag. | |
| SWMM_ENGINE_API int | swmm_get_event_count (SWMM_Engine engine, int *count) |
| Count configured routing-event entries. | |
| SWMM_ENGINE_API int | swmm_events_count (SWMM_Engine engine, int *count) |
| Count configured routing-event entries. | |
| SWMM_ENGINE_API int | swmm_events_get (SWMM_Engine engine, int idx, double *start, double *end) |
| Read the calendar window of a configured routing event. | |
| SWMM_ENGINE_API int | swmm_events_set (SWMM_Engine engine, int idx, double start, double end) |
| Replace one event calendar window in place. | |
| SWMM_ENGINE_API int | swmm_events_add (SWMM_Engine engine, double start, double end, int *out_idx) |
| Append a routing-event window in insertion order. | |
| SWMM_ENGINE_API int | swmm_events_remove (SWMM_Engine engine, int idx) |
| Remove one configured event and shift later indices down. | |
| SWMM_ENGINE_API int | swmm_events_clear (SWMM_Engine engine) |
| Remove all configured routing events. | |
| SWMM_ENGINE_API int | swmm_get_steady_state_skip (SWMM_Engine engine, int *enabled) |
| Read the stored steady-state routing-skip option. | |
| SWMM_ENGINE_API int | swmm_set_steady_state_skip (SWMM_Engine engine, int enabled) |
| Set the stored steady-state routing-skip option. | |
| SWMM_ENGINE_API int | swmm_runoff_iface_open_write (SWMM_Engine engine, const char *path) |
| Open a runoff cache for SAVE records using the current model schema. | |
| SWMM_ENGINE_API int | swmm_runoff_iface_open_read (SWMM_Engine engine, const char *path) |
| Open a compatible runoff cache for USE-mode record reads. | |
| SWMM_ENGINE_API int | swmm_runoff_iface_save_step (SWMM_Engine engine, double dt) |
| Request a manual runoff-cache snapshot. | |
| SWMM_ENGINE_API int | swmm_runoff_iface_read_step (SWMM_Engine engine, int *has_data) |
| Read one available runoff record into the current subcatchment state. | |
| SWMM_ENGINE_API int | swmm_runoff_iface_close (SWMM_Engine engine) |
| Close and release the runoff-cache file if present. | |
OpenSWMM Engine — primary transparent C API (master header).
This is the main public header for the openswmm.engine library (version 6.0.0-alpha.1). It defines:
Domain-specific APIs are in separate headers:
Including this header pulls in ALL of the above (master include). To use a single domain, include just that domain header.
Programmatic model building (no .inp):
Typical usage:
| #define SWMM_ENGINE_API __attribute__((visibility("default"))) |
| #define SWMM_TRANSPORT_CLASS_AGE 2 |
| #define SWMM_TRANSPORT_CLASS_COUNT 4 |
| #define SWMM_TRANSPORT_CLASS_MSX 1 |
| #define SWMM_TRANSPORT_CLASS_POLLUTANTS 0 |
| #define SWMM_TRANSPORT_CLASS_TEMPERATURE 3 |
| #define SWMM_TRANSPORT_DISABLED_BY_USER 1 |
reason = the option key
| #define SWMM_TRANSPORT_DOMAIN_COUNT 4 |
| #define SWMM_TRANSPORT_DOMAIN_GROUNDWATER 1 |
| #define SWMM_TRANSPORT_DOMAIN_NETWORK_1D 2 |
| #define SWMM_TRANSPORT_DOMAIN_RUNOFF 0 |
| #define SWMM_TRANSPORT_DOMAIN_SURFACE_2D 3 |
| #define SWMM_TRANSPORT_ENABLED 0 |
| #define SWMM_TRANSPORT_UNAVAILABLE 2 |
reason = why nothing is carried
| typedef enum SWMM_EngineState SWMM_EngineState |
| typedef enum SWMM_ErrorCode SWMM_ErrorCode |
| typedef enum SWMM_ObjectType SWMM_ObjectType |
| typedef struct SWMM_TransportCell SWMM_TransportCell |
| typedef struct SWMM_TransportDraft SWMM_TransportDraft |
Side-effect-free pre-run preview. Boolean fields must be 0 or 1; groundwater is -1 (Automatic), 0 (Off), 1 (On). This is planned transport, not proof of initialized runtime activity or local heat-flux support.
| typedef struct SWMM_TransportMatrix SWMM_TransportMatrix |
| typedef enum SWMM_WarnCode SWMM_WarnCode |
| enum SWMM_EngineState |
| enum SWMM_ErrorCode |
| enum SWMM_ObjectType |
| enum SWMM_WarnCode |
| SWMM_ENGINE_API const char * swmm_engine_abi_tag | ( | void | ) |
Identify the public C ABI compiled into the running engine image.
| SWMM_ENGINE_API int swmm_engine_advance_to | ( | SWMM_Engine | engine, |
| double | target_seconds, | ||
| double * | actual_seconds ) |
Advance to a specified elapsed-second exchange boundary without overshooting.
Flushes pending 2D work before successful return. Due external driver updates must be supplied first. Does not provide rollback or iterative coupling; inspect actual_seconds after errors.
| [in] | engine | Non-null RUNNING engine; cannot be invoked recursively from a step or its callbacks. |
| [in] | target_seconds | Finite absolute elapsed simulation time in seconds, at least the current coupling clock and no later than simulation end. |
| [out] | actual_seconds | Non-null accepted coupling-time output in seconds. With valid arguments, set before lifecycle/target checks and updated after advancement; may report partial progress on stepping failure. |
| SWMM_ENGINE_API int swmm_engine_close | ( | SWMM_Engine | engine | ) |
Stop IO and release active model files, plugins and checkpoint attachments.
May be called during teardown from any live engine state. Enters CLOSED and permits a fresh open; it does not free the handle. Flushes recorded fatal diagnostics on failed runs. Engine-owned pointers to mutable model data must not be retained across close/reopen.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| SWMM_ENGINE_API SWMM_Engine swmm_engine_create | ( | void | ) |
Allocate an independent engine in SWMM_STATE_CREATED.
| SWMM_ENGINE_API void swmm_engine_destroy | ( | SWMM_Engine | engine | ) |
Delete an engine and all resources it owns.
Do not call concurrently with any operation or from inside a callback. Callback user_data remains caller-owned and is never freed by this function.
| [in] | engine | Caller-owned engine handle, or NULL for a no-op. Do not use a non-null handle afterward or destroy it twice. |
| SWMM_ENGINE_API int swmm_engine_end | ( | SWMM_Engine | engine | ) |
Finalize a running or completed simulation and enter SWMM_STATE_ENDED.
Requires RUNNING or ENDED. Finalizes balances, pending IO and end-of-run output/hotstarts. If a prior error has placed the engine in an error state, preserves and returns the existing root-cause error instead of replacing it with a teardown-state complaint.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| SWMM_ENGINE_API int swmm_engine_get_elapsed_seconds | ( | SWMM_Engine | engine, |
| double * | seconds ) |
Read the routing elapsed clock, including during step callbacks.
No lifecycle guard is applied. This getter uses the context routing clock; swmm_engine_advance_to() reports the runtime coupling clock used for exchange boundaries.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [out] | seconds | Non-null destination for context elapsed_ms/1000 in seconds since simulation start. |
| SWMM_ENGINE_API int swmm_engine_get_state | ( | SWMM_Engine | engine, |
| int * | state ) |
Read the public lifecycle state of a live engine.
Internal PAUSED maps to RUNNING, REPORTED maps to ENDED, and the internal error state maps to SWMM_STATE_NONE.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [out] | state | Optional destination for an SWMM_EngineState integer. NULL performs only the handle check. |
| SWMM_ENGINE_API int swmm_engine_initialize | ( | SWMM_Engine | engine | ) |
Allocate simulation modules and initial state, entering SWMM_STATE_INITIALIZED.
Requires OPENED, or INITIALIZED for a pre-start rebuild. Resolves runtime physics/transport guards, initializes forcing arrays and compiles stored control rules. Metadata-only handles are refused. Reinitializing after a run requires a fresh open; initialization may change state to an error state on failure.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| SWMM_ENGINE_API int swmm_engine_open | ( | SWMM_Engine | engine, |
| const char * | inp, | ||
| const char * | rpt, | ||
| const char * | out, | ||
| const char * | input_plugin_lib ) |
Load a model and prepare its plugin configuration in SWMM_STATE_OPENED.
Requires CREATED or CLOSED and resets the model context for a fresh load. Ordinary open resolves and validates model references and may load configured plugins. Paths are consumed synchronously; the engine keeps its own copies as needed. Query swmm_get_last_error_msg() and accumulated errors/warnings after refusal. Existing report/output destinations can be written during the lifecycle; use separate private paths for staged work.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [in] | inp | Borrowed NUL-terminated input-model path. |
| [in] | rpt | Borrowed report destination path, or NULL to omit it. |
| [in] | out | Borrowed binary-results destination path, or NULL to omit it. |
| [in] | input_plugin_lib | Borrowed input plugin library path, component ID or id:version; NULL/empty selects the built-in INP reader when no input plugin is already registered. |
| SWMM_ENGINE_API int swmm_engine_open_metadata | ( | SWMM_Engine | engine, |
| const char * | inp ) |
Open a model for configured metadata without preparing simulation plugins.
Uses normal strict model validation and no report/result destinations. The returned OPENED model supports metadata getters; initialize/start are refused until the engine is closed and reopened normally. Model-declared SAVE paths are not opened by this metadata load.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [in] | inp | Borrowed NUL-terminated input-model path. |
| SWMM_ENGINE_API int swmm_engine_report | ( | SWMM_Engine | engine | ) |
Write final model/simulation reports after ending the simulation.
Requires the internal ENDED state and transitions to REPORTED (publicly exposed as SWMM_STATE_ENDED). Preserves the root-cause error for failed runs. Report plugins/configuration determine the destinations and content.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| SWMM_ENGINE_API int swmm_engine_run | ( | const char * | inp, |
| const char * | rpt, | ||
| const char * | out, | ||
| const char * | input_plugin_lib ) |
Create an engine, run the full lifecycle synchronously, and destroy it.
Chains open, initialize, start(save_results=1), step loop, end, report, close and destroy. Early failures close/destroy as appropriate; the temporary engine and its detailed diagnostics are not available after return. All input strings remain caller-owned.
| [in] | inp | Borrowed NUL-terminated input-model path. |
| [in] | rpt | Borrowed report destination path, or NULL to omit it. |
| [in] | out | Borrowed binary-results destination path, or NULL to omit it. |
| [in] | input_plugin_lib | Borrowed input plugin library path, component ID or id:version; NULL/empty selects the built-in INP reader when no input plugin is already registered. |
| SWMM_ENGINE_API int swmm_engine_run_with_callback | ( | const char * | inp, |
| const char * | rpt, | ||
| const char * | out, | ||
| const char * | input_plugin_lib, | ||
| SWMM_ProgressCallback | callback, | ||
| void * | user_data ) |
Run the full synchronous lifecycle with a borrowed progress callback.
Uses a temporary engine and destroys it before returning, as swmm_engine_run() does. Callbacks must not throw, close/destroy the temporary engine or recursively advance it; progress notifications cannot cancel the run.
| [in] | inp | Borrowed NUL-terminated input-model path. |
| [in] | rpt | Borrowed report destination path, or NULL to omit it. |
| [in] | out | Borrowed binary-results destination path, or NULL to omit it. |
| [in] | input_plugin_lib | Borrowed input plugin library path, component ID or id:version; NULL/empty selects the built-in INP reader when no input plugin is already registered. |
| [in] | callback | Optional progress function, invoked on the calling thread before each physical step; NULL disables progress notifications. |
| [in] | user_data | Borrowed opaque context passed unchanged to callback; may be NULL and must remain valid throughout this call. |
| SWMM_ENGINE_API void swmm_engine_set_lenient_open | ( | SWMM_Engine | engine, |
| int | on ) |
Select permissive model validation for subsequent editor loads.
Lenient open keeps parsed objects editable in OPENED despite post-parse reference/validation errors, which remain available through swmm_get_error_count()/swmm_get_error_at(). Hard input-reader failures still fail. Running the repaired model requires a fresh strict open.
| [in] | engine | Live engine handle; NULL is a no-op. |
| [in] | on | 0 selects strict validation (default); nonzero enables lenient open. |
| SWMM_ENGINE_API int swmm_engine_start | ( | SWMM_Engine | engine, |
| int | save_results ) |
Start an initialized simulation, entering SWMM_STATE_RUNNING.
Requires INITIALIZED. Opens configured interface files and prepares run-time plugins/outputs before stepping. Failure may leave partially prepared resources that must be closed; read the last error before teardown.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [in] | save_results | 0 disables regular result saving; nonzero enables it through the configured output path/plugins. |
| SWMM_ENGINE_API int swmm_engine_step | ( | SWMM_Engine | engine, |
| double * | elapsed_time ) |
Advance one physical simulation step and report elapsed days.
Requires RUNNING and refuses recursive stepping or a due external driver update. Invokes progress and begin callbacks before physics and the end callback after physics/output. Runtime source expiries may shorten the proposed step. A failure after accepted physics or output recording does not promise rollback; query state and diagnostics.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [out] | elapsed_time | Optional destination for elapsed simulation DAYS after the accepted step; 0 when the simulation is complete. NULL suppresses this output. Some early refusals leave it unchanged. |
| SWMM_ENGINE_API int swmm_engine_stride | ( | SWMM_Engine | engine, |
| int | n_steps, | ||
| double * | elapsed_time ) |
Perform up to a requested number of physical steps synchronously.
Stops early on an error or a step result <=0. A failed early step can overwrite the output with zero even when prior physics remains accepted. Each individual step performs its usual callbacks and lifecycle checks.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [in] | n_steps | Maximum step count; nonpositive values are a successful no-op after checking the handle. |
| [out] | elapsed_time | Optional elapsed-days output, initially set to zero and then to each step result; zero denotes completion. |
| SWMM_ENGINE_API const char * swmm_error_message | ( | int | code | ) |
Translate a known public error code to a static English description.
Does not require an engine or include operation-specific context; use swmm_get_last_error_msg() for the recorded diagnostic.
| [in] | code | SWMM_OK, an SWMM_ERR_* code, or a supported validation code. |
| SWMM_ENGINE_API int swmm_events_add | ( | SWMM_Engine | engine, |
| double | start, | ||
| double | end, | ||
| int * | out_idx ) |
Append a routing-event window in insertion order.
Does not sort, merge overlaps or validate finite values. Caller retains no references into the internal event vector.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [in] | start | Start as SWMM DateTime decimal days since 1899-12-30; must compare less than end. |
| [in] | end | End in the same calendar-day units. |
| [out] | out_idx | Optional destination for the appended zero-based index, written on success. |
| SWMM_ENGINE_API int swmm_events_clear | ( | SWMM_Engine | engine | ) |
Remove all configured routing events.
No lifecycle guard is applied; configure the event list before running.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| SWMM_ENGINE_API int swmm_events_count | ( | SWMM_Engine | engine, |
| int * | count ) |
Count configured routing-event entries.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [out] | count | Optional destination. Nonnegative number of stored event windows; alias of swmm_get_event_count(). |
| SWMM_ENGINE_API int swmm_events_get | ( | SWMM_Engine | engine, |
| int | idx, | ||
| double * | start, | ||
| double * | end ) |
Read the calendar window of a configured routing event.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [in] | idx | Zero-based event index in [0,event count). |
| [out] | start | Optional destination for event start as SWMM DateTime decimal days since 1899-12-30. |
| [out] | end | Optional destination for event end in the same calendar-day units. |
| SWMM_ENGINE_API int swmm_events_remove | ( | SWMM_Engine | engine, |
| int | idx ) |
Remove one configured event and shift later indices down.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [in] | idx | Zero-based event index to remove. |
| SWMM_ENGINE_API int swmm_events_set | ( | SWMM_Engine | engine, |
| int | idx, | ||
| double | start, | ||
| double | end ) |
Replace one event calendar window in place.
Applies no lifecycle, overlap, sorting or finite-value validation; configure valid ordered event data before running.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [in] | idx | Zero-based event index. |
| [in] | start | Start as SWMM DateTime decimal days since 1899-12-30; must compare less than end. |
| [in] | end | End in the same calendar-day units. |
| SWMM_ENGINE_API int swmm_get_current_time | ( | SWMM_Engine | engine, |
| double * | current ) |
Read the current elapsed physics time.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [out] | current | Optional destination. Elapsed seconds since simulation start (context current_time), NOT a DateTime calendar value. |
| SWMM_ENGINE_API int swmm_get_effective_threads | ( | SWMM_Engine | engine, |
| int | threads_option, | ||
| int * | global_threads, | ||
| int * | dw_threads, | ||
| int * | twod_threads ) |
Preview thread-team sizes for a request and the current model.
Read-only resolution using the same policy helpers as run setup. Model-size gates may reduce even an explicit request; automatic requests also apply applicable performance-core policy. Does not change the stored THREADS option or initialize a parallel backend.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [in] | threads_option | [OPTIONS] THREADS request: 0 is automatic; positive requests are resolved against model-size/runtime policies. |
| [out] | global_threads | Optional general OpenMP team-size destination. |
| [out] | dw_threads | Optional dynamic-wave team-size destination; zero when routing is not DYNWAVE. |
| [out] | twod_threads | Optional 2D CPU team-size destination; zero without an enabled nonempty mesh or 2D build support. |
| SWMM_ENGINE_API int swmm_get_end_time | ( | SWMM_Engine | engine, |
| double * | end ) |
Read the configured simulation end calendar date.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [out] | end | Optional destination. SWMM DateTime decimal days since 1899-12-30. |
| SWMM_ENGINE_API const char * swmm_get_error_at | ( | SWMM_Engine | engine, |
| int | index ) |
Borrow one accumulated error message.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [in] | index | Zero-based message index. |
| SWMM_ENGINE_API int swmm_get_error_count | ( | SWMM_Engine | engine | ) |
Count accumulated error messages.
This getter does not clear the list and is distinct from the stored last-error code.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| SWMM_ENGINE_API int swmm_get_event_count | ( | SWMM_Engine | engine, |
| int * | count ) |
Count configured routing-event entries.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [out] | count | Optional destination. Nonnegative number of stored event windows; alias of swmm_events_count(). |
| SWMM_ENGINE_API int swmm_get_flow_units | ( | SWMM_Engine | engine, |
| int * | flow_units ) |
Read the project display-flow unit code.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [out] | flow_units | Optional destination. 0=CFS, 1=GPM, 2=MGD, 3=CMS, 4=LPS, 5=MLD. |
| SWMM_ENGINE_API int swmm_get_last_error | ( | SWMM_Engine | engine | ) |
Read the stored simulation error code without clearing it.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| SWMM_ENGINE_API const char * swmm_get_last_error_msg | ( | SWMM_Engine | engine | ) |
Borrow the stored simulation error text.
Reading does not clear the error. Diagnostic lifetime is tied to the underlying stored string, which subsequent operations can replace.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| SWMM_ENGINE_API int swmm_get_routing_step | ( | SWMM_Engine | engine, |
| double * | dt ) |
Read the configured routing timestep limit.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [out] | dt | Optional destination. Configured routing-step seconds, not the last adaptive step duration. |
| SWMM_ENGINE_API int swmm_get_start_time | ( | SWMM_Engine | engine, |
| double * | start ) |
Read the configured simulation start calendar date.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [out] | start | Optional destination. SWMM DateTime decimal days since 1899-12-30. |
| SWMM_ENGINE_API int swmm_get_steady_state_skip | ( | SWMM_Engine | engine, |
| int * | enabled ) |
Read the stored steady-state routing-skip option.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [out] | enabled | Optional destination. 1 when skipping is enabled, otherwise 0. |
| SWMM_ENGINE_API int swmm_get_thread_info | ( | SWMM_ThreadInfo * | out | ) |
Query hardware and parallel-runtime limits without an engine.
Reports process-visible logical CPUs, OpenMP limits/availability, macOS performance-cluster CPUs and initialized Kokkos OpenMP team size. Zero indicates unavailable/unknown for fields whose struct comments permit it.
| [out] | out | Non-null caller-owned SWMM_ThreadInfo destination; all fields are filled on success. |
| SWMM_ENGINE_API int swmm_get_transport_matrix | ( | SWMM_Engine | engine, |
| SWMM_TransportMatrix * | out ) |
Resolve planned transport classes for each configured model domain.
Read after open and again after relevant option edits. An unopened/unavailable domain reports unavailable cells. This is configured transport resolution, not proof of runtime initialization or local heat-flux availability.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [out] | out | Non-null caller-owned matrix indexed [SWMM_TRANSPORT_DOMAIN_*][SWMM_TRANSPORT_CLASS_*]; reasons are NUL-terminated and truncated to their fixed capacity. |
| SWMM_ENGINE_API int swmm_get_unit_system | ( | SWMM_Engine | engine, |
| int * | unit_system ) |
Read the unit system implied by project flow units.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [out] | unit_system | Optional destination. 0=US/imperial or 1=SI/metric; CMS/LPS/MLD select SI. |
| SWMM_ENGINE_API const char * swmm_get_warning_at | ( | SWMM_Engine | engine, |
| int | index ) |
Borrow one accumulated warning message.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [in] | index | Zero-based message index. |
| SWMM_ENGINE_API int swmm_get_warning_count | ( | SWMM_Engine | engine | ) |
Count accumulated warning messages.
This getter does not clear the list and is distinct from the stored last-error code.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| SWMM_ENGINE_API int swmm_is_between_events | ( | SWMM_Engine | engine, |
| int * | is_between ) |
Read the current implementation event-list presence flag.
Despite the historical function name, the implementation does not compare the simulation clock with event windows; it reports only whether the event list is nonempty.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [out] | is_between | Optional destination: 1 when at least one event entry is configured, 0 for an empty event list. |
| SWMM_ENGINE_API int swmm_preview_transport_matrix | ( | SWMM_Engine | engine, |
| const SWMM_TransportDraft * | draft, | ||
| SWMM_TransportMatrix * | out ) |
Resolve transport for a temporary draft without mutating the model.
Uses existing mesh/aquifer authoring and a temporary options overlay. Does not initialize transport, validate runtime support, or persist the draft.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [in] | draft | Non-null borrowed draft: Boolean fields and surface_class entries must be 0/1; groundwater must be -1 (automatic), 0 (off), or 1 (on). |
| [out] | out | Non-null caller-owned resolved matrix with bounded NUL-terminated reasons; unchanged on argument refusal. |
| SWMM_ENGINE_API int swmm_runoff_iface_close | ( | SWMM_Engine | engine | ) |
Close and release the runoff-cache file if present.
Idempotent for a live engine; engine close also invokes this cleanup. Does not destroy the engine.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| SWMM_ENGINE_API int swmm_runoff_iface_open_read | ( | SWMM_Engine | engine, |
| const char * | path ) |
Open a compatible runoff cache for USE-mode record reads.
Header subcatchment count, pollutant count and flow units must match the current model. USE does not automatically suppress native runoff computation; manually loaded states can be overwritten by subsequent runoff work.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [in] | path | Non-null, nonempty NUL-terminated existing runoff-cache path; borrowed for the call. |
| SWMM_ENGINE_API int swmm_runoff_iface_open_write | ( | SWMM_Engine | engine, |
| const char * | path ) |
Open a runoff cache for SAVE records using the current model schema.
Call after configuring the model dimensions/units and before stepping. Automatic SAVE records are emitted by runoff substeps; close with swmm_runoff_iface_close() or engine close.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [in] | path | Non-null, nonempty NUL-terminated output path. Existing contents are truncated; string is borrowed for the call. |
| SWMM_ENGINE_API int swmm_runoff_iface_read_step | ( | SWMM_Engine | engine, |
| int * | has_data ) |
Read one available runoff record into the current subcatchment state.
Returns SWMM_OK even when the underlying read returns false; has_data is the only per-call availability signal. The next native runoff calculation may overwrite the imported state.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [out] | has_data | Optional destination: 1 when a record was read, 0 when no record is available (including EOF, no open file or an unsuitable read state). |
| SWMM_ENGINE_API int swmm_runoff_iface_save_step | ( | SWMM_Engine | engine, |
| double | dt ) |
Request a manual runoff-cache snapshot.
Normally SAVE records are emitted automatically. With no open SAVE file this is a no-op; this wrapper does not report a write/flush error from the underlying void save operation.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [in] | dt | Snapshot runoff substep duration in seconds, passed through without validation. |
| SWMM_ENGINE_API int swmm_set_progress_callback | ( | SWMM_Engine | engine, |
| SWMM_ProgressCallback | callback, | ||
| void * | user_data ) |
Register, replace or disable pre-step progress.
No lifecycle guard is applied. Callbacks run synchronously on the thread making the triggering engine call; they must not throw or recursively step/close/destroy the engine. See the callback typedef for timing and permitted updates.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [in] | callback | SWMM_ProgressCallback function pointer, or NULL to unregister. Borrowed until replaced/unregistered or engine destruction. |
| [in] | user_data | Borrowed opaque pointer passed through unchanged; may be NULL. Keep the context alive for every callback invocation. |
| SWMM_ENGINE_API int swmm_set_steady_state_skip | ( | SWMM_Engine | engine, |
| int | enabled ) |
Set the stored steady-state routing-skip option.
Sets the option directly without a lifecycle guard. Routing logic determines whether individual steps can be skipped.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [in] | enabled | 0 disables skipping; any nonzero value enables it. |
| SWMM_ENGINE_API int swmm_set_step_begin_callback | ( | SWMM_Engine | engine, |
| SWMM_StepBeginCallback | callback, | ||
| void * | user_data ) |
Register, replace or disable pre-physics step notifications.
No lifecycle guard is applied. Callbacks run synchronously on the thread making the triggering engine call; they must not throw or recursively step/close/destroy the engine. See the callback typedef for timing and permitted updates.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [in] | callback | SWMM_StepBeginCallback function pointer, or NULL to unregister. Borrowed until replaced/unregistered or engine destruction. |
| [in] | user_data | Borrowed opaque pointer passed through unchanged; may be NULL. Keep the context alive for every callback invocation. |
| SWMM_ENGINE_API int swmm_set_step_end_callback | ( | SWMM_Engine | engine, |
| SWMM_StepEndCallback | callback, | ||
| void * | user_data ) |
Register, replace or disable post-physics step notifications.
No lifecycle guard is applied. Callbacks run synchronously on the thread making the triggering engine call; they must not throw or recursively step/close/destroy the engine. See the callback typedef for timing and permitted updates.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [in] | callback | SWMM_StepEndCallback function pointer, or NULL to unregister. Borrowed until replaced/unregistered or engine destruction. |
| [in] | user_data | Borrowed opaque pointer passed through unchanged; may be NULL. Keep the context alive for every callback invocation. |
| SWMM_ENGINE_API int swmm_set_warning_callback | ( | SWMM_Engine | engine, |
| SWMM_WarningCallback | callback, | ||
| void * | user_data ) |
Register, replace or disable diagnostics.
No lifecycle guard is applied. Callbacks run synchronously on the thread making the triggering engine call; they must not throw or recursively step/close/destroy the engine. See the callback typedef for timing and permitted updates.
| [in] | engine | Non-null live engine handle; caller provides exclusive access on the owning thread. |
| [in] | callback | SWMM_WarningCallback function pointer, or NULL to unregister. Borrowed until replaced/unregistered or engine destruction. |
| [in] | user_data | Borrowed opaque pointer passed through unchanged; may be NULL. Keep the context alive for every callback invocation. |
| SWMM_ENGINE_API const char * swmm_transport_class_name | ( | int | species_class | ) |
Get the display name of a transport-species class.
| [in] | species_class | SWMM_TRANSPORT_CLASS_* integer in [0,SWMM_TRANSPORT_CLASS_COUNT). |
| SWMM_ENGINE_API const char * swmm_transport_domain_name | ( | int | domain | ) |
Get the display name of a transport-domain axis value.
| [in] | domain | SWMM_TRANSPORT_DOMAIN_* integer in [0,SWMM_TRANSPORT_DOMAIN_COUNT). |