-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathburningAlgorithm.py
More file actions
127 lines (91 loc) · 5.03 KB
/
Copy pathburningAlgorithm.py
File metadata and controls
127 lines (91 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 22 01:31:06 2022
@author: Laura Stricker, laura.stricker@mat.ethz.ch
Subroutines implementing burning algorithm described in
H J Herrmann et al, J. Phys. A: Math. Gen., 17 L261, 1984
"""
def forwardBurning(DM,backbone):
'''
FIRST BURNING ROUND (FORWARD):
It finds the length of elastic backbone, i.e. min number of connected particles
and min path length between P1-P2 (sum of distances between connected particles)
Parameters
----------
DM: CLASS(DataManager)
it includes all particles of largest cluster,box info and
conversion lookup from particle ID to index
Returns
-------
backbone.burningTimeForward: INT
backbone.minPathLength = FLOAT
sum of interparticle distances along min connected path
'''
firstBurntParticle = backbone.extremes[0] #pointers
lastBurntParticle = backbone.extremes[1]
burningTimeIndex = 1;
burntParticles = [firstBurntParticle]
firstBurntParticle.isBurntByParticleIndex = -1
firstBurntParticle.forwardBurningTime = burningTimeIndex
while burntParticles: #Exit condition: when nothing was found to burn
burningTimeIndex = burningTimeIndex + 1 #Burning step; consider it as a time!
burntParticlesAtPreviousTime = burntParticles
burntParticles = [];
#Loop over particles burnt at previous time
for particle in burntParticlesAtPreviousTime:
#Loop over neighbours of particle
for neighbourID in particle.neighbourIDs:
neighbourIndex = DM.getParticleIndexFromID(neighbourID)
neighbour = DM.particles[neighbourIndex]
#If the link is inside the box or via periodic boundary conditions
if neighbour.isConnectedThroughBox(particle, DM.box):
if not neighbour.isBurnt(): #if neighbour has not been burnt yet
neighbour.forwardBurningTime = burningTimeIndex
neighbour.isBurntByParticleIndex = particle.index
burntParticles.append(neighbour)
backbone.getSummaryForwardBurning(DM.particles,firstBurntParticle,lastBurntParticle)
#----------------------------------------------------------------------------------
def backwardBurning(DM,backbone):
'''
SECOND BURNING ROUND (BACKWARDS)
It finds the whole elastic backbone,i.e. all equivalent paths connecting points P1,P2
Parameters
----------
DM: CLASS(DataManager)
it includes all particles of largest cluster,box info and
conversion lookup from particle ID to index
Returns
-------
backbone.burningTimeBackward: INT
backbone.allMinPathsParticleCount = INT
total # particles on equivalent min paths between extremes
'''
firstBurntParticle = backbone.extremes[1] #pointers
lastBurntParticle = backbone.extremes[0]
burningTimeIndex = 1;
burntParticles = [firstBurntParticle]
firstBurntParticle.backwardBurningTime = burningTimeIndex
burntParticleCountTot = 0
for particle in DM.particles:
particle.resetBurningStatus()
while burntParticles: #Exit condition: when nothing was found to burn
burningTimeIndex = burningTimeIndex + 1 #Burning step; consider it as a time!
burntParticlesAtPreviousTime = burntParticles
burntParticles = [];
#Loop over particles burnt at previous time
for particle in burntParticlesAtPreviousTime:
#Loop over neighbours of particle
for neighbourID in particle.neighbourIDs:
neighbourIndex = DM.getParticleIndexFromID(neighbourID)
neighbour = DM.particles[neighbourIndex]
#If the link is inside the box or via periodic boundary conditions
if neighbour.isConnectedThroughBox(particle, DM.box):
#if neighbour has not been burnt yet
if (not neighbour.isBurnt()) and\
(neighbour.forwardBurningTime < particle.forwardBurningTime):
#if neighbour was burnt before particle in forward burning
neighbour.backwardBurningTime = burningTimeIndex
neighbour.isBurntByParticleIndex = particle.index
burntParticles.append(neighbour)
burntParticleCountTot += 1 # Number of all burnt particles
backbone.getSummaryBackwardBurning(lastBurntParticle,burntParticleCountTot)