Skip to content

bugfix for handling unstructured input data with multiple levels#26

Merged
mvertens merged 18 commits into
NorESMhub:noresmfrom
mvertens:feature/fix_unstructured_multilev_input
Dec 31, 2025
Merged

bugfix for handling unstructured input data with multiple levels#26
mvertens merged 18 commits into
NorESMhub:noresmfrom
mvertens:feature/fix_unstructured_multilev_input

Conversation

@mvertens
Copy link
Copy Markdown
Collaborator

@mvertens mvertens commented Dec 18, 2025

Description of changes

This fixes #25

Specific notes

This PR also does the following:

  • new error checking for most allocations
  • cleanup of stdout formatting
  • replacement of character(*) with character(len=*)
  • introduction logunit and mainproc in shr_strdata_type and both logunit and mainproc in shr_stream_streamType. This is needed since the inline interface was not always writing all log output consistently.
  • new expanded API for setting stream pointers with optional arguments in dshr_strdata_mod.F90 for
    shr_strdata_get_stream_pointer_1d and shr_strdata_get_stream_pointer_2d
 subroutine shr_strdata_get_stream_pointer_1d(sdat, strm_fld, strm_ptr, rc, requirePointer, errmsg) 
    type(shr_strdata_type)     , intent(in)    :: sdat
    character(len=*)           , intent(in)    :: strm_fld
    real(r8)                   , pointer       :: strm_ptr(:)
    integer                    , intent(out)   :: rc
    logical,          optional , intent(in)    :: requirePointer
    character(len=*), optional , intent(in)    :: errmsg

and

 subroutine shr_strdata_get_stream_pointer_2d(sdat, strm_fld, strm_ptr, rc, requirePointer, errmsg) 
    type(shr_strdata_type)     , intent(in)    :: sdat
    character(len=*)           , intent(in)    :: strm_fld
    real(r8)                   , pointer       :: strm_ptr(:,:)
    integer                    , intent(out)   :: rc
    logical,          optional , intent(in)    :: requirePointer
    character(len=*), optional , intent(in)    :: errmsg

If requirePointer is not provided - then if the pointer is not round the subroutine returns without an error. If requirePointer is an argument and is true, than normally an errmsg is provided that with it describes why the pointer is required. Also - now if the pointer is required and is found - then the pointer is initialized to NaN.
The new setting of NaNs in the stream and state pointers resulted in the following additional changes that needed to be brought in:

  • refactored dlnd code to remove presence of present nans in stream pointers
  • fixed problem in drof that came up due to presence of presence of nans
  • fixed problem in datm/cplhist that cam up due to presence of nans

Contributors other than yourself, if any: None

CDEPS Issues Fixed: #25

Are there dependencies on other component PRs: None

Are changes expected to change answers (bfb, different to roundoff, more substantial): bfb

Any User Interface Changes (namelist or namelist defaults changes): None

Testing performed:

  • Correctly reading in nudging data at ne16pg3 with 58 vertical levels.
  • aux_clm_noresm compared to ctsm5.4.002_noresm_v1 passed
  • aux_blom_noresm compared to noresm3_0_beta09 passed
  • aux_cam_noresm compared to noresm3_0_beta09 passed
  • noresm_prealpha compared to noresm3_0_beta09 passed

Hashes used for testing:
noresm3_0_beta09 with this PR

@mvertens mvertens requested a review from mvdebolskiy December 18, 2025 10:40
@mvertens mvertens added the bug Something isn't working label Dec 18, 2025
@mvertens mvertens requested review from gold2718 and removed request for mvdebolskiy December 24, 2025 21:57
Copy link
Copy Markdown
Collaborator

@gold2718 gold2718 left a comment

Choose a reason for hiding this comment

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

I found a few items that need fixing. Is there a way to test all the log output to make sure it is happening correctly?

Comment thread streams/dshr_strdata_mod.F90 Outdated
Comment thread streams/dshr_strdata_mod.F90 Outdated
Comment thread dlnd/dlnd_datamode_glc_forcing_mod.F90
Comment thread dlnd/dlnd_datamode_glc_forcing_mod.F90 Outdated
Comment thread dlnd/dlnd_datamode_glc_forcing_mod.F90 Outdated
Comment thread streams/dshr_stream_mod.F90 Outdated
Comment thread streams/dshr_stream_mod.F90 Outdated
Comment thread streams/dshr_stream_mod.F90 Outdated
Comment thread streams/dshr_stream_mod.F90 Outdated
Comment thread streams/dshr_stream_mod.F90 Outdated
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in NorESM Development Dec 28, 2025
@mvertens mvertens requested a review from gold2718 December 30, 2025 12:20
@mvertens
Copy link
Copy Markdown
Collaborator Author

@gold2718 - thanks for your careful review - I think this is ready for another review.

Copy link
Copy Markdown
Collaborator

@gold2718 gold2718 left a comment

Choose a reason for hiding this comment

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

I still have some requests. Most of these are suggested improvements, however, there are a couple of statements which could cause problems or crash the run.

Comment thread streams/dshr_strdata_mod.F90 Outdated
Comment thread streams/dshr_strdata_mod.F90 Outdated
Comment thread streams/dshr_strdata_mod.F90 Outdated
Comment thread streams/dshr_strdata_mod.F90 Outdated
Comment thread streams/dshr_strdata_mod.F90
Comment thread streams/dshr_stream_mod.F90 Outdated
Comment thread streams/dshr_stream_mod.F90 Outdated
Comment thread streams/dshr_stream_mod.F90 Outdated
Comment thread streams/dshr_stream_mod.F90 Outdated
Comment thread streams/dshr_stream_mod.F90 Outdated
@mvertens
Copy link
Copy Markdown
Collaborator Author

@gold2718 - I've addressed all of your comments. Thanks for catching the problems.

@mvertens mvertens requested a review from gold2718 December 31, 2025 11:57
Copy link
Copy Markdown
Collaborator

@gold2718 gold2718 left a comment

Choose a reason for hiding this comment

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

This looks okay now.

@mvertens mvertens merged commit ea91ddb into NorESMhub:noresm Dec 31, 2025
@github-project-automation github-project-automation Bot moved this from In Progress to Done in NorESM Development Dec 31, 2025
@mvertens mvertens self-assigned this Dec 31, 2025
@mvertens mvertens deleted the feature/fix_unstructured_multilev_input branch January 9, 2026 17:37
gold2718 added a commit to NorESMhub/CAM that referenced this pull request Apr 23, 2026
noresm3_0_031_cam6_4_121: refactor nudging code to use CDEPS

Summary: Refactor nudging code to use CDEPS on line remapping and interpolation

Contributors: @mvertens, @gold2718, @Ovewh

Reviewers: @gold2718

Purpose of changes:
The current nudging code (nudging.F90) requires a single file for every time sample - and often this is every 6 hours. In addition it does not do any mapping from the forcing data to the model grid. Using the CDEPS inline functionality along with its capability to do online horizontal regridding (including for multiple vertical levels) and time interpolation the nudging code has been completely refactored. With this new code - monthly nudging data can be read at just one resolution and the model vertical levels and used with any model grid.
The one change that comes with this is if there is missing data. In the original scheme, if missing data was encountered then the model 'coasted' through the forcing interval and was not nudged. In the new scheme, the time interpolation (linear or upper) is used with the actual data that is available.

To see more details of the inline functionality from CDEPS used here see: https://escomp.github.io/CDEPS/versions/master/html/index.html and in particular https://escomp.github.io/CDEPS/versions/master/html/streams.html#data-model-stream-inline-api

Changes made to build system: None

Changes made to the namelist: The following new namelist variables were introduced:
Nudge_Filenames, Nudge_Meshfile, Nugde_beg_day, Nudge_beg_month, Nudge_beg_year, Nudge_end_day, Nudge_end_month, Nudge_end_year, Nudge_file_times_per_day, Model_update_times_per_day

Changes to the defaults for the boundary datasets: None

Substantial timing or memory changes: TODO - the expectation is that the new code should be faster than the old one since a new file does not have to be opened and closed at every nudging time step. This needs to be confirmed.

Validation:
The following validation was run. using a noresm3_0_beta09 sandbox with this PR and the CDEPS PR NorESMhub/CDEPS#26. Two simulations were done - a reference simulation and a nudging to the reference simulation.

Testing:

- Two tests were added to aux_cam_noresm which test this functionality
- Tested on Betzy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

failure to read unstructured data with a vertical dimension

2 participants