gather forces acting on atoms within the system and store result in the forces matrix through pointers
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(mimic_communicator), | intent(inout) | :: | this | |||
type(subsystem_type), | intent(in), | dimension(:) | :: | frag_code | subsystem_type belonging to each code |
subroutine gather_forces(this, frag_code)
class(mimic_communicator), intent(inout) :: this
!> subsystem_type belonging to each code
type(subsystem_type), dimension(:), intent(in) :: frag_code
real(kind=dp), dimension(:), allocatable, target :: forces
type(fragment_type) :: current_fragment
integer :: code_atoms
integer :: n_code, n_fragment, n_atom
integer :: offset
do n_code = 1, this%num_clients
code_atoms = frag_code(n_code)%num_atoms
allocate(forces(code_atoms * 3))
call this%send_command(MCL_SEND_ATOM_FORCES, n_code)
call mcl_receive(forces, code_atoms * 3, MCL_DATA, n_code)
! offset = 1
do n_fragment = 1, size(frag_code(n_code)%fragments)
current_fragment = frag_code(n_code)%fragments(n_fragment)
do n_atom = 1, current_fragment%num_atoms
offset = (current_fragment%atoms(n_atom)%id - 1) * 3 + 1
current_fragment%atoms(n_atom)%force = &
& current_fragment%atoms(n_atom)%force &
& + forces(offset : offset + 2) * frag_code(n_code)%factor
! offset = offset + 3
end do ! n_atom
end do ! n_fragment
deallocate(forces)
end do ! n_code
end subroutine gather_forces