Indicator subroutine to determine if a position is in a region where the plasma parameter and fields are valid/known
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=Float64), | intent(in), | dimension(3) | :: | xyz | Position in beam coordinates |
|
logical, | intent(out) | :: | inp | Indicates whether plasma parameters and fields are valid/known |
||
integer, | intent(in), | optional | :: | input_coords | Indicates coordinate system of xyz. Beam grid (0), machine (1) and cylindrical (2) |
|
type(InterpolCoeffs3D), | intent(out), | optional | :: | coeffs | Interpolation coefficients used in calculation |
|
real(kind=Float64), | intent(out), | optional | dimension(3) | :: | uvw_out | Position in machine coordinates |
subroutine in_plasma(xyz, inp, input_coords, coeffs, uvw_out)
!+ Indicator subroutine to determine if a position is in a region where
!+ the plasma parameter and fields are valid/known
real(Float64), dimension(3), intent(in) :: xyz
!+ Position in beam coordinates
logical, intent(out) :: inp
!+ Indicates whether plasma parameters and fields are valid/known
integer, intent(in), optional :: input_coords
!+ Indicates coordinate system of xyz. Beam grid (0), machine (1) and cylindrical (2)
type(InterpolCoeffs3D), intent(out), optional :: coeffs
!+ Interpolation coefficients used in calculation
real(Float64), dimension(3), intent(out), optional :: uvw_out
!+ Position in machine coordinates
real(Float64), dimension(3) :: uvw
type(InterpolCoeffs3D) :: b
real(Float64) :: R, W, mask
real(Float64) :: phi
integer :: i, j, k, k2, err, ics
err = 1
if(present(input_coords)) then
ics = input_coords
else
ics = 0
endif
if(ics.eq.0) then
call xyz_to_uvw(xyz,uvw)
endif
if(ics.eq.1) then
uvw = xyz
endif
if(ics.eq.2) then
call cyl_to_uvw(xyz,uvw)
endif
R = sqrt(uvw(1)*uvw(1) + uvw(2)*uvw(2))
W = uvw(3)
phi = atan2(uvw(2),uvw(1))
!! Interpolate mask value
call interpol_coeff(inter_grid%r, inter_grid%z, inter_grid%phi, R, W, phi, b, err)
inp = .False.
if(err.eq.0) then
i = b%i
j = b%j
k = b%k
if(inter_grid%nphi .eq. 1) then
k2 = min(k+1,inter_grid%nphi)
else
k2 = k+1
endif
mask = b%b111*equil%mask(i,j,k) + b%b112*equil%mask(i,j,k2) + &
b%b121*equil%mask(i,j+1,k) + b%b122*equil%mask(i,j+1,k2) + &
b%b211*equil%mask(i+1,j,k) + b%b212*equil%mask(i+1,j,k2) + &
b%b221*equil%mask(i+1,j+1,k) + b%b222*equil%mask(i+1,j+1,k2)
if((mask.ge.0.5).and.(err.eq.0)) then
inp = .True.
endif
endif
if(present(coeffs)) coeffs = b
if(present(uvw_out)) uvw_out = uvw
end subroutine in_plasma