50#ifndef OPENSWMM_XSECT_BATCH_HPP
51#define OPENSWMM_XSECT_BATCH_HPP
53#ifndef OPENSWMM_RESTRICT
55#define OPENSWMM_RESTRICT __restrict
57#define OPENSWMM_RESTRICT __restrict__
71struct SimulationContext;
332double lookup(
double x,
const double* table,
int n_items);
342double invLookup(
double y,
const double* table,
int n_items,
const LocateLut* lut =
nullptr);
351int locate(
double y,
const double* table,
int n);
504 void computeAreas(
const double* depths,
double* areas,
int n_links)
const;
517 void computeHydRad(
const double* depths,
double* hydrad,
int n_links)
const;
530 void computeWidths(
const double* depths,
double* widths,
int n_links)
const;
571 double* a2,
double* am,
double* hrad1,
double* hrad_mid,
591 double* w2,
double* wm,
int n_links)
const;
621 double* a1,
double* a2,
double* am,
double* hrad1,
622 double* hrad_mid,
int n_links,
int tid,
int nthreads)
const;
645 double* w2,
double* wm,
int n_links,
int tid,
int nthreads)
const;
673 void setBypassMask(
const std::uint8_t* bypassed_by_link)
const;
707 int numGroups()
const {
return static_cast<int>(groups_.size()); }
727 std::vector<ShapeGroup> groups_;
736 static constexpr int kMaskFullGroup = -1;
737 mutable std::vector<ShapeGroup> packed_groups_;
738 mutable std::vector<int> packed_count_;
739 mutable bool mask_active_ =
false;
751 const ShapeGroup* maskedGroup(std::size_t gi)
const {
754 const int na = packed_count_[gi];
757 if (na != kMaskFullGroup)
758 gp = &packed_groups_[gi];
964 const double*
const* tables_b,
int table_size,
#define OPENSWMM_RESTRICT
Definition KernelPointers.hpp:9
Bit-exact geometry-table interpolation — the single source of truth.
Shape-grouped cross-section manager for batch computation.
Definition XSectBatch.hpp:447
void computeAreas(const double *depths, double *areas, int n_links) const
Compute grouped-link area ft2 in native units.
Definition XSectBatch.cpp:1372
void computeWidths(const double *depths, double *widths, int n_links) const
Compute grouped-link width ft in native units.
Definition XSectBatch.cpp:1427
void setBypassMask(const std::uint8_t *bypassed_by_link) const
Restrict the triple kernels to non-bypassed links for the current Picard iteration.
Definition XSectBatch.cpp:1528
void computeAreaHydRadTripleTeam(const double *d1, const double *d2, const double *dm, double *a1, double *a2, double *am, double *hrad1, double *hrad_mid, int n_links, int tid, int nthreads) const
Compute area/radius for three depth fields on one caller-owned team slice.
Definition XSectBatch.cpp:1474
void computeAreaAndHydRad(const double *depths, double *areas, double *hydrad, int n_links) const
Compute grouped-link area ft2,radius ft in native units.
Definition XSectBatch.cpp:1404
void build(const SimulationContext &ctx)
Declare the context convenience overload for shape-group construction.
void computeAreaHydRadTriple(const double *d1, const double *d2, const double *dm, double *a1, double *a2, double *am, double *hrad1, double *hrad_mid, int n_links) const
Compute area/radius for three depth fields using one grouped pass.
Definition XSectBatch.cpp:1515
void computeWidthsTriple(const double *d1, const double *d2, const double *dm, double *w1, double *w2, double *wm, int n_links) const
Compute width for three depth fields using one grouped pass.
Definition XSectBatch.cpp:1642
const ShapeGroup & group(int i) const
Borrow one indexed shape group.
Definition XSectBatch.hpp:716
void computeWidthsTripleTeam(const double *d1, const double *d2, const double *dm, double *w1, double *w2, double *wm, int n_links, int tid, int nthreads) const
Compute width for three depth fields on one caller-owned team slice.
Definition XSectBatch.cpp:1608
void computeDepthsFromArea(const double *areas, double *depths, int n_links) const
Compute grouped-link depth ft in native units.
Definition XSectBatch.cpp:1664
void computeHydRad(const double *depths, double *hydrad, int n_links) const
Compute grouped-link radius ft in native units.
Definition XSectBatch.cpp:1388
void computeSectionFactors(const double *areas, double *sfact, int n_links) const
Compute grouped-link native section factor in native units.
Definition XSectBatch.cpp:1652
void attachTransectTables(const SimulationContext &ctx)
Attach borrowed profile tables to irregular, custom and street shape groups.
Definition XSectBatch.cpp:222
int numGroups() const
Number of non-empty shape groups.
Definition XSectBatch.hpp:707
const ShapeGroup * findGroup(XSectShape shape) const
Borrow the first group with the requested kernel shape.
Definition XSectBatch.cpp:273
Definition UnitConversion.cpp:31
Definition XSectBatch.cpp:285
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)
Evaluate trapezoid batch area through the shared analytic leaf.
Definition XSectBatch.cpp:318
void width_rect(const double *OPENSWMM_RESTRICT w_max, double *OPENSWMM_RESTRICT width, int count)
Copy constant rectangular widths to the batch output.
Definition XSectBatch.cpp:753
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)
Evaluate triangular batch hydraulic radius through the shared leaf.
Definition XSectBatch.cpp:606
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)
Evaluate trapezoid batch hydraulic radius through the shared leaf.
Definition XSectBatch.cpp:596
void width_triangular(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT s_bot, double *OPENSWMM_RESTRICT width, int count)
Evaluate triangular batch top widths through the shared leaf.
Definition XSectBatch.cpp:746
void hydrad_rect(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT w_max, double *OPENSWMM_RESTRICT hydrad, int count)
Evaluate the simple two-bank rectangular batch radius formula.
Definition XSectBatch.cpp:614
void hydrad_circular(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT nrm, const double *OPENSWMM_RESTRICT r_full, double *OPENSWMM_RESTRICT hydrad, int count)
Evaluate circular/force-main batch hydraulic radii from the built-in table.
Definition XSectBatch.cpp:482
void hydrad_tabulated(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT nrm, const double *OPENSWMM_RESTRICT r_full, const double *table, int table_size, double *OPENSWMM_RESTRICT hydrad, int count)
Scale one shared normalized hydraulic-radius table for a batch.
Definition XSectBatch.cpp:713
void width_circular(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT nrm, const double *OPENSWMM_RESTRICT w_max, double *OPENSWMM_RESTRICT width, int count)
Evaluate circular batch top widths from the built-in width table.
Definition XSectBatch.cpp:726
void area_inv_tabulated(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT nrm, const double *OPENSWMM_RESTRICT a_full, const double *table, int table_size, const xsect::LocateLut *lut, double *OPENSWMM_RESTRICT area, int count)
Invert one shared normalized depth-versus-area table for batch areas.
Definition XSectBatch.cpp:357
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)
Evaluate power-function batch area through the shared analytic leaf.
Definition XSectBatch.cpp:340
void area_circular(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT nrm, const double *OPENSWMM_RESTRICT a_full, double *OPENSWMM_RESTRICT area, int count)
Evaluate circular/force-main normalized area for a contiguous batch.
Definition XSectBatch.cpp:296
void area_rect(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT w_max, double *OPENSWMM_RESTRICT area, int count)
Multiply rectangular depths and widths using the shared SIMD routine.
Definition XSectBatch.cpp:309
void perlink_tabulated(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT nrm, const double *OPENSWMM_RESTRICT scale, const double *const *tables, int table_size, double *OPENSWMM_RESTRICT result, int count)
Per-link tabulated lookup (for IRREGULAR shapes where each link has its own table).
Definition XSectBatch.cpp:463
void perlink_tabulated_pair(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT nrm, const double *OPENSWMM_RESTRICT scale_a, const double *OPENSWMM_RESTRICT scale_b, const double *const *tables_a, const double *const *tables_b, int table_size, double *OPENSWMM_RESTRICT out_a, double *OPENSWMM_RESTRICT out_b, int count)
Fuse two per-element profile lookups on one normalized depth grid.
Definition XSectBatch.cpp:386
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)
Evaluate trapezoid batch top widths through the shared leaf.
Definition XSectBatch.cpp:738
void width_tabulated(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT nrm, const double *OPENSWMM_RESTRICT w_max, const double *table, int table_size, double *OPENSWMM_RESTRICT width, int count)
Scale one shared normalized width table for a batch.
Definition XSectBatch.cpp:759
void area_tabulated(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT nrm, const double *OPENSWMM_RESTRICT a_full, const double *table, int table_size, double *OPENSWMM_RESTRICT area, int count)
Scale one shared normalized area table for a batch.
Definition XSectBatch.cpp:347
void area_hydrad_circular(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT nrm, const double *OPENSWMM_RESTRICT a_full, const double *OPENSWMM_RESTRICT r_full, double *OPENSWMM_RESTRICT area, double *OPENSWMM_RESTRICT hydrad, int count)
Fuse circular batch area and hydraulic-radius table interpolation.
Definition XSectBatch.cpp:499
void area_triangular(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT s_bot, double *OPENSWMM_RESTRICT area, int count)
Evaluate triangular batch area through the shared analytic leaf.
Definition XSectBatch.cpp:326
void area_parabolic(const double *OPENSWMM_RESTRICT depth, const double *OPENSWMM_RESTRICT r_bot, double *OPENSWMM_RESTRICT area, int count)
Evaluate parabolic batch area through the shared analytic leaf.
Definition XSectBatch.cpp:333
Definition XSectBatch.hpp:158
double getAmax(const XSectParams &xs)
Read the built-in area-at-maximum-conveyance ratio.
Definition XSection.cpp:274
double getdSdA(const XSectParams &xs, double a)
Query native section-factor derivative with respect to area through the shared host evaluator.
Definition XSection.cpp:268
double lookup(double x, const double *table, int n_items)
Interpolate a borrowed equally spaced normalized geometry table.
Definition XSection.cpp:237
double getYofA(const XSectParams &xs, double a)
Query native depth from area through the shared host evaluator.
Definition XSection.cpp:259
double getScircular(double alpha)
Compute normalized circular section factor from area ratio.
Definition XSection.cpp:246
double invLookup(double y, const double *table, int n_items, const LocateLut *lut=nullptr)
Invert a borrowed normalized geometry table including the legacy declining top.
Definition XSection.cpp:240
double getWofY(const XSectParams &xs, double y)
Query native top width from depth through the shared host evaluator.
Definition XSection.cpp:253
double getSofA(const XSectParams &xs, double a)
Query native section factor from area through the shared host evaluator.
Definition XSection.cpp:262
double getRofY(const XSectParams &xs, double y)
Query native hydraulic radius from depth through the shared host evaluator.
Definition XSection.cpp:256
double getYcrit(const XSectParams &xs, double q)
Query native critical depth from discharge through the shared host evaluator.
Definition XSection.cpp:277
int locate(double y, const double *table, int n)
Find a lower bracket in a nondecreasing geometry table.
Definition XSection.cpp:234
double getAofY(const XSectParams &xs, double y)
Query native wetted area from depth through the shared host evaluator.
Definition XSection.cpp:250
double getAofS(const XSectParams &xs, double s_factor)
Query native area from section factor through the shared host evaluator.
Definition XSection.cpp:271
bool isOpen(int type)
Classify a kernel shape using the legacy open-section set.
Definition XSection.cpp:280
int setParams(XSectParams &xs, int type, const double p[], double ucf)
Derive native full-flow geometry from authored shape dimensions.
Definition XSection.cpp:295
double getRofA(const XSectParams &xs, double a)
Query native hydraulic radius from area through the shared host evaluator.
Definition XSection.cpp:265
double getYcircular(double alpha)
Compute normalized circular depth from area ratio.
Definition XSection.cpp:243
Definition ExchangeLaw.hpp:60
XSectShape
Definition XSectBatch.hpp:77
@ POWERFUNC
Definition XSectBatch.hpp:86
@ MOD_BASKET
Definition XSectBatch.hpp:89
@ DUMMY
Definition XSectBatch.hpp:78
@ TRIANGULAR
Definition LinkData.hpp:70
@ RECT_CLOSED
Definition LinkData.hpp:67
@ ARCH
Arch pipe.
Definition LinkData.hpp:85
@ FORCE_MAIN
Circular force main (Hazen-Williams or D-W)
Definition LinkData.hpp:88
@ RECT_OPEN
Definition LinkData.hpp:68
@ BASKETHANDLE
Definition LinkData.hpp:79
@ STREET_XSECT
Street cross-section.
Definition LinkData.hpp:89
@ SEMICIRCULAR
Definition LinkData.hpp:80
@ IRREGULAR
User-supplied shape curve.
Definition LinkData.hpp:86
@ HORIZ_ELLIPSE
Horizontal elliptical pipe.
Definition LinkData.hpp:83
@ VERT_ELLIPSE
Vertical elliptical pipe.
Definition LinkData.hpp:84
@ CUSTOM
Shape from CURVE_SHAPE table.
Definition LinkData.hpp:87
@ RECT_ROUND
Rectangular-round bottom.
Definition LinkData.hpp:82
@ EGGSHAPED
Definition LinkData.hpp:74
@ SEMIELLIPTICAL
Definition LinkData.hpp:78
@ CATENARY
Definition LinkData.hpp:77
@ CIRCULAR
Definition LinkData.hpp:65
@ TRAPEZOIDAL
Definition LinkData.hpp:69
@ HORSESHOE
Definition LinkData.hpp:75
@ DUMMY
Dummy (no geometry)
Definition LinkData.hpp:90
@ PARABOLIC
Definition LinkData.hpp:71
@ RECT_TRIANG
Rectangular-triangular bottom.
Definition LinkData.hpp:81
@ FILLED_CIRCULAR
Definition LinkData.hpp:66
@ GOTHIC
Definition LinkData.hpp:76
double * y
Definition odesolve.c:37
SoA parameter block for all links of one cross-section shape.
Definition XSectBatch.hpp:384
std::vector< double > r_full
Hyd. radius at full (ft)
Definition XSectBatch.hpp:394
std::vector< const double * > hrad_tables
Per-link hyd-rad table.
Definition XSectBatch.hpp:410
std::vector< double > w_max
Max width (ft)
Definition XSectBatch.hpp:396
std::vector< double > buf_r
Scatter buffer for results.
Definition XSectBatch.hpp:416
std::vector< double > buf_r2
Second scatter buffer (for fused ops)
Definition XSectBatch.hpp:417
std::vector< double > inv_y_full
1.0 / y_full (or 0 if y_full==0)
Definition XSectBatch.hpp:399
XSectShape shape
Definition XSectBatch.hpp:385
int transect_tbl_size
Table size (same for all)
Definition XSectBatch.hpp:412
std::vector< double > r_bot
Definition XSectBatch.hpp:405
std::vector< double > s_bot
Definition XSectBatch.hpp:404
std::vector< double > y_bot
Definition XSectBatch.hpp:402
void resize(int n)
Resize primary shape-group geometry and numerical work arrays.
Definition XSectBatch.cpp:76
std::vector< const double * > area_tables
Per-link area table.
Definition XSectBatch.hpp:409
std::vector< const double * > width_tables
Per-link width table.
Definition XSectBatch.hpp:411
std::vector< int > link_idx
link_idx[i] = index in SimulationContext
Definition XSectBatch.hpp:389
std::vector< double > buf_d
Gather buffer for depths.
Definition XSectBatch.hpp:415
int count
Definition XSectBatch.hpp:386
std::vector< double > a_bot
Definition XSectBatch.hpp:403
std::vector< double > a_full
Full area (ft2)
Definition XSectBatch.hpp:393
std::vector< double > s_full
Section factor at full.
Definition XSectBatch.hpp:395
std::vector< double > y_full
Full depth (ft)
Definition XSectBatch.hpp:392
Central, reentrant simulation context.
Definition SimulationContext.hpp:390
Native cross-section geometry and borrowed optional normalized transect tables.
Definition XSectBatch.hpp:119
double s_full
Section factor when full (normally ft^(8/3); FORCE_MAIN uses R^0.63)
Definition XSectBatch.hpp:129
double s_bot
Slope of bottom section / exponent.
Definition XSectBatch.hpp:134
int culvert_code
Definition XSectBatch.hpp:121
const double * hrad_tbl
Normalized hyd-radius vs y/y_full.
Definition XSectBatch.hpp:144
int transect
Definition XSectBatch.hpp:122
int transect_tbl_size
Entry count of the tables above.
Definition XSectBatch.hpp:146
const double * width_tbl
Normalized width vs y/y_full.
Definition XSectBatch.hpp:145
double a_full
Area when full (ft2)
Definition XSectBatch.hpp:127
double r_bot
Radius of bottom section / coefficient.
Definition XSectBatch.hpp:135
double s_max
Section factor at max flow (same convention as s_full)
Definition XSectBatch.hpp:130
int type
Definition XSectBatch.hpp:120
double a_bot
Area of bottom section.
Definition XSectBatch.hpp:133
const xsect::LocateLut * area_lut
Definition XSectBatch.hpp:151
double w_max
Width at widest point (ft)
Definition XSectBatch.hpp:125
double yw_max
Depth at widest point (ft)
Definition XSectBatch.hpp:126
double y_bot
Depth of bottom section / fill depth.
Definition XSectBatch.hpp:132
double y_full
Full depth (ft)
Definition XSectBatch.hpp:124
double r_full
Hydraulic radius when full (ft)
Definition XSectBatch.hpp:128
const double * area_tbl
Normalized area vs y/y_full.
Definition XSectBatch.hpp:143
Definition XSectLookup.hpp:232