Convenience Wrappers
High-level functions for common elliptic PDE inversions on C-grids.
Each wrapper dispatches to spectral, CG, or capacitance solvers
depending on the method argument.
Streamfunction from Vorticity
finitevolx.streamfunction_from_vorticity(zeta, dx, dy, bc='dst', lambda_=0.0, method='spectral', mask=None, capacitance_solver=None, preconditioner=None)
Invert the vorticity–streamfunction relation ∇²ψ − λψ = ζ.
Solves the Poisson (λ = 0) or Helmholtz (λ ≠ 0) equation to recover the streamfunction from relative vorticity.
Three solver methods are available:
"spectral"— Direct spectral solver (DST/DCT/FFT) for rectangular domains. Selected by bc. Default."cg"— Preconditioned Conjugate Gradient for masked / irregular domains. Requires mask. Uses a spectral preconditioner by default, or a custom one via preconditioner."capacitance"— Capacitance matrix method for masked domains. Requires a pre-built :class:CapacitanceSolvervia capacitance_solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zeta
|
Float[Array, 'Ny Nx']
|
Relative vorticity (right-hand side). |
required |
dx
|
float
|
Grid spacings. |
required |
dy
|
float
|
Grid spacings. |
required |
bc
|
('dst', 'dct', 'fft')
|
Boundary-condition type for the spectral solver (used by
|
"dst"
|
lambda_
|
float
|
Helmholtz parameter. Use 0.0 for the pure Poisson problem (streamfunction from vorticity). Non-zero values arise in QG PV inversion: (∇² − λ)ψ = q. |
0.0
|
method
|
('spectral', 'cg', 'capacitance')
|
Solver method. Default: |
"spectral"
|
mask
|
Float[Array, 'Ny Nx'] or ArakawaCGridMask or None
|
Domain mask. Required for |
None
|
capacitance_solver
|
CapacitanceSolver or None
|
Pre-built capacitance solver. Required for
|
None
|
preconditioner
|
callable or None
|
Custom preconditioner for |
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, 'Ny Nx']
|
Streamfunction ψ. |
Source code in finitevolx/_src/solvers/elliptic.py
Pressure from Divergence
finitevolx.pressure_from_divergence(div_u, dx, dy, bc='dct', method='spectral', mask=None, capacitance_solver=None, preconditioner=None)
Solve ∇²p = ∇·u for the pressure correction.
Used in pressure-projection methods (Chorin splitting) where the divergence of the provisional velocity field must be removed.
Solver selection follows the same three-method dispatch as
:func:streamfunction_from_vorticity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
div_u
|
Float[Array, 'Ny Nx']
|
Divergence of the velocity field (right-hand side). |
required |
dx
|
float
|
Grid spacings. |
required |
dy
|
float
|
Grid spacings. |
required |
bc
|
('dct', 'dst', 'fft')
|
Boundary-condition type for the spectral solver.
|
"dct"
|
method
|
('spectral', 'cg', 'capacitance')
|
Solver method. Default: |
"spectral"
|
mask
|
Float[Array, 'Ny Nx'] or ArakawaCGridMask or None
|
Domain mask. Required for |
None
|
capacitance_solver
|
CapacitanceSolver or None
|
Pre-built capacitance solver. Required for
|
None
|
preconditioner
|
callable or None
|
Custom preconditioner for |
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, 'Ny Nx']
|
Pressure field p. |
Source code in finitevolx/_src/solvers/elliptic.py
PV Inversion
finitevolx.pv_inversion(pv, dx, dy, lambda_, bc='dst', method='spectral', mask=None, capacitance_solver=None, preconditioner=None)
QG potential-vorticity inversion: solve (∇² − λ)ψ = q.
Supports batched / multi-layer PV fields. When lambda_ is a 1-D
array of shape (nl,), each layer is solved with its own Helmholtz
parameter (e.g. 1/Rd² per vertical mode from
:func:~finitevolx.decompose_vertical_modes).
Solver selection follows the same three-method dispatch as
:func:streamfunction_from_vorticity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pv
|
Float[Array, '... Ny Nx']
|
Potential-vorticity field. Leading dimensions are batched. |
required |
dx
|
float
|
Grid spacings. |
required |
dy
|
float
|
Grid spacings. |
required |
lambda_
|
float or Float[Array, ' nl']
|
Helmholtz parameter(s). Scalar for a single layer; array of
shape |
required |
bc
|
('dst', 'dct', 'fft')
|
Boundary-condition type (for |
"dst"
|
method
|
('spectral', 'cg', 'capacitance')
|
Solver method. Default: |
"spectral"
|
mask
|
Float[Array, 'Ny Nx'] or ArakawaCGridMask or None
|
Domain mask. Required for |
None
|
capacitance_solver
|
CapacitanceSolver or None
|
Pre-built capacitance solver. Required for
|
None
|
preconditioner
|
callable or None
|
Custom preconditioner for |
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, '... Ny Nx']
|
Streamfunction ψ, same shape as pv. |
Source code in finitevolx/_src/solvers/elliptic.py
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 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 540 541 542 | |