Meshes and backend

class geoswe.Mesh2D(nx, ny, dx, dy, x0=0.0, y0=0.0, ngh=4)[source]

Bases: object

Uniform 2D cell-centred Cartesian mesh: nx × ny cells of size dx × dy with ngh ghost cells on every side.

Parameters:
nx: int
ny: int
dx: float
dy: float
x0: float = 0.0
y0: float = 0.0
ngh: int = 4
interior(arr)[source]

Strip the ghost layers of a single padded SCALAR field.

Scalar-field-only: arr must be 2-D, shape (nx+2*ngh, ny+2*ngh). For a stacked state q of shape (3, Nx, Ny), apply per component (mesh.interior(q[0])); passing the stack would silently slice the (variable, x) axes instead of (x, y).

Parameters:

arr (ndarray)

Return type:

ndarray

pad(arr)[source]

Zero-pad a SCALAR field of shape (nx, ny) with ngh ghost layers.

Scalar-field-only (see interior): arr must be 2-D.

Parameters:

arr (ndarray)

Return type:

ndarray

class geoswe.Mesh1D(nx, dx, x0=0.0, ngh=4)[source]

Bases: object

Uniform 1D cell-centred mesh: nx cells of width dx starting at x0, with ngh ghost cells per side.

Parameters:
nx: int
dx: float
x0: float = 0.0
ngh: int = 4
property length: float

Physical length of the interior, nx * dx.

interior(arr)[source]

Strip the ghost layers of a single padded SCALAR field, shape (nx+2*ngh,).

Scalar-field-only: for a stacked state q of shape (Nvar, N), apply per component (mesh.interior(q[0])).

Parameters:

arr (ndarray)

Return type:

ndarray

pad(arr)[source]

Allocate a padded array of length nx + 2*ngh and copy interior values.

Scalar-field-only: arr must have shape (nx,) (see interior).

Parameters:

arr (ndarray)

Return type:

ndarray

Backend control

These live in geoswe.backend and are re-exported at the top level, which is how every page and example calls them: geoswe.get_backend(). geoswe.set_backend only takes effect before any solver module has been imported; see Installation.

geoswe.set_backend(name)[source]

Switch the global backend to ‘numpy’ or ‘cupy’.

Must be called before any solver module is imported: geoswe.solver (and the CUDA kernels behind it) freeze the backend choice at import time, so a late switch would silently run the wrong code path. Prefer setting the GEOSWE_BACKEND environment variable before import geoswe.

Parameters:

name (str)

geoswe.get_backend()[source]

Return "cupy" when the GPU backend is active, else "numpy".

Return type:

str

geoswe.gpu_platform()[source]

GPU stack behind the CuPy backend: "cuda" (NVIDIA), "hip" (AMD ROCm), or None on the NumPy backend.

geoswe.to_host(arr)[source]

Return a NumPy array regardless of backend.

geoswe.to_device(arr)[source]

Move a host array to the current backend (GPU if CuPy).

geoswe.sync()[source]

Block until all GPU operations have completed (no-op on CPU).