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