![]() |
OpenSWMM Engine
6.0.0-alpha.3
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.3)
|
OpenSWMM Engine — standalone cross-section geometry C API. More...
Go to the source code of this file.
Typedefs | |
| typedef void * | SWMM_XSect |
| Opaque handle to a standalone cross-section. Free with swmm_xsect_free(). | |
| typedef enum SWMM_UnitSystem | SWMM_UnitSystem |
| Unit system for a standalone cross-section. | |
Enumerations | |
| enum | SWMM_UnitSystem { SWMM_UNITS_US = 0 , SWMM_UNITS_SI = 1 } |
| Unit system for a standalone cross-section. More... | |
Functions | |
| SWMM_ENGINE_API int | swmm_xsect_create (int shape, double geom1, double geom2, double geom3, double geom4, int unit_system, SWMM_XSect *out) |
| Create a cross-section from a shape code and its geometry parameters. | |
| SWMM_ENGINE_API int | swmm_xsect_create_irregular (const double *stations, const double *elevations, int n_pts, double x_left_bank, double x_right_bank, double n_left, double n_channel, double n_right, double length_factor, int unit_system, SWMM_XSect *out) |
| Create an irregular (natural channel) cross-section from a transect. | |
| SWMM_ENGINE_API int | swmm_xsect_create_custom (double y_full, const double *curve_depths, const double *curve_widths, int n_pts, int unit_system, SWMM_XSect *out) |
| Create a custom cross-section from a normalized shape curve. | |
| SWMM_ENGINE_API int | swmm_xsect_create_street (double width, double curb_height, double slope, double roughness, double gutter_depression, double gutter_width, int sides, double back_width, double back_slope, double back_roughness, int unit_system, SWMM_XSect *out) |
| Create a street cross-section. | |
| SWMM_ENGINE_API int | swmm_link_create_xsect (SWMM_Engine engine, int link_idx, SWMM_XSect *out) |
| Create a cross-section from a link of an open model. | |
| SWMM_ENGINE_API int | swmm_xsect_free (SWMM_XSect xsect) |
| Release a cross-section handle. | |
| SWMM_ENGINE_API int | swmm_xsect_get_shape (SWMM_XSect xsect, int *shape) |
| Get the shape code of a cross-section. | |
| SWMM_ENGINE_API int | swmm_xsect_get_units (SWMM_XSect xsect, int *unit_system, int *flow_units) |
| Get the unit system and flow units a handle reports its results in. | |
| SWMM_ENGINE_API const char * | swmm_xsect_shape_name (int shape) |
| Get the name of a cross-section shape code. | |
| SWMM_ENGINE_API int | swmm_xsect_area_of_depth (SWMM_XSect xsect, double depth, double *area) |
| Flow area at a given depth. | |
| SWMM_ENGINE_API int | swmm_xsect_width_of_depth (SWMM_XSect xsect, double depth, double *width) |
| Top width of the water surface at a given depth. | |
| SWMM_ENGINE_API int | swmm_xsect_hydrad_of_depth (SWMM_XSect xsect, double depth, double *hydrad) |
| Hydraulic radius (area / wetted perimeter) at a given depth. | |
| SWMM_ENGINE_API int | swmm_xsect_depth_of_area (SWMM_XSect xsect, double area, double *depth) |
| Depth of flow for a given area — the inverse of swmm_xsect_area_of_depth(). | |
| SWMM_ENGINE_API int | swmm_xsect_hydrad_of_area (SWMM_XSect xsect, double area, double *hydrad) |
| Hydraulic radius for a given area. | |
| SWMM_ENGINE_API int | swmm_xsect_sectfactor_of_area (SWMM_XSect xsect, double area, double *sf) |
| Section factor (A·R^(2/3)) for a given area. | |
| SWMM_ENGINE_API int | swmm_xsect_area_of_sectfactor (SWMM_XSect xsect, double sf, double *area) |
| Flow area for a given section factor — the inverse of swmm_xsect_sectfactor_of_area(), used to solve for normal depth. | |
| SWMM_ENGINE_API int | swmm_xsect_dsda (SWMM_XSect xsect, double area, double *dsda) |
| Derivative of the section factor with respect to area, dS/dA. | |
| SWMM_ENGINE_API int | swmm_xsect_critical_depth (SWMM_XSect xsect, double flow, double *ycrit) |
| Critical depth for a given flow. | |
| SWMM_ENGINE_API int | swmm_xsect_full_properties (SWMM_XSect xsect, double *y_full, double *a_full, double *r_full, double *w_max, double *s_full, double *a_max) |
| Full-depth (bank-full) properties of the cross-section. | |
| SWMM_ENGINE_API int | swmm_xsect_is_open (SWMM_XSect xsect, int *is_open) |
| Whether the cross-section is open to the atmosphere at its top. | |
| SWMM_ENGINE_API int | swmm_xsect_area_of_depth_array (SWMM_XSect xsect, const double *depth, int n, double *area) |
| Array form of swmm_xsect_area_of_depth(). | |
| SWMM_ENGINE_API int | swmm_xsect_width_of_depth_array (SWMM_XSect xsect, const double *depth, int n, double *width) |
| Array form of swmm_xsect_width_of_depth(). | |
| SWMM_ENGINE_API int | swmm_xsect_hydrad_of_depth_array (SWMM_XSect xsect, const double *depth, int n, double *hydrad) |
| Array form of swmm_xsect_hydrad_of_depth(). | |
| SWMM_ENGINE_API int | swmm_xsect_depth_of_area_array (SWMM_XSect xsect, const double *area, int n, double *depth) |
| Array form of swmm_xsect_depth_of_area(). | |
| SWMM_ENGINE_API int | swmm_xsect_hydrad_of_area_array (SWMM_XSect xsect, const double *area, int n, double *hydrad) |
| Array form of swmm_xsect_hydrad_of_area(). | |
| SWMM_ENGINE_API int | swmm_xsect_sectfactor_of_area_array (SWMM_XSect xsect, const double *area, int n, double *sf) |
| Array form of swmm_xsect_sectfactor_of_area(). | |
| SWMM_ENGINE_API int | swmm_xsect_area_of_sectfactor_array (SWMM_XSect xsect, const double *sf, int n, double *area) |
| Array form of swmm_xsect_area_of_sectfactor(). | |
| SWMM_ENGINE_API int | swmm_xsect_dsda_array (SWMM_XSect xsect, const double *area, int n, double *dsda) |
| Array form of swmm_xsect_dsda(). | |
| SWMM_ENGINE_API int | swmm_xsect_critical_depth_array (SWMM_XSect xsect, const double *flow, int n, double *ycrit) |
| Array form of swmm_xsect_critical_depth(). | |
OpenSWMM Engine — standalone cross-section geometry C API.
Exposes the engine's canonical cross-section geometry kernels as a reference implementation usable without a model. Construct a cross-section from shape + geometry parameters (or from transect, shape-curve or street data), then query area / top width / hydraulic radius / section factor / critical depth and their inverses. The same functions the routing solvers use answer these queries, so results agree with a simulation bit-for-bit.
A handle can also be taken from a link of an open model (swmm_link_create_xsect), using the geometry the engine actually built — including transect tables. Such a handle owns a deep copy and stays valid after the engine is closed.
| typedef enum SWMM_UnitSystem SWMM_UnitSystem |
Unit system for a standalone cross-section.
Matches the engine's internal 0=US / 1=SI coding (see swmm_get_unit_system()). Selects both the length units (ft vs m) and the default flow unit used by swmm_xsect_critical_depth() (CFS vs CMS).
| typedef void* SWMM_XSect |
Opaque handle to a standalone cross-section. Free with swmm_xsect_free().
| enum SWMM_UnitSystem |
Unit system for a standalone cross-section.
Matches the engine's internal 0=US / 1=SI coding (see swmm_get_unit_system()). Selects both the length units (ft vs m) and the default flow unit used by swmm_xsect_critical_depth() (CFS vs CMS).
| Enumerator | |
|---|---|
| SWMM_UNITS_US | Feet, ft², ft^(8/3), CFS. |
| SWMM_UNITS_SI | Metres, m², m^(8/3), CMS. |
| SWMM_ENGINE_API int swmm_link_create_xsect | ( | SWMM_Engine | engine, |
| int | link_idx, | ||
| SWMM_XSect * | out ) |
Create a cross-section from a link of an open model.
Deep-copies the geometry the engine actually built for the link, including any transect / shape-curve / street tables, so the handle remains valid after the engine is closed or destroyed. The handle inherits the model's unit system and flow units.
| engine | Engine handle with geometry resolved (OPENED or later). | |
| link_idx | Zero-based link index. | |
| [out] | out | Receives the new handle on success. |
link_idx is out of range; SWMM_ERR_LIFECYCLE if the model is still in the BUILDING state; SWMM_ERR_BADPARAM if out is NULL or the link has no cross-section (e.g. a pump). | SWMM_ENGINE_API int swmm_xsect_area_of_depth | ( | SWMM_XSect | xsect, |
| double | depth, | ||
| double * | area ) |
Flow area at a given depth.
| xsect | Cross-section handle. | |
| depth | Depth of flow, display units. Depths above the full depth of a closed shape are clamped, as in the routing solvers. | |
| [out] | area | Receives the area, display units squared. |
area is NULL or depth is negative or not finite. | SWMM_ENGINE_API int swmm_xsect_area_of_depth_array | ( | SWMM_XSect | xsect, |
| const double * | depth, | ||
| int | n, | ||
| double * | area ) |
Array form of swmm_xsect_area_of_depth().
| SWMM_ENGINE_API int swmm_xsect_area_of_sectfactor | ( | SWMM_XSect | xsect, |
| double | sf, | ||
| double * | area ) |
Flow area for a given section factor — the inverse of swmm_xsect_sectfactor_of_area(), used to solve for normal depth.
| xsect | Cross-section handle. | |
| sf | Section factor, display units^(8/3). | |
| [out] | area | Receives the area, display units squared. |
area is NULL or sf is negative or not finite. | SWMM_ENGINE_API int swmm_xsect_area_of_sectfactor_array | ( | SWMM_XSect | xsect, |
| const double * | sf, | ||
| int | n, | ||
| double * | area ) |
Array form of swmm_xsect_area_of_sectfactor().
| SWMM_ENGINE_API int swmm_xsect_create | ( | int | shape, |
| double | geom1, | ||
| double | geom2, | ||
| double | geom3, | ||
| double | geom4, | ||
| int | unit_system, | ||
| SWMM_XSect * | out ) |
Create a cross-section from a shape code and its geometry parameters.
Handles every self-contained shape — i.e. all of SWMM_XSectShape except SWMM_XSECT_IRREGULAR, SWMM_XSECT_CUSTOM and SWMM_XSECT_STREET, whose geometry comes from tabulated data and which have their own constructors below.
geom1–geom4 carry the same meaning as the [XSECTIONS] Geom1–Geom4 columns; see the per-shape notes on SWMM_XSectShape. Unused parameters may be passed as 0.
| shape | A SWMM_XSectShape code. | |
| geom1 | Full depth / diameter, in display units (see units). | |
| geom2 | Second geometry parameter, or 0. | |
| geom3 | Third geometry parameter, or 0. | |
| geom4 | Fourth geometry parameter, or 0. | |
| unit_system | A SWMM_UnitSystem value. | |
| [out] | out | Receives the new handle on success. |
out is NULL, shape is not a valid self-contained shape, unit_system is out of range, or the geometry is degenerate (e.g. non-positive depth). | SWMM_ENGINE_API int swmm_xsect_create_custom | ( | double | y_full, |
| const double * | curve_depths, | ||
| const double * | curve_widths, | ||
| int | n_pts, | ||
| int | unit_system, | ||
| SWMM_XSect * | out ) |
Create a custom cross-section from a normalized shape curve.
Mirrors a SHAPE-type [CURVES] entry scaled to y_full: curve_depths are y/yFull in [0,1] and curve_widths are the corresponding width/wMax.
| y_full | Full depth of the section, display units (> 0). | |
| curve_depths | Normalized depths (y/yFull), ascending. | |
| curve_widths | Normalized widths (w/wMax) at each depth. | |
| n_pts | Number of curve points (>= 2). | |
| unit_system | A SWMM_UnitSystem value. | |
| [out] | out | Receives the new handle on success. |
n_pts < 2, y_full <= 0, or an out-of-range unit_system. | SWMM_ENGINE_API int swmm_xsect_create_irregular | ( | const double * | stations, |
| const double * | elevations, | ||
| int | n_pts, | ||
| double | x_left_bank, | ||
| double | x_right_bank, | ||
| double | n_left, | ||
| double | n_channel, | ||
| double | n_right, | ||
| double | length_factor, | ||
| int | unit_system, | ||
| SWMM_XSect * | out ) |
Create an irregular (natural channel) cross-section from a transect.
Mirrors an [TRANSECTS] entry: stations/elevations are the GR station-elevation pairs, and the Manning's n triple is the NC line. The roughness values are load-bearing, not decorative — the hydraulic-radius table is conveyance-weighted across the left overbank / channel / right overbank subsections, so passing the wrong n changes the geometry this handle reports.
| stations | Station (horizontal) coordinates, display units, ascending. | |
| elevations | Elevation at each station, display units. | |
| n_pts | Number of station/elevation pairs (>= 2). | |
| x_left_bank | Station where the left overbank ends. Pass the same value as x_right_bank for a channel with no overbanks. | |
| x_right_bank | Station where the right overbank begins. | |
| n_left | Manning's n, left overbank. 0 → use n_channel. | |
| n_channel | Manning's n, main channel. Must be > 0. | |
| n_right | Manning's n, right overbank. 0 → use n_channel. | |
| length_factor | Main-channel / flood-plain length ratio. 0 → 1.0. | |
| unit_system | A SWMM_UnitSystem value. | |
| [out] | out | Receives the new handle on success. |
n_pts < 2, n_channel <= 0, an out-of-range unit_system, or a transect whose stations yield no wetted area. | SWMM_ENGINE_API int swmm_xsect_create_street | ( | double | width, |
| double | curb_height, | ||
| double | slope, | ||
| double | roughness, | ||
| double | gutter_depression, | ||
| double | gutter_width, | ||
| int | sides, | ||
| double | back_width, | ||
| double | back_slope, | ||
| double | back_roughness, | ||
| int | unit_system, | ||
| SWMM_XSect * | out ) |
Create a street cross-section.
Mirrors a [STREETS] entry; parameters match swmm_street_set_params(). Slopes are percentages, as in the input file.
| width | Distance from curb to crown, display units. | |
| curb_height | Curb height, display units. | |
| slope | Transverse road slope, percent. | |
| roughness | Manning's n of the road surface (> 0). | |
| gutter_depression | Depressed-gutter depth, display units. | |
| gutter_width | Depressed-gutter width, display units. | |
| sides | 1 = half street, 2 = full street. | |
| back_width | Backing width, display units (0 if none). | |
| back_slope | Backing slope, percent. | |
| back_roughness | Backing Manning's n. | |
| unit_system | A SWMM_UnitSystem value. | |
| [out] | out | Receives the new handle on success. |
out, a non-positive width/curb height/roughness, sides outside {1,2}, or an out-of-range unit_system. | SWMM_ENGINE_API int swmm_xsect_critical_depth | ( | SWMM_XSect | xsect, |
| double | flow, | ||
| double * | ycrit ) |
Critical depth for a given flow.
| xsect | Cross-section handle. | |
| flow | Flow, in the handle's flow units (see swmm_xsect_get_units()). | |
| [out] | ycrit | Receives the critical depth, display units. |
ycrit is NULL or flow is negative or not finite. | SWMM_ENGINE_API int swmm_xsect_critical_depth_array | ( | SWMM_XSect | xsect, |
| const double * | flow, | ||
| int | n, | ||
| double * | ycrit ) |
Array form of swmm_xsect_critical_depth().
| SWMM_ENGINE_API int swmm_xsect_depth_of_area | ( | SWMM_XSect | xsect, |
| double | area, | ||
| double * | depth ) |
Depth of flow for a given area — the inverse of swmm_xsect_area_of_depth().
| xsect | Cross-section handle. | |
| area | Flow area, display units squared. | |
| [out] | depth | Receives the depth, display units. |
depth is NULL or area is negative or not finite. | SWMM_ENGINE_API int swmm_xsect_depth_of_area_array | ( | SWMM_XSect | xsect, |
| const double * | area, | ||
| int | n, | ||
| double * | depth ) |
Array form of swmm_xsect_depth_of_area().
| SWMM_ENGINE_API int swmm_xsect_dsda | ( | SWMM_XSect | xsect, |
| double | area, | ||
| double * | dsda ) |
Derivative of the section factor with respect to area, dS/dA.
| xsect | Cross-section handle. | |
| area | Flow area, display units squared. | |
| [out] | dsda | Receives dS/dA, display units^(2/3). |
dsda is NULL or area is negative or not finite. | SWMM_ENGINE_API int swmm_xsect_dsda_array | ( | SWMM_XSect | xsect, |
| const double * | area, | ||
| int | n, | ||
| double * | dsda ) |
Array form of swmm_xsect_dsda().
| SWMM_ENGINE_API int swmm_xsect_free | ( | SWMM_XSect | xsect | ) |
Release a cross-section handle.
| xsect | Handle from any swmm_xsect_create* / swmm_link_create_xsect. NULL is accepted and ignored. |
| SWMM_ENGINE_API int swmm_xsect_full_properties | ( | SWMM_XSect | xsect, |
| double * | y_full, | ||
| double * | a_full, | ||
| double * | r_full, | ||
| double * | w_max, | ||
| double * | s_full, | ||
| double * | a_max ) |
Full-depth (bank-full) properties of the cross-section.
Every out-parameter is optional — pass NULL for any value not wanted.
| xsect | Cross-section handle. | |
| [out] | y_full | Full depth, display units. |
| [out] | a_full | Area when full, display units squared. |
| [out] | r_full | Hydraulic radius when full, display units. |
| [out] | w_max | Width at the widest point, display units. |
| [out] | s_full | Section factor when full, display units^(8/3). |
| [out] | a_max | Area at which flow is a maximum, display units squared. |
| SWMM_ENGINE_API int swmm_xsect_get_shape | ( | SWMM_XSect | xsect, |
| int * | shape ) |
Get the shape code of a cross-section.
| xsect | Cross-section handle. | |
| [out] | shape | Receives a SWMM_XSectShape code. |
shape is NULL. | SWMM_ENGINE_API int swmm_xsect_get_units | ( | SWMM_XSect | xsect, |
| int * | unit_system, | ||
| int * | flow_units ) |
Get the unit system and flow units a handle reports its results in.
flow_units matters only for swmm_xsect_critical_depth(); every other query is governed by unit_system alone.
| xsect | Cross-section handle. | |
| [out] | unit_system | Receives a SWMM_UnitSystem value (may be NULL). |
| [out] | flow_units | Receives the flow-unit code (may be NULL): 0=CFS, 1=GPM, 2=MGD, 3=CMS, 4=LPS, 5=MLD. A standalone handle reports CFS (US) or CMS (SI); a handle from a link reports its model's units. |
| SWMM_ENGINE_API int swmm_xsect_hydrad_of_area | ( | SWMM_XSect | xsect, |
| double | area, | ||
| double * | hydrad ) |
Hydraulic radius for a given area.
| xsect | Cross-section handle. | |
| area | Flow area, display units squared. | |
| [out] | hydrad | Receives the hydraulic radius, display units. |
hydrad is NULL or area is negative or not finite. | SWMM_ENGINE_API int swmm_xsect_hydrad_of_area_array | ( | SWMM_XSect | xsect, |
| const double * | area, | ||
| int | n, | ||
| double * | hydrad ) |
Array form of swmm_xsect_hydrad_of_area().
| SWMM_ENGINE_API int swmm_xsect_hydrad_of_depth | ( | SWMM_XSect | xsect, |
| double | depth, | ||
| double * | hydrad ) |
Hydraulic radius (area / wetted perimeter) at a given depth.
| xsect | Cross-section handle. | |
| depth | Depth of flow, display units. | |
| [out] | hydrad | Receives the hydraulic radius, display units. |
hydrad is NULL or depth is negative or not finite. | SWMM_ENGINE_API int swmm_xsect_hydrad_of_depth_array | ( | SWMM_XSect | xsect, |
| const double * | depth, | ||
| int | n, | ||
| double * | hydrad ) |
Array form of swmm_xsect_hydrad_of_depth().
| SWMM_ENGINE_API int swmm_xsect_is_open | ( | SWMM_XSect | xsect, |
| int * | is_open ) |
Whether the cross-section is open to the atmosphere at its top.
| xsect | Cross-section handle. | |
| [out] | is_open | Receives 1 for an open channel, 0 for a closed conduit. |
is_open is NULL. | SWMM_ENGINE_API int swmm_xsect_sectfactor_of_area | ( | SWMM_XSect | xsect, |
| double | area, | ||
| double * | sf ) |
Section factor (A·R^(2/3)) for a given area.
| xsect | Cross-section handle. | |
| area | Flow area, display units squared. | |
| [out] | sf | Receives the section factor, display units^(8/3). |
sf is NULL or area is negative or not finite. | SWMM_ENGINE_API int swmm_xsect_sectfactor_of_area_array | ( | SWMM_XSect | xsect, |
| const double * | area, | ||
| int | n, | ||
| double * | sf ) |
Array form of swmm_xsect_sectfactor_of_area().
| SWMM_ENGINE_API const char * swmm_xsect_shape_name | ( | int | shape | ) |
Get the name of a cross-section shape code.
Useful for reporting, and for checking a code at runtime after the 6.0 SWMM_XSectShape renumbering (see openswmm_links.h).
| shape | A SWMM_XSectShape code. |
"CIRCULAR", or NULL if shape is not a valid code. | SWMM_ENGINE_API int swmm_xsect_width_of_depth | ( | SWMM_XSect | xsect, |
| double | depth, | ||
| double * | width ) |
Top width of the water surface at a given depth.
| xsect | Cross-section handle. | |
| depth | Depth of flow, display units. | |
| [out] | width | Receives the top width, display units. |
width is NULL or depth is negative or not finite. | SWMM_ENGINE_API int swmm_xsect_width_of_depth_array | ( | SWMM_XSect | xsect, |
| const double * | depth, | ||
| int | n, | ||
| double * | width ) |
Array form of swmm_xsect_width_of_depth().