n_star (Roskar).ipynb 7.42 KB
 NUNEZ Arturo committed Aug 07, 2017 1 2 3 4 { "cells": [ { "cell_type": "code", NUNEZ Arturo committed Jun 12, 2018 5 "execution_count": 1, NUNEZ Arturo committed Aug 07, 2017 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", NUNEZ Arturo committed Jun 12, 2018 17 "execution_count": 2, NUNEZ Arturo committed Aug 07, 2017 18 "metadata": { NUNEZ Arturo committed Jan 18, 2018 19 "collapsed": false, NUNEZ Arturo committed Jan 19, 2018 20 "hide_input": true, NUNEZ Arturo committed Jan 18, 2018 21 "scrolled": true NUNEZ Arturo committed Aug 07, 2017 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", "\\n", "P_J = (4 \\Delta x_{min})^2 \\frac{G}{\\pi \\gamma}\\rho^2\n", "\\n", "where $\\Delta x_{min} = l_{box} \\,/ \\,2^{lmax}$, $\\gamma = 5/3$ and also the equilibrium temperature is defined as:\n", " \n", "\\n", "T_{eq} = \\frac{5000}{\\sqrt n_H}\n", "\\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", "\\n", "n_{star} = \\frac{2k_b T_{eq}}\n", " {G(4\\pi \\Delta x_{min})}\n", "\\n", "Most of the heavy lifting is inside the calculation of $n_H$ that is as follows\n", "\\n", "n_H = \\frac{2k_b M_{\\%}^{-1} (3n_H^*)^{-1}} {G(4 \\Delta x_{min})^2}\n", "\\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": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%latex\n", "from Roskar 2014\n", "\\n", "P_J = (4 \\Delta x_{min})^2 \\frac{G}{\\pi \\gamma}\\rho^2\n", "\\n", "where $\\Delta x_{min} = l_{box} \\,/ \\,2^{lmax}$, $\\gamma = 5/3$ and also the equilibrium temperature is defined as:\n", " \n", "\\n", "T_{eq} = \\frac{5000}{\\sqrt n_H}\n", "\\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", "\\n", "n_{star} = \\frac{2k_b T_{eq}}\n", " {G(4\\pi \\Delta x_{min})}\n", "\\n", "Most of the heavy lifting is inside the calculation of $n_H$ that is as follows\n", "\\n", "n_H = \\frac{2k_b M_{\\%}^{-1} (3n_H^*)^{-1}} {G(4 \\Delta x_{min})^2}\n", "\\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", NUNEZ Arturo committed Jun 12, 2018 82 "execution_count": 3, NUNEZ Arturo committed Aug 07, 2017 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", NUNEZ Arturo committed Aug 01, 2018 107 "execution_count": 7, NUNEZ Arturo committed Aug 07, 2017 108 109 110 111 112 113 114 115 "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ NUNEZ Arturo committed Aug 01, 2018 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" NUNEZ Arturo committed Aug 07, 2017 118 119 120 121 ] } ], "source": [ NUNEZ Arturo committed Jan 12, 2018 122 "# reproducing Roskar 2013\n", NUNEZ Arturo committed Aug 01, 2018 123 "levelmax = 20\n", NUNEZ Arturo committed Jul 23, 2018 124 "Delta_x = (37e6 / 2.**levelmax)\n", NUNEZ Arturo committed Jan 19, 2018 125 "\n", NUNEZ Arturo committed Aug 07, 2017 126 127 128 "n_h, aux=5., 20.\n", "i=0\n", "while (np.abs(n_h-aux)/n_h ) > 1e-4:\n", NUNEZ Arturo committed Jan 18, 2018 129 " aux = np.copy(n_h)\n", NUNEZ Arturo committed Aug 07, 2017 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", NUNEZ Arturo committed Jan 18, 2018 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)" NUNEZ Arturo committed Aug 07, 2017 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", NUNEZ Arturo committed Jun 03, 2018 150 "execution_count": 8, NUNEZ Arturo committed Aug 07, 2017 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", NUNEZ Arturo committed Jun 03, 2018 160 161 "p_j = 4.863 m_h / cc\n", "n_star = 8.336 m_H / cc\n" NUNEZ Arturo committed Aug 07, 2017 162 163 164 165 166 ] } ], "source": [ "# my box\n", NUNEZ Arturo committed Jun 03, 2018 167 "levelmax = 18# max reached by Zoom DMO\n", NUNEZ Arturo committed Aug 07, 2017 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", NUNEZ Arturo committed Jan 23, 2018 173 " aux = np.copy(n_h)\n", NUNEZ Arturo committed Aug 07, 2017 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", NUNEZ Arturo committed Jan 12, 2018 180 " (G*m_p*(4.*Delta_x*pctocm/100)**2)\n", NUNEZ Arturo committed Aug 07, 2017 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)" ] }, NUNEZ Arturo committed Jan 13, 2018 189 190 { "cell_type": "code", NUNEZ Arturo committed Jan 23, 2018 191 "execution_count": 20, NUNEZ Arturo committed Jan 13, 2018 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", NUNEZ Arturo committed Jan 23, 2018 202 "execution_count": 21, NUNEZ Arturo committed Jan 13, 2018 203 204 205 206 207 208 209 210 211 212 "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "7.612191598560314e-16" ] }, NUNEZ Arturo committed Jan 23, 2018 213 "execution_count": 21, NUNEZ Arturo committed Jan 13, 2018 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", NUNEZ Arturo committed Jan 23, 2018 246 "execution_count": 23, NUNEZ Arturo committed Jan 13, 2018 247 248 249 250 251 252 253 "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ NUNEZ Arturo committed Jan 23, 2018 254 "190.73486328125" NUNEZ Arturo committed Jan 13, 2018 255 256 ] }, NUNEZ Arturo committed Jan 23, 2018 257 "execution_count": 23, NUNEZ Arturo committed Jan 13, 2018 258 259 260 261 262 263 264 265 "metadata": {}, "output_type": "execute_result" } ], "source": [ "Delta_x\n" ] }, NUNEZ Arturo committed Aug 07, 2017 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 }