Changes between Version 12 and Version 13 of u/johannjc/scratchpad


Ignore:
Timestamp:
01/09/14 10:48:34 (11 years ago)
Author:
Jonathan
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • u/johannjc/scratchpad

    v12 v13  
    11== Self-gravitating equilibrium profile using density profile and external pressure ==
    22
    3 Mathematically, we are solving the equation of hydrostatic equilibrium [[latex($\nabla P(r) = -\rho(r) \nabla \phi(r)$)]] subject to the constraint that  [[latex($P(R)=P_0$)]].  Since [[latex($\phi(r) = \frac{G M(r)}{r}$)]] we can rewrite the equation for HSE as [[latex($\frac{dP}{dr}=\frac{GM(r)\rho(r)}{r^2}$)]] and we can express the enclosed mass as [[latex($M(r)=4\pi\displaystyle\int_0^r{\rho(r') r'^2dr'}$)]]
     3Mathematically, we are solving the equation of hydrostatic equilibrium
     4
     5[[latex($\nabla P(r) = -\rho(r) \nabla \phi(r)$)]]
     6
     7subject to the constraint that  [[latex($P(R)=P_0$)]]. 
     8
     9Since [[latex($\phi(r) = -\frac{G M(r)}{r}$)]] we can rewrite the equation for HSE as
     10{{{
     11#!latex
     12\begin{equation}
     13\frac{dP}{dr}=-\frac{GM(r)\rho(r)}{r^2}
     14\end{equation}
     15}}}
    416
    517
     18 and we can express the enclosed mass as
     19
     20{{{
     21#!latex
     22\setcounter{equation}{1}
     23\begin{equation}
     24M(r)=4\pi\displaystyle\int_0^r{\rho(r') r'^2dr'}
     25\end{equation}
     26}}}
     27
     28Now we can discretize equation 2 as
     29
     30{{{
     31#!latex
     32\setcounter{equation}{2}
     33\begin{equation}
     34M_{i+1}=M_i + 4\pi \rho_i r_i^2\Delta r_i
     35\end{equation}
     36}}}
     37
     38where [[latex($\Delta r_j = r_{j+1}-r_j$)]]
     39
     40and equation 1 as
     41
     42{{{
     43#!latex
     44\setcounter{equation}{3}
     45\begin{equation}
     46P_{i+1}=P_i-\Delta r_i \frac{G M_i \rho_i}{r_i^2}
     47\end{equation}
     48}}}
     49
     50
     51but a taylor series expansion shows that the error at each step in the integration goes as
     52
     53[[latex($\frac{\Delta r_j}{r_j} + \frac{\Delta \rho_j}{\rho_j} + ...$)]]
     54
     55so we need to limit out point spacing - or improve the accuracy of our discretization.
     56
     57If we apply linear interpolation to our density profile, we can discretize equation 2 as
     58
     59{{{
     60#!latex
     61\setcounter{equation}{5}
     62\begin{equation}
     63M_i=M(r_i)=4\pi\displaystyle\sum_{j=0}^i{\rho_j r_j^2\Delta r_j \left ( 1 + \frac{\Delta r_j}{r_j} + \frac{\Delta \rho}{2\rho} + \frac{\Delta r_j^2}{3 r_j^2} + \frac{2\Delta \rho \Delta r_j}{3 \rho r_j} + \frac{\Delta \rho \Delta r_j^2}{4 \rho r_j^2}\right )}
     64\end{equation}
     65}}}
     66
     67and equation 4 becomes a bit of a monster...
     68{{{
     69 if (r0 == 0d0) then
     70            dp=drho*((pi*drho*dr**4)/4d0 + (4d0*pi*rho*dr**3)/9d0) + (rho*(pi*drho*dr**3 + 2d0*pi*rho*dr**2))/3d0
     71         else
     72            epsilon=log(r0/(r0+dr))
     73            dp=((-36d0*drho*r0)*epsilon*M0*dr + (-36d0*drho*r0**2)*epsilon*M0 + (- 12d0*pi*drho**2*r0**5 + 48d0*pi*rho*drho*r0**4)*epsilon*dr + (- 12d0*pi*drho**2*r0**6 + 48d0*pi*rho*drho*r0**5)*epsi\
     74lon + (36d0*rho - 36d0*drho*r0)*M0*dr + (9d0*pi*drho**2*r0)*dr**5 + (17d0*pi*drho**2*r0**2 + 28d0*pi*rho*drho*r0)*dr**4 + (2d0*pi*drho**2*r0**3 + 64d0*pi*drho*r0**2*rho + 24d0*pi*r0*rho**2)*dr**3 + (\
     75- 6d0*pi*drho**2*r0**4 + 24d0*pi*drho*r0**3*rho + 72d0*pi*r0**2*rho**2)*dr**2 +(- 12d0*pi*drho**2*r0**5 + 48d0*pi*rho*drho*r0**4)*dr)/(36d0*r0**2 + 36d0*dr*r0)
     76         end if
     77
     78
     79         if (r0 > 0d0) then
     80            dp=dp
     81         end if
     82         data(i,i_Press)=data(i+1,i_Press)+ScaleGrav*dp
     83}}}
     84
     85