Interpolation utilities between cell-centered and staggered grids.
Public API¶
| Symbol | Type | Summary |
|---|---|---|
compute_boundary_values | function | Compute boundary values and boundary-normal gradients. |
construct_boundary_value_matrices | function | Build matrices that evaluate boundary values from cell-centered unknowns. |
create_staggered_array | function | Create a face/staggered field from scalar, centered, or staggered input. |
interp_cntr_to_stagg | function | Interpolate cell-centered values to face/staggered locations. |
interp_cntr_to_stagg_tvd | function | Perform TVD interpolation from cell centers to faces. |
interp_stagg_to_cntr | function | Interpolate face/staggered values to cell centers. |
compute_boundary_values(cell_centered_values, x_f, x_c = None, bc = None, axis = 0, bound_id = None)¶
Compute boundary values and boundary-normal gradients.
Parameters¶
cell_centered_values(numpy.ndarray) Cell-centered solution values.x_f(array_like) Face coordinates alongaxis.x_c(array_like, optional) Cell-center coordinates.bc(dict or tuple[dict | None, dict | None], optional) Boundary-condition data. For a single boundary query (bound_idset), a single dictionary is accepted. For both boundaries, pass a two-element tuple.axis(int, optional) Axis normal to the boundary.bound_id({0, 1} or None, optional) Boundary selector.Nonereturns both boundaries.
Returns¶
tupleIfbound_idisNone:(value_left, grad_left, value_right, grad_right). Otherwise:(value, grad)for the requested boundary.
construct_boundary_value_matrices(shape, x_f, x_c = None, bc = None, axis = 0, bound_id = 0, shape_d = None, format = 'csc')¶
Build matrices that evaluate boundary values from cell-centered unknowns.
Parameters¶
shape(tuple[int, ...]) Cell-centered field shape.x_f(array_like) Face coordinates alongaxis.x_c(array_like, optional) Cell-center coordinates near the selected boundary.bc(dict, optional) Boundary-condition dictionary with keysa,b, andd.axis(int, optional) Boundary-normal axis.bound_id({0, 1}, optional)0for the lower/left boundary,1for upper/right.shape_d(tuple[int, ...], optional) Shape of external inhomogeneous source unknowns.format({‘csc’, ‘csr’}, optional) Sparse format for the homogeneous matrix.
Returns¶
tuple(matrix, mat_bc)wherematrixmaps cell-centered values to boundary values andmat_bcmaps inhomogeneous boundary terms.
create_staggered_array(array, shape, axis, x_f = None, x_c = None)¶
Create a face/staggered field from scalar, centered, or staggered input.
Parameters¶
array(array_like) Input values. May be scalar, centered, or already staggered.shape(tuple[int, ...] or int) Target centered-field shape.axis(int) Staggering axis.x_f, x_c(array_like, optional) Face and center coordinates used when centered input must be interpolated to faces.
Returns¶
numpy.ndarrayBroadcasted/interpolated array with staggered shape.
interp_cntr_to_stagg(cell_centered_values, x_f, x_c = None, axis = 0)¶
Interpolate cell-centered values to face/staggered locations.
Parameters¶
cell_centered_values(numpy.ndarray) Values defined at cell centers.x_f(array_like) Face coordinates alongaxis.x_c(array_like, optional) Cell-center coordinates. If omitted, midpoint locations are used.axis(int, optional) Interpolation axis.
Returns¶
numpy.ndarrayStaggered values with one additional element alongaxis.
interp_cntr_to_stagg_tvd(cell_centered_values, x_f, x_c = None, bc = None, v = 0, tvd_limiter = None, axis = 0)¶
Perform TVD interpolation from cell centers to faces.
Parameters¶
cell_centered_values(numpy.ndarray) Cell-centered values.x_f(array_like) Face coordinates alongaxis.x_c(array_like, optional) Cell-center coordinates. If omitted, midpoint locations are used.bc(tuple[dict | None, dict | None], optional) Left and right boundary-condition dictionaries with keysa,b, andd.v(float or array_like, optional) Face velocity used to determine upwind/downwind directions.tvd_limiter(callable, optional) Limiter function with signaturephi(c_norm, x_norm_c, x_norm_d). IfNone, the routine returns linear upwind interpolation without TVD correction.axis(int, optional) Interpolation axis.
Returns¶
tuple[numpy.ndarray, numpy.ndarray]Interpolated staggered values and TVD correction term.
interp_stagg_to_cntr(staggered_values, x_f, x_c = None, axis = 0)¶
Interpolate face/staggered values to cell centers.
Parameters¶
staggered_values(numpy.ndarray) Values defined on staggered (face) locations.x_f(array_like) Face coordinates alongaxis.x_c(array_like, optional) Cell-center coordinates. If omitted, midpoint interpolation is used.axis(int, optional) Interpolation axis.
Returns¶
numpy.ndarrayCell-centered values with one fewer element alongaxis.