Skip to content

Conversation

@mvertens
Copy link
Collaborator

@mvertens mvertens commented Jan 12, 2026

Description of changes

Major refactor of stream usage

Specific notes

All data mode files across the data components(except for datm_datamode_gefs_mod.F90 and dice_datamode_cplhist_mod.F90) now have explicit setting of streams rather than using the implicit copy used by dfields. Copies that used to be done implicitly using the naming convention assumed by dfields are
now done explictly. This makes it clear what export fields are direct copies and what export fields are
derived fields that have no corresponding stream field.

In each datamode module - there are now two sections in the module variable list: export (and sometimes import) state pointers and stream pointer.

The following changes have been made throughout the code: character(*) => character(len=*), trim(subname) => subname (the latter is done since parameters, e.g. subname, don't need trim functions)

The following new routines have been introduced or deleted:

  • dwav
    • dwav_datamode_copyall.F90: new
  • drof
    • drof_datamode_copyall.F90: new
    • introduction of new datatype (stream_pointer_type) for multilevel stream pointers
    • expanded list of stream fields needed for drof.cplhist and added new functionality (e.g. drof_datamode_cplhist_mod.F90) to support this addition.
  • docn
    • combined docn_datamode_copyall_mod.F90 and docn_datamode_iaf_mod.F90 into a new file docn_datamode_sstdata_mod.F90. The two files docn_datamode_copyall_mod.F90 and docn_datamode_iaf_mod.F90 were effectively the same and two different datamodes are not needed since in both cases prescribed SST data was read in. (In addition, docn_datamode_iaf_mod.F90` set pointers to importState data which was never used and not needed).
    • ocn_comp_nuopc.F90: the datamode copyall is now sstdata and the datamode iaf is removed
    • changed cplhist and multilev_cplhist taxmode from extend to cycle
  • dlnd
    • introduction of new datatype (stream_pointer_type) for multilevel stream pointers
  • dice
    • dice_cplhist_data_mod.F90: still uses dfields since it is used by UFS
  • dglc
    • introduction of new datatype (stream_pointer_type) for multilevel stream pointers

NOTE: This PR also provides a new mapfile algorithm as a new option for mapping the streams input to the component model resolution. The new scheme does not have a default but is enabled via adding the following in the appropriate user_nl_XXX_streams where the user needs to fill in the entries in <> below:
<stream_name>:mapalgo = "mapfile:
As an example:
rof.ryf8485_jra:mapalgo="mapfile:/cluster/shared/noresm/inputdata/cpl/cpl6/map_JRA025_to_tnx1v4_e1000r300_170928.nc". This new capability enables a significant speedup in stand-alone ocean simulations. See NorESMhub/BLOM#686 (comment).

NOTE*:

Contributors other than yourself, if any: None

CDEPS Issues Fixed: #377

Are there dependencies on other component PRs (if so list):

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

  • docn cplhist mode can change answers due to changing taxmode from extend to cycle

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

Testing performed (will describe the noresm testing here)

  • aux_cdeps_noresm:
  • prealpha_noresm
    • compared to noresm3_0_beta09 - the only difference is SMS_Lm13.f19_f19_mtn14.I1850Clm50SpG.betzy_intel where atmImp_Faxa_ndep1 and atmImp_Faxa_ndep2 are different due to new new tag cdeps1.0.87_noresm_v2.

Hashes used for testing: noresm3_0_beta09 plus this CDEPS branch

mvertens added 30 commits May 12, 2025 10:26
…d_stream_usage' into feature/refactor_stream_usage
…al_streams' into feature/refactor_stream_usage
@mvertens
Copy link
Collaborator Author

@NickSzapiro-NOAA - I have refactored dice_datamode_cplhist_mod.F90 and verified that it compiles - but I cannot test it in either CESM or NorESM. If you could verify that this is working for UFS that would be great. Also - do you run docn in CPL hist mode? If not - I am wondering what the use case for it is - since I really cannot see how it would be used in either CESM or NorESM.

@billsacks
Copy link
Member

Just to record what I talked about with @mvertens

  • docn cplhist mode seems like it might not have value; we may want to just remove that. I'll check in with some other CESM folks about that. In any case, it seems like that may not need to be tested for this PR
  • drof cplhist mode probably does have applicability, but @mvertens noticed some pre-existing issues with it - in particular, it's not reading all of the fields that it should be. @mvertens is thinking of fixing it, and then we'll need to work with some people to validate it. But we probably don't need to worry about trying to do baseline comparisons of drof cplhist for this PR, since the baselines will be wrong for this mode.

@mvertens
Copy link
Collaborator Author

@billsacks - I have added a new datamode in drof - drof_datamode_cplhist.F90 - along with expanding the set of stream fields needed in cplhist mode. I have added a new testmods directory - cplhist_noresm and a new test that will now test this new functionality. I think we should create a new parallel directoyr cplhist_cesm that points the relevant datafiles that are needed to test this for cesm. All that is needed is a new shell_commands file.

if (associated(strm_Forr_rofi)) then
do ni = 1, size(Forr_rofi)
if (abs(strm_Forr_rofi(ni)) < 1.e28_r8) then
Forr_rofi(:) = strm_Forr_rofi(:)
Copy link
Contributor

Choose a reason for hiding this comment

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

Forr_rofi(ni) = strm_Forr_rofi(ni) instead of rofi(:)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ooops - thanks so much for catching this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Member

Choose a reason for hiding this comment

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

@mvertens - you commented that this is fixed (changing the whole-array assignment of Forr_rofi to just Forr_rofi(ni)), but it looks like you haven't yet pushed a commit fixing this? (You fixed other, similar issues.)


do ni = 1, size(Forr_rofl_glc)
if (abs(strm_Forr_rofl_glc(ni)) < 1.e28_r8) then
Forr_rofl_glc(:) = strm_Forr_rofl_glc(:)
Copy link
Contributor

Choose a reason for hiding this comment

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

Forr_rofl_glc(ni) = strm_Forr_rofl_glc(ni) instead of glc(:)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.


do ni = 1, size(Forr_rofi)
if (abs(strm_Forr_rofi(ni)) < 1.e28_r8) then
Forr_rofi(:) = strm_Forr_rofi(:)
Copy link
Contributor

Choose a reason for hiding this comment

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

Forr_rofi(ni) = strm_Forr_rofi(ni)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed.


do ni = 1, size(Forr_rofi_glc)
if (abs(strm_Forr_rofi_glc(ni)) < 1.e28_r8) then
Forr_rofi_glc(:) = strm_Forr_rofi_glc(:)
Copy link
Contributor

Choose a reason for hiding this comment

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

Forr_rofi_glc(ni) = strm_Forr_rofi_glc(ni)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

Comment on lines 196 to 204
call shr_strdata_get_stream_pointer(sdat, 'Sa_dens', strm_Sa_dens, requirePointer=.true., &
errmsg=subname//'ERROR: strm_Sa_ndens must be associated for cplhist datamode', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call shr_strdata_get_stream_pointer(sdat, 'Sa_pslv', strm_Sa_pslv, requirePointer=.true., &
errmsg=subname//'ERROR: strm_Sa_pslv must be associated for cplhist datamode', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call shr_strdata_get_stream_pointer(sdat, 'Sa_dens', strm_Sa_dens, requirePointer=.true., &
errmsg=subname//'ERROR: strm_Sa_dens must be associated for cplhist datamode', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
Copy link
Contributor

Choose a reason for hiding this comment

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

Sa_dens is here 2x

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for catching this. Fixed.

@NickSzapiro-NOAA
Copy link
Contributor

Thanks @mvertens ! dice cplhist test is ok in UFS with refactor

UFS RTs pass, except for datm_cdeps_lnd_era5_intel and its restart. These fail in run with

(datm_init_pointers): ERROR: strm_Sa_tdew must be associated for era5 datamode

Especially since this was PR from @uturuncoglu in ufs-community/ufs-weather-model#1845 , tagging here. Currently in this test, I think tdew needs to be calculated in datm/datm_datamode_era5_mod.F90

@NickSzapiro-NOAA
Copy link
Contributor

Also - do you run docn in CPL hist mode? If not - I am wondering what the use case for it is - since I really cannot see how it would be used in either CESM or NorESM.

For UFS, I think docn cplhist and sstdata can be the same, if can add units_CToK

@uturuncoglu
Copy link
Collaborator

@NickSzapiro-NOAA @mvertens
Here is some background. ERA5 mode is initially developed for HAFS application and then used for testing land component and also UFS Land DA. The dew point is used to calculate the humidity since ERA5 does not provide it directly. Also, in general all data modes getting lsize (the length of the stream, tdew for ERA5) from some variable and it seems there is no any consensus about it and the data component always fails when that particular variable not provided.

I wonder if there is a way to get rid of lsize completely such as querying mesh dimensions etc. It would be better solution and stream will not depend on any particular variable.

@mvertens
Copy link
Collaborator Author

@NickSzapiro-NOAA- thanks for your testing!

@NickSzapiro-NOAA @uturuncoglu - I think I am missing something in datm_datamode_era5_mod.F90.

In the the original code for this:

if (first_time)
     ! determine t2max (see below for use)
      if (associated(Sa_t2m)) then
        rtmp(1) = maxval(Sa_t2m(:))

        call ESMF_VMAllReduce(vm, rtmp, rtmp(2:), 1, ESMF_REDUCE_MAX, rc=rc)
        t2max = rtmp(2)
        if (mainproc) write(logunit,*) subname,' t2max = ',t2max
      end if

      ! determine tdewmax (see below for use)
      rtmp(1) = maxval(strm_tdew(:))
      call ESMF_VMAllReduce(vm, rtmp, rtmp(2:), 1, ESMF_REDUCE_MAX, rc=rc)
      td2max = rtmp(2)
      if (mainproc) write(logunit,*) subname,' td2max = ',td2max
      ! reset first_time
      first_time = .false.
endif
  • Since Sa_t2m is being advertised and a pointer to it is set as a module pointer, that pointer will always be associated. So I propose removing the if (associated(Sa_t2m)) query.
  • The original call shr_strdata_get_stream_pointer( sdat, 'Sa_tdew', strm_tdew , rc) simply keeps the pointer strm_tdew to null() if 'Sa_tdew' is not an import stream field. However, ifstrm_tdew is not associated - then the call to maxval(strm_tdew(:)) should throw an error. So I don't see how strm_tdew is ever calculated going into the first_time if clause.

In the new code:

  • The call to shr_strdata_get_stream_pointer( sdat,'Sa_tdew', strm_Sa_tdew , rc=rc) is the same as in the original code (other than renaming strm_tdew to strm_Sa_tdew).
  • There are a lot of other error checks I've put in place in the refactored datm_datamode_era5_mod.F90 - and I am wondering if all of them would potentially fail?

What does the ESMF configuration file look like for this datamode?

@uturuncoglu
Copy link
Collaborator

@NickSzapiro-NOAA It would be also nice to see actual error.

@uturuncoglu
Copy link
Collaborator

@NickSzapiro-NOAA We have just have a short chat with @mvertens about the issue. It seems that UFS WM is using CDEPS develop branch (https://github.com/NOAA-EMC/CDEPS/blob/develop/datm/datm_datamode_era5_mod.F90) and the ERA5 mode in that branch is different from the one found in ESCOMP. So, that was the issue. @mvertens will check the new code found in develop branch and try to fix the issue in ERA5 mode. Then once this PR merged, UFS WM needs to sync with ESCOMP to bring these changes.

@billsacks
Copy link
Member

The new code is missing the following two fields in the cpl hist file: atmImp_Faxa_swdn and atmImp_Faxa_swnet. Is that expected?

You expect to not see these fields anymore. There were no stream entries for either atmImp_Faxa_swdn and atmImp_Faxa_swnet in cplhist mode for datm - and so even though these fields were advertised - they were never filled in. So as part of this refactor I removed them - and as you can see it did not change the answers.

Great, thank you for clarifying that.

@billsacks
Copy link
Member

I have added a new datamode in drof - drof_datamode_cplhist.F90 - along with expanding the set of stream fields needed in cplhist mode. I have added a new testmods directory - cplhist_noresm and a new test that will now test this new functionality. I think we should create a new parallel directoyr cplhist_cesm that points the relevant datafiles that are needed to test this for cesm. All that is needed is a new shell_commands file.

@mvertens - Great, thanks! If the purpose of this is software testing, would it be reasonable for CESM to use the NorESM cplhist files for testing, so that we're running consistent tests and don't need to do double-maintenance on this test?

@fischer-ncar
Copy link
Collaborator

@mvertens @billsacks is this PR about ready for prealpha testing?

if (associated(strm_Forr_rofi)) then
do ni = 1, size(Forr_rofi)
if (abs(strm_Forr_rofi(ni)) < 1.e28_r8) then
Forr_rofi(:) = strm_Forr_rofi(:)
Copy link
Member

Choose a reason for hiding this comment

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

@mvertens - you commented that this is fixed (changing the whole-array assignment of Forr_rofi to just Forr_rofi(ni)), but it looks like you haven't yet pushed a commit fixing this? (You fixed other, similar issues.)

@mvertens
Copy link
Collaborator Author

@billsacks - I have pushed the drof change back.

@billsacks
Copy link
Member

I have pushed the drof change back.

It looks like you changed one of the (:) but not the other?

@billsacks
Copy link
Member

It looks like you changed one of the (:) but not the other?

Oh, never mind - I see your second commit.

@billsacks
Copy link
Member

@fischer-ncar - thanks for checking in. I talked to @mvertens and we both feel this is ready for your testing. See #376 (comment) for some notes on testing - specifically a few tests to add beyond the standard prealphas on derecho.

I'm in the midst of a deep dive into the different data model modes to make sure we're running testing covering everything we want to test, so I may come up with a few additional tests in the next day or so, but the prealphas plus the tests noted above should be close to what we want.

Thank you!

@billsacks
Copy link
Member

billsacks commented Jan 22, 2026

@fischer-ncar and @mvertens - I have done a pretty detailed analysis of the different data modes and their coverage in prealpha testing. In addition to the CESM prealpha testing, I want to make sure the following are covered:

@fischer-ncar - can you please add the following two tests to your testing, along with baseline comparisons (these tests are present in the aux_mom or aux_cice test lists but will need baselines for your testing) (I have also updated my testing comment with this request so it's all in one place):

  • SMS_D_Ld2.T62_t232.G.derecho_gnu (to cover DATM%NYF and DROF using a DIATREN mode)
  • ERS_Ld5.TL319_t232.G_IAF.derecho_intel.cice-default (to cover DATM%IAF and DROF using a DIATREN mode)

@mvertens - I don't think we have a way to test the following in CESM, so I wanted to double-check that you have tested these (sorry, you might have answered this before):

  • DLND%GCPL (i.e., T compset with CMEPS-generated forcing)
  • DLND%RCPL
  • DOCN%MULTILEV, DOCN%MULTILEV-CPLHIST and DOCN%MULTILEV-DOM

@mvertens - also, I think you said you have tested DWAV... just wanted to double-check that, since we don't have any DWAV testing in our prealpha test list (there's a test of ADWAV in aux_cmeps). (EDIT: I see that you ran aux_cdeps_noresm, which covers this.)

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.

docn-multilev is not reading in ocn input correctly

5 participants