ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
HybridDecomposition.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2026 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#pragma once
23
27
28#include "cell_system/Cell.hpp"
29
30#include "BoxGeometry.hpp"
31#include "LocalBox.hpp"
32#include "Particle.hpp"
33
34#include <utils/Vector.hpp>
35
36#include <boost/mpi/communicator.hpp>
37
38#include <cstddef>
39#include <functional>
40#include <optional>
41#include <set>
42#include <span>
43#include <utility>
44#include <vector>
45
46/**
47 * @brief Hybrid decomposition cell system.
48 *
49 * Store particles with short-range interactions
50 * in a @ref RegularDecomposition cell system and
51 * particles with long-range interactions
52 * in a @ref AtomDecomposition (N-square) cell system.
53 * All regular cells are coupled to the N-square cells.
54 */
56 boost::mpi::communicator m_comm;
57 BoxGeometry const &m_box;
58 double m_cutoff_regular;
59 std::vector<Cell *> m_local_cells;
60 std::vector<Cell *> m_ghost_cells;
61
62 /**
63 * Topology-agnostic direct-neighbor halo plan (see @c make_halo_plan).
64 * Holds ParticleList pointers into this decomposition's cells.
65 * Value-copying this object leaves these pointers dangling.
66 * @todo make non-copyable or rebuild-on-copy.
67 */
68 GhostComm::HaloPlan m_halo_plan;
69
70 /** RegularDecomposition to hold the small particles */
71 RegularDecomposition m_regular_decomposition;
72 /** N-Square Decomposition to hold large particles */
73 AtomDecomposition m_n_square;
74 /** Set containing the types that should be handled using n_square */
75 std::set<int> const m_n_square_types;
76
77 std::function<bool()> m_get_global_ghost_flags;
78
79 bool is_n_square_type(int type_id) const {
80 return m_n_square_types.contains(type_id);
81 }
82
83public:
84 HybridDecomposition(boost::mpi::communicator comm, double cutoff_regular,
85 double skin, std::function<bool()> get_ghost_flags,
86 BoxGeometry const &box_geo, LocalBox const &local_box,
87 std::set<int> n_square_types);
88
89 auto get_cell_grid() const { return m_regular_decomposition.cell_grid; }
90
91 auto get_cell_size() const { return m_regular_decomposition.cell_size; }
92
93 auto get_n_square_types() const { return m_n_square_types; }
94
95 void resort(bool global, std::vector<ParticleChange> &diff) override;
96
97 auto get_cutoff_regular() const { return m_cutoff_regular; }
98
99 GhostComm::HaloPlan const *halo_plan() const override { return &m_halo_plan; }
100
101 std::span<Cell *const> local_cells() const override { return m_local_cells; }
102 std::span<Cell *const> ghost_cells() const override { return m_ghost_cells; }
103
104 Cell *particle_to_cell(Particle const &p) override {
105 if (is_n_square_type(p.type())) {
106 return m_n_square.particle_to_cell(p);
107 }
108 return m_regular_decomposition.particle_to_cell(p);
109 }
110
111 Cell const *particle_to_cell(Particle const &p) const override {
112 if (is_n_square_type(p.type())) {
113 return m_n_square.particle_to_cell(p);
114 }
115 return m_regular_decomposition.particle_to_cell(p);
116 }
117
118 Utils::Vector3d max_cutoff() const override {
119 return m_n_square.max_cutoff();
120 }
121
122 Utils::Vector3d max_range() const override { return m_n_square.max_range(); }
123
124 std::optional<BoxGeometry> minimum_image_distance() const override {
125 return m_box;
126 }
127
128 BoxGeometry const &box() const override { return m_box; }
129
130 /** @brief Count particles in child regular decompositions. */
131 std::size_t count_particles_in_regular() const {
132 return count_particles(m_regular_decomposition.get_local_cells());
133 }
134
135 /** @brief Count particles in child N-square decompositions. */
136 std::size_t count_particles_in_n_square() const {
137 return count_particles(m_n_square.get_local_cells());
138 }
139
140private:
141 /**
142 * @brief Build the plan-based halo plan combining the regular child's
143 * neighbors/local with the n-square child's collective section.
144 */
145 GhostComm::HaloPlan make_halo_plan();
146
147 std::size_t count_particles(std::vector<Cell *> const &local_cells) const;
148};
Vector implementation and trait types for boost qvm interoperability.
Atom decomposition cell system.
Utils::Vector3d max_range() const override
Utils::Vector3d max_cutoff() const override
auto const & get_local_cells() const
Cell * particle_to_cell(Particle const &p) override
Determine which cell a particle id belongs to.
Definition Cell.hpp:96
Hybrid decomposition cell system.
std::span< Cell *const > local_cells() const override
std::size_t count_particles_in_regular() const
Count particles in child regular decompositions.
GhostComm::HaloPlan const * halo_plan() const override
Utils::Vector3d max_range() const override
std::size_t count_particles_in_n_square() const
Count particles in child N-square decompositions.
Cell * particle_to_cell(Particle const &p) override
Cell const * particle_to_cell(Particle const &p) const override
void resort(bool global, std::vector< ParticleChange > &diff) override
BoxGeometry const & box() const override
Utils::Vector3d max_cutoff() const override
std::optional< BoxGeometry > minimum_image_distance() const override
std::span< Cell *const > ghost_cells() const override
A distributed particle decomposition.
Struct holding all information for one particle.
Definition Particle.hpp:436
constexpr auto const & type() const
Definition Particle.hpp:459
Regular decomposition cell system.
Cell * particle_to_cell(Particle const &p) override
Utils::Vector3d cell_size
Cell size.
auto const & get_local_cells() const
Utils::Vector3i cell_grid
Grid dimensions per node.