feat(operators): missing Fourier operators — 3/2-rule `dealiased_product`, `iterated_laplacian`, `vorticity_from_velocity`/`streamfunction_from_vorticity`, vector advection, energy/enstrophy spectra, hyperviscous Helmholtz inverse for IMEX

Open
#110 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
40/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
jupyter, python

Research direction

The issue lists missing operators in spectraldiffx. Start by reading the existing SpectralDerivative class in grid.py and the hand-rolled implementations in demo_qg.py, navier_stokes_2d.py, and test_correctness.py. The first task is likely implementing dealiased_product with 3/2 padding; check the dealias handling in grid.py lines 83, 275, 500. Run the validation tests described in the acceptance criteria to confirm correctness.

Written by the indexing model from the issue text.

Description

enhancement

Part of #83.

Summary

Operations that every simulation notebook, script, or test hand-rolls, or that the API advertises without implementing:

Operator Status today Where it is hand-rolled
dealiased_product(a, b) with 3/2 zero-padding dealias="padding" is accepted by the grid type but is a no-op (grid.py:83, 275, 500); no padding code exists –
iterated_laplacian(u, n) only the spherical class has it demo_qg.py:513-516 loops deriv.laplacian
vorticity_from_velocity(u, v) = v_x − u_y; streamfunction_from_vorticity(zeta) = ∇⁻²ζ – five call sites do solve + gradient + sign flips instead of velocity_from_streamfunction
vector advection (u·∇)u – Navier–Stokes notebooks
energy_spectrum(u), enstrophy_spectrum(zeta) (isotropic shell binning) – demo_qg.py, navier_stokes_2d.py, test_correctness.py
helmholtz_inverse(u, alpha, nu, order) = (1 − dt(ν∇^{2n} ...))⁻¹ in spectral space for IMEX schemes SpectralHelmholtzSolver covers ∇² − α only pseudospectral_part2.py
advection_scalar(..., spectral=...) missing the spectral argument the other methods have –

Proposed fix

Implement on SpectralDerivative (N-D class from this epic, or on the existing 2D/3D classes if that lands first):

  • dealiased_product(a, b): pad both spectra to 3N/2 per axis, inverse transform, multiply, forward transform, truncate. Provide as the implementation behind dealias="padding", and validate the dealias field so unknown strings raise.
  • iterated_laplacian(u, n): (−K2)^n multiplier, one transform pair.
  • vorticity_from_velocity, streamfunction_from_vorticity (with the null-mode gauge documented), velocity_from_vorticity = composition.
  • advect_vector(u, v): (u·∇)u, (u·∇)v with the same dealiasing policy as jacobian.
  • energy_spectrum(u) and enstrophy_spectrum(zeta): |k|-shell binning with bin edges at integer wavenumbers; return (k_bins, E).
  • helmholtz_inverse(u_hat, coeffs): general 1 / (1 + Σ c_n (−K2)^n) multiplier for IMEX; document with the QG example.

Acceptance criteria

  • dealiased_product(cos(Kx), cos(Kx)) at K = largest kept mode has zero energy at the alias index for N ∈ {30, 32, 48, 64}; matches the 2/3-truncated product to 1e-12 on the retained modes.
  • iterated_laplacian(u, 2) == biharmonic(u) to 1e-12.
  • vorticity_from_velocity(*velocity_from_streamfunction(psi)) == laplacian(psi) to 1e-12.
  • energy_spectrum of cos(3x) + cos(4y) puts all energy in bins 3 and 4.
  • Notebooks demo_qg.py, navier_stokes_2d.py, qg_model.py use the new methods (no hand-rolled spectra or loops).
Dominant language
Python
Stars
2
Forks
0
Avg merge
8h 13m
Merged PRs (30d)
8

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from jejjohnson/spectraldiffx

All issues in jejjohnson/spectraldiffx

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.