Skip to content

TM5 boundary-layer diffusion (Calc_Kzz) ​

This page specifies TM5CalcKzzField and TM5CalcKzzCSField, interface-exchange (dkg) fields for the existing ImplicitVerticalDiffusion operator. It transcribes TM5's live Calc_Kzz: the friction velocity, the hydrostatic interface heights, the Holtslag–Boville boundary-layer scheme bldiff, and the conversion of the heat diffusivity into an exchange rate in kg s⁻¹ across each level interface. It is a new field type; the existing diffusion schemes and the preprocessing port tm5_bldiff.jl stay unchanged.

Lat-lon and reduced-Gaussian column physics, v5 inputs and runtime integration are implemented. Cubed-sphere live refresh and its tracer adjoint are also implemented. Local pydyn fixtures are read only through ATMOSTR_TM5_FIXTURES_DIR; they are never committed (§14).

The page follows the design of 2026-10-30, with the owner answers of that day. Statements marked estimate are design estimates, not measurements.

Sources ​

TM5 citations are file:line in the NOAA CarbonTracker TM5 repository (ct-unified-github at commit 2d60209); pydyn citations are at pydyn commit 0db6e6d.

AbbreviationRepository path
Kproj/ct-unified/trunk/src/diffusion_kernels.F90 (ustar_calc, bldiff_core)
SPproj/ct-unified/branches/speedup/src/diffusion__speedup.F90 (Calc_Kzz)
PCproj/ct-unified/trunk/src/meteo__pclim.F90 (the active overlay of base/trunk/src/meteo.F90)
MIproj/ct-unified/trunk/src/modelIntegration.F90
convbase/trunk/src/convection.F90
binasbase/trunk/src/binas.F90
levproj/levels/ml137/tropo34/src/dims_levels__ml137_tropo34.F90
rcbase/trunk/rc/meteo-tm5-noaa.rc
pydynpydyn/diffusion.py, pydyn/simple_diffusion.py

Conventions ​

The equations of §2–§7 use TM5's bottom-up indexing: layers l=1…L from the surface, interface l is the bottom of layer l (interface 1 is the surface, interface L+1 the top). The runtime is top-down (k=1 at the top). One adapter reverses the layer centres and all L+1 interfaces; the column physics has no orientation conditionals.

The mask function of TM5 is

J(a,b)=nint(0.5+sign(0.5,a−b))

(jqif, K:1026–1037): J=1 where a−b is +0 or positive, and J=0 where it is negative or −0. In Julia this is 1−signbit(a−b). pydyn implements it the same way (pydyn/diffusion.py:71–73).

1. Inputs and cadence in TM5 ​

Calc_Kzz is called from Proces_Update (MI:544), which runs once per dynamic step (base/trunk/src/tm5.F90:1303, after Meteo_Setup_Other at :1297). Its inputs:

  • Interface pressures phlb and layer masses M come from spm, the surface pressure linearly interpolated to the middle of the step (SP:954–966; spm at PC:2209–2218).

  • The heights G use the advected prognostic surface pressure sp (PC:1570, PC:5994, PC:6006–6020).

  • The winds come from the balanced, time-interpolated mass fluxes pu, pv.

  • For ERA5 (rc:287–298): model-level fields such as T and q are 3-hourly and interpolated (interp3), instantaneous surface fields hourly (interp1), accumulated surface fields are hourly interval means (aver1); orography and land-sea mask are constant and the Olsson/Ganzeveld roughness srols is monthly (rc:319–324).

Cache mode. NOAA production has read a precomputed dkg cache since 2026-05-07 and runs live Calc_Kzz only on a cache miss (base/trunk/src/diffusion.F90:72–76; rc:424–434). pydyn reports that this cache differs from live Calc_Kzz by about 7×10−6 rms relative per hour (docs/state.md:382–386 in pydyn), and pydyn's physics dumps were made with the cache. The parity target here is live Calc_Kzz (owner decision Q10).

2. Friction velocity ​

ustar_calc (K:175–283, called by dd_calc_ustar, K:137–170), NOAA default branch. The TM5-4DVAR land variant (K:260–264) is off by default (K:100), and the speedup overlay aborts if it is requested (SP:255–259).

With the land fraction x (TM5 stores percent, K:216), the surface stress τ=ewss2+nsss2 and V10=u102+v102:

u∗,sea=max(0.001, τ/ρ),ρ=1.2 kgm−3,u∗,land=κV10ln⁡(10/zh)ln⁡(75/zh)ln⁡(10/zl),zh=min(z0,ECMWF, 0.03),zl=max(z0,Olsson, 0.01),u∗=xu∗,land+(1−x)u∗,sea

(K:189, K:228–233, K:265–270, K:277). The 10-m wind is carried up the log profile of the clipped ECMWF roughness to 75 m, where the wind is assumed independent of the surface (K:254–256), and back down with the Olsson roughness; the NOAA branch uses ln⁡(10/zl) in the last factor, the 4DVAR branch ln⁡(75/zl). For x=0 the land terms are 0 and no land logarithm is evaluated. bldiff uses us=max(u∗,0.01) with κ=0.4 (K:630, binas:152). pydyn: ustar (pydyn/diffusion.py:76–89).

Roughness (owner decision Q8). TM5's z0,ECMWF is the ECMWF surface roughness sr, listed among the analysis surface fields (rc:119), and z0,Olsson is the monthly Olsson/Ganzeveld database srols (rc:120, rc:323–324). Q8 replaces only srols: its role (zl, floored at 0.01 m) is taken by the ERA5 forecast surface roughness fsr. sr keeps its role (zh, clipped at 0.03 m); the input writer accepts sr when present and otherwise uses fsr for both roles. If ERA5 provides the roughness only as fsr, both roles use the same field z0, and the land formula has three regimes:

z0 [m]zhzlu∗,land
z0≤0.01z00.01κV10ln⁡(75/z0)/[ln⁡(10/z0)ln⁡1000]
0.01<z0≤0.03z0z0κV10ln⁡(75/z0)/ln2⁡(10/z0)
z0>0.030.03z0κV10ln⁡2500/[ln⁡(1000/3)ln⁡(10/z0)]

In every case the formula needs zl<10 m, so that ln⁡(10/zl)>0; TM5 has no guard for it. The size of the change against srols is unknown until both datasets are compared on the same grid.

3. Interface heights ​

Meteo_Produce_Gph (PC:6006–6020), with pl=al+blps at the interfaces:

G1=orog,Gl+1=Gl+287.05Tl(1+0.608ql)gln⁡plpl+1(l=1…L−1),GL+1=200 km.

The top value is assigned, so ln⁡(p/0) is never taken. Layer centres are interpolated linearly in pressure (K:595, K:601–603):

p¯l=12(pl+pl+1),fl=pl−p¯lpl−pl+1,zl=(Gl−G1)(1−fl)+(Gl+1−G1)fl.

The top centre height is interpolated toward 200 km, and the boundary-layer height falls back to it when no crossing is found (§6). pydyn: geopotential (pydyn/diffusion.py:92–104).

4. Thermodynamics and surface buoyancy ​

Constants (K:486–509, K:873, binas):

SymbolValueSource
g9.80665 m s⁻²binas:55
κ0.4binas:152
cp1004 J kg⁻¹ K⁻¹binas:137
Lv2.5×106 J kg⁻¹binas:140
p0105 PaK:493
Ra8.3144×103/28.94≈287.2979 J kg⁻¹ K⁻¹K:490, binas:98, binas:116
ε, χRa/461.51≈0.622517, 1/ε−1≈0.606382K:492, K:503
κpRa/cp≈0.286153K:502
Ric, zacb, tiny0.3, 100, 10−9K:505–507
sffrac, ssfrac, βh=βm0.1, 0.1, 15K:488, K:495, K:509
fak, fakn8.5, 7.2K:499–500
Kfree,min, KBL,min, hmin10−15, 0.1, 100 mK:486, K:873, K:855

Three dry-air gas constants appear and are kept separate. The heights use the literal 287.05 (PC:6014) with the virtual-temperature factor 0.608. bldiff uses Ra=R/Ma with TM5's molar mass 28.94 g mol⁻¹ (binas:98), which gives 287.2979. The existing preprocessing port uses TM5_CONSTANTS.r_air = 287.307 (src/Parameters/PhysicalConstants.jl), 3.2×10−5 above 287.2979; it stays untouched, and the live Calc_Kzz constants are separate named values.

With p¯l from §3 (K:595–597, K:624–630, K:752–754):

θl=Tl(p0/p¯l)κp,θv,l=θl(1+χql),w′θ′=−sshf(G2−G1)g(p1−p2)cp,w′q′=−slhf(G2−G1)g(p1−p2)Lv,θs=θv,1,Hv=w′θ′+χθ1w′q′,Lob=−θsus3gκ[Hv+sign(10−10,Hv)].

sshf and slhf are ECMWF downward-positive fluxes [W m⁻²]; the factor (G2−G1)g/(p1−p2) is the inverse density of the lowest layer.

5. Winds and free-atmosphere diffusivity ​

TM5 recovers the winds from the face mass fluxes (K:644–668): ul=dx(pue+puw)/(2Ml) and vl=dy(pvn+pvs)/(2Ml) with dx=aeΔλcos⁡φj and dy=aeΔφ (ae = ae). pydyn: _winds (pydyn/diffusion.py:113–120).

At the interface above layer l, with z=Gl+1−G1 (K:684–727):

λ(z)=300 m (z≤1000 m),30+270e1−z/1000 otherwise,ℓ2=[1/λ+1/(κz)]−2,S2=max(Δu2+Δv2, 10−10)(zl+1−zl)2,α=ln⁡pl+1−ln⁡p¯lln⁡p¯l+1−ln⁡p¯l,θv,ifc=θv,l+α(θv,l+1−θv,l),Ri=g(θv,l+1−θv,l)θv,ifc(zl+1−zl)S2,Kn=ℓ2S2,Kfree={max(10−15, Kn/[1+10Ri(1+8Ri)])Ri≥0,max(10−15, Knmax(1−18Ri, 0))Ri<0.

The shear floor applies before the division by Δz2, and Ri=0 takes the stable branch (J(Ri,0)=1).

6. Boundary-layer height: two passes ​

Vogelezang and Holtslag (1996), as cited at K:736; K:749–855. For each layer centre,

Vl2=max((ul−u1)2+(vl−v1)2+100us2, 10−9)

(K:762–764, K:827–829), and the bulk Richardson number is

Ribl=g(θv,l−θref)(zl−z1)θsVl2+sign(10−10, ⋅).

Each pass scans upward to the first crossing of Ric=0.3 and interpolates linearly between centre heights; with no crossing it takes the highest centre (K:800, K:854). Work flags freeze the result once found, and an offset of 0.1 after the crossing keeps later denominators nonzero (K:791–796, K:845–850).

  • Pass 1 starts at l=1 with θref=θs (K:760–800). At l=1, zl−z1=0 gives Rib1=+10−10, which never crosses, and the interpolation there would start from the surface (K:771–772, K:780–782).

  • Pass 2 starts at l=2 (K:807–854). With j=J(Hv,0) and the pass-1 height h1: wsc=us[j(1−1.5h1/Lob)+(1−j)]1/3, Δθ=8.5Hv/wsc and θref=θs+jΔθ; the denominator keeps θs.

  • The result is h=max(h2,100 m) (K:855).

The scan uses the full L-layer profile, not the profile cut at the mixing cutoff, and ERA5's boundary-layer height is not used.

7. Boundary-layer diffusivity, Prandtl number and entrainment ​

K:887–966, at the interface above layer l with z=Gl+1−G1.

Masks. I=J(h,z) (inside the boundary layer), jU=J(Hv,0), jS=I(1−jU) (stable), jC=IjU (convective), η=Iz/h, surface layer j4=jCJ(0.1,η), mixed layer above it j5=jC(1−J(0.1,η)) (K:891–910).

Stable and neutral (Beljaars and Viterbo 1998, K:866).

ℓBL2=[1/(κz)+1/450]−2,jR=J(Ri,0),f=jR1+10Ri1+jRRi+(1−jR),Kbase=jSmax(ℓBL2S2f, 0.1)+(1−jS)Kfree

(K:916–924).

Unstable (Holtslag and Boville 1993, K:639). With a=1−1.5h/Lob:

Km=usκz(1−z/h)2(1−15z/Lob)1/3(surface layer),Km=usa1/3κz(1−z/h)2(mixed layer),w∗=(|Hv|gh/θs)1/3,Pr=jC[a1/3a+0.1κ7.2w∗usa1/3]+(1−jC),Kvh=jCmax(Km/Pr, 0.1)+(1−jC)Kbase

(K:928–961; in the Prandtl number Lob is replaced by −1 outside the convective boundary layer, K:952). TM5 divides by Pr; the existing _prandtl_inverse (src/Operators/Diffusion/pbl_physics.jl) is not its reciprocal and is not reused.

Entrainment. At the interface whose centre heights straddle h, jE=jUJ(h,zl)J(zl+1,h) (K:903–905), and

Kentr=0.2Hv(θv,l+1−θv,l)/(zl+1−zl),Kvh←jEKentr+(1−jE)Kvh

(K:964–966). TM5 applies no threshold, ceiling or floor here; §9 describes the one guard we add.

8. Exchange rate and the mixing cutoff ​

Dl=max(0,Kvh,l)2(Ml+1+Ml)(Gl+2−Gl)2(l=1…lmax−1),Dlmax=0

(K:980–988), in kg s⁻¹, built directly from the interface diffusivity without a centre-Kz detour. pydyn: dkg (pydyn/diffusion.py:256–263).

tropo34. NOAA's 34 levels (lev:43–47) are AtmosTransport's ml137_tropo34a (ECHLEVS_ML137_TROPO34A in src/Parameters/MetSourceConstants.jl), not ml137_tropo34. There lmax=26 (lev:34; the comment at lev:32–33 places the top of layer 26, ECMWF half-level 57, near 86 hPa). In top-down indexing, layers k=9…34 are mixed. A compact array D[k] (exchange between k and k+1) has D[1:8]=0 and D[34]=0; a full interface array is active at slots 10 … 34. The runtime stores the compact form; the adapter tests check its full-interface placement.

Other level sets (owner decision Q7). The cutoff is the pressure equivalent of tropo34a level 26: mix only the layers whose reference mid-layer pressure exceeds the pressure of ECMWF L137 half-level 57. From config/era5_L137_coefficients.toml, a57=8608.525391 Pa and b57=5.9×10−5, so p57=8614.34 Pa at the reference surface pressure 98500 Pa of the existing GEOS-Chem layer-count rule (8614.43 Pa at 105 Pa; the dependence on the reference is below 0.2 Pa). On tropo34a this gives exactly 26 layers, because half-level 57 is an interface of that set; on other sets it keeps the same physical depth. The implementation shares the rule of gchp_pbl_layer_count (src/Operators/Diffusion/gchp_nonlocal_pbl.jl), leaving the GEOS-Chem results bitwise unchanged. The cutoff is stored as the exact 8614.336891 Pa literal in Parameters, rather than reading the coefficient file at runtime. A coefficient-file test verifies the literal and the tropo34a count. Free-atmosphere K and the boundary-layer height still use the full column.

9. Guards and the entrainment NaN ​

ItemTM5Implemented here
u∗ floorssea u∗≥0.001; zl≥0.01; zh≤0.03; us≥0.01same
Shear and bulk V2floor 10−10 before Δz2; max(…+100us2,10−9)same
Lob, Ribsigned 10−10 offsetssame
h and K floorsh≥100 m; Kfree≥10−15; boundary-layer K≥0.1 where TM5 applies itsame
Masked branchesarithmetic masks jx+(1−j)y evaluate both branchesselection ifelse(j, x, y); selects the same value wherever both branches are finite
Entrainmentunguarded (below)K_vh = ifelse(jE & isfinite(K_entr), K_entr, K_BL)
Dmax(0,Kvh), then zero above the cutoffsame

The entrainment NaN. If θv,l+1=θv,l at an interface, Kentr=±∞ (NaN if also Hv=0). Outside the entrainment interface jE=0, and 0·∞ = NaN propagates into Kvh even though the entrainment branch is not selected. Fortran's MAX with a NaN argument is processor-dependent, so TM5's D there is compiler-defined; an infinite D makes the solve singular. pydyn reproduces the NaN (pydyn/diffusion.py:20–25, :250–252); its readable version simple_diffusion.py selects the used branch instead (:19–21).

The guard keeps a finite Kentr, also a negative one, which max(0,·) then clips as in TM5, and otherwise keeps the boundary-layer value. It selects the same value as TM5's mask arithmetic wherever TM5 is finite and differs only where TM5 is non-finite or compiler-defined. The column function returns the number of guarded interfaces, and the refresh warns once per run when the guard changes an entrainment value below the mixing cutoff. Unused singular branches and interfaces above the cutoff do not enter the warning count; the column also returns the full singular-expression count. The scheme does not fail fast: that would abort long runs on rare columns, more often in Float32. The parity path uses no @fastmath, no reassociation, and integer powers such as u_s^3, the form pydyn uses. Julia's exp, log and power functions are not the C library's, so parity is tested against the tolerances of §14, not bit for bit.

Two other unused-branch paths. TM5's masks also evaluate two expressions that are non-finite only in the branch that is not used:

  • Equal consecutive bulk Richardson numbers. Before the crossing (J(Ric,Ribl)=1), the interpolation term (Ric−Ribl−1)/(Ribl−Ribl−1) is evaluated anyway; equal values give a division by zero, and the mask 0·∞ makes h NaN (K:784–785, K:839–840; pydyn simple_diffusion.py:19–21 names this case). At an actual crossing the two values cannot be equal, because the previous one is at most 0.3 and the new one exceeds it.

  • Ri=−0.1 exactly. With jR=0 the stable term of f is 0/(1−1)=0/0 (K:921), and the NaN reaches Kbase through max(NaN,0.1), which is processor-dependent.

Branch selection takes the used branch in both cases (the previous h; f=1), as it does for entrainment. These selections are implemented with the column physics.

10. Integration in AtmosTransport ​

Topology-specific fields inside the existing operator.

julia
struct TM5CalcKzzField{FT,N,D<:AbstractArray{FT,N},S,P,M} <: AbstractTimeVaryingField{FT,N}
    dkg::D       # topology-native compact interface exchange [kg/s]
    scratch::S   # bottom-up column inputs and intermediates
    params::P    # precision-specific TM5 constants and mixing cutoff
    metrics::M   # mesh metrics built by Models.Physics, adapted with the field
    guard_warned::Base.RefValue{Bool} # host-side once-per-run warning state
end
  • Files: src/Operators/Diffusion/TM5CalcKzzField.jl (type, Adapt, refresh_tm5_calc_kzz!) and src/Operators/Diffusion/tm5_calc_kzz.jl (one pure @inline column function for CPU and GPU, generic in the float type, with no Float64 promotion; in Float32 it forms Δθv, the bulk-Richardson numerator and the log-pressure ratios with reduced cancellation, and compensates the pressure sum, §14). The column function returns D and its intermediates (u∗, G, z, θv, Ri, both height passes, Kvh, full and active guard counts); column tests call it directly.

  • Solve. DkgExchange reads interface exchange directly. Its factor method feeds the existing structured and face-indexed backward-Euler solves, including their flux-form tracer-mass update and column ledger. TM5CalcKzzCSField supplies six interior D panels to the same six-panel solver. It has no panel_field method: a generic Kz path must fail rather than interpret exchange in kg/s as diffusivity in m²/s.

  • Refresh. A new _refresh_pbl_kz_for_window! method (src/Models/Runner/driven_physics_refresh.jl) runs once per met window, after the window-advance air-mass reset; _refresh_dz_for_window! gets a no-op method. No new hook is needed.

  • Configuration. [diffusion] kind = "tm5_calc_kzz", with the existing surface-flux couplings (SplitSurfaceFluxCoupling by default, DiffusiveSurfaceFluxBoundary with surface_flux_boundary = true, which reduced-Gaussian runs reject today). lmax is computed when the field is materialised (§8).

  • PrecomputedCSDkgField and GCHPNonlocalPBLField stay untouched.

CS metrics and bounded scratch. The field owns one column-chunked scratch, shared across all panels, with at most 65,536 columns. LL/RG use the same chunking with their existing indexing and arithmetic order. Scratch is approximately 16 working-precision values per chunk column and layer, plus a guard count. At L137 the default chunk needs about 575 MB in Float32 or 1.15 GB in Float64 (decimal units), excluding D and metrics. D is stored on interior arrays; mass and fluxes are read through their halos without exchanging D halos.

For a CS cell of area A and mass m, recover face-normal speeds from the stored amounts over s seconds:

u1=A2ms(awLw+aeLe),u2=A2ms(bsLs+bnLn).

With c=ex⋅ey and sθ=1−c2, the orthonormal components are u′=(u1+cu2)/sθ and v′=u2. Geometry is computed in Float64 with cs_face_edge_lengths and panel_cell_local_tangent_basis, then rounded once. Calc_Kzz uses squared wind differences, so any fixed orthonormal frame per column gives the same D. This also handles GEOS-native panel orientation. Both surface couplings are supported on CS.

Inputs (owner decision Q5). Pressure, carrier mass and winds come from the runtime state; the binary adds only T, q and the surface fields, so the scheme works with either flux construction and on existing binaries plus the new section group.

Calc_Kzz inputTM5Implemented
Pressure (for G, p¯, density)G from the advected sp; phlb and M from the midpoint spmone profile from the window-start carrier mass: pk+1=pk+gmk/(S(1−qk)) from p1=A1, top-down; the (1−q) factor only on a dry basis
M in the winds and in Dmidpoint moist massruntime carrier mass m (dry by default); the solve uses the same m, so TM5's D/m structure is kept
u, vbalanced midpoint pu, pv over the midpoint Mstored window amounts: u=dx(amw+ame)/(2ms) with s = flux_application_seconds(window_dt, steps, flux_kind) and dx=A/Lface; reduced Gaussian sums the face segments per cell edge; the cubed sphere rotates panel components with panel_cell_local_tangent_basis
T, q3-hourly, interpolated to the step midpointtm5_t, tm5_q: mean of the two hourly analysis endpoints on target levels, merged with mass weights
u10, v10, srhourly, interpolatedmean of the two hourly endpoints; sr if available, otherwise fsr
sshf, slhf, ewss, nssshourly forecast interval meansERA5 reanalysis hourly accumulations over the window divided by its length
lsm, oroconstantconstant; lsm stored as a fraction
srolsmonthly Olsson/GanzeveldERA5 forecast surface roughness fsr (Q8)

Estimate: using dry instead of moist mass ratios changes the recovered winds by O(Δq) across a face, negligible next to the accepted difference between analysis and forecast inputs. tm5_q is used instead of the qv_start and qv_end sections because cubed-sphere binaries do not carry humidity endpoints.

Binary section group tm5_pbl (implemented). Optional, valid only in format version 5, all-or-nothing, one record per window:

SectionsShapeUnits and sign
tm5_t, tm5_qcellK; kg kg⁻¹ of total air
tm5_lsmsurfacefraction 0–1
tm5_sr, tm5_fsrsurfacem (tm5_fsr replaces srols, Q8)
tm5_u10, tm5_v10surfacem s⁻¹
tm5_ewss, tm5_nssssurfaceN m⁻², interval mean
tm5_sshf, tm5_slhfsurfaceW m⁻², ECMWF downward-positive (unlike the existing upward-positive pbl_hflux)
tm5_orosurfacem² s⁻²

Estimate: about 40 % of a C90 L34 window payload.

Enable the input writer with [preprocessing] include_tm5_pbl = true, input.thermo_dir and input.surface_dir. This is an hourly ERA5 spectral LL/RG/CS option. LL/RG can combine it with [preprocessing] spectral_flux_construction = "tm5_spectral"; those binaries carry both the TM5 flux identity and the complete tm5_pbl group. CS uses its existing spectral staging construction, recorded as point_sampled_spectral. LL-binary→CS remapping also passes the group through, with T/q weighted by source moist mass and surface fields by area. Averaging the stress and 10 m wind components before their magnitudes can underestimate friction velocity where direction varies within a cell; this applies to all targets and matters most for CS cells much coarser than the source. That path records regridded_transport_binary and the source construction. N320→CS input assembly remains deferred pending archive coverage. The thermo sidecar must contain t in K and q in kg/kg; the surface archive must contain the ten primitives, including the next day's 00 UTC endpoint. NetCDF, split ZIP and ARCO surface layouts are supported. Surface primitives (lsm, stresses, heat fluxes, sr/fsr, 10 m winds and orography) are cell-area means on the actual LL, RG or CS mesh, using the package's shared conservative regridder with intensive-field semantics. In particular, lsm is the coastal cell's land fraction, rather than the value at its centre. Excursions of the remapped fraction within 1e-12 of [0, 1] are clamped: rounding in the area mean leaves it up to about 3e-15 above 1 in all-land cells (LL 72×37, 2021-12-01). Larger excursions fail the binary validator. This follows TM5's two-dimensional area-aver input convention (base/trunk/src/tmm.F90:1062–1065). Roughness uses an arithmetic area mean. The shared regridder's spherical-polygon approximation and RG ring-boundary slivers also apply here (see conservative regridding). T/q retain coordinate-aware bilinear sampling at target cell centres and are merged with native moist layer-pressure weights before the endpoint mean. The LL and RG thermo paths share the existing bilinear sampler. The merge weights use each construction's stored window-start total surface pressure. Since that pressure can differ between constructions, merged T/q can differ beyond rounding; each merge is consistent with its binary's hybrid layers. Day-local input ownership reuses the shared hourly thermo endpoint, surface readers (including split-ZIP extraction), and surface remap weights. Thermo files stay open with their bilinear weights for the day. Consecutive records are decoded in temporal-chunk blocks capped at three hours, then only sampled target endpoints are retained. The next-day file supplies just midnight. This avoids repeated chunk decompression while preserving each record's scalar conversion, orientation and interpolation; the pressure-dependent layer merge and endpoint average keep their operation order. grid.target_vertical pressure-overlap remapping and grid.level_top != 1 are rejected before synthesis; at least two output layers are required. ERA5 reanalysis accumulations are hourly interval totals labelled by their ending time, not cumulative forecast-since-initialisation values. The reader validates units and divides by the supplied interval; already exported rates keep their values and ECMWF heat-flux signs.

Select the runtime with:

toml
[diffusion]
kind = "tm5_calc_kzz"
surface_flux_boundary = false

The (1-q) pressure correction dispatches on carrier-mass basis, rather than surface_pressure_basis: these are independent contracts. In particular, the normal dry-mass binary records total surface pressure but still needs the dry-to-total layer-mass correction. Archived ps does not set the runtime pressure profile.

Runtime column scratch holds approximately 16 × ncells × nlevels floating-point values, plus one integer guard count per cell; the D cache adds one field of ncells × nlevels. PBL height is a local scalar, with no extra stored diagnostic. For 34 layers and about 542,000 cells this is approximately 1.18 GB of Float32 scratch before D, metrics and solver workspaces. LL72/O24 sizes and CPU timing are measured in the implementation handoff; large RG runs must budget this allocation. A smaller-scratch implementation remains future work.

11. Differences from TM5 ​

TopicTM5Implemented hereNote
Refresh cadenceevery dynamic steponce per hourly met windowfollows the analysis-window decision
Pressuretwo: advected sp for G, midpoint spm for phlb and Mone, from the window-start runtime staterefreshed once per window, so the difference spans up to the surface-pressure change over the window
Inputsforecast fields, midpoint interpolationanalysis window means; accumulations over the windowsurface primitives are area means on both LL and RG; T/q use point interpolation (§10), whereas TM5 supports area/mass averaging for 3-D inputs
Mass basis of Dmoist spm massruntime carrier mass (dry)D/m structure kept; cancels for constant q
RoughnessOlsson/Ganzeveld srols for zlERA5 forecast roughness fsr for zl; sr keeps its role (§2)Q8; size not yet measured
Wind recovery lengthdx=aeΔλcos⁡φjdx=A/Lx, dy=2A/(Ls+Ln)effective face-metric lengths; on uniform LL, the relative differences are approximately −Δφ2/24 zonally and +Δφ2/12 meridionally
Entrainment NaNpropagates or compiler-definedguarded (§9)differs only where TM5 is non-finite
Masked arithmeticboth branches evaluatedifelse selectionsame value where finite
Cutofflmax=26 on tropo34pressure equivalent on any level set (§8)Q7; identical on tropo34a
Solvedense inverse of a matrix combined with convection (conv:475–476, conv:521–529), split x y z v s c c s v z y x (base/trunk/src/dims.F90:93–94)separate backward-Euler diffusion solve at the palindrome centreQ6: the combined matrix is deferred; the splitting difference remains
PrecisionFloat64 on CPUFloat32 on GPU in production; parity target is Float64 on CPUQ12; Float64 keeps TM5's literal arithmetic; Float32 uses algebraically identical forms with reduced cancellation (§14); tests report Float32 crossing changes separately
Dataproduction dkg cachelive Calc_KzzQ10
Runtime compositiondiffusion inside convection, Check_CFL, slopes, polar clusteringruntime unchangedbounds any "TM5-style" claim

TM5's combined matrix also divides by the prognostic mass m_dat (conv:314, conv:475–476), whereas D was built from the spm mass.

12. Relation to the existing schemes ​

All existing schemes stay bitwise unchanged.

Aspecttm5_bldiff.jl (preprocessing)WindowPBLKzField, LocalHoltslagBovilleKzFieldTM5CalcKzzField
Where it runspreprocessing; writes :dkg for cubed-sphere binaries (runtime kind = "tm5_dkg")runtime, layer-centre Kzruntime, interface D, once per window
EntrainmentTM5 form only for Δθv/Δz>10−4 K m⁻¹ (strict) and a finite K≤1000 m² s⁻¹, then floored at 0.1 m² s⁻¹; else the mixed-layer valuenoneTM5 form, guarded only where non-finite
Sourceport of TM5 cy3-4dvar bldiff (file header)Beljaars–Viterbo with PBL scaling; GEOS VDIFF local schemeTM5 ct-unified live Calc_Kzz

_beljaars_viterbo_kz, _prandtl_inverse and _shear_enhanced_kz are not repurposed. A leaf function of tm5_bldiff.jl may be shared only where constants, arithmetic order and mask semantics agree; it then moves to the earlier Diffusion module and the old wrapper stays bitwise unchanged.

13. Adjoint and window capture ​

For fixed D the backward-Euler solve is linear in tracer mass. The CS adjoint transposes its matrix with D read directly from the interior panels; the existing Kz transpose continues to reconstruct exchange from Kz and dz. The flux-form ledger corrects rounding and has no adjoint, as for Kz.

D depends on meteorological inputs, face fluxes and carrier air mass, and never on tracer mass. Even with air_mass_reset_mode = :none, prognostic air mass is advanced only by fixed meteorological fluxes. Thus D is forcing in every reset mode; derivatives through meteorology, friction velocity or K are outside the tracer-only adjoint.

cs_adjoint_inputs executes production's window refresh and freezes a copy of the six D panels once per met window. The captured field omits refresh scratch and geometry, and steps within a window share its operator. Replay uses the same DkgExchange forward solver. The capture keeps no layer thickness (diffusion_layer_thickness = nothing) because this solver never reads one. Under :none, capture advances carrier mass with production advection so the next window sees the same prognostic mass as the forward run. Tracers during capture are disposable. D is neither recomputed during replay nor stored in a tape slot. The tape pool, byte estimate and AutoTape policy are unaffected: forcing/operator objects are retained by reference outside the tape.

Frozen D requires 6Nc2Nz values per window, including zero planes. At C90 L34 that is 6.6 MB in Float32 (159 MB for 24 windows); C180 L137 requires 106 MB per window (2.55 GB per day). These arrays stay on the model's device with the captured fluxes. The Lin–Rood tape remains device-only; combined Lin–Rood/TM5 runs must budget for both. Compact active-layer storage is deferred. Adjoint coverage is CS only; LL/RG adjoints remain refused.

14. Tests and tolerances ​

StageCriterion
u∗, heights, windsFloat64, 10−12 scaled; branches exact; pure land, pure sea, coast and both friction floors
Free K and Ri10−12 scaled away from singular conditioning; floors at the right place
Boundary-layer heightcrossing indices exact away from thresholds; h to 10−11 relative
Kvh, entrainment10−11–10−10 scaled for finite, well-conditioned columns; non-finite TM5 cases against the §9 rule
D and cutoffinactive zeros exact; with injected Kvh, M, G: 10−12 scaled
Solvebackward residual 10−13–10−12 (Float64); isolated layers bit-exact; constant mixing ratio and mass within solver rounding
Float32 against Float64 CPU, synthetic fixture columns (well conditioned)active K and D: 2×10−4 per nonzero entry; D column L1: 3×10−5; all K (including above cutoff): 4×10−3; against Float64 on the Float32-rounded inputs, D: 2×10−5 per entry and 10−5 column L1; interfaces with exactly equal Float64 θv counted, not scored; branch flips reported separately
Float32 against Float64 CPU, real ERA5 windowsD per nonzero entry: median ≤1.5×10−5, p99 ≤2×10−4, maximum ≤2×10−2; D column L1: p99 ≤4×10−4, maximum ≤1.5×10−2; branch flips reported
CUDA Float32 against CPU Float32D per nonzero entry: p99 ≤2×10−5, maximum ≤5×10−4

Cubed-sphere CPU coverage. test_tm5_pbl_cs.jl checks the shared column physics, chunk sizes, C48 versus 2.5° LL columns, rotation invariance in both panel conventions, uniform tracer, column conservation, packed/single solves and the direct-D transpose including an empty layer. Face fluxes from the production LineIntegralFaceFluxes recover analytic wind speeds with RMS errors (m s⁻¹) of 0.05658, 0.01420 and 0.003553 for solid-body flow on C12, C24 and C48; the deformation flow gives 0.14306, 0.03585 and 0.008957. Both decrease by about four per refinement.

Production DrivenSimulation and frozen-D adjoint replay agree bit for bit for both surface couplings and :preserve_tracer_mass/:none resets. With :none, capture advances carrier mass through production advection; that advance currently also transports all tracers, so capture cost scales with tracer count. A future mass-only advance must preserve the carrier bits. Full and Stride checkpoints agree. The new split and boundary/:none footprint cases give relative errors of 2.91×10−14 and 1.60×10−14 against production central differences on the synthetic CPU test. These tests differentiate tracer mass and emissions, with meteorology fixed. GPU validation is separate.

Edge inventory (synthetic). Neutral Hv=+0 and −0; small stable flux; strong convection; zero and weak shear; no Ri crossing; a crossing exactly at a centre; the h floor; interfaces exactly at h and 0.1h; the 1000 m mixing-length transition; two equal consecutive bulk Richardson numbers; Ri=−0.1 exactly; weak, negative and zero inversions; a negative Kentr clipped by D; the sea stress floor; pure ocean with invalid land roughness; a coast; mountain orography; the 200 km top; a full 34-layer scan with 26 mixed layers.

pydyn fixtures. Local-only fixtures hold synthetic columns run through pydyn's pure functions (ustar, geopotential, _winds, bldiff, dkg, calc_kzz; owner decision Q9). They are generated and kept outside the repository, are not committed, and reproduce TM5's unguarded arithmetic, including the entrainment NaN. The parity loader and tests in test/core/test_tm5_calc_kzz.jl load fixtures from ATMOSTR_TM5_FIXTURES_DIR and skip with a clear message when the variable is unset or the required fixtures are absent. Matching the Calc_Kzz equations does not establish CFL, advection-moment or full-model parity with TM5, and an absent or skipped fixture is never reported as passed.

Float64 CPU comparison on the 16 local synthetic columns: maximum relative error in K_vh is 6.03e-14, in D 6.02e-14; maximum absolute errors are 7.06e-21 m²/s and 7.47e-14 kg/s, respectively. Heights, both PBL-height passes, friction velocity and Obukhov length match exactly on this fixture. All 32 Float32 PBL-height crossing indices agree with Float64. Two interfaces are built with exactly equal Float64 θv; there Ri=0 selects the stable branch and the entrainment quotient is non-finite. Rounding the inputs to Float32 moves them off this point: Float64 arithmetic on the rounded inputs gives Δθv=9.5×10−6 and −8.6×10−6 K. Float32 follows its inputs there, as Float64 on the rounded inputs does, and so changes 2 of the 16 singular-expression counts; the two interfaces are counted, not scored. On the other interfaces, measured Float32 D errors are 1.388e-4 maximum per nonzero entry and 2.553e-5 maximum column L1 relative error; Float64 arithmetic on the Float32-rounded inputs alone gives 1.390e-4 and 2.562e-5. Active K has maximum relative error 1.357e-4. Across all K interfaces, including those above the mixing cutoff, the maximum is 3.408e-3, at the top interface of one column (layer-mean pressures 211 and 54 Pa, Δθv=0.01 K), where D is zero. Against Float64 arithmetic on the same Float32 inputs, Float32 D differs by at most 4.54e-6 per entry and 1.52e-6 in column L1; literal Float32 differences of θv gave 1.5e-4 and 4.0e-5. These measurements cover the finite TM5 values; non-finite entrainment checks use the documented guard. They are column parity, not full-model TM5 parity.

Float32 on real data. K is a function of the gradient Richardson number, whose numerator Δθv=θv,l+1−θv,l is a difference of two values near 300 K. At weak-shear, near-neutral interfaces (|Δθv|≈10−3–10−2 K) the relative condition number of K with respect to T reaches 4.7×105. Each Float32 θv carries 1–2 ulp (3–6×10−5 K), so the Float32 column never subtracts two of them. With a=T(1+χq) and Π=(p0/p¯)κp,

θv,j−θv,i=(aj−ai)Πj+θv,i(ΠjΠi−1),ΠjΠi−1=expm1(κplog1pp¯i−p¯jp¯j),

with aj−ai=(Tj−Ti)(1+χqj)+Tiχ(qj−qi) and p¯i−p¯j=[(pi−pj)+(pi+1−pj+1)]/2. T, q and p enter only through differences, which are exact (Sterbenz) where the operands are within a factor of two. This removes cancellation in those operand differences and greatly improves near-surface accuracy. Residual cancellation remains in the final sum: the synthetic model-top interface evaluates approximately −144.27376 + 144.26372 = −0.010040283 K, an amplification of about 28,738. This form supplies Ri, the interface θv, the entrainment K and the bulk-Richardson numerator (θv,l−θv,1)−Δθ of both passes. On the ERA5 windows below, for adjacent interfaces it is more accurate than the direct difference in every pressure-ratio bin (median 1.1e-7 against 1.8e-5 K for |Πj/Πi−1|<0.01, 1.2e-4 against 1.5e-4 K for 0.3–0.5). The geopotential increment uses log1p((pl−pl+1)/pl+1) instead of ln⁡(pl/pl+1), the centre-height fraction (exactly 1/2) is formed from (pl−pl+1)/2, and the top-down pressure sum is Kahan-compensated. Only Float32 operations are used: Kahan's expm1 formulation uses Float32 exp and log, avoiding Base's Float64 fallback on AMDGPU. CUDA (libdevice), AMDGPU and Metal.jl provide Float32 log1p. Kahan's pressure additions contain no multiply that FMA contraction could fuse. Each change is a helper with a Float64 method that keeps TM5's literal expression, so Float64 results are bitwise unchanged.

Before the Kahan expm1 replacement, measured on 2021-12-01 (O24, windows at 00, 01, 02 and 12 UTC, identical window-start inputs), the Float32 D error relative to Float64 per nonzero entry has median 6.1e-6–6.3e-6, p99 5.3e-5–5.5e-5, p99.9 1.6e-4–1.8e-4 and maximum 1.1e-3–3.9e-3. The column L1 error has p99 8.9e-5–1.05e-4 and maximum 3.9e-4–3.4e-3. 0.25–0.31 % of entries exceed 1e-4 and at most 0.0051 % exceed 1e-3. No PBL-height crossing index or stability sign changes, and no interface needs the entrainment guard, as in Float64. Rounding only the Float64 inputs to Float32 gives median 4.3e-6–4.5e-6, p99 4.8e-5–5.2e-5 and maximum 1.1e-3–5.8e-3, with 0.22–0.27 % of entries above 1e-4. The Float32 column is up to approximately 10.2 % above this input-rounding floor in p99; the maximum is at most approximately 0.13 % above the floor. Replacing expm1 with Kahan's formulation changes p99 by at most 0.46 % across these four windows (up to 10.31 % above the floor); the maximum changes by at most 1.49 %, and remains at most approximately 0.13 % above the floor. Literal Float32 differences of θv gave median 1.2e-5, p99 1.3e-4, maximum 1.0e-2 and 1.7–1.9 % of entries above 1e-4. The remaining Float32 arithmetic error (median 3.0e-6 against Float64 on the rounded inputs) comes mostly from the wind shear, because the recovered Float32 winds are differenced across interfaces (S2 median 1.3e-6). Relative input noise of 1e-7 gives 3.3e-3–7.8e-2. In one 900 s diffusion solve, the Float32 D changes a surface plume's mixing ratio by at most 9.2e-5 of the column maximum (Float64 D from the rounded inputs: 8.8e-5; literal Float32: 3.2e-4).

CUDA. On an NVIDIA L40S, CUDA Float32 D differs from CPU Float32 by median 2.2e-7, p99 4.6e-6–4.8e-6 and at most 4.7e-5–1.8e-4 (O24, the four windows above) and 6.3e-5 (LL 72×37, 00 UTC; median 2.1e-7). With literal Float32 differences of θv these were p99 5e-5 and maxima 7.7e-4 and 1.3e-3. The remaining differences come from libdevice math and FMA contraction; the reformulation greatly reduces their amplification near the surface. Pressures agree bitwise on all these windows, so the compiled Kahan sum matches the CPU one, and the refresh kernel's PTX has no Float64 instruction. CUDA Float32 against CPU Float64 has a maximum of 3.9e-3 (O24). On LL 72×37 at 00 UTC it has a maximum of 1.3e-3 and a column L1 maximum of 5.4e-4 (literal Float32: 3.1e-3 and 1.9e-3). The compensated forms made the refresh kernel 4 % slower: 0.326 to 0.339 ms for O24 (3168 columns) and 3.53 to 3.67 ms for 422,400 columns of 34 layers (O24 columns tiled on a synthetic mesh). Three-window Float32 CUDA runs with live Calc_Kzz change the total air mass by -3.1e-9 (O24) and -1.9e-9 (LL 72×37); diffusion does not change air mass.

15. Owner decisions (2026-10-30) ​

  • Q5 Pressure, air mass and winds come from the runtime state; the binary adds only T, q and the surface fields.

  • Q6 The combined convection and diffusion matrix is deferred until pure diffusion parity passes; it must not require changes to the surface-flux operator.

  • Q7 On level sets other than tropo34a, the cutoff is the pressure equivalent of tropo34a level 26 (§8).

  • Q8 The ERA5 forecast surface roughness replaces the Olsson/Ganzeveld srols; the difference is documented (§2).

  • Q9 Local generation of pydyn fixtures from synthetic inputs is approved; the fixtures are not committed. A request for a live-Calc_Kzz dump waits.

  • Q10 The parity target is TM5's live Calc_Kzz, not the NOAA dkg cache.

  • Q12 Float32 on the GPU is acceptable for production; parity tests use Float64 on the CPU.

Column physics, binary inputs and live refresh on lat-lon, reduced-Gaussian and cubed-sphere grids are implemented, together with the frozen-diffusivity tracer adjoint. The combined convection and diffusion matrix stays deferred.

16. Implementation status ​

ItemStatus
This page; binary version-5 format gateImplemented
pydyn Calc_Kzz column fixturesGenerated locally outside the repository; not committed; loader and parity tests implemented using ATMOSTR_TM5_FIXTURES_DIR, with a clear skip when unset or fixtures are absent
B2: bldiff constants, column function, shared layer-count ruleImplemented
B3: tm5_pbl section group, ERA5 surface readers, lat-lon and reduced-Gaussian writersImplemented
B4: TM5CalcKzzField, DkgExchange, lat-lon and reduced-Gaussian runtime, golden regression casesImplemented
B5: cubed sphere, adjointImplemented; frozen per-window D, no met derivatives
B6: combined convection and diffusion matrixDeferred (Q6)

References ​

  • Beljaars, A. C. M., and Viterbo, P. (1998). Role of the boundary layer in a numerical weather prediction model. In Clear and Cloudy Boundary Layers, A. A. M. Holtslag and P. G. Duynkerke (eds.), Royal Netherlands Academy of Arts and Sciences, Amsterdam, 287–304.

  • Holtslag, A. A. M., and Boville, B. A. (1993). Local versus nonlocal boundary-layer diffusion in a global climate model. J. Climate 6, 1825–1842.

  • Jacobson, M. Z. Fundamentals of Atmospheric Modeling, sections 8.3 (friction velocity) and 8.4 (surface roughness lengths), cited in TM5 at K:220–236.

  • Krol, M., et al. (2005). The two-way nested global chemistry-transport zoom model TM5. Atmos. Chem. Phys. 5, 417–432.

  • Vogelezang, D. H. P., and Holtslag, A. A. M. (1996). Evaluation and model impacts of alternative boundary-layer height formulations. Bound.-Layer Meteorol. 81, 245–269.