ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
core/cluster_analysis/ClusterStructure.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2026 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 "pair_criteria/PairCriterion.hpp"
24
25#include "Cluster.hpp"
26#include "Particle.hpp"
27
28#include <cassert>
29#include <map>
30#include <memory>
31
32namespace ClusterAnalysis {
33
34/** @brief Holds the result and parameters of a cluster analysis */
36public:
37 /** @brief Map holding the individual clusters. The key is an integer cluster
38 * id */
39 std::map<int, std::shared_ptr<Cluster>> clusters;
40 /** @brief Map between particle ids and corresponding cluster ids */
41 std::map<int, int> cluster_id;
42 /** @brief Clear data structures */
43 void clear();
44 /** @brief Run cluster analysis, consider all particle pairs */
45 void run_for_all_pairs();
46 /** @brief Run cluster analysis, consider pairs of particles connected by a
47 * bonded interaction */
49 /** Is particle p part of a cluster */
50 bool part_of_cluster(Particle const &p) const {
51 return cluster_id.contains(p.id());
52 }
53 /** Sets the pair criterion which decides if two particles are neighbors */
54 void
55 set_pair_criterion(std::shared_ptr<PairCriteria::PairCriterion> const &c) {
56 m_pair_criterion = c;
57 }
58
60 return *m_pair_criterion;
61 }
62
63 void attach(std::weak_ptr<BoxGeometry const> const &box_geo) {
64 m_box_geo = box_geo;
65 }
66
67private:
68 /**
69 * @brief Cluster id graph.
70 * Clusters that turn out to be the same during the analysis process
71 * (i.e., if two particles are neighbors that already belong to different
72 * clusters) are automatically merged and mapped to a new id.
73 * Additional merges create additional nodes. Traverse this graph
74 * recursively with @c find_id_for to determine the final id
75 * of a cluster that was merged multiple times.
76 */
77 std::map<int, int> m_cluster_identities;
78
79 /** @brief pair criterion which decides whether two particles are neighbors */
80 std::shared_ptr<PairCriteria::PairCriterion> m_pair_criterion;
81
82 /** @brief Consider an individual pair of particles during cluster analysis */
83 void add_pair(const Particle &p1, const Particle &p2);
84 /** Merge clusters and populate their structures */
85 void merge_clusters();
86 /** @brief Follow a chain of cluster identities during analysis */
87 inline int find_id_for(int x) const;
88 /** @brief Get next free cluster id */
89 inline int get_next_free_cluster_id();
90 void sanity_checks() const;
91 auto get_box_geo() const {
92 auto ptr = m_box_geo.lock();
93 assert(ptr);
94 return ptr;
95 }
96 mutable std::weak_ptr<BoxGeometry const> m_box_geo;
97};
98
99} // namespace ClusterAnalysis
Holds the result and parameters of a cluster analysis.
std::map< int, int > cluster_id
Map between particle ids and corresponding cluster ids.
void clear()
Clear data structures.
void run_for_bonded_particles()
Run cluster analysis, consider pairs of particles connected by a bonded interaction.
PairCriteria::PairCriterion const & pair_criterion() const
void run_for_all_pairs()
Run cluster analysis, consider all particle pairs.
bool part_of_cluster(Particle const &p) const
Is particle p part of a cluster.
std::map< int, std::shared_ptr< Cluster > > clusters
Map holding the individual clusters.
void attach(std::weak_ptr< BoxGeometry const > const &box_geo)
void set_pair_criterion(std::shared_ptr< PairCriteria::PairCriterion > const &c)
Sets the pair criterion which decides if two particles are neighbors.
Criterion which returns a true/false value for a pair of particles.
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
Struct holding all information for one particle.
Definition Particle.hpp:435
auto const & id() const
Definition Particle.hpp:454