ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
core/collision_detection/utils.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2011-2024 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <config/config.hpp>
23
24#ifdef COLLISION_DETECTION
25
26#include "CollisionPair.hpp"
27
28#include "BoxGeometry.hpp"
29#include "Particle.hpp"
31#include "communication.hpp"
32#include "virtual_sites.hpp"
33
34#include <utils/Vector.hpp>
36
37#include <boost/mpi/collectives.hpp>
38#include <boost/serialization/utility.hpp>
39
40#include <stdexcept>
41#include <string>
42#include <utility>
43#include <vector>
44
45namespace CollisionDetection {
46
47inline auto &get_part(CellStructure &cell_structure, int id) {
48 auto const p = cell_structure.get_local_particle(id);
49
50 if (not p) {
51 throw std::runtime_error("Could not handle collision because particle " +
52 std::to_string(id) + " was not found.");
53 }
54
55 return *p;
56}
57
58#ifdef VIRTUAL_SITES_RELATIVE
60 CellStructure &cell_structure, BoxGeometry const &box_geo,
61 int const part_type_vs, double const min_global_cut,
62 int const current_vs_pid, Utils::Vector3d const &pos, int const relate_to) {
63 Particle new_part;
64 new_part.id() = current_vs_pid;
65 new_part.pos() = pos;
66 auto p_vs = cell_structure.add_particle(std::move(new_part));
67 vs_relate_to(*p_vs, get_part(cell_structure, relate_to), box_geo,
68 min_global_cut);
69 p_vs->type() = part_type_vs;
70}
71#endif // VIRTUAL_SITES_RELATIVE
72
73inline auto gather_collision_queue(std::vector<CollisionPair> const &local) {
74 auto global = local;
75 if (::comm_cart.size() > 1) {
77 boost::mpi::broadcast(::comm_cart, global, 0);
78 }
79 return global;
80}
81
82inline void add_bind_centers(std::vector<CollisionPair> &collision_queue,
83 CellStructure &cell_structure, int bond_centers) {
84 for (auto &c : collision_queue) {
85 // Ensure that the bond is associated with the non-ghost particle
86 if (cell_structure.get_local_particle(c.first)->is_ghost()) {
87 std::swap(c.first, c.second);
88 }
89
90 const int bondG[] = {c.second};
91
92 // Insert the bond for the non-ghost particle
93 get_part(cell_structure, c.first).bonds().insert({bond_centers, bondG});
94 }
95}
96
97} // namespace CollisionDetection
98
99#endif // COLLISION_DETECTION
Vector implementation and trait types for boost qvm interoperability.
boost::mpi::communicator comm_cart
The communicator.
This file contains the defaults for ESPResSo.
void place_vs_and_relate_to_particle(CellStructure &cell_structure, BoxGeometry const &box_geo, int const part_type_vs, double const min_global_cut, int const current_vs_pid, Utils::Vector3d const &pos, int const relate_to)
auto gather_collision_queue(std::vector< CollisionPair > const &local)
void add_bind_centers(std::vector< CollisionPair > &collision_queue, CellStructure &cell_structure, int bond_centers)
auto & get_part(CellStructure &cell_structure, int id)
void gather_buffer(std::vector< T, Allocator > &buffer, boost::mpi::communicator const &comm, int root=0)
Gather buffer with different size on each node.
Describes a cell structure / cell system.
Particle * get_local_particle(int id)
Get a local particle by id.
Particle * add_particle(Particle &&p)
Add a particle.
Struct holding all information for one particle.
Definition Particle.hpp:395
bool is_ghost() const
Definition Particle.hpp:440
void vs_relate_to(Particle &p_vs, Particle const &p_relate_to, BoxGeometry const &box_geo, double min_global_cut)
Setup a virtual site to track a real particle.