84 if (m_type_index.empty())
87 auto const local_forces = local_type_forces(particles);
88 auto const local_masses = local_type_masses(particles);
91 std::vector<Utils::Vector3d> forces(m_type_index.size(),
Utils::Vector3d{});
92 std::vector<double> masses(m_type_index.size(), 0.0);
95 boost::mpi::all_reduce(
::comm_cart, local_forces.data(),
96 static_cast<int>(local_forces.size()), forces.data(),
97 std::plus<Utils::Vector3d>{});
98 boost::mpi::all_reduce(
::comm_cart, local_masses.data(),
99 static_cast<int>(local_masses.size()), masses.data(),
100 std::plus<double>{});
102 for (
auto &p : particles) {
104 auto it = m_type_index.find(p.type());
105 if (it != m_type_index.end()) {
106 auto const mass_frac = p.mass() / masses[it->second];
107 auto const &type_force = forces[it->second];
108 for (
unsigned int i = 0u; i < 3u; i++) {
109 p.force()[i] -= mass_frac * type_force[i];