bmlite.mathutils#

The math module defines common mathematical operators, e.g., the gradient and divergence operators. Functions in this module are built to operate using arrays. Generally speaking, using vectorized math provides significant speed boosts in computational modeling by removing slower for loops and if statements.

Functions#

div_r(rm, rp, f[, axis])

Return spherical r-divergence.

div_x(xm, xp, f[, axis])

Return Cartesian x-divergence.

grad_r(r, f[, axis])

Return spherical r-gradient.

grad_x(x, f[, axis])

Return Cartesian x-gradient.

int_r(rm, rp, f[, axis])

Return spherical r-integral.

int_x(xm, xp, f[, axis])

Return Cartesian x-integral.

param_combinations(params, values)

Generate all possible combinations for a set of parameters given their

Module Contents#

bmlite.mathutils.div_r(rm, rp, f, axis=-1)[source]#

Return spherical r-divergence.

Parameters:
  • rm (1D np.array) – Independent variable values at “minus” boundaries.

  • rp (1D np.array) – Independent variable values at “plus” boundaries.

  • f (np.array) – Dependent variable evaluated at r boundaries.

  • axis (int, optional) – f dimension corresponding to r. The default is -1.

Returns:

df_dr (np.array) – The divergence 1/r**2 * d(r**2 * f)/dr. The shape is one fewer than f along the specified axis.

bmlite.mathutils.div_x(xm, xp, f, axis=-1)[source]#

Return Cartesian x-divergence.

Parameters:
  • xm (1D np.array) – Independent variable values at “minus” boundaries.

  • xp (1D np.array) – Independent variable values at “plus” boundaries.

  • f (np.array) – Dependent variable evaluated at x boundaries.

  • axis (int, optional) – f dimension corresponding to x. The default is -1.

Returns:

df_dx (np.array) – The divergence df/dx. The shape is one fewer than f along the specified axis.

Notes

This function is valid for any Cartesian direction, not just x. To get the 2D or 3D divergence, you have to evaluate and add the separate terms. For example,

div_f = div_x(xm, xp, fx, 0) + div_x(ym, yp, fy, 1)
      + div_x(zm, zp, fz, 2)

The fx, fy, and fz terms must be evaluated at the x, y, and z boundaries, respectively. For example, a grid with (Nx, Ny, Nz) volume discretizations will have an fx with shape (Nx + 1, Ny, Nz) because the number of boundaries is always one greater than the number of volumes.

bmlite.mathutils.grad_r(r, f, axis=-1)[source]#

Return spherical r-gradient.

Parameters:
  • r (1D np.array) – Independent variable values.

  • f (np.array) – Dependent variable values.

  • axis (int, optional) – f dimension corresponding to r. The default is -1.

Returns:

df_dr (np.array) – The gradient df/dr. The shape is one fewer than f along the specified axis.

bmlite.mathutils.grad_x(x, f, axis=-1)[source]#

Return Cartesian x-gradient.

Parameters:
  • x (1D np.array) – Independent variable values.

  • f (np.array) – Dependent variable values.

  • axis (int, optional) – f dimension corresponding to x. The default is -1.

Returns:

df_dx (np.array) – The gradient df/dx. The shape is one fewer than f along the specified axis.

Notes

This function is valid for any Cartesian direction, not just x.

bmlite.mathutils.int_r(rm, rp, f, axis=-1)[source]#

Return spherical r-integral.

Parameters:
  • rm (1D np.array) – Independent variable values at “minus” boundaries.

  • rp (1D nb.array) – Independent variable values at “plus” boundaries.

  • f (np.array) – Dependent variable evaluated at r centers.

  • axis (int, optional) – f dimension corresponding to r. The default is -1.

Returns:

int_r (np.array) – The result of integration. The dimension of the result is one fewer than f along the specified axis.

Notes

The result is over all spherical dimensions (r, theta, phi) assuming f is independent of theta and phi.

The integral is written for numerical results from finite volume solutions. Integration is performed over meshed control volumes, where f[i] is assumed uniform within a volume defined by rm[i] < r < rp[i].

bmlite.mathutils.int_x(xm, xp, f, axis=-1)[source]#

Return Cartesian x-integral.

Parameters:
  • xm (1D np.array) – Independent variable values at “minus” boundaries.

  • xp (1D np.array) – Independent variable values at “plus” boundaries.

  • f (np.array) – Dependent variable evaluated at x centers.

  • axis (int, optional) – f dimension corresponding to x. The default is -1.

Returns:

int_x (np.array) – The result of integration. The dimension of the result is one fewer than f along the specified axis.

Notes

The integral is written for numerical results from finite volume solutions. Integration is performed over meshed control volumes, where f[i] is assumed uniform within a volume defined by xm[i] < x < xp[i].

bmlite.mathutils.param_combinations(params, values)[source]#

Generate all possible combinations for a set of parameters given their possible values.

Parameters:
  • params (list[str]) – List of parameter names, including the domain, e.g. an.i0_deg.

  • values (list[1D array]) – List of possible values for each parameter. The array in each index i should correspond to the variable given in params with the same index.

Returns:

combinations (list[dict]) – List of dictionaries representing all possible combinations of parameter values.