-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Particle property ranges, remove ParticleRanges from P3M (#4737)
Partial fix for #4721, closes #4696 Description of changes: - Implements the `ParticlePropertyRange` struct containing static methods to transform a `ParticleRange` to a `boost::iterator_range` of properties of the particles, such as `ForceRange` or `ParticleRange`, which can then be used in range-based for-loops. The refactoring of the P3M part is not finished yet, but I think this PR could also be extended to remove the ParticleRanges from the remaining Coulomb interactions.
- Loading branch information
Showing
2 changed files
with
102 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (C) 2023 The ESPResSo project | ||
* | ||
* This file is part of ESPResSo. | ||
* | ||
* ESPResSo is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* ESPResSo is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "BoxGeometry.hpp" | ||
#include "Particle.hpp" | ||
#include "ParticleRange.hpp" | ||
|
||
#include <boost/iterator/transform_iterator.hpp> | ||
#include <boost/range/iterator_range.hpp> | ||
|
||
#include <utils/Vector.hpp> | ||
|
||
namespace ParticlePropertyRange { | ||
|
||
namespace detail { | ||
template <class Kernel> | ||
auto create_transform_range(ParticleRange const &particles, Kernel kernel) { | ||
auto transform_iterator_begin = | ||
boost::make_transform_iterator(particles.begin(), kernel); | ||
auto transform_iterator_end = | ||
boost::make_transform_iterator(particles.end(), kernel); | ||
return boost::make_iterator_range<decltype(transform_iterator_begin)>( | ||
transform_iterator_begin, transform_iterator_end); | ||
} | ||
} // namespace detail | ||
|
||
auto unfolded_pos_range(ParticleRange const &particles, | ||
BoxGeometry const &box) { | ||
auto return_unfolded_pos = [&box](Particle &p) { | ||
return ::detail::unfolded_position(p.pos(), p.image_box(), box.length()); | ||
}; | ||
return detail::create_transform_range(particles, return_unfolded_pos); | ||
} | ||
|
||
auto charge_range(ParticleRange const &particles) { | ||
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 detail::create_transform_range(particles, return_force); | ||
} | ||
|
||
} // namespace ParticlePropertyRange |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters