N-body Cosmological Simulation
   HOME

TheInfoList



OR:

In
physics Physics is the scientific study of matter, its Elementary particle, fundamental constituents, its motion and behavior through space and time, and the related entities of energy and force. "Physical science is that department of knowledge whi ...
and
astronomy Astronomy is a natural science that studies celestial objects and the phenomena that occur in the cosmos. It uses mathematics, physics, and chemistry in order to explain their origin and their overall evolution. Objects of interest includ ...
, an ''N''-body simulation is a simulation of a
dynamical system In mathematics, a dynamical system is a system in which a Function (mathematics), function describes the time dependence of a Point (geometry), point in an ambient space, such as in a parametric curve. Examples include the mathematical models ...
of particles, usually under the influence of physical forces, such as
gravity In physics, gravity (), also known as gravitation or a gravitational interaction, is a fundamental interaction, a mutual attraction between all massive particles. On Earth, gravity takes a slightly different meaning: the observed force b ...
(see ''n''-body problem for other applications). ''N''-body simulations are widely used tools in
astrophysics Astrophysics is a science that employs the methods and principles of physics and chemistry in the study of astronomical objects and phenomena. As one of the founders of the discipline, James Keeler, said, astrophysics "seeks to ascertain the ...
, from investigating the dynamics of
few-body systems In physics, a few-body system consists of a small number of well-defined structures or point particles. It is usually in-between the two-body and the many-body systems with large ''N''. Quantum mechanics In quantum mechanics, examples of few-body ...
like the
Earth Earth is the third planet from the Sun and the only astronomical object known to Planetary habitability, harbor life. This is enabled by Earth being an ocean world, the only one in the Solar System sustaining liquid surface water. Almost all ...
-
Moon The Moon is Earth's only natural satellite. It Orbit of the Moon, orbits around Earth at Lunar distance, an average distance of (; about 30 times Earth diameter, Earth's diameter). The Moon rotation, rotates, with a rotation period (lunar ...
-
Sun The Sun is the star at the centre of the Solar System. It is a massive, nearly perfect sphere of hot plasma, heated to incandescence by nuclear fusion reactions in its core, radiating the energy from its surface mainly as visible light a ...
system to understanding the evolution of the
large-scale structure of the universe The observable universe is a spherical region of the universe consisting of all matter that can be observed from Earth; the electromagnetic radiation from these objects has had time to reach the Solar System and Earth since the beginning of th ...
. In
physical cosmology Physical cosmology is a branch of cosmology concerned with the study of cosmological models. A cosmological model, or simply cosmology, provides a description of the largest-scale structures and dynamics of the universe and allows study of fu ...
, ''N''-body simulations are used to study processes of non-linear
structure formation In physical cosmology, structure formation describes the creation of galaxies, galaxy clusters, and larger structures starting from small fluctuations in mass density resulting from processes that created matter. The universe, as is now known from ...
such as
galaxy filament In cosmology, galaxy filaments are the largest known structures in the universe, consisting of walls of galactic superclusters. These massive, thread-like formations can commonly reach 50 to 80 megaparsecs ()—with the largest found to date b ...
s and
galaxy halo A galactic halo is an extended, roughly spherical component of a galaxy which extends beyond the main, visible component. Several distinct components of a galaxy comprise its halo: * the stellar halo * the galactic corona (hot gas, i.e. a plasm ...
s from the influence of
dark matter In astronomy, dark matter is an invisible and hypothetical form of matter that does not interact with light or other electromagnetic radiation. Dark matter is implied by gravity, gravitational effects that cannot be explained by general relat ...
. Direct ''N''-body simulations are used to study the dynamical evolution of
star cluster A star cluster is a group of stars held together by self-gravitation. Two main types of star clusters can be distinguished: globular clusters, tight groups of ten thousand to millions of old stars which are gravitationally bound; and open cluster ...
s.


Nature of the particles

The 'particles' treated by the simulation may or may not correspond to physical objects which are particulate in nature. For example, an N-body simulation of a star cluster might have a particle per star, so each particle has some physical significance. On the other hand, a simulation of a gas cloud cannot afford to have a particle for each atom or molecule of gas as this would require on the order of particles for each mole of material (see
Avogadro constant The Avogadro constant, commonly denoted or , is an SI defining constant with an exact value of when expressed in reciprocal moles. It defines the ratio of the number of constituent particles to the amount of substance in a sample, where th ...
), so a single 'particle' would represent some much larger quantity of gas (often implemented using
Smoothed Particle Hydrodynamics Smoothed-particle hydrodynamics (SPH) is a computational method used for simulating the mechanics of continuum media, such as solid mechanics and fluid flows. It was developed by Gingold and Monaghan and Lucy in 1977, initially for astrophysic ...
). This quantity need not have any physical significance, but must be chosen as a compromise between accuracy and manageable computer requirements.


Dark matter simulation

Dark matter In astronomy, dark matter is an invisible and hypothetical form of matter that does not interact with light or other electromagnetic radiation. Dark matter is implied by gravity, gravitational effects that cannot be explained by general relat ...
plays an important role in the formation of galaxies. The time evolution of the density f (in phase space) of dark matter particles, can be described by the collisionless
Boltzmann equation The Boltzmann equation or Boltzmann transport equation (BTE) describes the statistical behaviour of a thermodynamic system not in a state of equilibrium; it was devised by Ludwig Boltzmann in 1872.Encyclopaedia of Physics (2nd Edition), R. G ...
\frac = \frac+ \mathbf \cdot\nabla f - \frac \cdot\nabla\Phi In the equation,\mathbf is the velocity, and Φ is the gravitational potential given by
Poisson's Equation Poisson's equation is an elliptic partial differential equation of broad utility in theoretical physics. For example, the solution to Poisson's equation is the potential field caused by a given electric charge or mass density distribution; with t ...
. These two coupled equations are solved in an expanding background Universe, which is governed by the
Friedmann equations The Friedmann equations, also known as the Friedmann–Lemaître (FL) equations, are a set of equations in physical cosmology that govern cosmic expansion in homogeneous and isotropic models of the universe within the context of general relativi ...
, after determining the initial conditions of dark matter particles. The conventional method employed for initializing positions and velocities of dark matter particles involves moving particles within a uniform Cartesian lattice or a glass-like particle configuration. This is done by using a linear theory approximation or a low-order
perturbation theory In mathematics and applied mathematics, perturbation theory comprises methods for finding an approximate solution to a problem, by starting from the exact solution of a related, simpler problem. A critical feature of the technique is a middle ...
.


Direct gravitational ''N''-body simulations

In direct gravitational ''N''-body simulations, the equations of motion of a system of ''N'' particles under the influence of their mutual gravitational forces are integrated numerically without any simplifying approximations. These calculations are used in situations where interactions between individual objects, such as stars or planets, are important to the evolution of the system. The first direct gravitational ''N''-body simulations were carried out by Erik Holmberg at the
Lund Observatory Lund Observatory was the official English name for the astronomy department at Lund University, and is currently used as a network of researchers within astronomy or other space related research projects, administered by the Department of Physics ...
in 1941, determining the forces between stars in encountering galaxies via the mathematical equivalence between light propagation and gravitational interaction: putting light bulbs at the positions of the stars and measuring the directional light fluxes at the positions of the stars by a photo cell, the equations of motion can be integrated with effort. The first purely calculational simulations were then done by
Sebastian von Hoerner Sebastian Rudolf Karl von Hoerner (15 April 1919 – 7 January 2003) was a German astrophysicist and radio astronomer. He was born in Görlitz, Lower Silesia. During WW II, Von Hoerner served in the German Army on the Eastern Front. A bullet st ...
at the
Astronomisches Rechen-Institut The Astronomical Calculation Institute (; ARI) is a research institute in Heidelberg, Germany, with origins dating back from the 1700s. Beginning in 2005, the ARI became part of the Center for Astronomy at Heidelberg University (', ). Previous ...
in
Heidelberg Heidelberg (; ; ) is the List of cities in Baden-Württemberg by population, fifth-largest city in the States of Germany, German state of Baden-Württemberg, and with a population of about 163,000, of which roughly a quarter consists of studen ...
, Germany.
Sverre Aarseth Sverre Johannes Aarseth, (20 July 1934 – 28 December 2024) was a Norwegian research scientist at the Institute of Astronomy at the University of Cambridge. Aarseth spent his retirement as an active researcher. He dedicated his career to the d ...
at the
University of Cambridge The University of Cambridge is a Public university, public collegiate university, collegiate research university in Cambridge, England. Founded in 1209, the University of Cambridge is the List of oldest universities in continuous operation, wo ...
(UK) dedicated his entire scientific life to the development of a series of highly efficient ''N''-body codes for astrophysical applications which use adaptive (hierarchical) time steps, an Ahmad-Cohen neighbour scheme and regularization of close encounters. Regularization is a mathematical trick to remove the singularity in the Newtonian law of gravitation for two particles which approach each other arbitrarily close. Sverre Aarseth's codes are used to study the dynamics of star clusters, planetary systems and galactic nuclei.


General relativity simulations

Many simulations are large enough that the effects of
general relativity General relativity, also known as the general theory of relativity, and as Einstein's theory of gravity, is the differential geometry, geometric theory of gravitation published by Albert Einstein in 1915 and is the current description of grav ...
in establishing a Friedmann-Lemaitre-Robertson-Walker cosmology are significant. This is incorporated in the simulation as an evolving measure of distance (or
scale factor In affine geometry, uniform scaling (or isotropic scaling) is a linear transformation that enlarges (increases) or shrinks (diminishes) objects by a '' scale factor'' that is the same in all directions ( isotropically). The result of uniform sc ...
) in a comoving coordinate system, which causes the particles to slow in comoving coordinates (as well as due to the
redshift In physics, a redshift is an increase in the wavelength, and corresponding decrease in the frequency and photon energy, of electromagnetic radiation (such as light). The opposite change, a decrease in wavelength and increase in frequency and e ...
ing of their physical energy). However, the contributions of general relativity and the finite
speed of gravity In classical theories of gravitation, the changes in a gravitational field propagate. A change in the distribution of energy and momentum of matter results in subsequent alteration, at a distance, of the gravitational field which it produces. In ...
can otherwise be ignored, as typical dynamical timescales are long compared to the light crossing time for the simulation, and the space-time curvature induced by the particles and the particle velocities are small. The boundary conditions of these cosmological simulations are usually periodic (or toroidal), so that one edge of the simulation volume matches up with the opposite edge.


Calculation optimizations

''N''-body simulations are simple in principle, because they involve merely integrating the 6''N''
ordinary differential equation In mathematics, an ordinary differential equation (ODE) is a differential equation (DE) dependent on only a single independent variable (mathematics), variable. As with any other DE, its unknown(s) consists of one (or more) Function (mathematic ...
s defining the particle motions in
Newtonian gravity Newton's law of universal gravitation describes gravity as a force by stating that every particle attracts every other particle in the universe with a force that is proportional to the product of their masses and inversely proportional to the sq ...
. In practice, the number ''N'' of particles involved is usually very large (typical simulations include many millions, the
Millennium simulation The Millennium Run, or Millennium Simulation (referring to its size ) is a computer N-body simulation used to investigate how the distribution of matter in the Universe has evolved over time, in particular, how the observed population of galaxies ...
included ten billion) and the number of particle-particle interactions needing to be computed increases on the order of ''N''2, and so direct integration of the differential equations can be prohibitively computationally expensive. Therefore, a number of refinements are commonly used. Numerical integration is usually performed over small timesteps using a method such as
leapfrog integration In numerical analysis, leapfrog integration is a method for numerically integrating differential equations of the form \ddot x = \frac = A(x), or equivalently of the form \dot v = \frac = A(x), \qquad \dot x = \frac = v, particularly in the case ...
. However all numerical integration leads to errors. Smaller steps give lower errors but run more slowly. Leapfrog integration is roughly 2nd order on the timestep, other integrators such as
Runge–Kutta methods In numerical analysis, the Runge–Kutta methods ( ) are a family of Explicit and implicit methods, implicit and explicit iterative methods, List of Runge–Kutta methods, which include the Euler method, used in temporal discretization for the a ...
can have 4th order accuracy or much higher. One of the simplest refinements is that each particle carries with it its own timestep variable, so that particles with widely different dynamical times don't all have to be evolved forward at the rate of that with the shortest time. There are two basic approximation schemes to decrease the computational time for such simulations. These can reduce the
computational complexity In computer science, the computational complexity or simply complexity of an algorithm is the amount of resources required to run it. Particular focus is given to computation time (generally measured by the number of needed elementary operations ...
to O(N log N) or better, at the loss of accuracy.


Tree methods

In tree methods, such as a
Barnes–Hut simulation The Barnes–Hut simulation (named after Joshua Barnes and Piet Hut) is an approximation algorithm for performing an N-body simulation. It is notable for having Big O notation, order O(''n'' log ''n'') compared to a direct-sum algorithm ...
, an
octree An octree is a tree data structure in which each internal node has exactly eight child node, children. Octrees are most often used to partition a three-dimensional space by recursive subdivision, recursively subdividing it into eight Octant (geo ...
is usually used to divide the volume into cubic cells and only interactions between particles from nearby cells need to be treated individually; particles in distant cells can be treated collectively as a single large particle centered at the distant cell's center of mass (or as a low-order
multipole A multipole expansion is a mathematical series representing a function that depends on angles—usually the two angles used in the spherical coordinate system (the polar and azimuthal angles) for three-dimensional Euclidean space, \R^3. Multipol ...
expansion). This can dramatically reduce the number of particle pair interactions that must be computed. To prevent the simulation from becoming swamped by computing particle-particle interactions, the cells must be refined to smaller cells in denser parts of the simulation which contain many particles per cell. For simulations where particles are not evenly distributed, the
well-separated pair decomposition In computational geometry, a well-separated pair decomposition (WSPD) of a set of points S \subset \mathbb^d, is a sequence of pairs of sets (A_i, B_i), such that each pair is well-separated, and for each two distinct points p, q \in S, there exist ...
methods of Callahan and
Kosaraju Kosaraju Raghavayya (23 June 1905 – 27 October 1987), known mononumously by his surname Kosaraju, was an Indian lyricist and poet known for his works in Telugu cinema. He wrote about 3,000 songs in 350 films. His lyrics are steeped in Telug ...
yield optimal O(''n'' log ''n'') time per iteration with fixed dimension.


Particle mesh method

Another possibility is the particle mesh method in which space is discretised on a mesh and, for the purposes of computing the
gravitational potential In classical mechanics, the gravitational potential is a scalar potential associating with each point in space the work (energy transferred) per unit mass that would be needed to move an object to that point from a fixed reference point in the ...
, particles are assumed to be divided between the surrounding 2x2 vertices of the mesh. The potential energy Φ can be found with the
Poisson equation Poisson's equation is an elliptic partial differential equation of broad utility in theoretical physics. For example, the solution to Poisson's equation is the potential field caused by a given electric charge or mass density distribution; with th ...
\nabla^2\Phi=4\pi G,\, where ''G'' is
Newton's constant The gravitational constant is an empirical physical constant involved in the calculation of gravitational effects in Sir Isaac Newton's law of universal gravitation and in Albert Einstein's theory of general relativity. It is also known as t ...
and \rho is the density (number of particles at the mesh points). The
fast Fourier transform A fast Fourier transform (FFT) is an algorithm that computes the discrete Fourier transform (DFT) of a sequence, or its inverse (IDFT). A Fourier transform converts a signal from its original domain (often time or space) to a representation in ...
can solve this efficiently by going to the
frequency domain In mathematics, physics, electronics, control systems engineering, and statistics, the frequency domain refers to the analysis of mathematical functions or signals with respect to frequency (and possibly phase), rather than time, as in time ser ...
where the Poisson equation has the simple form \hat= -4\pi G\frac, where \vec is the comoving wavenumber and the hats denote Fourier transforms. Since \vec = -\vec\Phi, the gravitational field can now be found by multiplying by -i\vec and computing the inverse Fourier transform (or computing the inverse transform and then using some other method). Since this method is limited by the mesh size, in practice a smaller mesh or some other technique (such as combining with a tree or simple particle-particle algorithm) is used to compute the small-scale forces. Sometimes an adaptive mesh is used, in which the mesh cells are much smaller in the denser regions of the simulation.


Special-case optimizations

Several different
gravitational perturbation In astronomy, perturbation is the complex motion of a massive body subjected to forces other than the gravitational attraction of a single other massive body. The other forces can include a third (fourth, fifth, etc.) body, resistance, as fro ...
algorithms are used to get fairly accurate estimates of the path of objects in the
Solar System The Solar SystemCapitalization of the name varies. The International Astronomical Union, the authoritative body regarding astronomical nomenclature, specifies capitalizing the names of all individual astronomical objects but uses mixed "Sola ...
. People often decide to put a satellite in a
frozen orbit In orbital mechanics, a frozen orbit is an orbit for an artificial satellite in which perturbations have been minimized by careful selection of the orbital parameters. Perturbations can result from natural drifting due to the central body's shap ...
. The path of a satellite closely orbiting the Earth can be accurately modeled starting from the 2-body elliptical orbit around the center of the Earth, and adding small corrections due to the oblateness of the Earth, gravitational attraction of the Sun and Moon, atmospheric drag, etc. It is possible to find a frozen orbit without calculating the actual path of the satellite. The path of a small planet, comet, or long-range spacecraft can often be accurately modeled starting from the 2-body elliptical orbit around the Sun, and adding small corrections from the gravitational attraction of the larger planets in their known orbits. Some characteristics of the long-term paths of a system of particles can be calculated directly. The actual path of any particular particle does not need to be calculated as an intermediate step. Such characteristics include
Lyapunov stability Various types of stability may be discussed for the solutions of differential equations or difference equations describing dynamical systems. The most important type is that concerning the stability of solutions near to a point of equilibrium. ...
,
Lyapunov time In mathematics, the Lyapunov time is the characteristic timescale on which a dynamical system is chaotic. It is named after the Russian mathematician Aleksandr Lyapunov. It is defined as the inverse of a system's largest Lyapunov exponent. Use T ...
, various measurements from
ergodic theory Ergodic theory is a branch of mathematics that studies statistical properties of deterministic dynamical systems; it is the study of ergodicity. In this context, "statistical properties" refers to properties which are expressed through the behav ...
, etc.


Two-particle systems

Although there are millions or billions of particles in typical simulations, they typically correspond to a real particle with a very large mass, typically 109
solar mass The solar mass () is a frequently used unit of mass in astronomy, equal to approximately . It is approximately equal to the mass of the Sun. It is often used to indicate the masses of other stars, as well as stellar clusters, nebulae, galaxie ...
es. This can introduce problems with short-range interactions between the particles such as the formation of two-particle
binary Binary may refer to: Science and technology Mathematics * Binary number, a representation of numbers using only two values (0 and 1) for each digit * Binary function, a function that takes two arguments * Binary operation, a mathematical op ...
systems. As the particles are meant to represent large numbers of dark matter particles or groups of stars, these binaries are unphysical. To prevent this, a softened Newtonian force law is used, which does not diverge as the inverse-square radius at short distances. Most simulations implement this quite naturally by running the simulations on cells of finite size. It is important to implement the discretization procedure in such a way that particles always exert a vanishing force on themselves.


Softening

Softening is a numerical trick used in N-body techniques to prevent numerical
divergence In vector calculus, divergence is a vector operator that operates on a vector field, producing a scalar field giving the rate that the vector field alters the volume in an infinitesimal neighborhood of each point. (In 2D this "volume" refers to ...
s when a particle comes too close to another (and the
force In physics, a force is an influence that can cause an Physical object, object to change its velocity unless counterbalanced by other forces. In mechanics, force makes ideas like 'pushing' or 'pulling' mathematically precise. Because the Magnitu ...
goes to infinity). This is obtained by modifying the regularized
gravitational potential In classical mechanics, the gravitational potential is a scalar potential associating with each point in space the work (energy transferred) per unit mass that would be needed to move an object to that point from a fixed reference point in the ...
of each particle as \Phi = - \frac, (rather than 1/r) where \epsilon is the softening parameter. The value of the softening parameter should be set small enough to keep
simulation A simulation is an imitative representation of a process or system that could exist in the real world. In this broad sense, simulation can often be used interchangeably with model. Sometimes a clear distinction between the two terms is made, in ...
s realistic.


Results from ''N''-body simulations

''N''-body simulations give findings on the large-scale dark matter distribution and the structure of dark matter halos. According to simulations of cold dark matter, the overall distribution of dark matter on a large scale is not entirely uniform. Instead, it displays a structure resembling a network, consisting of voids, walls, filaments, and halos. Also, simulations show that the relationship between the concentration of halos and factors such as mass, initial fluctuation spectrum, and cosmological parameters is linked to the actual formation time of the halos. In particular, halos with lower mass tend to form earlier, and as a result, have higher concentrations due to the higher density of the Universe at the time of their formation. Shapes of halos are found to deviate from being perfectly spherical. Typically, halos are found to be elongated and become increasingly prolate towards their centers. However, interactions between dark matter and
baryons In particle physics, a baryon is a type of composite subatomic particle that contains an odd number of valence quarks, conventionally three. Protons and neutrons are examples of baryons; because baryons are composed of quarks, they belong to ...
would affect the internal structure of dark matter halos. Simulations that model both dark matters and baryons are needed to study small-scale structures.


Incorporating baryons, leptons and photons into simulations

Many simulations simulate only
cold dark matter In cosmology and physics, cold dark matter (CDM) is a hypothetical type of dark matter. According to the current standard model of cosmology, Lambda-CDM model, approximately 27% of the universe is dark matter and 68% is dark energy, with only a sm ...
, and thus include only the gravitational force. Incorporating
baryon In particle physics, a baryon is a type of composite particle, composite subatomic particle that contains an odd number of valence quarks, conventionally three. proton, Protons and neutron, neutrons are examples of baryons; because baryons are ...
s,
lepton In particle physics, a lepton is an elementary particle of half-integer spin (Spin (physics), spin ) that does not undergo strong interactions. Two main classes of leptons exist: electric charge, charged leptons (also known as the electron-li ...
s and
photon A photon () is an elementary particle that is a quantum of the electromagnetic field, including electromagnetic radiation such as light and radio waves, and the force carrier for the electromagnetic force. Photons are massless particles that can ...
s into the simulations dramatically increases their complexity and often radical simplifications of the underlying physics must be made. However, this is an extremely important area and many modern simulations are now trying to understand processes that occur during
galaxy formation In cosmology, the study of galaxy formation and evolution is concerned with the processes that formed a Homogeneity and heterogeneity, heterogeneous universe from a Big Bang, homogeneous beginning, the formation of the first galaxies, the way ga ...
which could account for galaxy bias.


Computational complexity

Reif and Tate prove that if the ''n''-body reachability problem is defined as follows – given ''n'' bodies satisfying a fixed electrostatic potential law, determining if a body reaches a destination ball in a given time bound where we require a poly(''n'') bits of accuracy and the target time is poly(''n'') is in
PSPACE In computational complexity theory, PSPACE is the set of all decision problems that can be solved by a Turing machine using a polynomial amount of space. Formal definition If we denote by SPACE(''f''(''n'')), the set of all problems that can ...
. On the other hand, if the question is whether the body ''eventually'' reaches the destination ball, the problem is PSPACE-hard. These bounds are based on similar complexity bounds obtained for ray tracing.


Example simulations


Common boilerplate code

The simplest implementation of N-body simulations where n\geq 3 is a naive propagation of orbiting bodies; naive implying that the only forces acting on the orbiting bodies is the gravitational force which they exert on each other. In
object-oriented programming Object-oriented programming (OOP) is a programming paradigm based on the concept of '' objects''. Objects can contain data (called fields, attributes or properties) and have actions they can perform (called procedures or methods and impl ...
languages, such as
C++ C++ (, pronounced "C plus plus" and sometimes abbreviated as CPP or CXX) is a high-level, general-purpose programming language created by Danish computer scientist Bjarne Stroustrup. First released in 1985 as an extension of the C programmin ...
, some
boilerplate code In computer programming, boilerplate code, or simply boilerplate, are sections of code that are repeated in multiple places with little to no variation. When using languages that are considered ''verbose'', the programmer must write a lot of boile ...
is useful for establishing the fundamental mathematical structures as well as data containers required for propagation; namely state vectors, and thus vectors, and some fundamental object containing this data, as well as the mass of an orbiting body. This method is applicable to other types of N-body simulations as well; a simulation of point masses with charges would use a similar method, however the force would be due to attraction or repulsion by interaction of electric fields. Regardless, acceleration of particle is a result of summed force vectors, divided by the mass of the particle: \vec = \frac \sum\vec An example of a programmatically stable and
scalable Scalability is the property of a system to handle a growing amount of work. One definition for software systems specifies that this may be done by adding resources to the system. In an economic context, a scalable business model implies that ...
method for containing kinematic data for a particle is the use of fixed length arrays, which in optimised code allows for easy memory allocation and prediction of consumed resources; as seen in the following C++ code: struct Vector3 ; struct OrbitalEntity ; Note that contains enough room for a state vector, where: *e_ = x, the projection of the objects position vector in Cartesian space along \left \;0\;0\right/math> *e_ = y, the projection of the objects position vector in Cartesian space along \left \;1\;0\right/math> *e_ = z, the projection of the objects position vector in Cartesian space along \left \;0\;1\right/math> *e_ = \dot, the projection of the objects velocity vector in Cartesian space along \left \;0\;0\right/math> *e_ = \dot, the projection of the objects velocity vector in Cartesian space along \left \;1\;0\right/math> *e_ = \dot, the projection of the objects velocity vector in Cartesian space along \left \;0\;1\right/math> Additionally, contains enough room for a mass value.


Initialisation of simulation parameters

Commonly, N-body simulations will be systems based on some type of
equations of motion In physics, equations of motion are equations that describe the behavior of a physical system in terms of its motion as a function of time. More specifically, the equations of motion describe the behavior of a physical system as a set of mathem ...
; of these, most will be dependent on some initial configuration to "seed" the simulation. In systems such as those dependent on some gravitational or electric potential, the force on a simulation entity is independent on its velocity. Hence, to seed the ''forces'' of the simulation, merely initial positions are needed, but this will not allow propagation- initial velocities are required. Consider a planet orbiting a star- it has no motion, but is subject to gravitational attraction to its host star. As a time progresses, and time ''steps'' are added, it will gather velocity according to its acceleration. For a given instant in time, t_, the resultant acceleration of a body due to its neighbouring masses is independent of its velocity, however, for the time step t_, the resulting change in position is significantly different due the propagation's inherent dependency on velocity. In basic propagation mechanisms, such as the symplectic euler method to be used below, the position of an object at t_ is only dependent on its velocity at t_, as the shift in position is calculated via \vec_=\vec_+\vec_ \cdot \Delta t Without acceleration, \vec_ is static, however, from the perspective of an observer seeing only position, it will take two time steps to see a change in velocity. A solar-system-like simulation can be accomplished by taking average distances of planet equivalent point masses from a central star. To keep code simple, a non-rigorous approach based on semi-major axes and mean velocities will be used. Memory space for these bodies must be reserved before the bodies are configured; to allow for scalability, a
malloc C dynamic memory allocation refers to performing manual memory management for dynamic memory allocation in the C programming language via a group of functions in the C standard library, namely , , , and . The C++ programming language includ ...
command may be used: OrbitalEntity* orbital_entities = malloc(sizeof(OrbitalEntity) * (9 + N_ASTEROIDS)); orbital_entities = ; // a star similar to the sun orbital_entities = ; // a planet similar to mercury orbital_entities = ; // a planet similar to venus orbital_entities = ; // a planet similar to earth orbital_entities = ; // a planet similar to mars orbital_entities = ; // a planet similar to jupiter orbital_entities = ; // a planet similar to saturn orbital_entities = ; // a planet similar to uranus orbital_entities = ; // a planet similar to neptune where is a variable which will remain at 0 temporarily, but allows for future inclusion of significant numbers of asteroids, at the users discretion. A critical step for the configuration of simulations is to establish the time ranges of the simulation, t_ to t_\text, as well as the incremental time step dt which will progress the simulation forward: double t_0 = 0; double t = t_0; double dt = 86400; double t_end = 86400 * 365 * 10; // approximately a decade in seconds double BIG_G = 6.67e-11; // gravitational constant The positions and velocities established above are interpreted to be correct for t = t_. The extent of a simulation would logically be for the period where t_\leq t < t_\text.


Propagation

An entire simulation can consist of hundreds, thousands, millions, billions, or sometimes trillions of time steps. At the elementary level, each time step (for simulations with particles moving due to forces exerted on them) involves * calculating the forces on each body * calculating the accelerations of each body (\vec) * calculating the velocities of each body (\vec_ = \vec_ + \vec_ \cdot \Delta t * calculating the new position of each body (\vec_ = \vec_ + \vec_ \cdot \Delta t The above can be implemented quite simply with a
while loop In most computer programming languages, a while loop is a control flow Statement (computer science), statement that allows code to be executed repeatedly based on a given Boolean data type, Boolean condition. The ''while'' loop can be thought o ...
which continues while t exists in the aforementioned range: while (t < t_end) Focusing on the inner four
rocky planet A terrestrial planet, tellurian planet, telluric planet, or rocky planet, is a planet that is composed primarily of silicate, rocks or metals. Within the Solar System, the terrestrial planets accepted by the IAU are the inner planets closest to ...
s in the simulation, the trajectories resulting from the above propagation is shown below:


See also

* * * * * * * *


References


Further reading

* * * * * *. {{Numerical integrators Physical cosmology Gravity Simulation Cosmological simulation Articles containing video clips Computational physics Particles