Gets electro-magnetic fields at position pos
or beam_grid indices ind
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(LocalEMFields), | intent(out) | :: | fields | Electro-magnetic fields at |
||
real(kind=Float64), | intent(in), | optional | dimension(3) | :: | pos | Position in beam grid coordinates |
integer(kind=Int32), | intent(in), | optional | dimension(3) | :: | ind | beam_grid indices |
logical, | intent(in), | optional | :: | machine_coords | Indicates that pos is machine coordinates |
subroutine get_fields(fields, pos, ind, machine_coords)
!+ Gets electro-magnetic fields at position `pos` or [[libfida:beam_grid]] indices `ind`
type(LocalEMFields),intent(out) :: fields
!+ Electro-magnetic fields at `pos`/`ind`
real(Float64), dimension(3), intent(in), optional :: pos
!+ Position in beam grid coordinates
integer(Int32), dimension(3), intent(in), optional :: ind
!+ [[libfida:beam_grid]] indices
logical, intent(in), optional :: machine_coords
!+ Indicates that pos is machine coordinates
logical :: inp, mc
real(Float64), dimension(3) :: xyz, uvw
real(Float64), dimension(3) :: uvw_bfield, uvw_efield
real(Float64), dimension(3) :: xyz_bfield, xyz_efield
real(Float64) :: phi, s, c
type(InterpolCoeffs2D) :: coeffs
integer :: i, j
fields%in_plasma = .False.
if(present(ind)) call get_position(ind,xyz)
if(present(pos)) xyz = pos
mc = .False.
if(present(machine_coords)) mc = machine_coords
call in_plasma(xyz,inp,mc,coeffs,uvw)
if(inp) then
phi = atan2(uvw(2),uvw(1))
i = coeffs%i
j = coeffs%j
fields = coeffs%b11*equil%fields(i,j) + coeffs%b12*equil%fields(i,j+1) + &
coeffs%b21*equil%fields(i+1,j) + coeffs%b22*equil%fields(i+1,j+1)
phi = atan2(uvw(2),uvw(1))
s = sin(phi) ; c = cos(phi)
!Convert cylindrical coordinates to uvw
uvw_bfield(1) = c*fields%br - s*fields%bt
uvw_bfield(2) = s*fields%br + c*fields%bt
uvw_bfield(3) = fields%bz
uvw_efield(1) = c*fields%er - s*fields%et
uvw_efield(2) = s*fields%er + c*fields%et
uvw_efield(3) = fields%ez
if(mc) then
xyz_bfield = uvw_bfield
xyz_efield = uvw_efield
else
!Represent fields in beam grid coordinates
xyz_bfield = matmul(beam_grid%inv_basis,uvw_bfield)
xyz_efield = matmul(beam_grid%inv_basis,uvw_efield)
endif
!Calculate field directions and magnitudes
fields%b_abs = norm2(xyz_bfield)
fields%e_abs = norm2(xyz_efield)
if(fields%b_abs.gt.0.d0) fields%b_norm = xyz_bfield/fields%b_abs
if(fields%e_abs.gt.0.d0) fields%e_norm = xyz_efield/fields%e_abs
call calc_perp_vectors(fields%b_norm,fields%a_norm,fields%c_norm)
fields%pos = xyz
fields%uvw = uvw
fields%in_plasma = .True.
fields%machine_coords = mc
fields%c = coeffs
endif
end subroutine get_fields