OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
XSectLookup.hpp File Reference

Bit-exact geometry-table interpolation — the single source of truth. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  openswmm::xsect::LocateLut
 

Namespaces

namespace  openswmm
 
namespace  openswmm::xsect
 

Functions

double openswmm::xsect::lookup_exact (double x, const double *t, int n) noexcept
 Interpolate a normalized geometry table with the legacy arithmetic grouping.
 
double openswmm::xsect::lookup_fast (double x, const double *t, int n) noexcept
 Interpolate normalized geometry using reciprocal multiplication and endpoint clamps.
 
double openswmm::xsect::norm_x (double depth, double param) noexcept
 Normalize a depth with the selected exact or fast-lookup operand convention.
 
double openswmm::xsect::norm_lookup (double depth, double param, const double *t, int n) noexcept
 Normalize a depth and dispatch the build-selected table interpolation.
 
int openswmm::xsect::lut_bucket (const LocateLut &L, double y) noexcept
 Map a value to one of64 locate-acceleration buckets.
 
int openswmm::xsect::locate_bisect (double y, const double *table, int jLast) noexcept
 Find a lower bracketing index in a nondecreasing table.
 
void openswmm::xsect::build_locate_lut (LocateLut &L, const double *table, int jLast) noexcept
 Build a byte-indexed acceleration map for a monotone geometry table.
 
int openswmm::xsect::locate_lut (double y, const double *table, int jLast, const LocateLut &L) noexcept
 Find the same lower bracket using a prebuilt bucket map.
 
int openswmm::xsect::locate_maybe_lut (double y, const double *table, int jLast, const LocateLut *L) noexcept
 Use a matching enabled bucket map or fall back to plain bisection.
 
void openswmm::xsect::build_invlookup_lut (LocateLut &L, const double *table, int n_items) noexcept
 Build a map for the actual truncated extent used by inverse geometry lookup.
 

Detailed Description

Bit-exact geometry-table interpolation — the single source of truth.

lookup_exact() is an op-for-op transliteration of legacy src/legacy/engine/xsect.c:lookup(). It is shared by BOTH the per-element accessor (xsect::lookup) and the batch geometry kernels (XSectBatch.cpp) so the two paths can never drift. The circular / force-main hot path and every shared-table shape (egg, horseshoe, arch, ellipse, baskethandle, …) interpolate through this one routine.

Bit-exactness contract (see docs/plans/xsect_bitexact_vectorization.md):

  • Use IEEE division (x / delta), never a precomputed reciprocal (x * inv_delta): a*(1/b) != a/b in double.
  • Keep legacy's exact operation grouping.
  • Never emit a fused multiply-add (FMA fuses mul+add and silently diverges NEON from x86). The global -ffp-contract=off / /fp:precise presets stop the compiler from contracting; do not reintroduce std::fma/intrinsic FMA in callers. IEEE division is correctly rounded and identical on every platform, so this routine is bit-identical on Windows/MSVC, Linux, and macOS(arm64/x86).

Preconditions (mirror legacy, whose callers guarantee them): x must be finite and in [0, 1] on entry (values > 1 are tolerated via the i >= n-1 early-out, matching legacy). static_cast<int> of a non-finite double is undefined behavior, so callers that can produce non-finite / negative x — e.g. a conduit normalized by a zero full-depth — MUST guard before calling (see xsect::lookup and the batch kernels).

Note
INTERNAL HEADER — not installed.
Author
Caleb Buahin caleb.nosp@m..bua.nosp@m.hin@g.nosp@m.mail.nosp@m..com
License
Apache-2.0