Skip to content

Commit

Permalink
add suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
jhossbach committed Oct 24, 2023
1 parent 81694f8 commit d0d4964
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
27 changes: 10 additions & 17 deletions src/core/ParticlePropertyIterator.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2022 The ESPResSo project
* Copyright (C) 2023 The ESPResSo project
*
* This file is part of ESPResSo.
*
Expand All @@ -16,21 +16,21 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ESPRESSO_SRC_CORE_PARTICLE_EXTRACT_PROPERTIES_HPP
#define ESPRESSO_SRC_CORE_PARTICLE_EXTRACT_PROPERTIES_HPP
#pragma once

#include "BoxGeometry.hpp"
#include "Particle.hpp"
#include "ParticleRange.hpp"
#include "grid.hpp"

#include <boost/iterator/transform_iterator.hpp>
#include <boost/range/iterator_range.hpp>
#include <tuple>

#include <utils/Vector.hpp>

namespace ParticlePropertyRange {

namespace {
namespace detail {
template <class Kernel>
auto create_transform_range(ParticleRange const &particles, Kernel kernel) {
auto transform_iterator_begin =
Expand All @@ -40,32 +40,25 @@ auto create_transform_range(ParticleRange const &particles, Kernel kernel) {
return boost::make_iterator_range<decltype(transform_iterator_begin)>(
transform_iterator_begin, transform_iterator_end);
}
} // namespace

auto pos_range(ParticleRange const &particles) {
auto return_pos = [](Particle &p) { return p.pos(); };
return create_transform_range(particles, return_pos);
}
} // namespace detail

auto unfolded_pos_range(ParticleRange const &particles,
BoxGeometry const &box) {
auto return_unfolded_pos = [&box](Particle &p) {
return unfolded_position(p.pos(), p.image_box(), box.length());
};
return create_transform_range(particles, return_unfolded_pos);
return detail::create_transform_range(particles, return_unfolded_pos);
}

auto charge_range(ParticleRange const &particles) {
auto return_charge = [](Particle &p) { return p.q(); };
return create_transform_range(particles, return_charge);
auto return_charge = [](Particle &p) -> double & { return p.q(); };
return detail::create_transform_range(particles, return_charge);
}
auto force_range(ParticleRange const &particles) {
auto return_force = [](Particle &p) -> Utils::Vector3d & {
return p.force();
};
return create_transform_range(particles, return_force);
return detail::create_transform_range(particles, return_force);
}

} // namespace ParticlePropertyRange

#endif
2 changes: 1 addition & 1 deletion src/core/electrostatics/p3m.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ static auto calc_dipole_moment(boost::mpi::communicator const &comm,
boost::accumulate(p_q_unfolded_pos_range, Utils::Vector3d{},
[](Utils::Vector3d dip, auto const &q_pos) {
auto const p_q = boost::get<0>(q_pos);
auto const p_unfolded_pos = boost::get<1>(q_pos);
auto const &p_unfolded_pos = boost::get<1>(q_pos);
return dip + dipole_moment(p_q, p_unfolded_pos);
});
return boost::mpi::all_reduce(comm, local_dip, std::plus<>());
Expand Down

0 comments on commit d0d4964

Please sign in to comment.