ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
core/observables/PairwiseDistances.hpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2025 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 "
BoxGeometry.hpp
"
23
#include "
PidPairwiseDistancesObservable.hpp
"
24
#include "
cell_system/CellStructure.hpp
"
25
#include "
cells.hpp
"
26
#include "
particle_node.hpp
"
27
#include "system/System.hpp"
28
29
#include <algorithm>
30
#include <cstddef>
31
#include <set>
32
#include <stdexcept>
33
#include <utility>
34
#include <vector>
35
36
namespace
Observables
{
37
38
/** @brief Track pairwise distances between two sets of particles. */
39
class
PairwiseDistances
:
public
PidPairwiseDistancesObservable
{
40
public
:
41
using
PidPairwiseDistancesObservable::PidPairwiseDistancesObservable
;
42
explicit
PairwiseDistances
(std::vector<int>
const
&
ids
,
43
std::vector<int>
const
&
target_ids
)
44
:
PidPairwiseDistancesObservable
(
ids
,
target_ids
),
45
m_pairs{get_unique_pairs(
ids
,
target_ids
)} {}
46
47
/** @brief Evaluate the current contact times */
48
std::vector<double>
49
evaluate
(boost::mpi::communicator
const
&comm,
ParticleReferenceRange
const
&,
50
ParticleObservables::traits<Particle>
const
&)
const override
{
51
52
if
(comm.rank() != 0) {
53
return
{};
54
}
55
// Get instances of the system and cell structures
56
auto
const
&
system
=
System::get_system
();
57
auto
const
&box_geo = *
system
.box_geo;
58
auto
&cell_structure = *
system
.cell_structure;
59
60
std::vector<double>
pairwise_distances
;
61
for
(
auto
const
&[
pid1
,
pid2
] : m_pairs) {
62
auto
const
*
p1
= cell_structure.get_local_particle(
pid1
);
63
auto
const
*
p2
= cell_structure.get_local_particle(
pid2
);
64
auto
const
dist
= box_geo.get_mi_vector(
p1
->pos(),
p2
->pos()).norm();
65
pairwise_distances
.emplace_back(
dist
);
66
}
67
return
pairwise_distances
;
68
}
69
70
std::vector<std::size_t>
shape
()
const override
{
return
{m_pairs.size()}; }
71
72
private
:
73
std::vector<std::pair<int, int>> m_pairs;
74
75
std::vector<std::pair<int, int>>
76
get_unique_pairs(std::vector<int>
const
&ids1, std::vector<int>
const
&ids2) {
77
std::set<std::pair<int, int>>
unique_pairs
;
78
for
(
int
id1 : ids1) {
79
for
(
int
id2 : ids2) {
80
if
(id1 != id2) {
81
unique_pairs
.emplace(std::minmax(id1, id2));
82
}
83
}
84
}
85
return
{
unique_pairs
.begin(),
unique_pairs
.end()};
86
}
87
};
88
89
}
// namespace Observables
BoxGeometry.hpp
CellStructure.hpp
PidPairwiseDistancesObservable.hpp
cells.hpp
This file contains everything related to the global cell structure / cell system.
Observables::PairwiseDistances
Track pairwise distances between two sets of particles.
Definition
core/observables/PairwiseDistances.hpp:39
Observables::PairwiseDistances::evaluate
std::vector< double > evaluate(boost::mpi::communicator const &comm, ParticleReferenceRange const &, ParticleObservables::traits< Particle > const &) const override
Evaluate the current contact times.
Definition
core/observables/PairwiseDistances.hpp:49
Observables::PairwiseDistances::shape
std::vector< std::size_t > shape() const override
Definition
core/observables/PairwiseDistances.hpp:70
Observables::PairwiseDistances::PairwiseDistances
PairwiseDistances(std::vector< int > const &ids, std::vector< int > const &target_ids)
Definition
core/observables/PairwiseDistances.hpp:42
Observables::PidObservable::ids
std::vector< int > const & ids() const
Definition
core/observables/PidObservable.hpp:67
Observables::PidPairwiseDistancesObservable
Calculate pairwise distances between two sets of particles.
Definition
PidPairwiseDistancesObservable.hpp:30
Observables::PidPairwiseDistancesObservable::target_ids
std::vector< int > const & target_ids() const
Definition
PidPairwiseDistancesObservable.hpp:37
Observables::PidPairwiseDistancesObservable::PidPairwiseDistancesObservable
PidPairwiseDistancesObservable(std::vector< int > const &ids, std::vector< int > const &target_ids)
Definition
PidPairwiseDistancesObservable.hpp:34
stream
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
Definition
common_cuda.cu:34
Observables
Definition
BondAngles.hpp:37
Observables::ParticleReferenceRange
std::vector< std::reference_wrapper< Particle const > > ParticleReferenceRange
Definition
core/observables/PidObservable.hpp:47
System::get_system
System & get_system()
Definition
core/system/System.cpp:132
particle_node.hpp
Particles creation and deletion.
ParticleObservables::traits
Definition
properties.hpp:27
src
core
observables
PairwiseDistances.hpp
Generated on Mon Dec 8 2025 02:32:30 for ESPResSo by
1.9.8