ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
Cell.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 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#ifndef CORE_CELL_HPP
20#define CORE_CELL_HPP
21
22#include "Particle.hpp"
23#include "ParticleList.hpp"
24
25#include <utils/Span.hpp>
26
27#include <boost/range/iterator_range.hpp>
28
29#include <algorithm>
30#include <utility>
31#include <vector>
32
33template <class CellRef> class Neighbors {
34 using storage_type = std::vector<CellRef>;
35
36public:
37 using value_type = typename storage_type::value_type;
38 using iterator = typename storage_type::iterator;
39 using const_iterator = typename storage_type::const_iterator;
40 using cell_range = boost::iterator_range<iterator>;
41
42private:
43 void copy(const Neighbors &rhs) {
44 m_neighbors = rhs.m_neighbors;
45 m_red_black_divider =
46 m_neighbors.begin() +
47 std::distance(rhs.m_neighbors.begin(),
48 const_iterator(rhs.m_red_black_divider));
49 }
50
51public:
52 Neighbors() = default;
53 Neighbors(const Neighbors &rhs) { copy(rhs); }
55 copy(rhs);
56 return *this;
57 }
58
60 Utils::Span<const CellRef> black_neighbors) {
61 m_neighbors.resize(red_neighbors.size() + black_neighbors.size());
62 m_red_black_divider = std::copy(red_neighbors.begin(), red_neighbors.end(),
63 m_neighbors.begin());
64 std::copy(black_neighbors.begin(), black_neighbors.end(),
65 m_red_black_divider);
66 }
67
68 /**
69 * @brief All neighbors.
70 */
71 cell_range all() { return {m_neighbors.begin(), m_neighbors.end()}; }
72 /**
73 * @brief Red partition of neighbors.
74 *
75 * An partition of the neighbors so that iterating over all
76 * neighbors_red of all cells visits every pair exactly once.
77 * Complement of neighbors_black.
78 */
79 cell_range red() { return {m_neighbors.begin(), m_red_black_divider}; }
80 /**
81 * @brief Black partition of neighbors.
82 *
83 * An partition of the neighbors so that iterating over all
84 * neighbors_black of all cells visits every pair exactly once.
85 * Complement of neighbors_red.
86 */
87 cell_range black() { return {m_red_black_divider, m_neighbors.end()}; }
88
89private:
90 /** Container with all the neighbors.
91 Red neighbors are first, black second. */
92 storage_type m_neighbors;
93 /** Iterator pointing to the first black neighbor
94 in the container. */
95 iterator m_red_black_divider;
96};
97
98class Cell {
100
101 ParticleList m_particles;
102
103public:
104 /** Particles */
105 auto &particles() { return m_particles; }
106 auto const &particles() const { return m_particles; }
107
109
110 /** Interaction pairs */
111 std::vector<std::pair<Particle *, Particle *>> m_verlet_list;
112
113 /**
114 * @brief All neighbors of the cell.
115 */
117};
118
119#endif
Definition Cell.hpp:98
neighbors_type m_neighbors
Definition Cell.hpp:108
std::vector< std::pair< Particle *, Particle * > > m_verlet_list
Interaction pairs.
Definition Cell.hpp:111
auto & particles()
Particles.
Definition Cell.hpp:105
neighbors_type & neighbors()
All neighbors of the cell.
Definition Cell.hpp:116
auto const & particles() const
Definition Cell.hpp:106
typename storage_type::value_type value_type
Definition Cell.hpp:37
typename storage_type::const_iterator const_iterator
Definition Cell.hpp:39
Neighbors & operator=(const Neighbors &rhs)
Definition Cell.hpp:54
Neighbors(Utils::Span< const CellRef > red_neighbors, Utils::Span< const CellRef > black_neighbors)
Definition Cell.hpp:59
cell_range black()
Black partition of neighbors.
Definition Cell.hpp:87
Neighbors(const Neighbors &rhs)
Definition Cell.hpp:53
cell_range all()
All neighbors.
Definition Cell.hpp:71
boost::iterator_range< iterator > cell_range
Definition Cell.hpp:40
cell_range red()
Red partition of neighbors.
Definition Cell.hpp:79
Neighbors()=default
typename storage_type::iterator iterator
Definition Cell.hpp:38
A stripped-down version of std::span from C++17.
Definition Span.hpp:38
DEVICE_QUALIFIER constexpr size_type size() const
Definition Span.hpp:86
DEVICE_QUALIFIER constexpr iterator end() const
Definition Span.hpp:91
DEVICE_QUALIFIER constexpr iterator begin() const
Definition Span.hpp:89