ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
core/collision_detection/CollisionDetection.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 "
ActiveProtocol.hpp
"
27
#include "
CollisionPair.hpp
"
28
29
#include "
Particle.hpp
"
30
#include "system/Leaf.hpp"
31
32
#include <memory>
33
#include <utility>
34
#include <variant>
35
#include <vector>
36
37
namespace
CollisionDetection
{
38
39
class
CollisionDetection
:
public
System::Leaf
<CollisionDetection> {
40
std::shared_ptr<ActiveProtocol> m_protocol;
41
42
public
:
43
CollisionDetection
() =
default
;
44
/** @brief Get currently active collision protocol. */
45
auto
get_protocol
()
const
{
return
m_protocol; }
46
/** @brief Set a new collision protocol. */
47
void
set_protocol(std::shared_ptr<ActiveProtocol> protocol);
48
/** @brief Delete the currently active collision protocol. */
49
void
unset_protocol();
50
/** @brief Validate parameters and create particle types if needed. */
51
void
initialize();
52
53
auto
is_off
()
const
{
54
return
m_protocol ==
nullptr
or std::holds_alternative<Off>(*m_protocol);
55
}
56
57
auto
cutoff
()
const
{
58
if
(m_protocol ==
nullptr
) {
59
return
INACTIVE_CUTOFF
;
60
}
61
return
std::visit([](
auto
const
&protocol) {
return
protocol.cutoff(); },
62
*m_protocol);
63
}
64
65
/// Handle queued collisions
66
void
handle_collisions();
67
68
void
clear_queue
() { local_collision_queue.clear(); }
69
70
/** @brief Detect (and queue) a collision between the given particles. */
71
void
detect_collision
(
Particle
const
&p1,
Particle
const
&p2,
72
double
const
dist_sq) {
73
if
(m_protocol) {
74
bool
collision_detected = std::visit(
75
[&p1, &p2, dist_sq](
auto
const
&protocol) {
76
return
protocol.detect_collision(p1, p2, dist_sq);
77
},
78
*m_protocol);
79
80
if
(collision_detected) {
81
local_collision_queue.emplace_back(p1.
id
(), p2.
id
());
82
}
83
}
84
}
85
/// During force calculation, colliding particles are recorded in the queue.
86
/// The queue is processed after force calculation, when it is safe to add
87
/// particles.
88
std::vector<CollisionPair>
local_collision_queue
;
89
};
90
91
}
// namespace CollisionDetection
92
93
#endif
// COLLISION_DETECTION
ActiveProtocol.hpp
CollisionPair.hpp
Particle.hpp
CollisionDetection::CollisionDetection::is_off
auto is_off() const
Definition
core/collision_detection/CollisionDetection.hpp:53
CollisionDetection::CollisionDetection::clear_queue
void clear_queue()
Definition
core/collision_detection/CollisionDetection.hpp:68
CollisionDetection::CollisionDetection::get_protocol
auto get_protocol() const
Get currently active collision protocol.
Definition
core/collision_detection/CollisionDetection.hpp:45
CollisionDetection::CollisionDetection::cutoff
auto cutoff() const
Definition
core/collision_detection/CollisionDetection.hpp:57
CollisionDetection::CollisionDetection::CollisionDetection
CollisionDetection()=default
CollisionDetection::CollisionDetection::detect_collision
void detect_collision(Particle const &p1, Particle const &p2, double const dist_sq)
Detect (and queue) a collision between the given particles.
Definition
core/collision_detection/CollisionDetection.hpp:71
CollisionDetection::CollisionDetection::local_collision_queue
std::vector< CollisionPair > local_collision_queue
During force calculation, colliding particles are recorded in the queue. The queue is processed after...
Definition
core/collision_detection/CollisionDetection.hpp:88
System::Leaf
Abstract class that represents a component of the system.
Definition
core/system/Leaf.hpp:34
config.hpp
This file contains the defaults for ESPResSo.
CollisionDetection
Definition
ActiveProtocol.hpp:33
INACTIVE_CUTOFF
constexpr double INACTIVE_CUTOFF
Cutoff for deactivated interactions.
Definition
nonbonded_interaction_data.hpp:44
Particle
Struct holding all information for one particle.
Definition
Particle.hpp:395
Particle::id
auto const & id() const
Definition
Particle.hpp:414
src
core
collision_detection
CollisionDetection.hpp
Generated on Thu Dec 19 2024 02:13:16 for ESPResSo by
1.9.8