39#include "system/System.hpp"
44#include <boost/serialization/set.hpp>
61template <
class Filter>
63 double const distance, Filter filter) {
64 std::vector<std::pair<int, int>> ret;
66 auto const pair_kernel = [cutoff2, &filter, &ret](
Particle const &p1,
69 if (d.dist2 < cutoff2 and filter(p1) and filter(p2)) {
73 std::swap(pid1, pid2);
75 ret.emplace_back(pid1, pid2);
85static auto get_max_neighbor_search_range(
System::System const &system) {
87 return std::ranges::min(cell_structure.max_range());
89static void search_distance_sanity_check_max_range(
System::System const &system,
90 double const distance) {
94 auto const max_range = get_max_neighbor_search_range(system);
95 if (distance > max_range) {
96 throw std::domain_error(
"pair search distance " + std::to_string(distance) +
97 " bigger than the decomposition range " +
98 std::to_string(max_range));
102search_distance_sanity_check_cell_structure(
System::System const &system,
106 throw std::runtime_error(
"Cannot search for neighbors in the hybrid "
107 "decomposition cell system");
110static void search_neighbors_sanity_checks(
System::System const &system,
111 double const distance) {
112 search_distance_sanity_check_max_range(system, distance);
113 search_distance_sanity_check_cell_structure(system, distance);
117std::optional<std::vector<int>>
119 double const distance) {
120 detail::search_neighbors_sanity_checks(system, distance);
121 std::vector<int> ret;
125 if (vec.norm2() < cutoff2) {
126 ret.emplace_back(p2.id());
130 auto const p = cell_structure.get_local_particle(pid);
131 if (p and not p->is_ghost()) {
132 cell_structure.run_on_particle_short_range_neighbors(*p, kernel);
144 auto const distance = std::ranges::min(cell_structure.max_range());
145 detail::search_neighbors_sanity_checks(system, distance);
146 std::vector<Particle const *> ret;
150 if (vec.norm2() < cutoff2) {
151 ret.emplace_back(&p2);
154 cell_structure.run_on_particle_short_range_neighbors(p, kernel);
159 double const distance) {
160 detail::search_neighbors_sanity_checks(system, distance);
162 [](
Particle const &) {
return true; });
165std::vector<std::pair<int, int>>
167 std::vector<int>
const &types) {
168 detail::search_neighbors_sanity_checks(system, distance);
170 return std::ranges::any_of(
171 types, [target = p.
type()](
int const type) { return type == target; });
177 std::vector<PairInfo> pairs;
178 auto const pair_kernel = [&pairs, rank](
Particle const &p1,
181 pairs.emplace_back(p1.id(), p2.id(), p1.pos(), p2.pos(), d.vec21, rank);
188 std::vector<NeighborPIDs> ret;
189 auto kernel = [&ret](
Particle const &p,
190 std::vector<Particle const *>
const &neighbors) {
191 std::vector<int> neighbor_pids;
192 neighbor_pids.reserve(neighbors.size());
193 for (
auto const &neighbor : neighbors) {
194 neighbor_pids.emplace_back(neighbor->id());
196 ret.emplace_back(p.
id(), neighbor_pids);
199 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.
auto const & type() const