Skip to content

+Improved buoyancy flux diagnostics in non-Boussinesq or layered mode - #1167

Open
Hallberg-NOAA wants to merge 5 commits into
NOAA-GFDL:dev/gfdlfrom
Hallberg-NOAA:revise_strat_Kd_work_diags
Open

+Improved buoyancy flux diagnostics in non-Boussinesq or layered mode#1167
Hallberg-NOAA wants to merge 5 commits into
NOAA-GFDL:dev/gfdlfrom
Hallberg-NOAA:revise_strat_Kd_work_diags

Conversation

@Hallberg-NOAA

Copy link
Copy Markdown
Member

This PR consists of a series of 5 commits that make the Kd_heat and Kd_salt diagnostics and the various Bflx_dia_... diagnostics work when MOM6 is run in layered mode and temperature and salinity are used as state variables. When temperature and salinity are not state variables, these diagnostics do not make sense, so they are no longer registered as diagnostics and no longer appear in the available_diags files.

The duplicated code the stratification diagnostics in the diabatic driver was consolidated into the new internal subroutine diagnose_strat_Kd_work(), which is now called with all 3 options in the diabatic driver.

This PR also eliminates the separate non-Boussinesq code to calculate N2_salt and N2_temp in diagnose_Kd_work(). The non-Boussinesq code previously used the Boussinesq reference density (via GV%Z_to_H) for several diagnostics, which is inconsistent with not making the Boussinesq approximation. Ironically, the Boussinesq code did not depend on the Boussinesq reference density when run in non-Boussinesq mode, because it used GV%H_to_RZ instead of GV%Rho0. So this commit both simplifies the code and fixes the diagnostics of the stratification in non-Boussinesq mode.

Finally, there are two sets of changes refactoring KdWork_Diagnostics() for better memory use and to limit the unnecessary exposure of arrays that are not intended to be used outside of this routine. This PR includes a commit that revises the interface to KdWork_Diagnostics() to pass in Kd_salt and Kd_heat rather than storing them in the VBF_CS. These arrays are always available when KdWork_Diagnostics() is called, and storing them just leads to an extra 3-d array copy. Internally within the diabatic driver code, these arrays are also being passed into diagnose_strat_Kd_work(), which calls KdWork_Diagnostics(). The final commit moves Bflx_salt, Bflx_temp, Bflx_salt_dz and Bflx_temp_dz from the VBF_CS into KdWork_Diagnostics() as simple local arrays. These were not exposed outside of KdWork_Diagnostics(), so there was no reason for them to have the more persistent memory that their inclusion in the type entailed. As a part of the refactoring of MOM_diagnose_KdWork.F90, it also adds local variables with the combinations of scaling factors that are repeatedly used for spatially integrating the layer-integrated buoyancy fluxes or as conversion factors for work or buoyancy flux diagnostics, and it does some minor clean-up on the syntax of the register_diag_field() calls in KdWork_init() to follow the MOM6 style guide.

All solutions are bitwise identical, but there are (deliberate) changes in some non-Boussinesq diagnostics and other layer-mode diagnostics that were previously just reporting zeros, while other diagnostics are no longer being offered in cases when they would have been nonsensical.

@Hallberg-NOAA Hallberg-NOAA added enhancement New feature or request refactor Code cleanup with no changes in functionality or results answer-changing A change in results (actual or potential) bugfix Fixes an existing bug labels Aug 21, 2026
@Hallberg-NOAA
Hallberg-NOAA requested a review from breichl August 21, 2026 09:11
  Moved two identical blocks of code that calculate terms related to the
stratification after mixing and the work done by various mixing terms into a new
internal subroutine, diagnose_strat_Kd_work(), that is now called from both
diabatic_ALE() and diabatic_ALE_legacy().  There is also some refactoring of the
code in diagnose_strat_Kd_work() to avoid array-syntax math and bring it into
alignment with the MOM6 code style.  All answers are bitwise identical.
  Added a new call to diagnose_strat_Kd_work() from within diabatic_layer() when
temperature and salinity are used as state variables.  Also fixed the
diagnostics of Kd_heat and Kd_salt in layered mode by setting the pertinent
variables even when KPP or double diffusion are not being used.  As written, the
`Bflx_dia_...` diagnostics are meaningless without temperature and salinity as
state variables, so there is a new `use_EOS` argument to Kd_work_init() and
these diagnostics are no longer offered in runs without an equation of state.
All answers are bitwise identical, but there are new diagnostics available in
some non-ALE mode runs and fewer diagnostics in the available_diags file for
others.
  Eliminated the separate non-Boussinesq code to calculate N2_salt and N2_temp
in diagnose_Kd_work().   The non-Boussinesq code previously used the Boussinesq
reference density (via GV%Z_to_H) for several diagnostics, which is inconsistent
with not making the Boussinesq approximation.  Ironically, the Boussinesq code
did not depend on the Boussinesq reference density when run in non-Boussinesq
mode, because it used GV%H_to_RZ instead of GV%Rho0.  So this commit both
simplifies the code and fixes the diagnostics of the stratification in
non-Boussinesq mode.  All solutions are bitwise identical, but some diagnostics
do change in non-Boussinesq mode.
  Revised the interface to KdWork_Diagnostics() to pass in Kd_salt and Kd_heat
rather than storing them in the VBF_CS.  These arrays are always available when
KdWork_Diagnostics is called, and storing them just leads to an extra 3-d array
copy.  Internally within the diabatic_driver code, these arrays are also being
passed into diagnose_strat_Kd_work(), which calls KdWork_Diagnostics().  All
answers are bitwise identical, but there are changes to a publicly visible
interface.
  Moved Bflx_salt, Bflx_temp, Bflx_salt_dz and Bflx_temp_dz from the VBF_CS into
KdWork_Diagnostics() as simple local arrays.  These were not exposed outside of
KdWork_Diagnostics(), so there was no reason for them to have the more
persistent memory that their inclusion in the type entailed.  Also added local
variables with the combinations of scaling factors that are repeatedly used for
spatially integrating the layer-integrated buoyancy fluxes or as conversion
factors for work or buoyancy flux diagnostics.  All answers are bitwise
identical, but there are 4 fewer arrays in a transparent type.
@Hallberg-NOAA
Hallberg-NOAA force-pushed the revise_strat_Kd_work_diags branch from d144434 to e456e9b Compare August 28, 2026 18:39
@knlowman

knlowman commented Sep 2, 2026

Copy link
Copy Markdown

Are there any updates on this pending pull request, @Hallberg-NOAA and @breichl ? I see it failed some tests.

@breichl

breichl commented Sep 8, 2026

Copy link
Copy Markdown

Hi @knlowman, I have inspected the code and agree with the proposed changes. I am planning to do some tests in OM5 as soon as possible to confirm that the updated diagnostics look right before I approve the PR, but I anticipate things should be okay. I am unsure why there are failed tests, but I do not think that they are problematic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

answer-changing A change in results (actual or potential) bugfix Fixes an existing bug enhancement New feature or request refactor Code cleanup with no changes in functionality or results

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants