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
|
ArakawaCGrid2D
|
The underlying 2-D grid. |
required |
Examples:
>>> import jax.numpy as jnp
>>> from finitevolx import ArakawaCGrid2D, Diffusion2D
>>> grid = ArakawaCGrid2D.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
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 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 | |
__call__(h, kappa, mask_h=None, mask_u=None, mask_v=None)
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 |
mask_h
|
Bool[Array, 'Ny Nx'] or Float[Array, 'Ny Nx'] or None
|
Ocean mask at T-points (1/True = ocean, 0/False = land). |
None
|
mask_u
|
Bool[Array, 'Ny Nx'] or Float[Array, 'Ny Nx'] or None
|
Ocean mask at U-points (1/True = ocean, 0/False = land). |
None
|
mask_v
|
Bool[Array, 'Ny Nx'] or Float[Array, 'Ny Nx'] or None
|
Ocean mask at V-points (1/True = ocean, 0/False = land). |
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, 'Ny Nx']
|
Diffusion tendency at T-points. |
Source code in finitevolx/_src/diffusion/diffusion.py
fluxes(h, kappa, mask_u=None, mask_v=None)
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 |
mask_u
|
Bool[Array, 'Ny Nx'] or Float[Array, 'Ny Nx'] or None
|
Ocean mask at U-points (1/True = ocean, 0/False = land). |
None
|
mask_v
|
Bool[Array, 'Ny Nx'] or Float[Array, 'Ny Nx'] or None
|
Ocean mask at V-points (1/True = ocean, 0/False = land). |
None
|
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
|
ArakawaCGrid3D
|
The underlying 3-D grid. |
required |
Examples:
>>> import jax.numpy as jnp
>>> from finitevolx import ArakawaCGrid3D, Diffusion3D
>>> grid = ArakawaCGrid3D.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
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 393 394 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 | |
__call__(h, kappa, mask_h=None, mask_u=None, mask_v=None)
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 |
mask_h
|
Bool[Array, 'Nz Ny Nx'] or Float[Array, 'Nz Ny Nx'] or None
|
Ocean mask at T-points (1/True = ocean, 0/False = land). |
None
|
mask_u
|
Bool[Array, 'Nz Ny Nx'] or Float[Array, 'Nz Ny Nx'] or None
|
Ocean mask at U-points (1/True = ocean, 0/False = land). |
None
|
mask_v
|
Bool[Array, 'Nz Ny Nx'] or Float[Array, 'Nz Ny Nx'] or None
|
Ocean mask at V-points (1/True = ocean, 0/False = land). |
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, 'Nz Ny Nx']
|
Diffusion tendency at T-points. |
Source code in finitevolx/_src/diffusion/diffusion.py
fluxes(h, kappa, mask_u=None, mask_v=None)
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 |
mask_u
|
Bool[Array, 'Nz Ny Nx'] or Float[Array, 'Nz Ny Nx'] or None
|
Ocean mask at U-points (1/True = ocean, 0/False = land). |
None
|
mask_v
|
Bool[Array, 'Nz Ny Nx'] or Float[Array, 'Nz Ny Nx'] or None
|
Ocean mask at V-points (1/True = ocean, 0/False = land). |
None
|
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
|
ArakawaCGrid2D
|
The underlying 2-D grid. |
required |
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 ArakawaCGrid2D, BiharmonicDiffusion2D
>>> grid = ArakawaCGrid2D.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
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 | |
__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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
ArakawaCGrid3D
|
The underlying 3-D grid. |
required |
Examples:
>>> import jax.numpy as jnp
>>> from finitevolx import ArakawaCGrid3D, BiharmonicDiffusion3D
>>> grid = ArakawaCGrid3D.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
__call__(h, kappa)
Apply horizontal biharmonic diffusion and return the tendency -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, mask_h=None, mask_u=None, mask_v=None)
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.
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 |
mask_h
|
Bool[Array, 'Ny Nx'] or Float[Array, 'Ny Nx'] or None
|
Ocean mask at T-points (1/True = ocean, 0/False = land). If provided, land-cell tendencies are zeroed. |
None
|
mask_u
|
Bool[Array, 'Ny Nx'] or Float[Array, 'Ny Nx'] or None
|
Ocean mask at U-points (1/True = ocean, 0/False = land). If provided, east-face fluxes through land boundaries are zeroed. |
None
|
mask_v
|
Bool[Array, 'Ny Nx'] or Float[Array, 'Ny Nx'] or None
|
Ocean mask at V-points (1/True = ocean, 0/False = land). If provided, north-face fluxes through land boundaries are zeroed. |
None
|
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)
Source code in finitevolx/_src/diffusion/diffusion.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |