Fail-loud TRIPWIRE for invariant I1′ — h_layer <= H_VANISHED ⇒
hTr = h_layer·c_live (the donor live layer’s concentration; hTr = 0
in a column with no live layer) for every registered tracer. Gated on
&vcoord_nml check_vanished_content (default .false.), which is
the knob the stability suite turns on for the cases that actually
have vanishing layers.
Pure scan + impure die, the check_h_positive_or_die pattern: the
scan (ms%scan_vanished_content) is a pure device reduction
returning two scalars, so the HEALTHY path costs two reductions per
tracer and no H←D copy; only a violation reaches the logger.
Runs immediately AFTER enforce_vanished_content, so a hit means the
enforcement point itself failed to establish the invariant — a bug in
the rule or an unmapped array on the device, not a stray kernel. That
is precisely what the tripwire is for: it guards the structural
guarantee rather than re-stating it.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(hgrid_t), | intent(in) | :: | grid | |||
| type(ocean_vcoord_t), | intent(in), | optional | :: | vcoord | ||
| type(multilayer_state_t), | intent(in) | :: | ms | |||
| integer, | intent(in) | :: | outer_step |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| character(len=320), | private | :: | msg | ||||
| integer, | private | :: | n_bad | ||||
| real(kind=wp), | private | :: | worst |
subroutine check_vanished_invariant_or_die(grid, vcoord, ms, outer_step) !! Fail-loud TRIPWIRE for invariant I1′ — `h_layer <= H_VANISHED ⇒ !! hTr = h_layer·c_live` (the donor live layer's concentration; `hTr = 0` !! in a column with no live layer) for every registered tracer. Gated on !! `&vcoord_nml check_vanished_content` (default `.false.`), which is !! the knob the stability suite turns on for the cases that actually !! have vanishing layers. !! !! Pure scan + impure die, the `check_h_positive_or_die` pattern: the !! scan (`ms%scan_vanished_content`) is a `pure` device reduction !! returning two scalars, so the HEALTHY path costs two reductions per !! tracer and no H←D copy; only a violation reaches the logger. !! !! Runs immediately AFTER `enforce_vanished_content`, so a hit means the !! enforcement point itself failed to establish the invariant — a bug in !! the rule or an unmapped array on the device, not a stray kernel. That !! is precisely what the tripwire is for: it guards the structural !! guarantee rather than re-stating it. type(hgrid_t), intent(in) :: grid type(ocean_vcoord_t), intent(in), optional :: vcoord type(multilayer_state_t), intent(in) :: ms integer, intent(in) :: outer_step integer :: n_bad real(wp) :: worst character(len=320) :: msg if (.not. present(vcoord)) return if (.not. vcoord%check_vanished_content) return call ms%scan_vanished_content(grid%nx_total, grid%ny_total, n_bad, worst) if (n_bad <= 0) return write (msg, "(a,i0,a,i0,a,es12.5)") & "[I1'] vanished-layer invariant violated at outer step ", outer_step, & ": ", n_bad, " filler cell(s) do not hold their donor's concentration; "// & "worst |hTr - h*c_live| = ", worst call logger%error(trim(msg)) call logger%error( & "[I1'] `h <= H_VANISHED ⇒ hTr = h*c_live`. The enforcement point "// & "(multilayer_state_t%enforce_vanished_content) runs immediately before this "// & "check, so a hit is a bug in the rule or an off-device array, not a stray "// & "kernel write. See src/core/ocean/README.md, 'The vanished-layer content rule'.") error stop "I1' violated (&vcoord_nml check_vanished_content)" end subroutine check_vanished_invariant_or_die