-
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.
add ParticlePropertyRange struct, start p3m refactor
- Loading branch information
Showing
2 changed files
with
69 additions
and
2 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,58 @@ | ||
/* | ||
* Copyright (C) 2010-2022 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/>. | ||
*/ | ||
#ifndef ESPRESSO_SRC_CORE_PARTICLE_EXTRACT_PROPERTIES_HPP | ||
#define ESPRESSO_SRC_CORE_PARTICLE_EXTRACT_PROPERTIES_HPP | ||
|
||
#include "Particle.hpp" | ||
#include "ParticleRange.hpp" | ||
#include <boost/iterator/transform_iterator.hpp> | ||
#include <boost/range/iterator_range.hpp> | ||
#include <tuple> | ||
#include <utils/Vector.hpp> | ||
|
||
struct ParticlePropertyRange { | ||
|
||
template <class Kernel> | ||
static auto create_transform_range(const ParticleRange &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); | ||
} | ||
|
||
static auto pos_range(const ParticleRange &particles) { | ||
auto return_pos = [](Particle &p) { return p.pos(); }; | ||
return create_transform_range(particles, return_pos); | ||
} | ||
|
||
static auto charge_range(const ParticleRange &particles) { | ||
auto return_charge = [](Particle &p) { return p.q(); }; | ||
return create_transform_range(particles, return_charge); | ||
} | ||
|
||
static auto force_range(const ParticleRange &particles) { | ||
auto return_force = [](Particle &p) { return p.force(); }; | ||
return create_transform_range(particles, return_force); | ||
} | ||
}; | ||
|
||
#endif |
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