| 1 |
!----------------------------------------------------------------- |
| 2 |
! |
| 3 |
! This file is (or was) part of SPLASH, a visualisation tool |
| 4 |
! for Smoothed Particle Hydrodynamics written by Daniel Price: |
| 5 |
! |
| 6 |
! http://users.monash.edu.au/~dprice/splash |
| 7 |
! |
| 8 |
! SPLASH comes with ABSOLUTELY NO WARRANTY. |
| 9 |
! This is free software; and you are welcome to redistribute |
| 10 |
! it under the terms of the GNU General Public License |
| 11 |
! (see LICENSE file for details) and the provision that |
| 12 |
! this notice remains intact. If you modify this file, please |
| 13 |
! note section 2a) of the GPLv2 states that: |
| 14 |
! |
| 15 |
! a) You must cause the modified files to carry prominent notices |
| 16 |
! stating that you changed the files and the date of any change. |
| 17 |
! |
| 18 |
! Copyright (C) 2005-2014 Daniel Price. All rights reserved. |
| 19 |
! Contact: [email protected] |
| 20 |
! |
| 21 |
!----------------------------------------------------------------- |
| 22 |
|
| 23 |
!--------------------------------------- |
| 24 |
! numerically integrate a polytrope |
| 25 |
! with the density = 1 at the centre |
| 26 |
! This uses scaled variables (no sigma in the equation) |
| 27 |
! then the radius is scaled to give the correct mass |
| 28 |
! Based on an old subroutine from Joe Monaghan |
| 29 |
!----------------------------------------- |
| 30 |
|
| 31 |
module polytrope |
| 32 |
implicit none |
| 33 |
public :: exact_polytrope |
| 34 |
|
| 35 |
contains |
| 36 |
|
| 37 |
subroutine exact_polytrope(gamma,polyk,totmass,rplot,denplot,npts,ierr) |
| 38 |
integer, intent(out) :: npts,ierr |
| 39 |
real, intent(in) :: gamma |
| 40 |
real, intent(in) :: polyk,totmass |
| 41 |
real, dimension(:), intent(inout) :: rplot |
| 42 |
real, dimension(size(rplot)), intent(out) :: denplot |
| 43 |
|
| 44 |
integer :: i,j |
| 45 |
real, parameter :: pi = 3.1415926536 |
| 46 |
real, dimension(size(rplot)) :: r,v,den |
| 47 |
real :: dr,an,rhs,rstar,totmassf |
| 48 |
real :: rhocentre,fac,rfac,G |
| 49 |
|
| 50 |
ierr = 0 |
| 51 |
print*,' gamma :',gamma |
| 52 |
dr = 0.001 |
| 53 |
G = 1. |
| 54 |
an = 1./(gamma-1.) |
| 55 |
v(1) = 0.0 |
| 56 |
v(2) = dr*(1.0 - dr*dr/6. ) |
| 57 |
r(1) = 0. |
| 58 |
|
| 59 |
i = 2 |
| 60 |
do while (v(i) >= 0.) |
| 61 |
r(i) = (i-1)*dr |
| 62 |
rhs = - r(i)*(v(i)/r(i))**an |
| 63 |
v(i+1) = 2*v(i) - v(i-1) + dr*dr*rhs |
| 64 |
i = i + 1 |
| 65 |
if (i+1 > size(rplot)) then |
| 66 |
dr = dr*2. |
| 67 |
r(2) = dr |
| 68 |
v(2) = dr*(1.0 - dr*dr/6. ) |
| 69 |
i = 2 |
| 70 |
endif |
| 71 |
enddo |
| 72 |
npts = i-1 |
| 73 |
rstar = r(npts) |
| 74 |
|
| 75 |
!-------------------------------------- |
| 76 |
! calculate the mass out to radius r |
| 77 |
! using the density without the central |
| 78 |
! density multiplier- call this totmassf |
| 79 |
! the true scaled totmass = 1. |
| 80 |
!---------------------------------------- |
| 81 |
|
| 82 |
den(1) = 1.0 |
| 83 |
totmassf = 0. |
| 84 |
do j = 2,npts |
| 85 |
den(j) = (v(j)/r(j))**an |
| 86 |
totmassf = totmassf + 4.*pi*r(j)*r(j)*den(j)*dr |
| 87 |
enddo |
| 88 |
|
| 89 |
!--------------------------------------------------- |
| 90 |
! rescale the central density to give desired massq |
| 91 |
! then rescale the radius to match this |
| 92 |
!--------------------------------------------------- |
| 93 |
fac = (gamma*polyk)/(4.*pi*G*(gamma - 1.)) |
| 94 |
rhocentre = ((totmass/totmassf)/fac**1.5)**(2./(3.*gamma - 4.)) |
| 95 |
rfac = sqrt(fac*rhocentre**(gamma - 2.)) |
| 96 |
|
| 97 |
print*,' Rstar = ',rstar*rfac |
| 98 |
print*,' central density :',rhocentre |
| 99 |
print*,' total mass :',totmass |
| 100 |
|
| 101 |
rplot = r * rfac |
| 102 |
denplot = rhocentre * den |
| 103 |
|
| 104 |
return |
| 105 |
end subroutine exact_polytrope |
| 106 |
|
| 107 |
end module polytrope |