ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
bond_breakage.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 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 "system/System.hpp"
23
24#include <boost/serialization/access.hpp>
25
26#include <array>
27#include <memory>
28#include <optional>
29#include <unordered_map>
30#include <vector>
31
32namespace BondBreakage {
33
34/** Stores one or two bond parnters for pair/angle bonds */
35using BondPartners = std::array<std::optional<int>, 2>;
36
37enum class ActionType {
38 NONE = 0,
39 DELETE_BOND = 1,
41};
42
47
48// Broken bond record
49struct QueueEntry {
53
54 // Serialization for synchronization across mpi ranks
56 template <typename Archive>
57 void serialize(Archive &ar, unsigned int const /* version */) {
58 ar & particle_id;
59 ar & bond_partners;
60 ar & bond_type;
61 }
62};
63
64/** @brief Record bonds broken during a time step. */
65using Queue = std::vector<QueueEntry>;
66
68 Queue m_queue;
69
70public:
71 /** @brief Bond breakage specifications. */
72 std::unordered_map<int, std::shared_ptr<BreakageSpec>> breakage_specs;
73
74 BondBreakage() : m_queue{}, breakage_specs{} {}
75
76 /** @brief Check if the bond between the particles should break, if yes, queue
77 * it.
78 */
79 bool check_and_handle_breakage(int particle_id,
80 BondPartners const &bond_partners,
81 int bond_type, double distance) {
82 if (breakage_specs.count(bond_type) == 0) {
83 return false; // No breakage rule for this bond type
84 }
85
86 // Retrieve relevant breakage spec
87 auto const &spec = *(breakage_specs.at(bond_type));
88
89 // Is the bond length longer than the breakage length?
90 if (distance >= spec.breakage_length) {
91 queue_breakage(particle_id, bond_partners, bond_type);
92 return true;
93 }
94 return false;
95 }
96
97 void clear_queue() { m_queue.clear(); }
98
100 if (not breakage_specs.empty()) {
101 process_queue_impl(system);
102 }
103 }
104
105private:
106 void process_queue_impl(System::System &system);
107
108 /** Add a particle+bond combination to the breakage queue */
109 void queue_breakage(int particle_id, BondPartners const &bond_partners,
110 int bond_type);
111};
112
113} // namespace BondBreakage
std::unordered_map< int, std::shared_ptr< BreakageSpec > > breakage_specs
Bond breakage specifications.
void process_queue(System::System &system)
bool check_and_handle_breakage(int particle_id, BondPartners const &bond_partners, int bond_type, double distance)
Check if the bond between the particles should break, if yes, queue it.
Main system class.
std::array< std::optional< int >, 2 > BondPartners
Stores one or two bond parnters for pair/angle bonds.
std::vector< QueueEntry > Queue
Record bonds broken during a time step.
void serialize(Archive &ar, unsigned int const)
friend class boost::serialization::access