ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ParticlePropertyIterator.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2023 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include "BoxGeometry.hpp"
23#include "Particle.hpp"
24#include "ParticleRange.hpp"
25
26#include <boost/iterator/transform_iterator.hpp>
27#include <boost/range/iterator_range.hpp>
28
29#include <utils/Vector.hpp>
30
32
33namespace detail {
34template <class Kernel>
35auto create_transform_range(ParticleRange const &particles, Kernel kernel) {
36 auto transform_iterator_begin =
37 boost::make_transform_iterator(particles.begin(), kernel);
38 auto transform_iterator_end =
39 boost::make_transform_iterator(particles.end(), kernel);
40 return boost::make_iterator_range<decltype(transform_iterator_begin)>(
41 transform_iterator_begin, transform_iterator_end);
42}
43} // namespace detail
44
45inline auto unfolded_pos_range(ParticleRange const &particles,
46 BoxGeometry const &box) {
47 auto return_unfolded_pos = [&box](Particle &p) {
48 return ::detail::unfolded_position(p.pos(), p.image_box(), box.length());
49 };
50 return detail::create_transform_range(particles, return_unfolded_pos);
51}
52
53inline auto pos_range(ParticleRange const &particles) {
54 auto return_pos = [](Particle &p) -> Utils::Vector3d & { return p.pos(); };
55 return detail::create_transform_range(particles, return_pos);
56}
57
58inline auto charge_range(ParticleRange const &particles) {
59 auto return_charge = [](Particle &p) -> double & { return p.q(); };
60 return detail::create_transform_range(particles, return_charge);
61}
62
63inline auto force_range(ParticleRange const &particles) {
64 auto return_force = [](Particle &p) -> Utils::Vector3d & {
65 return p.force();
66 };
67 return detail::create_transform_range(particles, return_force);
68}
69
70} // namespace ParticlePropertyRange
Vector implementation and trait types for boost qvm interoperability.
Utils::Vector3d const & length() const
Box length.
A range of particles.
auto charge_range(ParticleRange const &particles)
auto pos_range(ParticleRange const &particles)
auto force_range(ParticleRange const &particles)
auto unfolded_pos_range(ParticleRange const &particles, BoxGeometry const &box)
Struct holding all information for one particle.
Definition Particle.hpp:395