View source: R/run.simulation.R
run.simulation | R Documentation |
Run direct N-body simulations using an adaptive block timestep.
run.simulation(sim, measure.time = TRUE, verbose = TRUE)
sim |
structured list of simulation settings, which must contain the following sublists:
|
measure.time |
logical flag that determines whether time computation time will be measured and displayed. |
verbose |
logical flag indicating whether to show console outputs from external codes. Ignored when using the in-built simulator. |
UNITS: The initial conditions (in the sublist ics
) can be provided in any units. The units of mass, length and velocity then fix the other units.
For instance, [unit of time in seconds] = [unit of length in meters] / [unit of velocity in m/s]. E.g., if initial positions are given in units of 1AU=1.49598e11m and velocities in units of 1km/s, one unit of time is 1.49598e8s=4.74yrs.
Likewise, units of the gravitational constant G
are given via [unit of G in m^3*kg^(-1)*s^(-2)] = [unit of length in meters] * [unit of velocity in m/s]^2 / [unit of mass in kg]. E.g., for length units of 1AU=1.49598e11m, velocity units of 1km/s=1e3m/s and mass units of 1Msun=1.98847e30kg, a unit of G is
7.523272e-14 m^3*kg^(-1)*s^(-2). In these units the true value of G is about 887.154.
NBODYX simulator:
Can be downloaded from github via
git clone https://github.com/obreschkow/nbodyx
Details on installing, compiling and running the code are given in the README file.
Note: To run very high-accuracy simulations, such as the Pythagorean three-body problem, you can use 128-bit floating-point numbers by compiling the code as
make kind=16
GADGET-4 simulator:
This his a very powerful N-body+SPH simulator used primarily for large astrophysical simulations. GADGET-4 is not particularly suitable for small direct N-body problems, but it can nonetheless be used for such simulations for the sake of comparison, at least if not too much accuracy is needed and if a massively increased computational overhead is acceptable.
Please refer to https://wwwmpa.mpa-garching.mpg.de/gadget4 for details on how to download and compile the code. In order to use GADGET-4 with this R-package, it must be compiled with the following compile-time options (in the file Config.sh):
NTYPES=2
GADGET2_HEADER
SELFGRAVITY
ALLOW_DIRECT_SUMMATION
HIERARCHICAL_GRAVITY
DOUBLEPRECISION=1
ENLARGE_DYNAMIC_RANGE_IN_TIME
If and only if periodic boundary conditions are used, you also need to add the option
PERIODIC
If you plan to often switch between runs with open and periodic boundaries, it may be advisable to compile two versions of GADGET-4, with and without this option. To do so, one needs to create two sub-directories with the respective Config.sh files and compile them via
make -j [number of cores] DIR=[path containing Config.sh with PERIODIC]
make -j [number of cores] DIR=[path containing Config.sh without PERIODIC]
The runtime parameter file (param.txt) needed by GADGET-4 is written automatically when calling run.simulation
. The gravitational softening length in GADGET-4 is computed as sim$para$rsmooth/2.8, which ensures that the particles behave like point masses at separations beyond sim$para$rsmooth. If rsmooth is not provided, it is computed as stats::sd(apply(sim$ics$x,2,sd))*1e-5
. The accuracy parameter ErrTolIntAccuracy is set equal to sim$para$eta/sim$para$rsmooth*1e-3, which gives roughly comparable accuracy to in-built simulator for the Leapfrog integrator.
The routine returns the structured list of the input argument, with one sublist output
added. This sublist contains the items:
t |
k-vector with the simulation times of the k snapshots. |
x |
k-by-N-by-3 array giving the 3D coordinates of the N particles in k snapshots. |
v |
k-by-N-by-3 array giving the 3D velocities of the N particles in k snapshots. |
n.snapshots |
total number of snapshots. |
n.iterations |
total number of iterations used to run the simulation. |
Danail Obreschkow
sim = setup.halley()
sim = run.simulation(sim)
AU = 149597870700 # Astronomical unit in meters
plot(sim, units=AU, xlim=c(-20,60), ylim=c(-40,40), xlab='[AU]', ylab='[AU]')
cat(sprintf('This simulation was run with %d iterations.\n',sim$output$n.iterations))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.