Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Cleaned up the basic simulation example page a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Mar 1, 2024
1 parent dce3582 commit 8dda11f
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions docs/user-guide/basic-simulation/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ Start with importing Swiftest. ::
Initial Simulation Setup
===========================

Create a Swiftest Simulation object.
Create a Swiftest :class:`Simulation <swiftest.Simulation>` object.
Outputs are stored in the ``./simdata`` directory by default. ::

sim = swiftest.Simulation()

Now that we have a simulation object set up (with default parameters), we can add bodies to the simulation.
The biggest body in the simulation is taken as the central body.
The biggest body in the simulation is taken as the central body. Swiftest sets a Simulation object up with a set of default parameters,
including a default unit system of AU, y, and solar masses.

Solar System Bodies
=========================
Expand All @@ -40,16 +41,39 @@ Add other small bodies too: ::
Running the Simulation
========================

We now set up the simulation parameters. Here we have a simulation starting from `0.0 y` and running for `1 My = 1e6 years`
with time steps of `0.01 years`. ::
We now can some simulation parameters using the :func:`set_parameter <swiftest.Simulation.set_parameter>` method.
Here we have a simulation that runs for 1 My a step size of 0.01 y. We will also save the system every 1000 y and wait until the end of the simulation to write the simulation data to file using the ``dump_cadence=0`` argument ::

sim.set_parameter(tstart=0.0, tstop=1.0e6, dt=0.01)
sim.set_parameter(tstop=1.0e6, tstep_out=1e3, dt=0.01, dump_cadence=0)

Once everything is set up, we can save the simulation object and then run it: ::
Once everything is set up, we call the :func:`run <swiftest.Simulation.run>` method to integrate the system forward in time::

sim.save()
sim.run()

Swiftest is relatively flexible with arguments. You can pass the parameters in when initializing the simulation object, or even later when running.
So the following are all equivalent::

sim = swiftest.Simulation(tstop=1.0e6, tstep_out=1e3, dt=0.01, dump_cadence=0)
sim.add_solar_system_body(["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"])
sim.run()

sim = swiftest.Simulation()
sim.add_solar_system_body(["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"])
sim.set_parameter(tstop=1.0e6, tstep_out=1e3, dt=0.01, dump_cadence=0)
sim.run()

sim = swiftest.Simulation()
sim.add_solar_system_body(["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"])
sim.run(tstop=1.0e6, tstep_out=1e3, dt=0.01, dump_cadence=0)


Analayzing Simulation Output
=============================

Once a simulation has been run, its output data is stored in the ``./simdata`` directory. The main data is stored in a file with a
default name of ``data.nc``, which is a netCDF file. It is read in and stored as an `Xarray Dataset <https://docs.xarray.dev/en/stable/>`__ object in the ``sim.data`` attribute.


.. .. toctree::
.. :maxdepth: 2
.. :hidden:

0 comments on commit 8dda11f

Please sign in to comment.