@brief Subroutine for interpolating the pre-computed, 3-D magnetic field to the particles' position.
@param[in] Y Particles' position in cylindrical coordinates, Y(1,:) = , Y(2,:) = , and Y(3,:) = . @param[in,out] B Cartesian components of interpolated magnetic field components. B(1,:)=, B(2,:)=, and B(3,:)=. @param F Cylindrical components of interpolated magnetic field components. F(1,:)=, F(2,:)=, and F(3,:)=. @param flag Flag that indicates whether particles are followed in the simulation (flag=1), or not (flag=0). @param pp Particle iterator. @param ss Species iterator.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(KORC_PARAMS), | intent(in) | :: | params | |||
real(kind=rp), | intent(in), | DIMENSION(:,:), ALLOCATABLE | :: | Y | ||
real(kind=rp), | intent(inout), | DIMENSION(:,:), ALLOCATABLE | :: | B | ||
integer(kind=is), | intent(inout), | DIMENSION(:), ALLOCATABLE | :: | flag |
subroutine interp_3D_bfields(params,Y,B,flag)
TYPE(KORC_PARAMS), INTENT(IN) :: params
REAL(rp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) :: Y
REAL(rp), DIMENSION(:,:), ALLOCATABLE, INTENT(INOUT) :: B
REAL(rp), DIMENSION(:,:), ALLOCATABLE :: F
INTEGER(is), DIMENSION(:), ALLOCATABLE, INTENT(INOUT) :: flag
INTEGER :: pp
INTEGER :: ss
ss = size(Y,1)
ALLOCATE(F(ss,3))
!$OMP PARALLEL DO FIRSTPRIVATE(ss) PRIVATE(pp,ezerr) &
!$OMP& SHARED(F,Y,B,flag,bfield_3d)
do pp=1_idef,ss
if ( flag(pp) .EQ. 1_is ) then
call EZspline_interp(bfield_3d%R, Y(pp,1), Y(pp,2), Y(pp,3), &
F(pp,1), ezerr)
call EZspline_error(ezerr)
if (ezerr .NE. 0) then ! We flag the particle as lost
flag(pp) = 0_is
end if
call EZspline_interp(bfield_3d%PHI, Y(pp,1), Y(pp,2), Y(pp,3), &
F(pp,2), ezerr)
call EZspline_error(ezerr)
call EZspline_interp(bfield_3d%Z, Y(pp,1), Y(pp,2), Y(pp,3), &
F(pp,3), ezerr)
call EZspline_error(ezerr)
if (.not.params%GC_coords) then
B(pp,1) = F(pp,1)*COS(Y(pp,2)) - F(pp,2)*SIN(Y(pp,2))
B(pp,2) = F(pp,1)*SIN(Y(pp,2)) + F(pp,2)*COS(Y(pp,2))
B(pp,3) = F(pp,3)
else
B(pp,1) = F(pp,1)
B(pp,2) = F(pp,2)
B(pp,3) = F(pp,3)
end if
end if
end do
!$OMP END PARALLEL DO
DEALLOCATE(F)
end subroutine interp_3D_bfields