| 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) 2022- Daniel Price. All rights reserved. |
| 19 |
! Contact: [email protected] |
| 20 |
! |
| 21 |
!----------------------------------------------------------------- |
| 22 |
module extinction |
| 23 |
implicit none |
| 24 |
|
| 25 |
public :: get_extinction, get_extinction_los |
| 26 |
|
| 27 |
private |
| 28 |
|
| 29 |
contains |
| 30 |
!--------------------------------------------------------- |
| 31 |
! routine to compute line-of-sight extinction to a |
| 32 |
! collection of points (e.g. positions of sink particles) |
| 33 |
!--------------------------------------------------------- |
| 34 |
subroutine get_extinction(ncolumns,dat,npartoftype,masstype,itype,ndim,ntypes,& |
| 35 |
npts,xpts,ypts,zpts,coldens,icol) |
| 36 |
use labels, only:ix,ih,irho,ipmass |
| 37 |
use limits, only:get_particle_subset |
| 38 |
use projections3D, only:interpolate3D_proj_points |
| 39 |
use particle_data, only:icolourme |
| 40 |
use interpolation, only:get_n_interp,set_interpolation_weights |
| 41 |
use settings_data, only:iRescale,iverbose,required,UseTypeInRenderings |
| 42 |
use settings_part, only:iplotpartoftype |
| 43 |
use settings_render, only:npix,inormalise=>inormalise_interpolations,& |
| 44 |
idensityweightedinterpolation,exact_rendering |
| 45 |
use settings_xsecrot, only:anglex,angley,anglez |
| 46 |
use settings_units, only:units,unit_interp,unitzintegration |
| 47 |
use rotation, only:rotate_particles |
| 48 |
use params, only:int1 |
| 49 |
integer, intent(in) :: ncolumns,ntypes,ndim |
| 50 |
integer, intent(in) :: npartoftype(:) |
| 51 |
integer(kind=int1), intent(in) :: itype(:) |
| 52 |
real, intent(in) :: masstype(:) |
| 53 |
real, intent(in) :: dat(:,:) |
| 54 |
integer, intent(in) :: npts,icol |
| 55 |
real, intent(inout) :: xpts(npts),ypts(npts),zpts(npts) |
| 56 |
real, intent(out) :: coldens(:) |
| 57 |
integer :: n,ierr,mycol |
| 58 |
real, dimension(:), allocatable :: weight,x,y,z |
| 59 |
|
| 60 |
! |
| 61 |
!--sanity checks |
| 62 |
! |
| 63 |
if (ndim /= 3) then |
| 64 |
print "(a)",' ERROR: extinction only works with 3 dimensional data' |
| 65 |
return |
| 66 |
endif |
| 67 |
if (.not. (ih > 0 .and. ipmass > 0 .and. irho > 0)) then |
| 68 |
print "(a)",' ERROR: could not locate h,mass or rho in data' |
| 69 |
return |
| 70 |
endif |
| 71 |
if (icol < 0 .or. icol > ncolumns) then |
| 72 |
print "(a)",' ERROR: invalid column number for extinction' |
| 73 |
return |
| 74 |
endif |
| 75 |
mycol = icol |
| 76 |
if (mycol==0) mycol = irho |
| 77 |
! |
| 78 |
!--set number of particles to use in the interpolation routines |
| 79 |
! and allocate memory for weights |
| 80 |
! |
| 81 |
n = get_n_interp(ntypes,npartoftype,UseTypeInRenderings,iplotpartoftype,size(itype),.false.) |
| 82 |
allocate(weight(n),x(n),y(n),z(n),stat=ierr) |
| 83 |
if (ierr /= 0) then |
| 84 |
print*,' ERROR allocating memory for interpolation weights, aborting...' |
| 85 |
return |
| 86 |
endif |
| 87 |
x(1:n) = dat(1:n,ix(1)) |
| 88 |
y(1:n) = dat(1:n,ix(2)) |
| 89 |
z(1:n) = dat(1:n,ix(3)) |
| 90 |
! |
| 91 |
!--rotate positions if necessary |
| 92 |
! |
| 93 |
call rotate_particles(n,x,y,z,anglex,angley,anglez) |
| 94 |
! |
| 95 |
!--set interpolation weights (w = m/(rho*h^ndim) |
| 96 |
! |
| 97 |
call set_interpolation_weights(weight,dat,itype,(iplotpartoftype .and. UseTypeInRenderings),& |
| 98 |
n,npartoftype,masstype,ntypes,ncolumns,irho,ipmass,ih,ndim,iRescale,& |
| 99 |
idensityweightedinterpolation,inormalise,units,unit_interp,required,.false.,isinktype=0) |
| 100 |
! |
| 101 |
!--set default mask and apply range restrictions to data |
| 102 |
! |
| 103 |
icolourme(:) = 1 |
| 104 |
call get_particle_subset(icolourme,dat,ncolumns) |
| 105 |
|
| 106 |
! |
| 107 |
!--rotate positions if necessary |
| 108 |
! |
| 109 |
call rotate_particles(npts,xpts,ypts,zpts,anglex,angley,anglez) |
| 110 |
! |
| 111 |
! interpolate column density (or other column-integrated quantity) |
| 112 |
! to desired point locations |
| 113 |
! |
| 114 |
call interpolate3D_proj_points(x,y,z,dat(1:n,ih),weight,dat(1:n,mycol),icolourme,n,& |
| 115 |
xpts,ypts,zpts,coldens,npts,inormalise,iverbose) |
| 116 |
! |
| 117 |
! adjust units of z-integrated quantity |
| 118 |
! |
| 119 |
if (iRescale .and. units(ih) > 0. .and. .not.inormalise) then |
| 120 |
coldens = coldens*(unitzintegration/units(ih)) |
| 121 |
endif |
| 122 |
|
| 123 |
deallocate(x,y,z,weight) |
| 124 |
|
| 125 |
end subroutine get_extinction |
| 126 |
|
| 127 |
!-------------------------------------------------------------- |
| 128 |
! routine to compute line-of-sight extinction from a |
| 129 |
! given point (currently the origin) along a set of directions |
| 130 |
!-------------------------------------------------------------- |
| 131 |
subroutine get_extinction_los(ncolumns,dat,npartoftype,masstype,itype,ndim,ntypes,& |
| 132 |
ndirs,anglex_vals,angley_vals,anglez_vals,coldens,icol) |
| 133 |
use settings_xsecrot, only:anglex,angley,anglez |
| 134 |
use params, only:int1 |
| 135 |
integer, intent(in) :: ncolumns,ntypes,ndim |
| 136 |
integer, intent(in) :: npartoftype(:) |
| 137 |
integer(kind=int1), intent(in) :: itype(:) |
| 138 |
real, intent(in) :: masstype(:) |
| 139 |
real, intent(in) :: dat(:,:) |
| 140 |
integer, intent(in) :: ndirs,icol |
| 141 |
real, intent(in) :: anglex_vals(ndirs),angley_vals(ndirs),anglez_vals(ndirs) |
| 142 |
real, intent(out) :: coldens(ndirs) |
| 143 |
integer, parameter :: npts = 1 |
| 144 |
integer :: i |
| 145 |
real :: xpts(npts),ypts(npts),zpts(npts),coldensi(1) |
| 146 |
|
| 147 |
! set the position from which to compute extinction as the origin |
| 148 |
xpts = 0.; ypts = 0.; zpts = 0. |
| 149 |
|
| 150 |
do i=1,ndirs |
| 151 |
anglex = anglex_vals(i) |
| 152 |
angley = angley_vals(i) |
| 153 |
anglez = anglez_vals(i) |
| 154 |
call get_extinction(ncolumns,dat,npartoftype,masstype,itype,ndim,ntypes,& |
| 155 |
npts,xpts,ypts,zpts,coldensi,icol) |
| 156 |
coldens(i) = coldensi(1) |
| 157 |
enddo |
| 158 |
|
| 159 |
end subroutine get_extinction_los |
| 160 |
|
| 161 |
end module extinction |