Sorting#
- struphy.pic.sorting_kernels.flatten_index(n1: int, n2: int, n3: int, nx: int, ny: int, nz: int, algo_in: str | None = None)[source]#
Find the global index of a box based on its index in all 3 direction. At the moment this is simply sorted according to x then y then z but in the future more evolved indexing could be implemented.
- struphy.pic.sorting_kernels.unflatten_index(n_glob: int, nx: int, ny: int, nz: int, algo_in: str | None = None)[source]#
Find the multi-index (i, j, k) of a box based on its global flattened index. At the moment this is simply sorted according to x then y then z but in the future more evolved indexing could be implemented.
- struphy.pic.sorting_kernels.initialize_neighbours(neighbour: int[:, :], nx: int, ny: int, nz: int)[source]#
Initialize the list of neighbours of boxes (find the index of the neighbours and put the in the right line of the neighbouring array).
- struphy.pic.sorting_kernels.find_box(eta1: float, eta2: float, eta3: float, nx: int, ny: int, nz: int, domain_array: float[:])[source]#
Return the number of the box in which the point (eta1, eta2, eta3) is located, or -1 if the point is not on the process.
- Parameters:
eta1 (array) – Logical evaluation points.
eta2 (array) – Logical evaluation points.
eta3 (array) – Logical evaluation points.
nx (int) – Number of boxes in each dimension, per mpi process.
ny (int) – Number of boxes in each dimension, per mpi process.
nz (int) – Number of boxes in each dimension, per mpi process.
domain_array (array) – Information of the domain on the current mpi process.
- struphy.pic.sorting_kernels.get_next_index(box_nb: float, next_index: int[:], cumul_next_index: int[:])[source]#
Utilities for sorting
- struphy.pic.sorting_kernels.sort_boxed_particles(markers: float[:, :], swap_line_1: float[:], swap_line_2: float[:], n_boxes: int, next_index: int[:], cumul_next_index: int[:], box_index: int = -2)[source]#
Sort the particules taking advantage of the boxes
SPH evaluation#
- struphy.pic.sph_eval_kernels.distance(x: float, y: float, periodic: bool) float[source]#
Return the one dimensional distance of x and y taking in account the periodicity on [0,1].
- struphy.pic.sph_eval_kernels.naive_evaluation_kernel(args_markers: MarkerArguments, eta1: float, eta2: float, eta3: float, holes: bool[:], periodic1: bool, periodic2: bool, periodic3: bool, index: int, kernel_type: int, h1: float, h2: float, h3: float) float[source]#
Naive single-point sph evaluation. The sum is done over all particles in markers array.
- Parameters:
eta1 (float) – Evaluation point in logical space.
eta2 (float) – Evaluation point in logical space.
eta3 (float) – Evaluation point in logical space.
markers (array[float]) – Markers array.
Np (int) – Total number of particles.
holes (bool) – 1D array of length markers.shape[0]. True if markers[i] is a hole.
periodic1 (bool) – True if periodic in that dimension.
periodic2 (bool) – True if periodic in that dimension.
periodic3 (bool) – True if periodic in that dimension.
index (int) – Column index in markers array where the value multiplying the kernel in the evaluation is stored.
kernel_type (str) – Name of the smoothing kernel.
h1 (float) – Kernel width in respective dimension.
h2 (float) – Kernel width in respective dimension.
h3 (float) – Kernel width in respective dimension.
- struphy.pic.sph_eval_kernels.boxed_based_kernel(args_markers: MarkerArguments, eta1: float, eta2: float, eta3: float, loc_box: int, boxes: int[:, :], neighbours: int[:, :], holes: bool[:], periodic1: bool, periodic2: bool, periodic3: bool, index: int, kernel_type: int, h1: float, h2: float, h3: float) float[source]#
Box-based single-point sph evaluation. The sum is done over the particles that are in the 26 + 1 neighboring boxes of the
loc_boxthe evaluation point is in.- Parameters:
eta1 (float) – Evaluation point in logical space.
eta2 (float) – Evaluation point in logical space.
eta3 (float) – Evaluation point in logical space.
loc_box (int) – Box of the evaluation point.
boxes (2d array) – Box array of the sorting boxes structure.
neighbours (2d array) – Array containing the 27 neighbouring boxes of each box.
markers (array[float]) – Markers array.
Np (int) – Total number of particles.
holes (bool) – 1D array of length markers.shape[0]. True if markers[i] is a hole.
periodic1 (bool) – True if periodic in that dimension.
periodic2 (bool) – True if periodic in that dimension.
periodic3 (bool) – True if periodic in that dimension.
index (int) – Column index in markers array where the value multiplying the kernel in the evaluation is stored.
kernel_type (int) – Number of the smoothing kernel.
h1 (float) – Kernel width in respective dimension.
h2 (float) – Kernel width in respective dimension.
h3 (float) – Kernel width in respective dimension.
- struphy.pic.sph_eval_kernels.naive_evaluation_flat(args_markers: MarkerArguments, eta1: float[:], eta2: float[:], eta3: float[:], holes: bool[:], periodic1: bool, periodic2: bool, periodic3: bool, index: int, kernel_type: int, h1: float, h2: float, h3: float, out: float[:])[source]#
Naive flat sph evaluation. The sum is done over all particles in markers array.
- Parameters:
eta1 (array[float]) – Evaluation points in logical space for flat evaluation at (eta1[i], eta2[i], eta3[i]).
eta2 (array[float]) – Evaluation points in logical space for flat evaluation at (eta1[i], eta2[i], eta3[i]).
eta3 (array[float]) – Evaluation points in logical space for flat evaluation at (eta1[i], eta2[i], eta3[i]).
markers (array[float]) – Markers array.
Np (int) – Total number of particles.
holes (bool) – 1D array of length markers.shape[0]. True if markers[i] is a hole.
periodic1 (bool) – True if periodic in that dimension.
periodic2 (bool) – True if periodic in that dimension.
periodic3 (bool) – True if periodic in that dimension.
index (int) – Column index in markers array where the value multiplying the kernel in the evaluation is stored.
kernel_type (int) – Number of the smoothing kernel.
h1 (float) – Kernel width in respective dimension.
h2 (float) – Kernel width in respective dimension.
h3 (float) – Kernel width in respective dimension.
out (array[float]) – Output array of same size as eta1, eta2, eta3.
- struphy.pic.sph_eval_kernels.naive_evaluation_meshgrid(args_markers: MarkerArguments, eta1: float[:, :, :], eta2: float[:, :, :], eta3: float[:, :, :], holes: bool[:], periodic1: bool, periodic2: bool, periodic3: bool, index: int, kernel_type: int, h1: float, h2: float, h3: float, out: float[:, :, :])[source]#
Naive meshgrid sph evaluation. The sum is done over all particles in markers array.
- Parameters:
eta1 (array[float]) – Evaluation points in logical space for meshgrid evaluation at (eta1[i,j,k], eta2[i,j,k], eta3[i,j,k]).
eta2 (array[float]) – Evaluation points in logical space for meshgrid evaluation at (eta1[i,j,k], eta2[i,j,k], eta3[i,j,k]).
eta3 (array[float]) – Evaluation points in logical space for meshgrid evaluation at (eta1[i,j,k], eta2[i,j,k], eta3[i,j,k]).
markers (array[float]) – Markers array.
Np (int) – Total number of particles.
holes (bool) – 1D array of length markers.shape[0]. True if markers[i] is a hole.
periodic1 (bool) – True if periodic in that dimension.
periodic2 (bool) – True if periodic in that dimension.
periodic3 (bool) – True if periodic in that dimension.
index (int) – Column index in markers array where the value multiplying the kernel in the evaluation is stored.
kernel_type (int) – Number of the smoothing kernel.
h1 (float) – Kernel width in respective dimension.
h2 (float) – Kernel width in respective dimension.
h3 (float) – Kernel width in respective dimension.
out (array[float]) – Output array of same size as eta1, eta2, eta3.
- struphy.pic.sph_eval_kernels.box_based_evaluation_flat(args_markers: MarkerArguments, eta1: float[:], eta2: float[:], eta3: float[:], n1: int, n2: int, n3: int, domain_array: float[:], boxes: int[:, :], neighbours: int[:, :], holes: bool[:], periodic1: bool, periodic2: bool, periodic3: bool, index: int, kernel_type: int, h1: float, h2: float, h3: float, out: float[:])[source]#
Box-based flat sph evaluation. The sum is done over the particles that are in the 26 + 1 neighboring boxes of the
loc_boxthe evaluation point is in.- Parameters:
eta1 (array[float]) – Evaluation points in logical space for flat evaluation at (eta1[i], eta2[i], eta3[i]).
eta2 (array[float]) – Evaluation points in logical space for flat evaluation at (eta1[i], eta2[i], eta3[i]).
eta3 (array[float]) – Evaluation points in logical space for flat evaluation at (eta1[i], eta2[i], eta3[i]).
n1 (int) – Number of boxes in each dimension.
n2 (int) – Number of boxes in each dimension.
n3 (int) – Number of boxes in each dimension.
domain_array (array) – Information of the domain on the current mpi process.
boxes (2d array) – Box array of the sorting boxes structure.
neighbours (2d array) – Array containing the 27 neighbouring boxes of each box.
markers (array[float]) – Markers array.
Np (int) – Total number of particles.
holes (bool) – 1D array of length markers.shape[0]. True if markers[i] is a hole.
periodic1 (bool) – True if periodic in that dimension.
periodic2 (bool) – True if periodic in that dimension.
periodic3 (bool) – True if periodic in that dimension.
index (int) – Column index in markers array where the value multiplying the kernel in the evaluation is stored.
kernel_type (int) – Number of the smoothing kernel.
h1 (float) – Kernel width in respective dimension.
h2 (float) – Kernel width in respective dimension.
h3 (float) – Kernel width in respective dimension.
out (array[float]) – Output array of same size as eta1, eta2, eta3.
- struphy.pic.sph_eval_kernels.box_based_evaluation_meshgrid(args_markers: MarkerArguments, eta1: float[:, :, :], eta2: float[:, :, :], eta3: float[:, :, :], n1: int, n2: int, n3: int, domain_array: float[:], boxes: int[:, :], neighbours: int[:, :], holes: bool[:], periodic1: bool, periodic2: bool, periodic3: bool, index: int, kernel_type: int, h1: float, h2: float, h3: float, out: float[:, :, :])[source]#
Box-based meshgrid sph evaluation. The sum is done over the particles that are in the 26 + 1 neighboring boxes of the
loc_boxthe evaluation point is in.- Parameters:
eta1 (array[float]) – Evaluation points in logical space for meshgrid evaluation at (eta1[i,j,k], eta2[i,j,k], eta3[i,j,k]).
eta2 (array[float]) – Evaluation points in logical space for meshgrid evaluation at (eta1[i,j,k], eta2[i,j,k], eta3[i,j,k]).
eta3 (array[float]) – Evaluation points in logical space for meshgrid evaluation at (eta1[i,j,k], eta2[i,j,k], eta3[i,j,k]).
n1 (int) – Number of boxes in each dimension.
n2 (int) – Number of boxes in each dimension.
n3 (int) – Number of boxes in each dimension.
domain_array (array) – Information of the domain on the current mpi process.
boxes (2d array) – Box array of the sorting boxes structure.
neighbours (2d array) – Array containing the 27 neighbouring boxes of each box.
markers (array[float]) – Markers array.
Np (int) – Total number of particles.
holes (bool) – 1D array of length markers.shape[0]. True if markers[i] is a hole.
periodic1 (bool) – True if periodic in that dimension.
periodic2 (bool) – True if periodic in that dimension.
periodic3 (bool) – True if periodic in that dimension.
index (int) – Column index in markers array where the value multiplying the kernel in the evaluation is stored.
kernel_type (int) – Number of the smoothing kernel.
h1 (float) – Kernel width in respective dimension.
h2 (float) – Kernel width in respective dimension.
h3 (float) – Kernel width in respective dimension.
out (array[float]) – Output array of same size as eta1, eta2, eta3.
Smoothing kernels#
- struphy.pic.sph_smoothing_kernels.trigonometric_uni(x: float, h: float) float[source]#
Uni-variate kernel S(x, h) = pi/4/h * cos(x*pi/2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_trigonometric_uni(x: float, h: float) float[source]#
Derivative of S(x, h) = pi/4/h * cos(x*pi/2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.gaussian_uni(x: float, h: float) float[source]#
Uni-variate S(x, h) = 1/(sqrt(pi)*h/3) * exp(-(x**2/(h/3)**2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_gaussian_uni(x: float, h: float) float[source]#
Derivative of S(x, h) = 1/(sqrt(pi)*h/3) * exp(-(x**2/(h/3)**2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.linear_uni(x: float, h: float) float[source]#
Uni-variate S(x, h) = (1 - x)/h if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_linear_uni(x: float, h: float) float[source]#
Derivative of S(x, h) = (1 - x)/h if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.trigonometric_1d(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
1d kernel S(x, h) = pi/4/h * cos(x*pi/2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_trigonometric_1d(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
Derivative of S(x, h) = pi/4/h * cos(x*pi/2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.gaussian_1d(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
1d kernel S(x, h) = 1/(sqrt(pi)*h/3) * exp(-(x**2/(h/3)**2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_gaussian_1d(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
Derivative of S(x, h) = 1/(sqrt(pi)*h/3) * exp(-(x**2/(h/3)**2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.linear_1d(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
1d kernel S(x, h) = (1 - x)/h if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_linear_1d(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
Derivative of S(x, h) = (1 - x)/h if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.trigonometric_2d(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
Tensor product of kernels S(x, h) = pi/4/h * cos(x*pi/2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_trigonometric_2d_1(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
1st component of gradient of Tensor product of kernels S(x, h) = pi/4/h * cos(x*pi/2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_trigonometric_2d_2(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
2nd component of gradient of Tensor product of kernels S(x, h) = pi/4/h * cos(x*pi/2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.gaussian_2d(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
Tensor product of kernels S(x, h) = 1/(sqrt(pi)*h/3) * exp(-(x**2/(h/3)**2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_gaussian_2d_1(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
1st component of gradient of Tensor product of kernels S(x, h) = 1/(sqrt(pi)*h/3) * exp(-(x**2/(h/3)**2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_gaussian_2d_2(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
2nd component of gradient of Tensor product of kernels S(x, h) = 1/(sqrt(pi)*h/3) * exp(-(x**2/(h/3)**2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.linear_2d(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
Tensor product of kernels S(x, h) = pi/4/h * cos(x*pi/2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_linear_2d_1(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
1st component of gradient of Tensor product of kernels S(x, h) = pi/4/h * cos(x*pi/2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_linear_2d_2(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
2nd component of gradient of Tensor product of kernels S(x, h) = pi/4/h * cos(x*pi/2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.trigonometric_3d(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
Tensor product of kernels S(x, h) = pi/4/h * cos(x*pi/2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_trigonometric_3d_1(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
1st component of gradient of Tensor product of kernels S(x, h) = pi/4/h * cos(x*pi/2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_trigonometric_3d_2(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
2nd component of gradient of Tensor product of kernels S(x, h) = pi/4/h * cos(x*pi/2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_trigonometric_3d_3(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
3rd component of gradient of Tensor product of kernels S(x, h) = pi/4/h * cos(x*pi/2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.gaussian_3d(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
Tensor product of kernels S(x, h) = 1/(sqrt(pi)*h/3) * exp(-(x**2/(h/3)**2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_gaussian_3d_1(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
1st component of gradient of Tensor product of kernels S(x, h) = 1/(sqrt(pi)*h/3) * exp(-(x**2/(h/3)**2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_gaussian_3d_2(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
2nd component of gradient of Tensor product of kernels S(x, h) = 1/(sqrt(pi)*h/3) * exp(-(x**2/(h/3)**2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_gaussian_3d_3(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
3rd component of gradient of Tensor product of kernels S(x, h) = 1/(sqrt(pi)*h/3) * exp(-(x**2/(h/3)**2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.linear_isotropic_3d(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
Smoothing kernel S(r,h) = C(h)F(r/h) with F(x) = 1-x if x<1, 0 else, and C(h)=3/(pi*h^3) is a normalization coefficient so the the kernel has unit integral.
- struphy.pic.sph_smoothing_kernels.grad_linear_isotropic_3d_1(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
1st component of gradient of S(r,h) = C(h)F(r/h) with F(x) = 1-x if x<1, 0 else, and C(h)=3/(pi*h^3) is a normalization coefficient so the the kernel has unit integral.
- struphy.pic.sph_smoothing_kernels.grad_linear_isotropic_3d_2(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
1st component of gradient of S(r,h) = C(h)F(r/h) with F(x) = 1-x if x<1, 0 else, and C(h)=3/(pi*h^3) is a normalization coefficient so the the kernel has unit integral.
- struphy.pic.sph_smoothing_kernels.grad_linear_isotropic_3d_3(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
1st component of gradient of S(r,h) = C(h)F(r/h) with F(x) = 1-x if x<1, 0 else, and C(h)=3/(pi*h^3) is a normalization coefficient so the the kernel has unit integral.
- struphy.pic.sph_smoothing_kernels.linear_3d(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
Tensor product of kernels S(x, h) = pi/4/h * cos(x*pi/2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_linear_3d_1(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
1st component of gradient of Tensor product of kernels S(x, h) = pi/4/h * cos(x*pi/2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_linear_3d_2(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
2nd component of gradient of Tensor product of kernels S(x, h) = pi/4/h * cos(x*pi/2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.grad_linear_3d_3(r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
3rd component of gradient of Tensor product of kernels S(x, h) = pi/4/h * cos(x*pi/2) if |x|<1, 0 else.
- struphy.pic.sph_smoothing_kernels.smoothing_kernel(kernel_type: int, r1: float, r2: float, r3: float, h1: float, h2: float, h3: float) float[source]#
Each smoothing kernel is normalized to 1.
The kernel type numbers must have 3 digits, where the last digit is reserved for the gradient; if a kernel has the type number n, the i-th components of its gradient has the number n + i. This means we have space for 99 kernels (and its gradient components) in principle.
1d kernels <= 330
2d kernels <= 660
3d kernels >= 670
If you add a kernel, make sure it is also added to
ker_dct().