ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
CellStructure.cpp
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
23
28
29#include "BoxGeometry.hpp"
30#include "LocalBondState.hpp"
31#include "LocalBox.hpp"
32#include "Particle.hpp"
33#include "aosoa_pack.hpp"
35#include "communication.hpp"
37#include "ghosts.hpp"
42#include "system/System.hpp"
43
44#include <utils/Vector.hpp>
45#include <utils/contains.hpp>
47#include <utils/math/sqr.hpp>
48
49#ifdef ESPRESSO_CALIPER
50#include <caliper/cali.h>
51#endif
52
53#include <boost/mpi/collectives/all_reduce.hpp>
54
55#include <Cabana_Core.hpp>
56#include <Cabana_NeighborList.hpp>
57#include <Kokkos_Core.hpp>
58#include <omp.h>
59
60#include <algorithm>
61#include <cassert>
62#include <cmath>
63#include <cstddef>
64#include <cstdint>
65#include <iterator>
66#include <memory>
67#include <numbers>
68#include <optional>
69#include <ranges>
70#include <set>
71#include <stdexcept>
72#include <string>
73#include <unordered_set>
74#include <utility>
75#include <variant>
76#include <vector>
77
80 // Kokkos handle can only be freed after all Cabana containers have been freed
81 m_kokkos_handle.reset();
82}
83
85 m_local_force.reset();
86#ifdef ESPRESSO_ROTATION
87 m_local_torque.reset();
88#endif
89#ifdef ESPRESSO_NPT
90 m_local_virial.reset();
91#endif
92 m_id_to_index.reset();
93 m_aosoa.reset();
94 m_verlet_list_cabana.reset();
95 m_bond_state->clear();
96 m_rebuild_verlet_list_cabana = true;
97}
98void CellStructure::clear_bond_properties() { m_bond_state->reset(); }
99
100void CellStructure::set_kokkos_handle(std::shared_ptr<KokkosHandle> handle) {
101 m_kokkos_handle = std::move(handle);
102 m_bond_state = std::make_unique<LocalBondState>();
103}
104
105static auto estimate_max_counts(double pair_cutoff,
106 std::size_t number_of_unique_particles,
107 double local_box_volume,
108 std::size_t num_local_particles) {
109 if (std::isinf(pair_cutoff)) {
110 return number_of_unique_particles;
111 }
112 if (pair_cutoff < 0.) {
113 pair_cutoff = 0.;
114 }
115 // Estimate number of neighbors based on local density and cutoff sphere:
116 // volume n_neighbors = rho * (4/3) * pi * r^3, where rho = n_particles /
117 // volume
118 auto const local_density =
119 (local_box_volume > 0. && num_local_particles > 0)
120 ? static_cast<double>(num_local_particles) / local_box_volume
121 : 0.;
122 auto const cutoff_sphere_volume =
123 (4. / 3.) * std::numbers::pi * Utils::int_pow<3>(pair_cutoff);
124 // account for local fluctuations. Empirical.
125 auto const fluctuation_factor = 2.;
126 auto max_counts = static_cast<std::size_t>(
127 std::ceil(fluctuation_factor * local_density * cutoff_sphere_volume));
128 std::size_t constexpr threshold_num = 16;
129 if (max_counts < threshold_num) {
130 max_counts = std::min(threshold_num, number_of_unique_particles);
131 }
132 return max_counts;
133}
134
135void CellStructure::rebuild_local_properties(double const pair_cutoff) {
136#ifdef ESPRESSO_CALIPER
137 CALI_CXX_MARK_FUNCTION;
138#endif
139 assert(m_kokkos_handle);
140 using execution_space = Kokkos::DefaultExecutionSpace;
141 auto const num_threads = execution_space().concurrency();
142 auto const num_part = get_unique_particles().size();
143 auto const &system = get_system();
144 auto const local_box_volume = system.local_geo->volume();
145 auto max_counts = estimate_max_counts(pair_cutoff, num_part, local_box_volume,
147#ifdef ESPRESSO_COLLISION_DETECTION
148 if (system.has_collision_detection_enabled()) {
149 // TODO: use other types of Verlet list data structures
150 max_counts = num_part * 2ul;
151 }
152#endif
153 if (m_local_force) { // local properties are reallocated
154 Kokkos::realloc(get_local_force(), num_part, num_threads);
155#ifdef ESPRESSO_ROTATION
156 Kokkos::realloc(get_local_torque(), num_part, num_threads);
157#endif
158 Kokkos::realloc(get_id_to_index(), get_cached_max_local_particle_id() + 1);
159 Kokkos::deep_copy(get_id_to_index(), -1);
160 // Resize particle views using AoSoA_pack's resize method
161 m_aosoa->resize(num_part);
162 Kokkos::deep_copy(m_aosoa->flags, uint8_t{0});
163 m_verlet_list_cabana->reallocData(num_part, max_counts);
164 } else { // local properties are initialized
165 m_local_force =
166 std::make_unique<ForceType>("local_force", num_part, num_threads);
167#ifdef ESPRESSO_ROTATION
168 m_local_torque =
169 std::make_unique<ForceType>("local_torque", num_part, num_threads);
170#endif
171 m_id_to_index = std::make_unique<Kokkos::View<int *>>(
172 Kokkos::ViewAllocateWithoutInitializing("id_to_index"),
174 Kokkos::deep_copy(get_id_to_index(), -1);
175 // Create AoSoA_pack and initialize with resize
176 m_aosoa = std::make_unique<AoSoA_pack>();
177 m_aosoa->resize(num_part);
178 Kokkos::deep_copy(m_aosoa->flags, uint8_t{0});
179
180 m_verlet_list_cabana =
181 std::make_unique<ListType>(0ul, num_part, max_counts);
182 }
183#ifdef ESPRESSO_NPT
184 m_local_virial = std::make_unique<VirialType>("local_virial", num_threads);
185#endif
186}
187
189#ifdef ESPRESSO_CALIPER
190 CALI_CXX_MARK_FUNCTION;
191#endif
192 Kokkos::deep_copy(get_local_force(), 0.);
193}
194
196 Kokkos::deep_copy(get_local_force(), 0.);
197#ifdef ESPRESSO_ROTATION
198 Kokkos::deep_copy(get_local_torque(), 0.);
199#endif
200#ifdef ESPRESSO_NPT
201 Kokkos::deep_copy(get_local_virial(), 0.);
202#endif
203 Kokkos::deep_copy(get_aosoa().flags, uint8_t{0});
204}
205
206void CellStructure::update_bond_storage(int &pair_count, int &angle_count,
207 int &dihedral_count,
208 Particle const &p) {
209 auto &pair_list = m_bond_state->pair_list;
210 auto &pair_ids = m_bond_state->pair_ids;
211 auto &angle_list = m_bond_state->angle_list;
212 auto &angle_ids = m_bond_state->angle_ids;
213 auto &dihedral_list = m_bond_state->dihedral_list;
214 auto &dihedral_ids = m_bond_state->dihedral_ids;
215 for (auto const bond : p.bonds()) {
216 auto const partner_ids = bond.partner_ids();
217 try {
218 auto const partners = resolve_bond_partners(partner_ids);
219 if (partners.size() == 1u) { // pair bonds
220 auto p_index = Kokkos::atomic_fetch_add(&pair_count, 1);
221 pair_list(p_index, 0) = p.id();
222 pair_list(p_index, 1) = partners[0]->id();
223 pair_ids(p_index) = bond.bond_id();
224 } else if (partners.size() == 2u) { // angle bond
225 auto a_index = Kokkos::atomic_fetch_add(&angle_count, 1);
226 angle_list(a_index, 0) = p.id();
227 angle_list(a_index, 1) = partners[0]->id();
228 angle_list(a_index, 2) = partners[1]->id();
229 angle_ids(a_index) = bond.bond_id();
230 } else if (partners.size() == 3u) { // dihedral bond
231 auto d_index = Kokkos::atomic_fetch_add(&dihedral_count, 1);
232 dihedral_list(d_index, 0) = p.id();
233 dihedral_list(d_index, 1) = partners[0]->id();
234 dihedral_list(d_index, 2) = partners[1]->id();
235 dihedral_list(d_index, 3) = partners[2]->id();
236 dihedral_ids(d_index) = bond.bond_id();
237 }
238 } catch (BondResolutionError const &) {
239 bond_resolution_error(partner_ids);
240 }
241 }
242}
243
245#ifdef ESPRESSO_CALIPER
246 CALI_CXX_MARK_FUNCTION;
247#endif
248 auto &unique_particles = m_unique_particles;
249 unique_particles.clear();
250 unique_particles.resize(count_local_particles());
251 std::unordered_set<int> registered_index{};
252 using execution_space = Kokkos::DefaultExecutionSpace;
253 int n_threads = execution_space().concurrency();
254 std::vector<int> max_ids(n_threads);
255
256 m_bond_state->reset_counts();
257 std::vector<int> pair_counts(n_threads, 0);
258 std::vector<int> angle_counts(n_threads, 0);
259 std::vector<int> dihedral_counts(n_threads, 0);
260
262 *this, [&unique_particles, &max_ids, &pair_counts, &angle_counts,
263 &dihedral_counts](std::size_t index, Particle &p) {
264 unique_particles[index] = &p;
265 auto const thread_num = omp_get_thread_num();
266 max_ids[thread_num] = std::max(p.id(), max_ids[thread_num]);
267 for (auto const bond : p.bonds()) {
268 if (not bond.partner_ids().empty()) {
269 auto const partner_ids = bond.partner_ids();
270 if (partner_ids.size() == 1u) {
271 pair_counts[thread_num] += 1;
272 } else if (partner_ids.size() == 2u) {
273 angle_counts[thread_num] += 1;
274 } else if (partner_ids.size() == 3u) {
275 dihedral_counts[thread_num] += 1;
276 }
277 }
278 }
279 });
280 Kokkos::fence();
281 int pair_count = std::reduce(std::begin(pair_counts), std::end(pair_counts));
282 int angle_count =
283 std::reduce(std::begin(angle_counts), std::end(angle_counts));
284 int dihedral_count =
285 std::reduce(std::begin(dihedral_counts), std::end(dihedral_counts));
286 set_local_bond_numbers(pair_count, angle_count, dihedral_count);
287 m_bond_state->allocate();
288
289 int max_id = *(std::max_element(max_ids.begin(), max_ids.end()));
290 for (auto &p : ghost_particles()) {
291 auto const *local_particle = get_local_particle(p.id());
292 if (not local_particle) {
293 continue;
294 }
295 if (not local_particle->is_ghost()) {
296 continue;
297 }
298 if (registered_index.contains(p.id())) {
299 continue;
300 }
301 registered_index.insert(p.id());
302 unique_particles.emplace_back(&p);
303 max_id = std::max(p.id(), max_id);
304 }
305 registered_index.clear();
306 m_cached_max_local_particle_id = max_id;
307 m_num_local_particles_cached = unique_particles.size();
308}
309
311 : m_decomposition{std::make_unique<AtomDecomposition>(box)} {}
312
314 auto const max_id = get_max_local_particle_id();
315
316 for (auto const &p : local_particles()) {
317 auto const id = p.id();
318
319 if (id < 0 || id > max_id) {
320 throw std::runtime_error("Particle id out of bounds.");
321 }
322
323 if (get_local_particle(id) != &p) {
324 throw std::runtime_error("Invalid local particle index entry.");
325 }
326 }
327
328 /* checks: local particle id */
329 std::size_t local_part_cnt = 0u;
330 for (int n = 0; n < get_max_local_particle_id() + 1; n++) {
331 if (get_local_particle(n) != nullptr) {
332 local_part_cnt++;
333 if (get_local_particle(n)->id() != n) {
334 throw std::runtime_error("local_particles part has corrupted id.");
335 }
336 }
337 }
338
339 if (local_part_cnt != local_particles().size()) {
340 throw std::runtime_error(
341 std::to_string(local_particles().size()) + " parts in cells but " +
342 std::to_string(local_part_cnt) + " parts in local_particles");
343 }
344}
345
347 for (auto cell : decomposition().local_cells()) {
348 for (auto const &p : cell->particles()) {
349 if (particle_to_cell(p) != cell) {
350 throw std::runtime_error("misplaced particle with id " +
351 std::to_string(p.id()));
352 }
353 }
354 }
355}
356
358 auto remove_all_bonds_to = [id](BondList &bl) {
359 for (auto it = bl.begin(); it != bl.end();) {
360 if (Utils::contains(it->partner_ids(), id)) {
361 it = bl.erase(it);
362 } else {
363 std::advance(it, 1);
364 }
365 }
366 };
367
368 for (auto cell : decomposition().local_cells()) {
369 auto &parts = cell->particles();
370 for (auto it = parts.begin(); it != parts.end();) {
371 if (it->id() == id) {
372 it = parts.erase(it);
373 update_particle_index(id, nullptr);
375 } else {
376 remove_all_bonds_to(it->bonds());
377 it++;
378 }
379 }
380 }
381}
382
384 auto const sort_cell = particle_to_cell(p);
385 if (sort_cell) {
386 return std::addressof(
387 append_indexed_particle(sort_cell->particles(), std::move(p)));
388 }
389
390 return {};
391}
392
394 auto const sort_cell = particle_to_cell(p);
395 /* There is always at least one cell, so if the particle
396 * does not belong to a cell on this node we can put it there. */
397 auto cell = sort_cell ? sort_cell : decomposition().local_cells()[0];
398
399 /* If the particle isn't local a global resort may be
400 * needed, otherwise a local resort if sufficient. */
402
403 return std::addressof(
404 append_indexed_particle(cell->particles(), std::move(p)));
405}
406
408 auto it = std::ranges::find_if(std::ranges::views::reverse(m_particle_index),
409 [](auto const *p) { return p != nullptr; });
410
411 return (it != m_particle_index.rend()) ? (*it)->id() : -1;
412}
413
415 return m_bond_state->pair_count;
416}
418 return m_bond_state->angle_count;
419}
421 return m_bond_state->dihedral_count;
422}
423void CellStructure::set_local_bond_numbers(int pair_value, int angle_value,
424 int dihedral_value) {
425 m_bond_state->set_counts(pair_value, angle_value, dihedral_value);
426}
427#ifdef ESPRESSO_COLLISION_DETECTION
428void CellStructure::clear_new_bonds() { m_bond_state->clear_new_bonds(); }
430 std::vector<int> const &particle_ids) {
431 m_bond_state->add_new_bond(bond_id, particle_ids, get_id_to_index());
432}
433void CellStructure::rebuild_bond_list() { m_bond_state->rebuild(); }
434#endif // ESPRESSO_COLLISION_DETECTION
435
437 for (auto cell : decomposition().local_cells()) {
438 cell->particles().clear();
439 }
440
441 m_particle_index.clear();
443}
444
445/* Map the data parts flags from cells to those used internally
446 * by the ghost communication */
447unsigned map_data_parts(unsigned data_parts) {
448 using namespace Cells;
449
450 /* clang-format off */
451 return GHOSTTRANS_NONE
452 | ((data_parts & DATA_PART_PROPERTIES) ? GHOSTTRANS_PROPRTS : 0u)
453 | ((data_parts & DATA_PART_POSITION) ? GHOSTTRANS_POSITION : 0u)
454 | ((data_parts & DATA_PART_MOMENTUM) ? GHOSTTRANS_MOMENTUM : 0u)
455 | ((data_parts & DATA_PART_FORCE) ? GHOSTTRANS_FORCE : 0u)
456#ifdef ESPRESSO_BOND_CONSTRAINT
457 | ((data_parts & DATA_PART_RATTLE) ? GHOSTTRANS_RATTLE : 0u)
458#endif
459 | ((data_parts & DATA_PART_BONDS) ? GHOSTTRANS_BONDS : 0u);
460 /* clang-format on */
461}
462
464 ghost_communicator(decomposition().exchange_ghosts_comm(),
465 *get_system().box_geo, GHOSTTRANS_PARTNUM);
466}
467void CellStructure::ghosts_update(unsigned data_parts) {
468 ghost_communicator(decomposition().exchange_ghosts_comm(),
469 *get_system().box_geo, map_data_parts(data_parts));
470}
472 ghost_communicator(decomposition().collect_ghost_force_comm(),
473 *get_system().box_geo, GHOSTTRANS_FORCE);
474}
475#ifdef ESPRESSO_BOND_CONSTRAINT
480#endif
481
482namespace {
483/**
484 * @brief Apply a @ref ParticleChange to a particle index.
485 */
488
490 cs->update_particle_index(rp.id, nullptr);
491 }
493};
494} // namespace
495
496void CellStructure::resort_particles(bool global_flag) {
497 invalidate_ghosts();
498
499 std::vector<ParticleChange> diff;
500
501 m_decomposition->resort(global_flag, diff);
502
503 for (auto d : diff) {
504 std::visit(UpdateParticleIndexVisitor{this}, d);
505 }
506
507 auto const &lebc = get_system().box_geo->lees_edwards_bc();
508 m_rebuild_verlet_list = true;
509 m_rebuild_verlet_list_cabana = true;
510 m_le_pos_offset_at_last_resort = lebc.pos_offset;
511
512#ifdef ESPRESSO_ADDITIONAL_CHECKS
515#endif
516}
517
519 auto &system = get_system();
520 auto &local_geo = *system.local_geo;
521 auto const &box_geo = *system.box_geo;
522 set_particle_decomposition(
523 std::make_unique<AtomDecomposition>(::comm_cart, box_geo));
525 local_geo.set_cell_structure_type(m_type);
526 system.on_cell_structure_change();
527}
528
530 double range, std::optional<std::pair<int, int>> fully_connected_boundary) {
531 auto &system = get_system();
532 auto &local_geo = *system.local_geo;
533 auto const &box_geo = *system.box_geo;
534 set_particle_decomposition(std::make_unique<RegularDecomposition>(
535 ::comm_cart, range, box_geo, local_geo, fully_connected_boundary));
537 local_geo.set_cell_structure_type(m_type);
538 system.on_cell_structure_change();
539}
540
542 std::set<int> n_square_types) {
543 auto &system = get_system();
544 auto &local_geo = *system.local_geo;
545 auto const &box_geo = *system.box_geo;
546 set_particle_decomposition(std::make_unique<HybridDecomposition>(
547 ::comm_cart, cutoff_regular, m_verlet_skin,
548 [&system]() { return system.get_global_ghost_flags(); }, box_geo,
549 local_geo, n_square_types));
551 local_geo.set_cell_structure_type(m_type);
552 system.on_cell_structure_change();
553}
554
556 assert(value >= 0.);
557 m_verlet_skin = value;
558 m_verlet_skin_set = true;
559 m_rebuild_verlet_list_cabana = true;
560 get_system().on_verlet_skin_change();
561}
562
564 assert(not is_verlet_skin_set());
565 auto const max_cut = get_system().maximal_cutoff();
566 if (max_cut <= 0.) {
567 throw std::runtime_error(
568 "cannot automatically determine skin, please set it manually");
569 }
570 /* maximal skin that can be used without resorting is the maximal
571 * range of the cell system minus what is needed for interactions. */
572 auto const max_range = std::ranges::min(max_cutoff());
573 auto const new_skin = std::min(0.4 * max_cut, max_range - max_cut);
574 set_verlet_skin(new_skin);
575}
576
578 /* data parts that are only updated on resort */
579 auto constexpr resort_only_parts =
581
582 auto const global_resort = boost::mpi::all_reduce(
583 ::comm_cart, m_resort_particles, std::bit_or<unsigned>());
584
585 if (global_resort != Cells::RESORT_NONE) {
586 auto const do_global_resort = (global_resort & Cells::RESORT_GLOBAL) != 0;
587
588 /* Resort cell system */
589 resort_particles(do_global_resort);
590 ghosts_count();
591 ghosts_update(data_parts);
592
593 /* Add the ghost particles to the index if we don't already
594 * have them. */
595 for (auto &p : ghost_particles()) {
596 if (get_local_particle(p.id()) == nullptr) {
597 update_particle_index(p.id(), &p);
598 }
599 }
600
601 /* Particles are now sorted */
603 } else {
604 /* Communication step: ghost information */
605 ghosts_update(data_parts & ~resort_only_parts);
606 }
607}
608
609void CellStructure::parallel_for_each_particle_impl(
610 std::span<Cell *const> cells, ParticleUnaryOp &f) const {
611 if (cells.size() > 1) {
612 Kokkos::parallel_for( // loop over cells
613 "for_each_local_particle", cells.size(), [&](auto cell_idx) {
614 for (auto &p : cells[cell_idx]->particles())
615 f(p);
616 });
617 } else if (cells.size() == 1) {
618 auto &particles = cells.front()->particles();
619 Kokkos::parallel_for( // loop over particles
620 "for_each_local_particle", particles.size(),
621 [&](auto part_idx) { f(*(particles.begin() + part_idx)); });
622 }
623}
624
626 Utils::Vector3d const &additional_offset) const {
627 auto const lim = Utils::sqr(m_verlet_skin / 2.) - additional_offset.norm2();
628
630 [lim](bool &result, Particle const &p) {
631 if ((p.pos() - p.pos_at_last_verlet_update()).norm2() > lim) {
632 result = true;
633 }
634 };
635
636 Reduction::ReductionOp<bool> reduce_op = [](bool &acc, bool const &val) {
637 acc |= val;
638 };
639
640 return reduce_over_local_particles(*this, add_partial, reduce_op);
641}
@ NSQUARE
Atom decomposition (N-square).
@ HYBRID
Hybrid decomposition.
@ REGULAR
Regular decomposition.
unsigned map_data_parts(unsigned data_parts)
Map the data parts flags from cells to those used internally by the ghost communication.
static auto estimate_max_counts(double pair_cutoff, std::size_t number_of_unique_particles, double local_box_volume, std::size_t num_local_particles)
unsigned map_data_parts(unsigned data_parts)
Map the data parts flags from cells to those used internally by the ghost communication.
std::function< void(Particle &)> ParticleUnaryOp
Vector implementation and trait types for boost qvm interoperability.
void bond_resolution_error(std::span< const int > partner_ids)
Atom decomposition cell system.
Bond storage.
Definition BondList.hpp:84
Describes a cell structure / cell system.
ParticleRange ghost_particles() const
auto & get_local_force()
Particle * get_local_particle(int id)
Get a local particle by id.
void set_kokkos_handle(std::shared_ptr< KokkosHandle > handle)
void check_particle_sorting() const
Check that particles are in the correct cell.
auto & get_id_to_index()
std::size_t count_local_particles() const
virtual ~CellStructure()
int get_local_angle_bond_numbers() const
void clear_resort_particles()
Set the resort level to sorted.
auto is_verlet_skin_set() const
Whether the Verlet skin is set.
void clear_local_properties()
ParticleDecomposition const & decomposition() const
Get the underlying particle decomposition.
int get_local_pair_bond_numbers() const
void update_ghosts_and_resort_particle(unsigned data_parts)
Update ghost particles, with particle resort if needed.
Particle * add_local_particle(Particle &&p)
Add a particle.
void set_verlet_skin_heuristic()
Set the Verlet skin using a heuristic.
void set_verlet_skin(double value)
Set the Verlet skin.
void ghosts_update(unsigned data_parts)
Update ghost particles.
int get_local_dihedral_bond_numbers() const
int get_cached_max_local_particle_id() const
CellStructure(BoxGeometry const &box)
auto & get_local_torque()
auto & get_local_virial()
void update_particle_index(int id, Particle *p)
Update local particle index.
void set_local_bond_numbers(int p, int a, int d)
void ghosts_reduce_forces()
Add forces and torques from ghost particles to real particles.
auto const & get_unique_particles() const
void rebuild_local_properties(double pair_cutoff)
Utils::Vector3d max_range() const
Maximal pair range supported by current cell system.
void add_new_bond(int bond_id, std::vector< int > const &particle_ids)
bool check_resort_required(Utils::Vector3d const &additional_offset={}) const
Check whether a particle has moved further than half the skin since the last Verlet list update,...
auto resolve_bond_partners(std::span< const int > partner_ids)
Resolve ids to particles.
void ghosts_count()
Synchronize number of ghosts.
void set_resort_particles(Cells::Resort level)
Increase the local resort level at least to level.
void remove_particle(int id)
Remove a particle.
Particle * add_particle(Particle &&p)
Add a particle.
std::size_t get_num_local_particles_cached() const
void resort_particles(bool global_flag)
Resort particles.
void check_particle_index() const
Check that particle index is commensurate with particles.
void set_regular_decomposition(double range, std::optional< std::pair< int, int > > fully_connected_boundary)
Set the particle decomposition to RegularDecomposition.
void set_atom_decomposition()
Set the particle decomposition to AtomDecomposition.
void remove_all_particles()
Remove all particles from the cell system.
ParticleRange local_particles() const
void ghosts_reduce_rattle_correction()
Add rattle corrections from ghost particles to real particles.
void set_hybrid_decomposition(double cutoff_regular, std::set< int > n_square_types)
Set the particle decomposition to HybridDecomposition.
int get_max_local_particle_id() const
Get the maximal particle id on this node.
Utils::Vector3d max_cutoff() const
Maximal cutoff supported by current cell system.
void update_bond_storage(int &pair_count, int &angle_count, int &dihedral_count, Particle const &p)
Update bond storage(m_*_bond_list_kokkos and m_*_bond_id_kokkos).
void clear_bond_properties()
void reset_local_properties()
virtual std::span< Cell *const > local_cells() const =0
Get pointer to local cells.
base_type::size_type size() const
constexpr T norm2() const
Definition Vector.hpp:158
boost::mpi::communicator comm_cart
The communicator.
void ghost_communicator(GhostCommunicator const &gcr, BoxGeometry const &box_geo, unsigned int data_parts)
Do a ghost communication with the specified data parts.
Definition ghosts.cpp:443
Ghost particles and particle exchange.
@ GHOSTTRANS_MOMENTUM
transfer ParticleMomentum
Definition ghosts.hpp:132
@ GHOSTTRANS_RATTLE
transfer ParticleRattle
Definition ghosts.hpp:137
@ GHOSTTRANS_PARTNUM
resize the receiver particle arrays to the size of the senders
Definition ghosts.hpp:140
@ GHOSTTRANS_POSITION
transfer ParticlePosition
Definition ghosts.hpp:130
@ GHOSTTRANS_PROPRTS
transfer ParticleProperties
Definition ghosts.hpp:128
@ GHOSTTRANS_FORCE
transfer ParticleForce
Definition ghosts.hpp:134
@ GHOSTTRANS_NONE
Definition ghosts.hpp:126
@ GHOSTTRANS_BONDS
Definition ghosts.hpp:141
@ DATA_PART_PROPERTIES
Particle::p.
@ DATA_PART_BONDS
Particle::bonds.
ParticleRange particles(std::span< Cell *const > cells)
std::function< void(ResultType &, ResultType const &)> ReductionOp
Join two partial reduction results.
std::function< void(ResultType &, Particle const &)> AddPartialResultKernel
Kernel that adds the result from a single particle to a reduction.
DEVICE_QUALIFIER constexpr T sqr(T x)
Calculates the SQuaRe of x.
Definition sqr.hpp:28
bool contains(Range &&rng, T const &value)
Check whether a range contains a value.
Definition contains.hpp:36
STL namespace.
void enumerate_local_particles(CellStructure const &cs, Kernel &&kernel)
Run a kernel on all local particles with enumeration.
ResultType reduce_over_local_particles(CellStructure const &cs, Reduction::AddPartialResultKernel< ResultType > add_partial, Reduction::ReductionOp< ResultType > reduce_op)
performs a reduction over all particles
Exception indicating that a particle id could not be resolved.
Struct holding all information for one particle.
Definition Particle.hpp:435
auto const & bonds() const
Definition Particle.hpp:468
auto const & id() const
Definition Particle.hpp:454