Skip to content

Add scalar diffusion solver#944

Merged
brendancol merged 1 commit intomasterfrom
add-diffusion-940
Mar 4, 2026
Merged

Add scalar diffusion solver#944
brendancol merged 1 commit intomasterfrom
add-diffusion-940

Conversation

@brendancol
Copy link
Contributor

Summary

  • New diffuse() function: forward-Euler solver for the 2D diffusion equation (5-point Laplacian stencil)
  • Uniform or spatially varying diffusivity, auto CFL time step, four boundary modes
  • numpy (@ngjit), cupy (@cuda.jit), dask+numpy, dask+cupy via map_overlap

Changes

  • xrspatial/diffusion.py -- new module
  • xrspatial/tests/test_diffusion.py -- 15 tests (correctness, conservation, NaN handling, dask parity, input validation)
  • xrspatial/__init__.py -- re-export diffuse
  • xrspatial/accessor.py -- .xrs.diffuse() on DataArray and Dataset
  • docs/source/reference/diffusion.rst -- API docs
  • docs/source/reference/index.rst -- toctree entry
  • README.md -- feature matrix row
  • examples/user_guide/16_Diffusion.ipynb -- user guide notebook

Test plan

  • pytest xrspatial/tests/test_diffusion.py passes (15/15)
  • Verify GPU backends on a CUDA machine
  • Run the notebook end-to-end

Closes #940

New `diffuse()` function that runs explicit forward-Euler diffusion on
a 2D raster.  Supports uniform or spatially varying diffusivity, auto
CFL time step, and all four backends (numpy, cupy, dask+numpy, dask+cupy).
@github-actions github-actions bot added the performance PR touches performance-sensitive code label Mar 4, 2026
@brendancol brendancol merged commit 837eab3 into master Mar 4, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add scalar diffusion solver

1 participant