Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fluidsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
This instance will be upgraded to Heptapod 17.11.0rc1 on 2025-04-24 between 17:00 and 18:00 UTC+2
Show more breadcrumbs
fluiddyn
fluidsim
Commits
f972588b
Commit
f972588b
authored
6 years ago
by
calpe
Browse files
Options
Downloads
Patches
Plain Diff
Save array spatio_fft in time.
parent
3e8ba6bb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fluidsim/solvers/ns2d/strat/output/spatio_temporal_spectra.py
+88
-73
88 additions, 73 deletions
...dsim/solvers/ns2d/strat/output/spatio_temporal_spectra.py
with
88 additions
and
73 deletions
fluidsim/solvers/ns2d/strat/output/spatio_temporal_spectra.py
+
88
−
73
View file @
f972588b
...
...
@@ -9,8 +9,6 @@
:members:
:private-members:
#TODO: key_quantity == linear eigenmode a
"""
from
__future__
import
division
,
print_function
...
...
@@ -50,7 +48,7 @@
"
it_start
"
:
10
,
"
nb_times_compute
"
:
100
,
"
coef_decimate
"
:
10
,
"
key_quantity
"
:
"
ux
"
,
"
overlap_arrays
"
:
0.5
,
},
)
...
...
@@ -66,5 +64,4 @@
# Parameters
self
.
nb_times_compute
=
pspatiotemp_spectra
.
nb_times_compute
self
.
coef_decimate
=
pspatiotemp_spectra
.
coef_decimate
self
.
key_quantity
=
pspatiotemp_spectra
.
key_quantity
self
.
it_last_run
=
pspatiotemp_spectra
.
it_start
...
...
@@ -70,4 +67,5 @@
self
.
it_last_run
=
pspatiotemp_spectra
.
it_start
self
.
overlap_arrays
=
pspatiotemp_spectra
.
overlap_arrays
n0
=
len
(
list
(
range
(
0
,
output
.
sim
.
oper
.
shapeX_loc
[
0
],
self
.
coef_decimate
))
...
...
@@ -85,6 +83,8 @@
# 3D array
self
.
spatio_temp
=
np
.
empty
(
[
self
.
nb_times_compute
,
n0
,
n1
//
2
+
1
],
dtype
=
complex
)
self
.
spatio_temp_olap
=
np
.
empty
(
[
self
.
nb_times_compute
,
n0
,
n1
//
2
+
1
],
dtype
=
complex
)
# Array omegas
deltat
=
self
.
sim
.
time_stepping
.
deltat
...
...
@@ -96,6 +96,8 @@
0
,
self
.
delta_omega
*
(
nt
//
2
+
1
),
self
.
delta_omega
)
self
.
nb_times_in_spatio_temp
=
0
self
.
nb_times_in_spatio_temp_olap
=
-
int
(
self
.
overlap_arrays
*
self
.
nb_times_compute
)
def
_init_files
(
self
,
dict_arrays_1time
=
None
):
# we can not do anything when this function is called.
...
...
@@ -115,7 +117,18 @@
self
.
t_last_save
=
self
.
sim
.
time_stepping
.
t
def
_write_array_to_file
(
self
,
array
,
name
=
"
spatio_temp
"
):
"""
Writes array to file self.path_file
"""
array_to_file
=
{
name
:
array
}
if
not
os
.
path
.
exists
(
self
.
path_file
):
self
.
_init_files2
(
array_to_file
)
else
:
self
.
_add_dict_arrays_to_file
(
self
.
path_file
,
array_to_file
)
def
_online_save
(
self
):
"""
Computes and saves the values at one time.
"""
itsim
=
int
(
self
.
sim
.
time_stepping
.
t
/
self
.
sim
.
time_stepping
.
deltat
)
periods_save
=
self
.
sim
.
params
.
output
.
periods_save
.
spatio_temporal_spectra
...
...
@@ -118,7 +131,8 @@
def
_online_save
(
self
):
"""
Computes and saves the values at one time.
"""
itsim
=
int
(
self
.
sim
.
time_stepping
.
t
/
self
.
sim
.
time_stepping
.
deltat
)
periods_save
=
self
.
sim
.
params
.
output
.
periods_save
.
spatio_temporal_spectra
nb_times_compute
=
self
.
nb_times_compute
if
itsim
-
self
.
it_last_run
>=
periods_save
-
1
:
self
.
it_last_run
=
itsim
...
...
@@ -122,5 +136,5 @@
if
itsim
-
self
.
it_last_run
>=
periods_save
-
1
:
self
.
it_last_run
=
itsim
field
=
self
.
sim
.
state
.
state_phys
.
get_var
(
self
.
key_quantity
)
field
=
self
.
sim
.
state
.
compute
(
"
ap_fft
"
)
field_decimate
=
field
[::
self
.
coef_decimate
,
::
self
.
coef_decimate
]
...
...
@@ -126,5 +140,3 @@
field_decimate
=
field
[::
self
.
coef_decimate
,
::
self
.
coef_decimate
]
field_fft
=
self
.
oper_fft2
.
fft2d
(
field_decimate
)
self
.
spatio_temp
[
self
.
nb_times_in_spatio_temp
,
:,
:]
=
field_fft
self
.
nb_times_in_spatio_temp
+=
1
self
.
spatio_temp
[
self
.
nb_times_in_spatio_temp
,
:,
:]
=
field_decimate
...
...
@@ -130,5 +142,9 @@
if
self
.
nb_times_in_spatio_temp
==
self
.
nb_times_compute
:
self
.
nb_times_in_spatio_temp
=
0
self
.
t_last_save
=
self
.
sim
.
time_stepping
.
t
# Check start overlapped array
nb_times_olap
=
self
.
nb_times_in_spatio_temp_olap
condition
=
nb_times_olap
>=
0
and
nb_times_olap
<
nb_times_compute
if
condition
:
field
=
self
.
sim
.
state
.
compute
(
"
ap_fft
"
)
field_decimate
=
field
[::
self
.
coef_decimate
,
::
self
.
coef_decimate
]
self
.
spatio_temp_olap
[
nb_times_olap
,
:,
:]
=
field_decimate
...
...
@@ -134,6 +150,5 @@
for
i
,
value
in
enumerate
(
self
.
hamming
):
self
.
spatio_temp
[
i
,
:,
:]
=
value
*
self
.
spatio_temp
[
i
,
:,
:]
self
.
spatio_fft
=
self
.
oper_fft1
.
fft
(
self
.
spatio_temp
)
# Add index
self
.
nb_times_in_spatio_temp
+=
1
self
.
nb_times_in_spatio_temp_olap
+=
1
...
...
@@ -139,4 +154,6 @@
if
mpi
.
rank
==
0
:
spatio_temp_spectra
=
{
"
spatio_temp_spectra
"
:
self
.
spatio_fft
}
# Check and write overlapped file
if
self
.
nb_times_in_spatio_temp_olap
==
nb_times_compute
:
self
.
nb_times_in_spatio_temp_olap
=
0
self
.
_write_array_to_file
(
self
.
spatio_temp_olap
)
...
...
@@ -142,11 +159,9 @@
if
not
os
.
path
.
exists
(
self
.
path_file
):
self
.
_init_files2
(
spatio_temp_spectra
)
else
:
self
.
_add_dict_arrays_to_file
(
self
.
path_file
,
spatio_temp_spectra
)
# Check and write file
if
self
.
nb_times_in_spatio_temp
==
nb_times_compute
:
self
.
nb_times_in_spatio_temp
=
0
self
.
_write_array_to_file
(
self
.
spatio_temp
)
def
load
(
self
):
"""
Loads spatio temporal fft from file.
"""
with
h5py
.
File
(
self
.
path_file
,
"
r
"
)
as
f
:
...
...
@@ -149,7 +164,7 @@
def
load
(
self
):
"""
Loads spatio temporal fft from file.
"""
with
h5py
.
File
(
self
.
path_file
,
"
r
"
)
as
f
:
spatio_temp
oral_fft
=
f
[
"
spatio_temp
_spectra
"
].
value
return
spatio_temp
oral_fft
spatio_temp
=
f
[
"
spatio_temp
"
].
value
return
spatio_temp
...
...
@@ -155,7 +170,7 @@
def
_compute_energy_from_spatio_temporal_fft
(
self
,
spatio_temporal_fft
):
"""
Compute energy at each fourier mode from spatio temporal fft.
"""
return
(
1
/
2.
)
*
np
.
abs
(
spatio_temporal_fft
)
**
2
#
def _compute_energy_from_spatio_temporal_fft(self, spatio_temporal_fft):
#
"""
#
Compute energy at each fourier mode from spatio temporal fft.
#
"""
#
return (1 / 2.) * np.abs(spatio_temporal_fft) ** 2
...
...
@@ -161,6 +176,6 @@
def
plot_frequency_spectra
(
self
):
"""
Plots the frequency spectra F(\omega).
"""
# Load data from file
spatio_temporal_fft
=
self
.
load
()
#
def plot_frequency_spectra(self):
#
""" Plots the frequency spectra F(\omega). """
#
# Load data from file
#
spatio_temporal_fft = self.load()
...
...
@@ -166,4 +181,4 @@
# Average over all spatio_temporal_fft 3d arrays
spatio_temporal_fft
=
spatio_temporal_fft
.
mean
(
axis
=
0
)
#
# Average over all spatio_temporal_fft 3d arrays
#
spatio_temporal_fft = spatio_temporal_fft.mean(axis=0)
...
...
@@ -169,5 +184,5 @@
# Compute energy from spatio_temporal_fft
energy_fft
=
self
.
_compute_energy_from_spatio_temporal_fft
(
spatio_temporal_fft
)
#
# Compute energy from spatio_temporal_fft
#
energy_fft = self._compute_energy_from_spatio_temporal_fft(
#
spatio_temporal_fft)
...
...
@@ -173,4 +188,4 @@
omegas
=
np
.
arange
(
0
,
self
.
delta_omega
*
(
self
.
nb_times_compute
//
2
+
1
),
self
.
delta_omega
)
#
omegas = np.arange(
#
0, self.delta_omega * (self.nb_times_compute// 2 + 1), self.delta_omega)
...
...
@@ -176,3 +191,3 @@
E_omega
=
(
1
/
self
.
delta_omega
)
*
energy_fft
.
sum
(
1
).
sum
(
1
)
#
E_omega = (1 / self.delta_omega) * energy_fft.sum(1).sum(1)
...
...
@@ -178,8 +193,8 @@
# Plot
fig
,
ax
=
plt
.
subplots
()
ax
.
set_xlabel
(
"
$\omega$
"
)
ax
.
set_ylabel
(
r
"
$F(\omega)$
"
)
ax
.
set_title
(
r
"
$E(\omega)$
"
)
ax
.
loglog
(
omegas
,
E_omega
)
#
# Plot
#
fig, ax = plt.subplots()
#
ax.set_xlabel("$\omega$")
#
ax.set_ylabel(r"$F(\omega)$")
#
ax.set_title(r"$E(\omega)$")
#
ax.loglog(omegas, E_omega)
...
...
@@ -185,3 +200,3 @@
plt
.
show
()
#
plt.show()
...
...
@@ -187,6 +202,6 @@
def
plot_omega_kx
(
self
):
"""
Plots the frequency spectra F(\omega).
"""
# Load data from file
spatio_temporal_fft
=
self
.
load
()
#
def plot_omega_kx(self):
#
""" Plots the frequency spectra F(\omega). """
#
# Load data from file
#
spatio_temporal_fft = self.load()
...
...
@@ -192,4 +207,4 @@
# Average over all spatio_temporal_fft 3d arrays
spatio_temporal_fft
=
spatio_temporal_fft
.
mean
(
axis
=
0
)
#
# Average over all spatio_temporal_fft 3d arrays
#
spatio_temporal_fft = spatio_temporal_fft.mean(axis=0)
...
...
@@ -195,5 +210,5 @@
# Compute energy from spatio_temporal_fft
energy_fft
=
self
.
_compute_energy_from_spatio_temporal_fft
(
spatio_temporal_fft
)
#
# Compute energy from spatio_temporal_fft
#
energy_fft = self._compute_energy_from_spatio_temporal_fft(
#
spatio_temporal_fft)
...
...
@@ -199,5 +214,5 @@
delta_kx
=
2
*
pi
/
self
.
oper
.
Lx
nx_decimate
=
len
(
list
(
range
(
0
,
self
.
sim
.
oper
.
shapeX_loc
[
1
],
self
.
coef_decimate
)))
#
delta_kx = 2 * pi / self.oper.Lx
#
nx_decimate = len(
#
list(range(0, self.sim.oper.shapeX_loc[1], self.coef_decimate)))
...
...
@@ -203,5 +218,5 @@
kxs
=
np
.
arange
(
0
,
delta_kx
*
(
nx_decimate
//
2
+
1
),
delta_kx
)
omegas
=
np
.
arange
(
0
,
self
.
delta_omega
*
(
self
.
nb_times_compute
//
2
+
1
),
self
.
delta_omega
)
#
kxs = np.arange(0, delta_kx * (nx_decimate // 2 + 1), delta_kx)
#
omegas = np.arange(
#
0, self.delta_omega * (self.nb_times_compute// 2 + 1), self.delta_omega)
...
...
@@ -207,3 +222,3 @@
E_omega_kx
=
(
1
/
self
.
delta_omega
)
*
(
1
/
delta_kx
)
*
energy_fft
.
sum
(
1
)
#
E_omega_kx = (1 / self.delta_omega) * (1 / delta_kx) * energy_fft.sum(1)
...
...
@@ -209,4 +224,4 @@
# Plot
kx_grid
,
omega_grid
=
np
.
meshgrid
(
kxs
,
omegas
)
#
# Plot
#
kx_grid, omega_grid = np.meshgrid(kxs, omegas)
...
...
@@ -212,7 +227,7 @@
fig
,
ax
=
plt
.
subplots
()
ax
.
set_xlabel
(
"
$\omega$
"
)
ax
.
set_ylabel
(
"
$k_x$
"
)
ax
.
set_title
(
r
"
$E(\omega, k_x)$
"
)
ax
.
pcolor
(
omega_grid
,
kx_grid
,
E_omega_kx
)
#
fig, ax = plt.subplots()
#
ax.set_xlabel("$\omega$")
#
ax.set_ylabel("$k_x$")
#
ax.set_title(r"$E(\omega, k_x)$")
#
ax.pcolor(omega_grid, kx_grid, E_omega_kx)
...
...
@@ -218,2 +233,2 @@
plt
.
show
()
#
plt.show()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment