| 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-2022 Daniel Price. All rights reserved. |
| 19 |
! Contact: [email protected] |
| 20 |
! |
| 21 |
!----------------------------------------------------------------- |
| 22 |
module adjustdata |
| 23 |
implicit none |
| 24 |
|
| 25 |
contains |
| 26 |
|
| 27 |
!---------------------------------------------------- |
| 28 |
! |
| 29 |
! specify data dependencies for adjust data |
| 30 |
! procedures to ensure required quantities |
| 31 |
! are read from the data file |
| 32 |
! |
| 33 |
!---------------------------------------------------- |
| 34 |
subroutine get_adjust_data_dependencies(required) |
| 35 |
use labels, only:idustfrac,irho,ivx,ideltav |
| 36 |
use settings_data, only:ndimV,UseFakeDustParticles |
| 37 |
logical, intent(inout) :: required(0:) |
| 38 |
integer :: i |
| 39 |
|
| 40 |
! if making fake dust particles, read epsilon and deltav |
| 41 |
if (idustfrac > 0 .and. irho > 0 .and. UseFakeDustParticles) then |
| 42 |
if (required(irho)) required(idustfrac) = .true. |
| 43 |
if (ideltav > 0) then |
| 44 |
do i=ivx,ivx+ndimV-1 |
| 45 |
if (required(i)) required(ideltav+i-ivx) = .true. |
| 46 |
enddo |
| 47 |
if (any(required(ivx:ivx+ndimV-1))) required(idustfrac) = .true. |
| 48 |
endif |
| 49 |
endif |
| 50 |
|
| 51 |
end subroutine get_adjust_data_dependencies |
| 52 |
!---------------------------------------------------- |
| 53 |
! |
| 54 |
! amend data after the data read based on |
| 55 |
! various environment variable settings |
| 56 |
! |
| 57 |
! must be called AFTER the data has been read |
| 58 |
! but BEFORE rescaling to physical units is applied |
| 59 |
! |
| 60 |
!---------------------------------------------------- |
| 61 |
subroutine adjust_data_codeunits |
| 62 |
use system_utils, only:renvironment,envlist,ienvironment,lenvironment,ienvlist,& |
| 63 |
ienvstring,get_environment_or_flag,get_command_flag,renvlist |
| 64 |
use labels, only:ih,ix,ivx,get_sink_type,ipmass,idustfrac,irho,labeltype,label |
| 65 |
use settings_data, only:ncolumns,ndimV,ndim,ntypes,iverbose,UseFakeDustParticles,& |
| 66 |
UseFastRender,icoords,track_string |
| 67 |
use particle_data, only:dat,npartoftype,iamtype |
| 68 |
use filenames, only:ifileopen,nstepsinfile |
| 69 |
use geometry, only:labelcoord |
| 70 |
use part_utils, only:locate_first_two_of_type,locate_nth_particle_of_type,& |
| 71 |
locate_particle_from_string,get_binary,got_particles_of_type |
| 72 |
real :: hmin,dphi,domega,period |
| 73 |
real, dimension(3) :: x0,v0,xsink |
| 74 |
integer :: i,j,ierr,isink,isinkpos,itype,nlist,nerr |
| 75 |
integer :: ntot,isink1,isink2,isinklist(2),iorigin |
| 76 |
logical :: centreonsink,dontCentreVelocity,got_sinks,no_dust_particles |
| 77 |
character(len=20), dimension(3) :: list |
| 78 |
character(len=30) :: string |
| 79 |
|
| 80 |
! |
| 81 |
!--environment variable setting to enforce a minimum h |
| 82 |
! |
| 83 |
if (ih > 0 .and. ih <= ncolumns) then |
| 84 |
hmin = max(renvironment('SPLASH_HMIN_CODEUNITS',errval=-1.),& ! for backwards compatibility |
| 85 |
renvironment('SPLASH_BEAM',errval=-1.)) |
| 86 |
if (hmin > 0.) then |
| 87 |
if (.not.allocated(dat)) then |
| 88 |
print*,' INTERNAL ERROR: dat not allocated in adjust_data_codeunits' |
| 89 |
return |
| 90 |
endif |
| 91 |
print "(/,a,es10.3)",' >> SETTING MINIMUM H TO ',hmin |
| 92 |
where (dat(:,ih,:) < hmin .and. dat(:,ih,:) > 0.) |
| 93 |
dat(:,ih,:) = hmin |
| 94 |
end where |
| 95 |
print "(a)",' >> Switching accelerated rendering ON' |
| 96 |
UseFastRender = .true. |
| 97 |
endif |
| 98 |
endif |
| 99 |
|
| 100 |
if (ndim > 0) then |
| 101 |
! |
| 102 |
!--environment variable to corotate with first two sink particles |
| 103 |
! can be SPLASH_COROTATE=true (just picks first two sinks) |
| 104 |
! or SPLASH_COROTATE=1,3 |
| 105 |
! |
| 106 |
isinklist = ienvlist('SPLASH_COROTATE',2) |
| 107 |
got_sinks = all(isinklist > 0) |
| 108 |
if (lenvironment('SPLASH_COROTATE') .or. got_sinks) then |
| 109 |
itype = get_sink_type(ntypes) |
| 110 |
if (itype > 0) then |
| 111 |
if (all(npartoftype(itype,:) < 2)) then |
| 112 |
print "(a)",' ERROR: --corotate set but less than 2 sink particles' |
| 113 |
else |
| 114 |
if (iverbose >= 1) print* |
| 115 |
if (got_sinks) then |
| 116 |
print "(a,i3,a,i3,a)",' :: COROTATING FRAME WITH SINKS ',isinklist(1),& |
| 117 |
', ',isinklist(2),' from --corotate flag' |
| 118 |
else |
| 119 |
print "(a)",' :: COROTATING FRAME WITH FIRST 2 SINKS from --corotate flag' |
| 120 |
endif |
| 121 |
do j=1,nstepsinfile(ifileopen) |
| 122 |
if (got_sinks) then |
| 123 |
call locate_nth_particle_of_type(isinklist(1),isink1,itype,iamtype(:,j),npartoftype(:,j),ntot) |
| 124 |
call locate_nth_particle_of_type(isinklist(2),isink2,itype,iamtype(:,j),npartoftype(:,j),ntot) |
| 125 |
else |
| 126 |
! find first two sink particles in the data |
| 127 |
call locate_first_two_of_type(isink1,isink2,itype,iamtype(:,j),npartoftype(:,j),ntot) |
| 128 |
endif |
| 129 |
! get properties of the binary |
| 130 |
call get_binary(isink1,isink2,dat(:,:,j),x0,v0,dphi,domega,ndim,ndimV,ncolumns,ix,ivx,ipmass,iverbose,ierr) |
| 131 |
! rotate all the particles into this frame |
| 132 |
if (ierr==0) call rotate_particles(dat(:,:,j),ntot,dphi,domega,x0(1:ndim),ndim,ndimV,v0) |
| 133 |
enddo |
| 134 |
endif |
| 135 |
else |
| 136 |
print "(a,/,a)",' ERROR: --corotate set but could not determine type ', & |
| 137 |
' corresponding to sink particles' |
| 138 |
endif |
| 139 |
endif |
| 140 |
|
| 141 |
! |
| 142 |
!--environment variable setting to centre plots on a selected sink particle |
| 143 |
! |
| 144 |
!--can specify either just "true" for sink #1, or specify a number for a particular sink |
| 145 |
centreonsink = lenvironment('SPLASH_CENTRE_ON_SINK') .or. lenvironment('SPLASH_CENTER_ON_SINK') |
| 146 |
isink = max(ienvironment('SPLASH_CENTRE_ON_SINK'),ienvironment('SPLASH_CENTER_ON_SINK')) |
| 147 |
dontCentreVelocity = lenvironment('SPLASH_DONTCENTREVEL') .or. lenvironment('SPLASH_DONTCENTERVEL') |
| 148 |
if (isink > 0 .or. centreonsink .and. all(ix(1:ndim) > 0)) then |
| 149 |
if (isink==0) isink = 1 |
| 150 |
itype = get_sink_type(ntypes) |
| 151 |
if (itype > 0) then |
| 152 |
if (all(npartoftype(itype,:) < isink)) then |
| 153 |
print "(a,i10,a)",' ERROR: --sink = ',isink,' but not enough sink particles' |
| 154 |
else |
| 155 |
if (iverbose >= 1) print* |
| 156 |
! feature to centre on a sink particle but shift the origin to a different point |
| 157 |
x0 = renvlist('SPLASH_SHIFT',ndim,errval=-666.) |
| 158 |
|
| 159 |
print "(a,i0,a)",' :: CENTREING ON SINK ',isink,' from --sink flag' |
| 160 |
if (dontCentreVelocity) print "(a)",' :: NOT CENTREING VELOCITY' |
| 161 |
do j=1,nstepsinfile(ifileopen) |
| 162 |
call locate_nth_particle_of_type(isink,isinkpos,itype,iamtype(:,j),npartoftype(:,j),ntot) |
| 163 |
call centre_on_particle(isinkpos,dat(:,:,j),ntot,ndim,ndimV,ncolumns,dontCentreVelocity,& |
| 164 |
iverbose,label='sink',xi=xsink) |
| 165 |
if (all(abs(x0+666.) > tiny(0.))) then |
| 166 |
print "(a,3(1x,es10.3),a)",' :: SHIFTING TO x=',x0(1:ndim),' from --shift flag' |
| 167 |
call shift_positions(dat(:,:,j),ntot,ndim,x0) |
| 168 |
print "(a,3(1x,es10.3))",' :: distance of sink from original origin = ',xsink(1:ndim)+x0(1:ndim) |
| 169 |
endif |
| 170 |
enddo |
| 171 |
endif |
| 172 |
else |
| 173 |
print "(a,/,a)",' ERROR: --sink set but could not determine type ', & |
| 174 |
' corresponding to sink particles' |
| 175 |
endif |
| 176 |
endif |
| 177 |
! |
| 178 |
!--center on a particular particle |
| 179 |
! |
| 180 |
call get_environment_or_flag('SPLASH_ORIGIN',string) |
| 181 |
iorigin = ienvstring(string) ! first try to read the string as an integer |
| 182 |
|
| 183 |
if (iorigin > 0 .or. (len_trim(string) > 0) .and. all(ix(1:ndim) > 0) .and. ndim > 0) then |
| 184 |
if (track_string(1:1) /= '0' .and. len_trim(track_string) > 0) then |
| 185 |
print "(/,a,/)",' ERROR: cannot use --track and --origin at the same time, disabling particle tracking' |
| 186 |
track_string = '0' |
| 187 |
endif |
| 188 |
if (centreonsink) then |
| 189 |
print "(/,a,/)",' ERROR: cannot use --sink and --origin at the same time' |
| 190 |
else |
| 191 |
over_steps: do j=1,nstepsinfile(ifileopen) |
| 192 |
! |
| 193 |
!--handle strings like --origin=maxdens to locate the particle for the origin |
| 194 |
! |
| 195 |
ntot = sum(npartoftype(:,j)) |
| 196 |
if (index(string,',') > 0) then |
| 197 |
x0 = renvlist(string,ndim,errval=-666.) |
| 198 |
if (all(abs(x0+666.) > tiny(0.))) then |
| 199 |
print*,':: CENTREING ON x=',x0(1:ndim),' from --origin='//trim(string)//' flag' |
| 200 |
call shift_positions(dat(:,:,j),ntot,ndim,x0) |
| 201 |
endif |
| 202 |
exit over_steps |
| 203 |
elseif (len_trim(string) > 0 .and. iorigin==0) then |
| 204 |
iorigin = locate_particle_from_string(string,ntot,dat(:,:,j),irho) |
| 205 |
if (iorigin <= 0) exit over_steps |
| 206 |
endif |
| 207 |
if (j==1 .or. ienvstring(string) == 0) then |
| 208 |
print "(a,i0,a)",' :: CENTREING ON PARTICLE ',iorigin,' from --origin='//trim(string)//' flag' |
| 209 |
if (dontCentreVelocity) print "(a)",' :: NOT CENTREING VELOCITY' |
| 210 |
endif |
| 211 |
! |
| 212 |
!--now centre on the chosen particle |
| 213 |
! |
| 214 |
call centre_on_particle(iorigin,dat(:,:,j),ntot,ndim,ndimV,ncolumns,dontCentreVelocity,iverbose,label='') |
| 215 |
enddo over_steps |
| 216 |
endif |
| 217 |
endif |
| 218 |
|
| 219 |
! |
| 220 |
!--environment variable setting to subtract a mean velocity |
| 221 |
! |
| 222 |
if (ivx > 0 .and. ivx+ndimV-1 <= ncolumns) then |
| 223 |
call envlist('SPLASH_VZERO',nlist,list) |
| 224 |
nerr = 0 |
| 225 |
if (nlist > 0 .and. nlist < ndimV) then |
| 226 |
print "(/,2(a,i1))",' >> ERROR in --vzero setting: number of components = ',nlist,', needs to be ',ndimV |
| 227 |
nerr = 1 |
| 228 |
elseif (nlist > 0) then |
| 229 |
if (nlist > ndimV) print "(a,i1,a,i1)",' >> WARNING! --vzero setting has ',nlist, & |
| 230 |
' components: using only first ',ndimV |
| 231 |
nerr = 0 |
| 232 |
do i=1,ndimV |
| 233 |
read(list(i),*,iostat=ierr) v0(i) |
| 234 |
if (ierr /= 0) then |
| 235 |
print "(a)",' >> ERROR reading v'//trim(labelcoord(i,icoords))//& |
| 236 |
' component from --vzero setting' |
| 237 |
nerr = ierr |
| 238 |
endif |
| 239 |
enddo |
| 240 |
if (nerr==0) then |
| 241 |
print "(a)",' >> SUBTRACTING MEAN VELOCITY (from --vzero setting):' |
| 242 |
if (.not.allocated(dat) .or. size(dat(1,:,1)) < ivx+ndimV-1) then |
| 243 |
print*,' INTERNAL ERROR: dat not allocated in adjust_data_codeunits' |
| 244 |
return |
| 245 |
endif |
| 246 |
do i=1,ndimV |
| 247 |
print "(4x,a,es10.3)",trim(label(ivx+i-1))//' = '//trim(label(ivx+i-1))//' - ',v0(i) |
| 248 |
dat(:,ivx+i-1,:) = dat(:,ivx+i-1,:) - v0(i) |
| 249 |
enddo |
| 250 |
endif |
| 251 |
endif |
| 252 |
if (nerr /= 0) then |
| 253 |
print "(4x,a)",'WARNING: --vzero setting ignored' |
| 254 |
endif |
| 255 |
endif |
| 256 |
endif |
| 257 |
! |
| 258 |
!--fake a set of dust particles from the one-fluid dust formulation |
| 259 |
! |
| 260 |
no_dust_particles = .not.got_particles_of_type('dust',labeltype,npartoftype) |
| 261 |
if (idustfrac > 0 .and. irho > 0 .and. no_dust_particles) then |
| 262 |
if (UseFakeDustParticles) then |
| 263 |
call fake_twofluids(1,nstepsinfile(ifileopen),ndim,ndimV,dat,npartoftype,iamtype) |
| 264 |
elseif (iverbose >= 1) then |
| 265 |
print "(a)",' One fluid dust: set option in d) menu to make fake dust particles' |
| 266 |
endif |
| 267 |
endif |
| 268 |
|
| 269 |
! |
| 270 |
!--phase fold column 1 with a given period |
| 271 |
! |
| 272 |
period = renvironment('SPLASH_PHASEFOLD') |
| 273 |
if (period > 0.) then |
| 274 |
print "(a,es10.3)",' PHASE FOLDING column 1 with period of ',period |
| 275 |
dat(:,1,1) = dat(:,1,1) - period*int(dat(:,1,1)/period) |
| 276 |
endif |
| 277 |
|
| 278 |
if (ndim >= 1 .and. (lenvironment('SPLASH_GETH') .or. lenvironment('SPLASH_GET_H'))) then |
| 279 |
call get_h_on_all_particles(dat,npartoftype,nstepsinfile(ifileopen),ndim,ncolumns) |
| 280 |
endif |
| 281 |
|
| 282 |
end subroutine adjust_data_codeunits |
| 283 |
|
| 284 |
!----------------------------------------------------------------- |
| 285 |
! routine to rotate particles with a given cylindrical angle dphi |
| 286 |
!----------------------------------------------------------------- |
| 287 |
pure subroutine rotate_particles(dat,np,dphi,domega,x0,ndim,ndimV,v0) |
| 288 |
use labels, only:ix,ivx |
| 289 |
integer, intent(in) :: np,ndim,ndimV |
| 290 |
real, intent(in) :: dphi,domega |
| 291 |
real, dimension(:,:), intent(inout) :: dat |
| 292 |
real, dimension(ndim), intent(in) :: x0 |
| 293 |
real, dimension(ndimV), intent(in) :: v0 |
| 294 |
real, dimension(ndim) :: xi |
| 295 |
real, dimension(ndimV) :: vi |
| 296 |
real :: r,phi,xnew,ynew,cosp,sinp,vr,vphi |
| 297 |
integer :: i |
| 298 |
|
| 299 |
!--rotate positions |
| 300 |
do i=1,np |
| 301 |
xi = dat(i,ix(1:ndim)) - x0(1:ndim) |
| 302 |
r = sqrt(xi(1)**2 + xi(2)**2) |
| 303 |
phi = atan2(xi(2),xi(1)) |
| 304 |
phi = phi + dphi |
| 305 |
cosp = cos(phi) |
| 306 |
sinp = sin(phi) |
| 307 |
xnew = r*cosp |
| 308 |
ynew = r*sinp |
| 309 |
dat(i,ix(1)) = xnew |
| 310 |
dat(i,ix(2)) = ynew |
| 311 |
!--rotate velocities, if present |
| 312 |
if (ivx > 0) then |
| 313 |
vi = dat(i,ivx:ivx+ndimV-1) - v0 |
| 314 |
vr = vi(1)*xi(1)/r + vi(2)*xi(2)/r |
| 315 |
vphi = (vi(1)*(-xi(2)/r) + vi(2)*xi(1)/r) !- r*domega |
| 316 |
dat(i,ivx) = vr*cosp - vphi*sinp |
| 317 |
dat(i,ivx+1) = vr*sinp + vphi*cosp |
| 318 |
endif |
| 319 |
enddo |
| 320 |
|
| 321 |
end subroutine rotate_particles |
| 322 |
|
| 323 |
!------------------------------------------------------ |
| 324 |
! routine to centre particle positions and velocities |
| 325 |
! on a particle location |
| 326 |
!------------------------------------------------------ |
| 327 |
subroutine centre_on_particle(ipart,dat,np,ndim,ndimV,ncol,dontCentreVelocity,iverbose,label,xi) |
| 328 |
use labels, only:ix,ivx |
| 329 |
integer, intent(in) :: ipart,np,ndim,ndimV,ncol,iverbose |
| 330 |
logical, intent(in) :: dontCentreVelocity |
| 331 |
real, dimension(:,:), intent(inout) :: dat |
| 332 |
character(len=*), intent(in) :: label |
| 333 |
real, dimension(ndim), intent(out), optional :: xi |
| 334 |
real, dimension(ndim) :: x0 |
| 335 |
real, dimension(ndimV) :: v0 |
| 336 |
|
| 337 |
!--sanity check inputs |
| 338 |
if (ipart <= 0) then |
| 339 |
print "(a)",' ERROR: could not locate '//trim(label)//' particle in dat array' |
| 340 |
return |
| 341 |
endif |
| 342 |
if (ipart > np .or. ipart > size(dat(:,1))) then |
| 343 |
print "(/,a,/)",' ERROR: '//trim(label)//' particle number exceeds number of particles' |
| 344 |
return ! skip if iorigin > npart |
| 345 |
endif |
| 346 |
!--make positions relative to chosen particle |
| 347 |
x0(1:ndim) = dat(ipart,ix(1:ndim)) |
| 348 |
if (iverbose >= 1) print "(a,3(1x,es10.3))",' :: '//trim(label)//' position =',x0(1:ndim) |
| 349 |
!--make velocities relative to origin particle |
| 350 |
if ((ivx > 0 .and. ivx+ndimV-1 <= ncol) .and. (.not. dontCentreVelocity)) then |
| 351 |
v0(1:ndimV) = dat(ipart,ivx:ivx+ndimV-1) |
| 352 |
if (iverbose >= 1) print "(a,3(1x,es10.3))",' :: '//trim(label)//' velocity =',v0(1:ndimV) |
| 353 |
else |
| 354 |
v0 = 0. |
| 355 |
endif |
| 356 |
call shift_particles(dat(:,:),np,ndim,ndimV,ncol,x0,v0) |
| 357 |
|
| 358 |
! optionally return the position we shifted things to |
| 359 |
if (present(xi)) xi = x0 |
| 360 |
|
| 361 |
end subroutine centre_on_particle |
| 362 |
|
| 363 |
!------------------------------------------------------ |
| 364 |
! routine to shift particle positions and velocities |
| 365 |
! to new location |
| 366 |
!------------------------------------------------------ |
| 367 |
pure subroutine shift_particles(dat,np,ndim,ndimV,ncol,x0,v0) |
| 368 |
integer, intent(in) :: np,ndim,ndimV,ncol |
| 369 |
real, dimension(:,:), intent(inout) :: dat |
| 370 |
real, dimension(ndim), intent(in) :: x0 |
| 371 |
real, dimension(ndimV), intent(in) :: v0 |
| 372 |
|
| 373 |
call shift_positions(dat,np,ndim,x0) |
| 374 |
call shift_velocities(dat,np,ndimV,ncol,v0) |
| 375 |
|
| 376 |
end subroutine shift_particles |
| 377 |
|
| 378 |
!------------------------------------------------------ |
| 379 |
! routine to shift particle positions to new location |
| 380 |
!------------------------------------------------------ |
| 381 |
pure subroutine shift_positions(dat,np,ndim,x0) |
| 382 |
use labels, only:ix |
| 383 |
integer, intent(in) :: np,ndim |
| 384 |
real, dimension(:,:), intent(inout) :: dat |
| 385 |
real, dimension(ndim), intent(in) :: x0 |
| 386 |
integer :: icol |
| 387 |
|
| 388 |
!--shift positions |
| 389 |
do icol=1,ndim |
| 390 |
dat(1:np,ix(icol)) = dat(1:np,ix(icol)) - x0(icol) |
| 391 |
enddo |
| 392 |
|
| 393 |
end subroutine shift_positions |
| 394 |
|
| 395 |
!------------------------------------------------------ |
| 396 |
! routine to shift particle velocities by constant |
| 397 |
!------------------------------------------------------ |
| 398 |
pure subroutine shift_velocities(dat,np,ndimV,ncol,v0) |
| 399 |
use labels, only:ivx |
| 400 |
integer, intent(in) :: np,ndimV,ncol |
| 401 |
real, dimension(:,:), intent(inout) :: dat |
| 402 |
real, dimension(ndimV), intent(in) :: v0 |
| 403 |
integer :: icol |
| 404 |
|
| 405 |
!--make velocities relative to sink particle |
| 406 |
if (ivx > 0 .and. ivx+ndimV-1 <= ncol) then |
| 407 |
do icol=1,ndimV |
| 408 |
dat(1:np,ivx+icol-1) = dat(1:np,ivx+icol-1) - v0(icol) |
| 409 |
enddo |
| 410 |
endif |
| 411 |
|
| 412 |
end subroutine shift_velocities |
| 413 |
|
| 414 |
!------------------------------------------------------ |
| 415 |
! |
| 416 |
! routine to fake a set of dust particles from |
| 417 |
! the one fluid dust method |
| 418 |
! |
| 419 |
!------------------------------------------------------ |
| 420 |
subroutine fake_twofluids(istart,iend,ndim,ndimV,dat,npartoftype,iamtype) |
| 421 |
use params, only:int1 |
| 422 |
use labels, only:idustfrac,irho,ix,ih,ipmass,ivx,ideltav |
| 423 |
use mem_allocation, only:alloc |
| 424 |
use particle_data, only:maxpart,maxstep,maxcol |
| 425 |
use settings_data, only:iverbose,ndusttypes,idustfrac_plot,ideltav_plot |
| 426 |
integer, intent(in) :: istart,iend,ndim,ndimV |
| 427 |
real, dimension(:,:,:), intent(inout), allocatable :: dat |
| 428 |
integer, dimension(:,:), intent(inout), allocatable :: npartoftype |
| 429 |
integer(int1), dimension(:,:), intent(inout), allocatable :: iamtype |
| 430 |
integer :: ndust,jdust,ntoti,i,j |
| 431 |
integer :: idustfrac_temp,ideltav_temp |
| 432 |
real :: rhodust,rhogas,rhotot,dustfraci,gasfraci,pmassgas,pmassdust,pmassj |
| 433 |
real, dimension(ndimV) :: veli,vgas,vdust,deltav |
| 434 |
logical :: use_vels |
| 435 |
|
| 436 |
if (idustfrac > 0 .and. irho > 0) then |
| 437 |
! |
| 438 |
!--determine which dust fraction is being used to create the fake dust particles |
| 439 |
! |
| 440 |
!if (iverbose >= 0) print*,' got dustfrac in column ',idustfrac |
| 441 |
if (ndusttypes>1) then |
| 442 |
if (idustfrac_plot == 0 ) then |
| 443 |
idustfrac_temp = idustfrac |
| 444 |
idustfrac_plot = idustfrac_plot |
| 445 |
ideltav_temp = ideltav |
| 446 |
ideltav_plot = ideltav |
| 447 |
else |
| 448 |
idustfrac_temp = idustfrac_plot |
| 449 |
ideltav_temp = ideltav_plot |
| 450 |
endif |
| 451 |
else |
| 452 |
idustfrac_temp = idustfrac |
| 453 |
ideltav_temp = ideltav |
| 454 |
endif |
| 455 |
! |
| 456 |
!--create explicit dust phase from gas and one-fluid dust properties |
| 457 |
! |
| 458 |
do i=istart,iend |
| 459 |
ntoti = sum(npartoftype(:,i)) |
| 460 |
if (.not.allocated(dat) .or. (ntoti + npartoftype(1,i)) > maxpart) then |
| 461 |
call alloc(ntoti + npartoftype(1,i),maxstep,maxcol,mixedtypes=.true.) |
| 462 |
endif |
| 463 |
if (npartoftype(2,i) > 0) cycle |
| 464 |
ndust = 0 |
| 465 |
!--zero the properties of newly created dust particles |
| 466 |
dat(ntoti+1:ntoti+npartoftype(1,i),:,i) = 0. |
| 467 |
if (idustfrac_temp > size(dat(1,:,1)) .or. idustfrac_temp <= 0) then |
| 468 |
print*,' ERROR: idustfrac out of range: cannot create fake dust particles' |
| 469 |
return |
| 470 |
endif |
| 471 |
use_vels = (ideltav_temp > 0 .and. ivx > 0 .and. ndimV > 0) |
| 472 |
do j=1,ntoti |
| 473 |
if (iamtype(j,i)==1) then |
| 474 |
ndust = ndust + 1 ! one dust particle for every gas particle |
| 475 |
rhotot = dat(j,irho,i) |
| 476 |
dustfraci = dat(j,idustfrac_temp,i) |
| 477 |
gasfraci = 1. - dustfraci |
| 478 |
rhogas = rhotot*gasfraci |
| 479 |
rhodust = rhotot*dustfraci |
| 480 |
!--replace global properties with gas-only stuff |
| 481 |
dat(j,irho,i) = rhogas |
| 482 |
dat(j,idustfrac,i) = 0. ! dust fraction = 0 on gas particles |
| 483 |
!--copy x, smoothing length onto dust particle |
| 484 |
jdust = ntoti + ndust |
| 485 |
|
| 486 |
!--fill in dust properties |
| 487 |
if (ndim > 0) dat(jdust,ix(1:ndim),i) = dat(j,ix(1:ndim),i) |
| 488 |
if (ih > 0) dat(jdust,ih,i) = dat(j,ih,i) |
| 489 |
if (irho > 0) dat(jdust,irho,i) = rhodust |
| 490 |
dat(jdust,idustfrac,i) = 1. ! dust fraction = 1 on dust particles |
| 491 |
iamtype(ntoti + ndust,i) = 2 |
| 492 |
|
| 493 |
!--particle masses |
| 494 |
if (ipmass > 0) then |
| 495 |
pmassj = dat(j,ipmass,i) |
| 496 |
pmassgas = pmassj*gasfraci |
| 497 |
pmassdust = pmassj*dustfraci |
| 498 |
dat(j,ipmass,i) = pmassgas |
| 499 |
dat(jdust,ipmass,i) = pmassdust |
| 500 |
endif |
| 501 |
|
| 502 |
!--velocities |
| 503 |
if (use_vels) then |
| 504 |
veli(:) = dat(j,ivx:ivx+ndimV-1,i) |
| 505 |
deltav(:) = dat(j,ideltav_temp:ideltav_temp+ndimV-1,i) |
| 506 |
vgas(:) = veli(:) - (1. - gasfraci)*deltav(:) |
| 507 |
vdust(:) = veli(:) + gasfraci*deltav(:) |
| 508 |
dat(j,ivx:ivx+ndimV-1,i) = vgas(:) |
| 509 |
dat(jdust,ivx:ivx+ndimV-1,i) = vdust(:) |
| 510 |
if (ideltav /= 0) then |
| 511 |
!--set deltav to zero on gas and dust particles |
| 512 |
dat(j,ideltav_temp:ideltav_temp+ndimV-1,i) = deltav(:) |
| 513 |
dat(jdust,ideltav:ideltav+ndimV-1,i) = deltav(:) |
| 514 |
endif |
| 515 |
!if (abs(deltav(1)) > 0.3) print*,' particle ',j,'->',jdust,' vg = ',vgas(:),' vd = ',vdust(:),' v = ',veli,deltav |
| 516 |
endif |
| 517 |
endif |
| 518 |
enddo |
| 519 |
if (iverbose >= 1) then |
| 520 |
print "(a,i8,a)",' Creating ',ndust,' fake dust particles' |
| 521 |
if (.not.use_vels .and. ivx > 0) print "(a)",' WARNING: deltav not found in one fluid dust data: cannot get vels' |
| 522 |
endif |
| 523 |
npartoftype(2,i) = npartoftype(2,i) + ndust |
| 524 |
enddo |
| 525 |
else |
| 526 |
print "(a)",' ERROR: could not locate dust-to-gas ratio and/or density' |
| 527 |
endif |
| 528 |
|
| 529 |
end subroutine fake_twofluids |
| 530 |
|
| 531 |
subroutine get_h_on_all_particles(dat,npartoftype,nsteps,ndim,ncol) |
| 532 |
use labels, only:ih,irho,ix,label,ipmass |
| 533 |
use get_h, only:compute_h_and_density |
| 534 |
integer, intent(in) :: npartoftype(:,:),nsteps,ndim,ncol |
| 535 |
real, dimension(:,:,:), intent(inout) :: dat |
| 536 |
real, allocatable :: x(:,:),h(:),rho(:) |
| 537 |
integer :: i,j,ntot |
| 538 |
! |
| 539 |
!--compute h for the dataset if not already present |
| 540 |
! |
| 541 |
if (ih == 0 .and. ncol > 1) then |
| 542 |
ih = ncol - 1 |
| 543 |
label(ih) = 'h' |
| 544 |
endif |
| 545 |
if (irho == 0 .and. ncol > 2 .and. ipmass > 0) then |
| 546 |
irho = ncol - 2 |
| 547 |
label(irho) = 'rho' |
| 548 |
endif |
| 549 |
if (ih < 0) return |
| 550 |
do j=1,nsteps |
| 551 |
ntot = sum(npartoftype(:,j)) |
| 552 |
allocate(x(ndim,ntot),h(ntot),rho(ntot)) |
| 553 |
do i=ix(1),ix(ndim) |
| 554 |
x(i,1:ntot) = dat(1:ntot,i,j) |
| 555 |
enddo |
| 556 |
h = 0. |
| 557 |
rho = 0. |
| 558 |
call compute_h_and_density(ndim,ntot,1.0,x,h,rho) |
| 559 |
dat(1:ntot,ih,j) = h |
| 560 |
if (irho==ncol-2 .and. ipmass > 0) dat(1:ntot,irho,j) = rho(1:ntot)*dat(1:ntot,ipmass,j) |
| 561 |
enddo |
| 562 |
|
| 563 |
end subroutine get_h_on_all_particles |
| 564 |
|
| 565 |
end module adjustdata |