get_fields Subroutine

public subroutine get_fields(fields, pos, ind, input_coords, output_coords)

Gets electro-magnetic fields at position pos or beam_grid indices ind

Arguments

Type IntentOptional AttributesName
type(LocalEMFields), intent(out) :: fields

Electro-magnetic fields at pos/ind

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

integer(kind=Int32), intent(in), optional :: input_coords

Indicates coordinate system of inputs. Beam grid (0), machine (1) and cylindrical (2)

integer(kind=Int32), intent(in), optional :: output_coords

Indicates coordinate system of outputs. Beam grid (0), machine (1) and cylindrical (2)


Calls

proc~~get_fields~~CallsGraph proc~get_fields get_fields proc~calc_perp_vectors calc_perp_vectors proc~get_fields->proc~calc_perp_vectors proc~uvw_to_xyz uvw_to_xyz proc~get_fields->proc~uvw_to_xyz proc~in_plasma in_plasma proc~get_fields->proc~in_plasma proc~xyz_to_uvw xyz_to_uvw proc~get_fields->proc~xyz_to_uvw proc~in_plasma->proc~xyz_to_uvw proc~cyl_to_uvw cyl_to_uvw proc~in_plasma->proc~cyl_to_uvw interface~interpol_coeff interpol_coeff proc~in_plasma->interface~interpol_coeff proc~cyl_interpol3d_coeff cyl_interpol3D_coeff interface~interpol_coeff->proc~cyl_interpol3d_coeff proc~interpol1d_coeff interpol1D_coeff interface~interpol_coeff->proc~interpol1d_coeff proc~interpol2d_coeff_arr interpol2D_coeff_arr interface~interpol_coeff->proc~interpol2d_coeff_arr proc~interpol2d_coeff interpol2D_coeff interface~interpol_coeff->proc~interpol2d_coeff proc~cyl_interpol3d_coeff_arr cyl_interpol3D_coeff_arr interface~interpol_coeff->proc~cyl_interpol3d_coeff_arr proc~interpol1d_coeff_arr interpol1D_coeff_arr interface~interpol_coeff->proc~interpol1d_coeff_arr proc~cyl_interpol3d_coeff->proc~interpol2d_coeff proc~interpol2d_coeff_arr->proc~interpol2d_coeff proc~cyl_interpol3d_coeff_arr->proc~cyl_interpol3d_coeff proc~cyl_interpol3d_coeff_arr->proc~interpol2d_coeff proc~interpol1d_coeff_arr->proc~interpol1d_coeff

Called by

proc~~get_fields~~CalledByGraph proc~get_fields get_fields proc~fida_mc fida_mc proc~fida_mc->proc~get_fields proc~track track proc~fida_mc->proc~track proc~store_photons store_photons proc~store_photons->proc~get_fields proc~track_cylindrical track_cylindrical proc~track_cylindrical->proc~get_fields proc~store_npa store_npa proc~store_npa->proc~get_fields proc~mc_fastion_pass_grid mc_fastion_pass_grid proc~mc_fastion_pass_grid->proc~get_fields proc~track->proc~get_fields proc~fida_weights_los fida_weights_los proc~fida_weights_los->proc~get_fields proc~fida_weights_los->proc~track proc~pnpa_mc pnpa_mc proc~pnpa_mc->proc~get_fields proc~pnpa_mc->proc~store_npa proc~ndmc ndmc proc~ndmc->proc~get_fields proc~ndmc->proc~track proc~make_diagnostic_grids make_diagnostic_grids proc~make_diagnostic_grids->proc~get_fields proc~make_diagnostic_grids->proc~track_cylindrical proc~make_diagnostic_grids->proc~track proc~neutron_mc neutron_mc proc~neutron_mc->proc~get_fields proc~npa_mc npa_mc proc~npa_mc->proc~get_fields proc~npa_mc->proc~store_npa proc~store_fw_photons store_fw_photons proc~store_fw_photons->proc~get_fields proc~pfida_mc pfida_mc proc~pfida_mc->proc~get_fields proc~pfida_mc->proc~track_cylindrical proc~npa_weights npa_weights proc~npa_weights->proc~get_fields proc~mc_fastion mc_fastion proc~mc_fastion->proc~get_fields proc~neutron_f neutron_f proc~neutron_f->proc~get_fields proc~fida_weights_mc fida_weights_mc proc~fida_weights_mc->proc~get_fields proc~fida_weights_mc->proc~track proc~pnpa_f pnpa_f proc~pnpa_f->proc~store_npa proc~pnpa_f->proc~mc_fastion_pass_grid proc~dcx_spec dcx_spec proc~dcx_spec->proc~store_photons proc~dcx dcx proc~dcx->proc~track proc~halo_spec halo_spec proc~halo_spec->proc~store_photons proc~fida_f fida_f proc~fida_f->proc~track proc~fida_f->proc~mc_fastion proc~cold_spec cold_spec proc~cold_spec->proc~store_photons proc~nbi_spec nbi_spec proc~nbi_spec->proc~store_photons proc~npa_f npa_f proc~npa_f->proc~store_npa proc~npa_f->proc~mc_fastion proc~halo halo proc~halo->proc~track program~fidasim fidasim program~fidasim->proc~fida_mc program~fidasim->proc~fida_weights_los program~fidasim->proc~pnpa_mc program~fidasim->proc~ndmc program~fidasim->proc~make_diagnostic_grids program~fidasim->proc~neutron_mc program~fidasim->proc~npa_mc program~fidasim->proc~pfida_mc program~fidasim->proc~npa_weights program~fidasim->proc~neutron_f program~fidasim->proc~fida_weights_mc program~fidasim->proc~pnpa_f program~fidasim->proc~dcx_spec program~fidasim->proc~dcx program~fidasim->proc~halo_spec program~fidasim->proc~fida_f program~fidasim->proc~cold_spec program~fidasim->proc~nbi_spec program~fidasim->proc~npa_f program~fidasim->proc~halo proc~pfida_f pfida_f program~fidasim->proc~pfida_f proc~store_bes_photons store_bes_photons proc~store_bes_photons->proc~store_photons proc~pfida_f->proc~track_cylindrical proc~pfida_f->proc~mc_fastion_pass_grid proc~store_fida_photons store_fida_photons proc~store_fida_photons->proc~store_photons

Contents

Source Code


Source Code

subroutine get_fields(fields, pos, ind, input_coords, output_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
    integer(Int32), intent(in), optional               :: input_coords
        !+ Indicates coordinate system of inputs. Beam grid (0), machine (1) and cylindrical (2)
    integer(Int32), intent(in), optional               :: output_coords
        !+ Indicates coordinate system of outputs. Beam grid (0), machine (1) and cylindrical (2)

    logical :: inp
    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(InterpolCoeffs3D) :: coeffs
    integer :: i, j, k, k2, mc, ocs, ics

    fields%in_plasma = .False.

    if(present(input_coords)) then
        ics = input_coords
    else
        ics = 0
    endif

    if(present(output_coords)) then
        ocs = output_coords
    else
        ocs = 0
    endif

    if(present(ind)) call get_position(ind,xyz)

    if(present(pos)) then
        if(ics.eq.0) then
            xyz = pos
            call xyz_to_uvw(xyz, uvw)
        endif
        if(ics.eq.1) then
            uvw = pos
            call uvw_to_xyz(uvw, xyz)
        endif
    endif

    call in_plasma(xyz,inp,0,coeffs)
    if(inp) then
        i = coeffs%i
        j = coeffs%j
        k = coeffs%k
        if(inter_grid%nphi .eq. 1) then
            k2 = min(k+1,inter_grid%nphi)
        else
            k2 = k+1
        endif

        fields = coeffs%b111*equil%fields(i,j,k)    + coeffs%b121*equil%fields(i,j+1,k) +   &
                 coeffs%b112*equil%fields(i,j,k2)   + coeffs%b122*equil%fields(i,j+1,k2) +  &
                 coeffs%b211*equil%fields(i+1,j,k)  + coeffs%b221*equil%fields(i+1,j+1,k) + &
                 coeffs%b212*equil%fields(i+1,j,k2) + coeffs%b222*equil%fields(i+1,j+1,k2)

        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(ocs.eq.0) then
            !Represent fields in beam grid coordinates
            xyz_bfield = matmul(beam_grid%inv_basis,uvw_bfield)
            xyz_efield = matmul(beam_grid%inv_basis,uvw_efield)
            fields%pos = xyz
        endif
        if(ocs.eq.1) then
            xyz_bfield = uvw_bfield
            xyz_efield = uvw_efield
            fields%pos = uvw
        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%uvw = uvw
        fields%in_plasma = .True.
        fields%coords = ocs
        fields%b = coeffs
    endif

end subroutine get_fields