Skip to content

gravity_wave_drag: skip inactive ridge orientations and bound constituent vertical diffusion - #483

Open
g8j39 wants to merge 1 commit into
ESCOMP:mainfrom
g8j39:gw-drag-skip-inactive-ridges-and-bound-vdiff
Open

g8j39 wants to merge 1 commit into
ESCOMP:mainfrom
g8j39:gw-drag-skip-inactive-ridges-and-bound-vdiff

Conversation

@g8j39

@g8j39 g8j39 commented Nov 18, 2026

Copy link
Copy Markdown

Tag name (The PR title should also include the tag name):
Originator(s): g8j39

Description (include issue title and the keyword ['closes', 'fixes', 'resolves'] and issue number):
Fixes #482 (gravity_wave_drag: skip inactive ridge orientations and bound constituent vertical diffusion to breaking levels).

In 141-constituent coupled runs (B1850CM), gravity-wave drag spends avoidable time over ocean and flat terrain where no sub-grid ridge is active, and solves vertical constituent diffusion across all 93 levels even when wave breaking is absent or confined to a few levels (~2.4% of CPU samples in a 3-hour profile with the companion atmosphere patches active).

  • gravity_wave_drag_ridge.F90: Skip a ridge orientation when band_oro%ngwv == 0 and all columns have mxdis < orohmin, and skip gw_drag_prof when all(tau == 0._kind_phys).
  • gw_common.F90, gw_diffusion.F90: Scan gwut before vertical diffusion. Zero egwdffi and skip diffusion when no level breaks; otherwise solve only over [ktop_diff, kbot_diff] (one level wider on each side than breaking levels, where zero interface d_coef sets spr and sub in linear_1d_operators.F90 to zero and decouples the tridiagonal solve bit-for-bit).

Timing: On an earlier, slightly broader revision with other local optimization patches active in both arms (3-hour B1850CM, 32 MPI tasks, 2 interleaved pairs, gfortran 13.4.0 -O2 on cesm3_0_beta10; stock ~937 s), total time fell from 893.03 to 876.30 s (1.87% less total, 2.15% less atmosphere). This narrower commit has not been re-timed alone.

Validation:

  • Standalone real-module A/B check on main (this commit): compiles and matches unpatched main bit-for-bit (1,254,768 values, 0 diffs) across gfortran (13.4.0, 15.2.0), ifx 2025.0.4, and nvfortran 24.11-0.
  • Full-model cprnc checks (gfortran 13.4.0, cesm3_0_beta10, multi-patch CESM3 build): 0 diffs in 2-day B1850CM (6 pairs, 17 files / 4,263 fields) and 3-hour B1850CM (16 files / 4,183 fields); earlier checks also passed 8x4 OpenMP, restart, F2000climo, and QPC6. Full atmosphere-series setup and combined numbers are in the overview comment on SE: skip tendency-diagnostic buffers when the fields are not on a history tape CAM#1762.

Prepared with AI assistance (Google Gemini).

List all namelist files that were added or changed:
None.

List all files eliminated and why:
None.

List all files added and what they do:
None.

List all existing files that have been modified, and describe the changes:

  • schemes/gravity_wave_drag/gravity_wave_drag_ridge.F90: Skip inactive ridge orientations (band_oro%ngwv == 0 and all(mxdis(:ncol, nn) < orohmin)) and zero-stress gw_drag_prof calls.
  • schemes/gravity_wave_drag/gw_common.F90: Scan gwut for breaking levels; skip diffusion when none break, else pass [ktop_diff, kbot_diff] to gw_ediff and gw_diff_tend.
  • schemes/gravity_wave_drag/gw_diffusion.F90: Skip zero-gwut wave levels in gw_ediff and restrict gw_diff_tend qnew work to q(:, ktop:kbot).

List all automated tests that failed, as well as an explanation for why they weren't fixed:
CAM regression tests and CAM-SIMA snapshot tests have not been run (no NCAR machine access); the runs listed above are the only testing.

Is this an answer-changing PR? If so, is it a new physics package, algorithm change, tuning change, etc?
No. Bit-for-bit identical for finite inputs (cprnc on gfortran and standalone real-module A/B checks across gfortran, ifx, and nvfortran).

If yes to the above question, describe how this code was validated with the new/modified features:
N/A (bit-for-bit).

In gravity_wave_drag_ridge, ocean and flat-terrain chunks run all n_rdg
ridge orientations (10 in CESM3 B1850CM) even when surface displacement
is below orohmin or source stress tau vanishes before gw_drag_prof. Skip
those inactive iterations. In gw_common and gw_diffusion, scan gwut
before vertical diffusion, skip diffusion when no level breaks, and
otherwise restrict gw_ediff and gw_diff_tend to [ktop_diff, kbot_diff].

An earlier, slightly broader version saved 1.87% total run time (893.0
to 876.3 s; 2.15% ATM) across 2 interleaved 3-hour CESM3 B1850CM pairs
(32 MPI tasks, gfortran 13.4.0 -O2, measured with other local
optimization patches active in both arms); this narrower commit was not
re-timed alone.

Answer impact: Bit-for-bit identical whenever the original produces
finite results. Checked with 0 differing cprnc fields in CESM3 2-day and
3-hour B1850CM on this commit (gfortran 13.4.0 -O2, in a multi-patch
build; earlier revisions also passed 8x4 OpenMP, restart, F2000climo,
and QPC6), and verified bit-for-bit in a standalone real-module A/B
check across gfortran, ifx 2025.0.4, and nvfortran 24.11-0.

Assisted-by: Google Gemini
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.

gravity_wave_drag: skip inactive ridge orientations and bound constituent vertical diffusion to breaking levels

1 participant