ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
CellStructure.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#pragma once
23
25
26#include "BoxGeometry.hpp"
27#include "LocalBox.hpp"
28#include "Particle.hpp"
29#include "ParticleList.hpp"
30#include "ParticleRange.hpp"
32#include "bond_error.hpp"
33#include "cell_system/Cell.hpp"
35#include "config/config.hpp"
36#include "ghosts.hpp"
37#include "system/Leaf.hpp"
38
39#include <utils/math/sqr.hpp>
40
41#include <boost/container/static_vector.hpp>
42#include <boost/iterator/indirect_iterator.hpp>
43#include <boost/range/algorithm/transform.hpp>
44
45#include <algorithm>
46#include <cassert>
47#include <iterator>
48#include <memory>
49#include <optional>
50#include <set>
51#include <span>
52#include <stdexcept>
53#include <utility>
54#include <vector>
55
56namespace Cells {
57enum Resort : unsigned {
60 RESORT_GLOBAL = 2u
61};
62
63/**
64 * @brief Flags to select particle parts for communication.
65 */
66enum DataPart : unsigned {
67 DATA_PART_NONE = 0u, /**< Nothing */
68 DATA_PART_PROPERTIES = 1u, /**< Particle::p */
69 DATA_PART_POSITION = 2u, /**< Particle::r */
70 DATA_PART_MOMENTUM = 8u, /**< Particle::m */
71 DATA_PART_FORCE = 16u, /**< Particle::f */
72#ifdef BOND_CONSTRAINT
73 DATA_PART_RATTLE = 32u, /**< Particle::rattle */
74#endif
75 DATA_PART_BONDS = 64u /**< Particle::bonds */
76};
77} // namespace Cells
78
79/**
80 * @brief Map the data parts flags from cells to those
81 * used internally by the ghost communication.
82 *
83 * @param data_parts data parts flags
84 * @return ghost communication flags
85 */
86unsigned map_data_parts(unsigned data_parts);
87
88namespace Cells {
89inline ParticleRange particles(std::span<Cell *const> cells) {
90 /* Find first non-empty cell */
91 auto first_non_empty = std::ranges::find_if(
92 cells, [](const Cell *c) { return not c->particles().empty(); });
93
94 return {CellParticleIterator(first_non_empty, cells.end()),
95 CellParticleIterator(cells.end())};
96}
97} // namespace Cells
98
99/**
100 * @brief Distance vector and length handed to pair kernels.
101 */
102struct Distance {
104 : vec21(vec21), dist2(vec21.norm2()) {}
105
107 double dist2;
108};
109
110namespace detail {
111// NOLINTNEXTLINE(bugprone-exception-escape)
112struct MinimalImageDistance {
113 BoxGeometry const box;
114
115 Distance operator()(Particle const &p1, Particle const &p2) const {
116 return Distance(box.get_mi_vector(p1.pos(), p2.pos()));
117 }
118};
119
120struct EuclidianDistance {
121 Distance operator()(Particle const &p1, Particle const &p2) const {
122 return Distance(p1.pos() - p2.pos());
123 }
124};
125} // namespace detail
126
127/** Describes a cell structure / cell system. Contains information
128 * about the communication of cell contents (particles, ghosts, ...)
129 * between different nodes and the relation between particle
130 * positions and the cell system. All other properties of the cell
131 * system which are not common between different cell systems have to
132 * be stored in separate structures.
133 */
134struct CellStructure : public System::Leaf<CellStructure> {
135private:
136 /** The local id-to-particle index */
137 std::vector<Particle *> m_particle_index;
138 /** Implementation of the primary particle decomposition */
139 std::unique_ptr<ParticleDecomposition> m_decomposition;
140 /** Active type in m_decomposition */
142 /** One of @ref Cells::Resort, announces the level of resort needed.
143 */
144 unsigned m_resort_particles = Cells::RESORT_NONE;
145 bool m_rebuild_verlet_list = true;
146 std::vector<std::pair<Particle *, Particle *>> m_verlet_list;
147 double m_le_pos_offset_at_last_resort = 0.;
148 /** @brief Verlet list skin. */
149 double m_verlet_skin = 0.;
150 bool m_verlet_skin_set = false;
151 double m_verlet_reuse = 0.;
152
153public:
154 CellStructure(BoxGeometry const &box);
155
156 bool use_verlet_list = true;
157
158 /**
159 * @brief Update local particle index.
160 *
161 * Update the entry for a particle in the local particle
162 * index.
163 *
164 * @param id Entry to update.
165 * @param p Pointer to the particle.
166 */
168 assert(id >= 0);
169 // cppcheck-suppress assertWithSideEffect
170 assert(not p or p->id() == id);
171
172 if (static_cast<unsigned int>(id) >= m_particle_index.size())
173 m_particle_index.resize(static_cast<unsigned int>(id + 1));
174
175 m_particle_index[static_cast<unsigned int>(id)] = p;
176 }
177
178 /**
179 * @brief Update local particle index.
180 *
181 * Update the entry for a particle in the local particle
182 * index.
183 *
184 * @param p Pointer to the particle.
185 */
187 update_particle_index(p.id(), std::addressof(p));
188 }
189
190 /**
191 * @brief Update local particle index.
192 *
193 * @param pl List of particles whose index entries should be updated.
194 */
196 for (auto &p : pl) {
197 update_particle_index(p.id(), std::addressof(p));
198 }
199 }
200
201 /**
202 * @brief Clear the particles index.
203 */
204 void clear_particle_index() { m_particle_index.clear(); }
205
206private:
207 /**
208 * @brief Append a particle to a list and update this
209 * particle index accordingly.
210 * @param pl List to add the particle to.
211 * @param p Particle to add.
212 */
213 Particle &append_indexed_particle(ParticleList &pl, Particle &&p) {
214 /* Check if cell may reallocate, in which case the index
215 * entries for all particles in this cell have to be
216 * updated. */
217 auto const may_reallocate = pl.size() >= pl.capacity();
218 auto &new_part = pl.insert(std::move(p));
219
220 if (may_reallocate)
222 else {
223 update_particle_index(new_part);
224 }
225
226 return new_part;
227 }
228
229public:
230 /**
231 * @brief Get a local particle by id.
232 *
233 * @param id Particle to get.
234 * @return Pointer to particle if it is local,
235 * nullptr otherwise.
236 */
238 assert(id >= 0);
239
240 if (static_cast<unsigned int>(id) >= m_particle_index.size())
241 return nullptr;
242
243 return m_particle_index[static_cast<unsigned int>(id)];
244 }
245
246 /** @overload */
247 const Particle *get_local_particle(int id) const {
248 assert(id >= 0);
249
250 if (static_cast<unsigned int>(id) >= m_particle_index.size())
251 return nullptr;
252
253 return m_particle_index[static_cast<unsigned int>(id)];
254 }
255
256 template <class InputRange, class OutputIterator>
257 void get_local_particles(InputRange ids, OutputIterator out) {
258 std::ranges::transform(ids, out,
259 [this](int id) { return get_local_particle(id); });
260 }
261
262 CellStructureType decomposition_type() const { return m_type; }
263
264 /** Maximal cutoff supported by current cell system. */
266
267 /** Maximal pair range supported by current cell system. */
269
271 return Cells::particles(decomposition().local_cells());
272 }
273
275 return Cells::particles(decomposition().ghost_cells());
276 }
277
278private:
279 /** Cell system dependent function to find the right cell for a
280 * particle.
281 * \param p Particle.
282 * \return pointer to cell where to put the particle, nullptr
283 * if the particle does not belong on this node.
284 */
285 Cell *particle_to_cell(const Particle &p) {
287 }
288 Cell const *particle_to_cell(const Particle &p) const {
290 }
291
292public:
293 /**
294 * @brief Add a particle.
295 *
296 * Moves a particle into the cell system. This adds
297 * a particle to the local node, irrespective of where
298 * it belongs.
299 *
300 * @param p Particle to add.
301 * @return Pointer to the particle in the cell
302 * system.
303 */
305
306 /**
307 * @brief Add a particle.
308 *
309 * Moves a particle into the cell system, if it
310 * belongs to this node. Otherwise this does not
311 * have an effect and the particle is discarded.
312 * This can be used to add a particle without
313 * knowledge where it should be placed by calling
314 * the function on all nodes, it will then add
315 * the particle in exactly one place.
316 *
317 * @param p Particle to add.
318 * @return Pointer to particle if it is local, null
319 * otherwise.
320 */
322
323 /**
324 * @brief Remove a particle.
325 *
326 * Removes a particle and all bonds pointing
327 * to it. This is a collective call.
328 *
329 * @param id Id of particle to remove.
330 */
331 void remove_particle(int id);
332
333 /**
334 * @brief Get the maximal particle id on this node.
335 *
336 * This returns the highest particle id on
337 * this node, or -1 if there are no particles on this node.
338 */
339 int get_max_local_particle_id() const;
340
341 /**
342 * @brief Remove all particles from the cell system.
343 *
344 * This allows linear time removal of all particles from
345 * the system, removing each particle individually would
346 * be quadratic.
347 */
349
350 /**
351 * @brief Get the underlying particle decomposition.
352 *
353 * Should be used solely for informative purposes.
354 *
355 * @return The active particle decomposition.
356 */
358 return assert(m_decomposition), *m_decomposition;
359 }
360
361private:
363 return assert(m_decomposition), *m_decomposition;
364 }
365
366public:
367 /**
368 * @brief Increase the local resort level at least to @p level.
369 */
371 m_resort_particles |= level;
372 assert(m_resort_particles >= level);
373 }
374
375 /**
376 * @brief Get the currently scheduled resort level.
377 */
378 unsigned get_resort_particles() const { return m_resort_particles; }
379
380 /**
381 * @brief Set the resort level to sorted.
382 */
383 void clear_resort_particles() { m_resort_particles = Cells::RESORT_NONE; }
384
385 /**
386 * @brief Check whether a particle has moved further than half the skin
387 * since the last Verlet list update, thus requiring a resort.
388 * @param additional_offset Offset which is added to the distance the
389 * particle has travelled when comparing to half
390 * the Verlet skin (e.g., for Lees-Edwards BC).
391 * @return Whether a resort is needed.
392 */
393 bool
394 check_resort_required(Utils::Vector3d const &additional_offset = {}) const {
395 auto const particles = local_particles();
396 auto const lim = Utils::sqr(m_verlet_skin / 2.) - additional_offset.norm2();
397 return std::any_of(
398 particles.begin(), particles.end(), [lim](const auto &p) {
399 return ((p.pos() - p.pos_at_last_verlet_update()).norm2() > lim);
400 });
401 }
402
404 return m_le_pos_offset_at_last_resort;
405 }
406
407 /**
408 * @brief Synchronize number of ghosts.
409 */
410 void ghosts_count();
411
412 /**
413 * @brief Update ghost particles.
414 *
415 * Update ghost particles with data from the real particles.
416 *
417 * @param data_parts Particle parts to update, combination of @ref
418 * Cells::DataPart
419 */
420 void ghosts_update(unsigned data_parts);
421
422 /**
423 * @brief Update ghost particles, with particle resort if needed.
424 *
425 * Update ghost particles with data from the real particles.
426 * Resort particles if a resort is due.
427 *
428 * @param data_parts Particle parts to update, combination of @ref
429 * Cells::DataPart
430 */
431 void update_ghosts_and_resort_particle(unsigned data_parts);
432
433 /**
434 * @brief Add forces from ghost particles to real particles.
435 */
437
438#ifdef BOND_CONSTRAINT
439 /**
440 * @brief Add rattle corrections from ghost particles to real particles.
441 */
443#endif
444
445 /**
446 * @brief Resort particles.
447 */
448 void resort_particles(bool global_flag);
449
450 /** @brief Whether the Verlet skin is set. */
451 auto is_verlet_skin_set() const { return m_verlet_skin_set; }
452
453 /** @brief Get the Verlet skin. */
454 auto get_verlet_skin() const { return m_verlet_skin; }
455
456 /** @brief Set the Verlet skin. */
457 void set_verlet_skin(double value);
458
459 /** @brief Set the Verlet skin using a heuristic. */
461
462 void update_verlet_stats(int n_steps, int n_verlet_updates) {
463 if (n_verlet_updates > 0) {
464 m_verlet_reuse = n_steps / static_cast<double>(n_verlet_updates);
465 } else {
466 m_verlet_reuse = 0.;
467 }
468 }
469
470 /** @brief Average number of integration steps the Verlet list was re-used */
471 auto get_verlet_reuse() const { return m_verlet_reuse; }
472
473private:
474 /**
475 * @brief Resolve ids to particles.
476 *
477 * @throws BondResolutionError if one of the ids
478 * was not found.
479 *
480 * @param partner_ids Ids to resolve.
481 * @return Vector of Particle pointers.
482 */
483 auto resolve_bond_partners(std::span<const int> partner_ids) {
484 boost::container::static_vector<Particle *, 4> partners;
485 get_local_particles(partner_ids, std::back_inserter(partners));
486
487 /* Check if id resolution failed for any partner */
488 if (std::ranges::find(partners, nullptr) != partners.end()) {
489 throw BondResolutionError{};
490 }
491
492 return partners;
493 }
494
495 /**
496 * @brief Execute kernel for every bond on particle.
497 * @tparam Handler Callable, which can be invoked with
498 * (Particle, int, std::span<Particle *>),
499 * returning a bool.
500 * @param p Particles for whom the bonds are evaluated.
501 * @param handler is called for every bond, and handed
502 * p, the bond id and a span with the bond
503 * partners as arguments. Its return value
504 * should indicate if the bond was broken.
505 */
506 template <class Handler>
507 void execute_bond_handler(Particle &p, Handler handler) {
508 for (const BondView bond : p.bonds()) {
509 auto const partner_ids = bond.partner_ids();
510
511 try {
512 auto partners = resolve_bond_partners(partner_ids);
513 auto const partners_span = std::span(partners.data(), partners.size());
514 auto const bond_broken = handler(p, bond.bond_id(), partners_span);
515 if (bond_broken) {
516 bond_broken_error(p.id(), partner_ids);
517 }
518 } catch (const BondResolutionError &) {
519 bond_broken_error(p.id(), partner_ids);
520 }
521 }
522 }
523
524 /**
525 * @brief Go through ghost cells and remove the ghost entries from the
526 * local particle index.
527 */
528 void invalidate_ghosts() {
529 for (auto const &p : ghost_particles()) {
530 if (get_local_particle(p.id()) == &p) {
531 update_particle_index(p.id(), nullptr);
532 }
533 }
534 }
535
536 /** @brief Set the particle decomposition, keeping the particles. */
537 void set_particle_decomposition(
538 std::unique_ptr<ParticleDecomposition> &&decomposition) {
540
541 /* Swap in new cell system */
542 std::swap(m_decomposition, decomposition);
543
544 /* Add particles to new system */
545 for (auto &p : Cells::particles(decomposition->local_cells())) {
546 add_particle(std::move(p));
547 }
548 }
549
550public:
551 /**
552 * @brief Set the particle decomposition to @ref AtomDecomposition.
553 */
555
556 /**
557 * @brief Set the particle decomposition to @ref RegularDecomposition.
558 *
559 * @param range Interaction range.
560 * @param fully_connected_boundary neighbor cell directions for Lees-Edwards.
561 */
563 double range,
564 std::optional<std::pair<int, int>> fully_connected_boundary);
565
566 /**
567 * @brief Set the particle decomposition to @ref HybridDecomposition.
568 *
569 * @param cutoff_regular Interaction cutoff_regular.
570 * @param n_square_types Particle types to put into n_square decomposition.
571 */
572 void set_hybrid_decomposition(double cutoff_regular,
573 std::set<int> n_square_types);
574
575private:
576 /**
577 * @brief Run link_cell algorithm for local cells.
578 *
579 * @tparam Kernel Needs to be callable with (Particle, Particle, Distance).
580 * @param kernel Pair kernel functor.
581 */
582 template <class Kernel> void link_cell(Kernel kernel) {
583 auto const maybe_box = decomposition().minimum_image_distance();
584 auto const local_cells_span = decomposition().local_cells();
585 auto const first = boost::make_indirect_iterator(local_cells_span.begin());
586 auto const last = boost::make_indirect_iterator(local_cells_span.end());
587
588 if (maybe_box) {
590 first, last,
591 [&kernel, df = detail::MinimalImageDistance{decomposition().box()}](
592 Particle &p1, Particle &p2) { kernel(p1, p2, df(p1, p2)); });
593 } else {
594 if (decomposition().box().type() != BoxType::CUBOID) {
595 throw std::runtime_error("Non-cuboid box type is not compatible with a "
596 "particle decomposition that relies on "
597 "EuclideanDistance for distance calculation.");
598 }
600 first, last,
601 [&kernel, df = detail::EuclidianDistance{}](
602 Particle &p1, Particle &p2) { kernel(p1, p2, df(p1, p2)); });
603 }
604 }
605
606 /** Non-bonded pair loop with verlet lists.
607 *
608 * @param pair_kernel Kernel to apply
609 * @param verlet_criterion Filter for verlet lists.
610 */
611 template <class PairKernel, class VerletCriterion>
612 void verlet_list_loop(PairKernel pair_kernel,
613 const VerletCriterion &verlet_criterion) {
614 /* In this case the verlet list update is attached to
615 * the pair kernel, and the verlet list is rebuilt as
616 * we go. */
617 if (m_rebuild_verlet_list) {
618 m_verlet_list.clear();
619
620 link_cell([&](Particle &p1, Particle &p2, Distance const &d) {
621 if (verlet_criterion(p1, p2, d)) {
622 m_verlet_list.emplace_back(&p1, &p2);
623 pair_kernel(p1, p2, d);
624 }
625 });
626
627 m_rebuild_verlet_list = false;
628 } else {
629 auto const maybe_box = decomposition().minimum_image_distance();
630 /* In this case the pair kernel is just run over the verlet list. */
631 if (maybe_box) {
632 auto const distance_function =
633 detail::MinimalImageDistance{decomposition().box()};
634 for (auto &pair : m_verlet_list) {
635 pair_kernel(*pair.first, *pair.second,
636 distance_function(*pair.first, *pair.second));
637 }
638 } else {
639 auto const distance_function = detail::EuclidianDistance{};
640 for (auto &pair : m_verlet_list) {
641 pair_kernel(*pair.first, *pair.second,
642 distance_function(*pair.first, *pair.second));
643 }
644 }
645 }
646 }
647
648public:
649 /** Bonded pair loop.
650 * @param bond_kernel Kernel to apply
651 */
652 template <class BondKernel> void bond_loop(BondKernel const &bond_kernel) {
653 for (auto &p : local_particles()) {
654 execute_bond_handler(p, bond_kernel);
655 }
656 }
657
658 /** Non-bonded pair loop.
659 * @param pair_kernel Kernel to apply
660 */
661 template <class PairKernel> void non_bonded_loop(PairKernel pair_kernel) {
662 link_cell(pair_kernel);
663 }
664
665 /** Non-bonded pair loop with potential use
666 * of verlet lists.
667 * @param pair_kernel Kernel to apply
668 * @param verlet_criterion Filter for verlet lists.
669 */
670 template <class PairKernel, class VerletCriterion>
671 void non_bonded_loop(PairKernel pair_kernel,
672 const VerletCriterion &verlet_criterion) {
673 if (use_verlet_list) {
674 verlet_list_loop(pair_kernel, verlet_criterion);
675 } else {
676 /* No verlet lists, just run the kernel with pairs from the cells. */
677 link_cell(pair_kernel);
678 }
679 }
680
681 /**
682 * @brief Check that particle index is commensurate with particles.
683 *
684 * For each local particles is checked that has a correct entry
685 * in the particles index, and that there are no excess (non-existing)
686 * particles in the index.
687 */
688 void check_particle_index() const;
689
690 /**
691 * @brief Check that particles are in the correct cell.
692 *
693 * This checks for all local particles that the result
694 * of particles_to_cell is the cell the particles is
695 * actually in, e.g. that the particles are sorted according
696 * to particles_to_cell.
697 */
698 void check_particle_sorting() const;
699
700public:
701 /**
702 * @brief Find cell a particle is stored in.
703 *
704 * For local particles, this returns the cell they
705 * are stored in, otherwise nullptr is returned.
706 *
707 * @param p Particle to find cell for
708 * @return Cell for particle or nullptr.
709 */
711 assert(not get_resort_particles());
712
713 if (p.is_ghost()) {
714 return nullptr;
715 }
716
717 return particle_to_cell(p);
718 }
719
720 /**
721 * @brief Run kernel on all particles inside local cell and its neighbors.
722 *
723 * @param p Particle to find cell for
724 * @param kernel Function with signature <tt>double(Particle const&,
725 * Particle const&, Utils::Vector3d const&)</tt>
726 * @return false if cell is not found, otherwise true
727 */
728 template <class Kernel>
730 Kernel &kernel) {
731 auto const cell = find_current_cell(p);
732
733 if (cell == nullptr) {
734 return false;
735 }
736
737 auto const maybe_box = decomposition().minimum_image_distance();
738
739 if (maybe_box) {
740 auto const distance_function =
741 detail::MinimalImageDistance{decomposition().box()};
742 short_range_neighbor_loop(p, cell, kernel, distance_function);
743 } else {
744 auto const distance_function = detail::EuclidianDistance{};
745 short_range_neighbor_loop(p, cell, kernel, distance_function);
746 }
747 return true;
748 }
749
750private:
751 template <class Kernel, class DistanceFunc>
752 void short_range_neighbor_loop(Particle const &p1, Cell *const cell,
753 Kernel &kernel, DistanceFunc const &df) {
754 /* Iterate over particles inside cell */
755 for (auto const &p2 : cell->particles()) {
756 if (p1.id() != p2.id()) {
757 auto const vec = df(p1, p2).vec21;
758 kernel(p1, p2, vec);
759 }
760 }
761 /* Iterate over all neighbors */
762 for (auto const neighbor : cell->neighbors().all()) {
763 /* Iterate over particles in neighbors */
764 if (neighbor != cell) {
765 for (auto const &p2 : neighbor->particles()) {
766 auto const vec = df(p1, p2).vec21;
767 kernel(p1, p2, vec);
768 }
769 }
770 }
771 }
772};
ParticleIterator< std::span< Cell *const >::iterator > CellParticleIterator
CellStructureType
Cell structure topology.
@ NSQUARE
Atom decomposition (N-square).
unsigned map_data_parts(unsigned data_parts)
Map the data parts flags from cells to those used internally by the ghost communication.
void bond_broken_error(int id, std::span< const int > partner_ids)
Immutable view on a bond.
Definition BondList.hpp:44
BoxType type() const
Utils::Vector< T, 3 > get_mi_vector(const Utils::Vector< T, 3 > &a, const Utils::Vector< T, 3 > &b) const
Get the minimum-image vector between two coordinates.
Definition Cell.hpp:97
auto & particles()
Particles.
Definition Cell.hpp:104
A distributed particle decomposition.
virtual Utils::Vector3d max_cutoff() const =0
Maximum supported cutoff.
virtual std::span< Cell *const > local_cells() const =0
Get pointer to local cells.
virtual Cell * particle_to_cell(Particle const &p)=0
Determine which cell a particle id belongs to.
virtual Utils::Vector3d max_range() const =0
Range in which calculations are performed.
virtual std::optional< BoxGeometry > minimum_image_distance() const =0
Return the box geometry needed for distance calculation if minimum image convention should be used ne...
virtual BoxGeometry const & box() const =0
A range of particles.
Abstract class that represents a component of the system.
std::size_t capacity() const
Capacity of the container.
Definition Bag.hpp:104
T & insert(T const &v)
Insert an element into the container.
Definition Bag.hpp:147
std::size_t size() const
Number of elements in the container.
Definition Bag.hpp:90
Returns true if the particles are to be considered for short range interactions.
This file contains the defaults for ESPResSo.
Ghost particles and particle exchange.
void link_cell(CellIterator first, CellIterator last, PairKernel &&pair_kernel)
Iterates over all particles in the cell range, and over all pairs within the cells and with their nei...
Definition link_cell.hpp:32
DataPart
Flags to select particle parts for communication.
@ DATA_PART_MOMENTUM
Particle::m.
@ DATA_PART_FORCE
Particle::f.
@ DATA_PART_PROPERTIES
Particle::p.
@ DATA_PART_BONDS
Particle::bonds.
@ DATA_PART_NONE
Nothing.
@ DATA_PART_RATTLE
Particle::rattle.
@ DATA_PART_POSITION
Particle::r.
ParticleRange particles(std::span< Cell *const > cells)
DEVICE_QUALIFIER constexpr T sqr(T x)
Calculates the SQuaRe of x.
Definition sqr.hpp:28
auto constexpr new_part
Exception indicating that a particle id could not be resolved.
Describes a cell structure / cell system.
ParticleRange ghost_particles() const
Particle * get_local_particle(int id)
Get a local particle by id.
void update_particle_index(ParticleList &pl)
Update local particle index.
void check_particle_sorting() const
Check that particles are in the correct cell.
void clear_resort_particles()
Set the resort level to sorted.
Cell * find_current_cell(const Particle &p)
Find cell a particle is stored in.
auto is_verlet_skin_set() const
Whether the Verlet skin is set.
ParticleDecomposition const & decomposition() const
Get the underlying particle decomposition.
void clear_particle_index()
Clear the particles index.
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.
auto get_le_pos_offset_at_last_resort() const
void get_local_particles(InputRange ids, OutputIterator out)
void update_verlet_stats(int n_steps, int n_verlet_updates)
void update_particle_index(int id, Particle *p)
Update local particle index.
void ghosts_reduce_forces()
Add forces from ghost particles to real particles.
unsigned get_resort_particles() const
Get the currently scheduled resort level.
auto get_verlet_reuse() const
Average number of integration steps the Verlet list was re-used.
void non_bonded_loop(PairKernel pair_kernel)
Non-bonded pair loop.
Utils::Vector3d max_range() const
Maximal pair range supported by current cell system.
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,...
const Particle * get_local_particle(int id) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void bond_loop(BondKernel const &bond_kernel)
Bonded pair loop.
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.
void resort_particles(bool global_flag)
Resort particles.
void check_particle_index() const
Check that particle index is commensurate with particles.
auto get_verlet_skin() const
Get the Verlet skin.
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.
bool run_on_particle_short_range_neighbors(Particle const &p, Kernel &kernel)
Run kernel on all particles inside local cell and its neighbors.
void remove_all_particles()
Remove all particles from the cell system.
ParticleRange local_particles() const
void update_particle_index(Particle &p)
Update local particle index.
void ghosts_reduce_rattle_correction()
Add rattle corrections from ghost particles to real particles.
CellStructureType decomposition_type() const
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 non_bonded_loop(PairKernel pair_kernel, const VerletCriterion &verlet_criterion)
Non-bonded pair loop with potential use of verlet lists.
Distance vector and length handed to pair kernels.
Utils::Vector3d vec21
Distance(Utils::Vector3d const &vec21)
Struct holding all information for one particle.
Definition Particle.hpp:395
bool is_ghost() const
Definition Particle.hpp:440
auto const & pos() const
Definition Particle.hpp:431
auto const & id() const
Definition Particle.hpp:414