1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
|
! Copyright (C) 2005 Barbara Ercolano
!
! Version 2.02
module pathIntegration_mod
use common_mod
use interpolation_mod
use vector_mod
contains
! This subroutine performs the integration of opacities from a position
! aVec to the edge of the nebula in the arbitrary direction uHat
subroutine integratePathTau(grid, aVec, uHat, freq, nTau, absTau, lambda)
implicit none
type(grid_type), intent(in) :: grid(*) ! grid
type(vector), intent(in) :: uHat ! direction vector
type(vector), intent(in) :: aVec ! starting position vector
integer, intent(out) :: nTau ! actual size of opacity and length arrays
real, intent(in) :: freq ! the frequency [Hz]
real, intent(out), &
& dimension(maxTau) :: absTau ! absorption optical depth
real, intent(out), &
& dimension(maxTau) :: lambda ! distance array
! local variables
type(vector) :: rVec ! position vector
type(vector) :: vHat ! direction vector
integer :: freqP ! frequency index
integer :: i ! counter
integer :: xP, yP, zP ! x, y, and z axis indeces
integer, parameter :: nl = 4 ! defines the size of the distance increment
real :: dlSmall ! distance increment
if (nGrids>1) then
print*, 'integratePathTau: tau integration routine still not developed for multiple grids... returning '
return
end if
! locate the input frequency in the frequency array
call locate(nuArray(1:nbins), freq, freqP)
if (freqP<=0 .or. freqP>nbins) then
print*, "! integratePathTau: out of bounds frequency ", freqP, freq, nuArray(1), nuArray(nbins)
print*, nuArray
stop
end if
! locate the starting position in the cartesian grid
call locate(grid(1)%xAxis, aVec%x, xP)
if ( xP < grid(1)%nx ) then
if ( aVec%x >= (grid(1)%xAxis(xP)+ &
& grid(1)%xAxis(xP+1))/2. ) xP = xP+1
end if
call locate(grid(1)%yAxis, aVec%y, yP)
if ( yP < grid(1)%ny ) then
if ( aVec%y >= (grid(1)%yAxis(yP)+ &
& grid(1)%yAxis(yP+1))/2. ) yP = yP+1
end if
call locate(grid(1)%zAxis, aVec%z, zP)
if ( zP < grid(1)%nz ) then
if ( aVec%z >= (grid(1)%zAxis(zP)+ &
& grid(1)%zAxis(zP+1))/2. ) zP = zP+1
end if
! check that the input position is not outside the grid
if ( (xP <= 0).or.(xP > grid(1)%nx) ) then
print*, "! integratePathTau: starting position in x is outside the grid",xP,yP,zP
stop
else if ( (yP <= 0).or.(yP > grid(1)%ny) ) then
print*, "! integratePathTau: starting position in y is outside the grid",xP,yP,zP
stop
else if ( (zP <= 0).or.(zP > grid(1)%nz) ) then
print*, "! integratePathTau: starting position in z is outside the grid",xP,yP,zP
stop
end if
! define dlSmall
dlSmall = dl(1)
! initialize the optical depth arrays
absTau = 0.
lambda = 0.
! initialize nTau
nTau = 1
! initialize direction vactor
vHat = uHat
! the first optical depth are all zero (as displacement is zero)
! these have already been set to zero in the initialization of the arrays
! so add the first displacements vector (dlSmall*vHat)
rVec = aVec + dlSmall*vHat
! execute this loop until the edge of the grid is reached
do i = 1, maxTau
! check if the path is still within the ionized region
if (rVec%x > grid(1)%xAxis(grid(1)%nx)) exit
if (rVec%y > grid(1)%yAxis(grid(1)%ny)) exit
if (rVec%z > grid(1)%zAxis(grid(1)%nz)) exit
if ( sqrt( (rvec%x/1.e10)**2 + (rvec%y/1.e10)**2 + (rvec%z/1.e10)**2)*1.e10 >= R_out &
& .and. R_out > 0.) exit
if (lgSymmetricXYZ) then
if( rVec%x < grid(1)%xAxis(1) ) then
vHat%x = -vHat%x
rVec%x = -rVec%x
call locate(grid(1)%xAxis, rVec%x, xP)
end if
if( rVec%y < grid(1)%yAxis(1) ) then
vHat%y = -vHat%y
rVec%y = -rVec%y
call locate(grid(1)%yAxis, rVec%y, yP)
end if
if( rVec%z < grid(1)%zAxis(1) ) then
vHat%z = -vHat%z
rVec%z = -rVec%z
call locate(grid(1)%zAxis, rVec%z, zP)
end if
end if
! x-axis
if (xP < grid(1)%nx) then
if ( rVec%x > (grid(1)%xAxis(xP)+grid(1)%xAxis(xP+1))/2. ) then
xP = xP + 1
end if
else if (xP == grid(1)%nx) then
if ( rVec%x > grid(1)%xAxis(xP) ) exit
end if
if (xP > 1) then
if ( rVec%x < (grid(1)%xAxis(xP)+grid(1)%xAxis(xP-1))/2. ) then
xP = xP - 1
end if
end if
! y-axis
if (yP < grid(1)%ny) then
if ( rVec%y > (grid(1)%yAxis(yP)+grid(1)%yAxis(yP+1))/2. ) then
yP = yP + 1
end if
else if (yP == grid(1)%ny) then
if (rVec%y > grid(1)%yAxis(yP)) exit
end if
if (yP > 1) then
if ( rVec%y < (grid(1)%yAxis(yP)+grid(1)%yAxis(yP-1))/2. ) then
yP = yP - 1
end if
end if
! z-axis
if (zP < grid(1)%nz) then
if ( rVec%z > (grid(1)%zAxis(zP)+grid(1)%zAxis(zP+1))/2. ) then
zP = zP + 1
end if
else if (zP == grid(1)%nz) then
if (rVec%z > grid(1)%zAxis(zP)) exit
end if
if (zP > 1) then
if ( rVec%z < (grid(1)%zAxis(zP)+grid(1)%zAxis(zP-1))/2. ) then
zP = zP - 1
end if
end if
if (.not.lgSymmetricXYZ) then
if ((xP < 1) .or. (zP < 1) .or. (yP < 1)) exit
end if
! check if there's any symmetries and if the path must be reflected
if (lgSymmetricXYZ) then
if (xP<1) then
vHat%x=-vHat%x
rVec%x=-rVec%x
call locate(grid(1)%xAxis, rVec%x, xP)
if (xP < grid(1)%nx) then
if ( rVec%x > (grid(1)%xAxis(xP)+grid(1)%xAxis(xP+1))/2. ) xP = xP + 1
else if (xP == grid(1)%nx) then
if (rVec%x > grid(1)%xAxis(xP)) exit
end if
end if
if (yP<1) then
vHat%y=-vHat%y
rVec%y=-rVec%y
call locate(grid(1)%yAxis, rVec%y, yP)
if (yP < grid(1)%ny) then
if ( rVec%y > (grid(1)%yAxis(yP)+grid(1)%yAxis(yP+1))/2. ) yP = yP + 1
else if (yP == grid(1)%ny) then
if (rVec%y > grid(1)%yAxis(yP)) exit
end if
end if
if (zP<1) then
vHat%z=-vHat%z
rVec%z=-rVec%z
call locate(grid(1)%zAxis, rVec%z, zP)
if (zP < grid(1)%nz) then
if ( rVec%z > (grid(1)%zAxis(zP)+grid(1)%zAxis(zP+1))/2. ) zP = zP + 1
else if (zP == grid(1)%nz) then
if (rVec%z > grid(1)%zAxis(zP)) exit
end if
end if
end if
! increment nTau
nTau = nTau + 1
! this should never happen (as the loop is stopped at maxTau anyway)
! just a sanity check
if (nTau > maxTau) then
print*, "! integratePathTau: tau arrays are full", xP,yP,zP
exit
end if
! add the delta optical depths
absTau(nTau) = absTau(nTau-1) + grid(1)%opacity(grid(1)%active(xP,yP,zP),freqP)*dlSmall
lambda(nTau) = lambda(nTau-1) + dlSmall
! increment position by adding the displacements vector (dlSmall*vHat)
rVec = rVec + dlSmall*vHat
end do
end subroutine integratePathTau
! This subroutine performs the integration of opacities from a position
! aVec to the edge of the nebula in the arbitrary direction uHat
subroutine integratePathTauNu(grid, aVec, uHat, freqP, absTau)
implicit none
type(grid_type), intent(in) :: grid(*) ! grid
type(vector), intent(in) :: uHat ! direction vector
type(vector), intent(in) :: aVec ! starting position vector
real, intent(out) :: absTau ! extinction optical depth
! local variables
type(vector) :: rVec ! position vector
type(vector) :: vHat ! direction vector
integer, intent(in) :: freqP ! the frequency index
integer :: i ! counter
integer :: xP, yP, zP ! x, y, and z axis indeces
real :: dlSmall ! distance increment
if (nGrids>1) then
print*, 'integratePathTau: tau integration routine still not developed for multiple grids... returning '
return
end if
! locate the starting position in the cartesian grid
call locate(grid(1)%xAxis, aVec%x, xP)
if ( xP < grid(1)%nx ) then
if ( aVec%x >= (grid(1)%xAxis(xP)+ &
& grid(1)%xAxis(xP+1))/2. ) xP = xP+1
end if
call locate(grid(1)%yAxis, aVec%y, yP)
if ( yP < grid(1)%ny ) then
if ( aVec%y >= (grid(1)%yAxis(yP)+ &
& grid(1)%yAxis(yP+1))/2. ) yP = yP+1
end if
call locate(grid(1)%zAxis, aVec%z, zP)
if ( zP < grid(1)%nz ) then
if ( aVec%z >= (grid(1)%zAxis(zP)+ &
& grid(1)%zAxis(zP+1))/2. ) zP = zP+1
end if
! check that the input position is not outside the grid
if ( (xP <= 0).or.(xP > grid(1)%nx) ) then
print*, "! integratePathTau: starting position in x is outside the grid",xP,yP,zP
stop
else if ( (yP <= 0).or.(yP > grid(1)%ny) ) then
print*, "! integratePathTau: starting position in y is outside the grid",xP,yP,zP
stop
else if ( (zP <= 0).or.(zP > grid(1)%nz) ) then
print*, "! integratePathTau: starting position in z is outside the grid",xP,yP,zP
stop
end if
dlSmall = 0.
if (uHat%x > 0.) then
! find linear increment
dlSmall = abs(grid(1)%xAxis(2) - grid(1)%xAxis(1))
do i = 2, grid(1)%nx-1
dlSmall = min(dlSmall, abs(grid(1)%xAxis(i+1)-grid(1)%xAxis(i)) )
end do
end if
if (uHat%y > 0.) then
if (dlSmall <= 0.) then
! find linear increment
dlSmall = abs(grid(1)%yAxis(2) - grid(1)%yAxis(1))
do i = 2, grid(1)%ny-1
dlSmall = min(dlSmall, abs(grid(1)%yAxis(i+1)-grid(1)%yAxis(i)) )
end do
else
! find linear increment
do i = 1, grid(1)%ny-1
dlSmall = min(dlSmall, abs(grid(1)%yAxis(i+1)-grid(1)%yAxis(i)) )
end do
end if
end if
if (uHat%z > 0.) then
if (dlSmall <= 0.) then
! find linear increment
dlSmall = abs(grid(1)%zAxis(2) - grid(1)%zAxis(1))
do i = 2, grid(1)%nz-1
dlSmall = min(dlSmall, abs(grid(1)%zAxis(i+1)-grid(1)%zAxis(i)) )
end do
else
! find linear increment
do i = 1, grid(1)%nz-1
dlSmall = min(dlSmall, abs(grid(1)%zAxis(i+1)-grid(1)%zAxis(i)) )
end do
end if
end if
dlSmall = dlSmall/2.
! initialize the optical depth arrays
absTau = 0.
! initialize direction vector
vHat = uHat
! the first optical depth are all zero (as displacement is zero)
! these have already been set to zero in the initialization of the arrays
! so add the first displacements vector (dlSmall*vHat)
rVec = aVec + dlSmall*vHat
! execute this loop until the edge of the grid is reached
do i = 1, maxTau
! check if the path is still within the ionized region
if (rVec%x > grid(1)%xAxis(grid(1)%nx)) exit
if (rVec%y > grid(1)%yAxis(grid(1)%ny)) exit
if (rVec%z > grid(1)%zAxis(grid(1)%nz)) exit
if ( sqrt( (rvec%x/1.e10)**2 + (rvec%y/1.e10)**2 + (rvec%z/1.e10)**2)*1.e10 >= R_out &
& .and. R_out > 0.) exit
if (lgSymmetricXYZ) then
if( rVec%x < grid(1)%xAxis(1) ) then
vHat%x = -vHat%x
rVec%x = -rVec%x
call locate(grid(1)%xAxis, rVec%x, xP)
end if
if( rVec%y < grid(1)%yAxis(1) ) then
vHat%y = -vHat%y
rVec%y = -rVec%y
call locate(grid(1)%yAxis, rVec%y, yP)
end if
if( rVec%z < grid(1)%zAxis(1) ) then
vHat%z = -vHat%z
rVec%z = -rVec%z
call locate(grid(1)%zAxis, rVec%z, zP)
end if
end if
! x-axis
if (xP < grid(1)%nx) then
if ( rVec%x > (grid(1)%xAxis(xP)+grid(1)%xAxis(xP+1))/2. ) then
xP = xP + 1
end if
else if (xP == grid(1)%nx) then
if ( rVec%x > grid(1)%xAxis(xP) ) exit
end if
if (xP > 1) then
if ( rVec%x < (grid(1)%xAxis(xP)+grid(1)%xAxis(xP-1))/2. ) then
xP = xP - 1
end if
end if
! y-axis
if (yP < grid(1)%ny) then
if ( rVec%y > (grid(1)%yAxis(yP)+grid(1)%yAxis(yP+1))/2. ) then
yP = yP + 1
end if
else if (yP == grid(1)%ny) then
if (rVec%y > grid(1)%yAxis(yP)) exit
end if
if (yP > 1) then
if ( rVec%y < (grid(1)%yAxis(yP)+grid(1)%yAxis(yP-1))/2. ) then
yP = yP - 1
end if
end if
! z-axis
if (zP < grid(1)%nz) then
if ( rVec%z > (grid(1)%zAxis(zP)+grid(1)%zAxis(zP+1))/2. ) then
zP = zP + 1
end if
else if (zP == grid(1)%nz) then
if (rVec%z > grid(1)%zAxis(zP)) exit
end if
if (zP > 1) then
if ( rVec%z < (grid(1)%zAxis(zP)+grid(1)%zAxis(zP-1))/2. ) then
zP = zP - 1
end if
end if
if (.not.lgSymmetricXYZ) then
if ((xP < 1) .or. (zP < 1) .or. (yP < 1)) exit
end if
! check if there's any symmetries and if the path must be reflected
if (lgSymmetricXYZ) then
if (xP<1) then
vHat%x=-vHat%x
rVec%x=-rVec%x
call locate(grid(1)%xAxis, rVec%x, xP)
if (xP < grid(1)%nx) then
if ( rVec%x > (grid(1)%xAxis(xP)+grid(1)%xAxis(xP+1))/2. ) xP = xP + 1
else if (xP == grid(1)%nx) then
if (rVec%x > grid(1)%xAxis(xP)) exit
end if
end if
if (yP<1) then
vHat%y=-vHat%y
rVec%y=-rVec%y
call locate(grid(1)%yAxis, rVec%y, yP)
if (yP < grid(1)%ny) then
if ( rVec%y > (grid(1)%yAxis(yP)+grid(1)%yAxis(yP+1))/2. ) yP = yP + 1
else if (yP == grid(1)%ny) then
if (rVec%y > grid(1)%yAxis(yP)) exit
end if
end if
if (zP<1) then
vHat%z=-vHat%z
rVec%z=-rVec%z
call locate(grid(1)%zAxis, rVec%z, zP)
if (zP < grid(1)%nz) then
if ( rVec%z > (grid(1)%zAxis(zP)+grid(1)%zAxis(zP+1))/2. ) zP = zP + 1
else if (zP == grid(1)%nz) then
if (rVec%z > grid(1)%zAxis(zP)) exit
end if
end if
end if
! add the delta optical depths
absTau = absTau + grid(1)%opacity(grid(1)%active(xP,yP,zP),freqP)*dlSmall
! increment position by adding the displacements vector (dlSmall*vHat)
rVec = rVec + dlSmall*vHat
end do
end subroutine integratePathTauNu
end module pathIntegration_mod
|