Subroutine that initializes the gyro-angle distribution of the particles.
When evolving the particles in the 6-D phase space, in addition to the position (3 degrees of freedom), energy (one degree of freedom), pitch angle (one degree of freedom), we need to define the gyro-angle of the particle (one degree of freedom), which is given by the pitch angle and the direction of the local magnetic field. By default, this subroutine generates a uniform gyro-angle distribution.
Notice that all the simulation variables are normalized here.
Call to subroutine unitVectors in korc_fields.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(KORC_PARAMS), | intent(in) | :: | params | Core KORC simulation parameters. |
||
type(FIELDS), | intent(in) | :: | F | An instance of the KORC derived type FIELDS. This structure has the information of the magnetic field. |
||
type(SPECIES), | intent(inout) | :: | spp | An instance of the derived type SPECIES containing all the parameters and simulation variables of the different species in the simulation. |
subroutine gyro_distribution(params,F,spp)
USE, INTRINSIC :: iso_c_binding
!! @Note Subroutine that initializes the gyro-angle distribution
!! of the particles. @endnote
!! When evolving the particles in the 6-D phase space, in addition to
!! the position (3 degrees of freedom), energy (one degree of freedom),
!! pitch angle (one degree of freedom), we need to define the gyro-angle
!! of the particle (one degree of freedom), which is given by the pitch
!! angle and the direction of the local magnetic field. By default, this
!! subroutine generates a uniform gyro-angle distribution.
!! @note Notice that all the simulation variables are normalized
!! here. @endnote
TYPE(KORC_PARAMS), INTENT(IN) :: params
!! Core KORC simulation parameters.
TYPE(FIELDS), INTENT(IN) :: F
!! An instance of the KORC derived type FIELDS. This structure
!! has the information of the magnetic field.
TYPE(SPECIES), INTENT(INOUT) :: spp
!! An instance of the derived type SPECIES containing all the
!! parameters and
!! simulation variables of the different species in the simulation.
REAL(rp), DIMENSION(:,:), ALLOCATABLE :: b1
!! Basis vector pointing along the local magnetic field, that is,
!! along \(\mathbf{b} = \mathbf{B}/B\).
REAL(rp), DIMENSION(:,:), ALLOCATABLE :: b2
!! Basis vector perpendicular to b1
REAL(rp), DIMENSION(:,:), ALLOCATABLE :: b3
!! Basis vector perpendicular to b1 and b2.
REAL(rp), DIMENSION(:), ALLOCATABLE :: Vo
!! Initial particle speed.
REAL(rp), DIMENSION(:), ALLOCATABLE :: V1
!! Velocity component along b1.
REAL(rp), DIMENSION(:), ALLOCATABLE :: V2
!! Velocity component along b2.
REAL(rp), DIMENSION(:), ALLOCATABLE :: V3
!! Velocity component along b3.
REAL(rp), DIMENSION(:), ALLOCATABLE :: theta
!! Uniform random number in the interval \([0,2\pi]\)
!! representing the gyro-angle.
INTEGER :: jj
!! Particle iterator.
TYPE(C_PTR), DIMENSION(:), ALLOCATABLE :: hint
ALLOCATE(Vo(spp%ppp))
ALLOCATE(V1(spp%ppp))
ALLOCATE(V2(spp%ppp))
ALLOCATE(V3(spp%ppp))
ALLOCATE(b1(spp%ppp,3))
ALLOCATE(b2(spp%ppp,3))
ALLOCATE(b3(spp%ppp,3))
ALLOCATE(hint(spp%ppp))
hint=C_NULL_PTR
#ifdef FIO
hint=spp%vars%hint
#endif
ALLOCATE( theta(spp%ppp) )
! * * * * INITIALIZE VELOCITY * * * *
call init_random_seed()
call RANDOM_NUMBER(theta)
theta = 2.0_rp*C_PI*theta
if (spp%spatial_distribution.eq.'TRACER') theta=2.0*C_PI
Vo = SQRT( 1.0_rp - 1.0_rp/(spp%vars%g(:)**2) )
V1 = Vo*COS(C_PI*spp%vars%eta/180.0_rp)
V2 = Vo*SIN(C_PI*spp%vars%eta/180.0_rp)*COS(theta)
V3 = Vo*SIN(C_PI*spp%vars%eta/180.0_rp)*SIN(theta)
!write(6,*) 'V123',V1,V2,V3
!do jj=1_idef,spp%ppp
! write(6,*) 'MPI',params%mpi_params%rank,'X', &
! spp%vars%X(jj,:)*params%cpp%length
!end do
call unitVectors(params,spp%vars%X,F,b1,b2,b3,spp%vars%flagCon, &
spp%vars%cart,hint)
!! Call to subroutine [[unitVectors]] in [[korc_fields]].
!
!write(6,*) 'X',spp%vars%X
!write(6,*) 'b-hat',b1
!write(6,*) 'b-1',b2
!write(6,*) 'b-2',b3
do jj=1_idef,spp%ppp
if ( spp%vars%flagCon(jj) .EQ. 1_idef ) then
spp%vars%V(jj,1) = V1(jj)*b1(jj,1) + V2(jj)*b2(jj,1) + V3(jj)*b3(jj,1)
spp%vars%V(jj,2) = V1(jj)*b1(jj,2) + V2(jj)*b2(jj,2) + V3(jj)*b3(jj,2)
spp%vars%V(jj,3) = V1(jj)*b1(jj,3) + V2(jj)*b2(jj,3) + V3(jj)*b3(jj,3)
end if
end do
!write(6,'("Vx: ",E17.10)') spp%vars%V(:,1)
!write(6,'("Vy: ",E17.10)') spp%vars%V(:,2)
!write(6,'("Vz: ",E17.10)') spp%vars%V(:,3)
DEALLOCATE(theta)
DEALLOCATE(Vo)
DEALLOCATE(V1)
DEALLOCATE(V2)
DEALLOCATE(V3)
DEALLOCATE(b1)
DEALLOCATE(b2)
DEALLOCATE(b3)
DEALLOCATE(hint)
end subroutine gyro_distribution