Sparse gradient and divergence operators for finite-volume discretisation.
Public API¶
| Symbol | Type | Summary |
|---|---|---|
construct_div | function | Construct a divergence matrix that maps face fluxes to cell balances. |
construct_grad | function | Construct the full gradient operator including boundary contributions. |
construct_grad_bc | function | Construct boundary-face gradient corrections and source terms. |
construct_grad_int | function | Construct the interior-face gradient operator. |
construct_div(shape, x_f, nu = 0, axis = 0, format = 'csc')¶
Construct a divergence matrix that maps face fluxes to cell balances.
Parameters¶
shape(tuple[int, ...] or int) Cell-centered field shape.x_f(array_like) Face coordinates alongaxis.nu(int or callable, optional) Geometry descriptor.0gives Cartesian,1cylindrical,2spherical, and a callablenu(x)enables custom metrics.axis(int, optional) Axis for flux divergence.format({‘csc’, ‘csr’}, optional) Sparse format of the returned operator.
Returns¶
scipy.sparse.csc_array or scipy.sparse.csr_arrayDivergence operator.
construct_grad(shape, x_f, x_c = None, bc = (None, None), axis = 0, shapes_d = (None, None), format = 'csc')¶
Construct the full gradient operator including boundary contributions.
Parameters¶
shape(tuple[int, ...] or int) Cell-centered field shape.x_f(array_like) Face coordinates alongaxis.x_c(array_like, optional) Cell-center coordinates alongaxis. If omitted, they are generated as arithmetic midpoints.bc(tuple[dict | None, dict | None], optional) Left and right boundary-condition dictionaries with coefficients'a','b', and'd'.axis(int, optional) Differentiation axis.shapes_d(tuple[tuple | None, tuple | None], optional) Optional output shapes for inhomogeneous boundary source vectors.format({‘csc’, ‘csr’}, optional) Sparse format used for returned operator matrices.
Returns¶
tupleWithoutshapes_d:(grad_matrix, grad_bc). Withshapes_d:(grad_matrix, grad_bc_left, grad_bc_right).
construct_grad_bc(shape, x_f, x_c = None, bc = (None, None), axis = 0, shapes_d = (None, None), format = 'csc')¶
Construct boundary-face gradient corrections and source terms.
Parameters¶
shape(tuple[int, ...]) Cell-centered field shape.x_f(array_like) Face coordinates alongaxis.x_c(array_like, optional) Cell-center coordinates.bc(tuple[dict | None, dict | None], optional) Left and right boundary-condition dictionaries with keysa,b, andd.axis(int, optional) Differentiation axis.shapes_d(tuple[tuple | None, tuple | None], optional) Optional source-vector shapes for left/right boundary contributions.format({‘csc’, ‘csr’}, optional) Sparse format for returned operator matrices.
Returns¶
tuple(grad_matrix_bc, grad_bc)whenshapes_dis not supplied, or(grad_matrix_left, grad_bc_left, grad_matrix_right, grad_bc_right)otherwise.
construct_grad_int(shape, x_f, x_c = None, axis = 0, format = 'csc')¶
Construct the interior-face gradient operator.
Parameters¶
shape(tuple[int, ...]) Cell-centered field shape.x_f(array_like) Face coordinates alongaxis.x_c(array_like, optional) Cell-center coordinates. If omitted, arithmetic midpoints are used.axis(int, optional) Differentiation axis.format({‘csc’, ‘csr’}, optional) Output sparse format.
Returns¶
scipy.sparse.csc_array or scipy.sparse.csr_arrayMatrix that maps cell-centered values to face-normal gradients.