Run a simple simulation with online plot
These scripts are examples of how one can run small simulations with
instantaneous plotting. This can be useful for simple tests. The first script
can be launched by the commands python simul_ns2d_plotphys.py
(sequential).
import os
import fluiddyn as fld
from fluidsim.solvers.ns2d.solver import Simul
if "FLUIDSIM_TESTS_EXAMPLES" in os.environ:
t_end = 1.0
nh = 16
else:
t_end = 10.0
nh = 64
params = Simul.create_default_params()
params.short_name_type_run = "test"
params.oper.nx = params.oper.ny = nh
params.oper.Lx = params.oper.Ly = Lh = 10.0
delta_x = Lh / nh
params.nu_8 = 2e-3 * params.forcing.forcing_rate ** (1.0 / 3) * delta_x**8
params.time_stepping.t_end = 10.0
params.init_fields.type = "dipole"
params.forcing.enable = True
params.forcing.type = "tcrandom"
params.output.sub_directory = "examples"
params.output.periods_plot.phys_fields = 0.1
params.output.periods_save.phys_fields = 0.2
params.output.periods_save.spatial_means = 0.05
params.output.ONLINE_PLOT_OK = True
sim = Simul(params)
sim.time_stepping.start()
print(
"""
A movie can be produced with the command (using ffmpeg):
sim.output.phys_fields.animate(dt_frame_in_sec=0.1, dt_equations=0.08, repeat=False, save_file=1, tmax=10)
"""
)
fld.show()
The second script is dedicated to online plotting of statistic quantities.
import os
import fluiddyn as fld
from fluidsim.solvers.ns2d.solver import Simul
if "FLUIDSIM_TESTS_EXAMPLES" in os.environ:
t_end = 2.0
nh = 24
else:
t_end = 10.0
nh = 32
params = Simul.create_default_params()
params.short_name_type_run = "examples"
params.output.sub_directory = "examples"
params.oper.nx = params.oper.ny = nh
params.oper.Lx = params.oper.Ly = Lh = 10
delta_x = Lh / nh
params.nu_8 = 2.0 * params.forcing.forcing_rate ** (1.0 / 3) * delta_x**8
params.time_stepping.t_end = t_end
params.init_fields.type = "dipole"
params.forcing.enable = True
params.forcing.type = "tcrandom"
params.output.periods_print.print_stdout = 0.5
params.output.periods_save.phys_fields = 1.0
params.output.periods_save.spectra = 0.5
params.output.periods_save.spatial_means = 0.05
params.output.periods_save.spect_energy_budg = 0.5
params.output.periods_save.increments = 0.5
params.output.ONLINE_PLOT_OK = True
params.output.spectra.HAS_TO_PLOT_SAVED = True
params.output.spatial_means.HAS_TO_PLOT_SAVED = True
params.output.spect_energy_budg.HAS_TO_PLOT_SAVED = True
params.output.increments.HAS_TO_PLOT_SAVED = True
params.output.phys_fields.field_to_plot = "rot"
sim = Simul(params)
sim.time_stepping.start()
sim.output.phys_fields.plot()
fld.show()