Loading [MathJax]/extensions/TeX/AMSmath.js
ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
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 auto const res = std::ranges::copy(red_neighbors, m_neighbors.begin());
62 m_red_black_divider = res.out;
63 std::ranges::copy(black_neighbors, m_red_black_divider);
64 }
65
66 /**
67 * @brief All neighbors.
68 */
69 cell_range all() { return {m_neighbors.begin(), m_neighbors.end()}; }
70 /**
71 * @brief Red partition of neighbors.
72 *
73 * An partition of the neighbors so that iterating over all
74 * neighbors_red of all cells visits every pair exactly once.
75 * Complement of neighbors_black.
76 */
77 cell_range red() { return {m_neighbors.begin(), m_red_black_divider}; }
78 /**
79 * @brief Black partition of neighbors.
80 *
81 * An partition of the neighbors so that iterating over all
82 * neighbors_black of all cells visits every pair exactly once.
83 * Complement of neighbors_red.
84 */
85 cell_range black() { return {m_red_black_divider, m_neighbors.end()}; }
86
87private:
88 /** Container with all the neighbors.
89 Red neighbors are first, black second. */
90 storage_type m_neighbors;
91 /** Iterator pointing to the first black neighbor
92 in the container. */
93 iterator m_red_black_divider;
94};
95
96class Cell {
98
99 ParticleList m_particles;
100
101public:
102 /** Particles */
103 auto &particles() { return m_particles; }
104 auto const &particles() const { return m_particles; }
105
107
108 /** Interaction pairs */
109 std::vector<std::pair<Particle *, Particle *>> m_verlet_list;
110
111 /**
112 * @brief All neighbors of the cell.
113 */
115};
116
117#endif
Definition Cell.hpp:96
neighbors_type m_neighbors
Definition Cell.hpp:106
std::vector< std::pair< Particle *, Particle * > > m_verlet_list
Interaction pairs.
Definition Cell.hpp:109
auto & particles()
Particles.
Definition Cell.hpp:103
neighbors_type & neighbors()
All neighbors of the cell.
Definition Cell.hpp:114
auto const & particles() const
Definition Cell.hpp:104
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:85
Neighbors(const Neighbors &rhs)
Definition Cell.hpp:52
cell_range all()
All neighbors.
Definition Cell.hpp:69
boost::iterator_range< iterator > cell_range
Definition Cell.hpp:39
cell_range red()
Red partition of neighbors.
Definition Cell.hpp:77
Neighbors()=default
typename storage_type::iterator iterator
Definition Cell.hpp:37