Skip to content

Add Spectral Nudging Option and Fix Nudging Behavior When Files Are Missing#1402

Open
patcal wants to merge 3 commits into
ESCOMP:cam_developmentfrom
patcal:cam6_4_116_NudgingRevision
Open

Add Spectral Nudging Option and Fix Nudging Behavior When Files Are Missing#1402
patcal wants to merge 3 commits into
ESCOMP:cam_developmentfrom
patcal:cam6_4_116_NudgingRevision

Conversation

@patcal

@patcal patcal commented Sep 30, 2025

Copy link
Copy Markdown
Collaborator

This pull request addresses issues #1393 and #1273

For Issue #1273 an error exit with a message is invoked if a missing nudging file is encountered.

For Issue #1393 a module for computing spherical harmonics on the physics grid is implemented. The nudging module has additional functionality that uses this module to optionally filter nudging tendencies to scales larger then a specified truncation scale.

This functionality is controlled by 2 additional variables in the &nudging_nl namelist.
Nudge_SpectralFilter- LOGICAL Option to apply spherical harminic filtering to
the model state and target data so that nudging
tendencies are only applied to scales larger than
the specified truncation.

Nudge_SpectralNtrunc - INT The number of meridional spherical harmonic modes used
for spectral filtering. The nominal horizontal scale of
the filtering can be estimated as:

                                                          Hscale = PI*6350/Nudge_SpectralNtrunc

                                          i.e. Nudge_SpectralNtrunc=40 corresponds to a horizontal 
                                                 nudging scale  Hscale~500km.

@patcal patcal requested a review from fvitt September 30, 2025 05:29
@patcal patcal added bug-fix This PR was created to fix a specific bug. CoupledEval3 labels Sep 30, 2025
@cacraigucar cacraigucar self-assigned this Sep 30, 2025

@fvitt fvitt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some initial questions and comments. Do you have a test case for spectral nudging that you can point me to? I can implement a regression test case.


logical :: Nudge_SpectralFilter =.false.
integer :: Nudge_SpectralNtrunc = -1
integer :: Nudge_SpectralNbasis = -1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am not seeing where Nudge_SpectralNbasis gets sets. Is it always -1?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hi @fvitt , for the spherical harmonics, the user specifies the meridional truncation(L). For each index (l < L+1) there are (2l+1) basis functions, so the init() routine sums up the total number of these basis functions and returns the value into Nudge_SpectralNbasis.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@patcal @fvitt was there ever a regression test added so we can verify if something gets broken in a future commit.

Comment on lines +1351 to +1355
write(iulog,*) 'NUDGING: WARNING - analyses file NOT FOUND. You can switch nudging '
write(iulog,*) 'NUDGING: OFF to coast thru a known gap in your files '
write(iulog,*) 'NUDGING: by commenting out the following endrun command.'
endif
call endrun('nudging_timestep_init:: ERROR Missing Nudging File')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should a namelist switch to turn on / off the abort behavior? I agree that aborting the run should be the default behavior.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We could add that, but I don't know if it would be worth the effort. The only case I know of where it was needed was for YOTC data which had processing errors that led to some randomly dispersed gaps in the available data. So it is not a common problem, and most users who have a gap in there data will figure out a way to fill in their missing data. Also, allowing for this option would make the pending implementation of higher order time interpolation methods a bit more complex as they would have to account for the gaps.

Comment thread src/utils/spherical_harmonic_mod.F90 Outdated
!=======================================================================

!=======================================================================
! legacy spherepack routines

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As far as I can tell, these spherepack routines are duplicates of the spherepack routines in zonal_mean_mod.F90. If so, the spherepack routines in zonal_mean_mod should be removed and zonal_mean_mod should use the routines here.

Comment thread src/utils/spherical_harmonic_mod.F90 Outdated


!=======================================================================
subroutine Invert_Matrix(I_Mat,Nbas,O_InvMat)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks like a duplicate of Invert_Matrix in zonal_mean_mod

Comment thread src/utils/spherical_harmonic_mod.F90 Outdated

! Type definitions
!-------------------
type SphericalHarmonic_t

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could the existing ZonalMean class be replaced by "special" use of this SphericalHarmonic class (m=0)?

@jtruesdal

Copy link
Copy Markdown
Collaborator

Thanks @patcal I'll see if I can update this to the head of the trunk.

Comment thread src/physics/cam/nudging.F90 Outdated
Comment thread src/physics/cam/nudging.F90
Comment thread bld/namelist_files/namelist_definition.xml Outdated
Comment thread src/utils/ug_spectralmethods_mod.F90 Outdated
Comment thread src/utils/ug_spectralmethods_mod.F90 Outdated
Comment thread src/utils/ug_spectralmethods_mod.F90 Outdated

@jtruesdal jtruesdal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a nice refactor. I didn't test the code to pull shr_reprosum out of the level loop it was just an example but something like that should work.

@patcal

patcal commented Jun 23, 2026 via email

Copy link
Copy Markdown
Collaborator Author

@jtruesdal

jtruesdal commented Jun 23, 2026 via email

Copy link
Copy Markdown
Collaborator

@patcal patcal force-pushed the cam6_4_116_NudgingRevision branch from 30ab709 to 9abc12a Compare June 23, 2026 18:25

@jtruesdal jtruesdal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

All looks good now for me.

@patcal

patcal commented Jun 23, 2026 via email

Copy link
Copy Markdown
Collaborator Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix This PR was created to fix a specific bug. CoupledEval3 Must have CESM3

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants