pyloggrid.LogGrid.Grid
Class that directly handles the log grid & related maths
Module Contents
Classes
Main class that handles the log grid |
|
Functions to perform maths on log grids |
|
Computes a few classical physical properties |
Functions
|
Setup the imported C function. Important to avoid segfaults. |
- _setup_convolver_c(convolver_c) None
Setup the imported C function. Important to avoid segfaults. We keep the convolver as an argument to allow importing this function elsewhere
- class Grid(D: int, l_params: dict[str, float | bool], N_points: int, fields_name: list[str], k_min: float = None, k0: bool = False, n_threads: int = None)
Main class that handles the log grid
- get_l_from_params() float
Sets the grid spacing from the grid’s parameters.
- Returns:
the grid spacing
See
pyoggrid.LogGrid.Framework.Solverfor more information.- Reference:
Campolina & Mailybaev 2020, Fluid dynamics on logarithmic lattices
- generate_points(k_min: float) tuple[ndarray, ndarray, ndarray, ndarray]
Create the grid’s wavevector arrays
- Parameters:
k_min – the minimum wavevector
- Returns:
(array of wave vectors along X axis
[N,], logmean of array of wave vectors along X axis [N,], array of wave vectors[D, N, (2N, 2N)], array of wave vector modulus[N, (2N, 2N)])
- load_fields(fields: dict[str, ndarray]) Grid
Load fields from a grid of another dimension. If the new grid is smaller, discard outer fields. If bigger, set new fields to 0.
- Parameters:
fields – fields from the previous grid. fields names must correspond for both grids, as well as
k_min.
- class Maths(grid: Grid, n_threads: int = 0)
Functions to perform maths on log grids
- convolve_batch
Convolve a list of convolutions at once. More efficient that calling
convolve()several times. Use asconvolve_batch([(f0,g0), (f1,g1), ...])- Type:
Callable
- cached_conv_kernel
- generate_convolution_kernel() tuple[ndarray, ndarray, ndarray, ndarray, ndarray, ndarray]
Generate the convolution kernel (who interacts with who) for log grid convolutions
- Returns:
(kernel offsets, kernel signs) | signs are used to determine when to take the complex conjugate (+1 = normal, -1 = conjugate)
- _convolve_batch_V_inner(fgs: list[tuple[ndarray, ndarray]], V: int) ndarray
Inner function for <_convolve_batch_V>. Convolves in batch V couples, calling the corresponding
convolve_list_batch_Vfunction in C.
- _convolve_batch_V(fgs: list[tuple[ndarray, ndarray]]) ndarray
from couples
((f0, g0), (f1, g1), ...), computes their convolution- Returns:
the convolved arrays
f0*g0,f1*g1, etc.
- _convolve_batch_list_slower(fgs: list[tuple[ndarray, ndarray]]) ndarray
from couples
((f0, g0), (f1, g1), ...), computes their convolution using batched OMP-supported convolutions- Returns:
the convolved arrays
f0*g0,f1*g1, etc.
- _convolve_batch_list(fgs: list[tuple[ndarray, ndarray]]) Iterable[ndarray]
from couples
((f0, g0), (f1, g1), ...), computes their convolution- Returns:
the convolved arrays
f0*g0,f1*g1, etc.
- static inv(f: numpy._typing.ArrayLike) ndarray
Inverse of a linear operator.
it’s assumed that where the operator is zero, the function to invert will also be zero
- P_projector(A: numpy._typing.ArrayLike) ndarray
Turns
dUdt = A - gradPintodUdt = A'- Parameters:
A –
dUdtwithout the pressure term- Returns:
A'
- class Physics(grid: Grid)
Computes a few classical physical properties
- spectrum(fun: Callable[[dict[str, ndarray], ndarray], ndarray]) ndarray
Spectrum for the quantity calculated by the callback Callback takes two args:
fieldsandks. The first one isgrid.fields. The second one is a grid-shaped bool array corresponding to concernedks. The callback should return a summable np.ndarray[observable(k) for k in ks]. Ex kinetic energy 2D:fun(fields, ks) = ux[k]*conj(ux[k]) + uy[k]*conj(uy[k])- Returns:
np.ndarray of the spectrum along each point of grid.ks_1D
TODO update utest
- cumulative_k(fun: Callable[[dict[str, ndarray], ndarray], ndarray]) ndarray
Compute the cumulative quantity between wave number 0 and k, defined by the sum over |k’| < k of that quantity TODO add utest
- compute_by_shell(fun: Callable[[dict[str, ndarray], ndarray], ndarray], normalize: bool = False) ndarray
Structure function for the quantity calculated by the callback Callback takes two args:
fieldsandks. The first one isgrid.fields. The second one is a grid-shaped bool array corresponding to concernedks. The callback should return a summable np.ndarray[observable(k) for k in ks]. Ex kinetic energy 2D:fun(fields, ks) = ux[k]*conj(ux[k]) + uy[k]*conj(uy[k])- Parameters:
fun – the function to compute
normalize – if True, normalize the result on each shell
- Returns:
np.ndarray of the structure function along each point of grid.ks_1D
TODO: add utest