56#ifndef OPENSWMM_XSECT_LOOKUP_HPP
57#define OPENSWMM_XSECT_LOOKUP_HPP
76inline double lookup_exact(
double x,
const double* t,
int n)
noexcept {
77 const double delta = 1.0 /
static_cast<double>(n - 1);
78 int i =
static_cast<int>(x / delta);
82 double x0 = i * delta;
83 double y = t[i] + (x - x0) * (t[i + 1] - t[i]) / delta;
86 double x1 = (
static_cast<double>(i) + 1.0) * delta;
88 y + (x - x0) * (x - x1) / (delta * delta) * (t[i] / 2.0 - t[i + 1] + t[i + 2] / 2.0);
126inline double lookup_fast(
double x,
const double* t,
int n)
noexcept {
127 const double inv_delta =
static_cast<double>(n - 1);
128 const double delta = 1.0 / inv_delta;
133 int i =
static_cast<int>(x * inv_delta);
136 double x0 = i * delta;
137 double y = t[i] + (x - x0) * (t[i + 1] - t[i]) * inv_delta;
139 double x1 = (
static_cast<double>(i) + 1.0) * delta;
140 double y2 =
y + (x - x0) * (x - x1) * (inv_delta * inv_delta) *
141 (t[i] / 2.0 - t[i + 1] + t[i + 2] / 2.0);
166inline double norm_x(
double depth,
double param)
noexcept {
167#ifdef SWMM_XSECT_FAST_LOOKUP
168 double x = depth * param;
175 return (param > 0.0 && depth > 0.0) ? (depth / param) : 0.0;
189inline double norm_lookup(
double depth,
double param,
const double* t,
int n)
noexcept {
190#ifdef SWMM_XSECT_FAST_LOOKUP
253 int b =
static_cast<int>((
y - L.t0) * L.scale);
279 if (
y >= table[jLast])
281 while (j2 - j1 > 1) {
282 int j = (j1 + j2) >> 1;
305 if (!table || jLast < 2 || jLast > 254)
307 for (
int j = 1; j <= jLast; ++j)
308 if (!(table[j] >= table[j - 1]))
311 const double span = table[jLast] - table[0];
320 for (
int j = 0; j <= jLast; ++j) {
325 L.lo[b] =
static_cast<unsigned char>(best);
348 if (
y >= table[jLast])
353 int j2 = L.lo[b + 1] + 1;
356 while (j2 - j1 > 1) {
357 int jm = (j1 + j2) >> 1;
379 if (L && L->scale > 0.0 && L->j_last == jLast)
396 if (!table || n_items < 4) {
401 if (table[n - 3] > table[n - 1])
Definition XSectBatch.hpp:158
double lookup_fast(double x, const double *t, int n) noexcept
Interpolate normalized geometry using reciprocal multiplication and endpoint clamps.
Definition XSectLookup.hpp:126
double norm_lookup(double depth, double param, const double *t, int n) noexcept
Normalize a depth and dispatch the build-selected table interpolation.
Definition XSectLookup.hpp:189
double lookup_exact(double x, const double *t, int n) noexcept
Interpolate a normalized geometry table with the legacy arithmetic grouping.
Definition XSectLookup.hpp:76
int 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.
Definition XSectLookup.hpp:378
void build_locate_lut(LocateLut &L, const double *table, int jLast) noexcept
Build a byte-indexed acceleration map for a monotone geometry table.
Definition XSectLookup.hpp:303
void 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.
Definition XSectLookup.hpp:395
int locate_bisect(double y, const double *table, int jLast) noexcept
Find a lower bracketing index in a nondecreasing table.
Definition XSectLookup.hpp:274
int lut_bucket(const LocateLut &L, double y) noexcept
Map a value to one of64 locate-acceleration buckets.
Definition XSectLookup.hpp:252
double norm_x(double depth, double param) noexcept
Normalize a depth with the selected exact or fast-lookup operand convention.
Definition XSectLookup.hpp:166
int locate_lut(double y, const double *table, int jLast, const LocateLut &L) noexcept
Find the same lower bracket using a prebuilt bucket map.
Definition XSectLookup.hpp:343
double * y
Definition odesolve.c:37
Definition XSectLookup.hpp:232
int j_last
the jLast this map was built for
Definition XSectLookup.hpp:237
unsigned char lo[kBuckets+1]
lo[b] = max{ j : bucket(table[j]) < b }
Definition XSectLookup.hpp:238
double scale
kBuckets / (table[jLast] - t0); 0 == disabled
Definition XSectLookup.hpp:236
double t0
table[0] — the low end of the value range
Definition XSectLookup.hpp:235
static constexpr int kBuckets
Definition XSectLookup.hpp:233