Skip to content

Commit 483673b

Browse files
author
agoua
committed
Modif Kolmolaw aniso
1 parent badcd5d commit 483673b

File tree

6 files changed

+52
-48
lines changed

6 files changed

+52
-48
lines changed

doc/examples/simul_ns3d_forced_isotropic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
params = Simul.create_default_params()
3636

37-
params.output.sub_directory = "examples"
37+
params.output.sub_directory = "examples/test_iso3d"
3838

3939
ny = nz = nx
4040
Lx = 3
@@ -77,8 +77,8 @@
7777
params.output.periods_save.spatial_means = 0.1
7878
params.output.periods_save.spectra = 0.1
7979
params.output.periods_save.spect_energy_budg = 0.1
80+
params.output.periods_save.kolmo_law = 0.1
8081

8182
params.output.spectra.kzkh_periodicity = 1
82-
8383
sim = Simul(params)
8484
sim.time_stepping.start()

fluidsim/base/output/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,6 @@ def _create_file_from_dict_arrays(
617617
if os.path.exists(path_file):
618618
print("file NOT created since it already exists!")
619619
elif mpi.rank == 0:
620-
621620
with h5py.File(path_file, "w") as file:
622621
file.attrs["date saving"] = str(datetime.datetime.now()).encode()
623622
file.attrs["name_solver"] = self.output.name_solver

fluidsim/base/output/kolmo_law3d.py

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class KolmoLaw(SpecificOutput):
6666
6767
This output saves the components in the spherical basis of the vectors
6868
:math:`\J_\alpha` averaged over the azimutal angle (i.e. as a function of
69-
:math:`r_h` and :math:`r_z`).
69+
:math:`r_h` and :math:`r_v`).
7070
7171
We can take the example of the quantity :math:`\langle | \delta b |^2
7272
\delta \v \rangle_\x` to explain how these quantities are computed. Using
@@ -147,7 +147,7 @@ def __init__(self, output):
147147
"drz": rz_store,
148148
"dr": r_store,
149149
}
150-
self.pow_store = 5/4
150+
self.pow_store = 5 / 4
151151
pow_store = self.pow_store
152152
for i in range(n_store):
153153
index = ((i + 1) / n_store) ** (pow_store)
@@ -418,7 +418,7 @@ def plot_kolmo_law(
418418
ax2.set_xscale("log")
419419
if slope is not None:
420420
ax2.plot(posxprime, check_slope, label=f"$r^{2}$")
421-
# ax2.plot(posx, E_k / (rad ** (coef_comp2)), label="4*E")
421+
422422
ax2.plot(posx, pos2ycomp)
423423
ax2.set_title(f"tmin={tmin:.2g}, tmax={tmax:.2g}")
424424

@@ -496,15 +496,15 @@ def compute(self):
496496
J_A_xyz = [None] * 3
497497

498498
E_k_mean = 0.0
499-
K_k = np.ones_like(K)
499+
K_k = np.ones_like(K)
500500
E_k_proc = np.mean(K)
501501
collect_E_k = mpi.comm.gather(E_k_proc, root=0)
502502
if mpi.rank == 0:
503503
E_k_mean = np.mean(collect_E_k)
504504
else:
505-
E_k_mean = None
505+
E_k_mean = None
506506

507-
E_k_mean = mpi.comm.bcast(E_k_mean, root = 0)
507+
E_k_mean = mpi.comm.bcast(E_k_mean, root=0)
508508

509509
E_k = E_k_mean * K_k
510510
val = None
@@ -525,16 +525,18 @@ def compute(self):
525525
for ind_j in range(3):
526526
tmp += 4 * tf_vi[ind_j] * tf_vjvi[ind_i, ind_j].conj()
527527

528-
tmp = 1j * tmp.imag
528+
tmp = 1j * tmp.imag
529+
mom = 1j * tmp.imag
529530

530531
J_K_xyz[ind_i] = self.sim.oper.ifft(tmp)
532+
531533
if "b" in keys_state_phys:
532534
J_A_xyz[ind_i] = self.sim.oper.ifft(mom)
533535

534536
S2_K_xyz = 2 * E_k - 2 * self.sim.oper.ifft(val)
535537

536-
# S2_K_xyz = 2 * K - S2_K_xyz
537-
538+
nh_store = n_store
539+
nv_store = n_store
538540

539541
J_k_v = np.zeros([nh_store, nv_store])
540542
J_k_h = np.zeros([nh_store, nv_store])
@@ -592,7 +594,7 @@ def compute(self):
592594

593595
if "b" in keys_state_phys:
594596
J_a_xyz = np.array(J_A_xyz)
595-
597+
596598
pow_store = self.pow_store
597599

598600
for index, value in np.ndenumerate(J_k_xyz[2]): # average on each process
@@ -622,29 +624,24 @@ def compute(self):
622624

623625
if "b" in keys_state_phys:
624626
J_a_hv_average["J_a_v"][rh_i, rv_i] += J_a_xyz[2][index]
625-
((self.rhrz["rh"][index] / self.rh_max) ** (1/pow_store)) * n_store
626-
)
627-
((self.rhrz["rz"][index] / self.rh_max) ** (1/pow_store)) * n_store
628-
629-
else:
630-
r_i = floor(
631-
((self.rhrz["r"][index] / self.r_max) ** (1/pow_store)) * n_store
627+
J_a_hv_average["J_a_h"][rh_i, rv_i] += np.sqrt(
628+
J_a_xyz[0] ** 2 + J_a_xyz[1] ** 2
632629
)
633-
count_iso[r_i] += 1
634-
J_k_xyz_prov["J_k_prov"][r_i] += J_k_xyz_pro[index]
635-
S2_k_xyz_prov["S2_k_prov"][r_i] += S2_k_xyz[index]
636630

637-
if mpi.nb_proc == 1:
638-
J_k_hv_prov["count"] = J_a_hv_prov["count"] = count
631+
if mpi.nb_proc > 0: # average on one process
639632

640-
if mpi.nb_proc > 0:
641-
642-
collect_J_k_prov = mpi.comm.gather(J_k_xyz_prov["J_k_prov"], root=0)
643-
collect_S2_k_prov = mpi.comm.gather(
644-
S2_k_xyz_prov["S2_k_prov"], root=0
633+
collect_J_k_average = mpi.comm.gather(
634+
J_k_xyz_average["J_k_average"], root=0
635+
) # gather all results on one process
636+
collect_S2_k_average = mpi.comm.gather(
637+
S2_k_xyz_average["S2_k_average"], root=0
645638
)
646639
collect_count_iso = mpi.comm.gather(count_iso, root=0)
647640

641+
collect_J_k_v = mpi.comm.gather(J_k_hv_average["J_k_v"], root=0)
642+
collect_J_k_h = mpi.comm.gather(J_k_hv_average["J_k_h"], root=0)
643+
collect_count = mpi.comm.gather(count, root=0)
644+
648645
if "b" in keys_state_phys:
649646
collect_J_a_v = mpi.comm.gather(J_a_hv_average["J_a_v"], root=0)
650647
collect_J_a_h = mpi.comm.gather(J_a_hv_average["J_a_h"], root=0)
@@ -672,20 +669,24 @@ def compute(self):
672669
J_k_xyz_average["count"] = count_final_iso
673670
S2_k_xyz_average["count2"] = count_final_iso
674671

675-
count_final_iso = np.sum(collect_count_iso, axis=0)
676-
J_k_xyz_prov["count"] = count_final_iso
677-
S2_k_xyz_prov["count2"] = count_final_iso
678-
if "b" in keys_state_phys:
679-
for index, value in np.ndenumerate(J_k_hv_prov["J_k_z"]):
680-
if count_final[index] == 0:
681-
J_k_hv_prov["J_k_z"][index] = 0.0
682-
J_k_hv_prov["J_k_h"][index] = 0.0
683-
684-
J_a_hv_prov["J_a_z"][index] = 0.0
685-
J_a_hv_prov["J_a_h"][index] = 0.0
686-
else:
687-
J_k_hv_prov["J_k_z"][index] = (
688-
value / count_final[index]
672+
for index, value in np.ndenumerate(J_k_hv_average["J_k_v"]):
673+
if count_final[index] == 0:
674+
J_k_hv_average["J_k_v"][index] = 0.0
675+
J_k_hv_average["J_k_h"][index] = 0.0
676+
if "b" in keys_state_phys:
677+
J_a_hv_average["J_a_v"][index] = 0.0
678+
J_a_hv_average["J_a_h"][index] = 0.0
679+
else:
680+
J_k_hv_average["J_k_v"][index] = (
681+
value / count_final[index]
682+
)
683+
J_k_hv_average["J_k_h"][index] = (
684+
J_k_hv_average["J_k_h"][index] / count_final[index]
685+
)
686+
if "b" in keys_state_phys:
687+
J_a_hv_average["J_a_v"][index] = (
688+
J_a_hv_average["J_a_v"][index]
689+
/ count_final[index]
689690
)
690691
J_a_hv_average["J_a_h"][index] = (
691692
J_a_hv_average["J_a_h"][index]

fluidsim/base/output/spectra.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def _plot_ndim(
165165
coef_compensate=0,
166166
coef_plot_k3=None,
167167
coef_plot_k53=None,
168+
coef_plot_k43=None,
168169
coef_plot_k2=None,
169170
xlim=None,
170171
ylim=None,
@@ -261,6 +262,10 @@ def _plot_ndim(
261262
to_plot = coef_plot_k2 * ks_no0 ** (-2) * coef_norm
262263
ax.plot(ks, to_plot, "k:", label=r"$\propto k^{-2}$")
263264

265+
if coef_plot_k43 is not None:
266+
to_plot = coef_plot_k43 * ks_no0 ** (-4.0 / 3) * coef_norm
267+
ax.plot(ks, to_plot, "k:", label=r"$\propto k^{-4/3}$")
268+
264269
if xlim is not None:
265270
ax.set_xlim(xlim)
266271

fluidsim/solvers/ns3d/output/spectra.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ def _plot_times(
267267
to_plot = coef_plot_k53 * ks_no0 ** (-5.0 / 3) * coef_norm
268268
ax.plot(ks[1:], to_plot[1:], "k-.")
269269

270-
if coef_plot_k2 is not None:
271-
to_plot = coef_plot_k2 * ks_no0 ** (-2) * coef_norm
270+
if coef_plot_k1 is not None:
271+
to_plot = coef_plot_k1 * ks_no0 ** (-2) * coef_norm
272272
ax.plot(ks[1:], to_plot[1:], "k--")
273273

274274
if xlim is not None:

fluidsim/solvers/ns3d/test_solver.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def init_params(cls):
118118
periods[key] = 0.1
119119

120120
params.output.spectra.kzkh_periodicity = 2
121-
121+
122122
Lx, Ly, Lz = params.oper.Lx, params.oper.Ly, params.oper.Lz
123123
nx, ny, nz = params.oper.nx, params.oper.ny, params.oper.nz
124124
probes_region = (0.0, Lx, 0.0, Ly, 0.0, Lz)
@@ -628,4 +628,3 @@ def test_milestone(self):
628628

629629
if __name__ == "__main__":
630630
unittest.main()
631-
#mpirun -n 2 python -m pytest fluidsim/solvers/ns3d/test_solver.py::TestOutput::test_output -v -s

0 commit comments

Comments
 (0)