========== Simulation ========== Setting up a simulation ------------------------ A PHARE simulation is configured entirely from a Python script, by declaring a small number of objects. Each is declared once (diagnostics may be declared several times, once per output), and ``Simulation`` must always be declared first - every other block below depends on it. .. code-block:: python # ------------ MANDATORY BLOCKS ph.Simulation( # time evolution, domain, AMR, restart and diagnostics-output parameters ) ph.MaxwellianFluidModel( # magnetic field profile and ion population(s), for a Hybrid simulation ) # -- or, for an MHD simulation -- ph.MHDModel( # density, velocity, magnetic field and pressure profiles ) ph.ElectronModel( # electron fluid closure - required for a Hybrid simulation ) # ------------ END OF MANDATORY BLOCKS # ------------ OPTIONAL BLOCKS ph.LoadBalancer( # tune how work is redistributed across MPI ranks ) ph.ElectromagDiagnostics(...) # E and B field outputs ph.FluidDiagnostics(...) # ion moment outputs ph.ParticleDiagnostics(...) # particle outputs ph.MHDDiagnostics(...) # MHD fluid outputs ph.InfoDiagnostics(...) # run-monitoring outputs # ------------ END OF OPTIONAL BLOCKS See :doc:`models` for ``MaxwellianFluidModel``/``MHDModel``/``ElectronModel``, :doc:`diagnostics` for the diagnostics blocks, and :doc:`load_balancing` for ``LoadBalancer``. This page covers the ``Simulation`` block itself. The Simulation block --------------------- ``Simulation`` sets the overall numerical and physical parameters of the run: how long it evolves and at what resolution, the physical domain and mesh, adaptive mesh refinement, restart checkpoints, and where diagnostics are written. .. autoclass:: pyphare.pharein.Simulation Domain and time, worked example -------------------------------- The domain can be given as any two of ``cells`` (number of mesh cells), ``dl`` (mesh spacing) and ``domain_size`` (physical size) - the third is derived. Likewise for time, any two of ``time_step``, ``time_step_nbr`` and ``final_time``: .. code-block:: python import pyphare.pharein as ph ph.Simulation( cells=(100, 100), dl=(0.2, 0.2), # domain_size is derived: (20, 20) time_step=0.001, time_step_nbr=1000, # final_time is derived: ~1.0 refinement="tagging", max_nbr_levels=3, ) .. note:: When ``final_time`` and ``time_step`` are both given, ``time_step`` is kept exactly as given and ``final_time`` is treated as a target: the actual number of steps is rounded to the nearest integer, so the run may stop slightly before or after the requested ``final_time``. Restarts and diagnostics output --------------------------------- See :doc:`restarts` for ``restart_options`` and :doc:`diagnostics` for ``diag_options`` and the diagnostics blocks themselves.