Skip to content

Commit d6c6459

Browse files
committed
some more clarification
1 parent c08e0ea commit d6c6459

File tree

3 files changed

+66
-13
lines changed

3 files changed

+66
-13
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# 2D PM n-body code for cosmology
2+
[![Entangled badge](https://img.shields.io/badge/entangled-Use%20the%20source!-%2300aeff)](https://entangled.github.io/)
23

34
## Install
45
This code has the following dependencies:

docs/index.html

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
by <i>Johan Hidding</i></span></a>
100100
<div class="collapse navbar-collapse" id="navbarSupportedContent">
101101
<ul>
102+
<li><a href="#code-structure">Code structure</a></li>
102103
<li><a href="#the-box">The Box</a></li>
103104
<li><a href="#cosmology">Cosmology</a></li>
104105
<li><a href="#mass-deposition">Mass deposition</a></li>
@@ -117,18 +118,43 @@
117118
-->
118119

119120
<main role="main" class="flex-fill"><div class="container my-5">
120-
<p>This is a particle-mesh n-body code for cosmological n-body simulations. This code has several uses. For many methods of analysis in cosmology it can be very helpful to have a 2D sample available to test them with. This code is very nice to play around with for students, since it is written in 100% Python. Lastly, having 2D simulations can give a great deal of insight.</p>
121+
<p>This is a particle-mesh n-body code for cosmological n-body simulations. This code has several uses.</p>
122+
<ul>
123+
<li>Testing new methods: For many methods of analysis in cosmology it can be very helpful to have a 2D sample available to test them with.</li>
124+
<li>Teaching: This code is very nice to play around with for students, since it is written in 100% Python.</li>
125+
<li>Learning: Lastly, having 2D simulations can give a great deal of insight.</li>
126+
</ul>
127+
<p>To run the code, you need to have installed:</p>
128+
<ul>
129+
<li>Python 3.8</li>
130+
<li>Numpy</li>
131+
<li>Scipy</li>
132+
<li>Gnuplot</li>
133+
</ul>
134+
<p>Run with:</p>
135+
<pre><code>python -m nbody.nbody</code></pre>
136+
<h1 id="code-structure">Code structure</h1>
137+
<p>The code is structured in the following components:</p>
138+
<ul>
139+
<li>Cosmology: we need to know Hubble factor <span class="math inline">\(H\)</span> as a function of the expansion factor <span class="math inline">\(a\)</span>.</li>
140+
<li>Mass deposition: PM codes need a way to convert from particles to a grid representation of the density.</li>
141+
<li>Interpolation: Then we need to go back and interpolate grid quantities on particle coordinates.</li>
142+
<li>Integrator: Cosmic structure formation is described by a Hamiltonian system of equations: we need to solve these, in this case using the Leap-frog method.</li>
143+
<li>Solver: To solve the Poisson equation, we need to integrate the density in Fourier space to obtain the potential.</li>
144+
<li>Initialization: The simulation is started using the Zeldovich Approximation.</li>
145+
<li>Main: glue everything together.</li>
146+
</ul>
121147
<div class="annotated-code">
122148
<p><span><em>«nbody/nbody.py»=</em></span></p>
123-
<div class="sourceCode" id="cb1" data-file="nbody/nbody.py"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true"></a><span class="op">&lt;&lt;</span>imports<span class="op">&gt;&gt;</span></span>
124-
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true"></a></span>
125-
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true"></a><span class="op">&lt;&lt;</span>cosmology<span class="op">&gt;&gt;</span></span>
126-
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true"></a><span class="op">&lt;&lt;</span>mass<span class="op">-</span>deposition<span class="op">&gt;&gt;</span></span>
127-
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true"></a><span class="op">&lt;&lt;</span>interpolation<span class="op">&gt;&gt;</span></span>
128-
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true"></a><span class="op">&lt;&lt;</span>integrator<span class="op">&gt;&gt;</span></span>
129-
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true"></a><span class="op">&lt;&lt;</span>solver<span class="op">&gt;&gt;</span></span>
130-
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true"></a><span class="op">&lt;&lt;</span>initialization<span class="op">&gt;&gt;</span></span>
131-
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true"></a><span class="op">&lt;&lt;</span>main<span class="op">&gt;&gt;</span></span></code></pre></div>
149+
<div class="sourceCode" id="cb2" data-file="nbody/nbody.py"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true"></a><span class="op">&lt;&lt;</span>imports<span class="op">&gt;&gt;</span></span>
150+
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true"></a></span>
151+
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true"></a><span class="op">&lt;&lt;</span>cosmology<span class="op">&gt;&gt;</span></span>
152+
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true"></a><span class="op">&lt;&lt;</span>mass<span class="op">-</span>deposition<span class="op">&gt;&gt;</span></span>
153+
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true"></a><span class="op">&lt;&lt;</span>interpolation<span class="op">&gt;&gt;</span></span>
154+
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true"></a><span class="op">&lt;&lt;</span>integrator<span class="op">&gt;&gt;</span></span>
155+
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true"></a><span class="op">&lt;&lt;</span>solver<span class="op">&gt;&gt;</span></span>
156+
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true"></a><span class="op">&lt;&lt;</span>initialization<span class="op">&gt;&gt;</span></span>
157+
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true"></a><span class="op">&lt;&lt;</span>main<span class="op">&gt;&gt;</span></span></code></pre></div>
132158
</div>
133159
<p>Some things we will definitely need:</p>
134160
<div class="annotated-code">
@@ -166,7 +192,7 @@ <h1 id="cosmology">Cosmology</h1>
166192
<span id="cosmology-methods-2"><a href="#cosmology-methods-2" aria-hidden="true"></a><span class="kw">def</span> OmegaK(<span class="va">self</span>):</span>
167193
<span id="cosmology-methods-3"><a href="#cosmology-methods-3" aria-hidden="true"></a> <span class="cf">return</span> <span class="dv">1</span> <span class="op">-</span> <span class="va">self</span>.OmegaM <span class="op">-</span> <span class="va">self</span>.OmegaL</span></code></pre></div>
168194
</div>
169-
<p>and the gravitational constant,</p>
195+
<p>and the (a?) gravitational constant,</p>
170196
<p><span class="math display">\[G = \frac{3}{2} \Omega_{m} H_0^2.\]</span>{#eq:grav-const}</p>
171197
<div class="annotated-code">
172198
<p><span><em>«cosmology-methods»+</em></span></p>

lit/index.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,33 @@ title: 2D particle-mesh n-body code
33
author: Johan Hidding
44
---
55

6-
This is a particle-mesh n-body code for cosmological n-body simulations. This code has several uses. For many methods of analysis in cosmology it can be very helpful to have a 2D sample available to test them with. This code is very nice to play around with for students, since it is written in 100% Python. Lastly, having 2D simulations can give a great deal of insight.
6+
This is a particle-mesh n-body code for cosmological n-body simulations. This code has several uses.
7+
8+
- Testing new methods: For many methods of analysis in cosmology it can be very helpful to have a 2D sample available to test them with.
9+
- Teaching: This code is very nice to play around with for students, since it is written in 100% Python.
10+
- Learning: Lastly, having 2D simulations can give a great deal of insight.
11+
12+
To run the code, you need to have installed:
13+
14+
- Python 3.8
15+
- Numpy
16+
- Scipy
17+
- Gnuplot
18+
19+
Run with:
20+
21+
python -m nbody.nbody
22+
23+
# Code structure
24+
The code is structured in the following components:
25+
26+
- Cosmology: we need to know Hubble factor $H$ as a function of the expansion factor $a$.
27+
- Mass deposition: PM codes need a way to convert from particles to a grid representation of the density.
28+
- Interpolation: Then we need to go back and interpolate grid quantities on particle coordinates.
29+
- Integrator: Cosmic structure formation is described by a Hamiltonian system of equations: we need to solve these, in this case using the Leap-frog method.
30+
- Solver: To solve the Poisson equation, we need to integrate the density in Fourier space to obtain the potential.
31+
- Initialization: The simulation is started using the Zeldovich Approximation.
32+
- Main: glue everything together.
733

834
``` {.python file=nbody/nbody.py}
935
<<imports>>
@@ -58,7 +84,7 @@ def OmegaK(self):
5884
return 1 - self.OmegaM - self.OmegaL
5985
```
6086

61-
and the gravitational constant,
87+
and the (a?) gravitational constant,
6288

6389
$$G = \frac{3}{2} \Omega_{m} H_0^2.$${#eq:grav-const}
6490

0 commit comments

Comments
 (0)