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#
|
Return spherical r-divergence. |
|
Return Cartesian x-divergence. |
|
Return spherical r-gradient. |
|
Return Cartesian x-gradient. |
|
Return spherical r-integral. |
|
Return Cartesian x-integral. |
|
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 thanfalong 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 thanfalong 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, andfzterms must be evaluated at thex,y, andzboundaries, respectively. For example, a grid with (Nx, Ny, Nz) volume discretizations will have anfxwith 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 thanfalong 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 thanfalong 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
falong the specified axis.
Notes
The result is over all spherical dimensions (r, theta, phi) assuming
fis 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 byrm[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
falong 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 byxm[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
ishould correspond to the variable given inparamswith the same index.
- Returns:
combinations (list[dict]) – List of dictionaries representing all possible combinations of parameter values.