get_fields Subroutine

public subroutine get_fields(fields, pos, ind, machine_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

logical, intent(in), optional :: machine_coords

Indicates that pos is machine coordinates


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~in_plasma in_plasma proc~get_fields->proc~in_plasma interface~interpol_coeff interpol_coeff proc~in_plasma->interface~interpol_coeff proc~xyz_to_uvw xyz_to_uvw proc~in_plasma->proc~xyz_to_uvw proc~interpol2d_coeff interpol2D_coeff interface~interpol_coeff->proc~interpol2d_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~interpol1d_coeff_arr interpol1D_coeff_arr interface~interpol_coeff->proc~interpol1d_coeff_arr proc~interpol2d_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~store_fw_photons store_fw_photons proc~store_fw_photons->proc~get_fields proc~store_npa store_npa proc~store_npa->proc~get_fields proc~fida_weights_los fida_weights_los proc~fida_weights_los->proc~get_fields proc~neutron_mc neutron_mc proc~neutron_mc->proc~get_fields proc~read_npa read_npa proc~read_npa->proc~get_fields proc~npa_mc npa_mc proc~npa_mc->proc~get_fields proc~npa_mc->proc~store_npa proc~store_bes_photons store_bes_photons proc~store_bes_photons->proc~get_fields proc~neutron_f neutron_f proc~neutron_f->proc~get_fields proc~npa_weights npa_weights proc~npa_weights->proc~get_fields proc~mc_fastion mc_fastion proc~mc_fastion->proc~get_fields proc~store_fida_photons store_fida_photons proc~store_fida_photons->proc~get_fields proc~fida_weights_mc fida_weights_mc proc~fida_weights_mc->proc~get_fields proc~fida_f fida_f proc~fida_f->proc~mc_fastion proc~npa_f npa_f proc~npa_f->proc~store_npa proc~npa_f->proc~mc_fastion program~fidasim fidasim program~fidasim->proc~fida_mc program~fidasim->proc~fida_weights_los program~fidasim->proc~neutron_mc program~fidasim->proc~read_npa program~fidasim->proc~npa_mc program~fidasim->proc~neutron_f program~fidasim->proc~npa_weights program~fidasim->proc~fida_weights_mc program~fidasim->proc~fida_f program~fidasim->proc~npa_f

Contents

Source Code


Source Code

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