Skip to content

(0.105.1) Add density and gravity_wave_speed to PerturbationAdvection#5314

Merged
glwagner merged 16 commits intomainfrom
glw/perturbation-advection-density
Feb 26, 2026
Merged

(0.105.1) Add density and gravity_wave_speed to PerturbationAdvection#5314
glwagner merged 16 commits intomainfrom
glw/perturbation-advection-density

Conversation

@glwagner
Copy link
Copy Markdown
Member

@glwagner glwagner commented Feb 20, 2026

Summary

Extends PerturbationAdvection with two optional keyword arguments for models with density-weighted prognostic variables (e.g., anelastic atmospheric models):

  • density: when provided, converts density-weighted fields (ρψ) to intensive fields (ψ) before radiation and back after. Fixes the dimensional inconsistency when applying PerturbationAdvection directly to prognostic variables like ρu, ρθ, ρq.

  • gravity_wave_speed: additional phase speed added to the advective velocity, following Klemp & Wilhelmson (1978). Useful for momentum fields where gravity waves propagate faster than the mean flow.

Both default to nothing and 0 respectively, so this is fully backward compatible.

Also adds _fill_*_halo! methods for Center-located fields, enabling PerturbationAdvection to be used on scalar fields (tracers, ρθ, etc.) in addition to Face-located velocity/momentum fields.

Motivation

This is motivated by NumericalEarth/Breeze.jl#494, which would otherwise have to maintain a separate PerturbationMomentumAdvection scheme with ~270 lines of duplicated radiation logic. With this upstream change, Breeze can use PerturbationAdvection directly and delete the duplicate code.

Test plan

  • Existing PerturbationAdvection API is unchanged (new kwargs have defaults)
  • Existing boundary condition integration tests pass
  • Test with density-weighted fields in Breeze.jl

🤖 Generated with Claude Code

glwagner and others added 2 commits February 19, 2026 19:25
Extends PerturbationAdvection with two optional features needed for
models with density-weighted prognostic variables (e.g., anelastic models):

1. `density` field: when provided, converts density-weighted fields (ρψ)
   to intensive fields (ψ) before radiation and back after. This fixes the
   dimensional inconsistency when applying PerturbationAdvection directly
   to prognostic variables like ρu, ρθ, ρq.

2. `gravity_wave_speed`: additional phase speed added to the advective
   velocity, following Klemp & Wilhelmson (1978). Useful for momentum
   fields where gravity waves propagate faster than the mean flow.

Both default to `nothing` and `0` respectively, so this is fully backward
compatible — existing code using PerturbationAdvection is unaffected.

Also adds _fill_*_halo! methods for Center-located fields, enabling
PerturbationAdvection to be used on scalar fields (tracers, ρθ, etc.)
in addition to Face-located velocity/momentum fields.

Motivated by NumericalEarth/Breeze.jl#494 which currently maintains a
separate PerturbationMomentumAdvection scheme with ~270 lines of
duplicated radiation logic.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
@glwagner glwagner changed the title Add density and gravity_wave_speed to PerturbationAdvection (0.105.1) Add density and gravity_wave_speed to PerturbationAdvection Feb 20, 2026
glwagner and others added 2 commits February 20, 2026 08:06
…call sites

Add a 2-positional-arg constructor for backward compatibility after the
struct gained gravity_wave_speed and density fields. Update tests and
validation scripts to use keyword arguments. Rename test_CGSolver to
test_cgsolver to conform with naming conventions.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@glwagner glwagner requested a review from tomchor February 21, 2026 00:09
@glwagner
Copy link
Copy Markdown
Member Author

i think tests will pass but CI is being flaky now

@glwagner glwagner requested a review from jagoosw February 23, 2026 01:22
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 24, 2026

Codecov Report

❌ Patch coverage is 54.41176% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.45%. Comparing base (51c67b5) to head (6a6d87f).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/BoundaryConditions/perturbation_advection.jl 54.41% 31 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5314      +/-   ##
==========================================
+ Coverage   68.94%   73.45%   +4.51%     
==========================================
  Files         398      398              
  Lines       21793    22574     +781     
==========================================
+ Hits        15025    16582    +1557     
+ Misses       6768     5992     -776     
Flag Coverage Δ
buildkite 68.86% <56.06%> (-0.08%) ⬇️
julia 68.86% <56.06%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@jagoosw jagoosw left a comment

Choose a reason for hiding this comment

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

LGTM

end

# Backward compatibility: support old 2-positional-arg constructor
PerturbationAdvection(inflow_timescale::Number, outflow_timescale::Number) =
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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

agree, its just the 2 arguments that are needed

Copy link
Copy Markdown
Member

@tomchor tomchor left a comment

Choose a reason for hiding this comment

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

Nice! Great addition

@glwagner glwagner merged commit 9a109e7 into main Feb 26, 2026
80 checks passed
@glwagner glwagner deleted the glw/perturbation-advection-density branch February 26, 2026 09:46
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