OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
openswmm_xsect.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2//
3// Copyright 2026 Caleb Buahin
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
59
60#ifndef OPENSWMM_XSECT_H
61#define OPENSWMM_XSECT_H
62
63#include "openswmm_engine.h"
64#include "openswmm_links.h"
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
71typedef void* SWMM_XSect;
72
85
86/* =========================================================================
87 * Construction / destruction
88 * ========================================================================= */
89
129SWMM_ENGINE_API int swmm_xsect_create(int shape, double geom1, double geom2, double geom3,
130 double geom4, int unit_system, SWMM_XSect* out);
131
168SWMM_ENGINE_API int swmm_xsect_create_irregular(const double* stations, const double* elevations,
169 int n_pts, double x_left_bank, double x_right_bank,
170 double n_left, double n_channel, double n_right,
171 double length_factor, int unit_system,
172 SWMM_XSect* out);
173
200SWMM_ENGINE_API int swmm_xsect_create_custom(double y_full, const double* curve_depths,
201 const double* curve_widths, int n_pts, int unit_system,
202 SWMM_XSect* out);
203
236SWMM_ENGINE_API int swmm_xsect_create_street(double width, double curb_height, double slope,
237 double roughness, double gutter_depression,
238 double gutter_width, int sides, double back_width,
239 double back_slope, double back_roughness,
240 int unit_system, SWMM_XSect* out);
241
271SWMM_ENGINE_API int swmm_link_create_xsect(SWMM_Engine engine, int link_idx, SWMM_XSect* out);
272
285
286/* =========================================================================
287 * Identity
288 * ========================================================================= */
289
301SWMM_ENGINE_API int swmm_xsect_get_shape(SWMM_XSect xsect, int* shape);
302
323SWMM_ENGINE_API int swmm_xsect_get_units(SWMM_XSect xsect, int* unit_system, int* flow_units);
324
336SWMM_ENGINE_API const char* swmm_xsect_shape_name(int shape);
337
338/* =========================================================================
339 * Queries — scalar
340 * ========================================================================= */
341
356SWMM_ENGINE_API int swmm_xsect_area_of_depth(SWMM_XSect xsect, double depth, double* area);
357
371SWMM_ENGINE_API int swmm_xsect_width_of_depth(SWMM_XSect xsect, double depth, double* width);
372
386SWMM_ENGINE_API int swmm_xsect_hydrad_of_depth(SWMM_XSect xsect, double depth, double* hydrad);
387
401SWMM_ENGINE_API int swmm_xsect_depth_of_area(SWMM_XSect xsect, double area, double* depth);
402
416SWMM_ENGINE_API int swmm_xsect_hydrad_of_area(SWMM_XSect xsect, double area, double* hydrad);
417
431SWMM_ENGINE_API int swmm_xsect_sectfactor_of_area(SWMM_XSect xsect, double area, double* sf);
432
447SWMM_ENGINE_API int swmm_xsect_area_of_sectfactor(SWMM_XSect xsect, double sf, double* area);
448
462SWMM_ENGINE_API int swmm_xsect_dsda(SWMM_XSect xsect, double area, double* dsda);
463
477SWMM_ENGINE_API int swmm_xsect_critical_depth(SWMM_XSect xsect, double flow, double* ycrit);
478
501SWMM_ENGINE_API int swmm_xsect_full_properties(SWMM_XSect xsect, double* y_full, double* a_full,
502 double* r_full, double* w_max, double* s_full,
503 double* a_max);
504
516SWMM_ENGINE_API int swmm_xsect_is_open(SWMM_XSect xsect, int* is_open);
517
518/* =========================================================================
519 * Queries — array
520 * ========================================================================= */
521/*
522 * Each scalar query above has an `_array` counterpart evaluating `n` inputs in
523 * one call. `in` and `out` must each hold `n` elements and may alias. `n` == 0
524 * is a no-op returning SWMM_OK. All inputs are validated before any result is written; invalid input
525 * returns SWMM_ERR_BADPARAM and preserves the output array.
526 */
527
546SWMM_ENGINE_API int swmm_xsect_area_of_depth_array(SWMM_XSect xsect, const double* depth, int n,
547 double* area);
566SWMM_ENGINE_API int swmm_xsect_width_of_depth_array(SWMM_XSect xsect, const double* depth, int n,
567 double* width);
586SWMM_ENGINE_API int swmm_xsect_hydrad_of_depth_array(SWMM_XSect xsect, const double* depth, int n,
587 double* hydrad);
606SWMM_ENGINE_API int swmm_xsect_depth_of_area_array(SWMM_XSect xsect, const double* area, int n,
607 double* depth);
626SWMM_ENGINE_API int swmm_xsect_hydrad_of_area_array(SWMM_XSect xsect, const double* area, int n,
627 double* hydrad);
646SWMM_ENGINE_API int swmm_xsect_sectfactor_of_area_array(SWMM_XSect xsect, const double* area, int n,
647 double* sf);
666SWMM_ENGINE_API int swmm_xsect_area_of_sectfactor_array(SWMM_XSect xsect, const double* sf, int n,
667 double* area);
686SWMM_ENGINE_API int swmm_xsect_dsda_array(SWMM_XSect xsect, const double* area, int n,
687 double* dsda);
707SWMM_ENGINE_API int swmm_xsect_critical_depth_array(SWMM_XSect xsect, const double* flow, int n,
708 double* ycrit);
709
710#ifdef __cplusplus
711}
712#endif
713
714#endif /* OPENSWMM_XSECT_H */
#define SWMM_ENGINE_API
Definition openswmm_2d.h:62
void * SWMM_Engine
Opaque handle to an OpenSWMM Engine instance.
Definition openswmm_callbacks.h:55
OpenSWMM Engine — primary transparent C API (master header).
SWMM_ENGINE_API const char * swmm_xsect_shape_name(int shape)
Get the name of a cross-section shape code.
Definition openswmm_xsect_impl.cpp:702
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().
Definition openswmm_xsect_impl.cpp:730
SWMM_ENGINE_API int swmm_xsect_hydrad_of_area_array(SWMM_XSect xsect, const double *area, int n, double *hydrad)
Evaluate swmm_xsect_hydrad_of_area() for an entire input array.
Definition openswmm_xsect_impl.cpp:824
SWMM_ENGINE_API int swmm_xsect_hydrad_of_area(SWMM_XSect xsect, double area, double *hydrad)
Hydraulic radius for a given area.
Definition openswmm_xsect_impl.cpp:736
SWMM_ENGINE_API int swmm_xsect_critical_depth(SWMM_XSect xsect, double flow, double *ycrit)
Critical depth for a given flow.
Definition openswmm_xsect_impl.cpp:759
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.
Definition openswmm_xsect_impl.cpp:426
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.
Definition openswmm_xsect_impl.cpp:618
SWMM_ENGINE_API int swmm_xsect_area_of_sectfactor_array(SWMM_XSect xsect, const double *sf, int n, double *area)
Evaluate swmm_xsect_area_of_sectfactor() for an entire input array.
Definition openswmm_xsect_impl.cpp:837
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.
Definition openswmm_xsect_impl.cpp:474
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.
Definition openswmm_xsect_impl.cpp:752
SWMM_ENGINE_API int swmm_xsect_area_of_depth_array(SWMM_XSect xsect, const double *depth, int n, double *area)
Evaluate swmm_xsect_area_of_depth() for an entire input array.
Definition openswmm_xsect_impl.cpp:796
void * SWMM_XSect
Opaque handle to a standalone cross-section. Free with swmm_xsect_free().
Definition openswmm_xsect.h:71
SWMM_UnitSystem
Unit system for a standalone cross-section.
Definition openswmm_xsect.h:81
@ SWMM_UNITS_US
Definition openswmm_xsect.h:82
@ SWMM_UNITS_SI
Definition openswmm_xsect.h:83
SWMM_ENGINE_API int swmm_xsect_free(SWMM_XSect xsect)
Release a cross-section handle.
Definition openswmm_xsect_impl.cpp:676
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.
Definition openswmm_xsect_impl.cpp:742
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.
Definition openswmm_xsect_impl.cpp:569
SWMM_ENGINE_API int swmm_xsect_critical_depth_array(SWMM_XSect xsect, const double *flow, int n, double *ycrit)
Evaluate swmm_xsect_critical_depth() for an entire input array.
Definition openswmm_xsect_impl.cpp:849
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.
Definition openswmm_xsect_impl.cpp:528
SWMM_ENGINE_API int swmm_xsect_area_of_depth(SWMM_XSect xsect, double depth, double *area)
Flow area at a given depth.
Definition openswmm_xsect_impl.cpp:712
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.
Definition openswmm_xsect_impl.cpp:724
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.
Definition openswmm_xsect_impl.cpp:718
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(),...
Definition openswmm_xsect_impl.cpp:747
SWMM_ENGINE_API int swmm_xsect_depth_of_area_array(SWMM_XSect xsect, const double *area, int n, double *depth)
Evaluate swmm_xsect_depth_of_area() for an entire input array.
Definition openswmm_xsect_impl.cpp:817
SWMM_ENGINE_API int swmm_xsect_dsda_array(SWMM_XSect xsect, const double *area, int n, double *dsda)
Evaluate swmm_xsect_dsda() for an entire input array.
Definition openswmm_xsect_impl.cpp:843
SWMM_ENGINE_API int swmm_xsect_hydrad_of_depth_array(SWMM_XSect xsect, const double *depth, int n, double *hydrad)
Evaluate swmm_xsect_hydrad_of_depth() for an entire input array.
Definition openswmm_xsect_impl.cpp:810
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.
Definition openswmm_xsect_impl.cpp:764
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.
Definition openswmm_xsect_impl.cpp:692
SWMM_ENGINE_API int swmm_xsect_get_shape(SWMM_XSect xsect, int *shape)
Get the shape code of a cross-section.
Definition openswmm_xsect_impl.cpp:685
SWMM_ENGINE_API int swmm_xsect_width_of_depth_array(SWMM_XSect xsect, const double *depth, int n, double *width)
Evaluate swmm_xsect_width_of_depth() for an entire input array.
Definition openswmm_xsect_impl.cpp:803
SWMM_ENGINE_API int swmm_xsect_sectfactor_of_area_array(SWMM_XSect xsect, const double *area, int n, double *sf)
Evaluate swmm_xsect_sectfactor_of_area() for an entire input array.
Definition openswmm_xsect_impl.cpp:831
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.
Definition openswmm_xsect_impl.cpp:785