numbacs.flows ============= .. py:module:: numbacs.flows Module Contents --------------- .. py:function:: get_interp_arrays_2D(tvals, xvals, yvals, U, V) 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. :param tvals: times over which the ode is defined, must be ascending. :type tvals: np.ndarray, shape = (nt,) :param xvals: x values over which the ode is defined, must be ascending. :type xvals: np.ndarray, shape = (nx,) :param yvals: y values over which the ode is defined, must be ascending. :type yvals: np.ndarray, shape = (ny,) :param U: x-compnent of the velocity. :type U: np.ndarray, shape = (nt,nx,ny) :param V: y-compnent of the velocity. :type V: np.ndarray, shape = (nt,nx,ny) :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. .. py:function:: get_interp_arrays_2D_steady(xvals, yvals, U, V) 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. :param xvals: x values over which the ode is defined, must be ascending. :type xvals: np.ndarray, shape = (nx,) :param yvals: y values over which the ode is defined, must be ascending. :type yvals: np.ndarray, shape = (ny,) :param U: x-compnent of the velocity. :type U: np.ndarray, shape = (nt,nx,ny) :param V: y-compnent of the velocity. :type V: np.ndarray, shape = (nt,nx,ny) :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. .. py:function:: get_interp_arrays_scalar(tvals, xvals, yvals, f) 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. :param tvals: times over which the f is defined, must be ascending. :type tvals: np.ndarray, shape = (nt,) :param xvals: x values over which f ode is defined, must be ascending. :type xvals: np.ndarray, shape = (nx,) :param yvals: y values over which the f is defined, must be ascending. :type yvals: np.ndarray, shape = (ny,) :param f: scalar value to be interpolated. :type f: np.ndarray, shape = (nt,nx,ny) :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. .. py:function:: get_flow_2D(grid_vel, C_eval_u, C_eval_v, spherical=0, extrap_mode='constant', r=6371.0) 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. :param grid_vel: grid endpoints and number of points in x and y directions :type grid_vel: tuple :param C_eval_u: array containing coefficients for u cubic spline. :type C_eval_u: np.ndarray, shape = (nt+2,nx+2,ny+2) :param C_eval_v: array containing coefficients for v cubic spline. :type C_eval_v: np.ndarray, shape = (nt+2,nx+2,ny+2) :param spherical: 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. :type spherical: int, optional :param extrap_mode: type of extrapolation mode used for interpolant. The default is 'constant'. :type extrap_mode: str, optional :param r: radius used for spherical conversion, used if spherical > 0. The default is 6371. :type r: float, optional :returns: **funcptr** -- address to C callback. :rtype: int .. py:function:: get_callable_2D(grid_vel, C_eval_u, C_eval_v, spherical=0, extrap_mode='constant', r=6371.0, return_type='array') 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. :param grid_vel: grid endpoints and number of points in t, x, and y directions :type grid_vel: tuple :param C_eval_u: array containing coefficients for u cubic spline. :type C_eval_u: np.ndarray, shape = (nt+2,nx+2,ny+2) :param C_eval_v: array containing coefficients for v cubic spline. :type C_eval_v: np.ndarray, shape = (nt+2,nx+2,ny+2) :param spherical: 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. :type spherical: int, optional :param extrap_mode: type of extrapolation mode used for interpolant. The default is 'constant'. :type extrap_mode: str, optional :param r: radius used for spherical conversion, used if spherical = 1. The default is 6371. :type r: float, optional :returns: **vel_spline** -- jit-callable function for vector field. :rtype: jit-callable .. py:function:: get_callable_scalar(grid_f, C_eval_f, extrap_mode='constant') Create jit-callable spline for scalar field f defined over grid_f. :param grid_f: grid endpoints and number of points in t, x, and y directions. :type grid_f: tuple :param C_eval_f: array containing coefficients for f cubic spline. :type C_eval_f: np.ndarray, shape = (nt+2,nx+2,ny+2) :param extrap_mode: type of extrapolation mode used for interpolant. The default is 'constant'. :type extrap_mode: str, optional :returns: **f_spline** -- jit callable function for spline of f. :rtype: jit-callable .. py:function:: get_flow_linear_2D(grid_vel, U, V, spherical=0, extrap_mode='constant', r=6371.0) 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. :param grid_vel: grid endpoints and number of points in x and y directions :type grid_vel: tuple :param U: x-compnent of the velocity. :type U: np.ndarray, shape = (nt,nx,ny) :param V: y-compnent of the velocity. :type V: np.ndarray, shape = (nt,nx,ny) :param spherical: 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. :type spherical: int, optional :param extrap_mode: type of extrapolation mode used for interpolant. The default is 'constant'. :type extrap_mode: str, optional :param r: radius used for spherical conversion, used if spherical > 0. The default is 6371. :type r: float, optional :returns: **funcptr** -- address to C callback. :rtype: int .. py:function:: get_callable_linear_2D(grid_vel, U, V, spherical=0, extrap_mode='constant', r=6371.0, return_type='array') 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. :param grid_vel: grid endpoints and number of points in x and y directions :type grid_vel: tuple :param U: x-compnent of the velocity. :type U: np.ndarray, shape = (nt,nx,ny) :param V: y-compnent of the velocity. :type V: np.ndarray, shape = (nt,nx,ny) :param spherical: 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. :type spherical: int, optional :param return_spline: flag to determine if spline is returned. The default is False. :type return_spline: boolean, optional :param extrap_mode: type of extrapolation mode used for interpolant. The default is 'constant'. :type extrap_mode: str, optional :param r: radius used for spherical conversion, used if spherical > 0. The default is 6371. :type r: float, optional :param return_type: 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. :type return_type: np.ndarray or tuple, optional :returns: **vel_spline** -- jit-callable function for vector field. :rtype: jit-callable .. py:function:: get_callable_scalar_linear(grid_f, f, extrap_mode='constant') Create jit-callable linear interpolant for scalar field f defined over grid_f. Linear interpolant is used. :param grid_f: grid endpoints and number of points in t, x, and y directions. :type grid_f: tuple :param f: array containing values of f. :type f: np.ndarray, shape = (nt,nx,ny) :param extrap_mode: type of extrapolation mode used for interpolant. The default is 'constant'. :type extrap_mode: str, optional :returns: **f_interp** -- jit callable function for linear interpolant of f. :rtype: jit-callable .. py:function:: get_predefined_flow(flow_str, int_direction=1.0, return_default_params=True, return_domain=True, parameter_description=False) Create a C callback for one of the predefined flows. :param flow_str: string representing which flow to retrieve. Currently 'double_gyre', 'bickley_jet', and 'abc' are supported. :type flow_str: str :param int_direction: direction of integration (either -1. or 1.). The default is 1. :type int_direction: float, optional :param return_default_params: flag to determine if default parameters will be returned. The default is True. :type return_default_params: boolean, optional :param return_domain: flag to determine if domain will be returned. The default is True. :type return_domain: boolean, optional :param parameter_description: flag to determine if string containing description of parameters is returned. The default if False. :type parameter_description: boolean, optional :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. .. py:function:: get_predefined_callable(flow_str, params=None, return_domain=True, parameter_description=False, return_type='array') Create a jit-callable for one of the predefined flows. :param flow_str: string representing which flow to retrieve. Currently 'double_gyre', 'bickley_jet', and 'abc' are supported. :type flow_str: str :param params: parameters to be used to define the flow. The default is None, i.e. default params. :type params: np.ndarray, shape = (nprms,), optional :param return_domain: flag to determine if domain will be returned. The default is True. :type return_domain: boolean, optional :param parameter_description: flag to determine if string containing description of parameters is returned. The default if False. :type parameter_description: boolean, optional :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.