clamp_fraction Function

private 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.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: x

Return Value real(kind=wp)


Called by

proc~~clamp_fraction~~CalledByGraph proc~clamp_fraction clamp_fraction proc~porous_update_face_areas porous_update_face_areas proc~porous_update_face_areas->proc~clamp_fraction proc~ocean_porous_refresh ocean_porous_refresh proc~ocean_porous_refresh->proc~porous_update_face_areas proc~engine_step engine_step proc~engine_step->proc~ocean_porous_refresh proc~driver_run_ocean driver_run_ocean proc~driver_run_ocean->proc~engine_step proc~rdb_ocean_step rdb_ocean_step proc~rdb_ocean_step->proc~engine_step proc~driver_run driver_run proc~driver_run->proc~driver_run_ocean

Source Code

   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