n_star (Roskar).ipynb 9.68 KB
Newer Older
1
2
3
4
{
 "cells": [
  {
   "cell_type": "code",
5
   "execution_count": 1,
6
7
8
9
10
11
12
13
14
15
16
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
17
   "execution_count": 2,
18
   "metadata": {
19
    "collapsed": false,
20
    "hide_input": true,
21
    "scrolled": true
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "from Roskar 2014\n",
       "\\begin{equation}\n",
       "P_J = (4 \\Delta x_{min})^2 \\frac{G}{\\pi \\gamma}\\rho^2\n",
       "\\end{equation}\n",
       "where $\\Delta x_{min} = l_{box} \\,/ \\,2^{lmax}$, $\\gamma = 5/3$ and also the equilibrium temperature is defined as:\n",
       "    \n",
       "\\begin{equation}\n",
       "T_{eq} = \\frac{5000}{\\sqrt n_H}\n",
       "\\end{equation}\n",
       "here number density of hydrogen is expressed in (H/cm^3).Now, it can be proved that the n_star of a hydro run is given by:\n",
       "\\begin{equation}\n",
       "n_{star} = \\frac{2k_b T_{eq}}\n",
       "                 {G(4\\pi \\Delta x_{min})}\n",
       "\\end{equation}\n",
       "Most of the heavy lifting is inside the calculation of $n_H$ that is as follows\n",
       "\\begin{equation}\n",
       "n_H = \\frac{2k_b  M_{\\%}^{-1} (3n_H^*)^{-1}} {G(4 \\Delta x_{min})^2}\n",
       "\\end{equation}\n",
       "\n",
       "thi is done until   $|n_H-n_H^*|/n_H$>0.0001 for convergence. notice that here the is a molecular gas so $m_{\\%} = (0.76m_p+0.24m_{He}) $."
      ],
      "text/plain": [
       "<IPython.core.display.Latex object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%%latex\n",
    "from Roskar 2014\n",
    "\\begin{equation}\n",
    "P_J = (4 \\Delta x_{min})^2 \\frac{G}{\\pi \\gamma}\\rho^2\n",
    "\\end{equation}\n",
    "where $\\Delta x_{min} = l_{box} \\,/ \\,2^{lmax}$, $\\gamma = 5/3$ and also the equilibrium temperature is defined as:\n",
    "    \n",
    "\\begin{equation}\n",
    "T_{eq} = \\frac{5000}{\\sqrt n_H}\n",
    "\\end{equation}\n",
    "here number density of hydrogen is expressed in (H/cm^3).Now, it can be proved that the n_star of a hydro run is given by:\n",
    "\\begin{equation}\n",
    "n_{star} = \\frac{2k_b T_{eq}}\n",
    "                 {G(4\\pi \\Delta x_{min})}\n",
    "\\end{equation}\n",
    "Most of the heavy lifting is inside the calculation of $n_H$ that is as follows\n",
    "\\begin{equation}\n",
    "n_H = \\frac{2k_b  M_{\\%}^{-1} (3n_H^*)^{-1}} {G(4 \\Delta x_{min})^2}\n",
    "\\end{equation}\n",
    "\n",
    "thi is done until   $|n_H-n_H^*|/n_H$>0.0001 for convergence. notice that here the is a molecular gas so $m_{\\%} = (0.76m_p+0.24m_{He}) $."
   ]
  },
  {
   "cell_type": "code",
82
   "execution_count": 3,
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# then \n",
    "# constants\n",
    "k_b = 1.38e-23 # J K^-1 \n",
    "m_He = 6.646468e-27 # kg\n",
    "m_p = 1.672e-27 # kg\n",
    "G = 6.67e-11 # m^3 kg^-1 s^-2  \n",
    "m_mg = (0.76 * m_p + 0.24*m_He)\n",
    "pctocm = 3.08567758e18"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Reproducing Roskar 2013 value of $p_J$"
   ]
  },
  {
   "cell_type": "code",
107
   "execution_count": 4,
108
109
110
111
112
113
114
115
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
116
117
      "With Delta_x = 35.714 as in Roskar 2013 we reproduce the value for p_j = n_h = 18.0160629004\n",
      "and Teq = 1177.98581172\n"
118
119
120
121
122
     ]
    }
   ],
   "source": [
    "# reproducing Roskar 2013\n",
123
    "levelmax = 20\n",
124
    "Delta_x = 35.714#36e6 / 2.**levelmax\n",
125
126
127
128
129
130
131
132
133
    "\n",
    "n_h, aux=5., 20.\n",
    "i=0\n",
    "while (np.abs(n_h-aux)/n_h ) > 1e-4:\n",
    "    aux = np.copy(n_h)\n",
    "    n_h = (2*np.pi*k_b*1e4*np.sqrt(0.3))/\\\n",
    "          (G* m_mg*np.sqrt(aux)*(4*Delta_x*pctocm/100)**2)\n",
    "    n_h /= (m_p*1e6)#\n",
    "\n",
134
    "\n",
135
    "Teq = 5000/np.sqrt(n_h)\n",
136
    "\n",
137
138
139
140
141
142
    "print \"With Delta_x = {0} as in Roskar 2013 we reproduce the value for p_j = n_h = {1}\".format(Delta_x,n_h)\n",
    "print \"and Teq = {0}\".format(Teq)"
   ]
  },
  {
   "cell_type": "code",
143
   "execution_count": 52,
144
145
146
147
148
149
150
151
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
      "39.0\n",
      "0.8670303260137321\n",
      "1.7423551526078138\n",
      "0.3961373743997542\n",
      "0.28685888223305883\n",
      "0.11847519410838325\n",
      "0.06508122993995183\n",
      "0.031033785686198457\n",
      "0.01588765486721152\n",
      "0.0078504068917792\n",
      "0.003948466516169543\n",
      "0.001968406033336382\n",
      "0.0009856583875317458\n",
      "0.0004924651718333048\n",
      "0.00024632356898545565\n",
      "0.00012313903592466217\n",
      "6.157520475427508e-05\n",
      "3.0786180635163585e-05\n",
      "1.539344574734524e-05\n",
      "With Delta_x = 34.0595245361 as in Roskar 2013 we reproduce the value for p_j = n_h = 19.1926988648\n",
      "and Teq = 1141.30568281\n"
173
174
175
176
     ]
    }
   ],
   "source": [
177
    "# reproducing Roskar 2013\n",
178
    "levelmax = 20\n",
179
    "Delta_x = (35.714e6 / 2.**levelmax)\n",
180
    "\n",
181
    "n_h, aux=5., 200.\n",
182
    "i=0\n",
183
184
    "while (np.abs(n_h-aux)/n_h ) > 1e-5:\n",
    "    print (np.abs(n_h-aux)/n_h )\n",
185
    "    aux = np.copy(n_h)\n",
186
    "  \n",
187
188
189
190
    "    n_h = (2*np.pi*k_b*1e4*np.sqrt(0.3))/\\\n",
    "          (G* m_mg*np.sqrt(aux)*(4*Delta_x*pctocm/100)**2)\n",
    "    n_h /= (m_p*1e6)#\n",
    "\n",
191
192
193
194
    "Teq = 5000/np.sqrt(n_h)\n",
    "    \n",
    "print \"With Delta_x = {0} as in Roskar 2013 we reproduce the value for p_j = n_h = {1}\".format(Delta_x,n_h)\n",
    "print \"and Teq = {0}\".format(Teq)"
195
196
   ]
  },
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "35.714285714285715"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "25/0.7"
   ]
  },
219
220
221
222
223
224
225
226
227
228
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# My value\n",
    "for levelmax =17 and boxlength = 25 Mpc "
   ]
  },
  {
   "cell_type": "code",
229
   "execution_count": 27,
230
231
232
233
234
235
236
237
238
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the resulting values for my sim are: \n",
239
240
      "p_j            =      2.599 m_h / cc\n",
      "n_star         =      4.454 m_H / cc\n"
241
242
243
244
245
     ]
    }
   ],
   "source": [
    "# my box\n",
246
247
    "levelmax = 17# max reached by Zoom DMO\n",
    "box_len = 20e6 # parsec\n",
248
249
250
251
    "Delta_x = (box_len / 2.**levelmax)\n",
    "n_h, aux=5., 20.\n",
    "i=0\n",
    "while (np.abs(n_h-aux)/n_h ) > 1e-4:\n",
252
    "    aux = np.copy(n_h)\n",
253
254
255
256
257
258
    "    n_h = (2*np.pi*k_b*1e4*np.sqrt(0.3))/\\\n",
    "          (G* m_mg*np.sqrt(aux)*(4*Delta_x*pctocm/100)**2) # kg per cubic meter\n",
    "    n_h /= (m_p*1e6) # H per cubic centimeter\n",
    "    \n",
    "# so my n_star is\n",
    "n_star = (2*np.pi*k_b*1e4*np.sqrt(0.3/n_h))/\\\n",
259
    "         (G*m_p*(4.*Delta_x*pctocm/100)**2)\n",
260
261
262
263
264
265
266
267
    "         \n",
    "        \n",
    "n_star /= (m_p*1e6)\n",
    "print \"the resulting values for my sim are: \" \n",
    "print \"p_j            =      {0:.3f} m_h / cc\".format(n_h)\n",
    "print \"n_star         =      {0:.3f} m_H / cc\".format(n_star)"
   ]
  },
268
269
  {
   "cell_type": "code",
270
   "execution_count": 18,
271
272
273
274
275
276
277
278
279
280
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "mstar=n_star*(1./(2.**levelmax))**3. /n_h"
   ]
  },
  {
   "cell_type": "code",
281
   "execution_count": 19,
282
283
284
285
286
287
288
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
289
       "9.514354866889036e-17"
290
291
      ]
     },
292
     "execution_count": 19,
293
294
295
296
297
298
299
300
301
302
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(n_star/n_h)*(1./(2.**levelmax))**3."
   ]
  },
  {
   "cell_type": "code",
303
   "execution_count": 20,
304
305
306
307
308
309
310
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
311
       "9.514354866889036e-17"
312
313
      ]
     },
314
     "execution_count": 20,
315
316
317
318
319
320
321
322
323
324
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mstar"
   ]
  },
  {
   "cell_type": "code",
325
   "execution_count": 21,
326
327
328
329
330
331
332
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
333
       "76.2939453125"
334
335
      ]
     },
336
     "execution_count": 21,
337
338
339
340
341
342
343
344
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Delta_x\n"
   ]
  },
345
346
  {
   "cell_type": "code",
347
   "execution_count": 57,
348
   "metadata": {
349
    "collapsed": false
350
   },
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5477.225575051661"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1e4*np.sqrt(.3)"
   ]
366
  },
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  },
  "latex_envs": {
   "bibliofile": "biblio.bib",
   "cite_by": "apalike",
   "current_citInitial": 1,
   "eqLabelWithNumbers": true,
   "eqNumInitial": 0
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}