numbacs.flows
Module Contents
- numbacs.flows.get_interp_arrays_2D(tvals, xvals, yvals, U, V)[source]
Compute coefficient arrays for cubic spline of velocity field defined by U,V over values tvals,xvals,yvals and return the grid tuple and coefficient arrays which can be used by ‘eval_spline’ function of the interpolation package.
- Parameters:
tvals (np.ndarray, shape = (nt,)) – times over which the ode is defined, must be ascending.
xvals (np.ndarray, shape = (nx,)) – x values over which the ode is defined, must be ascending.
yvals (np.ndarray, shape = (ny,)) – y values over which the ode is defined, must be ascending.
U (np.ndarray, shape = (nt,nx,ny)) – x-compnent of the velocity.
V (np.ndarray, shape = (nt,nx,ny)) – y-compnent of the velocity.
- Returns:
grid_vel (tuple) – grid endpoints and number of points in x and y directions
C_eval_u (np.ndarray, shape = (nt+2,nx+2,ny+2)) – array containing coefficients for u cubic spline.
C_eval_v (np.ndarray, shape = (nt+2,nx+2,ny+2)) – array containing coefficients for v cubic spline.
- numbacs.flows.get_interp_arrays_2D_steady(xvals, yvals, U, V)[source]
Compute coefficient arrays for cubic spline of velocity field defined by U,V over values xvals,yvals and return the grid tuple and coefficient arrays which can be used by ‘eval_spline’ function of the interpolation package.
- Parameters:
xvals (np.ndarray, shape = (nx,)) – x values over which the ode is defined, must be ascending.
yvals (np.ndarray, shape = (ny,)) – y values over which the ode is defined, must be ascending.
U (np.ndarray, shape = (nt,nx,ny)) – x-compnent of the velocity.
V (np.ndarray, shape = (nt,nx,ny)) – y-compnent of the velocity.
- Returns:
grid_vel (tuple) – grid endpoints and number of points in x and y directions
C_eval_u (np.ndarray, shape = (nt+2,nx+2,ny+2)) – array containing coefficients for u cubic spline.
C_eval_v (np.ndarray, shape = (nt+2,nx+2,ny+2)) – array containing coefficients for v cubic spline.
- numbacs.flows.get_interp_arrays_scalar(tvals, xvals, yvals, f)[source]
Compute coefficient arrays for cubic spline of scalar field f defined over values tvals,xvals,yvals and return the grid tuple and coefficient array which can be used by ‘eval_spline’ function of the interpolation package.
- Parameters:
tvals (np.ndarray, shape = (nt,)) – times over which the f is defined, must be ascending.
xvals (np.ndarray, shape = (nx,)) – x values over which f ode is defined, must be ascending.
yvals (np.ndarray, shape = (ny,)) – y values over which the f is defined, must be ascending.
f (np.ndarray, shape = (nt,nx,ny)) – scalar value to be interpolated.
- Returns:
grid_f (tuple) – grid endpoints and number of points in t, x and y directions
C_eval_f (np.ndarray, shape = (nt+2,nx+2,ny+2)) – array containing coefficients for f cubic spline.
- numbacs.flows.get_flow_2D(grid_vel, C_eval_u, C_eval_v, spherical=0, extrap_mode='constant', r=6371.0)[source]
Create a C callback for the ode defined by the vector field (U,V) defined over a spatial grid given by (xvals,yvals) over times defined by tvals. Cubic interpolant is used.
- Parameters:
grid_vel (tuple) – grid endpoints and number of points in x and y directions
C_eval_u (np.ndarray, shape = (nt+2,nx+2,ny+2)) – array containing coefficients for u cubic spline.
C_eval_v (np.ndarray, shape = (nt+2,nx+2,ny+2)) – array containing coefficients for v cubic spline.
spherical (int, optional) – int used to determine if flow is defined in spherical coordinate system; 0 if not spherical, 1 if spherical and lon = [-180,180), 2 if spherical and lon = [0,360), units expected are degrees and both lon and lat must be ascending, lat is expected to = [-90,90]. The default is 0.
extrap_mode (str, optional) – type of extrapolation mode used for interpolant. The default is ‘constant’.
r (float, optional) – radius used for spherical conversion, used if spherical > 0. The default is 6371.
- Returns:
funcptr – address to C callback.
- Return type:
int
- numbacs.flows.get_callable_2D(grid_vel, C_eval_u, C_eval_v, spherical=0, extrap_mode='constant', r=6371.0, return_type='array')[source]
Create a jit-callable spline for the ode defined by the vector field (U,V) defined over a spatial grid given by (xvals,yvals) over times defined by tvals.
- Parameters:
grid_vel (tuple) – grid endpoints and number of points in t, x, and y directions
C_eval_u (np.ndarray, shape = (nt+2,nx+2,ny+2)) – array containing coefficients for u cubic spline.
C_eval_v (np.ndarray, shape = (nt+2,nx+2,ny+2)) – array containing coefficients for v cubic spline.
spherical (int, optional) – int used to determine if flow is defined in spherical coordinate system; 0 if not spherical, 1 if spherical, units expected are degrees and both lon and lat must be ascending, lat is expected to = [-90,90]. The default is 0.
extrap_mode (str, optional) – type of extrapolation mode used for interpolant. The default is ‘constant’.
r (float, optional) – radius used for spherical conversion, used if spherical = 1. The default is 6371.
- Returns:
vel_spline – jit-callable function for vector field.
- Return type:
jit-callable
- numbacs.flows.get_callable_scalar(grid_f, C_eval_f, extrap_mode='constant')[source]
Create jit-callable spline for scalar field f defined over grid_f.
- Parameters:
grid_f (tuple) – grid endpoints and number of points in t, x, and y directions.
C_eval_f (np.ndarray, shape = (nt+2,nx+2,ny+2)) – array containing coefficients for f cubic spline.
extrap_mode (str, optional) – type of extrapolation mode used for interpolant. The default is ‘constant’.
- Returns:
f_spline – jit callable function for spline of f.
- Return type:
jit-callable
- numbacs.flows.get_flow_linear_2D(grid_vel, U, V, spherical=0, extrap_mode='constant', r=6371.0)[source]
Create a C callback for the ode defined by the vector field (U,V) defined over a grid given by (xvals,yvals) over times defined by tvals. Linear interpolant is used. It is currently recommended to use the spline version as, in our tests, the spline is both more accurate and faster when used in ode solver.
- Parameters:
grid_vel (tuple) – grid endpoints and number of points in x and y directions
U (np.ndarray, shape = (nt,nx,ny)) – x-compnent of the velocity.
V (np.ndarray, shape = (nt,nx,ny)) – y-compnent of the velocity.
spherical (int, optional) – int used to determine if flow is defined in spherical coordinate system; 0 if not spherical, 1 if spherical and lon = [-180,180), 2 if spherical and lon = [0,360), units expected are degrees and both lon and lat must be ascending, lat is expected to = [-90,90]. The default is 0.
extrap_mode (str, optional) – type of extrapolation mode used for interpolant. The default is ‘constant’.
r (float, optional) – radius used for spherical conversion, used if spherical > 0. The default is 6371.
- Returns:
funcptr – address to C callback.
- Return type:
int
- numbacs.flows.get_callable_linear_2D(grid_vel, U, V, spherical=0, extrap_mode='constant', r=6371.0, return_type='array')[source]
Create a jit-callable for the ode defined by the vector field (U,V) defined over a spatial grid given by (xvals,yvals) over times defined by tvals. Linear interpolant is used.
- Parameters:
grid_vel (tuple) – grid endpoints and number of points in x and y directions
U (np.ndarray, shape = (nt,nx,ny)) – x-compnent of the velocity.
V (np.ndarray, shape = (nt,nx,ny)) – y-compnent of the velocity.
spherical (int, optional) – int used to determine if flow is defined in spherical coordinate system; 0 if not spherical, 1 if spherical units expected are degrees and both lon and lat must be ascending, lat is expected to = [-90,90]. The default is 0.
return_spline (boolean, optional) – flag to determine if spline is returned. The default is False.
extrap_mode (str, optional) – type of extrapolation mode used for interpolant. The default is ‘constant’.
r (float, optional) – radius used for spherical conversion, used if spherical > 0. The default is 6371.
return_type (np.ndarray or tuple, optional) – determines the return type of the callable generated here. If return_type == ‘array’, only a single point can be passed to vel_func (needed for funcs from numbacs.diagnostics), if return_type == ‘tuple’, many points (or a single point) can be passed to vel_func at once for quicker computation.
- Returns:
vel_spline – jit-callable function for vector field.
- Return type:
jit-callable
- numbacs.flows.get_callable_scalar_linear(grid_f, f, extrap_mode='constant')[source]
Create jit-callable linear interpolant for scalar field f defined over grid_f. Linear interpolant is used.
- Parameters:
grid_f (tuple) – grid endpoints and number of points in t, x, and y directions.
f (np.ndarray, shape = (nt,nx,ny)) – array containing values of f.
extrap_mode (str, optional) – type of extrapolation mode used for interpolant. The default is ‘constant’.
- Returns:
f_interp – jit callable function for linear interpolant of f.
- Return type:
jit-callable
- numbacs.flows.get_predefined_flow(flow_str, int_direction=1.0, return_default_params=True, return_domain=True, parameter_description=False)[source]
Create a C callback for one of the predefined flows.
- Parameters:
flow_str (str) – string representing which flow to retrieve. Currently ‘double_gyre’, ‘bickley_jet’, and ‘abc’ are supported.
int_direction (float, optional) – direction of integration (either -1. or 1.). The default is 1.
return_default_params (boolean, optional) – flag to determine if default parameters will be returned. The default is True.
return_domain (boolean, optional) – flag to determine if domain will be returned. The default is True.
parameter_description (boolean, optional) – flag to determine if string containing description of parameters is returned. The default if False.
- Returns:
funcptr (int) – address of C callback.
default_params (np.ndarray, shape = (nprms,), optional) – default parameters.
domain (tuple, optional) – array containing endpoints of domain for each dimension.
p_str (str, optional) – string containing description of parameters in equation.
- numbacs.flows.get_predefined_callable(flow_str, params=None, return_domain=True, parameter_description=False, return_type='array')[source]
Create a jit-callable for one of the predefined flows.
- Parameters:
flow_str (str) – string representing which flow to retrieve. Currently ‘double_gyre’, ‘bickley_jet’, and ‘abc’ are supported.
params (np.ndarray, shape = (nprms,), optional) – parameters to be used to define the flow. The default is None, i.e. default params.
return_domain (boolean, optional) – flag to determine if domain will be returned. The default is True.
parameter_description (boolean, optional) – flag to determine if string containing description of parameters is returned. The default if False.
- Returns:
func (jit-callable) – jit callable function for vector field.
domain (tuple, optional) – array containing endpoints of domain for each dimension.
p_str (str, optional) – string containing description of parameters in equation.