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

Commit

Permalink
Added example data output
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Mar 1, 2024
1 parent 488afb8 commit d7393ed
Showing 1 changed file with 61 additions and 4 deletions.
65 changes: 61 additions & 4 deletions docs/user-guide/basic-simulation/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ file. The default value is 10, which means that Swiftest will store 10 outputs i
Setting ``dump_cadence`` to 0 is a a special case that tells Swiftest to store *all* output in memory until the end of the
simulation. This is useful for short simulations, but can be memory intensive for long simulations.

.. note::
Changing the value of ``dump_cadence`` does not change the amount of data that is output by the end of the simulation. It only
changes how often the data is written to disk. Changing the value of ``tstep_out`` (or ``istep_out``) *does* change the amount of
data that is output by the end of the simulation. Intermediate steps between output steps are not saved to disk, and cannot be
recovered after the simulation has finished.

The choice of what values to set for ``tstep_out`` (or ``istep_out``), ``nstep_out``, and ``dump_cadence`` depends on the particular
simulation. Higher values of ``dump_cadence`` are typically useful for simulations with small numbers of bodies and small values
of ```tstep_out`` where frequent writing to disk can severely impact performance. For simulations with large numbers of bodies and
Expand All @@ -87,10 +93,10 @@ so that the memory usage does not become too large. The default value of ``dump_
caes.

We can set these 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
Here we have a simulation that runs for 100,000 y 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(tstop=1.0e6, tstep_out=1e3, dt=0.01, dump_cadence=0)
sim.set_parameter(tstop=1.0e5, tstep_out=1e3, dt=0.01, dump_cadence=0)

Once everything is set up, we call the :func:`run <swiftest.Simulation.run>` method to integrate the system forward in time::

Expand All @@ -99,7 +105,7 @@ Once everything is set up, we call the :func:`run <swiftest.Simulation.run>` met
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 = swiftest.Simulation(tstop=1.0e5, 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()

Expand All @@ -110,7 +116,7 @@ So the following are all equivalent::

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)
sim.run(tstop=1.0e5, tstep_out=1e3, dt=0.01, dump_cadence=0)

.. note::
Swiftest uses OpenMP parallelization to help speed up the integration, however the parallelization is most effective when there
Expand All @@ -131,6 +137,57 @@ Once a simulation has been run, its output data is stored in the ``./simdata`` d
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.

Here is an example of what the dataset looks like after the above simulation has been run::

In [8]: sim.data
Out[8]:
<xarray.Dataset> Size: 229kB

Dimensions: (time: 101, space: 3, name: 9)
Coordinates:
* time (time) float64 808B 0.0 1e+03 2e+03 ... 9.9e+04 1e+05
* space (space) <U1 12B 'x' 'y' 'z'
* name (name) <U32 1kB 'Sun' 'Mercury' ... 'Uranus' 'Neptune'
Data variables:
id (name) int64 72B 0 1 2 3 4 5 6 7 8
status (time, name) int64 7kB 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0
npl (time) int64 808B 8 8 8 8 8 8 8 8 8 8 ... 8 8 8 8 8 8 8 8 8
ntp (time) int64 808B 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0
nplm (time) int64 808B 8 8 8 8 8 8 8 8 8 8 ... 8 8 8 8 8 8 8 8 8
particle_type (name) <U32 1kB 'Central Body' ... 'Massive Body'
rh (time, name, space) float64 22kB nan nan ... -15.76 -0.4033
vh (time, name, space) float64 22kB nan nan ... -0.03418
gr_pseudo_vh (time, name, space) float64 22kB nan nan ... -0.03418
a (time, name) float64 7kB nan 0.3871 0.7233 ... 19.16 30.17
e (time, name) float64 7kB nan 0.2056 ... 0.03379 0.008614
inc (time, name) float64 7kB nan 7.003 3.394 ... 1.306 1.884
capom (time, name) float64 7kB nan 48.3 76.6 ... 150.3 124.7
omega (time, name) float64 7kB nan 29.2 54.96 ... 135.7 310.1
capm (time, name) float64 7kB nan 338.3 200.5 ... 212.3 254.7
varpi (time, name) float64 7kB nan 77.5 131.6 ... 286.0 74.82
lam (time, name) float64 7kB nan 55.84 332.0 ... 138.3 329.5
f (time, name) float64 7kB nan 327.0 200.2 ... 210.3 253.8
cape (time, name) float64 7kB nan 333.0 200.3 ... 211.3 254.3
Gmass (time, name) float64 7kB 39.48 6.554e-06 ... 0.002033
mass (time, name) float64 7kB 1.0 1.66e-07 ... 5.15e-05
rhill (time, name) float64 7kB nan nan nan nan ... nan nan nan
radius (time, name) float64 7kB 0.00465 1.631e-05 ... 0.0001646
origin_time (name) float64 72B 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
origin_type (name) <U32 1kB 'Initial conditions' ... 'Initial condit...
origin_rh (name, space) float64 216B 0.0 0.0 0.0 ... 2.045 -0.7287
origin_vh (name, space) float64 216B 0.0 0.0 0.0 ... 1.149 -0.02168
collision_id (name) int64 72B 0 0 0 0 0 0 0 0 0
discard_time (name) float64 72B 0.0 1.798e+308 ... 1.798e+308 1.798e+308
discard_rh (name, space) float64 216B 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0
discard_vh (name, space) float64 216B 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0
discard_body_id (name) int64 72B -2147483647 -2147483647 ... -2147483647
Ip (time, name, space) float64 22kB 0.0 0.0 0.07 ... 0.0 0.23
rot (time, name, space) float64 22kB 642.2 ... 1.721e+05
rotphase (time) float64 808B 0.0 281.4 197.1 ... 176.4 126.8 344.4
j2rp2 (time) float64 808B 4.754e-12 4.754e-12 ... 4.754e-12
j4rp4 (time) float64 808B -2.247e-18 -2.247e-18 ... -2.247e-18



.. toctree::
.. :maxdepth: 2
Expand Down

0 comments on commit d7393ed

Please sign in to comment.