| 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-2013 Daniel Price. All rights reserved. |
| 19 |
! Contact: [email protected] |
| 20 |
! |
| 21 |
!----------------------------------------------------------------- |
| 22 |
|
| 23 |
!----------------------------------------------------------------- |
| 24 |
! module handling plotting of azimuthally-averaged quantities |
| 25 |
! for disc simulations |
| 26 |
!----------------------------------------------------------------- |
| 27 |
module disc |
| 28 |
implicit none |
| 29 |
integer, parameter, private :: maxbins = 1001 |
| 30 |
integer, dimension(maxbins), private :: ninbin |
| 31 |
real, dimension(maxbins), private :: radius,yplot,sigma,spsound,omegasq |
| 32 |
integer, private :: nbins |
| 33 |
|
| 34 |
public :: disccalc,discplot |
| 35 |
|
| 36 |
private |
| 37 |
|
| 38 |
contains |
| 39 |
|
| 40 |
subroutine disccalc(iplot,npart,rpart,pmass_in,rminin,rmaxin,ymin,ymax,& |
| 41 |
itransx,itransy,icolourpart,iamtype,usetype,noftype,gamma,mstar,& |
| 42 |
dat,units,units_dz,iRescale,ipmass,irho,ispsound,iutherm,ix,ivx) |
| 43 |
use transforms, only:transform_limits_inverse,transform_inverse,transform |
| 44 |
use params, only:int1,maxparttypes,doub_prec |
| 45 |
use physcon, only:pi |
| 46 |
use part_utils, only:igettype |
| 47 |
integer, intent(in) :: iplot,npart,itransx,itransy |
| 48 |
real, dimension(npart), intent(in) :: rpart |
| 49 |
real, intent(in) :: pmass_in,rminin,rmaxin,gamma,mstar |
| 50 |
real, intent(out) :: ymin,ymax |
| 51 |
integer, dimension(npart), intent(in) :: icolourpart |
| 52 |
integer(kind=int1), dimension(:), intent(in) :: iamtype |
| 53 |
logical, dimension(maxparttypes), intent(in) :: usetype |
| 54 |
integer, dimension(maxparttypes), intent(in) :: noftype |
| 55 |
real, intent(in) :: units(:),units_dz |
| 56 |
logical, intent(in) :: iRescale |
| 57 |
real, dimension(:,:), intent(in) :: dat |
| 58 |
integer, intent(in) :: ipmass,irho,ispsound,iutherm,ix(:),ivx |
| 59 |
|
| 60 |
integer :: i,ibin |
| 61 |
real :: pmassi,rbin,deltar,area,rmin,rmax |
| 62 |
real :: x,y,vx,vy,r,vphi |
| 63 |
real(doub_prec) :: sigmai,toomreq,epicyclic,Omegai,spsoundi,dOmegasq_dr |
| 64 |
real(doub_prec) :: unit_mass,unit_r,unit_u,unit_dz,unit_dens,unit_cs2 |
| 65 |
real, dimension(1) :: rad |
| 66 |
logical :: mixedtypes |
| 67 |
integer :: itype,np |
| 68 |
|
| 69 |
ninbin(:) = 0 |
| 70 |
sigma(:) = 0. |
| 71 |
spsound(:) = 0. |
| 72 |
omegasq(:) = 0. |
| 73 |
pmassi = 0. |
| 74 |
|
| 75 |
! work out the unit of mass, r needed for computing Toomre Q |
| 76 |
unit_mass = 1.d0 |
| 77 |
unit_r = 1.d0 |
| 78 |
unit_u = 1.d0 |
| 79 |
unit_dz = 1.d0 |
| 80 |
unit_dens = 1.d0 |
| 81 |
unit_cs2 = 1.d0 |
| 82 |
unit_dz = 1.d0 |
| 83 |
if (iRescale) then |
| 84 |
if (ix(1) > 0) unit_r = units(ix(1)) |
| 85 |
if (iutherm > 0) unit_u = units(iutherm) |
| 86 |
if (irho > 0) unit_dens = units(irho) |
| 87 |
if (ipmass > 0) then |
| 88 |
unit_mass = units(ipmass) |
| 89 |
elseif (irho > 0) then |
| 90 |
unit_mass = units(irho)*units_dz**3 |
| 91 |
endif |
| 92 |
unit_dz = units_dz |
| 93 |
if (ispsound > 0) unit_cs2 = units(ispsound) |
| 94 |
endif |
| 95 |
! |
| 96 |
!--print info |
| 97 |
! |
| 98 |
select case(iplot) |
| 99 |
case(1) |
| 100 |
print "(a)",' calculating disc surface density profile ' |
| 101 |
case(2) |
| 102 |
if (iutherm > 0 .or. ispsound > 0) then |
| 103 |
print "(a,es10.3,a)",' calculating Toomre Q parameter (assuming Mstar=',mstar,' and Keplerian rotation)' |
| 104 |
if (ispsound == 0) then |
| 105 |
if (gamma < 1.00001) then |
| 106 |
print "(a)",' isothermal equation of state: using cs^2 = 2/3*utherm' |
| 107 |
else |
| 108 |
print "(a,f6.3,a,f6.3,a)",' ideal gas equation of state: using cs^2 = ',gamma*(gamma-1),'*u (gamma = ',gamma,')' |
| 109 |
endif |
| 110 |
endif |
| 111 |
else |
| 112 |
print "(a)",' ERROR: cannot calculate Toomre Q parameter: thermal energy/sound speed not present in dump file' |
| 113 |
return |
| 114 |
endif |
| 115 |
case(3) |
| 116 |
print "(a)",' calculating kappa^2/Omega^2 ' |
| 117 |
case default |
| 118 |
print "(a)",' ERROR: unknown plot in discplot. ' |
| 119 |
return |
| 120 |
end select |
| 121 |
! |
| 122 |
!--if transformations (e.g. log) are applied to r, then limits |
| 123 |
! will already be set in transformed space - need to obtain |
| 124 |
! limits in non-transformed space. |
| 125 |
! |
| 126 |
rmin = rminin |
| 127 |
rmax = rmaxin |
| 128 |
if (itransx > 0) call transform_limits_inverse(rmin,rmax,itransx) |
| 129 |
! |
| 130 |
!--try to get appropriate value for nbins |
| 131 |
! |
| 132 |
nbins = min(4*int(npart**(1./3.)) + 1,maxbins) |
| 133 |
! |
| 134 |
!--set array of radius values for plotting |
| 135 |
! |
| 136 |
deltar = (rmax - rmin)/(nbins - 1) |
| 137 |
do ibin=1,nbins |
| 138 |
radius(ibin) = rmin + (ibin-0.5)*deltar |
| 139 |
enddo |
| 140 |
mixedtypes = size(iamtype) >= npart |
| 141 |
! |
| 142 |
!--calculate surface density in each radial bin |
| 143 |
! |
| 144 |
np = 0 |
| 145 |
!$omp parallel do default(none) & |
| 146 |
!$omp shared(npart,rpart,sigma,omegasq,pmass_in,itransx,icolourpart,rmin,deltar,nbins,mstar) & |
| 147 |
!$omp shared(ninbin,spsound,gamma,iamtype,mixedtypes,usetype,noftype) & |
| 148 |
!$omp shared(dat,unit_cs2,ispsound,iutherm,ivx,ipmass,ix) & |
| 149 |
!$omp private(i,rad,pmassi,ibin,rbin,area,itype,x,y,vx,vy,r,vphi) & |
| 150 |
!$omp reduction(+:np) |
| 151 |
over_parts: do i=1,npart |
| 152 |
!--skip particles with itype < 0 |
| 153 |
if (icolourpart(i) < 0) cycle over_parts |
| 154 |
if (mixedtypes) then |
| 155 |
itype = int(iamtype(i)) |
| 156 |
else |
| 157 |
itype = igettype(i,noftype) |
| 158 |
endif |
| 159 |
if (.not.usetype(itype)) cycle over_parts |
| 160 |
np = np + 1 |
| 161 |
|
| 162 |
if (itransx==0) then |
| 163 |
rad(1) = rpart(i) |
| 164 |
else |
| 165 |
rad(1) = rpart(i) |
| 166 |
call transform_inverse(rad,itransx) |
| 167 |
endif |
| 168 |
if (ipmass > 0) then |
| 169 |
pmassi = dat(i,ipmass) |
| 170 |
else |
| 171 |
pmassi = pmass_in |
| 172 |
endif |
| 173 |
ibin = int((rad(1) - rmin)/deltar) + 1 |
| 174 |
if (ibin > 0 .and. ibin <= nbins) then |
| 175 |
rbin = rmin + (ibin-0.5)*deltar |
| 176 |
|
| 177 |
area = pi*((rbin + 0.5*deltar)**2 - (rbin - 0.5*deltar)**2) |
| 178 |
!$omp atomic |
| 179 |
sigma(ibin) = sigma(ibin) + pmassi/area |
| 180 |
if (ispsound > 0) then |
| 181 |
!$omp atomic |
| 182 |
spsound(ibin) = spsound(ibin) + real((dat(i,ispsound))**2/unit_cs2) |
| 183 |
elseif (iutherm > 0) then |
| 184 |
if (gamma < 1.00001) then |
| 185 |
!$omp atomic |
| 186 |
spsound(ibin) = spsound(ibin) + real(2./3.*(dat(i,iutherm)/unit_cs2)) |
| 187 |
else |
| 188 |
!$omp atomic |
| 189 |
spsound(ibin) = spsound(ibin) + real(gamma*(gamma-1.)*(dat(i,iutherm)/unit_cs2)) |
| 190 |
endif |
| 191 |
endif |
| 192 |
if (ivx > 0 .and. ix(1) > 0 .and. ix(2) > 0) then |
| 193 |
!--angular velocity Omega = vphi / r with |
| 194 |
! vphi from full x,y,vx,vy in the disc plane |
| 195 |
x = dat(i,ix(1)) |
| 196 |
y = dat(i,ix(2)) |
| 197 |
vx = dat(i,ivx) |
| 198 |
vy = dat(i,ivx+1) |
| 199 |
r = sqrt(x*x + y*y) |
| 200 |
if (r > 0.) then |
| 201 |
vphi = (x*vy - y*vx)/r |
| 202 |
!$omp atomic |
| 203 |
omegasq(ibin) = omegasq(ibin) + (vphi/r)**2 |
| 204 |
endif |
| 205 |
endif |
| 206 |
|
| 207 |
!$omp atomic |
| 208 |
ninbin(ibin) = ninbin(ibin) + 1 |
| 209 |
endif |
| 210 |
enddo over_parts |
| 211 |
!$omp end parallel do |
| 212 |
|
| 213 |
print "(1x,a,i10,a,i10,a,i4,a)",'used ',np,' of ',npart,' particles in ',nbins,' bins' |
| 214 |
select case(iplot) |
| 215 |
case(3) |
| 216 |
! |
| 217 |
!--average Keplerian rotation frequency in each bin |
| 218 |
! |
| 219 |
do ibin=1,nbins |
| 220 |
omegasq(ibin) = omegasq(ibin)/real(ninbin(ibin)) |
| 221 |
enddo |
| 222 |
do ibin=1,nbins |
| 223 |
! compute epicyclic frequency r*dOmega^2/dr + 4 Omega^2 |
| 224 |
if (ibin < nbins) then |
| 225 |
dOmegasq_dr = (omegasq(ibin+1) - omegasq(ibin))/(radius(ibin+1) - radius(ibin)) |
| 226 |
else |
| 227 |
dOmegasq_dr = (omegasq(ibin) - omegasq(ibin-1))/(radius(ibin) - radius(ibin-1)) |
| 228 |
endif |
| 229 |
epicyclic = radius(ibin)*dOmegasq_dr + 4*omegasq(ibin) |
| 230 |
yplot(ibin) = epicyclic/omegasq(ibin) |
| 231 |
enddo |
| 232 |
case(2) |
| 233 |
! |
| 234 |
!--calculate Toomre Q parameter in each bin using surface density |
| 235 |
! |
| 236 |
epicyclic = 0. |
| 237 |
do ibin=1,nbins |
| 238 |
sigmai = sigma(ibin)*(unit_r**2/unit_mass) ! convert back to code units |
| 239 |
! |
| 240 |
!--for Toomre Q need the epicyclic frequency |
| 241 |
! in a Keplerian disc kappa = Omega |
| 242 |
! |
| 243 |
Omegai = sqrt(mstar/(radius(ibin)/unit_r)**3) |
| 244 |
epicyclic = Omegai |
| 245 |
! |
| 246 |
!--spsound is RMS sound speed for all particles in the annulus |
| 247 |
! |
| 248 |
if (ninbin(ibin) > 0) then |
| 249 |
spsoundi = sqrt(spsound(ibin)/real(ninbin(ibin))) ! unit conversion already done |
| 250 |
else |
| 251 |
spsoundi = 0. |
| 252 |
endif |
| 253 |
! |
| 254 |
!--now calculate Toomre Q |
| 255 |
! |
| 256 |
if (sigmai > 0.) then |
| 257 |
toomreq = spsoundi*epicyclic/(pi*sigmai) |
| 258 |
else |
| 259 |
toomreq = 0. |
| 260 |
endif |
| 261 |
yplot(ibin) = real(toomreq,kind=kind(yplot)) |
| 262 |
enddo |
| 263 |
case default |
| 264 |
! |
| 265 |
!--return surface density in units of [g/cm^2], not [g/cm^3 au] or [Msun/au^2] |
| 266 |
! |
| 267 |
yplot = sigma*(unit_r**2/unit_mass) ! convert back to code units |
| 268 |
yplot = yplot*unit_dens*unit_dz ! convert to units of unit_dens * unit_dz |
| 269 |
end select |
| 270 |
! |
| 271 |
!--give very small number instead of zero to avoid problems on log plots |
| 272 |
! |
| 273 |
where (yplot(1:nbins) < tiny(0.)) yplot(1:nbins) = minval(yplot,mask=yplot>0.) |
| 274 |
|
| 275 |
if (itransx > 0) call transform(radius,itransx) |
| 276 |
if (itransy > 0) call transform(yplot,itransy) |
| 277 |
! |
| 278 |
!--return min and max of y axis so adaptive plot limits can be set |
| 279 |
! |
| 280 |
ymin = minval(yplot(1:nbins),mask=(yplot(1:nbins) /= 0.)) |
| 281 |
ymax = maxval(yplot(1:nbins),mask=(yplot(1:nbins) /= 0.)) |
| 282 |
|
| 283 |
end subroutine disccalc |
| 284 |
|
| 285 |
!--------------------------------------------------- |
| 286 |
! |
| 287 |
! subroutine to actually perform the disc plotting |
| 288 |
! |
| 289 |
!--------------------------------------------------- |
| 290 |
subroutine discplot |
| 291 |
use plotlib, only:plot_line |
| 292 |
|
| 293 |
call plot_line(nbins,radius,yplot) |
| 294 |
|
| 295 |
end subroutine discplot |
| 296 |
|
| 297 |
end module disc |