unitVectors Subroutine

public subroutine unitVectors(params, Xo, F, b1, b2, b3, flag, cart, hint)

Arguments

Type IntentOptional AttributesName
type(KORC_PARAMS), intent(in) :: params

Core KORC simulation parameters.

real(kind=rp), intent(in), DIMENSION(:,:), ALLOCATABLE:: Xo

Array with the position of the simulated particles.

type(FIELDS), intent(in) :: F

F An instance of the KORC derived type FIELDS.

real(kind=rp), intent(inout), DIMENSION(:,:), ALLOCATABLE:: b1

Basis vector pointing along the local magnetic field, that is, along .

real(kind=rp), intent(inout), DIMENSION(:,:), ALLOCATABLE:: b2

Basis vector perpendicular to b1

real(kind=rp), intent(inout), DIMENSION(:,:), ALLOCATABLE:: b3

Basis vector perpendicular to b1 and b2.

integer(kind=is), intent(inout), optional DIMENSION(:), ALLOCATABLE:: flag

Flag for each particle to decide whether it is being followed (flag=T) or not (flag=F).

logical :: cart
type(C_PTR), intent(inout), DIMENSION(:), ALLOCATABLE:: hint

Flag for each particle to decide whether it is being followed (flag=T) or not (flag=F).


Calls

proc~~unitvectors~~CallsGraph proc~unitvectors 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

Called by

proc~~unitvectors~~CalledByGraph proc~unitvectors unitVectors proc~gyro_distribution gyro_distribution proc~gyro_distribution->proc~unitvectors

Contents

Source Code


Source Code

  subroutine unitVectors(params,Xo,F,b1,b2,b3,flag,cart,hint)
    !! @note Subrotuine that calculates an orthonormal basis using information 
    !! of the (local) magnetic field at position \(\mathbf{X}_0\). @endnote
    TYPE(KORC_PARAMS), INTENT(IN)                                      :: params
    !! Core KORC simulation parameters.
    REAL(rp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN)                  :: Xo
    !! Array with the position of the simulated particles.
    TYPE(FIELDS), INTENT(IN)                                           :: F
    !! F An instance of the KORC derived type FIELDS.
    REAL(rp), DIMENSION(:,:), ALLOCATABLE, INTENT(INOUT)               :: b1
    !! Basis vector pointing along the local magnetic field, 
    !! that is, along \(\mathbf{b} = \mathbf{B}/B\).
    REAL(rp), DIMENSION(:,:), ALLOCATABLE, INTENT(INOUT)               :: b2
    !!  Basis vector perpendicular to b1
    REAL(rp), DIMENSION(:,:), ALLOCATABLE, INTENT(INOUT)               :: b3
    !! Basis vector perpendicular to b1 and b2.
    INTEGER(is), DIMENSION(:), ALLOCATABLE, OPTIONAL, INTENT(INOUT)    :: flag
    !! Flag for each particle to decide whether it is being 
    !! followed (flag=T) or not (flag=F).
    TYPE(C_PTR), DIMENSION(:), ALLOCATABLE, INTENT(INOUT)    :: hint
    !! Flag for each particle to decide whether it is being 
    !! followed (flag=T) or not (flag=F).
    TYPE(PARTICLES)                                                    :: vars
    !! A temporary instance of the KORC derived type PARTICLES.
    INTEGER                                                            :: ii
    !! Iterator.
    INTEGER                                                            :: ppp
    !! Number of particles.
    LOGICAL :: cart
    REAL(rp), DIMENSION(3) ::b1tmp,b2tmp,b3tmp,tmpvec

!    write(output_unit_write,*) 'in unitVector'
    
    ppp = SIZE(Xo,1) ! Number of particles

    ALLOCATE( vars%X(ppp,3) )
    ALLOCATE( vars%Y(ppp,3) )
    ALLOCATE( vars%B(ppp,3) )
    ALLOCATE( vars%gradB(ppp,3) )
    ALLOCATE( vars%curlb(ppp,3) )
    ALLOCATE( vars%PSI_P(ppp) )
    ALLOCATE( vars%E(ppp,3) )
    ALLOCATE( vars%flagCon(ppp) )
    ALLOCATE( vars%initLCFS(ppp) )

#ifdef FIO
    ALLOCATE( vars%hint(ppp) )
#endif
    
    vars%X = Xo
#ifdef FIO
    vars%hint = hint
#endif
    vars%flagCon = flag
    vars%initLCFS = 0_is
    vars%B=0._rp
    vars%PSI_P=0._rp
    vars%cart=.false.
    
    !write(output_unit_write,*) 'before init_random_seed'
    
    call init_random_seed()

   ! write(output_unit_write,*) 'before get_fields'

    !write(6,*) 'before first get fields'
    call get_fields(params,vars,F)
    !write(6,*) 'before second get fields'

    !write(6,'("Bx: ",E17.10)') vars%B(:,1)*params%cpp%Bo
    !write(6,'("By: ",E17.10)') vars%B(:,2)*params%cpp%Bo
    !write(6,'("Bz: ",E17.10)') vars%B(:,3)*params%cpp%Bo

        !write(output_unit_write,*) 'before b1,b2,b3 calculation'

    tmpvec=(/1.0_rp,1.0_rp,1.0_rp/)
    
    do ii=1_idef,ppp
       !write(6,*) 'ii',ii
       if ( vars%flagCon(ii) .EQ. 1_idef ) then
          b1tmp = vars%B(ii,:)/sqrt(vars%B(ii,1)*vars%B(ii,1)+ &
               vars%B(ii,2)*vars%B(ii,2)+vars%B(ii,3)*vars%B(ii,3))

          b2tmp = cross(b1tmp,tmpvec)
          b2tmp = b2tmp/sqrt(b2tmp(1)*b2tmp(1)+b2tmp(2)*b2tmp(2)+ &
               b2tmp(3)*b2tmp(3))

          b3tmp = cross(b1tmp,b2tmp)
          b3tmp = b3tmp/sqrt(b3tmp(1)*b3tmp(1)+b3tmp(2)*b3tmp(2)+ &
               b3tmp(3)*b3tmp(3))
       end if
       b1(ii,:)=b1tmp
       b2(ii,:)=b2tmp
       b3(ii,:)=b3tmp
    end do

    !write(output_unit_write,*) 'before copying hint and flag'
#ifdef FIO
    hint = vars%hint
#endif
    
    if (PRESENT(flag)) then
       flag = vars%flagCon
    end if

    DEALLOCATE( vars%X )
    DEALLOCATE( vars%Y )
    DEALLOCATE( vars%B )
    DEALLOCATE( vars%PSI_P )
    DEALLOCATE( vars%gradB )
    DEALLOCATE( vars%curlb )
    DEALLOCATE( vars%E )
    DEALLOCATE( vars%flagCon )
#ifdef FIO
    DEALLOCATE( vars%hint)
#endif
    
    !write(output_unit_write,*) 'out unitVectors'
    
  end subroutine unitVectors