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

EBT Backscatter #706

Merged
merged 11 commits into from
Sep 27, 2024
Merged

Conversation

ElizabethYankovsky
Copy link

@ElizabethYankovsky ElizabethYankovsky commented Aug 7, 2024

Backscatter code using the equivalent barotropic (EBT) mode documented in Yankovsky et al. (2024).

  • Added BS_struct as the vertical structure of backscatter in MOM_lateral_mixing_coeffs. Adapted from Jenny Chang’s codes. Modified by Wenda Zhang.
  • Set BS_EBT_power>0 (default is 0) to use the EBT mode for BS_struct
  • Added a kill switch in MOM_hor_visc to stabilize the backscatter simulation. Set EY24_EBT_BS = True (default is False) to use the kill switch.
  • Added diagnostics in MOM_MEKE to track sources and sinks of MEKE

Backscatter code using the equivalent barotropic (EBT) mode documented in Yankovsky et al. (2024).
Copy link

codecov bot commented Aug 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 37.04%. Comparing base (d234bce) to head (aa32aac).

Additional details and impacted files
@@             Coverage Diff              @@
##           dev/gfdl     #706      +/-   ##
============================================
+ Coverage     37.03%   37.04%   +0.01%     
============================================
  Files           273      273              
  Lines         82552    82725     +173     
  Branches      15442    15484      +42     
============================================
+ Hits          30572    30646      +74     
- Misses        46263    46330      +67     
- Partials       5717     5749      +32     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@marshallward marshallward left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a few suggestions. The main one was a proposal to reduce the number of divides in the MEKE src_* calculations. I also noticed some indentations and zombie comments which should be cleaned up.

I think that it might be beneficial to move FrictWork and FrictWork_bh into separate loops, and wrap them with individual id_* checks. (Note that find_FrictWork is a proxy for id_FrictWork > 0.) The if (visc_limit_[hq]_flag)` checks could have a negative impact on performance, and I think it would be better to apply them as a mask (see comments).

I noticed the appearance of ** in computing CS%BS_struct but there is probably not much we can do about it at this time.

Overall I think is at a very high level of quality and should be ready to merge soon.

src/parameterizations/lateral/MOM_hor_visc.F90 Outdated Show resolved Hide resolved
src/parameterizations/lateral/MOM_hor_visc.F90 Outdated Show resolved Hide resolved
src/parameterizations/lateral/MOM_hor_visc.F90 Outdated Show resolved Hide resolved
src/parameterizations/lateral/MOM_hor_visc.F90 Outdated Show resolved Hide resolved
src/parameterizations/lateral/MOM_hor_visc.F90 Outdated Show resolved Hide resolved
src/parameterizations/lateral/MOM_MEKE.F90 Outdated Show resolved Hide resolved
src/parameterizations/lateral/MOM_MEKE.F90 Outdated Show resolved Hide resolved
src/parameterizations/lateral/MOM_MEKE.F90 Outdated Show resolved Hide resolved
src/parameterizations/lateral/MOM_hor_visc.F90 Outdated Show resolved Hide resolved
ElizabethYankovsky and others added 10 commits August 23, 2024 14:07
- Separate FrictWork and FrictWork_bh loops
- Simplified the computation for MEKE%mom_src and MEKE%mom_src_bh when MEKE%backscatter_Ro_c /= 0.

(cherry picked from commit 8ffc6a8)
This patch modifies the calculation of `src_btm_drag` to avoid
additional division operations.

We first note the following variable renames:

* `Isfac` is now `damping`, since it describes the net damping or
  reduction of any damped fields.  `sfac` has been removed since it no
  longer appears in the expressions.

* `ldamping` is now `damp_rate`.  This is primarily to avoid confusion
  with `damping`, but also to more accurately describe its role.

* `ldamping_Strang1` is replaced to `damp_rate_s1`.  It is used for a
  similar purpose (cacheing of values from the first stage) but now
  holds a slightly different value.

The following modifications were made.

1. The conditional split of `sdt` into `sdt_damping` substeps is
   quantified by a new term, `damp_step` which is equal to 0.5 or 1.
   `sdt_damp` is computed as `sdt * damp_step`.

   The presence of `sdt_damp / sdt` in our expressions is replaced with
   `damp_step`, which avoids an extra division.

2. The first expression (using new notation) was originally

    sfac = 1 + sdt_damp * damp_rate
    D = M * (1 - sfac) / (sdt * sfac)

   where `D` is `src_btm_drag` and `M` is `MEKE_current(i,j)`

   This has been transformed to

    D = - M * (sdt_damp * damp_rate)
            / (sdt * (1 + sdt_damp * damp_rate))

      = - M * (sdt_damp / sft) * damp_rate
            * (1 / (1 + sdt_damp * damp_rate))

      = - M * damp_step * damp_rate * damping

   This new expression for `D` no longer requires a division.

3. In the second stage expression for `src_btm_drag`, we again use
   `damp_rate` to replace `ldamping`.  We also use `damp_rate1` to
   denote the original value of `ldaming_Strang1`.

    sfac = (1 + sdt_damp * damp_rate1) * (1 + sdt_damp * damp_rate)
    D = M * (1 - sfac) / (sdt * sfac)

   Using `damping1` to denote the damping from the first stage, `D` can
   be transformed as follows.

    D = -M * (sdt_damp * damp_rate + sdt_damp * damp_rate1
                + sdt_damp**2 * damp_rate * damp_rate1)
      / (sdt * (1 + sdt_damp * damp_rate) * (1 + sdt_damp * damp_rate1))

      = -M * (sdt_damp / sdt) * (1 / (1 + sdt_damp * damp_rate))
        * (damp_rate + damp_rate1 + sdt_damp * damp_rate * damp_rate1)
        / (1 + sdt_damp * damp_rate1)

      = -M * damp_step * damping
        * (damp_rate * (1 + sdt_damp * damp_rate1) + damp_rate1)
        / (1 + sdt_damp * damp_rate1)

      = -M * damp_step * damping * (damp_rate + damp_rate1 * damping1)

   We now store `damp_rate1 * damping1` in `damp_rate_s1(:,:)` rather
   than just `damping1`, and can reduce this expression to

    D = -M * damp_step * damping * (damp_rate + damp_rate_s1(i,j))

   which requires no division.  It also requires no additional
   read or writes.

Assuming there are no mistakes here, this should only cause negligible
bitwise differences in the results.

Also, comments have been added which explain that we cannot modify the
existing expressions for `MEKE%MEKE`, since they would alter the bitwise
results of existing runs.
In the second stage of Strang splitting, there is a check for `sdt >
sdt_damping`, following a check for nonzero `KH` or `K4`.

However, `sdt_damp` can only be less than `sdt` when these are nonzero.
Otherwise, `sdt_damping` equals `sdt`.

Best as I can tell, this check is unnecessary and potentially
problematic for optimization.  This patch removes the redundant check.
MEKE: No-division implementation of src_btm_drag
Resolved conflicts related to if(h_limit_flag) and new FMA-safe
parentheses in FrictWork.
@marshallward
Copy link
Member

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

There are new diagnostics and parameters related to EBT, but otherwise no issues.

Copy link
Member

@marshallward marshallward left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks good now.

Some additional work might be needed on the FrictWork loops, but this can be worked on when the mom_src/GME_snk summations are separated from the main k-loop.

@marshallward marshallward merged commit df2cd12 into NOAA-GFDL:dev/gfdl Sep 27, 2024
10 checks passed
theresa-morrison pushed a commit to theresa-morrison/MOM6 that referenced this pull request Nov 18, 2024
* EBT Backscatter

Backscatter code using the equivalent barotropic (EBT) mode documented in Yankovsky et al. (2024).

* Modifications to MOM_hor_visc:
- Separate FrictWork and FrictWork_bh loops
- Simplified the computation for MEKE%mom_src and MEKE%mom_src_bh when MEKE%backscatter_Ro_c /= 0.

(cherry picked from commit 8ffc6a8)

---------

Co-authored-by: Wenda Zhang <zhangwenda33@hotmail.com>
Co-authored-by: Marshall Ward <marshall.ward@noaa.gov>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants