26#include "communication.hpp"
28#include "system/System.hpp"
33#include <boost/mpi.hpp>
34#include <boost/serialization/access.hpp>
41#include <unordered_set>
49using Action = std::variant<DeleteBond, DeleteAngleBond, DeleteAllBonds>;
55void BondBreakage::queue_breakage(
int particle_id,
59 std::lock_guard<std::mutex>
lock(queue_mtx);
60 m_queue.emplace_back(
QueueEntry{particle_id, bond_partners, bond_type});
79 return bond_partners[1];
86 {{*(
e.bond_partners[0]), *(
e.bond_partners[1])}},
91#ifdef ESPRESSO_VIRTUAL_SITES_RELATIVE
102 "breakage action has to be configured for the "
103 "bond on the virtual site. Encountered a particle "
104 "that is not virtual.";
114 p2->vs_relative().to_particle_id},
116 p1->vs_relative().to_particle_id},
125 if (
not vs->is_virtual()) {
127 "breakage action has to be configured for the "
128 "bond on the virtual site. Encountered a particle "
129 "that is not virtual.";
149 auto &bond_list = p.
bonds();
150 auto it = std::find(bond_list.begin(), bond_list.end(),
view);
151 if (
it != bond_list.end()) {
160 std::vector<std::pair<int, int>>
to_delete;
161 for (
auto b : p.
bonds()) {
162 if (b.partner_ids().size() == 1
and b.partner_ids()[0] ==
other_pid)
176 : cell_structure{cell_structure} {}
197 auto &cell_structure = *
system.cell_structure;
203 assert(breakage_specs.contains(
e.bond_type));
204 auto const &
spec = breakage_specs.at(
e.bond_type);
209 for (
auto const &a :
actions) {
210 std::visit(execute(cell_structure), a);
211 system.on_particle_change();
216 std::span<Particle *>
partners,
int bond_id,
221 retval = bond_breakage.check_and_handle_breakage(
222 p.
id(), {{partners[0]->id(), std::nullopt}}, bond_id, d);
226 retval = bond_breakage.check_and_handle_breakage(
227 p.id(), {{partners[0]->id(), partners[1]->id()}}, bond_id, d);
233 system.cell_structure->update_ghosts_and_resort_particle(
234 system.get_global_ghost_flags());
execute(CellStructure &cell_structure)
void operator()(DeleteAngleBond const &d) const
void operator()(DeleteBond const &d) const
void operator()(DeleteAllBonds const &d) const
Immutable view on a bond.
ESPRESSO_ATTR_ALWAYS_INLINE Utils::Vector3< T > get_mi_vector(Utils::Vector3< T > const &a, Utils::Vector3< T > const &b) const
Get the minimum-image vector between two coordinates.
Describes a cell structure / cell system.
Particle * get_local_particle(int id)
Get a local particle by id.
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
boost::mpi::communicator comm_cart
The communicator.
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
#define runtimeErrorMsg()
static void remove_pair_bonds_to(Particle &p, int other_pid)
Delete pair bonds to a specific partner.
static void remove_bond(Particle &p, BondView const &view)
Delete specific bond.
static ActionSet actions_for_breakage(CellStructure const &cell_structure, QueueEntry const &e, BreakageSpec const &spec)
Constructs the actions to take for a breakage queue entry.
@ REVERT_BIND_AT_POINT_OF_COLLISION
static auto gather_global_queue(Queue const &local_queue)
Gathers combined queue from all mpi ranks.
std::variant< DeleteBond, DeleteAngleBond, DeleteAllBonds > Action
static bool bond_handler(BondBreakage &bond_breakage, Particle &p, std::span< Particle * > partners, int bond_id, BoxGeometry const &box_geo)
std::array< std::optional< int >, 2 > BondPartners
Stores one or two bond partners for pair/angle bonds.
std::vector< QueueEntry > Queue
Record bonds broken during a time step.
std::unordered_set< Action > ActionSet
void gather_buffer(std::vector< T, Allocator > &buffer, boost::mpi::communicator const &comm, int root=0)
Gather buffer with different size on each node.
Struct holding all information for one particle.
auto const & bonds() const