42 m_cluster_identities.clear();
56 auto const box_geo_handle = get_box_geo();
57 auto const &box_geo = *box_geo_handle;
61 this->add_pair(p1, p2);
69 auto const box_geo_handle = get_box_geo();
70 auto const &box_geo = *box_geo_handle;
72 for (
const auto &p : partCfg) {
73 for (
auto const bond : p.bonds()) {
74 if (bond.partner_ids().size() == 1) {
92 if (!m_pair_criterion) {
97 if (m_pair_criterion->decide(p1, p2)) {
102 const int cid = get_next_free_cluster_id();
124 m_cluster_identities[cid1] = cid2;
125 }
else if (cid1 < cid2) {
126 m_cluster_identities[cid2] = cid1;
136void ClusterStructure::merge_clusters() {
142 std::vector<std::pair<int, int>> to_be_changed;
148 const int cid = find_id_for(it.second);
151 to_be_changed.emplace_back(it.first, cid);
154 clusters[cid] = std::make_shared<Cluster>(m_box_geo);
159 for (
auto it : to_be_changed) {
170 clusters[it.second] = std::make_shared<Cluster>(m_box_geo);
172 clusters[it.second]->particles.push_back(it.first);
177 std::sort(c.second->particles.begin(), c.second->particles.end());
181int ClusterStructure::find_id_for(
int x) {
183 while (m_cluster_identities.find(tmp) != m_cluster_identities.end()) {
184 tmp = m_cluster_identities[tmp];
189int ClusterStructure::get_next_free_cluster_id() {
191 int max_seen_cluster = 0;
194 if (max_seen_cluster < cid) {
195 max_seen_cluster = cid;
198 return max_seen_cluster + 1;
201void ClusterStructure::sanity_checks()
const {
203 throw std::runtime_error(
204 "Cluster analysis is not compatible with non-cuboid box types");
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.
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.
Particle cache on the head node.
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
#define runtimeErrorMsg()
void for_each_pair(ForwardIterator first, ForwardIterator last, BinaryOp op)
Execute op for each pair of elements in [first, last) once.
const Particle & get_particle_data(int p_id)
Get particle data.
Particles creation and deletion.
Struct holding all information for one particle.