viscid.calculator.calc module

This has a mechanism to dispatch to different backends. You can change the order of preference of the backend by changing default_backends. TODO: this dispatch mechanism is very simple, maybe something a little more flexable would be useful down the line?

viscid.calculator.calc.convective_deriv(a, b=None, bnd=True)[source]

Compute (a dot nabla) b for vector fields a and b

viscid.calculator.calc.project_vector(a, b)[source]

Calculates the vector (a dot b_hat) * b_hat

viscid.calculator.calc.project_along_line(line, fld, interp_kind='trilin')[source]

Project a Vector Field Parallel to a streamline

Parameters:
  • line (ndarray) – 3xN of points along the
  • fld (VectorField) – Field to interpolate and project onto the line
  • interp_kind (str) – which interpolation to use, const or trilin
viscid.calculator.calc.resample_lines(lines, factor=1, kind='linear')[source]

Resample a bunch of lines

Parameters:
  • lines (sequence) – a list of 3xN ndarrays that are lines
  • factor (float) – how to resample. 2 will give a point at the midpoint of all points, 3 will give two points, etc. 0.5 will leave half the number of points, etc. This should be > 0.0.
  • kind (str) – How to interpolate; must be a value recognized by scipy.interpolate.interp1d()
Raises:

ValueError – List of resampled 3xN ndarrays

viscid.calculator.calc.integrate_along_line(line, fld, reduction='dot', mask_func=None, interp_kind='trilin')[source]

Integrate the value of fld along a line

Parameters:
  • line (ndarray) – 3xN ndarray
  • fld (Field) – Field to interpolate / integrate
  • reduction (str) – If fld is a vector field, what quantity to integrate. Can be “dot” to dot the vectors with ds along the line, or “mag” to integrate the magnitude.
  • interp_kind (str) – which interpolation to use, const or trilin
Returns:

a scalar with the same dtype as fld

viscid.calculator.calc.integrate_along_lines(lines, fld, reduction='dot', mask_func=None, interp_kind='trilin')[source]

Integrate the value of fld along a list of lines

Parameters:
  • lines (list) – list of 3xN ndarrays, N needs not be the same for all lines
  • fld (Field) – Field to interpolate / integrate
  • reduction (str) – If fld is a vector field, what quantity to integrate. Can be “dot” to dot the vectors with ds along the line, or “mag” to integrate the magnitude.
  • interp_kind (str) – which interpolation to use, const or trilin
Returns:

ndarray with shape (len(lines), )

viscid.calculator.calc.jacobian_at_point(B, x, y, z, dx=None, dy=None, dz=None)[source]

Get the Jacobian at a point

If dx|dy|dz == None, then their set to the grid spacing at the point of interest

Returns:The jacobian as a 3x3 ndarray. The result is in xyz order, in other words:
[ [d_x Bx, d_y Bx, d_z Bx],
  [d_x By, d_y By, d_z By],
  [d_x Bz, d_y Bz, d_z Bz] ]
viscid.calculator.calc.jacobian_at_ind(B, ix, iy, iz)[source]

Get the Jacobian at index

Returns:The jacobian as a 3x3 ndarray. The result is in xyz order, in other words:
[ [d_x Bx, d_y Bx, d_z Bx],
  [d_x By, d_y By, d_z By],
  [d_x Bz, d_y Bz, d_z Bz] ]
viscid.calculator.calc.jacobian_eig_at_point(B, x, y, z, dx=None, dy=None, dz=None)[source]

Get the eigen vals/vecs of the jacobian

Returns: evals, evecs (3x3 ndarray)
The evec[:, i] corresponds to evals[i]. Eigen vectors are returned in xyz order, aka evec[:, 0] is [x, y, z] for the 0th eigen vector
viscid.calculator.calc.jacobian_eig_at_ind(B, ix, iy, iz)[source]

Get the eigen vals/vecs of the jacobian

Returns: evals, evecs (3x3 ndarray)
The evec[:, i] corresponds to evals[i]. Eigen vectors are returned in xyz order, aka evec[:, 0] is [x, y, z] for the 0th eigen vector
viscid.calculator.calc.div_at_point(A, x, y, z, dx=None, dy=None, dz=None)[source]

Returns divergence at a point

viscid.calculator.calc.curl_at_point(A, x, y, z, dx=None, dy=None, dz=None)[source]

Returns curl at point as ndarray with shape (3,) xyz

viscid.calculator.calc.extend_boundaries(fld, nl=1, nh=1, axes='all', nr_comp=None, order=1, crd_order=1, crds=None, invarient_dx=0.0, crd_invarient_dx=1.0)[source]

Extend and pad boundaries of field (leaves new corners @ 0.0)

Parameters:
  • fld (Field) – Field to extend
  • nl (int) – extend this many cells in lower direction
  • nh (int) – extend this many cells in upper direction
  • axes (str, list) – something like ‘xyz’, [‘x’, ‘theta’], etc.
  • nr_comp (int, None) – index of shape that corresponds to vector component dimension
  • order (int) – extrapolation order for data; 0 for repeating boundary values or 1 for linear extrapolation
  • crd_order (int) – extrapolation order for crds; 0 for repeating boundary values or 1 for linear extrapolation
  • crds (Coordinates) – Use these coordinates, no extrapolate them
  • invarient_dx (float) – if fld has a single cell in a given dimension, and order == 1, the field is extended with constant dx, using 0 here is synonymous with 0th order
  • invarient_dx – if fld has a single cell in a given dimension, and crd_order == 1, the coordinates in that dimension are extended with constant dx, using 0 here is synonymous with crd_order = 0.
Returns:

A new extended / padded ndarray

Return type:

ndarray

Warning

When using crd_order=0 (0 order hold), coordinates will be extended by repeating boundary values, so min_dx will be 0. Keep this in mind if dividing by dx.

viscid.calculator.calc.extend_boundaries_ndarr(arr, nl=1, nh=1, axes='all', nr_comp=None, order=1, invarient_dx=0.0)[source]

Extend and pad boundaries of ndarray (leaves new corners @ 0.0)

Parameters:
  • arr (ndarray) – Array to extend
  • nl (int) – extend this many cells in lower direction
  • nh (int) – extend this many cells in upper direction
  • axes (list) – list of ints that correspond to axes that should be extended. If nr_comp != None, then axes > nr_comp will be shifted by 1.
  • nr_comp (int, None) – index of shape that corresponds to vector component dimension
  • order (int) – 0 for repeating boundary values or 1 for linear extrapolation
  • invarient_dx (float) – if len(arr) == 1 and order == 1, then the array is extended with constant dx, using 0 here is synonymous with 0th order.
Returns:

A new extended / padded ndarray

Return type:

ndarray