Skip to content

Commit 56b99e8

Browse files
wip adding bessel methods
1 parent c23578b commit 56b99e8

File tree

3 files changed

+99
-9
lines changed

3 files changed

+99
-9
lines changed

src/fluidsf/__init__.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
from .bin_data import bin_data
77
from .calculate_advection_2d import calculate_advection_2d
88
from .calculate_advection_3d import calculate_advection_3d
9+
from .calculate_cascades_from_bessel_2d import calculate_cascades_from_bessel_2d
910
from .calculate_separation_distances import calculate_separation_distances
1011
from .calculate_separation_distances_3d import calculate_separation_distances_3d
1112
from .calculate_sf_maps_2d import calculate_sf_maps_2d
1213
from .calculate_structure_function_1d import calculate_structure_function_1d
1314
from .calculate_structure_function_2d import calculate_structure_function_2d
1415
from .calculate_structure_function_3d import calculate_structure_function_3d
16+
from .calculate_wavenumbers_2d import calculate_wavenumbers_2d
1517
from .generate_sf_maps_2d import generate_sf_maps_2d
1618
from .generate_structure_functions_1d import generate_structure_functions_1d
1719
from .generate_structure_functions_2d import generate_structure_functions_2d
@@ -24,21 +26,23 @@
2426
__version__ = "0.2.0"
2527

2628
__all__ = (
27-
"generate_sf_maps_2d",
28-
"generate_structure_functions_1d",
29-
"generate_structure_functions_2d",
30-
"generate_structure_functions_3d",
31-
"calculate_sf_maps_2d",
32-
"calculate_structure_function_1d",
33-
"calculate_structure_function_2d",
34-
"calculate_structure_function_3d",
29+
"bin_data",
3530
"calculate_advection_2d",
3631
"calculate_advection_3d",
32+
"calculate_cascades_from_bessel_2d",
3733
"calculate_separation_distances",
3834
"calculate_separation_distances_3d",
35+
"calculate_sf_maps_2d",
36+
"calculate_structure_function_1d",
37+
"calculate_structure_function_2d",
38+
"calculate_structure_function_3d",
39+
"calculate_wavenumbers_2d",
40+
"generate_sf_maps_2d",
41+
"generate_structure_functions_1d",
42+
"generate_structure_functions_2d",
43+
"generate_structure_functions_3d",
3944
"shift_array_1d",
4045
"shift_array_2d",
4146
"shift_array_3d",
4247
"shift_array_xy",
43-
"bin_data",
4448
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from scipy.integrate import cumulative_trapezoid
2+
from scipy.special import jv
3+
import pandas as pd
4+
5+
6+
def calculate_cascades_from_bessel_2d(
7+
kr, df, xdiffs, ydiffs, dx, dy, sf_keys=["SF_advection_velocity_x"]
8+
):
9+
"""
10+
Calculate the cascades from the structure functions using Bessel functions.
11+
12+
Parameters
13+
----------
14+
kr: numpy.ndarray
15+
The kr wavevector.
16+
df: pandas.DataFrame
17+
The structure functions in a DataFrame.
18+
xdiffs: numpy.ndarray
19+
The x separation distances.
20+
ydiffs: numpy.ndarray
21+
The y separation distances.
22+
dx: float
23+
The x grid spacing.
24+
dy: float
25+
The y grid spacing.
26+
sf_keys: list
27+
The keys of the structure functions to use. Defaults to
28+
["SF_advection_velocity_x"].
29+
30+
Returns
31+
-------
32+
numpy.ndarray:
33+
The cascades.
34+
"""
35+
bessels1 = [jv(1, kr[i] * xdiffs) for i in range(kr.shape[0])]
36+
bessels2 = [jv(2, kr[i] * xdiffs) for i in range(kr.shape[0])]
37+
bessels3 = [jv(3, kr[i] * xdiffs) for i in range(kr.shape[0])]
38+
39+
for key in sf_keys:
40+
df[key] = df[key].fillna(0)
41+
42+
bessel_energy_integral_asf_v = [
43+
-0.5 * kr[kk] * cumulative_trapezoid(df[key] * bessels1[kk], dx=dx[kk])
44+
for kk in range(1, len(kr) + 1)
45+
]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import numpy as np
2+
3+
4+
def calculate_wavevector_2d(xdiffs, ydiffs):
5+
"""
6+
Calculate the kr wavevector from the separation distances.
7+
Assumes a uniform grid with no periodic boundary conditions.
8+
9+
Parameters
10+
----------
11+
xdiffs: numpy.ndarray
12+
The x separation distances.
13+
ydiffs: numpy.ndarray
14+
The y separation distances.
15+
16+
Returns
17+
-------
18+
numpy.ndarray:
19+
The kr wavevector.
20+
"""
21+
nx = len(xdiffs)
22+
ny = len(ydiffs)
23+
dx = abs(xdiffs[1] - xdiffs[0])
24+
dy = abs(ydiffs[1] - ydiffs[0])
25+
26+
kx_int = 1 / dx
27+
ky_int = 1 / dy
28+
29+
kx = 2 * np.py * np.arange(-nx / 2, nx / 2) * (kx_int / nx)
30+
ky = 2 * np.py * np.arange(-ny / 2, ny / 2) * (ky_int / ny)
31+
32+
kx_max_mat = max(max(-kx[: nx // 2 + 1]), max(ky))
33+
34+
dkx = 2 * np.pi / max(xdiffs)
35+
dky = 2 * np.pi / max(ydiffs)
36+
37+
dkr_mat = np.sqrt(dkx**2 + dky**2)
38+
39+
kr = np.arange(dkr_mat / 2, kx_max_mat + dkr_mat, dkr_mat)
40+
41+
return kr

0 commit comments

Comments
 (0)