GCC Code Coverage Report


Directory: ./
File: src/percolation.cpp
Date: 2024-04-18 12:22:13
Exec Total Coverage
Lines: 2 47 4.3%
Functions: 1 4 25.0%
Branches: 0 13 0.0%

Line Branch Exec Source
1 #include "percolation.hpp"
2 #include "interaction.hpp"
3 #include "particle.hpp"
4 #include "potentials.hpp"
5 #include "types.hpp"
6 #include <algorithm>
7 #include <iterator>
8 #include <map>
9 #include <set>
10
11 Clusterer::Clusterer(std::vector<Particle> &particles, const Vec &L, double cutoff,
12 std::vector<int> &particle2Coordination, std::vector<int> &particle2Cluster,
13 std::map<int, std::list<int>> &cluster2Particles)
14 : particles(particles), L(L), cutoff(cutoff), cutoffsq(cutoff * cutoff),
15 particle2Coordination(particle2Coordination), particle2Cluster(particle2Cluster),
16 cluster2Particles(cluster2Particles) {}
17
18 double Clusterer::operator()(Particle &p1, Particle &p2) {
19 int i = std::distance(&particles.front(), &p1);
20 int j = std::distance(&particles.front(), &p2);
21 double distsq = r_ij(L, particles[i].r, particles[j].r).squaredNorm();
22 if (distsq < cutoffsq && particle2Cluster[i] != particle2Cluster[j]) {
23 particle2Coordination[i]++;
24 particle2Coordination[j]++;
25 int oldCluster = std::max(particle2Cluster[i], particle2Cluster[j]);
26 int newCluster = std::min(particle2Cluster[i], particle2Cluster[j]);
27 for (int i : cluster2Particles[oldCluster]) {
28 particle2Cluster[i] = newCluster;
29 }
30 cluster2Particles[newCluster].splice(cluster2Particles[newCluster].end(),
31 cluster2Particles[oldCluster]);
32 }
33 return 0.;
34 }
35
36 75 Percolation::Percolation(System *system)
37 75 : system(system), tLast(std::numeric_limits<double>::quiet_NaN()) {}
38
39 void Percolation::update() {
40 if (system->t == tLast) {
41 return;
42 }
43 // Initialize data structures
44 this->tLast = system->t;
45 int n = system->particles.size();
46 numClusters = 0;
47 coordinationCount.clear();
48 coordinationCount.resize(n + 1);
49 clusterSizeCount.clear();
50 clusterSizeCount.resize(n + 1);
51 particle2Coordination.resize(n);
52 std::fill(particle2Coordination.begin(), particle2Coordination.end(), 0);
53 particle2Cluster.resize(n);
54 for (int i = 0; i < n; ++i) {
55 particle2Cluster[i] = i;
56 cluster2Particles[i] = {i};
57 }
58 // Do the clustering algorithm
59 Clusterer clusterer(system->particles, system->L, system->interaction->internal->range,
60 particle2Coordination, particle2Cluster, cluster2Particles);
61 system->interaction->iteratePairs(clusterer, true, false);
62 // Do the coordination statistics
63 // Just go through all particles and make a histogram of the coordinations
64 for (int coord : particle2Coordination) {
65 coordinationCount[coord]++;
66 }
67 // Do the cluster sizes
68 // Go through all cluster lists and get their sizes
69 for (auto &[_, particlesInCluster] : cluster2Particles) {
70 int clusterSize = particlesInCluster.size();
71 if (clusterSize > 0) {
72 numClusters++;
73 clusterSizeCount[clusterSize] += clusterSize;
74 }
75 }
76 // coordinationCount and clusterSizeCount are normed to the number of particles
77 }
78