The PySpace Framework¶
This document is an introduction to the design of PySpace. This provides high level details on the functionality of PySpace. This should allow the user to use the module and extend it effectively.
To understand the framework, we will work through a general N-body problem.
Here we will be using the BruteForceSimulator
, however the framework
is essentially the same for any Simulator
.
N-body problem¶
Consider a problem of \(n\) bodies with mass \(m_i\) for the \(i^{th}\) planet.
Equations¶
Handling collisions¶
From the above equation, it is clear that force will become infinite when \(r_{ij} = 0\)
To solve this problem we use a gravity softening method proposed by Aarseth in 1963. Thus we change our force equation to
where \(\epsilon\) is the softening factor. By default, \(\epsilon = 0\)
Numerical Integration¶
BruteForceSimulator
uses leap frog integrator for updating velocity and positions of planets.
Understanding the framework¶
PySpace uses pyspace.planet.PlanetArray
for storing planets.
pyspace.planet.PlanetArray
stores numpy arrays for \(x, y, z, v_x, v_y, v_z, a_x, a_y, a_z, m, r\).
cdef public ndarray x
cdef public ndarray y
cdef public ndarray z
cdef public ndarray v_x
cdef public ndarray v_y
cdef public ndarray v_z
cdef public ndarray a_x
cdef public ndarray a_y
cdef public ndarray a_z
cdef public ndarray m
cdef public ndarray r
Note
Currently r
doesn’t have any use per se. However, we plan to use it
for better collision handling in the future.
pyspace.simulator.Simulator
stores pointers to these numpy arrays and then passes these raw pointers
to the C++ function, brute_force_update
which then updates the pointers using the above numerical integration scheme.
Algorithms¶
A number of techniques for solving the N-body problem are available. Following are currently implemented in PySpace.
Brute Force¶
This is implemented in pyspace.simulator.BruteForceSimulator
which uses
the \(O(n^2)\) brute force algorithm for calculating forces in a planet.
Visualization¶
PySpace dumps a vtk output of the simulations. These can then be visualized using tools such as Paraview, MayaVi, etc.
The vtk dump is controlled by the dump_output
flag in Simulator::simulate
.
The vtk dump by default only dumps \(v_x, v_y, v_z\) ie. velocities
of the planets.
For dumping custom data, use set_data
in pyspace.simulator.Simulator
.