def fig7_spectra(path, fig, ax, t_start, run_nb, nu_order=8): sim = fls.load_sim_for_plot(path, merge_missing_params=True) kh, E_tot, EK, EA = _mean_spectra(sim, t_start) eps = _eps(sim, t_start) k_d = _k_diss(sim.params) nu = getattr(sim.params, f"nu_{nu_order}") norm = k_d * nu * kh**nu_order color_list = sns.color_palette() kh_f = kh / k_d integral = np.trapz(2 * E_tot * norm, kh_f, dx=kh_f[1] - kh_f[0]) kdiss_max = kh_f[np.where((E_tot * norm) == (E_tot * norm).max())] ax.plot( kh_f, 2 * E_tot * norm / eps, # (2 * integral), c=color_list[run_nb], linewidth=1, # label=f'$c = {sim.params.c2**0.5}, n= {sim.params.oper.nx}$' label=f"{kdiss_max}" # label=f'int={integral}' ) ax.vlines(kdiss_max, 0, 2.2, colors=color_list[run_nb], linewidth=0.5) # more minor ticks minor_locator = AutoMinorLocator(5) ax.xaxis.set_minor_locator(minor_locator) ax.set_ylim(0, 2.2) ax.set_xlim(0.6, 2.5) # 2 ax.set_xlabel("$k/k_d$") ax.set_ylabel(_label(nu_order))
def fig2_seb(path, fig=None, ax=None, t_start=None): sim = fls.load_sim_for_plot(path, merge_missing_params=True) path_file = os.path.join(path, "spect_energy_budg.h5") f = h5py.File(path_file, "r") k_f = _k_f(sim.params) # eps = _eps(sim, t_start) eps, E, ts, tmax = epsetstmax(path) if t_start is None: t_start = ts imin_plot = _index_where(f["times"][...], t_start) khE = (f["khE"][...] + 0.1) / k_f transfers = 0 for key in ("Tq_AAA", "Tq_GAAs", "Tq_GAAd", "Tq_AGG", "Tq_GGG"): transfers += f[key][imin_plot:].mean(0) / eps Pi_tot = cumsum_inv(transfers) * sim.oper.deltak print(eps) ax.axhline(1.0, color="k", ls=":") ax.set_xlabel("$k/k_f$") ax.set_ylabel(r"$\Pi(k)/\epsilon$") ax.set_xscale("log") ax.set_yscale("linear") ax.plot(khE, Pi_tot, "k", linewidth=2, label=r"$\Pi$") ax.set_ylim([-0.1, 1.1])
def fig_struct_order( path, fig, ax, eps, Fr, order=[2, 4, 6], tmin=10, tmax=1000, delta_t=0.5, key="ux", run_nb=0, label_func=None, coeff=1, ylabel=True, test=False, n_colors=10, ): sim = fls.load_sim_for_plot(path, merge_missing_params=True) rxs, So_var_dict, deltax = _rxs_str_func( sim, order, tmin, tmax, delta_t, [key], cache=test ) for ax1 in ax: ax1.set_xlabel("$r/L_f$") ax1.set_xscale("log") ax1.set_yscale("log") if label_func is None: label_func = _label L_f = np.pi / _k_f(sim.params) # color_list = ['r', 'b', 'g', 'c', 'm', 'y', 'k'] color_list = sns.color_palette(n_colors=n_colors) if coeff == "1/c": coeff = 1 / sim.params.c2 ** 0.5 elif coeff == "c": coeff = sim.params.c2 ** 0.5 for i, (o, ax1) in enumerate(zip(order, ax)): ax1.set_ylabel(label_func(key, o)) key_order = "{0}_{1:.0f}".format(key, o) norm = ( (L_f * Fr ** 0.5) ** (o / 3 - 1) * eps ** (o / 3) * rxs * coeff ** o ) So_var = So_var_dict[key_order] / norm ax1.plot( rxs / L_f, So_var, c=color_list[run_nb], linewidth=1, label=label_func(key, o), ) if o == 2: ax1.set_ylim([1e-1, 8]) ax1.set_xlim([1e-3, 2])
def fig11_ratio_struct(path, fig, ax1, order=[2, 3, 4, 5], tmin=0, tmax=1000, delta_t=0.5): sim = fls.load_sim_for_plot(path, merge_missing_params=True) key_var = ["ux", "uy"] rxs, So_var_dict, deltax = _rxs_str_func(sim, order, tmin, tmax, delta_t, key_var, force_absolute=True) ax1.set_xlabel("$r/L_f$") ax1.set_ylabel("$R_p(r)$") # ax1.set_title('Ratio of longitundinal and transverse struct. functions') ax1.set_xscale("log") ones = pl.ones(rxs.shape) shock_model = { 0: 1.0, 1: pl.pi / 4, 2: 2, 3: 6 * pl.pi / 8, 4: 8.0 / 3, 5: 15.0 * pl.pi / 16, 6: 16.0 / 5, } L_f = pl.pi / _k_f(sim.params) # color_list = ['r', 'b', 'g', 'c', 'm', 'y', 'k'] color_list = iter(sns.color_palette()) for o in order: color1 = next(color_list) # color2 = ':' + color1 So_ux = So_var_dict["{0}_{1:.0f}".format("ux", o)] So_uy = So_var_dict["{0}_{1:.0f}".format("uy", o)] ax1.plot( rxs / L_f, abs(So_ux) / abs(So_uy), c=color1, linewidth=1, label="$R_{:.0f}$".format(o), ) ax1.plot(rxs / L_f, ones * shock_model[int(o)], linestyle=":", c=color1) ax1.set_xlim([0.001, 3]) ax1.set_ylim([0.0, 11]) rev_legend(ax, loc=1, fontsize=9)
def test_output(self): sim = self.sim oper = sim.oper X, Y, Z = oper.get_XYZ_loc() def compute_forcing_fft_each_time(self): return {"vx_fft": oper.create_arrayK(value=0)} sim.forcing.forcing_maker.monkeypatch_compute_forcing_fft_each_time( compute_forcing_fft_each_time) sim.time_stepping.start() sim.state.compute("divh") np.testing.assert_almost_equal(sum(sim.output.compute_energies()), sim.output.compute_energy()) if mpi.nb_proc > 1: return sim2 = fls.load_sim_for_plot(sim.output.path_run) sim2.output.print_stdout.load() sim2.output.print_stdout.plot() sim2.output.spatial_means.load() sim2.output.spatial_means.load_dataset() sim2.output.spatial_means.plot() sim2.output.spectra.load1d_mean() sim2.output.spectra.load3d_mean() sim2.output.spectra.plot1d( tmin=0.1, tmax=10, delta_t=0.01, coef_compensate=5 / 3, coef_plot_k3=1.0, coef_plot_k53=1.0, ) sim2.output.spectra.plot3d( tmin=0.1, tmax=10, delta_t=0.01, coef_compensate=5 / 3, coef_plot_k3=1.0, coef_plot_k53=1.0, ) sim2.output.phys_fields.set_equation_crosssection(f"x={sim.oper.Lx/4}") sim2.output.phys_fields.animate("vx") sim2.output.phys_fields.plot(field="vx", time=10) plt.close("all")
def fig7_spectra(path, fig, ax, Fr, c, t_start, run_nb, n_colors=10): sim = fls.load_sim_for_plot(path, merge_missing_params=True) kh, E_tot, EK, EA = _mean_spectra(sim, t_start) eps = _eps(sim, t_start) k_f = _k_f(sim.params) # norm = (kh ** (-2) * # sim.params.c2 ** (1. / 6) * # eps ** (5. / 9) * # k_f ** (4. / 9)) o = 2 L_f = pl.pi / k_f norm = (L_f * Fr**0.5)**(o / 3 - 1) * eps**(o / 3) * kh**-2 color_list = sns.color_palette(n_colors=n_colors) kh_f = kh / k_f ax.plot( kh_f, E_tot / norm, # "k", c=color_list[run_nb], # c="k", # linestyle=next(style), linewidth=1, label=f"$c = {c}$", ) # ax.plot(kh_f, EK / norm, 'r', linewidth=2, label='$E_K$') # ax.plot(kh_f, EA / norm, 'b', linewidth=2, label='$E_A$') if run_nb == 0: s1 = slice(_index_where(kh_f, 3), _index_where(kh_f, 80)) s2 = slice(_index_where(kh_f, 30), _index_where(kh_f, 200)) ax.plot((kh_f)[s1], 0.7 * (kh_f**-2 / norm)[s1], "k-", linewidth=1) ax.text(10, 0.2, "$k^{-2}$") # ax.plot((kh_f)[s2], (kh_f ** -1.5 / norm)[s2], 'k-', linewidth=1) # ax.text(70, 1.5, '$k^{-3/2}$') ax.set_xscale("log") ax.set_yscale("log") ax.set_xlabel("$k/k_f$") ax.set_ylabel(_label()) # ax.legend() rev_legend(ax, loc=1, fontsize=8) fig.tight_layout()
def fig2_seb(path, fig=None, ax=None, t_start=None): sim = fls.load_sim_for_plot(path, merge_missing_params=True) path_file = os.path.join(path, "spect_energy_budg.h5") f = h5py.File(path_file, "r") k_f = _k_f(sim.params) # eps = _eps(sim, t_start) eps, E, ts, tmax = epsetstmax(path) if t_start is None: t_start = ts imin_plot = _index_where(f["times"][...], t_start) khE = (f["khE"][...] + 0.1) / k_f transferEKr = f["transfer2D_EKr"][imin_plot:].mean(0) / eps transferEKd = f["transfer2D_EKd"][imin_plot:].mean(0) / eps transferEAr = f["transfer2D_EAr"][imin_plot:].mean(0) / eps transferEAd = f["transfer2D_EAd"][imin_plot:].mean(0) / eps # transferEPd = f['transfer2D_EPd'][imin_plot:].mean(0) / eps PiEKr = cumsum_inv(transferEKr) * sim.oper.deltak PiEKd = cumsum_inv(transferEKd) * sim.oper.deltak PiEAr = cumsum_inv(transferEAr) * sim.oper.deltak PiEAd = cumsum_inv(transferEAd) * sim.oper.deltak # PiEPd = cumsum_inv(transferEPd) * sim.oper.deltak print(eps) ax.axhline(1.0, color="k", ls=":") PiEK = PiEKr + PiEKd PiEA = PiEAr + PiEAd PiE = PiEK + PiEA ax.set_xlabel("$k/k_f$") ax.set_ylabel(r"$\Pi(k)/\epsilon$") ax.set_xscale("log") ax.set_yscale("linear") ax.plot(khE, PiE, "k", linewidth=2, label=r"$\Pi$") ax.plot(khE, PiEK, "r:", linewidth=2, label=r"$\Pi_K$") ax.plot(khE, PiEA, "b--", linewidth=2, label=r"$\Pi_A$") ax.set_ylim([-0.1, 1.1]) ax.legend()
def test_output(self): sim = self.sim sim.time_stepping.start() if mpi.nb_proc > 1: return sim2 = fls.load_sim_for_plot(sim.output.path_run) sim2.output.print_stdout.load() sim2.output.print_stdout.plot() sim2.output.spatial_means.load() sim2.output.spatial_means.load_dataset() sim2.output.spatial_means.plot() sim2.output.spectra.load1d_mean() sim2.output.spectra.load3d_mean() sim2.output.spectra.plot1d( tmin=0.1, tmax=10, delta_t=0.01, coef_compensate=5 / 3, coef_plot_k3=1.0, coef_plot_k53=1.0, ) sim2.output.spectra.plot3d( tmin=0.1, tmax=10, delta_t=0.01, coef_compensate=5 / 3, coef_plot_k3=1.0, coef_plot_k53=1.0, ) sim2.output.phys_fields.set_equation_crosssection(f"x={sim.oper.Lx/4}") sim2.output.phys_fields.animate("vx") sim2.output.phys_fields.plot(field="vx", time=10) plt.close("all")
def fig1_energy( paths, fig=None, ax=None, t_start=0.0, legend=None, linestyle=None, normalized=False, ): # fig.subplots_adjust(right=0.78) if legend is None: legend = [os.path.basename(p) for p in paths] for i, path in enumerate(paths): # with stdout_redirected(): sim = fls.load_sim_for_plot(path, merge_missing_params=True) P0 = _eps(sim, t_start) k_f = _k_f(sim.params) # path + '/params_simul.xml') L_f = pl.pi / k_f dico = sim.output.spatial_means.load() E = dico["E"] t = dico["t"] if normalized: E_f = (P0 * L_f) ** (2.0 / 3) T_f = (P0 / L_f ** 2) ** (-1.0 / 3) E = E / E_f t = t / T_f print( "{}\teps={}\tk_f={}\tE_f={}\tT_f={}".format( label, P0, k_f, E_f, T_f ) ) label = legend[i] ax.plot(t, E, linestyle, linewidth=1.0, label=label)
def fig12_flatness( path, fig, ax, tmin=0, tmax=1000, delta_t=0.5, key_var=("uy", "ux"), run_nb=0, ax_inset=None, cache=False, n_colors=10, ): sim = fls.load_sim_for_plot(path, merge_missing_params=True) order = [2, 4] rxs, So_var_dict, deltax = _rxs_str_func( sim, order, tmin, tmax, delta_t, key_var, cache=cache ) ax.set_xlabel("$r/L_f$") # ax.set_ylabel('$F_T, F_L$') # ax.set_title('Flatness of longitundinal and transverse increments') # ax.hold(True) ax.set_xscale("log") ax.set_yscale("log") _label = {"ux": "F_L", "uy": "F_T"} L_f = pl.pi / _k_f(sim.params) # color_list = ['r', 'b', 'g', 'c', 'm', 'r', 'b'] color_list = sns.color_palette(n_colors=n_colors) def get_F(key): So_4 = So_var_dict["{0}_{1:.0f}".format(key, 4)] So_2 = So_var_dict["{0}_{1:.0f}".format(key, 2)] return So_4 / So_2 ** 2 if len(key_var) == 1: key = key_var[0] F = get_F(key) label = _label[key] # r^-1 line cond = pl.logical_and(rxs > 0.015 * L_f, rxs < 0.17 * L_f) fac = 12 ax.plot(rxs[cond] / L_f, fac / rxs[cond], "k", linewidth=0.5) x_text = rxs[cond].mean() / 2 / L_f + 0.02 y_text = fac / rxs[cond].mean() * 2 ax.text(x_text, y_text, "$r^{-1}$") else: F = np.divide(*map(get_F, key_var)) print("F=", F.shape) label = f"{_label[key_var[0]]}/{_label[key_var[1]]}" label = f"${label}$" color1 = color_list[run_nb] ax.plot(rxs / L_f, F, c=color1, linewidth=1, label=label) if ax_inset is not None: ax_inset.semilogx( rxs / L_f, get_F("uy") / get_F("ux"), color_list[run_nb], linewidth=1 )
def test_forcing_output(self): sim = self.sim sim.time_stepping.start() sim.state.compute("rot_fft") sim.state.compute("rot_fft") with self.assertRaises(ValueError): sim.state.compute("abc") sim.state.compute("abc", RAISE_ERROR=False) ux_fft = sim.state.compute("ux_fft") uy_fft = sim.state.compute("uy_fft") sim.state.init_statespect_from(ux_fft=ux_fft) sim.state.init_statespect_from(uy_fft=uy_fft) sim.output.compute_enstrophy() if mpi.nb_proc == 1: plt.close("all") sim.output.frequency_spectra.compute_frequency_spectra() sim.output.plot_summary() sim.output.spectra.plot2d() sim.output.spatial_means.plot_energy() sim.output.spatial_means.plot_dt_energy() sim.output.spatial_means.plot_energy_shear_modes() plt.close("all") sim.output.spatial_means.compute_time_means() sim.output.spatial_means.load_dataset() sim.output.spatial_means.time_first_saved() sim.output.spatial_means.time_last_saved() sim.output.spectra_multidim.plot() with self.assertRaises(ValueError): sim.state.get_var("test") sim2 = fls.load_sim_for_plot(sim.output.path_run) sim2.output spatio_temporal_spectra = sim2.output.spatio_temporal_spectra spatio_temporal_spectra.compute_frequency_spectra() spatio_temporal_spectra.print_info_frequency_spectra() spatio_temporal_spectra.plot_frequency_spectra_individual_mode( mode=(1, 1)) spatio_temporal_spectra.plot_kx_omega_cross_section() spatio_temporal_spectra.plot_kz_omega_cross_section() sim2.output.increments.load() sim2.output.increments.plot() sim2.output.increments.load_pdf_from_file() sim2.output.phys_fields.animate( "ux", dt_frame_in_sec=1e-6, dt_equations=0.3, repeat=False, clim=(-1, 1), save_file=False, numfig=1, ) sim2.output.phys_fields.plot() # `compute('q')` two times for better coverage... sim.state.get_var("q") sim.state.get_var("q") sim.state.get_var("div") path_run = sim.output.path_run if mpi.nb_proc > 1: path_run = mpi.comm.bcast(path_run) sim3 = fls.load_state_phys_file(path_run, modif_save_params=False) sim3.params.time_stepping.t_end += 0.2 sim3.time_stepping.start() if mpi.nb_proc == 1: sim3.output.phys_fields.animate( "ux", dt_frame_in_sec=1e-6, dt_equations=0.3, repeat=False, clim=(-1, 1), save_file=False, numfig=1, ) plt.close("all")
def test_forcing_output(self): sim = self.sim sim.time_stepping.start() sim.state.compute("rot_fft") sim.state.compute("rot_fft") sim.state.compute("ux_fft") sim.state.compute("uy_fft") if mpi.nb_proc == 1: sim.output.spectra.plot1d() sim.output.spectra.plot2d() sim.output.spectra.load2d_mean() sim.output.spectra.load1d_mean() sim.output.spatial_means.plot() sim.output.spatial_means.plot_dt_energy() sim.output.spatial_means.plot_dt_enstrophy() sim.output.spatial_means.compute_time_means() sim.output.spatial_means.load_dataset() sim.output.spatial_means.time_first_saved() sim.output.spatial_means.time_last_saved() sim.output.print_stdout.plot_energy() sim.output.print_stdout.plot_deltat() sim.output.spectra_multidim.plot() sim.output.spect_energy_budg.plot() with self.assertRaises(ValueError): sim.state.get_var("test") sim2 = fls.load_sim_for_plot(sim.output.path_run) sim2.output sim2.output.increments.load() sim2.output.increments.plot() sim2.output.increments.load_pdf_from_file() sim2.output.increments.plot_pdf() sim2.output.phys_fields.animate( "ux", dt_frame_in_sec=1e-6, dt_equations=0.3, repeat=False, clim=(-1, 1), save_file=False, numfig=1, ) sim2.output.phys_fields.plot() # `compute('q')` two times for better coverage... sim.state.get_var("q") sim.state.get_var("q") sim.state.get_var("div") path_run = sim.output.path_run if mpi.nb_proc > 1: path_run = mpi.comm.bcast(path_run) sim3 = fls.load_state_phys_file(path_run, modif_save_params=False) sim3.params.time_stepping.t_end += 0.2 sim3.time_stepping.start() plt.close("all")
from pathlib import Path import matplotlib.pyplot as plt import fluidsim as fls paths = sorted((Path(fls.FLUIDSIM_PATH) / "examples").glob("dedalus_*")) path = paths[-1] sim = fls.load_sim_for_plot(path) sim.output.phys_fields.plot("b") plt.show()
def fig3_struct(path, fig, ax1, tmin=0, tmax=1000): sim = fls.load_sim_for_plot(path, merge_missing_params=True) path_file = os.path.join(path, "increments.h5") f = h5py.File(path_file, "r") dset_times = f["times"] times = dset_times[...] if tmax is None: tmax = times.max() rxs = f["rxs"][...] oper = f["/info_simul/params/oper"] nx = oper.attrs["nx"] Lx = oper.attrs["Lx"] deltax = Lx / nx rxs = pl.array(rxs, dtype=pl.float64) * deltax imin_plot = pl.argmin(abs(times - tmin)) imax_plot = pl.argmin(abs(times - tmax)) S_uL2JL = f["struc_func_uL2JL"][imin_plot:imax_plot + 1].mean(0) S_uT2JL = f["struc_func_uT2JL"][imin_plot:imax_plot + 1].mean(0) S_c2h2uL = f["struc_func_c2h2uL"][imin_plot:imax_plot + 1].mean(0) S_Kolmo = f["struc_func_Kolmo"][imin_plot:imax_plot + 1].mean(0) # S_uT2uL = f['struc_func_uT2uL'][imin_plot:imax_plot + 1].mean(0) eps = _eps(sim, tmin) S_Kolmo_theo = -4 * eps * rxs Lf = pl.pi / _k_f(sim.params) ax1.set_xscale("log") ax1.set_yscale("linear") # ax1.plot(rxs / Lf, # (S_uL2JL+S_uT2JL+S_c2h2uL)/S_Kolmo_theo, # 'y', linewidth=1, label='sum check') def _label(x, y): pre = "" if y == "uu": y = r"\mathbf{u}" y2 = r"|\delta {}|^2".format(y) else: if y == "h": pre = "c ^ 2" y2 = r"(\delta {})^2".format(y) return "$ -\langle {} \delta {} {} \\rangle $".format(pre, x, y2) ax1.set_xlabel("$r/L_f$") label1 = _label("J_L", "uu") label2 = _label("u_L", "h") label3 = label1[:-10] + " + " + label2[10:] def label_norm(label): str_norm = " / (4\epsilon r)$" return label.rstrip(" $") + str_norm ax1.set_ylabel(label_norm(label3)) ax1.plot(rxs / Lf, S_Kolmo / S_Kolmo_theo, "k", linewidth=2, label=(label3)) ax1.plot( rxs / Lf, (S_uL2JL + S_uT2JL) / S_Kolmo_theo, "r:", linewidth=2, label=(label1), ) ax1.plot(rxs / Lf, S_c2h2uL / S_Kolmo_theo, "b--", linewidth=2, label=(label2)) # ax1.plot(rxs / Lf, S_uL2JL / S_Kolmo_theo, # 'r--', linewidth=2, label=_label('J_L', 'u_L')) # ax1.plot(rxs / Lf, S_uT2JL / S_Kolmo_theo, # 'r-.', linewidth=2, label=_label('J_L', 'u_T')) # cond = rxs < 6 * deltax # ax1.plot(rxs[cond] / Lf, 1.e0 * rxs[cond] ** 3 / S_Kolmo_theo[cond], # 'y', linewidth=2, label='$r^3/S; r<6dx$') ax1.axhline(1.0, color="k", ls=":") # ax1.plot(rxs, pl.ones(rxs.shape), 'k:', linewidth=1) ax1.set_xlim([None, 2]) ax1.set_ylim([-0.1, 1.1]) ax1.legend(loc=8)
def test_output(self): sim = self.sim sim.time_stepping.start() if mpi.nb_proc == 1: phys_fields = sim.output.phys_fields phys_fields.plot(equation=f"iz=0", numfig=1000) phys_fields.get_field_to_plot_from_state() phys_fields.get_field_to_plot_from_state(sim.state.get_var("vx")) phys_fields.get_field_to_plot_from_state("vx", "x=0") phys_fields.get_field_to_plot_from_state("vx", "ix=0") phys_fields.get_field_to_plot_from_state("vx", "y=0") phys_fields.get_field_to_plot_from_state("vx", "iy=0") phys_fields.get_field_to_plot_from_state("vx", "z=0") # compute twice for better coverage sim.state.compute("rotz") sim.state.compute("rotz") sim.state.compute("divh") sim.output.phys_fields._get_grid1d("iz=0") sim.output.phys_fields._get_grid1d("iy=0") path_run = sim.output.path_run if mpi.nb_proc > 1: path_run = mpi.comm.bcast(path_run) if mpi.nb_proc == 1: sim2 = fls.load_sim_for_plot(path_run) sim2.output.print_stdout.load() sim2.output.print_stdout.plot() sim2.output.spatial_means.load() sim2.output.spatial_means.load_dataset() sim2.output.spatial_means.plot() sim2.output.spectra.load1d_mean() sim2.output.spectra.load3d_mean() sim2.output.spectra.plot1d( tmin=0.1, tmax=10, delta_t=0.01, coef_compensate=5 / 3, coef_plot_k3=1.0, coef_plot_k53=1.0, ) sim2.output.spectra.plot3d( tmin=0.1, tmax=10, delta_t=0.01, coef_compensate=5 / 3, coef_plot_k3=1.0, coef_plot_k53=1.0, ) sim2.output.phys_fields.set_equation_crosssection( f"x={sim.oper.Lx/4}" ) sim2.output.phys_fields.animate("vx") sim2.output.phys_fields.plot( field="vx", time=10, equation=f"z={sim.oper.Lz/4}" ) sim3 = fls.load_state_phys_file(path_run, modif_save_params=False) sim3.params.time_stepping.t_end += 0.2 sim3.time_stepping.start() if mpi.nb_proc == 1: sim3.output.phys_fields.animate( "vx", dt_frame_in_sec=1e-6, dt_equations=0.3, repeat=False, clim=(-1, 1), save_file=False, numfig=1, ) sys.argv = ["fluidsim-create-xml-description", path_run] run() plt.close("all")
args = parser.parse_args() path_root = "/fsnet/project/meige/2015/15DELDUCA/DataSim/Coef_Diss" paths_gamma = glob(os.path.join(path_root, "Coef_Diss_gamma*")) if args.gamma == 0.2: index = 0 elif args.gamma == 0.5: index = 1 elif args.gamma == 1.0: index = 2 paths_sim = sorted(glob(paths_gamma[index] + "/NS2D.strat*")) path_file = glob(paths_sim[-1] + "/state_phys*")[-1] sim = load_sim_for_plot(paths_sim[-1]) params = _deepcopy(sim.params) params.oper.NO_SHEAR_MODES = bool(args.NO_SHEAR_MODES) params.init_fields.type = "from_file" params.init_fields.from_file.path = path_file params.time_stepping.USE_CFL = False params.time_stepping.t_end += 500 params.time_stepping.deltat0 = sim.time_stepping.deltat * 0.5 params.NEW_DIR_RESULTS = True params.oper.type_fft = "fft2d.mpi_with_fftw1d"
import pandas as pd import numpy as np from paths import load_df import matplotlib.pyplot as plt import fluidsim as fs from base import matplotlib_rc, markers, _k_f from paths import paths_sim, exit_if_figure_exists path_fig = exit_if_figure_exists(__file__) df = load_df() df.set_index("short name", inplace=True, drop=False) df_shock_sep = pd.read_csv("dataframes/shock_sep.csv", comment="#") df_shock_sep.set_index("short_name", inplace=True) df.head() sim = fs.load_sim_for_plot(paths_sim[df_shock_sep.iloc[0].name], merge_missing_params=True) Lf = np.pi / _k_f(sim.params) df["shock separation"] = df_shock_sep["mean"] / Lf df.head() matplotlib_rc(11) fig, ax = plt.subplots(figsize=(5, 3)) mark = markers() for n, grp in df.groupby("$n$"): ax.scatter( r"$F_f$", "shock separation", marker=next(mark), # kind="scatter", loglog=True, ax=ax data=grp,
def test_forcing_output(self): sim = self.sim sim.time_stepping.start() sim.state.compute("rot_fft") sim.state.compute("rot_fft") with self.assertRaises(ValueError): sim.state.compute("abc") sim.state.compute("abc", RAISE_ERROR=False) ux_fft = sim.state.compute("ux_fft") uy_fft = sim.state.compute("uy_fft") sim.state.init_statespect_from(ux_fft=ux_fft) sim.state.init_statespect_from(uy_fft=uy_fft) if mpi.nb_proc == 1: sim.output.spectra.plot1d() sim.output.spectra.plot2d() sim.output.spectra.load2d_mean() sim.output.spectra.load1d_mean() sim.output.spatial_means.plot() sim.output.spatial_means.plot_dt_energy() sim.output.spatial_means.plot_dt_enstrophy() sim.output.spatial_means.compute_time_means() sim.output.spatial_means.load_dataset() sim.output.spatial_means.time_first_saved() sim.output.spatial_means.time_last_saved() sim.output.print_stdout.plot_energy() sim.output.print_stdout.plot_deltat() sim.output.spectra_multidim.plot() sim.output.spect_energy_budg.plot() with self.assertRaises(ValueError): sim.state.get_var("test") sim2 = fls.load_sim_for_plot(sim.output.path_run) sim2.output sim2.output.increments.load() sim2.output.increments.plot() sim2.output.increments.load_pdf_from_file() sim2.output.increments.plot_pdf() sim2.output.phys_fields.animate( "ux", dt_frame_in_sec=1e-6, dt_equations=0.3, repeat=False, clim=(-1, 1), save_file=False, numfig=1, ) sim2.output.phys_fields.plot() # `compute('q')` two times for better coverage... sim.state.get_var("q") sim.state.get_var("q") sim.state.get_var("div") path_run = sim.output.path_run if mpi.nb_proc > 1: path_run = mpi.comm.bcast(path_run) sim3 = fls.load_state_phys_file(path_run, modif_save_params=False) sim3.params.time_stepping.t_end += 0.2 sim3.time_stepping.start() if mpi.nb_proc == 1: sim3.output.phys_fields.animate( "ux", dt_frame_in_sec=1e-6, dt_equations=0.3, repeat=False, clim=(-1, 1), save_file=False, numfig=1, ) plt.close("all") # test_enstrophy_conservation # Verify that the enstrophy growth rate due to nonlinear tendencies # (advection term) must be zero. self.sim.params.forcing.enable = False tendencies_fft = self.sim.tendencies_nonlin() state_spect = self.sim.state.state_spect oper = self.sim.oper Frot_fft = tendencies_fft.get_var("rot_fft") rot_fft = state_spect.get_var("rot_fft") T_rot = (Frot_fft.conj() * rot_fft + Frot_fft * rot_fft.conj()).real / 2.0 sum_T = oper.sum_wavenumbers(T_rot) self.assertAlmostEqual(sum_T, 0, places=14)
for t in range(10, 26): _df = pd.read_csv( # "dataframes/shock_sep_laplacian_nupt1.csv", f"dataframes/shock_sep_laplacian_nupt1_by_counting_t{t}.csv", comment="#", ) _dfs.append(_df.set_index("short_name")) _df_concat = pd.concat(_dfs, keys=range(10, 26)) df_shock_sep = _df_concat.groupby(level=1).mean() df_shock_sep df_shock_sep.to_csv("dataframes/shock_sep_laplacian_nupt1_by_counting_mean.csv") sim = fs.load_sim_for_plot(paths_sim[df_shock_sep.iloc[0].name]) Lf = np.pi / _k_f(sim.params) df["shock separation"] = df_shock_sep["mean"] / Lf df.head() df["shock separation"] = df_shock_sep["mean"] / Lf df.head() matplotlib_rc(11) fig, ax = plt.subplots(figsize=(5, 3)) mark = markers() for n, grp in df.groupby("$n$"): ax.scatter( r"$F_f$",
if MAKE_TABLE: path_table = ("/home/users/calpelin7m/" + f"Phd/docs/Manuscript/buoyancy_reynolds_table_n{nx}.tex") to_print = ("\\begin{table}[h]\n" "\\centering \n" "\\begin{tabular}{cccc} \n" "\\toprule[1.5pt] \n" + \ "\\bm{$\\gamma$} & \\bm{$F_h$} & \\bm{$Re_8$} & \\bm{$\\mathcal{R}$} \\\\ \n" "\\midrule\\ \n") for path in path_simulations: # Load object simulations sim = load_sim_for_plot(path) # Compute gamma from path gamma_str = path.split("_gamma")[1].split("_")[0] if gamma_str.startswith("0"): gamma_table = float(gamma_str[0] + "." + gamma_str[1]) else: gamma_table = float(gamma_str) # Compute mean kinetic dissipation dict_spatial = sim.output.spatial_means.load() times = dict_spatial["t"] epsK_tot = dict_spatial["epsK_tot"] epsK_tmean = np.mean(epsK_tot[-n_files_tmean:], axis=0) print("epsilon", epsK_tmean)