Diffusion Operators
Harmonic (∇²) and biharmonic (∇⁴) diffusion operators for C-grid staggered models.
finitevolx.Diffusion2D
Bases: Module
Horizontal diffusion operator (flux form) on a 2-D Arakawa C-grid.
Computes ∂h/∂t = ∇·(κ ∇h) at T-points from staggered face fluxes via forward-then-backward finite differences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
CartesianGrid2D
|
The underlying 2-D grid. |
required |
mask
|
Mask2D or None
|
Optional land/ocean mask. When provided, the three-step
intermediate-flux masking pattern is applied inside both
:meth:
Unlike most other operators in this package, diffusion cannot
use the simpler post-compute pattern because the divergence at
wet T-cells adjacent to land would otherwise be contaminated
by polluted dry-side face fluxes. |
required |
Examples:
>>> import jax.numpy as jnp
>>> from finitevolx import CartesianGrid2D, Diffusion2D
>>> grid = CartesianGrid2D.from_interior(8, 8, 1.0, 1.0)
>>> diff_op = Diffusion2D(grid=grid)
>>> h = jnp.ones((grid.Ny, grid.Nx))
>>> tendency = diff_op(h, kappa=1e-3) # zero for constant tracer
>>> flux_x, flux_y = diff_op.fluxes(h, kappa=1e-3)
Source code in finitevolx/_src/diffusion/diffusion.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
__call__(h, kappa, wall='closed')
Diffusion tendency ∂h/∂t = ∇·(κ ∇h) at T-points.
dh[j, i] = (flux_x[j, i+1/2] - flux_x[j, i-1/2]) / dx + (flux_y[j+1/2, i] - flux_y[j-1/2, i]) / dy
where: flux_x[j, i+1/2] = κ * (h[j, i+1] - h[j, i]) / dx flux_y[j+1/2, i] = κ * (h[j+1, i] - h[j, i]) / dy
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h
|
Float[Array, 'Ny Nx']
|
Tracer field at T-points. |
required |
kappa
|
float or Float[Array, 'Ny Nx']
|
Diffusion coefficient (scalar or T-point field). |
required |
wall
|
('closed', 'open')
|
Domain-wall face treatment. |
"closed"
|
Returns:
| Type | Description |
|---|---|
Float[Array, 'Ny Nx']
|
Diffusion tendency at T-points. When |
Source code in finitevolx/_src/diffusion/diffusion.py
fluxes(h, kappa, wall='closed')
Diagnostic diffusive face fluxes at U- and V-points.
Returns the east-face and north-face diffusive fluxes before the divergence step, useful for flux-conservative time-stepping and diagnostics.
flux_x[j, i+1/2] = κ * (h[j, i+1] - h[j, i]) / dx (U-points)
flux_y[j+1/2, i] = κ * (h[j+1, i] - h[j, i]) / dy (V-points)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h
|
Float[Array, 'Ny Nx']
|
Tracer field at T-points. |
required |
kappa
|
float or Float[Array, 'Ny Nx']
|
Diffusion coefficient (scalar or T-point field). |
required |
wall
|
('closed', 'open')
|
Domain-wall face treatment (see :meth: |
"closed"
|
Returns:
| Type | Description |
|---|---|
tuple[Float[Array, 'Ny Nx'], Float[Array, 'Ny Nx']]
|
|
Source code in finitevolx/_src/diffusion/diffusion.py
finitevolx.Diffusion3D
Bases: Module
Horizontal diffusion operator (flux form) on a 3-D Arakawa C-grid.
Applies ∂h/∂t = ∇·(κ ∇h) independently at each z-level. The 3-D array shape is [Nz, Ny, Nx].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
CartesianGrid3D
|
The underlying 3-D grid. |
required |
mask
|
Mask3D or None
|
Optional 3-D land/ocean mask. When provided, the intermediate
flux masking pattern from :class: |
required |
Examples:
>>> import jax.numpy as jnp
>>> from finitevolx import CartesianGrid3D, Diffusion3D
>>> grid = CartesianGrid3D.from_interior(4, 8, 8, 1.0, 1.0, 1.0)
>>> diff_op = Diffusion3D(grid=grid)
>>> h = jnp.ones((grid.Nz, grid.Ny, grid.Nx))
>>> tendency = diff_op(h, kappa=1e-3) # zero for constant tracer
Source code in finitevolx/_src/diffusion/diffusion.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | |
__call__(h, kappa, wall='closed')
Diffusion tendency ∂h/∂t = ∇·(κ ∇h) at T-points over all z-levels.
Applies the horizontal diffusion stencil independently at each
z-level. Only interior cells [1:-1, 1:-1, 1:-1] are written;
the ghost ring is left as zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h
|
Float[Array, 'Nz Ny Nx']
|
Tracer field at T-points. |
required |
kappa
|
float or Float[Array, 'Nz Ny Nx']
|
Diffusion coefficient (scalar or T-point field). |
required |
wall
|
('closed', 'open')
|
Lateral domain-wall face treatment, applied identically at every
z-level (see :class: |
"closed"
|
Returns:
| Type | Description |
|---|---|
Float[Array, 'Nz Ny Nx']
|
Diffusion tendency at T-points. When |
Source code in finitevolx/_src/diffusion/diffusion.py
fluxes(h, kappa, wall='closed')
Diagnostic diffusive face fluxes at U- and V-points, all z-levels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h
|
Float[Array, 'Nz Ny Nx']
|
Tracer field at T-points. |
required |
kappa
|
float or Float[Array, 'Nz Ny Nx']
|
Diffusion coefficient (scalar or T-point field). |
required |
wall
|
('closed', 'open')
|
Lateral domain-wall face treatment (see :class: |
"closed"
|
Returns:
| Type | Description |
|---|---|
tuple[Float[Array, 'Nz Ny Nx'], Float[Array, 'Nz Ny Nx']]
|
|
Source code in finitevolx/_src/diffusion/diffusion.py
finitevolx.BiharmonicDiffusion2D
Bases: Module
Biharmonic (∇⁴) diffusion operator on a 2-D Arakawa C-grid.
Computes the local biharmonic diffusion tendency:
∂h/∂t|_diff = −κ · ∇⁴h
where ∇⁴h = ∇²(∇²h) is implemented as two successive flux-form
Laplacians via :class:Diffusion2D. The negative sign ensures that a
positive κ provides dissipation (the operator damps high-wavenumber
modes).
Scale-selective property: for a Fourier mode with wavenumber k, the
harmonic tendency scales as −κ_h · k² while the biharmonic tendency
scales as −κ_bi · k⁴. Biharmonic diffusion therefore damps small
scales much more strongly than large scales.
Only interior cells [1:-1, 1:-1] are written; the ghost ring is
zero. The caller is responsible for boundary conditions.
Notes
The ghost ring of the intermediate Laplacian ∇²h is zero (Dirichlet-0),
not a zero-normal-gradient (Neumann) BC. This means the second Laplacian
pass reads a zero halo for the intermediate field, which contaminates the
outermost interior row/column of the final tendency even if the input h
had correctly set ghost cells. Only results in the deep interior
[2:-2, 2:-2] are fully BC-consistent. For periodic domains, call
enforce_periodic on h before invoking this operator; this sets the
input ghost ring correctly and reduces (but does not eliminate) the
Dirichlet-0 contamination of the intermediate field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
CartesianGrid2D
|
The underlying 2-D grid. |
required |
mask
|
Mask2D or None
|
Optional land/ocean mask. When provided, the inner harmonic
Diffusion2D is deliberately built with |
None
|
References
.. [1] MITgcm Biharmonic Mixing: https://mitgcm.readthedocs.io/en/latest/optionals/packages/mixing.html#biharmonic-mixing .. [2] Leith, C. E. (1968). Diffusion approximation for two-dimensional turbulence. Physics of Fluids, 11(3), 671-673.
Examples:
>>> import jax.numpy as jnp
>>> from finitevolx import CartesianGrid2D, BiharmonicDiffusion2D
>>> grid = CartesianGrid2D.from_interior(8, 8, 1.0, 1.0)
>>> op = BiharmonicDiffusion2D(grid=grid)
>>> h = jnp.ones((grid.Ny, grid.Nx))
>>> tend = op(h, kappa=1e-6) # zero for constant field
>>> tend.shape
(10, 10)
Source code in finitevolx/_src/diffusion/diffusion.py
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 | |
__call__(h, kappa)
Apply biharmonic diffusion and return the tendency -kappa * nabla^4 h.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h
|
Float[Array, 'Ny Nx']
|
Scalar tracer field at T-points, shape |
required |
kappa
|
float
|
Biharmonic diffusion coefficient (kappa >= 0 gives dissipation). |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, 'Ny Nx']
|
Tendency -kappa * nabla^4 h at T-points, same shape as |
Source code in finitevolx/_src/diffusion/diffusion.py
finitevolx.BiharmonicDiffusion3D
Bases: Module
Biharmonic (nabla^4) diffusion operator on a 3-D Arakawa C-grid.
Applies the horizontal biharmonic Laplacian independently at each z-level:
dh/dt|_diff = -kappa * nabla^4_h h
where nabla^4_h = nabla^2_h(nabla^2_h) denotes the horizontal biharmonic
operator, implemented as two successive :class:Diffusion3D passes.
Only interior cells [1:-1, 1:-1, 1:-1] are written; the ghost ring
is zero. The caller is responsible for boundary conditions.
Notes
The ghost ring of the intermediate Laplacian is zero (Dirichlet-0).
See :class:BiharmonicDiffusion2D notes for details.
The inner harmonic :class:Diffusion3D is deliberately built with
mask=None; the outer mask is applied as a post-compute * mask.h
on the final tendency only — same exception as
:class:BiharmonicDiffusion2D.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
CartesianGrid3D
|
The underlying 3-D grid. |
required |
mask
|
Mask3D or None
|
Optional 3-D land/ocean mask. Applied final-only (see class docstring). |
None
|
Examples:
>>> import jax.numpy as jnp
>>> from finitevolx import CartesianGrid3D, BiharmonicDiffusion3D
>>> grid = CartesianGrid3D.from_interior(4, 8, 8, 1.0, 1.0, 1.0)
>>> op = BiharmonicDiffusion3D(grid=grid)
>>> h = jnp.ones((grid.Nz, grid.Ny, grid.Nx))
>>> tend = op(h, kappa=1e-6)
>>> tend.shape
(6, 10, 10)
Source code in finitevolx/_src/diffusion/diffusion.py
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 | |
__call__(h, kappa)
Apply horizontal biharmonic diffusion: -kappa * nabla^4_h h.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h
|
Float[Array, 'Nz Ny Nx']
|
Scalar tracer field at T-points, shape |
required |
kappa
|
float
|
Biharmonic diffusion coefficient (kappa >= 0 gives dissipation). |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, 'Nz Ny Nx']
|
Tendency -kappa * nabla^4_h h at T-points, same shape as |
Source code in finitevolx/_src/diffusion/diffusion.py
finitevolx.diffusion_2d(h, kappa, dx, dy)
Horizontal tracer diffusion tendency at T-points (flux form).
Computes ∂h/∂t = ∇·(κ ∇h) = ∂/∂x(κ ∂h/∂x) + ∂/∂y(κ ∂h/∂y) at interior T-points using forward-then-backward finite differences.
Only interior cells [1:-1, 1:-1] are written; the ghost ring is left
as zero. East and north boundary faces are not computed, giving no-flux
(closed-wall) BCs at all four domain walls by default.
This is the mask-free functional form. For masked diffusion, use
:class:Diffusion2D with a mask= class attribute; it applies the
mask via the intermediate-flux pattern described in the module
docstring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h
|
Float[Array, 'Ny Nx']
|
Tracer field at T-points. |
required |
kappa
|
float or Float[Array, 'Ny Nx']
|
Diffusion coefficient. May be a scalar or an array of the same shape
as |
required |
dx
|
float
|
Grid spacing in x. |
required |
dy
|
float
|
Grid spacing in y. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, 'Ny Nx']
|
Diffusion tendency ∂h/∂t at T-points, same shape as |
Examples:
>>> import jax.numpy as jnp
>>> h = jnp.zeros((10, 10))
>>> tendency = diffusion_2d(h, kappa=1.0, dx=0.1, dy=0.1)
>>> tendency.shape
(10, 10)