OpenSWMM Engine  6.0.0-alpha.3
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.3)
Loading...
Searching...
No Matches
openswmm_2d.h
Go to the documentation of this file.
1
21
22#ifndef OPENSWMM_2D_H
23#define OPENSWMM_2D_H
24
25#include "openswmm_callbacks.h"
26
27#ifdef OPENSWMM_ENGINE_STATIC
28# define SWMM_ENGINE_API
29#else
30# ifdef _WIN32
31# ifdef openswmm_engine_EXPORTS
32# define SWMM_ENGINE_API __declspec(dllexport)
33# else
34# define SWMM_ENGINE_API __declspec(dllimport)
35# endif
36# else
37# define SWMM_ENGINE_API __attribute__((visibility("default")))
38# endif
39#endif
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45/* =========================================================================
46 * 2D Module Status
47 * ========================================================================= */
48
55SWMM_ENGINE_API int swmm_2d_is_active(SWMM_Engine engine, int* active);
56
68
69/* =========================================================================
70 * Mesh Geometry — Query (read-only after initialization)
71 * ========================================================================= */
72
76
80
86 double* x, double* y, double* z);
87
92 double* x, double* y, double* z);
93
112SWMM_ENGINE_API int swmm_2d_set_vertex_z(SWMM_Engine engine, int idx, double z);
113
119 int* v0, int* v1, int* v2);
120
126 double* area);
127
131 double* cx, double* cy,
132 double* cz);
133
137 double* n);
138
145 double n);
146
151 const char* tag);
152
157 const char* tag);
158
164 char* buf, int buflen);
165
171 char* buf, int buflen);
172
177 int* n0, int* n1, int* n2);
178
191 double* length,
192 double* nx,
193 double* ny);
194
195/* =========================================================================
196 * Coupling Map — Query
197 * ========================================================================= */
198
202
206
212 int vertex_idx,
213 int* node_idx);
214
220 int tri_idx,
221 int* node_idx);
222
239 int vertex_idx,
240 const char* node_name);
241
248 int vertex_idx,
249 double* cd);
250
258 int vertex_idx,
259 double cd);
260
267 int vertex_idx,
268 double* area);
269
278 int vertex_idx,
279 double area);
280
281/* =========================================================================
282 * 2D State — Per-Triangle (read during RUNNING)
283 * ========================================================================= */
284
289SWMM_ENGINE_API int swmm_2d_get_depth(SWMM_Engine engine, int idx, double* depth);
290
293SWMM_ENGINE_API int swmm_2d_get_head(SWMM_Engine engine, int idx, double* head);
294
298 double* flux);
299
303 double* rainfall);
304
308 double* net_source);
309
313SWMM_ENGINE_API int swmm_2d_get_depths_bulk(SWMM_Engine engine, double* depths);
314
317SWMM_ENGINE_API int swmm_2d_get_heads_bulk(SWMM_Engine engine, double* heads);
318
322 double* fluxes);
323
340 double* flux);
341
342/* =========================================================================
343 * 2D Edge Conveyance (§11A of docs/2dModelStrategy.md)
344 *
345 * Per-edge multiplicative factor in [0, 1] that attenuates the
346 * diffusion-wave flux across the edge (default 1.0 = unrestricted, 0.0 =
347 * wall). Storage is flat 2D `[tri * 3 + edge_local]`. Interior edges
348 * are symmetric: setting the value on one slot mirrors to the partner
349 * slot on the neighbour triangle so mass conservation is preserved.
350 *
351 * Safe to call between routing steps. Calling during a routing step is
352 * undefined — the CVODE sub-stepper holds a const reference to the mesh.
353 * ========================================================================= */
354
362 int tri, int edge,
363 double* conveyance);
364
378 int tri, int edge,
379 double conveyance);
380
387 double* conveyance);
388
392
393/* =========================================================================
394 * 2D State — Per-Vertex (reconstructed heads)
395 * ========================================================================= */
396
400 double* head);
401
405 double* heads);
406
407/* =========================================================================
408 * 2D Solver Statistics
409 * ========================================================================= */
410
413SWMM_ENGINE_API int swmm_2d_get_max_depth(SWMM_Engine engine, double* max_depth);
414
417SWMM_ENGINE_API int swmm_2d_get_total_volume(SWMM_Engine engine, double* volume);
418
423 double* flow);
424
428
432 double* h_last);
433
438 double* max_depths);
439
444 double* max_velocities);
445
450 double* max_errs);
451
456
462 double* init_storage,
463 double* final_storage,
464 double* rainfall_in,
465 double* coupling_1d_to_2d_in,
466 double* coupling_2d_to_1d_out,
467 double* outfall_in,
468 double* outfall_out,
469 double* boundary_in,
470 double* boundary_out,
471 double* evap_out);
472
473/* =========================================================================
474 * 2D Forcing — Override rainfall or coupling for external control
475 * ========================================================================= */
476
484 double value, int mode,
485 int persist);
486
490 double value, int mode,
491 int persist);
492
505 double value, int mode,
506 int persist);
507
511 double value, int mode,
512 int persist);
513
518 double value, int mode,
519 int persist);
520
524
525/* =========================================================================
526 * 2D Solver Options — Query/Modify (valid after INITIALIZED)
527 * ========================================================================= */
528
531SWMM_ENGINE_API int swmm_2d_get_dry_depth(SWMM_Engine engine, double* dry_depth);
532
535SWMM_ENGINE_API int swmm_2d_set_dry_depth(SWMM_Engine engine, double dry_depth);
536
540
544
548
552
553/* =========================================================================
554 * 2D Boundary Conditions
555 * ========================================================================= */
556
566#define SWMM_2D_BC_WALL 0
567#define SWMM_2D_BC_NORMAL_FLOW 1
568#define SWMM_2D_BC_SPECIFIED_STAGE 2
569#define SWMM_2D_BC_SPECIFIED_FLOW 3
570#define SWMM_2D_BC_RATING_CURVE 4
571
575
582 int tri_idx, int edge,
583 int* bc_type);
584
588 int tri_idx, int edge,
589 int bc_type);
590
594 int tri_idx, int edge,
595 double* head);
596
600 int tri_idx, int edge,
601 double head);
602
606 int tri_idx, int edge,
607 double* slope);
608
612 int tri_idx, int edge,
613 double slope);
614
623 int tri_idx,
624 int edge,
625 const char* name);
626
631 int tri_idx, int edge,
632 double* flow);
633
636 int tri_idx, int edge,
637 double flow);
638
642 int tri_idx,
643 int edge,
644 const char* name);
645
652 int tri_idx,
653 int edge,
654 const char* name);
655
659 int tri_idx, int edge,
660 double* cum_flux);
661
662#ifdef __cplusplus
663} /* extern "C" */
664#endif
665
666#endif /* OPENSWMM_2D_H */
SWMM_ENGINE_API int swmm_2d_get_total_exchange_flow(SWMM_Engine engine, double *flow)
Get total exchange flow rate (sum of all coupling flows, m³/s). Positive = net flow from 2D into 1D n...
Definition Api2D.cpp:604
SWMM_ENGINE_API int swmm_2d_get_edge_bc_head(SWMM_Engine engine, int tri_idx, int edge, double *head)
Get specified stage boundary head for an edge.
Definition Api2D.cpp:931
SWMM_ENGINE_API int swmm_2d_vertex_get_coupled_node(SWMM_Engine engine, int vertex_idx, int *node_idx)
Get vertex coupling: which SWMM node is coupled to this vertex.
Definition Api2D.cpp:271
SWMM_ENGINE_API int swmm_2d_set_vertex_coupling_cd(SWMM_Engine engine, int vertex_idx, double cd)
Set the coupling discharge coefficient of a vertex ([2D_VERTEX_NODE_MAP] CD column)....
Definition Api2D.cpp:325
SWMM_ENGINE_API int swmm_2d_triangle_get_area(SWMM_Engine engine, int idx, double *area)
Get triangle area.
Definition Api2D.cpp:135
SWMM_ENGINE_API int swmm_2d_get_rel_tolerance(SWMM_Engine engine, double *rtol)
Get CVODE relative tolerance.
Definition Api2D.cpp:828
SWMM_ENGINE_API int swmm_2d_get_continuity_error(SWMM_Engine engine, double *err)
Get the global 2D surface continuity error (fraction).
Definition Api2D.cpp:664
SWMM_ENGINE_API int swmm_2d_get_edge_bc_flow(SWMM_Engine engine, int tri_idx, int edge, double *flow)
Get prescribed flow per metre of edge (m³/s/m) for a SPECIFIED_FLOW edge. V-E4.
Definition Api2D.cpp:1012
SWMM_ENGINE_API int swmm_2d_triangle_get_neighbours(SWMM_Engine engine, int idx, int *n0, int *n1, int *n2)
Get triangle neighbour indices (-1 = boundary edge).
Definition Api2D.cpp:227
SWMM_ENGINE_API int swmm_2d_get_edge_bc_type(SWMM_Engine engine, int tri_idx, int edge, int *bc_type)
Get boundary condition type for an edge.
Definition Api2D.cpp:901
SWMM_ENGINE_API int swmm_2d_reset_edge_conveyance(SWMM_Engine engine)
Reset every edge's conveyance factor to 1.0 (unrestricted).
Definition Api2D.cpp:518
SWMM_ENGINE_API int swmm_2d_get_cvode_steps(SWMM_Engine engine, long *steps)
Get number of CVODE internal steps taken in the last advance.
Definition Api2D.cpp:613
SWMM_ENGINE_API int swmm_2d_edge_get_geometry_bulk(SWMM_Engine engine, double *length, double *nx, double *ny)
Bulk get edge geometry — time-invariant edge length and outward unit normal components,...
Definition Api2D.cpp:543
SWMM_ENGINE_API int swmm_2d_get_total_volume(SWMM_Engine engine, double *volume)
Get total 2D surface volume (sum of depth * area).
Definition Api2D.cpp:595
SWMM_ENGINE_API int swmm_2d_boundary_edge_count(SWMM_Engine engine, int *count)
Get the number of boundary edges (edges with no neighbour).
Definition Api2D.cpp:885
SWMM_ENGINE_API int swmm_2d_set_edge_bc_type(SWMM_Engine engine, int tri_idx, int edge, int bc_type)
Set boundary condition type for an edge.
Definition Api2D.cpp:912
SWMM_ENGINE_API int swmm_2d_vertex_get_xyz_bulk(SWMM_Engine engine, double *x, double *y, double *z)
Bulk get vertex coordinates.
Definition Api2D.cpp:98
SWMM_ENGINE_API int swmm_2d_set_vertex_tag(SWMM_Engine engine, int idx, const char *tag)
Set the descriptive tag of a vertex (the [2D_VERTICES] TAG column). Distinct from the 1D<->2D couplin...
Definition Api2D.cpp:167
SWMM_ENGINE_API int swmm_2d_set_vertex_z(SWMM_Engine engine, int idx, double z)
Set vertex Z (ground elevation).
Definition Api2D.cpp:112
SWMM_ENGINE_API int swmm_2d_set_rel_tolerance(SWMM_Engine engine, double rtol)
Set CVODE relative tolerance.
Definition Api2D.cpp:837
SWMM_ENGINE_API int swmm_2d_get_stat_max_continuity_err(SWMM_Engine engine, double *max_errs)
Get per-triangle max |continuity residual| statistics (cumulative, m3/s).
Definition Api2D.cpp:653
SWMM_ENGINE_API int swmm_2d_vertex_get_heads_bulk(SWMM_Engine engine, double *heads)
Bulk get reconstructed heads at all vertices.
Definition Api2D.cpp:571
SWMM_ENGINE_API int swmm_2d_get_triangle_tag(SWMM_Engine engine, int idx, char *buf, int buflen)
Get the descriptive tag of a triangle (the [2D_TRIANGLES] TAG column). Copies up to buflen-1 bytes in...
Definition Api2D.cpp:203
SWMM_ENGINE_API int swmm_2d_get_coupling_flux(SWMM_Engine engine, int idx, double *flux)
Get coupling exchange flux at a triangle (m/s, + = into 2D).
Definition Api2D.cpp:382
SWMM_ENGINE_API int swmm_2d_get_stat_max_depths(SWMM_Engine engine, double *max_depths)
Get per-triangle max depth statistics (cumulative).
Definition Api2D.cpp:631
SWMM_ENGINE_API int swmm_2d_set_triangle_tag(SWMM_Engine engine, int idx, const char *tag)
Set the descriptive tag of a triangle (the [2D_TRIANGLES] TAG column, e.g. a region / subcatchment id...
Definition Api2D.cpp:178
SWMM_ENGINE_API int swmm_2d_set_edge_bc_slope(SWMM_Engine engine, int tri_idx, int edge, double slope)
Set normal flow boundary slope for an edge.
Definition Api2D.cpp:964
SWMM_ENGINE_API int swmm_2d_force_rainfall(SWMM_Engine engine, int idx, double value, int mode, int persist)
Force rainfall on a specific triangle.
Definition Api2D.cpp:707
SWMM_ENGINE_API int swmm_2d_get_max_depth(SWMM_Engine engine, double *max_depth)
Get the maximum depth across all triangles.
Definition Api2D.cpp:585
SWMM_ENGINE_API int swmm_2d_get_depth(SWMM_Engine engine, int idx, double *depth)
Get water depth at a triangle.
Definition Api2D.cpp:362
SWMM_ENGINE_API int swmm_2d_get_head(SWMM_Engine engine, int idx, double *head)
Get total head at a triangle (z + depth).
Definition Api2D.cpp:372
SWMM_ENGINE_API int swmm_2d_get_edge_flux_bulk(SWMM_Engine engine, double *flux)
Bulk get normal edge flux at every edge of every triangle.
Definition Api2D.cpp:527
SWMM_ENGINE_API int swmm_2d_get_edge_bc_cum_flux(SWMM_Engine engine, int tri_idx, int edge, double *cum_flux)
Get cumulative boundary flux at an edge (m³, + = outflow).
Definition Api2D.cpp:976
SWMM_ENGINE_API int swmm_2d_triangle_coupling_count(SWMM_Engine engine, int *count)
Get the number of triangle-to-node coupling points.
Definition Api2D.cpp:257
SWMM_ENGINE_API int swmm_2d_triangle_get_centroid(SWMM_Engine engine, int idx, double *cx, double *cy, double *cz)
Get triangle centroid coordinates.
Definition Api2D.cpp:145
SWMM_ENGINE_API int swmm_2d_get_net_source(SWMM_Engine engine, int idx, double *net_source)
Get net source/sink rate at a triangle (m/s).
Definition Api2D.cpp:402
SWMM_ENGINE_API int swmm_2d_vertex_get_head(SWMM_Engine engine, int idx, double *head)
Get reconstructed head at a vertex.
Definition Api2D.cpp:561
SWMM_ENGINE_API int swmm_2d_force_evap(SWMM_Engine engine, int idx, double value, int mode, int persist)
Force evaporation on a specific triangle.
Definition Api2D.cpp:739
SWMM_ENGINE_API int swmm_2d_get_depths_bulk(SWMM_Engine engine, double *depths)
Bulk get depths for all triangles.
Definition Api2D.cpp:412
SWMM_ENGINE_API int swmm_2d_set_edge_bc_head(SWMM_Engine engine, int tri_idx, int edge, double head)
Set specified stage boundary head for an edge.
Definition Api2D.cpp:942
SWMM_ENGINE_API int swmm_2d_set_abs_tolerance(SWMM_Engine engine, double atol)
Set CVODE absolute tolerance.
Definition Api2D.cpp:855
SWMM_ENGINE_API int swmm_2d_triangle_count(SWMM_Engine engine, int *count)
Get the number of mesh triangles.
Definition Api2D.cpp:78
SWMM_ENGINE_API int swmm_2d_get_rainfall(SWMM_Engine engine, int idx, double *rainfall)
Get rainfall intensity at a triangle (m/s).
Definition Api2D.cpp:392
SWMM_ENGINE_API int swmm_2d_get_coupling_fluxes_bulk(SWMM_Engine engine, double *fluxes)
Bulk get coupling fluxes for all triangles.
Definition Api2D.cpp:432
SWMM_ENGINE_API int swmm_2d_prepare_for_edit(SWMM_Engine engine)
Make the parsed 2D mesh editable without a full initialize().
Definition Api2D.cpp:59
SWMM_ENGINE_API int swmm_2d_set_triangle_mannings(SWMM_Engine engine, int idx, double n)
Set triangle Manning's roughness coefficient.
Definition Api2D.cpp:157
SWMM_ENGINE_API int swmm_2d_get_stat_max_velocities(SWMM_Engine engine, double *max_velocities)
Get per-triangle max velocity-magnitude statistics (cumulative, m/s).
Definition Api2D.cpp:642
SWMM_ENGINE_API int swmm_2d_set_vertex_coupled_node(SWMM_Engine engine, int vertex_idx, const char *node_name)
Set (or clear) the SWMM node a vertex is coupled to, by name.
Definition Api2D.cpp:293
SWMM_ENGINE_API int swmm_2d_get_dry_depth(SWMM_Engine engine, double *dry_depth)
Get the dry depth threshold (m).
Definition Api2D.cpp:810
SWMM_ENGINE_API int swmm_2d_get_edge_conveyance_bulk(SWMM_Engine engine, double *conveyance)
Bulk get conveyance factor at every edge of every triangle.
Definition Api2D.cpp:506
SWMM_ENGINE_API int swmm_2d_set_edge_bc_tseries_name(SWMM_Engine engine, int tri_idx, int edge, const char *name)
Set the timeseries NAME to drive a SPECIFIED_STAGE edge.
Definition Api2D.cpp:993
SWMM_ENGINE_API int swmm_2d_get_cvode_last_step(SWMM_Engine engine, double *h_last)
Get CVODE last internal step size.
Definition Api2D.cpp:622
SWMM_ENGINE_API int swmm_2d_force_clear_all(SWMM_Engine engine)
Clear all 2D forcings.
Definition Api2D.cpp:786
SWMM_ENGINE_API int swmm_2d_get_mass_balance(SWMM_Engine engine, double *init_storage, double *final_storage, double *rainfall_in, double *coupling_1d_to_2d_in, double *coupling_2d_to_1d_out, double *outfall_in, double *outfall_out, double *boundary_in, double *boundary_out, double *evap_out)
Get the global 2D mass-balance terms (all m3). Any pointer may be NULL.
Definition Api2D.cpp:676
SWMM_ENGINE_API int swmm_2d_vertex_count(SWMM_Engine engine, int *count)
Get the number of mesh vertices.
Definition Api2D.cpp:70
SWMM_ENGINE_API int swmm_2d_triangle_get_coupled_node(SWMM_Engine engine, int tri_idx, int *node_idx)
Get triangle coupling: which SWMM node is coupled to this triangle.
Definition Api2D.cpp:282
SWMM_ENGINE_API int swmm_2d_force_rainfall_uniform(SWMM_Engine engine, double value, int mode, int persist)
Force rainfall on all triangles (uniform).
Definition Api2D.cpp:722
SWMM_ENGINE_API int swmm_2d_vertex_get_xyz(SWMM_Engine engine, int idx, double *x, double *y, double *z)
Get vertex coordinates.
Definition Api2D.cpp:86
SWMM_ENGINE_API int swmm_2d_force_evap_uniform(SWMM_Engine engine, double value, int mode, int persist)
Force evaporation on all triangles (uniform).
Definition Api2D.cpp:754
SWMM_ENGINE_API int swmm_2d_get_edge_bc_slope(SWMM_Engine engine, int tri_idx, int edge, double *slope)
Get normal flow boundary slope for an edge.
Definition Api2D.cpp:953
SWMM_ENGINE_API int swmm_2d_get_abs_tolerance(SWMM_Engine engine, double *atol)
Get CVODE absolute tolerance.
Definition Api2D.cpp:846
SWMM_ENGINE_API int swmm_2d_triangle_get_vertices(SWMM_Engine engine, int idx, int *v0, int *v1, int *v2)
Get triangle connectivity (3 vertex indices).
Definition Api2D.cpp:123
SWMM_ENGINE_API int swmm_2d_get_heads_bulk(SWMM_Engine engine, double *heads)
Bulk get heads for all triangles.
Definition Api2D.cpp:422
SWMM_ENGINE_API int swmm_2d_set_dry_depth(SWMM_Engine engine, double dry_depth)
Set the dry depth threshold (m).
Definition Api2D.cpp:819
SWMM_ENGINE_API int swmm_2d_set_edge_conveyance(SWMM_Engine engine, int tri, int edge, double conveyance)
Set the per-edge conveyance factor for one edge.
Definition Api2D.cpp:486
SWMM_ENGINE_API int swmm_2d_get_vertex_coupling_cd(SWMM_Engine engine, int vertex_idx, double *cd)
Get the coupling discharge coefficient of a vertex ([2D_VERTEX_NODE_MAP] CD column; default 0....
Definition Api2D.cpp:314
SWMM_ENGINE_API int swmm_2d_vertex_coupling_count(SWMM_Engine engine, int *count)
Get the number of vertex-to-node coupling points.
Definition Api2D.cpp:243
SWMM_ENGINE_API int swmm_2d_triangle_get_mannings(SWMM_Engine engine, int idx, double *n)
Get triangle Manning's roughness.
Definition Api2D.cpp:217
SWMM_ENGINE_API int swmm_2d_get_edge_conveyance(SWMM_Engine engine, int tri, int edge, double *conveyance)
Get the per-edge conveyance factor for one edge.
Definition Api2D.cpp:473
SWMM_ENGINE_API int swmm_2d_force_coupling_flux(SWMM_Engine engine, int idx, double value, int mode, int persist)
Force coupling flux on a specific triangle (override computed exchange).
Definition Api2D.cpp:771
SWMM_ENGINE_API int swmm_2d_get_vertex_tag(SWMM_Engine engine, int idx, char *buf, int buflen)
Get the descriptive tag of a vertex (the [2D_VERTICES] TAG column). Copies up to buflen-1 bytes into ...
Definition Api2D.cpp:189
SWMM_ENGINE_API int swmm_2d_get_vertex_coupling_area(SWMM_Engine engine, int vertex_idx, double *area)
Get the coupling exchange area of a vertex ([2D_VERTEX_NODE_MAP] AREA column, m²; default 1....
Definition Api2D.cpp:336
SWMM_ENGINE_API int swmm_2d_is_active(SWMM_Engine engine, int *active)
Check whether the 2D module is active for this simulation.
Definition Api2D.cpp:52
SWMM_ENGINE_API int swmm_2d_set_vertex_coupling_area(SWMM_Engine engine, int vertex_idx, double area)
Set the coupling exchange area of a vertex ([2D_VERTEX_NODE_MAP] AREA column, m²)....
Definition Api2D.cpp:347
double * y
Definition odesolve.c:28
SWMM_ENGINE_API int swmm_2d_set_edge_bc_flow_tseries_name(SWMM_Engine engine, int tri_idx, int edge, const char *name)
Set the timeseries NAME to drive a SPECIFIED_FLOW edge. V-E4 — same resolution contract as swmm_2d_se...
Definition Api2D.cpp:1034
#define SWMM_ENGINE_API
Definition openswmm_2d.h:37
SWMM_ENGINE_API int swmm_2d_set_edge_bc_flow(SWMM_Engine engine, int tri_idx, int edge, double flow)
Set prescribed flow per metre of edge (m³/s/m). V-E4.
Definition Api2D.cpp:1023
SWMM_ENGINE_API int swmm_2d_set_edge_bc_rating_curve_name(SWMM_Engine engine, int tri_idx, int edge, const char *name)
Set the curve NAME to drive a RATING_CURVE edge.
Definition Api2D.cpp:1053
Callback function typedefs for the OpenSWMM Engine C API.
void * SWMM_Engine
Opaque handle to an OpenSWMM Engine instance.
Definition openswmm_callbacks.h:35