| 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-2017 Daniel Price. All rights reserved. |
| 19 |
! Contact: [email protected] |
| 20 |
! |
| 21 |
!----------------------------------------------------------------- |
| 22 |
|
| 23 |
!--------------------------------------------------------------------------- |
| 24 |
! compute exact solution for various spiral structures: |
| 25 |
! |
| 26 |
! 1) planet-disc interaction in phi-r plane |
| 27 |
! (Ogilvie & Lubow (2002), MNRAS 330, 950) |
| 28 |
! 2) planet-disc interaction from Rafikov (2002) |
| 29 |
! 3) general parameterised spiral arms |
| 30 |
!--------------------------------------------------------------------------- |
| 31 |
module planetdisc |
| 32 |
implicit none |
| 33 |
public :: exact_planetdisc |
| 34 |
integer, parameter :: maxspirals = 2 |
| 35 |
integer, parameter :: maxcoeff = 5 |
| 36 |
character(len=*), dimension(maxspirals), parameter, public :: labelspiral = & |
| 37 |
(/'Planet-disc interaction (Rafikov 2002; Ogilvie & Lubow 2002)',& |
| 38 |
'Spiral arm fitting formula r(phi) = sum(a_i*phi^i,i=1,4) '/) |
| 39 |
|
| 40 |
contains |
| 41 |
|
| 42 |
subroutine exact_planetdisc(iplot,ispiral,use_clockwise,use_nonlin,time,HonR,rplanet,q,phi0,& |
| 43 |
narms,params,rplot,yplot,ierr) |
| 44 |
use plotlib, only:plot_line |
| 45 |
use geometry, only:set_planet_wake,planet_wake_t |
| 46 |
integer, intent(in) :: iplot,ispiral,narms |
| 47 |
logical, intent(in) :: use_clockwise,use_nonlin |
| 48 |
integer, intent(out) :: ierr |
| 49 |
real, intent(in) :: time, HonR, rplanet, q, phi0, params(:,:) |
| 50 |
real, dimension(:), intent(inout) :: rplot |
| 51 |
real, dimension(size(rplot)), intent(out) :: yplot |
| 52 |
integer :: npts,iend,istart |
| 53 |
integer :: i,j,norbits,iarm |
| 54 |
logical :: use_ogilvie |
| 55 |
real :: r,rr,phase,dr,phi,rmin,rmax,phimin,phimax,dphi,coeff(maxcoeff) |
| 56 |
real, parameter :: pi = 4.*atan(1.) |
| 57 |
real :: p,t0,dt,dir |
| 58 |
|
| 59 |
p = 0.5 |
| 60 |
t0 = 0. |
| 61 |
ierr = 0 |
| 62 |
npts = size(rplot) |
| 63 |
norbits = int(time/(2.*pi)) |
| 64 |
phase = phi0*pi/180. ! convert to radians |
| 65 |
!if (time > 0.) phase = phase + (time - (2.*pi*norbits)) |
| 66 |
use_ogilvie = .false. |
| 67 |
if (use_clockwise) then |
| 68 |
dir = -1. |
| 69 |
else |
| 70 |
dir = 1. |
| 71 |
endif |
| 72 |
|
| 73 |
select case(ispiral) |
| 74 |
case(2) |
| 75 |
print "(a,i2)",' Spiral arm fitting formula r = sum(a_i*phi^i,i=1,4) narms =',narms |
| 76 |
case default |
| 77 |
print "(a,f6.2,a,f8.1,a)",' Planet-disc interaction: H/R=',HonR,' q = ',q |
| 78 |
use_ogilvie = (abs(q - 0.5) < epsilon(q)) |
| 79 |
if (use_ogilvie) then |
| 80 |
print "(a)",' Using Ogilvie & Lubow (2002) exact solution' |
| 81 |
elseif (use_nonlin) then |
| 82 |
print "(a)",' Using Rafikov (2002) exact solution for power-law disc + CR21 non-linear corrections' |
| 83 |
else |
| 84 |
print "(a)",' Using Rafikov (2002) exact solution for power-law disc' |
| 85 |
endif |
| 86 |
end select |
| 87 |
|
| 88 |
select case(iplot) |
| 89 |
case(8) ! in planet-wake coordinates |
| 90 |
yplot(1:npts) = 0. ! planet wake is a straight line at eta=0 |
| 91 |
case(2) |
| 92 |
! in phi-r plane |
| 93 |
istart = 1 |
| 94 |
do i=1,npts |
| 95 |
r = rplot(i) |
| 96 |
if (use_ogilvie) then |
| 97 |
! |
| 98 |
! Ogilvie & Lubow (2002) |
| 99 |
! |
| 100 |
if (r > rplanet) then |
| 101 |
yplot(i) = phase - 2./(3.*HonR)*(sqrt(r**3) - 1.5*log(r) - 1.) |
| 102 |
else |
| 103 |
yplot(i) = phase + 2./(3.*HonR)*(sqrt(r**3) - 1.5*log(r) - 1.) |
| 104 |
endif |
| 105 |
else |
| 106 |
! |
| 107 |
! Rafikov (2002) |
| 108 |
! |
| 109 |
rr = r/rplanet |
| 110 |
yplot(i) = phase + sign(1.,r-rplanet)*(1./(HonR))* & |
| 111 |
((rr**(q-0.5))/(q-0.5) - (rr**(q+1.))/(q+1.) - 3./((2.*q-1.)*(q+1.))) |
| 112 |
endif |
| 113 |
if (yplot(i) > pi) then |
| 114 |
phase = phase - 2.*pi |
| 115 |
if (i > 1) then |
| 116 |
iend = i |
| 117 |
call plot_line(iend-istart+1,rplot(istart:iend),yplot(istart:iend)) |
| 118 |
istart = i+1 |
| 119 |
endif |
| 120 |
endif |
| 121 |
if (yplot(i) <= -pi) then |
| 122 |
phase = phase + 2.*pi |
| 123 |
! plot separate line segments every time we cross the phase boundary |
| 124 |
if (i > 1) then |
| 125 |
iend = i |
| 126 |
call plot_line(iend-istart+1,rplot(istart:iend),yplot(istart:iend)) |
| 127 |
istart = i+1 |
| 128 |
endif |
| 129 |
endif |
| 130 |
enddo |
| 131 |
ierr = 1 ! do not plot outside this routine |
| 132 |
return |
| 133 |
case default ! in x-y plane |
| 134 |
! define npts outside planet orbit |
| 135 |
rmin = 1.e-3 |
| 136 |
rmax = min(max(maxval(rplot),abs(minval(rplot))),5.*rplanet) |
| 137 |
dr = (rmax - rmin)/npts |
| 138 |
do iarm=1,narms |
| 139 |
if (ispiral==2) then |
| 140 |
phimin = params(1,iarm) + 90. ! add 90 deg for East of North convention |
| 141 |
phimax = params(2,iarm) + 90. |
| 142 |
coeff(:) = params(3:,iarm) |
| 143 |
dphi = (phimax - phimin)/npts |
| 144 |
!print*,' GOT RMIN = ',rmin,phimin,phimax, 'COEFFS=',coeff |
| 145 |
endif |
| 146 |
! outside planet |
| 147 |
if (use_nonlin) then |
| 148 |
call set_planet_wake(rplanet,phase,p,q,HonR) |
| 149 |
t0 = 0. !1.89*3. !mp/mthermal |
| 150 |
endif |
| 151 |
do i=1,npts |
| 152 |
select case(ispiral) |
| 153 |
case(2) |
| 154 |
! |
| 155 |
! Spiral arm fitting formula |
| 156 |
! |
| 157 |
phi = phimin + (i-1)*dphi |
| 158 |
r = 0. ! rmin |
| 159 |
do j=1,maxcoeff |
| 160 |
r = r + coeff(j)*((phi-phimin)*pi/180.)**(j-1) |
| 161 |
enddo |
| 162 |
phi = phi*pi/180. ! convert to radians |
| 163 |
case default |
| 164 |
r = rmax - (i-1)*dr |
| 165 |
rr = r/rplanet |
| 166 |
if (use_ogilvie) then |
| 167 |
! |
| 168 |
! Ogilvie & Lubow (2002) |
| 169 |
! |
| 170 |
if (r > rplanet) then |
| 171 |
phi = phase - 2./(3.*HonR)*(sqrt(rr**3) - 1.5*log(rr) - 1.) |
| 172 |
else |
| 173 |
phi = phase + 2./(3.*HonR)*(sqrt(rr**3) - 1.5*log(rr) - 1.) |
| 174 |
endif |
| 175 |
else |
| 176 |
! |
| 177 |
! Rafikov (2002) |
| 178 |
! |
| 179 |
phi = phase + sign(1.,r-rplanet)*(1./(HonR))* & |
| 180 |
((rr**(q-0.5))/(q-0.5) - (rr**(q+1.))/(q+1.) - 3./((2.*q-1.)*(q+1.))) |
| 181 |
! phi = phase-sign(1.,r-rplanet)*(1./(HonR))*(((r/rplanet)**(1.+q)) & |
| 182 |
! *(1./(1.+q)-(1./(1.-p+q))*(r/rplanet)**(-p))-1./(1.+q)+1./(1.-p+q)) |
| 183 |
if (use_nonlin) then |
| 184 |
dt = planet_wake_t(r) - t0 |
| 185 |
if (dt > 0.) phi = phi + sign(1.,r-rplanet)*HonR*sqrt(dt) |
| 186 |
endif |
| 187 |
endif |
| 188 |
rplot(i) = dir*r*cos(phi) |
| 189 |
yplot(i) = r*sin(phi) |
| 190 |
end select |
| 191 |
!print*,'r, phi = ',r,phi,' : x, y = ',rplot(i),yplot(i) |
| 192 |
enddo |
| 193 |
call plot_line(npts,rplot,yplot) |
| 194 |
enddo |
| 195 |
ierr = 1 ! do not plot outside this routine |
| 196 |
end select |
| 197 |
|
| 198 |
end subroutine exact_planetdisc |
| 199 |
|
| 200 |
end module planetdisc |