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

*Fix indexing bugs in get_field_nc #334

Merged

Conversation

Hallberg-NOAA
Copy link
Member

Fixed two horizontal indexing bugs in get_field_nc(), where the difference between the array starting index (always 1 in this subroutine) and the values in the handle argument were not being taken into account when the array was being passed in with only its computational domain. Also initialized the internal unlim_index array in get_netcdf_fields() to fix a problem with using an uninitialized array that was being flagged when run in debug mode. With this commit, the model is once again reproducing the expected answers when rescaling is applied for vertical distances or time. All answers are bitwise identical in cases that were working before.

This commit addresses the issue at github.com//issues/333, which can be closed once this commit is merged into dev/gfdl.

  Fixed two horizontal indexing bugs in get_field_nc, where the difference
between the array starting index (always 1 in this subroutine) and the values
in the handle argument were not being taken into account when the array was
being passed in with only its computational domain.  Also initialized the
internal unlim_index array in get_netcdf_fields to fix a problem with using an
uninitialized array that was being flagged when run in debug mode.  With this
commit, the model is once again reproducing the expected answers when rescaling
is applied for vertical distances or time.  All answers are bitwise identical
in cases that were working before.

  This commit addresses the issue at github.com/NOAA-GFDL/issues/333, which
can be closed once this commit is merged into dev/gfdl.
@Hallberg-NOAA Hallberg-NOAA added bug Something isn't working answer-changing A change in results (actual or potential) labels Mar 11, 2023
@codecov
Copy link

codecov bot commented Mar 11, 2023

Codecov Report

Merging #334 (e07249c) into dev/gfdl (ceb4c92) will increase coverage by 10.41%.
The diff coverage is n/a.

❗ Current head e07249c differs from pull request most recent head daea32f. Consider uploading reports for the commit daea32f to get more accurate results

@@              Coverage Diff              @@
##           dev/gfdl     #334       +/-   ##
=============================================
+ Coverage     37.16%   47.58%   +10.41%     
=============================================
  Files           265       41      -224     
  Lines         74508     4535    -69973     
  Branches      13839      797    -13042     
=============================================
- Hits          27692     2158    -25534     
+ Misses        41722     2197    -39525     
+ Partials       5094      180     -4914     

see 234 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

This patch addresses some of the proposed changes to `get_field_nc`.

* `WARNING` is removed from `use MOM_error_handler` since it is unused.

* Zero initialization of `values_c` by `source=` has been removed.

  This initialization serves no purpose, since every value will be
  filled by the netCDF read statement.

* `values_c` indexing is now 1-based

  `values` has ambiguous shape, so it can follow no natural indexing.
  Although `values_c` always resides on the compute domain, the transfer
  to `values` may feel unintuitive.  Allocating from the 1 index
  identifies this as an explicit transfer of 1-based indices.

* Computation of the data domain indices were moved to the actual
  transfer of `values_c` to `values`.

* A comment was added to explain the initial "magic value" of
  `unlim_index`.

(It has also been suggested that the zero initialization of the intent(out)
`values` array should be removed, even when it has halos that would not be set
here.  However, this was deemed beyond the scope of this bug-fix PR, so this
commit was edited during merging to restore the initialization of `values` to
exactly what was there on the dev/gfdl branch before this PR, leaving this
particular change to be addressed with a later PR as necessary. - R. Hallberg)

Stylistic changes consistent with the existing file have also been
imposed:

* `values_nc` renamed to `values_c`

  Previous suffix indicated some special netCDF property of this field,
  when it's just the compute subdomain of the field's values.

* Comments have been truncated for readability

* Column width is restricted to 80

* Composite statements (semicolons) have been removed
@Hallberg-NOAA Hallberg-NOAA force-pushed the get_field_nc_indexing_bugfix branch from 7f9b66e to e0fcbc7 Compare March 13, 2023 12:19
  Made the values argument to MOM_read_data_2d and get_field_nc intent inout to
preserve the previous values of this array in any halos it might have, and
removed a line initializing the halos of this array to 0.  Also added some
missing comments describing arguments to these routines  and changed the
existing comments describing the arguments to get_field_nc to use doxygen
syntax.  All answers in test cases are bitwise identical.
@Hallberg-NOAA
Copy link
Member Author

I have now changed the values arguments to get_field_nc() and read_netCDF_data_2d() to be intent(inout), as discussed in the conversation regarding the updated pull request related to this on upstream branch, and I suspect that this PR is ready to go.

@raphaeldussin
Copy link

cannot comment much on the code (LGTM) but this fix is necessary to run OM4 with debug compiler flags or else it dies trying to read the tidal amplitude file.

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.

Not a fan of the comment bloat in daea32f but you've worn me down. I approve.

@marshallward
Copy link
Member

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

@marshallward marshallward merged commit 37389b5 into NOAA-GFDL:dev/gfdl Mar 26, 2023
@Hallberg-NOAA Hallberg-NOAA deleted the get_field_nc_indexing_bugfix branch May 10, 2024 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answer-changing A change in results (actual or potential) bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

read_netCDF_data leads to cryptic model failure when rescale value argument is not 1
3 participants