gyro_distribution Subroutine

private subroutine gyro_distribution(params, F, spp)

Uses

  • proc~~gyro_distribution~~UsesGraph proc~gyro_distribution gyro_distribution iso_c_binding iso_c_binding proc~gyro_distribution->iso_c_binding

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.

Call to subroutine unitVectors in korc_fields.

Arguments

Type IntentOptional AttributesName
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.


Calls

proc~~gyro_distribution~~CallsGraph proc~gyro_distribution gyro_distribution proc~init_random_seed init_random_seed proc~gyro_distribution->proc~init_random_seed proc~unitvectors unitVectors proc~gyro_distribution->proc~unitvectors proc~cross~2 cross proc~unitvectors->proc~cross~2 init_random_seed init_random_seed proc~unitvectors->init_random_seed proc~get_fields get_fields proc~unitvectors->proc~get_fields proc~get_analytical_fields get_analytical_fields proc~get_fields->proc~get_analytical_fields proc~interp_fields interp_fields proc~get_fields->proc~interp_fields proc~uniform_fields uniform_fields proc~get_fields->proc~uniform_fields proc~cyl_check_if_confined cyl_check_if_confined proc~get_analytical_fields->proc~cyl_check_if_confined proc~analytical_fields analytical_fields proc~get_analytical_fields->proc~analytical_fields proc~cart_to_tor_check_if_confined cart_to_tor_check_if_confined proc~get_analytical_fields->proc~cart_to_tor_check_if_confined proc~cart_to_cyl cart_to_cyl proc~get_analytical_fields->proc~cart_to_cyl proc~analytical_fields_gc analytical_fields_GC proc~get_analytical_fields->proc~analytical_fields_gc proc~analytical_fields_gc_init analytical_fields_GC_init proc~get_analytical_fields->proc~analytical_fields_gc_init proc~interp_3d_bfields interp_3D_bfields proc~interp_fields->proc~interp_3d_bfields proc~get_fio_vector_potential get_fio_vector_potential proc~interp_fields->proc~get_fio_vector_potential proc~gradient_2d_bfields gradient_2D_Bfields proc~interp_fields->proc~gradient_2d_bfields proc~interp_3d_efields interp_3D_efields proc~interp_fields->proc~interp_3d_efields proc~interp_fofields_aorsa interp_FOfields_aorsa proc~interp_fields->proc~interp_fofields_aorsa proc~interp_2d_efields interp_2D_efields proc~interp_fields->proc~interp_2d_efields proc~interp_fofields_mars interp_FOfields_mars proc~interp_fields->proc~interp_fofields_mars proc~interp_2d_curlbfields interp_2D_curlbfields proc~interp_fields->proc~interp_2d_curlbfields proc~calculate_magnetic_field calculate_magnetic_field proc~interp_fields->proc~calculate_magnetic_field proc~get_fio_magnetic_fields get_fio_magnetic_fields proc~interp_fields->proc~get_fio_magnetic_fields proc~korc_abort korc_abort proc~interp_fields->proc~korc_abort proc~interp_2d_gradbfields interp_2D_gradBfields proc~interp_fields->proc~interp_2d_gradbfields proc~check_if_in_lcfs check_if_in_LCFS proc~interp_fields->proc~check_if_in_lcfs proc~get_fio_electric_fields get_fio_electric_fields proc~interp_fields->proc~get_fio_electric_fields proc~check_if_in_fields_domain check_if_in_fields_domain proc~interp_fields->proc~check_if_in_fields_domain proc~interp_2d_bfields interp_2D_bfields proc~interp_fields->proc~interp_2d_bfields proc~uniform_magnetic_field uniform_magnetic_field proc~uniform_fields->proc~uniform_magnetic_field proc~uniform_electric_field uniform_electric_field proc~uniform_fields->proc~uniform_electric_field ezspline_error ezspline_error proc~interp_3d_bfields->ezspline_error interface~fio_eval_field fio_eval_field proc~get_fio_vector_potential->interface~fio_eval_field proc~gradient_2d_bfields->ezspline_error proc~interp_3d_efields->ezspline_error proc~interp_fofields_aorsa->ezspline_error ezspline_interp ezspline_interp proc~interp_fofields_aorsa->ezspline_interp proc~interp_2d_efields->ezspline_error proc~interp_fofields_mars->ezspline_error proc~interp_fofields_mars->ezspline_interp proc~interp_2d_curlbfields->ezspline_error proc~calculate_magnetic_field->ezspline_error proc~get_fio_magnetic_fields->interface~fio_eval_field omp_get_thread_num omp_get_thread_num proc~get_fio_magnetic_fields->omp_get_thread_num mpi_abort mpi_abort proc~korc_abort->mpi_abort proc~interp_2d_gradbfields->ezspline_error proc~get_fio_electric_fields->interface~fio_eval_field proc~interp_2d_bfields->ezspline_error

Contents

Source Code


Source Code

  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