Subroutine that calculates the mean electric or magnetic field in case external fields are being used.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(FIELDS), | intent(in) | :: | F | An instance of the KORC derived type FIELDS. |
||
real(kind=rp), | intent(out) | :: | Fo | Mean electric or magnetic field. |
||
type(KORC_STRING), | intent(in) | :: | op_field | String that specifies what mean field will be calculated. Its value can be 'B' or 'E'. |
subroutine mean_F_field(F,Fo,op_field)
!! @note Subroutine that calculates the mean electric or magnetic field in
!! case external fields are being used. @endnote
TYPE(FIELDS), INTENT(IN) :: F
!! An instance of the KORC derived type FIELDS.
REAL(rp), INTENT(OUT) :: Fo
!! Mean electric or magnetic field.
TYPE(KORC_STRING), INTENT(IN) :: op_field
!!String that specifies what mean field will be calculated.
!! Its value can be 'B' or 'E'.
if (TRIM(op_field%str) .EQ. 'B') then
if (ALLOCATED(F%B_3D%R)) then ! 3D field
Fo = SUM( SQRT(F%B_3D%R**2 + F%B_3D%PHI**2 + F%B_3D%Z**2) )/ &
SIZE(F%B_3D%R)
else if (ALLOCATED(F%B_2D%R)) then ! Axisymmetric 2D field
Fo = SUM( SQRT(F%B_2D%R**2 + F%B_2D%PHI**2 + F%B_2D%Z**2) )/ &
SIZE(F%B_2D%R)
end if
else if (TRIM(op_field%str) .EQ. 'E') then
if (ALLOCATED(F%E_3D%R)) then ! 3D field
Fo = SUM( SQRT(F%E_3D%R**2 + F%E_3D%PHI**2 + F%E_3D%Z**2) )/ &
SIZE(F%E_3D%R)
else if (ALLOCATED(F%E_2D%R)) then ! Axisymmetric 2D field
Fo = SUM( SQRT(F%E_2D%R**2 + F%E_2D%PHI**2 + F%E_2D%Z**2) )/ &
SIZE(F%E_2D%R)
end if
else
write(output_unit_write,'("KORC ERROR: Please enter a valid field: mean_F_field")')
call korc_abort(17)
end if
end subroutine mean_F_field