Clamp an open-area fraction into [0,1], NaN-safely.
The bracket is unreachable in exact arithmetic — A is monotone
with slope in [0,1], so (A(hi)-A(lo))/(hi-lo) already lies in
[0,1] — but it is NOT unreachable in floating point: the
above-d_max branch evaluates A = eta - d_avg, and the
difference of two such values can exceed hi - lo by an ulp, so
the min is what makes a fully submerged sill give back EXACTLY
1. The explicit non-finite test is the repo’s clamp rule
(CLAUDE.md): under nvfortran’s relaxed FP an if/else clamp
lowers to a NaN-blind min/max select, which would launder a NaN
into a plausible 0 or 1 instead of a visibly blocked face.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | x |
pure function clamp_fraction(x) result(f) !! Clamp an open-area fraction into `[0,1]`, NaN-safely. !! !! The bracket is unreachable in exact arithmetic — `A` is monotone !! with slope in `[0,1]`, so `(A(hi)-A(lo))/(hi-lo)` already lies in !! `[0,1]` — but it is NOT unreachable in floating point: the !! above-`d_max` branch evaluates `A = eta - d_avg`, and the !! difference of two such values can exceed `hi - lo` by an ulp, so !! the `min` is what makes a fully submerged sill give back EXACTLY !! 1. The explicit non-finite test is the repo's clamp rule !! (CLAUDE.md): under nvfortran's relaxed FP an `if/else` clamp !! lowers to a NaN-blind min/max select, which would launder a NaN !! into a plausible 0 or 1 instead of a visibly blocked face. real(wp), intent(in) :: x real(wp) :: f if (.not. ieee_is_finite(x)) then f = 0.0_wp else f = max(0.0_wp, min(1.0_wp, x)) end if end function clamp_fraction