Fix cvmix_KPP StokesMOST: divide-by-zero and NaN injection under calm wind conditions#948
Open
patrickscholz wants to merge 1 commit into
Open
Fix cvmix_KPP StokesMOST: divide-by-zero and NaN injection under calm wind conditions#948patrickscholz wants to merge 1 commit into
patrickscholz wants to merge 1 commit into
Conversation
…alm wind compute_stokes_velocities_MOM6style computes Tp = 0.8*uv10 and then fp = 1/Tp. When uv10 = 0 (calm wind, doldrums, idealised cases, or forcing interpolation crossing zero): Tp = 0 -> fp = Inf -> kp = Inf. Additionally uS0 = Astokes*uv10^2 * uwind/uv10 = 0/0 = NaN, poisoning all Stokes drift components and propagating NaN into the KPP Langmuir turbulence computation permanently. Apply a 1e-3 m/s floor (background gustiness) to uv10 before any ratio.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Affects only cvmix_KPP with
kpp_use_StokesMOST = .true.(the default). When wind speed is exactly zero,compute_stokes_velocities_MOM6styleproduces a division by zero and a0/0 = NaNthat permanently corrupts the Stokes drift and Langmuir turbulence in the affected column. The fix is a single-line lower bound onuv10.The bug: a cascade of singularities at zero wind
The subroutine derives the peak wave frequency and wavenumber from the 10-m wind speed, then uses the wind direction to decompose the Stokes drift into vector components:
Every output of the subroutine (
uS_top,vS_top,uS_mid,vS_mid,uS_mean,vS_mean) is then computed fromuS0/vS0, so all six outputs become NaN. These NaN values feed directly into:cvmix_kpp_compute_StokesXi— the Stokes similarity parameter (Langmuir turbulence strength)compute_Efactor— the Langmuir enhancement factor for entrainmentcvmix_coeffs_kpp— the final KPP diffusivities and viscositiesOnce NaN enters the KPP mixing tensor it propagates irreversibly to tracer and momentum fields for that column — the model either crashes on the next timestep or silently produces garbage values.
When does zero wind occur?
The fix
A single-line lower bound on
uv10before any ratio is computed (src/cvmix_driver/gen_modules_cvmix_kpp.F90):1.0e-3 m/s(1 mm/s) represents physical background gustiness and is orders of magnitude below any meaningful wave-generating wind speed. It eliminates both thefp = 1/Tpsingularity and theuwind/uv10 = 0/0NaN while having zero practical effect on results.Scope
kpp_use_StokesMOST = .true.(the default Langmuir turbulence path)kpp_use_StokesMOST = .false.sqrt(uwind^2 + vwind^2) < 1e-3 m/s; all other conditions are completely unaffected