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-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 "BoxGeometry.hpp"
23#include "pair_criteria/PairCriterion.hpp"
24
25#include "Cluster.hpp"
26#include "Particle.hpp"
27
28#include <map>
29#include <memory>
30
31namespace ClusterAnalysis {
32
33/** @brief Holds the result and parameters of a cluster analysis */
35public:
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(const Particle &p);
51 /** Sets the pair criterion which decides if two particles are neighbors */
52 void
53 set_pair_criterion(std::shared_ptr<PairCriteria::PairCriterion> const &c) {
54 m_pair_criterion = c;
55 }
56
58 return *m_pair_criterion;
59 }
60
61 void attach(std::weak_ptr<BoxGeometry const> const &box_geo) {
62 m_box_geo = box_geo;
63 }
64
65private:
66 /** @brief Clusters that turn out to be the same during the analysis process
67 * (i.e., if two particles are neighbors that already belong to different
68 * clusters
69 */
70 std::map<int, int> m_cluster_identities;
71
72 /** @brief pair criterion which decides whether two particles are neighbors */
73 std::shared_ptr<PairCriteria::PairCriterion> m_pair_criterion;
74
75 /** @brief Consider an individual pair of particles during cluster analysis */
76 void add_pair(const Particle &p1, const Particle &p2);
77 /** Merge clusters and populate their structures */
78 void merge_clusters();
79 /** @brief Follow a chain of cluster identities during analysis */
80 inline int find_id_for(int x);
81 /** @brief Get next free cluster id */
82 inline int get_next_free_cluster_id();
83 void sanity_checks() const;
84 auto get_box_geo() const {
85 auto ptr = m_box_geo.lock();
86 assert(ptr);
87 return ptr;
88 }
89 mutable std::weak_ptr<BoxGeometry const> m_box_geo;
90};
91
92} // 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.
bool part_of_cluster(const Particle &p)
Is particle p part of a cluster.
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.
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.
Struct holding all information for one particle.
Definition Particle.hpp:395