39#include "system/System.hpp"
44#include <boost/serialization/set.hpp>
62template <
class Filter>
64 double const distance, Filter filter) {
65 std::vector<std::pair<int, int>> ret;
67 auto const pair_kernel = [cutoff2, &filter, &ret](
Particle const &p1,
70 if (d.dist2 < cutoff2 and filter(p1) and filter(p2))
71 ret.emplace_back(p1.id(), p2.id());
77 for (
auto &pair : ret) {
78 if (pair.first > pair.second)
79 std::swap(pair.first, pair.second);
86static auto get_max_neighbor_search_range(
System::System const &system) {
88 return std::ranges::min(cell_structure.max_range());
90static void search_distance_sanity_check_max_range(
System::System const &system,
91 double const distance) {
95 auto const max_range = get_max_neighbor_search_range(system);
96 if (distance > max_range) {
97 throw std::domain_error(
"pair search distance " + std::to_string(distance) +
98 " bigger than the decomposition range " +
99 std::to_string(max_range));
103search_distance_sanity_check_cell_structure(
System::System const &system,
107 throw std::runtime_error(
"Cannot search for neighbors in the hybrid "
108 "decomposition cell system");
111static void search_neighbors_sanity_checks(
System::System const &system,
112 double const distance) {
113 search_distance_sanity_check_max_range(system, distance);
114 search_distance_sanity_check_cell_structure(system, distance);
118std::optional<std::vector<int>>
120 double const distance) {
121 detail::search_neighbors_sanity_checks(system, distance);
122 std::vector<int> ret;
126 if (vec.norm2() < cutoff2) {
127 ret.emplace_back(p2.id());
131 auto const p = cell_structure.get_local_particle(pid);
132 if (p and not p->is_ghost()) {
133 cell_structure.run_on_particle_short_range_neighbors(*p, kernel);
145 auto const distance = std::ranges::min(cell_structure.max_range());
146 detail::search_neighbors_sanity_checks(system, distance);
147 std::vector<Particle const *> ret;
151 if (vec.norm2() < cutoff2) {
152 ret.emplace_back(&p2);
155 cell_structure.run_on_particle_short_range_neighbors(p, kernel);
160 double const distance) {
161 detail::search_neighbors_sanity_checks(system, distance);
163 [](
Particle const &) {
return true; });
166std::vector<std::pair<int, int>>
168 std::vector<int>
const &types) {
169 detail::search_neighbors_sanity_checks(system, distance);
171 return std::any_of(types.begin(), types.end(),
173 [p](
int const type) { return p.type() == type; });
179 std::vector<PairInfo> pairs;
180 auto const pair_kernel = [&pairs, rank](
Particle const &p1,
183 pairs.emplace_back(p1.id(), p2.id(), p1.pos(), p2.pos(), d.vec21, rank);
190 std::vector<NeighborPIDs> ret;
191 auto kernel = [&ret](
Particle const &p,
192 std::vector<Particle const *>
const &neighbors) {
193 std::vector<int> neighbor_pids;
194 neighbor_pids.reserve(neighbors.size());
195 for (
auto const &neighbor : neighbors) {
196 neighbor_pids.emplace_back(neighbor->id());
198 ret.emplace_back(p.
id(), neighbor_pids);
201 for (
auto const &p : cell_structure.local_particles()) {
@ HYBRID
Hybrid decomposition.
Vector implementation and trait types for boost qvm interoperability.
static auto get_interacting_neighbors(System::System const &system, Particle const &p)
Get pointers to all interacting neighbors of a central particle.
static auto get_pairs_filtered(System::System const &system, double const distance, Filter filter)
Get pairs of particles that are closer than a distance and fulfill a filter criterion.
std::optional< std::vector< int > > get_short_range_neighbors(System::System const &system, int const pid, double const distance)
Get ids of particles that are within a certain distance of another particle.
std::vector< PairInfo > non_bonded_loop_trace(System::System const &system, int const rank)
Returns pairs of particle ids, positions and distance as seen by the non-bonded loop.
std::vector< std::pair< int, int > > get_pairs_of_types(System::System const &system, double const distance, std::vector< int > const &types)
Get pairs closer than distance if both their types are in types.
std::vector< NeighborPIDs > get_neighbor_pids(System::System const &system)
Returns pairs of particle ids and neighbor particle id lists.
std::vector< std::pair< int, int > > get_pairs(System::System const &system, double const distance)
Get pairs closer than distance from the cells.
This file contains everything related to the global cell structure / cell system.
std::shared_ptr< CellStructure > cell_structure
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
DEVICE_QUALIFIER constexpr T sqr(T x)
Calculates the SQuaRe of x.
Particles creation and deletion.
Distance vector and length handed to pair kernels.
Struct holding all information for one particle.