interp_fields Subroutine

public subroutine interp_fields(params, prtcls, F)

Arguments

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

Core KORC simulation parameters.

type(PARTICLES), intent(inout) :: prtcls

An instance of PARTICLES containing the variables of a given species.

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

An instance of KORC's derived type FIELDS containing all the information about the fields used in the simulation. See korc_types and korc_fields.


Contents

Source Code


Source Code

subroutine interp_fields(params,prtcls,F)
  !! @note Subroutine that works as an interface for calling the 
  !! appropriate subroutines for interpolating or calculating the 
  !! electric and magnetic fields. @endnote
  TYPE(KORC_PARAMS), INTENT(IN)      :: params
    !! Core KORC simulation parameters.
  TYPE(PARTICLES), INTENT(INOUT) :: prtcls
    !! An instance of PARTICLES containing the variables of a given species.
  TYPE(FIELDS), INTENT(IN)       :: F
    !! An instance of KORC's derived type FIELDS containing all the 
    !! information about the fields used in the simulation.
    !! See [[korc_types]] and [[korc_fields]].
  
  if (.not.params%GC_coords) call cart_to_cyl(prtcls%X,prtcls%Y)
  
!  write(6,'("BR: ",E17.10)') prtcls%BR(:,1)
!  write(6,'("Y: ",E17.10)') prtcls%X(2,1)
!  write(6,'("Z: ",E17.10)') prtcls%X(3,1)
  
  call check_if_in_fields_domain(F,prtcls%Y, prtcls%flag)

  !write(6,*) 'checked domain'

  if ((ALLOCATED(F%PSIp).and.F%Bflux).or.F%ReInterp_2x1t) then

!     write(6,'("3 size of PSI_P: ",I16)') size(prtcls%PSI_P)

!     write(6,'("B_X: ",E17.10)') prtcls%B(:,1)
!     write(6,'("B_Z: ",E17.10)') prtcls%B(:,3)
!     write(6,'("B_Y: ",E17.10)') prtcls%B(:,2)
!     write(6,'("PSI_P: ",E17.10)') prtcls%PSI_P
     
     call calculate_magnetic_field(params,prtcls%Y,F,prtcls%B,prtcls%E, &
          prtcls%PSI_P,prtcls%flag)

     !write(6,*) 'interp PSIp'
     
!     write(6,'("interp_fields")')
!     write(6,'("B_X: ",E17.10)') prtcls%B(:,1)
!     write(6,'("B_Z: ",E17.10)') prtcls%B(:,3)
!     write(6,'("B_Y: ",E17.10)') prtcls%B(:,2)

  end if

  if (ALLOCATED(F%PSIp3D).and.F%Bflux3D) then

!     write(6,'("3 size of PSI_P: ",I16)') size(prtcls%PSI_P)

!     write(6,'("B_X: ",E17.10)') prtcls%B(:,1)
!     write(6,'("B_Z: ",E17.10)') prtcls%B(:,3)
!     write(6,'("B_Y: ",E17.10)') prtcls%B(:,2)
!     write(6,'("PSI_P: ",E17.10)') prtcls%PSI_P
     
     call calculate_magnetic_field(params,prtcls%Y,F,prtcls%B,prtcls%E, &
          prtcls%PSI_P,prtcls%flag)

!     write(6,'("interp_fields")')
!     write(6,'("B_X: ",E17.10)') prtcls%B(:,1)
!     write(6,'("B_Z: ",E17.10)') prtcls%B(:,3)
!     write(6,'("B_Y: ",E17.10)') prtcls%B(:,2)

  end if
  
  if (ALLOCATED(F%B_2D%R).and.F%Bfield) then
     call interp_2D_bfields(params,prtcls%Y,prtcls%B,prtcls%flag)
  end if

  if (ALLOCATED(F%B_3D%R).and.F%Bfield) then
     call interp_3D_bfields(params,prtcls%Y,prtcls%B,prtcls%flag)
  end if

!  if (ALLOCATED(F%E_2D%R).and.F%Efield) then
!     call interp_2D_efields(params,prtcls%Y,prtcls%E,prtcls%flag)
!  end if

  if (ALLOCATED(F%E_3D%R).and.F%Efield.and.(.not.F%ReInterp_2x1t)) then
     call interp_3D_efields(params,prtcls%Y,prtcls%E,prtcls%flag)
     
  end if

  if (ALLOCATED(F%E_3D%R).and.F%Efield.and.F%ReInterp_2x1t) then
     call interp_2D_efields(params,prtcls%Y,prtcls%E,prtcls%flag)

!     write(6,*) 'interpolated efield'
     
  end if
  
  if (params%GC_coords.and.ALLOCATED(F%gradB_2D%R).and.F%Bfield) then
     call interp_2D_gradBfields(prtcls%Y,prtcls%gradB,prtcls%flag)

  end if

  if (params%GC_coords.and.ALLOCATED(F%gradB_2D%R).and.F%Bfield) then
     call interp_2D_curlbfields(prtcls%Y,prtcls%curlb,prtcls%flag)
  end if

  if(params%GC_coords.and.params%orbit_model(3:6)=='grad') then
     call gradient_2D_bfields(prtcls%Y,prtcls%BR,prtcls%BPHI, &
          prtcls%BZ,prtcls%flag)
  end if
  
end subroutine interp_fields