refactor(diffusion): consolidate the eddy-diffusivity pipeline and diffusive-flux application - #4669
Merged
haakon-e merged 7 commits intoJul 13, 2026
Conversation
Member
Author
|
This change is part of the following stack: Change managed by git-spice. |
Contributor
|
📖 Docs preview for this PR: https://clima.github.io/ClimaAtmos.jl/previews/PR4669/ |
haakon-e
force-pushed
the
he/edmfx-updraft-horizontal-diffusion
branch
from
July 9, 2026 19:04
b61b1f4 to
8632e7d
Compare
haakon-e
force-pushed
the
he/refactor-eddy-diffusivity-pipeline
branch
from
July 9, 2026 19:04
25110fb to
ef842c7
Compare
This was referenced Jul 9, 2026
haakon-e
force-pushed
the
he/edmfx-updraft-horizontal-diffusion
branch
from
July 10, 2026 01:15
8632e7d to
6d768fa
Compare
haakon-e
force-pushed
the
he/refactor-eddy-diffusivity-pipeline
branch
from
July 10, 2026 01:15
ef842c7 to
aab5f54
Compare
haakon-e
force-pushed
the
he/edmfx-updraft-horizontal-diffusion
branch
from
July 10, 2026 07:36
6d768fa to
2f58f5e
Compare
haakon-e
force-pushed
the
he/refactor-eddy-diffusivity-pipeline
branch
from
July 10, 2026 07:36
aab5f54 to
78f56d3
Compare
haakon-e
force-pushed
the
he/edmfx-updraft-horizontal-diffusion
branch
from
July 10, 2026 19:29
2f58f5e to
59f4895
Compare
haakon-e
force-pushed
the
he/refactor-eddy-diffusivity-pipeline
branch
from
July 10, 2026 19:29
78f56d3 to
4940847
Compare
haakon-e
force-pushed
the
he/edmfx-updraft-horizontal-diffusion
branch
from
July 10, 2026 20:30
59f4895 to
5af9a08
Compare
haakon-e
force-pushed
the
he/refactor-eddy-diffusivity-pipeline
branch
from
July 10, 2026 20:30
4940847 to
c318221
Compare
haakon-e
force-pushed
the
he/edmfx-updraft-horizontal-diffusion
branch
from
July 11, 2026 00:29
5af9a08 to
eb9ff2c
Compare
haakon-e
force-pushed
the
he/refactor-eddy-diffusivity-pipeline
branch
from
July 11, 2026 00:29
c318221 to
2152bdc
Compare
Extract the TKE -> mixing length -> Prandtl -> eddy viscosity/diffusivity chain, previously duplicated at seven sites, into `ᶜeddy_diffusivities!`. Callers supply the mixing-length output field via the required `ᶜmixing_length_field` keyword and optional `K_u`/`K_h` output fields, preserving each site's scratch slots and lazy or materialized policy; the closure inputs (`grid_scale`, `buoyancy_gradient`) pass through unchanged. Migrated sites: the vertical and horizontal EDMFX SGS diffusive fluxes, the vertical and horizontal updraft diffusion, the TKE tendency for both EDMF models, and the diffusion Jacobian coefficients.
…helpers Add two boundary-condition operators to the abbreviations: ᶜdiffdivᵥ for the zero-flux scalar-flux divergence (Covariant3, matching ᶠgradᵥ output) and ᶠdiffdivᵥ_u₃ for the zero-flux vertical-momentum divergence. Add two lazy flux helpers to the eddy-diffusion closures: ᶜdiffusive_flux_divergenceᵥ for a single diffusive scalar flux and ᶠtotal_enthalpy_gradientᵥ for the dry-static-energy + water-enthalpy gradient. These centralize the per-function operators and flux expressions currently rebuilt across the five vertical diffusion sites; no call sites change in this commit. Add a unit test asserting the new operators and lazy helpers reproduce the per-function forms they replace, over both float types.
… helpers Replace the per-function zero-flux divergence operators and gradient shadow in vertical_smagorinsky_lilly_tendency! with the shared ᶜdiffdivᵥ, ᶠdiffdivᵥ_u₃, and ᶜdiffusive_flux_divergenceᵥ, folding ρ and D into the flux coefficient in the existing left-to-right order. Delete the momentum-flux boundary-correction term, which is the divergence of a zero flux with a zero-value boundary and so evaluates to zero identically.
Replace the per-function zero-flux divergence operators and gradient shadow in vertical_amd_tendency! with the shared ᶜdiffdivᵥ, ᶠdiffdivᵥ_u₃, and ᶜdiffusive_flux_divergenceᵥ. The energy term stays materialized before the tracer loop, since the loop overwrites the ᶠD_amd scratch field per tracer. Delete the momentum-flux boundary-correction term, which is the divergence of a zero flux with a zero-value boundary and evaluates to zero identically. The AMD diffusivity gradient operators (ᶠgradᵥ_uvw, ᶠgradᵥ_scalar) are retained.
…elpers Replace the zero-flux divergence operators and gradient shadow in vertical_diffusion_boundary_layer_tendency! with the shared ᶜdiffdivᵥ, ᶠtotal_enthalpy_gradientᵥ (energy), and ᶜdiffusive_flux_divergenceᵥ (tracers). The tracer eddy diffusivity keeps its existing scaling placement (α folded into K_h before interpolation). The momentum term is unchanged.
…helpers Replace the zero-flux divergence operators in edmfx_sgs_diffusive_flux_tendency! with the shared ᶜdiffdivᵥ, ᶠtotal_enthalpy_gradientᵥ (energy), and ᶜdiffusive_flux_divergenceᵥ (q_tot and tracers). The TKE flux keeps its own divergence operator because it carries a nonzero surface-flux bottom boundary, and the momentum term is unchanged.
…hared helpers Replace the zero-flux divergence operators in edmfx_vertical_diffusion_tendency! with the shared ᶜdiffusive_flux_divergenceᵥ for the updraft mse, q_tot, and SGS tracer fluxes, keeping the trailing division by the updraft density.
haakon-e
force-pushed
the
he/edmfx-updraft-horizontal-diffusion
branch
from
July 11, 2026 01:33
eb9ff2c to
7ab7415
Compare
haakon-e
force-pushed
the
he/refactor-eddy-diffusivity-pipeline
branch
from
July 11, 2026 01:33
2152bdc to
e91b55b
Compare
Base automatically changed from
he/edmfx-updraft-horizontal-diffusion
to
he/edmf-3d-diffusion
July 13, 2026 17:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Consolidates the diffusion code in two layers: how eddy diffusivities are computed, and how diffusive fluxes are applied.
Coefficient layer. Extracts the TKE → mixing length → Prandtl → eddy viscosity/diffusivity chain, previously duplicated at seven sites, into a single
ᶜeddy_diffusivities!function. Callers supply the mixing-length output field and optionalK_u/K_houtput fields, preserving each site's scratch slots and lazy or materialized policy; the closure inputs (grid_scale,buoyancy_gradient) pass through unchanged. The implicit-Jacobian scheme dispatcher is renamededdy_diffusivity_coefficients!→ᶜimplicit_diffusion_coefficients!to distinguish it from the closure chain. Migrated sites: the vertical and horizontal EDMFX SGS diffusive fluxes, the vertical and horizontal updraft diffusion, the TKE tendency for both EDMF models, and the diffusion Jacobian coefficients.Flux-application layer. Adds two shared zero-flux boundary-condition divergence operators (
ᶜdiffdivᵥ,ᶠdiffdivᵥ_u₃, next to the existing operator constants inabbreviations.jl) and two lazy helpers (ᶜdiffusive_flux_divergenceᵥ,ᶠtotal_enthalpy_gradientᵥ), then migrates the five vertical diffusion sites that rebuilt these per function — vertical Smagorinsky–Lilly, vertical AMD,vertical_diffusion_boundary_layer_tendency!, the EDMFX grid-mean SGS diffusive flux, and the EDMFX updraft vertical diffusion — one commit per site.Behavior-preserving. The coefficient-layer extraction reproduces each site's original expression, and every flux-application commit is bit-for-bit identical to its parent. The dynamics test group (
Prognostic equations,Tracer/mass transport consistency,EDMFX horizontal diffusive flux) passes on this branch, and a new unit test (test/diffusion_operators.jl) pins the shared operators and helpers, including the diffusive-flux sign, atFloat32andFloat64.Scope and limitations. The diagnostics that recompute the closure fields lazily (
edt,evu,edth,evuh) are deliberately not routed through the new function, which mutates scratch; unifying them needs either a lazy variant or cached diffusivity fields. A behavior-changing correction to the vertical-diffusion tracer scaling, surfaced by this refactor, is deferred to a follow-up PR. Unifying the tendency functions themselves (a per-direction driver over a declarative field table) is out of scope here.