|
99 | 99 | by <i>Johan Hidding</i></span></a>
|
100 | 100 | <div class="collapse navbar-collapse" id="navbarSupportedContent">
|
101 | 101 | <ul>
|
| 102 | +<li><a href="#code-structure">Code structure</a></li> |
102 | 103 | <li><a href="#the-box">The Box</a></li>
|
103 | 104 | <li><a href="#cosmology">Cosmology</a></li>
|
104 | 105 | <li><a href="#mass-deposition">Mass deposition</a></li>
|
|
117 | 118 | -->
|
118 | 119 |
|
119 | 120 | <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> |
121 | 147 | <div class="annotated-code">
|
122 | 148 | <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"><<</span>imports<span class="op">>></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"><<</span>cosmology<span class="op">>></span></span> |
126 |
| -<span id="cb1-4"><a href="#cb1-4" aria-hidden="true"></a><span class="op"><<</span>mass<span class="op">-</span>deposition<span class="op">>></span></span> |
127 |
| -<span id="cb1-5"><a href="#cb1-5" aria-hidden="true"></a><span class="op"><<</span>interpolation<span class="op">>></span></span> |
128 |
| -<span id="cb1-6"><a href="#cb1-6" aria-hidden="true"></a><span class="op"><<</span>integrator<span class="op">>></span></span> |
129 |
| -<span id="cb1-7"><a href="#cb1-7" aria-hidden="true"></a><span class="op"><<</span>solver<span class="op">>></span></span> |
130 |
| -<span id="cb1-8"><a href="#cb1-8" aria-hidden="true"></a><span class="op"><<</span>initialization<span class="op">>></span></span> |
131 |
| -<span id="cb1-9"><a href="#cb1-9" aria-hidden="true"></a><span class="op"><<</span>main<span class="op">>></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"><<</span>imports<span class="op">>></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"><<</span>cosmology<span class="op">>></span></span> |
| 152 | +<span id="cb2-4"><a href="#cb2-4" aria-hidden="true"></a><span class="op"><<</span>mass<span class="op">-</span>deposition<span class="op">>></span></span> |
| 153 | +<span id="cb2-5"><a href="#cb2-5" aria-hidden="true"></a><span class="op"><<</span>interpolation<span class="op">>></span></span> |
| 154 | +<span id="cb2-6"><a href="#cb2-6" aria-hidden="true"></a><span class="op"><<</span>integrator<span class="op">>></span></span> |
| 155 | +<span id="cb2-7"><a href="#cb2-7" aria-hidden="true"></a><span class="op"><<</span>solver<span class="op">>></span></span> |
| 156 | +<span id="cb2-8"><a href="#cb2-8" aria-hidden="true"></a><span class="op"><<</span>initialization<span class="op">>></span></span> |
| 157 | +<span id="cb2-9"><a href="#cb2-9" aria-hidden="true"></a><span class="op"><<</span>main<span class="op">>></span></span></code></pre></div> |
132 | 158 | </div>
|
133 | 159 | <p>Some things we will definitely need:</p>
|
134 | 160 | <div class="annotated-code">
|
@@ -166,7 +192,7 @@ <h1 id="cosmology">Cosmology</h1>
|
166 | 192 | <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>
|
167 | 193 | <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>
|
168 | 194 | </div>
|
169 |
| -<p>and the gravitational constant,</p> |
| 195 | +<p>and the (a?) gravitational constant,</p> |
170 | 196 | <p><span class="math display">\[G = \frac{3}{2} \Omega_{m} H_0^2.\]</span>{#eq:grav-const}</p>
|
171 | 197 | <div class="annotated-code">
|
172 | 198 | <p><span><em>«cosmology-methods»+</em></span></p>
|
|
0 commit comments