Running a simple simulationΒΆ

This script is an example of how one can run a small simulation with instantaneous plotting. This can be useful for simple tests. It can be launched by the commands python simul_ns2d.py (sequencial) and mpirun -np 8 python simul_ns2d.py (parallel on 8 processes).

from math import pi

from fluidsim.solvers.ns2d.solver import Simul

import fluiddyn as fld

params = Simul.create_default_params()

params.short_name_type_run = 'test'

params.oper.nx = params.oper.ny = nh = 32
params.oper.Lx = params.oper.Ly = Lh = 2 * pi

delta_x = Lh / nh
params.nu_8 = 2.*params.forcing.forcing_rate**(1./3)*delta_x**8

params.time_stepping.t_end = 2.

params.init_fields.type = 'dipole'

params.FORCING = True
params.forcing.type = 'random'

params.output.sub_directory = 'examples'

params.output.periods_print.print_stdout = 0.25

params.output.periods_save.phys_fields = 1.
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.periods_plot.phys_fields = 0.0

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.output.phys_fields.plot()
sim.time_stepping.start()
sim.output.phys_fields.plot()

fld.show()

Of course the plots slow down the simulation, so for larger simulation we just remove the plot command from the script, which gives:

from math import pi

from fluidsim.solvers.ns2d.solver import Simul

params = Simul.create_default_params()

params.short_name_type_run = 'test'

params.oper.nx = params.oper.ny = nh = 32
params.oper.Lx = params.oper.Ly = Lh = 2 * pi

delta_x = Lh / nh
params.nu_8 = 2.*params.forcing.forcing_rate**(1./3)*delta_x**8

params.time_stepping.t_end = 2.

params.init_fields.type = 'dipole'

params.FORCING = True
params.forcing.type = 'random'

params.output.sub_directory = 'examples'

params.output.periods_print.print_stdout = 0.25

params.output.periods_save.phys_fields = 1.
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.periods_plot.phys_fields = 0.0

sim = Simul(params)

sim.time_stepping.start()

To submit the simulation on a cluster (here on one node), just run this tiny script:


from fluiddyn.clusters.legi import Calcul3 as Cluster
cluster = Cluster()


cluster.submit_script(
    'simul_ns2d.py', name_run='fld_example',
    nb_cores_per_node=cluster.nb_cores_per_node)