-
Notifications
You must be signed in to change notification settings - Fork 1
/
switching_events.py
184 lines (165 loc) · 5.52 KB
/
switching_events.py
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
"""
## Steps:
1) define the various constants
2) create data structure and Poisson Distribution processes
3) loop over all samples
i) generate "common" QP events
ii) generate "rare" QP events
iii) generate "pair recombination" events
iv) generate "trapping events"
v) generate "untrapping" events
4) compute number of QPs in trapped state and other states (annhilated,untrapped)
5) compute and store the effect on "frequency shift terms for each time point"
"""
def simulateTrappingDynamics():
nGenerated = []
nBulk = []
nTrapped = []
nReleased = []
nAnnhilated = []
for t in time_range:
"""
first event
"""
if t == 1:
nBulk.append(0)
nTrapped.append(0)
"""
generate QPs
"""
qp_generated = generate_qp(generation_process())
"""
add generated QP stay to bulk
"""
qp_bulk = nBulk[t - 1] + qp_generated
"""
annhilate QPs from bulk from previous time step
"""
qp_recombined = recombine_qp(annhilation_process(), nBulk[t - 1])
"""
remove qp from bulk that recombined
"""
qp_bulk = qp_bulk - qp_recombined
"""
Trap QPs
"""
qp_trapped = trap_qp(trapping_process(), qp_bulk) + nTrapped[t - 1]
"""
Release QPs
"""
qp_untrapped = release_qp(release_process(), nTrapped[t - 1])
"""
Update the number of trapped QP
"""
qp_trapped = qp_trapped - qp_untrapped
"""
Update QP number in bulk
"""
qp_bulk = qp_bulk - qp_trapped
"""
store values to disc
"""
nGenerated.append(qp_generated)
nAnnhilated.append(qp_recombined)
nTrapped.append(qp_trapped)
nReleased.append(qp_untrapped)
nBulk.append(qp_bulk)
"""
Calculate Shift In Frequency
"""
measure_frequency_shift()
def getSwitchingEvents():
"""
Constants Defining
"""
phi0 = phi0
rphi0 = phi0 / (2 * pi)
alpha = Delta / (2 * (rphi0**2))
"""
Creating Poisson Distribution for the various process
"""
cs = array([1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int) #channels?
factorials = array([factorial(k) for k in cs],
dtype=int) #factorials of cs values
pR = ((dt / tauR)**cs) * exp(
-dt / tauR) / factorials #poisson distribution of release
pT = ((dt / tau)**cs) * exp(
-dt / tau) / factorials #poisson distribution of trap
pCommon = ((dt / tauCommon)**cs) * exp(
-dt / tauCommon) / factorials #poisson distribution of common
pRare = ((dt / tauRare)**cs) * exp(
-dt / tauRare) / factorials #poisson distribution of cosmic
pRecomb = ((dt / tauRecomb)**cs) * exp(
-dt / tauRecomb) / factorials #poisson distribution of recombine
"""
Data Structures for storing info from simulation
"""
trappedChannels = [] #?
nTrapped = [] #number of trapped QP
lFreqFactors = [] #?
# alpha = Delta/(4*(rphi0**2))
freqFactors = zeros(N) #?
nBulk = list(ones(3)) #3D vector for some reason?
bulkPop = [] #?
burstIndices = [] #?
for n in range(N):
"""
Produce common QP generation events
"""
commask = random() < pCommon
k = cs[commask][-1] if commask.any() else 0
for _ in range(k):
nBulk.append(1)
nBulk.append(1)
"""
Produce rare QP generation events -- such as cosmic ray bursts
"""
raremask = random() < pRare
k = cs[raremask][-1] if raremask.any() else 0
for _ in range(k):
burstIndices.append(n)
burst = int(random() * 50)
for i in range(burst):
nBulk.append(1)
nBulk.append(1)
"""
Produce pair recombination events
"""
recombmask = random() < len(nBulk) * pRecomb
k = cs[recombmask][-1] if recombmask.any() else 0
k = min((k, len(nBulk) // 2))
for _ in range(k):
nBulk.remove(1)
nBulk.remove(1)
"""
Produce trapping events
"""
trapmask = random() < len(nBulk) * pT
k = cs[trapmask][-1] if trapmask.any() else 0
k = min((k, len(nBulk)))
for _ in range(k):
tau = _MC_doro(Ne, Delta, de, T)
E = _Ea(tau, Delta, de)
trappedChannels.append({'t': tau, 'E': E})
if nBulk:
nBulk.remove(1)
"""
Produce release events
"""
relmask = random() < len(trappedChannels) * pR
k = cs[relmask][-1] if relmask.any() else 0
k = min((k, len(trappedChannels)))
for _ in range(k):
ch = choice(trappedChannels)
trappedChannels.remove(ch)
nBulk.append(1)
# Track changes
nTrapped.append(len(trappedChannels))
bulkPop.append(len(nBulk))
# Calculate frequency shift terms for each time point -- Sum_i 1/L_i
lFreqFactors.append([
alpha * c['t'] * (cosd / sqrt(1 - c['t'] * sin2) + c['t'] * sind2 /
(4 * sqrt(1 - c['t'] * sin2)**3))
for c in trappedChannels
])
freqFactors[n] += sum(lFreqFactors[n])