compute_center_of_charge Function

public pure function compute_center_of_charge(particles) result(center_of_charge)

compute center-of-charge of a set particles

Arguments

TypeIntentOptionalAttributesName
class(particle_type), intent(in), dimension(:):: particles

Return Value real(kind=dp),dimension(3)


Contents


Source Code

pure function compute_center_of_charge(particles) result(center_of_charge)

    class(particle_type), dimension(:), intent(in) :: particles

    integer :: i
    real(dp) :: charge
    real(dp) :: total_charge
    real(dp), dimension(3) :: coordinate
    real(dp), dimension(3) :: center_of_charge

    total_charge = 0.0_dp
    center_of_charge = 0.0_dp
    do i = 1, size(particles)
        charge = particles(i)%charge
        coordinate = particles(i)%coordinate
        total_charge = total_charge + charge
        center_of_charge = center_of_charge + charge * coordinate
    end do
    center_of_charge = center_of_charge / total_charge

end function compute_center_of_charge