58#ifndef OPENSWMM_ENGINE_FV_SECTION_GEOMETRY_HPP
59#define OPENSWMM_ENGINE_FV_SECTION_GEOMETRY_HPP
68inline constexpr double kPi = 3.14159265358979323846;
87 double c = 1.0 -
y / r;
92 return 2.0 * std::acos(c);
109 return 0.5 * r * r * (th - std::sin(th));
123 const double s =
y * (2.0 * r -
y);
124 return (s > 0.0) ? 2.0 * std::sqrt(s) : 0.0;
140 return 2.0 *
kPi * r;
165double simpsonStep(F& f,
double a,
double b,
double fa,
double fm,
double fb,
double whole,
166 double eps,
int depth) {
167 const double m = 0.5 * (a + b);
168 const double lm = 0.5 * (a + m), rm = 0.5 * (m + b);
169 const double flm = f(lm), frm = f(rm);
170 const double left = (m - a) / 6.0 * (fa + 4.0 * flm + fm);
171 const double right = (b - m) / 6.0 * (fm + 4.0 * frm + fb);
172 const double delta = left + right - whole;
173 if (depth <= 0 || std::fabs(delta) <= 15.0 * eps)
174 return left + right + delta / 15.0;
175 return simpsonStep(f, a, m, fa, flm, fm, left, 0.5 * eps, depth - 1) +
176 simpsonStep(f, m, b, fm, frm, fb, right, 0.5 * eps, depth - 1);
192template <
class F>
double integrate(F f,
double a,
double b,
double eps = 1.0e-12,
int depth = 40) {
195 const double fa = f(a), fb = f(b), fm = f(0.5 * (a + b));
196 const double whole = (b - a) / 6.0 * (fa + 4.0 * fm + fb);
197 return simpsonStep(f, a, b, fa, fm, fb, whole, eps, depth);
214 double c = 1.0 -
y / by;
219 const double phi_max = std::acos(c);
220 auto ds = [&](
double phi) {
221 const double cx = ax * std::cos(phi), sy = by * std::sin(phi);
222 return std::sqrt(cx * cx + sy * sy);
224 return 2.0 *
integrate(ds, 0.0, phi_max, 1.0e-12 * (ax + by));
301 return xs.
s_bot * h * h;
303 return (4.0 / 3.0) * xs.
r_bot * h * std::sqrt(h);
305 return xs.
r_bot * std::pow(h, xs.
s_bot + 1.0);
340 return 2.0 * xs.
s_bot * h;
342 return 2.0 * xs.
r_bot * std::sqrt(h);
344 return (h > 0.0) ? (xs.
s_bot + 1.0) * xs.
r_bot * std::pow(h, xs.
s_bot) : 0.0;
379 double p = xs.
w_max + 2.0 * h;
390 return 2.0 * h * xs.
r_bot;
392 const double x = 2.0 * std::sqrt(h) / xs.
r_bot;
393 const double t = std::sqrt(1.0 + x * x);
394 return 0.5 * xs.
r_bot * xs.
r_bot * (x * t + std::log(x + t));
400 const double hc = (xs.
s_bot + 1.0) * xs.
r_bot / 2.0;
401 const double m = xs.
s_bot;
402 auto ds = [&](
double y) {
403 const double dxdy = (
y > 0.0) ? hc * m * std::pow(
y, m - 1.0) : 0.0;
404 return std::sqrt(1.0 + dxdy * dxdy);
406 const double y0 = 1.0e-9 * h;
408 (
detail::integrate(ds, y0, h, 1.0e-12 * h) + std::hypot(y0, hc * std::pow(y0, m)));
Cross-section geometry — unified batch + per-element API.
Definition SectionGeometry.hpp:75
double circTheta(double r, double y)
Evaluate the central angle of a circular water segment.
Definition SectionGeometry.hpp:86
double integrate(F f, double a, double b, double eps=1.0e-12, int depth=40)
Integrate a scalar function with adaptive Simpson quadrature.
Definition SectionGeometry.hpp:192
double circPerim(double r, double y)
Evaluate the exact submerged circular arc length.
Definition SectionGeometry.hpp:136
double ellipsePerim(double ax, double by, double y)
Integrate the submerged arc of a mathematical ellipse.
Definition SectionGeometry.hpp:211
double simpsonStep(F &f, double a, double b, double fa, double fm, double fb, double whole, double eps, int depth)
Recursively refine a cached Simpson panel to an absolute error target.
Definition SectionGeometry.hpp:165
double circWidth(double r, double y)
Evaluate the exact circular free-surface chord width.
Definition SectionGeometry.hpp:120
double circArea(double r, double y)
Evaluate the exact wetted area of a circular segment.
Definition SectionGeometry.hpp:103
Definition SectionGeometry.hpp:66
double widthOfDepth(const XSectParams &xs, double h)
Evaluate per-barrel top width including the invert boundary value.
Definition SectionGeometry.hpp:323
double hydRadOfDepth(const XSectParams &xs, double h)
Evaluate per-barrel hydraulic radius for the FV closure builder.
Definition SectionGeometry.hpp:429
double perimeterOfDepth(const XSectParams &xs, double h)
Evaluate per-barrel wetted perimeter for FV geometry sampling.
Definition SectionGeometry.hpp:363
constexpr double kPi
Definition SectionGeometry.hpp:68
bool hasClosedForm(int type)
Identify shapes with an analytic area/width and direct or quadrature perimeter here.
Definition SectionGeometry.hpp:236
double areaOfDepth(const XSectParams &xs, double h)
Evaluate per-barrel flow area for the FV closure builder.
Definition SectionGeometry.hpp:282
bool isPolynomialOpen(int type)
Identify open sections represented by quadratic area and linear perimeter.
Definition SectionGeometry.hpp:259
constexpr double kRectAlfMax
Definition SectionGeometry.hpp:73
double getWofY(const XSectParams &xs, double y)
Query native top width from depth through the shared host evaluator.
Definition XSection.cpp:253
double getRofY(const XSectParams &xs, double y)
Query native hydraulic radius from depth through the shared host evaluator.
Definition XSection.cpp:256
double getAofY(const XSectParams &xs, double y)
Query native wetted area from depth through the shared host evaluator.
Definition XSection.cpp:250
XSectShape
Definition XSectBatch.hpp:77
@ TRIANGULAR
Definition XSectBatch.hpp:84
@ RECT_CLOSED
Definition XSectBatch.hpp:81
@ POWERFUNC
Definition XSectBatch.hpp:86
@ FORCE_MAIN
Definition XSectBatch.hpp:102
@ RECT_OPEN
Definition XSectBatch.hpp:82
@ CIRCULAR
Definition XSectBatch.hpp:79
@ TRAPEZOIDAL
Definition XSectBatch.hpp:83
@ PARABOLIC
Definition XSectBatch.hpp:85
@ FILLED_CIRCULAR
Definition XSectBatch.hpp:80
double * y
Definition odesolve.c:37
Native cross-section geometry and borrowed optional normalized transect tables.
Definition XSectBatch.hpp:119
double s_bot
Slope of bottom section / exponent.
Definition XSectBatch.hpp:134
double a_full
Area when full (ft2)
Definition XSectBatch.hpp:127
double r_bot
Radius of bottom section / coefficient.
Definition XSectBatch.hpp:135
int type
Definition XSectBatch.hpp:120
double w_max
Width at widest point (ft)
Definition XSectBatch.hpp:125
double y_bot
Depth of bottom section / fill depth.
Definition XSectBatch.hpp:132
double y_full
Full depth (ft)
Definition XSectBatch.hpp:124