Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+Revise equation of state interfaces for consistency #118

Merged
merged 9 commits into from
May 19, 2022

Conversation

Hallberg-NOAA
Copy link
Member

This PR includes a series of commits that standardize some of the less-used
interfaces or arguments to the MOM6 equation of state routines and how they are
used in a few places. There is a particular emphasis on the consistency of
which routines use rescaled variables or MKS variables, so that essentially all
of the dimensional rescaling related to the equation of state now occurs inside
of the routines in MOM_EOS.F90. By design, there is not expected to be any
noticeable performance impact. The vast majority of calls to the equation of
state routines are unaltered. All answers in test cases are bitwise identical,
but there are a few (probably untested) places where the rescaled units of some
arguments are corrected.

Changes of note include:

  • Refactored MOM_density_integrals to use the newer calculate_density_1d() and
    calculated_stanley_density_1d() interfaces to the equation of state routines,
    and to thereby shift all related dimensional rescaling into MOM_EOS.F90.

  • Revised the calculation of the drho_dT and drho_dS diagnostics to use
    dimensional consistency testing, along with the newer interface to
    calculate_density_1d

  • Added calculate_TFreeze_1d to the overloaded interface calculate_TFreeze,
    with dimensional rescaling of its arguments taken from its EOS_type argument
    and an optional two-element domain, rather than two mandatory integer
    arguments used with calculate_TFreeze_array. The older interface is also
    retained within the overloaded interface to calculate_TFreeze.

  • Modified calculate_density_scalar and calculate_stanley_density_scalar to use
    units of [R ~> kg m-3] for its rho_ref optional argument, following the
    pattern from calculate_density_1d. These arguments were not previously used.

  • Renamed the internally visible routine calculate_density_second_derivs_array
    to calculate_density_second_derivs_1d and changed its argument list to take
    an optional two-element domain, rather than two mandatory integer arguments,
    to follow the pattern set by calculate_density_derivs_1d. Because this
    routine was only being called in two places the older interface is not being
    preserved in the overloaded interface calculate_density_second_derivs.

  • Renamed the internally visible routine calculate_compress_array
    to calculate_compress_1d and changed its argument list to take
    an optional two-element domain, rather than two mandatory integer arguments,
    to follow the pattern set by calculate_density_derivs_1d. Because this
    routine was only being called in one place the older interface is not being
    preserved in the overloaded interface calculate_compress.

  • Eliminated some unnecessary local variables (mostly p_scale) for brevity and
    code clarity.

  • Modified two calls to calculate_density_second_derivs in
    thickness_diffuse_full to use its revised interface.

  • Modified one call to calculate_compress in build_slight_column to use
    its revised interface.

  • Made the description of units more precise in numerous comments describing
    the equation of state calls.

  • Eliminated numerous unused module use statements for EOS routines

The commits in this commit include:

  • 0903609a6 +Make equation of state interfaces more consistent
  • f51355476 Clarify argument units for int_density_dz_wright
  • 75ebb4090 +Refactored MOM_density_integrals
  • 3a9d51163 Revise how the drho_dT diagnostic is calculated
  • 07df0bfd7 Clarify units for equation of state arguments
  • 9c2e57310 Document variables in diagnoseMLDbyEnergy
  • 548be25b5 Remove unused module use for calculate_density

  Removed unused module use statements for EOS_type, calculate_density or
calculate_density_derivs in 20 files.  All answers are bitwise identical.
  Added comments documenting the units of the variables in diagnoseMLDbyEnergy
and slightly refactored this routine to clean up its call to calculate_density
and eliminated a redundant array of interface depths.  Also fixed several
spelling errors in comments. All answers and diagnostics are bitwise identical.
  Documented the units of variables as they actually appear in subroutine calls
to various equation of state or density integral routines, eliminating the
potentially confusing lists of alternative units in comments.  Only comments are
changed, and all answers are bitwise identical.
  Revised the calculation of the drho_dT and drho_dS diagnostics to use
dimensional consistency testing, along with the newer interface to
calculate_density that takes dimensionally rescaled arguments.  With this
change, the units of most the variables in this section of code match their
descriptions in comments, although there is still the local re-use of some 3-d
arrays as temporaries with units that do not match.  All answers and output are
bitwise identical.
  Refactored MOM_density_integrals to use the newer calculate_density_1d() and
calculated_stanley_density_1d() interfaces to the equation of state routines,
and to thereby shift all related dimensional rescaling into MOM_EOS.F90.  Also
revised the comments describing the arguments to a number of the equation of
state routines to eliminate confusing options and clearly indicate the units of
each input and output variable.  As a part of this change, the units of the
rho_ref argument to calculate_stanley_density_1d were changed from [kg m-3] to
[R ~> kg m-3] to match the equivalent routine calculate_density_1d().  Because
this does not appear to have been used previously, this should not be a problem,
and answers will not change unless a dimensional consistency test is underway.
All answers are bitwise identical, but there is one minor change to the rescaled
units of one apparently unused optional argument.
  Modified the comments describing the units of the arguments to
int_density_dz_wright, int_spec_vol_dp_wright int_density_dz_linear and
int_spec_vol_dp_linear so that they reflect the units as they are used in
practice where they are called from analytic_int_density_dz or
analytic_int_specific_vol_dp.  All answers are bitwise identical.
  This commit has several interface changes to some little-called equation of
state routines to follow the patterns set by the most commonly used equation
of state routines.  All answers in test cases are bitwise identical.

 - Added calculate_TFreeze_1d to the overloaded interface calculate_TFreeze,
   with dimensional rescaling of its arguments taken from its EOS_type argument
   and an optional two-element domain, rather than two mandatory integer
   arguments used with calculate_TFreeze_array.  The older interface is also
   retained within the overloaded interface to calculate_TFreeze.

 - Modified calculate_density_scalar and calculate_stanley_density_scalar to use
   units of [R ~> kg m-3] for its rho_ref optional argument, following the
   pattern from calculate_density_1d.  These arguments were not previously used.

 - Renamed the internally visible routine calculate_density_second_derivs_array
   to calculate_density_second_derivs_1d and changed its argument list to take
   an optional two-element domain, rather than two mandatory integer arguments,
   to follow the pattern set by calculate_density_derivs_1d.  Because this
   routine was only being called in two places the older interface is not being
   preserved in the overloaded interface calculate_density_second_derivs.

 - Renamed the internally visible routine calculate_compress_array
   to calculate_compress_1d and changed its argument list to take
   an optional two-element domain, rather than two mandatory integer arguments,
   to follow the pattern set by calculate_density_derivs_1d.  Because this
   routine was only being called in one place the older interface is not being
   preserved in the overloaded interface calculate_compress.

 - Eliminated some unnecessary local variables (mostly p_scale) for brevity and
   code clarity.

 - Modified two calls to calculate_density_second_derivs in
   thickness_diffuse_full to use its revised interface.

 - Modified one call to calculate_compress in build_slight_column to use
   its revised interface.
@codecov
Copy link

codecov bot commented Apr 27, 2022

Codecov Report

Merging #118 (2a362c4) into dev/gfdl (0e8acd9) will increase coverage by 0.02%.
The diff coverage is 26.81%.

@@             Coverage Diff              @@
##           dev/gfdl     #118      +/-   ##
============================================
+ Coverage     28.78%   28.81%   +0.02%     
============================================
  Files           249      249              
  Lines         72991    72934      -57     
============================================
+ Hits          21010    21015       +5     
+ Misses        51981    51919      -62     
Impacted Files Coverage Δ
src/ALE/MOM_ALE.F90 34.23% <ø> (ø)
src/ALE/coord_slight.F90 0.00% <0.00%> (ø)
src/diagnostics/MOM_wave_speed.F90 23.97% <ø> (ø)
src/equation_of_state/MOM_EOS_Wright.F90 30.05% <ø> (-2.32%) ⬇️
src/equation_of_state/MOM_EOS_linear.F90 17.67% <0.00%> (ø)
...arameterizations/lateral/MOM_thickness_diffuse.F90 30.76% <0.00%> (-0.14%) ⬇️
...rc/parameterizations/vertical/MOM_bkgnd_mixing.F90 32.59% <ø> (ø)
...parameterizations/vertical/MOM_diabatic_driver.F90 39.21% <ø> (ø)
...meterizations/vertical/MOM_internal_tide_input.F90 0.00% <ø> (ø)
...rameterizations/vertical/MOM_regularize_layers.F90 5.78% <ø> (ø)
... and 21 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0e8acd9...2a362c4. Read the comment docs.

  Corrected a bug in the calculation of drho_dS_dP and drho_dT_dP in the
calculate_density_second_derivs routines, where the inverse of the correct
rescaling was being used.  However, these routines are only called in a very few
places and these particular output fields are not being used, so this bug does
not alter any existing MOM6 solutions.
@Hallberg-NOAA
Copy link
Member Author

This PR is the starting point for PR #122, so please use a git merge instead of a rebase to reconcile this with any changes in its base branch, to avoid having duplicated commits between the two PRs. Each of the commits here are potentially significant for future git bisections, so please do not squash this commit.

@Hallberg-NOAA Hallberg-NOAA added the enhancement New feature or request label May 7, 2022
@marshallward
Copy link
Member

Gaea regression: https://gitlab.gfdl.noaa.gov/ogrp/MOM6/-/pipelines/15535 ✔️

@marshallward
Copy link
Member

This PR is the starting point for PR #122, so please use a git merge instead of a rebase to reconcile this with any changes in its base branch, to avoid having duplicated commits between the two PRs. Each of the commits here are potentially significant for future git bisections, so please do not squash this commit.

Since this hasn't been merged yet, do you just want to rebase #122 onto this one?

@marshallward
Copy link
Member

Nevermind, I'll just do the regular merge. Though perhaps we should discourage PRs which build on other PRs like this.

@marshallward marshallward merged commit 9d6def6 into NOAA-GFDL:dev/gfdl May 19, 2022
@Hallberg-NOAA Hallberg-NOAA deleted the EOS_interface_cleanup branch July 16, 2022 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants