OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
XSectBatch.hpp
Go to the documentation of this file.
1
34#ifndef OPENSWMM_XSECT_BATCH_HPP
35#define OPENSWMM_XSECT_BATCH_HPP
36
37#ifndef OPENSWMM_RESTRICT
38# if defined(_MSC_VER)
39# define OPENSWMM_RESTRICT __restrict
40# else
41# define OPENSWMM_RESTRICT __restrict__
42# endif
43#endif
44
45#include <vector>
46#include <cstddef>
47#include <cstdint>
48#include <cmath>
49
50namespace openswmm {
51
52// Forward declaration
53struct SimulationContext;
54
55// ============================================================================
56// Cross-section shape codes (matches legacy enums.h XsectType)
57// ============================================================================
58
59enum class XSectShape : int {
60 DUMMY = 0,
61 CIRCULAR = 1,
63 RECT_CLOSED = 3,
64 RECT_OPEN = 4,
65 TRAPEZOIDAL = 5,
66 TRIANGULAR = 6,
67 PARABOLIC = 7,
68 POWERFUNC = 8,
69 RECT_TRIANG = 9,
70 RECT_ROUND = 10,
71 MOD_BASKET = 11,
72 HORIZ_ELLIPSE = 12,
73 VERT_ELLIPSE = 13,
74 ARCH = 14,
75 EGGSHAPED = 15,
76 HORSESHOE = 16,
77 GOTHIC = 17,
78 CATENARY = 18,
79 SEMIELLIPTICAL = 19,
80 BASKETHANDLE = 20,
81 SEMICIRCULAR = 21,
82 IRREGULAR = 22,
83 CUSTOM = 23,
84 FORCE_MAIN = 24,
85 STREET_XSECT = 25
86};
87
88// ============================================================================
89// Cross-section parameter struct (mirrors legacy TXsect)
90// ============================================================================
91
93 int type = 0;
94 int culvert_code = 0;
95 int transect = -1;
96
97 double y_full = 0.0;
98 double w_max = 0.0;
99 double yw_max = 0.0;
100 double a_full = 0.0;
101 double r_full = 0.0;
102 double s_full = 0.0;
103 double s_max = 0.0;
104
105 double y_bot = 0.0;
106 double a_bot = 0.0;
107 double s_bot = 0.0;
108 double r_bot = 0.0;
109};
110
111// ============================================================================
112// Per-element functions (xsect:: namespace)
113// ============================================================================
114
115namespace xsect {
116
117double getAofY(const XSectParams& xs, double y);
118double getRofY(const XSectParams& xs, double y);
119double getWofY(const XSectParams& xs, double y);
120double getYofA(const XSectParams& xs, double a);
121double getSofA(const XSectParams& xs, double a);
122double getRofA(const XSectParams& xs, double a);
123double getdSdA(const XSectParams& xs, double a);
124double getAofS(const XSectParams& xs, double s_factor);
125double getAmax(const XSectParams& xs);
126double getYcrit(const XSectParams& xs, double q);
127bool isOpen(int type);
128int setParams(XSectParams& xs, int type, const double p[], double ucf);
129
130// Lookup table helpers (exposed for batch kernels and testing)
131double lookup(double x, const double* table, int n_items);
132double invLookup(double y, const double* table, int n_items);
133int locate(double y, const double* table, int n);
134double getYcircular(double alpha);
135double getScircular(double alpha);
136
137} // namespace xsect
138
139// ============================================================================
140// Shape group — contiguous SoA for all links sharing one shape type
141// ============================================================================
142
155 int count = 0;
156
157 // Mapping back to global link arrays
158 std::vector<int> link_idx;
159
160 // Geometry parameters (contiguous, aligned for SIMD)
161 std::vector<double> y_full;
162 std::vector<double> a_full;
163 std::vector<double> r_full;
164 std::vector<double> s_full;
165 std::vector<double> w_max;
166
167 // Multi-purpose parameters (meaning depends on shape)
168 std::vector<double> y_bot;
169 std::vector<double> a_bot;
170 std::vector<double> s_bot;
171 std::vector<double> r_bot;
172
174 void resize(int n);
175};
176
177// ============================================================================
178// XSectGroups — the shape-grouped index over all links
179// ============================================================================
180
194public:
204 void build(const SimulationContext& ctx);
205
214 void build(const XSectParams* params, int n_links);
215
216 // ========================================================================
217 // Batch compute — results scattered to global link arrays
218 // ========================================================================
219
227 void computeAreas(const double* depths, double* areas, int n_links) const;
228
236 void computeHydRad(const double* depths, double* hydrad, int n_links) const;
237
245 void computeWidths(const double* depths, double* widths, int n_links) const;
246
254 void computeSectionFactors(const double* areas, double* sfact, int n_links) const;
255
263 void computeDepthsFromArea(const double* areas, double* depths, int n_links) const;
264
265 // ========================================================================
266 // Accessors
267 // ========================================================================
268
270 int numGroups() const { return static_cast<int>(groups_.size()); }
271
273 const ShapeGroup& group(int i) const { return groups_[i]; }
274
276 const ShapeGroup* findGroup(XSectShape shape) const;
277
278private:
279 std::vector<ShapeGroup> groups_;
280};
281
282// ============================================================================
283// Shape-specific batch kernels (called by XSectGroups, also usable directly)
284// ============================================================================
285
286namespace xsect_batch {
287
295void area_circular(
296 const double* OPENSWMM_RESTRICT depth,
297 const double* OPENSWMM_RESTRICT y_full,
298 const double* OPENSWMM_RESTRICT a_full,
299 double* OPENSWMM_RESTRICT area,
300 int count
301);
302
304void area_rect(
305 const double* OPENSWMM_RESTRICT depth,
306 const double* OPENSWMM_RESTRICT w_max,
307 double* OPENSWMM_RESTRICT area,
308 int count
309);
310
313 const double* OPENSWMM_RESTRICT depth,
314 const double* OPENSWMM_RESTRICT y_bot,
315 const double* OPENSWMM_RESTRICT s_bot,
316 double* OPENSWMM_RESTRICT area,
317 int count
318);
319
321void area_triangular(
322 const double* OPENSWMM_RESTRICT depth,
323 const double* OPENSWMM_RESTRICT s_bot,
324 double* OPENSWMM_RESTRICT area,
325 int count
326);
327
329void area_parabolic(
330 const double* OPENSWMM_RESTRICT depth,
331 const double* OPENSWMM_RESTRICT r_bot,
332 double* OPENSWMM_RESTRICT area,
333 int count
334);
335
337void area_powerfunc(
338 const double* OPENSWMM_RESTRICT depth,
339 const double* OPENSWMM_RESTRICT s_bot,
340 const double* OPENSWMM_RESTRICT r_bot,
341 double* OPENSWMM_RESTRICT area,
342 int count
343);
344
346void area_tabulated(
347 const double* OPENSWMM_RESTRICT depth,
348 const double* OPENSWMM_RESTRICT y_full,
349 const double* OPENSWMM_RESTRICT a_full,
350 const double* table,
351 int table_size,
352 double* OPENSWMM_RESTRICT area,
353 int count
354);
355
358 const double* OPENSWMM_RESTRICT depth,
359 const double* OPENSWMM_RESTRICT y_full,
360 const double* OPENSWMM_RESTRICT a_full,
361 const double* table,
362 int table_size,
363 double* OPENSWMM_RESTRICT area,
364 int count
365);
366
367// --- Hydraulic radius batch kernels ---
368
369void hydrad_circular(
370 const double* OPENSWMM_RESTRICT depth,
371 const double* OPENSWMM_RESTRICT y_full,
372 const double* OPENSWMM_RESTRICT r_full,
373 double* OPENSWMM_RESTRICT hydrad,
374 int count
375);
376
378 const double* OPENSWMM_RESTRICT depth,
379 const double* OPENSWMM_RESTRICT y_bot,
380 const double* OPENSWMM_RESTRICT s_bot,
381 const double* OPENSWMM_RESTRICT r_bot,
382 double* OPENSWMM_RESTRICT hydrad,
383 int count
384);
385
387 const double* OPENSWMM_RESTRICT depth,
388 const double* OPENSWMM_RESTRICT s_bot,
389 const double* OPENSWMM_RESTRICT r_bot,
390 double* OPENSWMM_RESTRICT hydrad,
391 int count
392);
393
394void hydrad_rect(
395 const double* OPENSWMM_RESTRICT depth,
396 const double* OPENSWMM_RESTRICT w_max,
397 double* OPENSWMM_RESTRICT hydrad,
398 int count
399);
400
402 const double* OPENSWMM_RESTRICT depth,
403 const double* OPENSWMM_RESTRICT y_full,
404 const double* OPENSWMM_RESTRICT r_full,
405 const double* table,
406 int table_size,
407 double* OPENSWMM_RESTRICT hydrad,
408 int count
409);
410
411// --- Top width batch kernels ---
412
413void width_circular(
414 const double* OPENSWMM_RESTRICT depth,
415 const double* OPENSWMM_RESTRICT y_full,
416 const double* OPENSWMM_RESTRICT w_max,
417 double* OPENSWMM_RESTRICT width,
418 int count
419);
420
422 const double* OPENSWMM_RESTRICT depth,
423 const double* OPENSWMM_RESTRICT y_bot,
424 const double* OPENSWMM_RESTRICT s_bot,
425 double* OPENSWMM_RESTRICT width,
426 int count
427);
428
430 const double* OPENSWMM_RESTRICT depth,
431 const double* OPENSWMM_RESTRICT s_bot,
432 double* OPENSWMM_RESTRICT width,
433 int count
434);
435
436void width_rect(
437 const double* OPENSWMM_RESTRICT w_max,
438 double* OPENSWMM_RESTRICT width,
439 int count
440);
441
442void width_tabulated(
443 const double* OPENSWMM_RESTRICT depth,
444 const double* OPENSWMM_RESTRICT y_full,
445 const double* OPENSWMM_RESTRICT w_max,
446 const double* table,
447 int table_size,
448 double* OPENSWMM_RESTRICT width,
449 int count
450);
451
452} // namespace xsect_batch
453
454} // namespace openswmm
455
456#endif // OPENSWMM_XSECT_BATCH_HPP
#define OPENSWMM_RESTRICT
Definition XSectBatch.hpp:41
Shape-grouped cross-section manager for batch computation.
Definition XSectBatch.hpp:193
void computeAreas(const double *depths, double *areas, int n_links) const
Compute area for every link, reading depth from depths[link].
Definition XSectBatch.cpp:612
void computeWidths(const double *depths, double *widths, int n_links) const
Compute top width for every link.
Definition XSectBatch.cpp:760
void build(const SimulationContext &ctx)
Build shape groups from SimulationContext link data.
const ShapeGroup & group(int i) const
Access a specific shape group.
Definition XSectBatch.hpp:273
void computeDepthsFromArea(const double *areas, double *depths, int n_links) const
Compute depth from area for every link (inverse).
Definition XSectBatch.cpp:840
void computeHydRad(const double *depths, double *hydrad, int n_links) const
Compute hydraulic radius for every link.
Definition XSectBatch.cpp:695
void computeSectionFactors(const double *areas, double *sfact, int n_links) const
Compute section factor for every link (from area, not depth).
Definition XSectBatch.cpp:821
int numGroups() const
Number of non-empty shape groups.
Definition XSectBatch.hpp:270
const ShapeGroup * findGroup(XSectShape shape) const
Find the group for a given shape (returns nullptr if no links have that shape).
Definition XSectBatch.cpp:101
void area_trapezoidal(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT y_bot, const double *OPENSWMM_RESTRICT s_bot, double *OPENSWMM_RESTRICT area, int count)
Batch area for TRAPEZOIDAL: area = (y_bot + s_bot * depth) * depth.
Definition XSectBatch.cpp:165
void width_rect(const double *OPENSWMM_RESTRICT w_max, double *OPENSWMM_RESTRICT width, int count)
Definition XSectBatch.cpp:481
void hydrad_triangular(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT s_bot, const double *OPENSWMM_RESTRICT r_bot, double *OPENSWMM_RESTRICT hydrad, int count)
Definition XSectBatch.cpp:342
void hydrad_trapezoidal(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT y_bot, const double *OPENSWMM_RESTRICT s_bot, const double *OPENSWMM_RESTRICT r_bot, double *OPENSWMM_RESTRICT hydrad, int count)
Definition XSectBatch.cpp:321
void width_triangular(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT s_bot, double *OPENSWMM_RESTRICT width, int count)
Definition XSectBatch.cpp:466
void hydrad_rect(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT w_max, double *OPENSWMM_RESTRICT hydrad, int count)
Definition XSectBatch.cpp:358
void hydrad_circular(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT y_full, const double *OPENSWMM_RESTRICT r_full, double *OPENSWMM_RESTRICT hydrad, int count)
Definition XSectBatch.cpp:284
void hydrad_tabulated(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT y_full, const double *OPENSWMM_RESTRICT r_full, const double *table, int table_size, double *OPENSWMM_RESTRICT hydrad, int count)
Definition XSectBatch.cpp:375
void width_circular(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT y_full, const double *OPENSWMM_RESTRICT w_max, double *OPENSWMM_RESTRICT width, int count)
Definition XSectBatch.cpp:416
void area_inv_tabulated(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT y_full, const double *OPENSWMM_RESTRICT a_full, const double *table, int table_size, double *OPENSWMM_RESTRICT area, int count)
Batch area for shapes using invLookup (gothic, catenary, semielliptical, semicircular).
Definition XSectBatch.cpp:261
void area_powerfunc(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT s_bot, const double *OPENSWMM_RESTRICT r_bot, double *OPENSWMM_RESTRICT area, int count)
Batch area for POWERFUNC: area = r_bot * depth^(s_bot+1).
Definition XSectBatch.cpp:211
void area_circular(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT y_full, const double *OPENSWMM_RESTRICT a_full, double *OPENSWMM_RESTRICT area, int count)
Batch area for CIRCULAR/FORCE_MAIN — lookup table interpolation.
Definition XSectBatch.cpp:114
void area_rect(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT w_max, double *OPENSWMM_RESTRICT area, int count)
Batch area for RECT_CLOSED / RECT_OPEN: area = depth * w_max.
Definition XSectBatch.cpp:155
void width_trapezoidal(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT y_bot, const double *OPENSWMM_RESTRICT s_bot, double *OPENSWMM_RESTRICT width, int count)
Definition XSectBatch.cpp:450
void width_tabulated(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT y_full, const double *OPENSWMM_RESTRICT w_max, const double *table, int table_size, double *OPENSWMM_RESTRICT width, int count)
Definition XSectBatch.cpp:491
void area_tabulated(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT y_full, const double *OPENSWMM_RESTRICT a_full, const double *table, int table_size, double *OPENSWMM_RESTRICT area, int count)
Batch area for any tabulated shape (egg, horseshoe, arch, ellipse, etc.).
Definition XSectBatch.cpp:224
void area_triangular(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT s_bot, double *OPENSWMM_RESTRICT area, int count)
Batch area for TRIANGULAR: area = s_bot * depth^2.
Definition XSectBatch.cpp:182
void area_parabolic(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT r_bot, double *OPENSWMM_RESTRICT area, int count)
Batch area for PARABOLIC: area = (4/3) * r_bot * depth^(3/2).
Definition XSectBatch.cpp:198
double getAmax(const XSectParams &xs)
Definition XSection.cpp:796
double getdSdA(const XSectParams &xs, double a)
Definition XSection.cpp:760
double lookup(double x, const double *table, int n_items)
Definition XSection.cpp:42
double invLookup(double y, const double *table, int n_items)
Definition XSection.cpp:63
double getYofA(const XSectParams &xs, double a)
Definition XSection.cpp:639
double getScircular(double alpha)
Definition XSection.cpp:101
double getWofY(const XSectParams &xs, double y)
Definition XSection.cpp:517
double getSofA(const XSectParams &xs, double a)
Definition XSection.cpp:701
double getRofY(const XSectParams &xs, double y)
Definition XSection.cpp:583
double getYcrit(const XSectParams &xs, double q)
Definition XSection.cpp:806
int locate(double y, const double *table, int n)
Definition XSection.cpp:32
double getAofY(const XSectParams &xs, double y)
Definition XSection.cpp:455
double getAofS(const XSectParams &xs, double s_factor)
Definition XSection.cpp:773
bool isOpen(int type)
Definition XSection.cpp:903
int setParams(XSectParams &xs, int type, const double p[], double ucf)
Definition XSection.cpp:921
double getRofA(const XSectParams &xs, double a)
Definition XSection.cpp:750
double getYcircular(double alpha)
Definition XSection.cpp:95
Definition Controls.cpp:24
XSectShape
Definition XSectBatch.hpp:59
@ FORCE_MAIN
Circular force main (Hazen-Williams or D-W)
@ STREET_XSECT
Street cross-section.
@ IRREGULAR
User-supplied shape curve.
@ CUSTOM
Shape from CURVE_SHAPE table.
@ RECT_ROUND
Rectangular-round bottom.
@ DUMMY
Dummy (no geometry)
@ RECT_TRIANG
Rectangular-triangular bottom.
double * y
Definition odesolve.c:28
SoA parameter block for all links of one cross-section shape.
Definition XSectBatch.hpp:153
std::vector< double > r_full
Hyd. radius at full (ft)
Definition XSectBatch.hpp:163
std::vector< double > w_max
Max width (ft)
Definition XSectBatch.hpp:165
XSectShape shape
Definition XSectBatch.hpp:154
std::vector< double > r_bot
Definition XSectBatch.hpp:171
std::vector< double > s_bot
Definition XSectBatch.hpp:170
std::vector< double > y_bot
Definition XSectBatch.hpp:168
void resize(int n)
Resize all arrays to n elements.
Definition XSectBatch.cpp:35
std::vector< int > link_idx
link_idx[i] = index in SimulationContext
Definition XSectBatch.hpp:158
int count
Definition XSectBatch.hpp:155
std::vector< double > a_bot
Definition XSectBatch.hpp:169
std::vector< double > a_full
Full area (ft2)
Definition XSectBatch.hpp:162
std::vector< double > s_full
Section factor at full.
Definition XSectBatch.hpp:164
std::vector< double > y_full
Full depth (ft)
Definition XSectBatch.hpp:161
Central, reentrant simulation context.
Definition SimulationContext.hpp:141
Definition XSectBatch.hpp:92
double s_full
Section factor when full (ft^4/3)
Definition XSectBatch.hpp:102
double s_bot
Slope of bottom section / exponent.
Definition XSectBatch.hpp:107
int culvert_code
Definition XSectBatch.hpp:94
int transect
Definition XSectBatch.hpp:95
double a_full
Area when full (ft2)
Definition XSectBatch.hpp:100
double r_bot
Radius of bottom section / coefficient.
Definition XSectBatch.hpp:108
double s_max
Section factor at max flow (ft^4/3)
Definition XSectBatch.hpp:103
int type
Definition XSectBatch.hpp:93
double a_bot
Area of bottom section.
Definition XSectBatch.hpp:106
double w_max
Width at widest point (ft)
Definition XSectBatch.hpp:98
double yw_max
Depth at widest point (ft)
Definition XSectBatch.hpp:99
double y_bot
Depth of bottom section / fill depth.
Definition XSectBatch.hpp:105
double y_full
Full depth (ft)
Definition XSectBatch.hpp:97
double r_full
Hydraulic radius when full (ft)
Definition XSectBatch.hpp:101