n_star (Roskar).ipynb 7.42 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": 7,
108 109 110 111 112 113 114 115
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
116 117
      "With Delta_x = 35.285949707 as in Roskar 2013 we reproduce the value for p_j = n_h = 18.3080473755\n",
      "and Teq = 1168.55454942\n"
118 119 120 121
     ]
    }
   ],
   "source": [
122
    "# reproducing Roskar 2013\n",
123
    "levelmax = 20\n",
124
    "Delta_x = (37e6 / 2.**levelmax)\n",
125
    "\n",
126 127 128
    "n_h, aux=5., 20.\n",
    "i=0\n",
    "while (np.abs(n_h-aux)/n_h ) > 1e-4:\n",
129
    "    aux = np.copy(n_h)\n",
130 131 132 133
    "    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 135 136 137
    "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)"
138 139 140 141 142 143 144 145 146 147 148 149
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# My value\n",
    "for levelmax =17 and boxlength = 25 Mpc "
   ]
  },
  {
   "cell_type": "code",
150
   "execution_count": 8,
151 152 153 154 155 156 157 158 159
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the resulting values for my sim are: \n",
160 161
      "p_j            =      4.863 m_h / cc\n",
      "n_star         =      8.336 m_H / cc\n"
162 163 164 165 166
     ]
    }
   ],
   "source": [
    "# my box\n",
167
    "levelmax = 18# max reached by Zoom DMO\n",
168 169 170 171 172
    "box_len = 25e6 # parsec\n",
    "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",
173
    "    aux = np.copy(n_h)\n",
174 175 176 177 178 179
    "    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",
180
    "         (G*m_p*(4.*Delta_x*pctocm/100)**2)\n",
181 182 183 184 185 186 187 188
    "         \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)"
   ]
  },
189 190
  {
   "cell_type": "code",
191
   "execution_count": 20,
192 193 194 195 196 197 198 199 200 201
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "mstar=n_star*(1./(2.**levelmax))**3. /n_h"
   ]
  },
  {
   "cell_type": "code",
202
   "execution_count": 21,
203 204 205 206 207 208 209 210 211 212
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7.612191598560314e-16"
      ]
     },
213
     "execution_count": 21,
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(n_star/n_h)*(1./(2.**levelmax))**3."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7.612191598560314e-16"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mstar"
   ]
  },
  {
   "cell_type": "code",
246
   "execution_count": 23,
247 248 249 250 251 252 253
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
254
       "190.73486328125"
255 256
      ]
     },
257
     "execution_count": 23,
258 259 260 261 262 263 264 265
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Delta_x\n"
   ]
  },
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
  {
   "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
}