Fix out-of-bounds access on zk in cvmix_kpp_compute_StokesXi#113
Open
alperaltuntas wants to merge 1 commit intoCVMix:masterfrom
Open
Fix out-of-bounds access on zk in cvmix_kpp_compute_StokesXi#113alperaltuntas wants to merge 1 commit intoCVMix:masterfrom
alperaltuntas wants to merge 1 commit intoCVMix:masterfrom
Conversation
- Fix a Fortran runtime error caused by accessing zk(kSL+1) when the KPP surface layer cell index kSL equals the number of vertical levels - Guard the post-loop tauEbot normalization: use the cell-center spacing zk(ktmp) - zk(ktmp+1) when ktmp < size(zk), and fall back to the interface spacing zi(ktmp) - zi(ktmp+1) at the bottom cell
Contributor
Author
|
I don't have the permissions to add reviewers, so I am mentioning @mnlevy1981 and @gustavo-marques |
mnlevy1981
reviewed
Apr 21, 2026
Comment on lines
+3533
to
+3537
| if (ktmp < size(zk)) then | ||
| tauEbot = (tauxbot * delU + tauybot * delV) / (zk(ktmp) - zk(ktmp+1)) | ||
| else | ||
| tauEbot = (tauxbot * delU + tauybot * delV) / (zi(ktmp) - zi(ktmp+1)) | ||
| endif |
Contributor
There was a problem hiding this comment.
I'd like to talk to Bill L about the best way to fix this. I see that the block of code being modified
! Integrate from top of surface layer cell to Surface layer Depth
delH = SLDepth + zi(ktmp)
sigbot = CVmix_kpp_params_in%surf_layer_ext
Gbot = cvmix_kpp_composite_shape(sigbot)
TauMAG = ustar * ustar * Gbot / sigbot
tauCG = CempCGm * Gbot * (taux0 * cosOmega - tauy0 * sinOmega)
! tauDG = sqrt( TauMAG**2 - tauCG**2 ) ! G
tauDG = TauMAG ! E
tauxbot = tauDG * cosOmega - tauCG * sinOmega
tauybot = tauDG * sinOmega + tauCG * cosOmega
tauEbot = (tauxbot * delU + tauybot * delV) / (zk(ktmp) - zk(ktmp+1) )Is similar to what happens in the do loop above it:
! Integrate Both Shear Production Terms from Surface to top of surface layer cell
do ktmp = 1, kSL-1
delU = uE(ktmp) - uE(ktmp+1)
delV = vE(ktmp) - vE(ktmp+1)
Omega_E2x= atan2( delV , delU )
cosOmega = cos(Omega_E2x)
sinOmega = sin(Omega_E2x)
delH = zi(ktmp) - zi(ktmp+1)
dbot = dtop + delH
sigbot = dbot / BLdepth
Gbot = cvmix_kpp_composite_shape(sigbot)
TauMAG = ustar * ustar * Gbot / sigbot
tauCG = CempCGm * Gbot * (taux0 * cosOmega - tauy0 * sinOmega)
! tauDG = sqrt( TauMAG**2 - tauCG**2 ) ! G
tauDG = TauMAG ! E
tauxbot = tauDG * cosOmega - tauCG * sinOmega
tauybot = tauDG * sinOmega + tauCG * cosOmega
tauEbot = (tauxbot * delU + tauybot * delV) / (zk(ktmp) - zk(ktmp+1) )So I just want to make sure we are computing all of those terms correctly when kSl == size(zk)
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.
Fixes: #112