Skip to content

Add FFT-free spatial sweep alternative for wind shear perturbation (ustars/ustarn)#288

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/refactor-ustarn-ustars-calculation
Draft

Add FFT-free spatial sweep alternative for wind shear perturbation (ustars/ustarn)#288
Copilot wants to merge 2 commits intomainfrom
copilot/refactor-ustarn-ustars-calculation

Conversation

Copy link
Contributor

Copilot AI commented Mar 12, 2026

The WindShear.compute_shear method computed dtaux/dtauy (Weng et al. perturbation theory, driving ustars/ustarn) exclusively via 2-D FFT. This adds a loop-and-sweep alternative that avoids FFT entirely, structured analogously to the directional Ct sweep in utils.py.

Core algorithm (shear.py)

  • New compute_shear_spatial method: applies a Gaussian spatial filter (replaces FFT-based high-frequency filter), computes central-difference bed slopes, then delegates to a row-by-row Cauchy sweep.
  • New module-level @njit(cache=True) helper _cauchy_hilbert_sweep: for each y-row sweeps the antisymmetric kernel 1/(k·π) over all nx cells — the discrete Hilbert transform of the slope in the wind direction. Numerically ~88–90 % correlated with the FFT result.
  • Amplitude coefficients derived from Weng et al. inner-layer parameters (alpha_s = 2·log(l/z₀)/ul², alpha_n = 2/ul²), consistent with compute_shear.
  • Complexity is O(ny · nx²) vs FFT's O(ny · nx · log nx); a performance note is included in the docstring.

Method selection

WindShear.__init__ gains a method parameter ('fft' | 'spatial', default 'fft'). Existing behaviour is unchanged.

# Select the new sweep-based method in model config:
# method_shear = 'spatial'

# Or directly:
ws = WindShear(x, y, z, dx=dx, dy=dy, L=L, l=l, z0=z0,
               buffer_width=buf, method='spatial')

wind.initialize and constants.py updated to recognise 'spatial' as a valid method_shear value alongside 'fft', 'quasi2d', and 'duna2d'.

Tests (tests/test_shear.py)

12 new tests covering _cauchy_hilbert_sweep (flat bed → zero, antisymmetric hill response, amplitude linearity, row independence) and WindShear with method='spatial' (zero-wind, non-trivial output, ≥ 0.7 correlation with FFT, shape, backward compatibility of FFT path).


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- shear.py: add compute_shear_spatial + _cauchy_hilbert_sweep (numba JIT)
- shear.py: add method parameter to WindShear.__init__ ('fft'|'spatial')
- wind.py: pass method_shear='spatial' to WindShear when selected
- constants.py: document 'spatial' as valid method_shear option
- tests/test_shear.py: 12 new tests for helper and WindShear

Co-authored-by: Sierd <14054272+Sierd@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor ustarn and ustars calculation to avoid FFT Add FFT-free spatial sweep alternative for wind shear perturbation (ustars/ustarn) Mar 12, 2026
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.

2 participants