|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <config/config.hpp> |
| 4 | + |
| 5 | +#ifdef COLLISION_DETECTION |
| 6 | + |
| 7 | +#include "bonded_interactions/bonded_interaction_data.hpp" |
| 8 | +#include "nonbonded_interactions/nonbonded_interaction_data.hpp" |
| 9 | + |
| 10 | +#include <variant> |
| 11 | + |
| 12 | +struct CollisionPair; |
| 13 | + |
| 14 | +namespace Collision { |
| 15 | + |
| 16 | +class Off { |
| 17 | +public: |
| 18 | + Off() = default; |
| 19 | + |
| 20 | + auto cutoff() const { return INACTIVE_CUTOFF; } |
| 21 | + |
| 22 | + void initialize(BondedInteractionsMap &, InteractionsNonBonded &) { return; } |
| 23 | + |
| 24 | + void handle_collisions(System::System &system, std::vector<CollisionPair> &) { |
| 25 | + } |
| 26 | + bool detect_collision(Particle const &p1, Particle const &p2, |
| 27 | + double const dist_sq) const { |
| 28 | + return false; |
| 29 | + } |
| 30 | +}; |
| 31 | + |
| 32 | +class BindCenters { |
| 33 | + |
| 34 | +public: |
| 35 | + double distance; |
| 36 | + // Square of distance at which particle are bound |
| 37 | + double distance_sq; |
| 38 | + |
| 39 | + /// bond type used between centers of colliding particles |
| 40 | + int bond_centers; |
| 41 | + |
| 42 | + BindCenters(double distance, int bond_centers) |
| 43 | + : distance{distance}, distance_sq{distance * distance}, |
| 44 | + bond_centers{bond_centers} {} |
| 45 | + |
| 46 | + void initialize(BondedInteractionsMap &bonded_ias, |
| 47 | + InteractionsNonBonded &nonbonded_ias); |
| 48 | + |
| 49 | + auto cutoff() const { return distance; } |
| 50 | + |
| 51 | + void handle_collisions(System::System &system, |
| 52 | + std::vector<CollisionPair> &local_collision_queue); |
| 53 | + |
| 54 | + bool detect_collision(Particle const &p1, Particle const &p2, |
| 55 | + double const dist_sq) const { |
| 56 | + if (dist_sq > distance_sq) |
| 57 | + return false; |
| 58 | + |
| 59 | + // Ignore virtual particles |
| 60 | + if (p1.is_virtual() or p2.is_virtual()) |
| 61 | + return false; |
| 62 | + |
| 63 | + // Check, if there's already a bond between the particles |
| 64 | + if (pair_bond_exists_on(p1.bonds(), p2.id(), bond_centers)) |
| 65 | + return false; |
| 66 | + |
| 67 | + if (pair_bond_exists_on(p2.bonds(), p1.id(), bond_centers)) |
| 68 | + return false; |
| 69 | + |
| 70 | + /* If we're still here, there is no previous bond between the particles, |
| 71 | + we have a new collision */ |
| 72 | + |
| 73 | + // do not create bond between ghost particles |
| 74 | + if (p1.is_ghost() and p2.is_ghost()) { |
| 75 | + return false; |
| 76 | + } |
| 77 | + return true; |
| 78 | + } |
| 79 | +}; |
| 80 | + |
| 81 | +#ifdef VIRTUAL_SITES_RELATIVE |
| 82 | +class BindVS { |
| 83 | +public: |
| 84 | + double distance; |
| 85 | + // Square of distance at which particle are bound |
| 86 | + double distance_sq; |
| 87 | + |
| 88 | + /// bond type used between centers of colliding particles |
| 89 | + int bond_centers; |
| 90 | + /// bond type used between virtual sites |
| 91 | + int bond_vs; |
| 92 | + /** Placement of virtual sites for MODE_VS. |
| 93 | + * 0=on same particle as related to, |
| 94 | + * 1=on collision partner, |
| 95 | + * 0.5=in the middle between |
| 96 | + */ |
| 97 | + double vs_placement; |
| 98 | + /// particle type for virtual sites created on collision |
| 99 | + int part_type_vs; |
| 100 | + |
| 101 | + BindVS(double distance, int bond_centers, int bond_vs, double vs_placement, |
| 102 | + int part_type_vs) |
| 103 | + : distance{distance}, distance_sq{distance * distance}, |
| 104 | + bond_centers{bond_centers}, bond_vs{bond_vs}, |
| 105 | + vs_placement{vs_placement}, part_type_vs{part_type_vs} {} |
| 106 | + |
| 107 | + void initialize(BondedInteractionsMap &bonded_ias, |
| 108 | + InteractionsNonBonded &nonbonded_ias); |
| 109 | + |
| 110 | + auto cutoff() const { return distance; } |
| 111 | + |
| 112 | + void handle_collisions(System::System &system, |
| 113 | + std::vector<CollisionPair> &local_collision_queue); |
| 114 | + |
| 115 | + bool detect_collision(Particle const &p1, Particle const &p2, |
| 116 | + double const dist_sq) const { |
| 117 | + if (dist_sq > distance_sq) |
| 118 | + return false; |
| 119 | + |
| 120 | + // Ignore virtual particles |
| 121 | + if (p1.is_virtual() or p2.is_virtual()) |
| 122 | + return false; |
| 123 | + |
| 124 | + // Check, if there's already a bond between the particles |
| 125 | + if (pair_bond_exists_on(p1.bonds(), p2.id(), bond_centers)) |
| 126 | + return false; |
| 127 | + |
| 128 | + if (pair_bond_exists_on(p2.bonds(), p1.id(), bond_centers)) |
| 129 | + return false; |
| 130 | + |
| 131 | + /* If we're still here, there is no previous bond between the particles, |
| 132 | + we have a new collision */ |
| 133 | + |
| 134 | + // do not create bond between ghost particles |
| 135 | + if (p1.is_ghost() and p2.is_ghost()) { |
| 136 | + return false; |
| 137 | + } |
| 138 | + return true; |
| 139 | + } |
| 140 | +}; |
| 141 | + |
| 142 | +class GlueToSurf { |
| 143 | +public: |
| 144 | + double distance; |
| 145 | + // Square of distance at which particle are bound |
| 146 | + double distance_sq; |
| 147 | + /// bond type used between centers of colliding particles |
| 148 | + int bond_centers; |
| 149 | + /// bond type used between virtual sites |
| 150 | + int bond_vs; |
| 151 | + /// particle type for virtual sites created on collision |
| 152 | + int part_type_vs; |
| 153 | + /// For mode "glue to surface": The distance from the particle which is to be |
| 154 | + /// glued to the new virtual site |
| 155 | + double dist_glued_part_to_vs; |
| 156 | + /// For mode "glue to surface": The particle type being glued |
| 157 | + int part_type_to_be_glued; |
| 158 | + /// For mode "glue to surface": The particle type to which the virtual site is |
| 159 | + /// attached |
| 160 | + int part_type_to_attach_vs_to; |
| 161 | + /// Particle type to which the newly glued particle is converted |
| 162 | + int part_type_after_glueing; |
| 163 | + |
| 164 | + GlueToSurf(double distance, int bond_centers, int bond_vs, int part_type_vs, |
| 165 | + double dist_glued_part_to_vs, int part_type_to_be_glued, |
| 166 | + int part_type_to_attach_vs_to, int part_type_after_glueing) |
| 167 | + : distance{distance}, distance_sq{distance * distance}, |
| 168 | + bond_centers{bond_centers}, bond_vs{bond_vs}, |
| 169 | + part_type_vs{part_type_vs}, |
| 170 | + dist_glued_part_to_vs{dist_glued_part_to_vs}, |
| 171 | + part_type_to_be_glued{part_type_to_be_glued}, |
| 172 | + part_type_to_attach_vs_to{part_type_to_attach_vs_to}, |
| 173 | + part_type_after_glueing{part_type_after_glueing} {} |
| 174 | + |
| 175 | + void initialize(BondedInteractionsMap &bonded_ias, |
| 176 | + InteractionsNonBonded &nonbonded_ias); |
| 177 | + |
| 178 | + auto cutoff() const { return distance; } |
| 179 | + |
| 180 | + /** @brief Check additional criteria for the glue_to_surface collision mode */ |
| 181 | + bool glue_to_surface_criterion(Particle const &p1, Particle const &p2) const { |
| 182 | + return (((p1.type() == part_type_to_be_glued) and |
| 183 | + (p2.type() == part_type_to_attach_vs_to)) or |
| 184 | + ((p2.type() == part_type_to_be_glued) and |
| 185 | + (p1.type() == part_type_to_attach_vs_to))); |
| 186 | + } |
| 187 | + |
| 188 | + void handle_collisions(System::System &system, |
| 189 | + std::vector<CollisionPair> &local_collision_queue); |
| 190 | + |
| 191 | + bool detect_collision(Particle const &p1, Particle const &p2, |
| 192 | + double const dist_sq) const { |
| 193 | + if (dist_sq > distance_sq) |
| 194 | + return false; |
| 195 | + |
| 196 | + // If we are in the glue to surface mode, check that the particles |
| 197 | + // are of the right type |
| 198 | + |
| 199 | + if (!glue_to_surface_criterion(p1, p2)) |
| 200 | + return false; |
| 201 | + |
| 202 | + // Ignore virtual particles |
| 203 | + if (p1.is_virtual() or p2.is_virtual()) |
| 204 | + return false; |
| 205 | + |
| 206 | + // Check, if there's already a bond between the particles |
| 207 | + if (pair_bond_exists_on(p1.bonds(), p2.id(), bond_centers)) |
| 208 | + return false; |
| 209 | + |
| 210 | + if (pair_bond_exists_on(p2.bonds(), p1.id(), bond_centers)) |
| 211 | + return false; |
| 212 | + |
| 213 | + /* If we're still here, there is no previous bond between the particles, |
| 214 | + we have a new collision */ |
| 215 | + |
| 216 | + // do not create bond between ghost particles |
| 217 | + if (p1.is_ghost() and p2.is_ghost()) { |
| 218 | + return false; |
| 219 | + } |
| 220 | + return true; |
| 221 | + } |
| 222 | +}; |
| 223 | +#endif // VIRTUAL_SITES_RELATIVE |
| 224 | +using ActiveProtocol = std::variant<Off, BindCenters, |
| 225 | +#ifdef VIRTUAL_SITES_RELATIVE |
| 226 | + BindVS, GlueToSurf |
| 227 | +#endif // VIRTUAL_SITES_RELATIVE |
| 228 | + >; |
| 229 | +} // namespace Collision |
| 230 | +#endif |
0 commit comments