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
cells.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22/**
23 * @file
24 * This file contains everything related to the global cell structure / cell
25 * system.
26 *
27 * The cell system (@ref CellStructure) describes how particles are
28 * distributed on the cells and how particles of different cells
29 * (regardless if they reside on the same or different nodes)
30 * interact with each other. The following cell systems are implemented:
31 *
32 * - regular decomposition: The simulation box is divided spatially
33 * into cells (see @ref RegularDecomposition.hpp). This is suitable for
34 * short-range interactions.
35 * - N-square: The particles are distributed equally on all nodes
36 * regardless their spatial position (see @ref AtomDecomposition.hpp).
37 * This is suitable for long-range interactions that cannot be treated
38 * by a special method like P3M.
39 * - hybrid decomposition: Initializes both regular decomposition
40 * and N-square at the same time and is given a set of particle types
41 * @c n_square_types (see @ref HybridDecomposition.hpp). By default,
42 * particles will be distributed using the regular decomposition.
43 * For particles of the types defined as @c n_square_types the N-square
44 * method is used. This is suitable for systems containing lots of small
45 * particles with short-range interactions mixed with a few large
46 * particles with long-range interactions. There, the large particles
47 * should be treated using N-square.
48 */
49
50#pragma once
51
52#include "cell_system/Cell.hpp"
55
56#include "BoxGeometry.hpp"
57#include "Particle.hpp"
58#include "system/System.hpp"
59
60#include <utils/Vector.hpp>
61
62#include <optional>
63#include <utility>
64#include <vector>
65
66/**
67 * @brief Get pairs closer than @p distance from the cells.
68 *
69 * Pairs are sorted so that first.id < second.id
70 */
71std::vector<std::pair<int, int>> get_pairs(System::System const &system,
72 double distance);
73
74/**
75 * @brief Get pairs closer than @p distance if both their types are in @p types
76 *
77 * Pairs are sorted so that first.id < second.id
78 */
79std::vector<std::pair<int, int>>
80get_pairs_of_types(System::System const &system, double distance,
81 std::vector<int> const &types);
82
83/**
84 * @brief Get ids of particles that are within a certain distance
85 * of another particle.
86 */
87std::optional<std::vector<int>>
88get_short_range_neighbors(System::System const &system, int pid,
89 double distance);
90
92 NeighborPIDs() = default;
93 NeighborPIDs(int _pid, std::vector<int> _neighbor_pids)
94 : pid{_pid}, neighbor_pids{std::move(_neighbor_pids)} {}
95
96 int pid;
97 std::vector<int> neighbor_pids;
98};
99
100namespace boost {
101namespace serialization {
102template <class Archive>
103void serialize(Archive &ar, NeighborPIDs &n, unsigned int const /* version */) {
104 ar & n.pid;
105 ar & n.neighbor_pids;
106}
107} // namespace serialization
108} // namespace boost
109
110/**
111 * @brief Returns pairs of particle ids and neighbor particle id lists.
112 */
113std::vector<NeighborPIDs> get_neighbor_pids(System::System const &system);
114
115class PairInfo {
116public:
117 PairInfo() = default;
118 PairInfo(int _id1, int _id2, Utils::Vector3d _pos1, Utils::Vector3d _pos2,
119 Utils::Vector3d _vec21, int _node)
120 : id1(_id1), id2(_id2), pos1(_pos1), pos2(_pos2), vec21(_vec21),
121 node(_node) {}
122 int id1;
123 int id2;
127 int node;
128};
129
130namespace boost {
131namespace serialization {
132template <class Archive>
133void serialize(Archive &ar, PairInfo &p, unsigned int const /* version */) {
134 ar & p.id1;
135 ar & p.id2;
136 ar & p.pos1;
137 ar & p.pos2;
138 ar & p.vec21;
139 ar & p.node;
140}
141} // namespace serialization
142} // namespace boost
143
144/**
145 * @brief Returns pairs of particle ids, positions and distance as seen by the
146 * non-bonded loop.
147 */
148std::vector<PairInfo> non_bonded_loop_trace(System::System const &system,
149 int rank);
Vector implementation and trait types for boost qvm interoperability.
std::vector< std::pair< int, int > > get_pairs(System::System const &system, double distance)
Get pairs closer than distance from the cells.
Definition cells.cpp:159
std::optional< std::vector< int > > get_short_range_neighbors(System::System const &system, int pid, double distance)
Get ids of particles that are within a certain distance of another particle.
Definition cells.cpp:119
std::vector< std::pair< int, int > > get_pairs_of_types(System::System const &system, double distance, std::vector< int > const &types)
Get pairs closer than distance if both their types are in types.
Definition cells.cpp:167
std::vector< NeighborPIDs > get_neighbor_pids(System::System const &system)
Returns pairs of particle ids and neighbor particle id lists.
Definition cells.cpp:188
std::vector< PairInfo > non_bonded_loop_trace(System::System const &system, int rank)
Returns pairs of particle ids, positions and distance as seen by the non-bonded loop.
Definition cells.cpp:176
PairInfo(int _id1, int _id2, Utils::Vector3d _pos1, Utils::Vector3d _pos2, Utils::Vector3d _vec21, int _node)
Definition cells.hpp:118
int id1
Definition cells.hpp:122
Utils::Vector3d vec21
Definition cells.hpp:126
PairInfo()=default
Utils::Vector3d pos2
Definition cells.hpp:125
Utils::Vector3d pos1
Definition cells.hpp:124
int node
Definition cells.hpp:127
int id2
Definition cells.hpp:123
Main system class.
void serialize(Archive &ar, std::tuple< T... > &pack, unsigned int const)
Serialize std::tuple.
std::vector< int > neighbor_pids
Definition cells.hpp:97
NeighborPIDs()=default
NeighborPIDs(int _pid, std::vector< int > _neighbor_pids)
Definition cells.hpp:93