Skip to content

Refactor MOM_barotropic for clearer OBCs#861

Merged
Hallberg-NOAA merged 4 commits intoNOAA-GFDL:dev/gfdlfrom
Hallberg-NOAA:refactor_btstep_OBC
Mar 20, 2025
Merged

Refactor MOM_barotropic for clearer OBCs#861
Hallberg-NOAA merged 4 commits intoNOAA-GFDL:dev/gfdlfrom
Hallberg-NOAA:refactor_btstep_OBC

Conversation

@Hallberg-NOAA
Copy link
Copy Markdown
Member

This series of 4 commits refactors btstep() and other related routines in MOM_barotropic.F90 for simpler application of open boundary conditions. Swapping of the order of certain OBC-related calculations allowed for fewer temporary arrays to be used to store previous values without changing answers. These changes include moving the transport calculations out of btloop_update_u() and btloop_update_v() with a substantial shortening (from 8 lines to 5) of their argument lists and the elimination of the routines store_u_for_OBCs() and store_v_for_OBCs(). What had previously been the single routine
apply_velocity_OBCs() is now split into apply_u_velocity_OBCs() and apply_v_velocity_OBCs(), in preparation for further targeting of the OBC calculations. The accumulation and posting of diagnostics was moved to the end of the barotropic time stepping loop for greater code clarity. Several diagnostic arrays are now declared with the standard memory sizes so they can be used directly without additional copies. As a result of these changes, a total of 8 diagnostic 2-d arrays are now declared with standard-sized halos, while another 14 2-d arrays were eliminated altogether.

All answers are bitwise identical, and no external interfaces are changed. The commits in this PR include:

  • 7fce5d342 Reduce the size of barotropic diagnostic arrays
  • 7206ed9ae Calculate transports outside of btloop_update_u
  • eff3927bc Split apply_velocity_OBCs into two routines
  • 875a6861e Apply OBCs earlier in btstep

@Hallberg-NOAA Hallberg-NOAA added the refactor Code cleanup with no changes in functionality or results label Mar 18, 2025
@theresa-cordero theresa-cordero self-requested a review March 19, 2025 17:06
Copy link
Copy Markdown

@theresa-cordero theresa-cordero left a comment

Choose a reason for hiding this comment

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

These changes appear reasonable to me and I am ready to approve. They should be tested with more OBC options to make sure there are no answer changes. @yichengt900 would you be able to test this with the regression tests for the CEFI regional configurations?

@yichengt900
Copy link
Copy Markdown

@theresa-cordero, this PR passed the CEFI regression test suite.

  Switched the order of the application of the open boundary conditions in
btstep and the accumulation of the time integrated transports and the time
averaged velocities, which avoids the need to reset these integrals after the
open boundary conditions have been applied.  This permits the elimination of 6
2-d arrays that are not needed and the elimination of 6 arguments each to
store_u_for_OBCs and store_v_for_OBCs.   Also moved the code resetting the
diagnostic pressure gradient force at the OBC faces to the end of
btloop_update_u and btloop_update_v, thereby eliminating separate OBC-related
code blocks.  All answers are bitwise identical and no public interfaces are
changed.
  Split apply_velocity_OBCs into apply_u_velocity_OBCs and apply_v_velocity_OBCs
to allow for shorter lists of arguments and more targeted routines.  Also moved
the calls to store_u_for_OBCs and store_v_for_OBCs to be just before the calls
to btloop_update_u and btloop_update_v as a step toward possibly combining these
routines.   All answers are bitwise identical and no public interfaces are
changed.
  Moved the calculation of the barotropic transports (uhbt and vhbt) out of
btloop_update_u and btloop_update_v, and moved the code storing the previous
velocities in ubt_prev and vbt_prev into these same routines, thereby
eliminating the tiny routines store_u_for_OBCs and store_u_for_OBCs.  The code
calculating ubt_trans and vbt_trans was moved to occur alongside the calculation
of the transports.  Also reordered the descriptions of the arguments to
btloop_update_u and btloop_update_v to match the order of the arguments
themselves.  All answers are bitwise identical and no public interfaces are
changed.
  Restrict the size of 6 barotropic diagnostics to not have wide halos as this
led to unnecessary copies, and avoid the use of duplicated wide-halo arrays for
the calculation of uhbtav, CS%ubtav, vhbtav and CS%vbtav, thereby eliminating 4
unneeded arrays.  The code setting ubt_int, uhbt_int, vbt_int and vhbt_int was
moved into apply_u_velocity_OBCs and apply_v_velocity_OBCs, eliminating a pair
of loops that look for where OBCs are applied, so that there are now just two
such loops for each of the u- and v-velocities inside of the barotropic time
stepping loop (ideally there would just be one).  The now unused routines
store_u_for_OBCs and store_v_for_OBCs were eliminated.   All answers are bitwise
identical, and no interfaces are changed.
@Hallberg-NOAA
Copy link
Copy Markdown
Member Author

This PR has passed pipeline testing at https://gitlab.gfdl.noaa.gov/ogrp/mom6ci/MOM6/-/pipelines/26793.

@Hallberg-NOAA Hallberg-NOAA merged commit f9e1a84 into NOAA-GFDL:dev/gfdl Mar 20, 2025
10 checks passed
@Hallberg-NOAA Hallberg-NOAA deleted the refactor_btstep_OBC branch April 22, 2025 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code cleanup with no changes in functionality or results

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants