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

+(*)Grid rotation now works with restarts #787

Open
wants to merge 3 commits into
base: dev/gfdl
Choose a base branch
from

Conversation

Hallberg-NOAA
Copy link
Member

@Hallberg-NOAA Hallberg-NOAA commented Dec 26, 2024

This PR consists of 3 commits that together will allow for simulations with grid rotation to properly read restart files and write restart files that are equivalent to those that are generated with an unrotated grid. The restart are not identical because the FMS field_chksum() function is giving different answers for equivalent arrays for reasons that are not yet understood, so for now the use of the restart files with rotated grids will only work in some cases when RESTART_CHECKSUMS_REQUIRED = False. The first two commits add new optional arguments to I/O related framework routines to facilitate these changes, while the third commit makes the necessary changes to MOM_restart and the initialization of the model from a re start file.

Added the new zero_zeros optional argument to the 10 MOM_write_field() routines in MOM_io and the 6 rescale_comp_data()routines inMOM_domain_infra` to cause negative zeros to replaced with ordinary signless zeros before they are written out to files. This has no impact at all on answers, but it does help with comparisons between rotated restart files, in which meaningless differences between positive and negative zeros were leading to false differences between files.

Added a new turns optional argument to 6 versions of the MOM_read_data() routines to allow for the reading to override the number of turns in theMOM_domain that is passed into these routines. Several internal turns variables in the same routines were renamed qturns to allow for the new optional arguments. Also check for whether the MOM_domain%domain_in pointer is associated before it is used, avoiding a segmentation fault that was occurring when a restart file is read and ROTATE_INDEX = true.

Modified MOM_restart() so that restart files generated by rotated runs match unrotated restart files, and the model can be properly initialized from a restart file when the grid is rotated. Also added runtime options to convert negative zeros into ordinary zeros before they are written to restart files (selected with RESTART_UNSIGNED_ZEROS) and to properly do the checksums on the velocity points on all of the faces (selected with RESTART_SYMMETRIC_CHECKSUMS).

Also added the new interfaces copy_restart_var() and copy_restart_vector() to use the names of restart variables and the pointers stored in the restart control structure to obtain a copy of the variables as the restart variables with the
option to undo grid rotation. These routines are necessary because the reading of restart files occurs during a phase of the model initialization that works on an unrotated grid, and they are called from inside of MOM_initialize_state.

The ranges for the checksums stored in restart files are now set correctly for each variable, depending on where it is discretized, but when RESTART_SYMMETRIC_CHECKSUMS = false (the default), the previous ranges are still used so answers do not change in unrotated test case.

The conversion factors used for the pair of register_restart_field() calls in register_restart_pair() now include the necessary sign changes for the rotation, as set in the new internal routine set_conversion_pair(). There is also now a scalar_pair optional argument to the register_restart_pair() routines to accommodate the rotation of pairs of
scalars that do not change sign when rotated (e.g., grid-lengths).

Instead of working with the hor_grid character string, the restart code has been modified to instead use the encoded integer position argument returned from query_vardesc(). This avoids several redundant blocks of code that translate the hor_grid strings into positions.

All answers are bitwise identical when there is no grid rotation, but with grid rotation the restart files that are created are modified to have the correct signs and replicate the restart fields with no rotation. Also, cases with grid rotation can now be reinitialized from restart files, while previously this simply did not work, either giving an incorrect reinitialized state or a
segmentation fault. There are two new runtime parameters in some MOM_parameter_doc files, and there are new optional arguments to several publicly visible routines. This commits in this PR include:

  • e33f93f90 (*)+Modified MOM_restart to fix rotated restarts
  • 671884f74 +Add turns argument to MOM_read_data
  • 0806e1e80 +Add zero_zeros optional arg to MOM_write_field

  Added the new zero_zeros optional argument to the 10 MOM_write_field routines
in MOM_io and the 6 rescale_comp_data routines in MOM_domain_infra to cause
negative zeros to replaced with ordinary signless zeros before they are written
out to files.  This has no impact at all on answers, but it does help with
comparisons between rotated restart files, in which meaningless differences
between positive and negative zeros were leading to false differences between
files.  All answers are bitwise identical, and all output is equivalent, but
there are new optional arguments to 16 routines covered by 2 publicly visible
interfaces.
  Added a new turns optional argument to 6 versions of the MOM_read_data
routines to allow for the reading to override the number of turns in the
MOM_domain that is passed into these routines.  Several internal turns variables
in the same routines were renamed qturns to allow for the new optional
arguments. Also check for whether the MOM_domain%domain_in pointer is associated
before it is used, avoiding a segmentation fault that was occurring when a
restart file is read and ROTATE_INDEX is true.  These changes are necessary to
allow for the model to be initialized from a restart files with rotated grids.
Several instances of continuation line indentation that do not follow the
typical 4-space pattern used elsewhere in the MOM6 code and documented in the
MOM6 style guide were also altered to follow the standard.  All answers that
previously worked are bitwise identical, but there are new optional arguments to
publicly visible interfaces.
@Hallberg-NOAA Hallberg-NOAA added bug Something isn't working enhancement New feature or request Parameter change Input parameter changes (addition, removal, or description) labels Dec 26, 2024
  Modified MOM_restart so that restart files generated by rotated runs match
unrotated restart files, and the model can be properly initialized from a
restart file when the grid is rotated.  Also added runtime options to convert
negative zeros into ordinary zeros before they are written to restart files
(selected with RESTART_UNSIGNED_ZEROS) and to properly do the checksums on the
velocity points on all of the faces (selected with RESTART_SYMMETRIC_CHECKSUMS).

  Also added the new interfaces copy_restart_var and copy_restart vector to use
the names of restart variables and the pointers stored in the restart control
structure to obtain a copy of the variables as the restart variables with the
option to undo the rotation.  These routines are necessary because the reading
of restart files occurs during a phase of the model initialization that works on
an unrotated grid, and they are called from inside of MOM_initialize_state.

  The ranges for the checksums are now set correctly for each variable,
depending on where it is discretized, but when RESTART_SYMMETRIC_CHECKSUMS is
false, the previous ranges are still used so answers do not change in unrotated
test case.

  The conversion factors used for the pair of register_restart_field calls in
register_restart_pair now include the necessary sign changes for the rotation,
as set in the new internal routine set_conversion_pair.  There is also now a
scalar_pair optional argument to the register_restart_pair routines to
accommodate the rotation of pairs of scalars that do not change sign when
rotated (e.g., grid-lengths).

  Instead of working with the hor_grid character string, the restart code has
been modified to instead use the encoded integer position argument returned
from query_vardesc.  This avoids several redundant blocks of code that translate
the hor_grid strings into positions.

  All answers are bitwise identical when there is no grid rotation, but with
grid rotation the restart files that are created are modified to have the
correct signs and replicate the restart fields with no rotation.  Also, cases
with grid rotation can now be reinitialized from restart files, while previously this
simply did not work, either giving an incorrect reinitialized state or a
segmentation fault.  There are also two new runtime parameters in some
MOM_parameter_doc files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request Parameter change Input parameter changes (addition, removal, or description)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant