Skip to content

A few refactorings to handle fields with ungridded dimensions, particularly for prep_rof_mod#628

Merged
billsacks merged 4 commits intoESCOMP:mainfrom
billsacks:handle_fields_with_ungridded_dims
Feb 6, 2026
Merged

A few refactorings to handle fields with ungridded dimensions, particularly for prep_rof_mod#628
billsacks merged 4 commits intoESCOMP:mainfrom
billsacks:handle_fields_with_ungridded_dims

Conversation

@billsacks
Copy link
Member

Description of changes

These are changes to support adding water tracers in CMEPS, which will be done using fields with ungridded dimensions. In particular, the changes here are needed to support adding ROF-related fields. I initially developed and tested these changes in the context of my branch for adding water tracers, but have split these off to their own PR to facilitate review of these changes, since they potentially impact things beyond just the addition of water tracers.

(1) Refactor med_field_info_mod and med_methods_mod to expose two methods that will be useful for the water tracer work: med_field_info_create_from_field (extracted from med_field_info_array_from_state) and med_field_info_esmf_fieldcreate (extracted from med_methods_FB_init)

(2) Change the mechanism for getting ungridded info from a Field: The previous mechanism - using ESMF/NUOPC attributes - doesn't work in a new context where I want to use this routine. So I have changed this to do a more direct querying of the Field. I added write statements to check whether there were any differences from this change, in ERS_D_Ld3.ne30pg3_t232.B1850C_LTso.derecho_intel.allactive-defaultio. At least in that configuration, the only difference was that, in various calls, cpl_scalars is now given an ungridded dimension of size 4, whereas previously it was not given an ungridded dimension. The new behavior seems probably correct, but I guess this didn't have any impact before. As noted below, this doesn't change answers, at least for the tests I ran.

(3) Generalize code in prep_rof to handle fields with ungridded dimensions. This will be needed for water tracers. The one piece that is not handled yet is the irrigation-specific mapping.

Specific notes

Contributors other than yourself, if any:

CMEPS Issues Fixed (include github issue #):

Are changes expected to change answers? (specify if bfb, different at roundoff, more substantial) NO - bfb

Any User Interface Changes (namelist or namelist defaults changes)? NO

Testing performed

Please describe the tests along with the target model and machine(s)
If possible, please also added hashes that were used in the testing

Tested in the context of cesm3_0_alpha08b, or something close to it (ESCOMP/CESM@622984f), with share updated to share1.1.18, and the changes here rebased onto cmeps1.1.32.

The following tests all passed and were bit-for-bit with baselines:

ERS_Ly7.f09_g17_gris4.T1850Gg.derecho_intel
SMS_Lm13.f10_f10_mg37.I1850Clm50SpG.derecho_intel
MULTINOAIS_Ly2.f10_f10_ais8gris4_mg37.I1850Clm50SpRsGag.derecho_intel.cism-change_params
SMS_D_Ld1.ne30pg3_t232.I1850Clm50BgcSpinup.derecho_intel.clm-cplhist
SMS_Ld40.TL319_t232.C_JRA.derecho_intel
ERS_D_Ld3.ne30pg3_t232.B1850C_LTso.derecho_intel.allactive-defaultio
ERI.ne30pg3_t232.B1850C_LTso.derecho_intel.allactive-defaultio
ERC_D_Ln9.ne30pg3_ne30pg3_mt232.FHISTC_LTso.derecho_intel.cam-outfrq9s
ERI.TL319_t232.G_JRA.derecho_intel.cice-default
SMS_D.TL319_t232.G_JRA_RYF.derecho_intel

Expose two methods that will be useful for the water tracer work:

(1) med_field_info_create_from_field: create a single field_info object
    from information in an ESMF_Field (extracted from
    med_field_info_array_from_state)

(2) med_field_info_esmf_fieldcreate: create an ESMF Field based on a
    field_info object (extracted from med_methods_FB_init)
The previous mechanism - using ESMF/NUOPC attributes - doesn't work in a
new context where I want to use this routine. From some initial testing,
it seems that this new mechanism of querying the Field for its various
ungridded variables gives the same result in most cases; the one
exception I see is for the cpl_scalars Fields. I'm guessing this will be
okay, but I'll do some testing to verify this.
This will be needed for water tracers.

The one piece that is *not* handled yet is the irrigation-specific
mapping.
@billsacks billsacks requested a review from mvertens January 31, 2026 23:16
@billsacks
Copy link
Member Author

I'll need to make similar changes in med_phases_post_rof_mod and possibly some other prep/post modules, but for now I think I'll keep this PR as is and then open additional PRs with changes elsewhere as I tackle these additional modules for the water tracer work.

public :: med_field_info_create
! Create a single field_info object from direct specification of values
public :: med_field_info_create_directly

Copy link
Collaborator

Choose a reason for hiding this comment

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

You could create an interface and call these interchangably

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. I personally find that to often be more confusing than helpful except in very limited cases such as supporting multiple data types or array ranks: In cases where there is a completely different interface, my experience is that having a generic interface adds little if any value, and just makes it harder to figure out what's actually being called when trying to trace the code.

That said, I'm open to doing this if others prefer it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree that it's not always useful or prudent to do this and I leave it to your discretion.

@billsacks billsacks merged commit 6d93e62 into ESCOMP:main Feb 6, 2026
4 checks passed
@billsacks billsacks deleted the handle_fields_with_ungridded_dims branch February 6, 2026 20:07
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.

3 participants