Skip to content

Prepare for PR to dev/gfdl#6

Open
nikizadehgfdl wants to merge 2012 commits intonikizadehgfdl:merge-bgc-obc-3_fix_restartfrom
NOAA-GFDL:dev/gfdl
Open

Prepare for PR to dev/gfdl#6
nikizadehgfdl wants to merge 2012 commits intonikizadehgfdl:merge-bgc-obc-3_fix_restartfrom
NOAA-GFDL:dev/gfdl

Conversation

@nikizadehgfdl
Copy link
Copy Markdown
Owner

No description provided.

nikizadehgfdl pushed a commit that referenced this pull request Aug 12, 2022
Add initialization tests using CS%initialized
@marshallward marshallward force-pushed the dev/gfdl branch 3 times, most recently from 8a66adc to 9de6ce7 Compare September 11, 2023 18:27
Hallberg-NOAA and others added 25 commits June 6, 2025 17:56
  Added the new optional argument OBC_N2 to calc_isoneutral_slopes that can be
use to specify that only interior points are used to calculate the buoyancy
frequencies at velocity points when open boundary conditions are in use.  When
the new OBC_N2 argument is absent or false, the solutions are identical to what
they had been previously, but this gives a dependence on the arbitrary outer
thicknesses when open boundary conditions are used.  By default, all answers are
bitwise identical, but there is a new optional argument to a publicly visible
interface.
  Added the new runtime option MIXING_COEFS_OBC_BUG that can be set to false to
specify that only interior data should be used for thickness weighting in the
lateral mixing coefficient calculations when open boundary conditions are in
use, and that only interior temperatures, salinities, pressures and thicknesses
should be used when calculating the buoyancy frequency at open boundary velocity
faces.  These changes are implemented by introducing two new 3-d arrays that set
the thicknesses at velocity points and there are a few new logical tests inside
of some loops, which may slow down the code slightly in routines that had never
previously been notable for the amount of time spent there.  They also make use
of the recently added OBC_N2 argument to calc_isoneutral_slopes().  There are
new ocean_OBC_type arguments to calc_resoln_function() and calc_sqg_struct() as
a part of these changes.  The default setting for MIXING_COEFS_OBC_BUG retains
the previous (incorrect) answers, and all answers are bitwise identical in cases
without open boundary conditions regardless of how it is set.  There is a new
entry in some MOM_parameter_doc files for some cases with active open boundary
conditions and new arguments to publicly visible interfaces.
  This commit revises setup_OBC_tracer_reservoirs and other OBC routines to allow
some cases using open boundary conditions and tracer reservoirs to reproduce
across restarts and added the new runtime parameter OBC_RESERVOIR_INIT_BUG that
can be set to true to recover the previous answers in cases that are not
initialized from a restart file.   There is a new optional MOM_restart_CS argument
to setup_OBC_tracer_reservoirs that can be used to query whether the reservoirs
have been read from a restart file before resetting them to values that may have
been set during initialization.  If the reservoirs have not been set from a
restart file, there is now a preference to set them from the tracer reservoir
(tres) element in the OBC tracer registry on the segments (if it has been
initialized) rather than the interior tracer values that have been recorded on the
segment.

  Fill_temp_salt_segments and fill_obgc_segments have been modified to only set
the tres segment data if it has not been initialized already, as indicated by
the is_initialized field.

  This commit adds the new public routine set_initialized_OBC_tracer_reservoirs
that can be used to record in the restart control structure that the OBC%tres_x
and OBC%tres_y fields have been initialized and should not be reset to new
values during initialization.

  The calls to setup_OBC_tracer_reservoirs and open_boundary_halo update have
been moved after the call to tracer_flow_control_init so that the full arrays of
tracer reservoirs do not need to be initialized in fill_obgc_segments.
Fill_obgc_segments was refactored to separate out the steps that should occur
there from those that should not and are wrapped in a bug flag.

  A debugging checksum call to chksum_OBC_segments was added to the top of
radiation_open_bdry_conds to assist in any future debugging of the OBC code.

  Added doxygen comments describing several routines that were previously
missing such a description.

  By default, all answers are bitwise identical, but there is a new publicly
visible routine, a new optional argument to a public interface and a new runtime
parameter that can be used to correct the previous behavior that broke the
reproducibility across restarts of some cases using open boundary conditions
with tracer reservoirs.
  Copy segment tracer registry data from the input segment to the target segment
in rotate_OBC_segment_data, including the tracer reservoirs on segments.  With
this change, configurations using tracers with open boundary conditions are now
passing the rotational consistency tests.  This will change answers with some
rotated cases with active OBCs, but all answers in non-rotated cases or cases
without tracers in OBCs are bitwise identical.
  When there are specified open boundary conditions, dyed_channel_update_flow()
was setting the normal transport with the wrong units of [L2 T-1 ~> m2 s-1]
instead of [H L2 T-1 ~> m3 s-1 or kg s-1], effectively omitting the layer
thickness in the transports.  This has been corrected by adding the new runtime
parameter CHANNEL_FLOW_OBC_TRANSPORT_BUG that either uses a fixed thickness if
true (of 1 m or 1 kg m-2) or the actual interior thickness.  In either case, the
model is now passing the dimensional consistency testing.  This change requires
a new layer thickness argument to  dyed_channel_update_flow().  In addition,
code was added to dyed_channel_update_flow so that it also satisfies rotational
consistency.  By default, answers are bitwise identical when no dimensional
rescaling or grid rotation is applied, but there is a new runtime parameter and
a new argument to dyed_channel_update_flow.
  Modified shelfwave_set_OBC_data to work properly with grid rotation of 90, 180
or 270 degrees.  With these changes the ESMG shelfwave test case is now giving
bitwise identical answers under grid rotation.  This commit also corrects a
recently added problem with potentially unallocated arrays being used to test
whether a pointer is set to the unrotated tracer reservoirs in cases where there
are no tracers.  This commit does change (and fix) answers when grid rotation is
used, but answers are bitwise identical when there is no grid rotation, and
there are no changes to any public interfaces.
  Modified tidal_bay_set_OBC_data to work properly with grid rotation of 90, 180
or 270 degrees.  With these changes the ESMG Tidal_bay test case is now giving
bitwise identical answers under grid rotation.  This commit does change (and
fix) answers when grid rotation is used, but answers are bitwise identical
when there is no grid rotation, and there are no changes to any public
interfaces.
* *Implement subcycing for internal tides refraction/propagation

This PR allows to bring back the thermodynamics timestep higher
while keeping the raytracing under CFL by doing multiple steps
within the thermo step.

The only variable that needs to be accumulated in the subcycling
is the slope loss (residual of transmission and reflection on slopes)
Since it is already accumulated within the 2 directions of propagation,
it only needs to be initialized outside of the subcycling.

* unindent loop for easier git diff (will indent back later)

* fix bad placement of complete_group_pass and sync En

* rewrite subcycle in terms of a timestep and group_pass

* fix indexing bug, remove useless init/passing

* fixes from review

---------

Co-authored-by: Raphael Dussin <Raphael.Dussin@noaa.gov>
  This commit adds the new runtime parameter ENABLE_BUGS_BY_DEFAULT and use it
to set the defaults for a number of bug-fix parameters that have been added
within about the past year and have not yet had their defaults set to correct
the bugs. The default value (True) allows us to move the version of the code
forward without changing any existing answers by default.  Conversely, setting
this to false means that no bugs are used unless they are actively selected,
which is probably the right choice for new runs.  The defaults for groups of
bug-fix flags are periodically changed to correct the bug, at which point this
new parameter will no longer be used to set their default.  This commit also
uses ENABLE_BUGS_BY_DEFAULT to set the defaults for 16 existing runtime
parameters, including  DETERMINE_TEMP_CONVERGENCE_BUG, RHO_PGF_REF_BUG,
VISC_REM_BUG,  OBC_RESERVOIR_INIT_BUG, OBC_HOR_INDEXING_BUG, EXTERIOR_OBC_BUG,
VERTEX_SHEAR_VISCOSITY_BUG, VERTEX_SHEAR_OBC_BUG, EPBL_MLD_ITER_BUG,
MEKE_GM_SRC_ALT_SLOPE_BUG, HOR_DIFF_LIMIT_BUG, MIXING_COEFS_OBC_BUG,
FRICTWORK_BUG, LA_MISALIGNMENT_BUG, IDL_HURR_SCM_EDGE_TAPER_BUG and
CHANNEL_FLOW_OBC_TRANSPORT_BUG, which are scattered across 16 modules.  For 7 of
these parameters, the default will be reset to false soon.  By default all
solutions are bitwise identical, but there is a new runtime parameter that will
occur in all of the MOM_parameter_doc.all files.
  Corrected the previous PE-count and layout dependency of answers for cases
with open boundaries are not at the natural edges of the domain by storing the
previous barotropic velocities in ubt_prev and vbt_prev over a wider range of
loop indices, and by increasing the stencil size used in btstep_timeloop in such
cases.  Because the required loop range no longer matches the range over which
the new velocities are set in bt_loop_update_u() and bt_loop_update_v(), the
code setting these arrays has been moved out of these routines and into the main
body of btstep_timeloop().  This commit will change answers (and make them
invariant to the PE count and layout) in some cases, such as the ESMG-configs
Kelvin_wave/rotate45_BT and Kelvin_wave/rotate_BT test cases, where there are
southern open boundaries appearing in the northern halo regions on any PEs, for
example.  In all the Kelvin_wave test cases, the answers now agree with the
previous single-PE answers.  Most regional configurations with OBCs only apply
them at the edges of the domain and hence will not be impacted, and no answers
are changed in cases without open boundary conditions.
  This commit adds the new runtime parameters BT_WIDE_HALO_MIN_STENCIL and
DEBUG_BT_WIDE_HALOS to control the stencil width used with wide halos and to
specify whether the checksums for the entire active halo of values are written
when DEBUG_BT is enabled, or just the symmetric computational domain.  Setting
`BT_WIDE_HALO_MIN_STENCIL = 2` and `DEBUG_BT_WIDE_HALOS = False` provides for
cleaner checksums in some cases because they are invariant to the use of wide
halos, the width of those wide halos, or the relative positions of interior-
domain OBCs relative to PE boundaries.  This commit also changes a number of
velocity point checksums in btstep_timeloop to do symmetric output.  All model
solutions are bitwise identical regardless of how these new parameters are set,
but they can alter some debugging output.
Inconsistencies in jobs within a workflow were leading to differences in
compiler versions across jobs.  This was breaking GitHub Actions
workflows.  We want to continue using `*-latest` runners, so we have
merged the FMS stage into each of the MOM6 builds.

There are additional changes which improve the overall workflow/job
decomposition.

* FMS builds included in MOM6 stage

* Artifacts are now packed into tarballs, which preserve most of the
  file state (mtime, file mode, etc).

  * No longer any need to chmod the executables.

  * `*.gnco` timestamp warnings are removed.

  * Overall simplification of generated executable lists; we now
    assume that build/* only contains executables.

* build.timing and build.unit are now correctly tagged as .NOTPARALLEL

* Macros for defining the target URL are now environment variables,
  stored in the workspace `env`.
  Fixed spatial indexing bugs with Kelvin_set_OBC_data when the new runtime
parameter KELVIN_SET_OBC_INDEXING_BUGS is set to false.  All answers are
mathematically equivalent even when KELVIN_SET_OBC_INDEXING_BUGS is true, but
only because in the existing cases using Kelvin_set_OBC_data use an f-plane with
a uniform depth, but there are changes at roundoff with some compilers for some
of the ESMG/Kelvin_wave test cases.  Also added comments noting where there are
missing temporal variability factors.  By default, all answers are bitwise
identical but there is a new runtime parameter.
  Modified Kelvin_set_OBC_data to work properly with grid rotation of 90, 180 or
270 degrees.  With these changes the ESMG Kelvin_wave test cases are now giving
(mostly) bitwise identical answers under grid rotation.  This commit does change
(and fix) answers when grid rotation is used.  There are no changes to any
public interfaces.
update MOM6 to its main repo. 20250527 commit.
  Do not set non-segment 3d OBC arrays in the unrotated OBC type when grid
rotation is in use, and added a fatal error if there is an attempt to use grid
rotation with tracer reservoirs when OBC_RESERVOIR_INIT_BUG is true.  Also
eliminated duplicative statements nullifying these pointers after they have been
deallocated.  Also converted the non-segment 3d OBC arrays from pointers to
allocatables, as there is no longer any reason for them to be pointers.  All
answers are bitwise identical unless undergoing a grid rotation test, and the
grid rotation tests work properly for all cases with the relevant bugs disabled.
  Added the new on_face element to the OBC_segment_data_type to indicate where a
field is staggered, and the used this to simplify the code and the logical tests
in initialize_segment_data and update_OBC_segment_data.  The new function
field_is_on_face() is used to set the on_face elements.  Also, duplicated code
that determines whether data requirements have been satisfied has been moved
into a single block of code that used regardless of whether the data is
specified or provided from a file.  There is also the new routine field_is_tidal
that can be used to determine the appropriate vertical extent of a field within
the model.  With these changes, there has been a substantial consolidation of
the blocks of code that allocates and initializes the various input buffers.

  In addition, some of the duplicated code setting the tracer reservoir values
for temperatures, salinities and other "obgc" tracers has been consolidated into
a single block of code.  The code setting the SSH at boundaries was also
consolidated rather than having duplicate blocks with and without the ramping
enabled.  Several redundant logical tests or unneeded arrays were also
eliminated.

  With these changes, MOM_open_boundary.F90 is shorter by about 190 lines and
should be easier to read and maintain.  There are no changes to publicly visible
interfaces, and all answers are bitwise identical.
  Fix a bug in determining where to apply OBC-related masking when interpolating
v-velocities to u-points to calculate the surface friction velocity under ice
shelves.  It would usually only arise at eastward OBCs under ice-shelves, but it
could also occur for westward OBCs that are within a few points of the western
side of the domain.  This bug breaks rotational symmetry and reproducibility
across processor counts and layout when there are any open boundary conditions
under ice shelves.  However, there are no reports of the detection of any such
problems, and I am unaware of any cases using open boundary conditions under ice
shelves, so it seems very likely that there are no existing MOM6 configurations
that would trigger this specific bug.  Given all these considerations and the
resulting expectation that it is exceptionally unlikely that fixing this bug
would impact any existing work, rather than introducing a bug-fix runtime
parameter to retain this bug, this commit simply fixes it with the obvious
single-character correction.
  Set the sign of OBC%segnum_u and OBC%segnum_v to indicate the direction of
open boundary currents at the u- and v- velocity faces, with positive values at
logically eastern and northern boundary condition faces and negative values at
western and souther boundary condition faces.  This new information is used to
set open boundary condition properties in 10 files, while in 5 of these files
the absolute value is used to recover the previous answers.  Also added the new
elements u_OBCs_on_PE and v_OBCs_on_PE to the ocean_OBC_type.  All answers are
bitwise identical, but there are two new elements and an important change to two
elements of the publicly visible transparent ocean_OBC_type.
  Add 16 integer elements to the ocean_OBC_type to indicate the ranges of
indices over which various directions of open boundary conditions are found in
the data and computational domain of the local PE.  Also added 4 logical
elements that indicate whether each of the 4 orientations of OBCs are fond on
the local PE.All answers are bitwise identical, but there are 16 new integer
elements and 4 new logical elements in a transparent public type.
  Refactored the OBC-related code in 5 routines (set_viscous_BBL(),
vertvisc_coef(), find_coupling_coef(), calc_isoneutral_slopes() and
ALE_remap_set_h_vel_OBC()) in 4 modules to use the restricted OBC loop ranges
for the various orientations of OBCs for greater efficiency, and in some cases
to avoid the use of multiple levels of nested types and looping over segments
that seem to be causing problems with our efforts to port MOM6 to GPUs.  The
cases where the loop over the OBC segments continue to be used are those where
the details of the segments matter (and not just their orientation) or where
they are being applied in ways where the order of the segments might matter.
All answers are bitwise identical, and there are no changes to any publicly
visible interfaces.
  Added the new parameter INTERPOLATED_SQG_STRUCTURE that can be set to false to
avoid interpolating properties to velocity points and then interpolating the
buoyancy frequencies and layer thicknesses back to tracer points when
calculating the SQG vertical structure.  This involves extensive additions to
calc_sqg_struct() to calculate the SQG vertical structure on an individual
column without interpolation.  The new code also cancels out common thicknesses
in the numerator and denominator and uses thickness_to_dz() to find the vertical
extents of the layers rather than using find_eta() and taking a difference
between the heights of pairs of interfaces, making it far less susceptible to
roundoff errors and able to work properly with vanishing layers.  The one change
when this new option is not set to false is that the diagnostics of N2_u and
N2_v are no longer posted when SQG_EXPO is not positive, although it is not
clear to me that these diagnostics should ever be posted from this routine.  The
default for INTERPOLATED_SQG_STRUCTURE is true, but I suspect that all of this
interpolation of N2 may be undesirable, especially as it might lead to
problematic behavior near coastlines or seamounts, and I will recommend that the
default be changed to false once this can be done gracefully without disrupting
any applications that are already using calc_sqg_struct().

  As a part of these changes, SQG_EXPO will only be logged when it would
actually be used, and the logic governing a number of deallocate calls in
VarMix_end() was simplified.  The Laplac3_const_u, Laplac3_const_v, KH_u_QG and
KH_v_QG elements of the VarMix_CS were converted from potentially static arrays
to allocatable arrays to reduce the MOM6 memory footprint when they are not
in use.  These should always have been allocatable, and there is no change
when MOM6 is not in static memory mode.

  By default all solutions are bitwise identical, but there is a new runtime
parameter that will appear in some MOM_parameter_doc files, while another unused
runtime parameter will disappear from others.
  Converted 28 arrays from potentially static using the ALLOCABLE_ and ALLOC_
macros into dynamic arrays in three modules.  This change reduces the static
memory footprint of MOM6.  These arrays are only ever used conditionally based
on parameter settings, so they should never have been declared using these
static memory macros.  All answers are bitwise identical and there are no
changes to any public interfaces.
* Add conditional halo pass for frazil inside make_frazil

Frazil may need an extra halo pass, but only when all of the following are true:
(1) frazil is calculated and applied in the halo (e.g., vertex_shear is true)
(2) the thermodynamic loop is called more than once before passing frazil to the sea-ice (dt_therm<dt_cpld)
(3) reclaim_frazil is true
(4) a previous make_frazil was called after the diabatic loop and before T&S were updated in halos.

This commit adds the halo pass inside make_frazil since it is where we can know all of these conditions at once.  We needed to add a flag to know if frazil was reset (which happens if dt_therm>=dt_cpld), in which case the halo pass would be unnecessary.  We needed an optional argument for make_frazil so we could flag to only do this update on the first call to make_frazil (which is needed because the previous call to make_frazil was after the diabatic loop, condition 4)

* Shorten line in MOM_diabatic_driver

* Move halo update on frazil out of make_frazil and into post_diabatic_halo_updates

---------

Co-authored-by: brandon.reichl <brandon.reichl@noaa.gov>
Hallberg-NOAA and others added 30 commits March 20, 2026 18:07
  Refactored 34 calls to real_to_time() to use the new unscale argument and
replaced 16 calls to time_type_to_real() with calls to the new routine
time_to_real(), of which 15 use a scale argument.  Also use the new scale
argument in 5 calls to time_minus_signed().  In four instances, extensive
expressions for the end of a diagnostic interval are being stored in new
temporary time-type variables.  Although these changes lead to some lines that
are longer than before, the use of the scale and unscale arguments makes it much
easier to detect incorrect rescaling factors.  All answers are bitwise
identical.
This commit reworks segment%field array. Previously, the array is
dynamically decided by available input fields, i.e. segment%num_fields
= number of input fields + number of BGC tracers. Problems: 1) indexing
of the field is not fixed. 2) There is no direct one-on-one mapping
between field array and a dozen of xxx_needed flags in segment.

The new approach always creates a field array with its first 13 members
being the 13 physical fields, which predetermines the indexing. It also
merges the xxx_needed flags to their corresponding fields. Note that
only used/available fields have their buffer_src and buffer_dst arrays
allocated, so there is no additional memory cost.

With the new structure, initialize_segment_data is refactored to have
four steps,
1) Initialize 13 physical fields, including toggling required fields
using subroutine segment_determine_required_fields.
2) Create a list of available inputs from parameter file and map their
indices with the 13 physical fields.
3) Allocate available physical fields. (allocated() = is_available)
4) Determine and allocate BGC fields.

Misc
* Two new subroutine/function
  * subroutine segment_determine_required_fields
  * function find_phys_field_index
* The model stops if a variable not in the 13 physical field is given.
* The model stops if there is a required input missing and informs which
segment and field.
* A warning is now issued if a field is provided but not needed.
* MAX_OBC_FIELDS (=100) is replaced by NUM_PHYS_FIELDS (=13)
* Remove all x_values_needed flag and 6 indices to locate tidal fields
* Remove subroutine rotate_OBC_segment_values_needed
* Apply fixed indices to tidal fields in update_OBC_segment_data
- MOM_ice_shelf_dynamics.F90: split loop_bounds_type members (ish, ieh,
- MOM_ice_shelf.F90: add missing = -1 initializer to id_dhdt_shelf

A disclosure: Copilot has been used to make these changes.
t17d and t20d are the depth of the 17 and 20 degC isotherms
respectively, measured from the surface. Interpolation is done
via Recon1d reconstruction and then a new function in the class
that solves that inverts the reconstruction. This solver was not
in the original class because I had originally only thought it
would be used in the new grid generator which interpolates
density and not for the reconstructed field. Since some other
diagnostics for CMIP will make use of remapping or T, I figured
we might as well use the reconstructions to do the interpolation.

- adds to new registrations and posts in MOM_diagnostics
- adds function `%x(self, k, val)` to the Recon1d class.
  Revised the MOM_ice_shelf_diag_mediator code that creates the
MOM_IceShelf.available_diags file to follow the same pattern of logging as the
rest of MOM6.  The specific changes include moving the module name(s) to their
own line, adding static diagnostics to the variables that are logged in the
available_diags file (however, the ice shelf code does not have any static
diagnostics yet), logging the axes of the diagnostic, and adding cell metrics to
describe how a diagnostic might be reduced and logging these as well.  All
solutions are bitwise identical, but there are new entries and added information
in the MOM_IceShelf.available_diags files.
  Modified set_IS_axes_info() to follow the pattern from the rest of MOM6 and
take the units for the horizontal axes from the grid type.  In most cases, this
has the effect of changing the units from "degrees_E" and "degrees_N" to
"degrees_east" and "degrees_north" to follow CMIP protocols, and to mirror
changes that were made to the standard MOM6 framework code in 2017.  The names
of the gridspace axes were changed from `xB`, `yB`, `xT` and `yT` to `Iq`, `Jq`,
`ih` and `jh` to mirror the names in MOM6.  The long descriptions of these array
axis variables were also updated for clarity when `USE_INDEX_DIAGNOSTIC_AXES` is
true.  All solutions are bitwise identical, but there are changes to the
metadata and axis variable names in some output files, and some runtime
parameters that had been read from both `set_IS_axes_info()` and
`set_grid_metrics()` in MOM_grid_initialize.F90 are now only read in the latter
routine.  As a result of these changes, `set_IS_axes_info()` no longer takes a
`param_file_type` argument and the grid argument is now `intent(in)`.
  Added a missing dimensional scaling argument in the test for when to write
harmonic analysis diagnostics in HA_accum.  Also used the new unscale argument
in 2 calls to real_to_time in HA_init and used the new scale argument in one
call to time_to_real in HA_accum.  Answers and diagnostics are bitwise identical
when scaling is not applied, but this does correct a problem where some
diagnostics may have been written at the wrong time previously when dimensional
rescaling of time is being used.
  Edited the conversion factors for the 'ale_u2' and 'ale_v2' diagnostics to use
an equivalent form that makes it a little more obvious that the conversion
factors correspond to the declared units.  All answers are bitwise identical.
  This commit clarifies a number of comments in the MOM_diag_mediator.  It also
corrects multiple instances of spelling errors or non-standard use of white
space in comments.  There was also some rearrangement of module use statements
and the elimination of other unneeded module use calls.  Only comments or
spacing are changed, and all answers are bitwise identical.
A locally allocated array was uninitialized which is harmless for most configurations
that use time-filtering in the vertical grid generation. The time-filter uses land
masks and sets things to zero on land. Without the time-filter, we encountered non-
reproducible behavior on the root PE.

I also de-allocated a local variable (Rb) used on another if-branch in the same routine.
This commit refactors update_OBC_segment_data using the previously
introduced new structure segment%field component. Specifically, the code
that calculates normal_vel, normal_trans, normal_trans_bt,
tangential_vel gradient and external values of tracer / thickness
reservoir, is updated. The changes include,

* The previous loop + if structure is replaced by direct indexing of the
physical fields.
* Tidal velocity and SSH code is refactored to cji structure (c for
constituent), rather than an embedded if-branch within [ji] loop of a
[ij]c structure.
    * As a result, segment has three new 2D arrays, tidal_v[nt] and
    tidal_elev.
* Introduce orientation-agnostic looping indices [ij][se]_seg, currently
only used for tracer cell fields.
* Add tr_index in OBC_segment_data_type (segment%field) to facilitate
reservoir update.
* Add Newton iterations for the ice-shelf velocity solution

The previous Shallow Shelf Approximation solution used an iteration-on-viscosity scheme with Picard
iterations only. This commit adds the capability to change to Newton iterations once a certain
tolerance is met, which should reduce the number of iterations needed to reach convergence. This
tolerance to change to Newton is set by the new parameter NEWTON_AFTER_TOLERANCE. This parameter
defaults to the same value of ICE_NONLINEAR_TOLERANCE so that Newton is not called by default. The
Newton scheme is paired with the Eisenstat & Walker 1994 approach for adapting the CG tolerance to
help the Newton scheme achieve quadratic convergence without over-tightening at later Newton
steps. To use the adaptive CG tolerance, set NEWTON_ADAPT_CG_TOLERANCE=True (default is True).

* Newton iteration PR fix

Style changes, parentheses, removed string comparison from loops

* Pass_var optimization and FMAs

Made some changes to pass_var 'complete' arguments for Newton-related
variables. Also removed some Newton-related pass_vars and a
CS%doing_newton=.false. that were made before entering the the SSA
solution loop (at this point, Newton is already false, and there is no
need to update Newton-related halos yet). Added parentheses for
rotational symmetry with FMAs.
  Replaced "end if" with "endif" in 35 places in 10 files and "end do" with
"enddo" in 12 places in 4 files to comply with the MOM6 style guide.  In
addition, in 23 places in 7 files, code like `if(test)` were replaced with
`if (test)`, also to align with the MOM6 style guide.  All answers are
bitwise identical.
  Removed 41 trailing semicolons (MOM6 is in Fortran, not C).  In 406 other
lines of code the white space around semicolons was standardized to ' ; ' to
match the other ~14000 lines of code with semicolons joining Fortran statements
on the same line.  In a few cases there were also some improvements to indents
related to these changes.  With these changes, all semicolons that could be
replaced with a newline and still have correct Fortran follow the ' ; '
pattern.  These changes are scattered across 86 files.  Most of these changes
involve only white space, and all answers are bitwise identical.
Create a new subroutine read_OBC_segment_data out of a very chunky
update_OBC_segment_data. The new subroutine enables better control on
whether the update is associated with new external data through IO or
just recalculation (with evolved model internal state, i.e thickness,
tides).

Misc
* Use orientation-agnostic loop indices for segment%h and segment%htot
* Add [ij]_offset_in to loop over interior cells
* Field segment%Cg, which is never used, is now removed.
Create a new subroutine initialize_OBC_segment_reservoirs to initialize
thickness and tracer reservoir of OBC segments. This part of code was
original part of update_OBC_segment_data, but it is only called during
initialization.
This commit fixes a bug in particle advection of particles that are advected by uh and vh. When the tracer timestep doesn't match the dynamics timestep, these particles need to be advected using the tracer timestep. The previous version of the code sometimes leads to unphysical particle movement, and this commit fixes the issue.
  Added the new interfaces `symmetric_sum()` and `symmetric_sum_unit_tests()` to
the MOM_array_transform module, and added a call to `symmetric_sum_unit_tests()`
to `unit_tests()`.  The two functions wrapped by the `symmetric_sum()` interface
are intended to be a general template for rotationally symmetric sums, but they
demonstrably work as intended (as demonstrated by the passing unit tests) for
any rectangular arrays.  The new driver in test_MOM_array_transform.F90 tests
these new arrays.  Although `symmetric_sum()` is not used yet in the MOM6 code
apart from the tests, it was developed to address problems with failures of
rotational symmetry in the diagnostic downscaling routines, and will be used
there soon.  All answers are bitwise identical, but there are two new publicly
visible interfaces.
Resolves merge conflict due to new PLM_WLS test.
This commit refactors normal velocity/transport calculation in
update_OBC_segment_data, using the orientation-agnostic loop ranges.
Note that there is still an orientation-branch because the grid spacing
G%dyCu and G%dxCv are different.

* The field segment%h is removed, as we can just use h directly.
* Comments are added to better illustrate the subroutine structure
Remove inaccurate warning message in logs when OBC_TEMP_SALT_NEEDED_BUG
is false but temperature and salinity are needed and provided.
This commit fixes the bug that OBC segment data does not update if only
value mode is used for all segments. Previously, there were two issues,

1. Subroutine update_OBC_data, which is a wrapper over subroutine
update_OBC_segment_data is only called if global flag OBC%update_OBC is
True. This flag, however, is only turned on if there OBC is specified by
files.
2. Inside of update_OBC_data, subroutine update_OBC_segment_data is only
called if global flags OBC%any_needs_IO_for_data or
OBC%add_tide_constituents is True, which again prohibits OBC update with
"value".

Example: if normal velocity is specified by value, the transport is
calculate once during initialization using initial thickness. And the
transport is never updated through the run. And the model will restart
with a different transport.

A new runtime parameter OBC_VALUE_UPDATE_BUG is added to fix/recover
this bug. In addition, OBC%update_OBC is set to True if
initialize_segment_data is called. a separate procedure is added to set
any_needs_IO_for_data, for clarity.
  Added diag_mediator capabilities that had been developed and used in the SIS2
and MOM_ice_shelf versions of the diag mediator, in preparation for some of
these separate versions to be combined into a single version.  This includes
adding an overload to the register_scalar_field() interface so that scalars can
be registered with or without providing a null axis, retaining the existing
interface while adding the one that is widely used with the ice shelf code.  The
previous routine register_scalar_field() is now register_scalar_field_CS(), but
it has the same public interface.

  This commit also adds the new public interface MOM_diag_send_complete() that
calls the FMS routine that flushes the IO buffers.  Although this call can be
too expensive for production runs, it can be very useful for debugging.

  Internally, register_diag_field() now checks for standard axes for 2-d fields,
analogously to what was previously done for 3-d fields, thereby avoiding the
allocation of a separate axis group for each 2-d diagnostic.  This has been the
case for ice-shelf code for some time, and it will save memory will giving
identical results.

  The testing for incompatible mask and array sizes was consolidated into a
single call each in post_data_2d_low() and post_data_3d_low(), paving the way
for adding the option of masking static fields.

  All solutions are bitwise identical and diagnostic output (including metadata)
is identical to what was previously output, but there are two new public
interfaces.
  Renamed the q-point index space axis names to be uniformly Iq and Jq, rather
than having names that change depending on whether or not symmetric memory is
being used.  This commit also changes the long names of the grid space axes to
be consistent between the x and y axes and to mirror those that have been
adopted in the ice shelf code.  The order of the logical tests for index space
axes and symmetric memory around the calls to diag_axis_init were swapped to
that corresponding cases are next to each other, perhaps making any
inconsistencies more obvious.  There were also minor changes to the code setting
the axis label variables to follow the MOM6 case convention for indices and the
spacing conventions for assignments, as described in the MOM6 style guide.  All
solutions are bitwise identical, but there are changes to the names of the axis
label variables and their long descriptions when USE_INDEX_DIAGNOSTIC_AXES is
true.
  Corrected the cell_methods for 8 families of tracer content tendency
diagnostics.  Without this change, the 2-fold downscaled tendencies are 4 times
too large, and the 3-fold downscaled tendencies 9 times too large.  The
misleading comment describing the local `conv_units` string variable in
register_tracer_diagnostics() was also fixed.  All solutions and standard
diagnostics are bitwise identical, but there are changes in the values of
downscaled diagnostics and changes in metadata.
Makedep preprocessor parsing assumed define macros of the form `#define
macro(X) some-macro` but did not support empty macros of the form
`#define macro(X)`.

Preprocessor flag macros were assumed to be of the form `-DMACRO=VALUE`,
and did not support empty macros `-DMACRO`.

This patch addresses both issues.
…_vars

- To reproduce across restart files requires an additional halo update on diffu and diffv in MOM_dynamics_split_RK2.F90
- To reproduce across layouts with vertex shear option requires a halo update on thickness before remapping the viscosities on the vertex points.
- Setting BBL_USE_TIDAL_BG = True causes the model to fail dimensional consistency test.  If you set the spatial scale as m_to_L instead of m_to_Z in MOM_set_viscosity it fixes the issue.
- Fixing documentation fo L/T scaling of tideamp
  - Change suggested Hallberg
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.