40#ifndef OPENSWMM_XSECT_LOOKUP_HPP
41#define OPENSWMM_XSECT_LOOKUP_HPP
54inline double lookup_exact(
double x,
const double* t,
int n)
noexcept {
55 const double delta = 1.0 /
static_cast<double>(n - 1);
56 int i =
static_cast<int>(x / delta);
57 if (i >= n - 1)
return t[n - 1];
59 double x0 = i * delta;
60 double y = t[i] + (x - x0) * (t[i + 1] - t[i]) / delta;
63 double x1 = (
static_cast<double>(i) + 1.0) * delta;
64 double y2 =
y + (x - x0) * (x - x1) / (delta * delta) *
65 (t[i] / 2.0 - t[i + 1] + t[i + 2] / 2.0);
90inline double lookup_fast(
double x,
const double* t,
int n)
noexcept {
91 const double inv_delta =
static_cast<double>(n - 1);
92 const double delta = 1.0 / inv_delta;
93 if (x < 0.0) x = 0.0;
else if (x > 1.0) x = 1.0;
94 int i =
static_cast<int>(x * inv_delta);
95 if (i >= n - 1)
return t[n - 1];
96 double x0 = i * delta;
97 double y = t[i] + (x - x0) * (t[i + 1] - t[i]) * inv_delta;
99 double x1 = (
static_cast<double>(i) + 1.0) * delta;
100 double y2 =
y + (x - x0) * (x - x1) * (inv_delta * inv_delta) *
101 (t[i] / 2.0 - t[i + 1] + t[i + 2] / 2.0);
102 if (y2 > 0.0)
y = y2;
104 if (
y < 0.0)
y = 0.0;
112inline double norm_x(
double depth,
double param)
noexcept {
113#ifdef SWMM_XSECT_FAST_LOOKUP
114 double x = depth * param;
115 if (x < 0.0) x = 0.0;
else if (x > 1.0) x = 1.0;
118 return (param > 0.0 && depth > 0.0) ? (depth / param) : 0.0;
123inline double norm_lookup(
double depth,
double param,
const double* t,
int n)
noexcept {
124#ifdef SWMM_XSECT_FAST_LOOKUP
Definition XSectBatch.hpp:126
double lookup_fast(double x, const double *t, int n) noexcept
Reciprocal-multiply lookup (fast, NOT bit-exact — see §6).
Definition XSectLookup.hpp:90
double norm_lookup(double depth, double param, const double *t, int n) noexcept
Mode-aware normalize + table lookup (bit-exact by default; §6 fast if opted in).
Definition XSectLookup.hpp:123
double lookup_exact(double x, const double *t, int n) noexcept
Bit-exact transliteration of legacy xsect.c:lookup().
Definition XSectLookup.hpp:54
double norm_x(double depth, double param) noexcept
Definition XSectLookup.hpp:112
double * y
Definition odesolve.c:28