-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlaneSource_PhaseWaves.go
248 lines (191 loc) · 7.84 KB
/
PlaneSource_PhaseWaves.go
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
///////////////////////////////////////////////////////////////
//
// Cellular automaton version Linear Schrodinger-like waves
// This is a single time-deriv phase based Schrodinger-like
// with no intentional conservation, just transmitted vector
// Instead of an exterior restoring force, we now have an interior
// memory of intermediate velocity as a phase shift
//
// In this version the amplitude source starts from the left
// as a single points source which has to pass through the slits
//
// Changing arg ss to ds opens the XXX sluices ...
//
///////////////////////////////////////////////////////////////
package main
import (
// "fmt"
"os"
C "Cellibrium"
)
// **********************************************************
const DoF = 10000
const wrange = 10000
const PERIOD = C.WAVELENGTH * wrange
// ****************************************************************
func main () {
C.MODEL_NAME = "LongSourceSlits"
var st [C.Ylim]string
switch os.Args[1] {
case "ds" : C.DOUBLE_SLIT = true
case "ss" : C.DOUBLE_SLIT = false
}
st[0] = "*************************************"
st[1] = "*........*..........................|"
st[2] = "*........*..........................|"
st[3] = "*........*..........................|"
st[4] = "*........*..........................|"
st[5] = "*........*..........................|"
st[6] = "*........*..........................|"
st[7] = "*........*..........................|"
st[8] = "*........*..........................|"
st[9] = "*........*..........................|"
st[10] = "*........*..........................|"
st[11] = "*........*..........................|"
st[12] = "*........*..........................|"
st[13] = "*........*..........................|"
st[14] = "*........*..........................|"
st[15] = "*........*..........................|"
st[16] = "*........*..........................|"
st[17] = "*........*..........................|"
st[18] = "*........*..........................|"
st[19] = "*........*..........................|"
st[20] = "*........*..........................|"
st[21] = "*........*..........................|"
st[22] = "*........*..........................|"
st[23] = "*........*..........................|"
st[24] = "*........*..........................|"
st[25] = "*........*..........................|"
st[26] = "*........*..........................|"
st[27] = "*........<..........................|" // X
st[28] = "*........<..........................|" // X
st[29] = "*........<..........................|" // X
st[30] = "*........*..........................|"
st[31] = "*........*..........................|"
st[32] = "*........*..........................|"
st[33] = "*........*..........................|"
st[34] = "*........*..........................|"
st[35] = "*........*..........................|"
st[36] = "*........*..........................|"
st[37] = "*........*..........................|"
st[38] = "*........*..........................|"
st[39] = "*........*..........................|"
st[40] = "*........*..........................|"
st[41] = "*........*..........................|"
st[42] = "*........*..........................|"
st[43] = "*........*..........................|"
st[44] = "*........*..........................|"
st[45] = "*........*..........................|"
st[46] = "*........*..........................|"
st[47] = "*........>..........................|"
st[48] = "*........>..........................|"
st[49] = "*........>..........................|"
st[50] = "*........*..........................|"
st[51] = "*........*..........................|"
st[52] = "*........*..........................|"
st[53] = "*........*..........................|"
st[54] = "*........*..........................|"
st[55] = "*........*..........................|"
st[56] = "*........*..........................|"
st[57] = "*........*..........................|"
st[58] = "*........*..........................|"
st[59] = "*........*..........................|"
st[60] = "*........*..........................|"
st[61] = "*........*..........................|"
st[62] = "*........*..........................|"
st[63] = "*........*..........................|"
st[64] = "*........*..........................|"
st[65] = "*........*..........................|"
st[66] = "*........*..........................|"
st[67] = "*........*..........................|"
st[68] = "*........*..........................|"
st[69] = "*........*..........................|"
st[70] = "*........*..........................|"
st[71] = "*........*..........................|"
st[72] = "*........*..........................|"
st[73] = "*........*..........................|"
st[74] = "*........*..........................|"
st[75] = "*************************************"
// Keep the data structures for agents global too for convenience
C.Initialize(st,DoF)
C.ShowState(st,1,37,76,"+")
EquilGuideRail()
//C.ShowState(st,C.MAXTIME,37,76,"+")
C.ShowAffinity(st,C.MAXTIME,37,76)
//go C.MovingPromise()
//C.ShowPhase(st,C.MAXTIME,37,76)
}
// ****************************************************************
func EquilGuideRail() {
for i := 1; i < C.Adim; i++ {
go UpdateAgent_Flow(i)
}
}
// ****************************************************************
func UpdateAgent_Flow(agent int) {
// Start with an unconditional promise to break the deadlock symmetry
for direction := 0; direction < C.N; direction++ {
neighbour := C.AGENT[agent].Neigh[direction]
if neighbour != 0 {
var breaker C.Message
breaker.Value = C.AGENT[agent].Psi
breaker.Angle = C.AGENT[agent].Theta
breaker.Phase = C.TICK
C.CHANNEL[agent][neighbour] = breaker
}
}
C.CausalIndependence(true)
for t := 0; t < C.MAXTIME; t++ {
// Every pair of agents has a private directional channel that's not overwritten by anyone else
// Messages persist until they are read and cannot unseen
for direction := 0; direction < C.N; direction++ {
var send,recv C.Message
neighbour := C.AGENT[agent].Neigh[direction]
if neighbour == 0 {
continue // wall signal
}
recv = C.AcceptFromChannel(neighbour,agent)
// ****************** PROCESS *********************
// We put directional updates per direction instead of
// for all at once (grad rather than Laplacian) to get
// more accurate updates..
C.AGENT[agent] = EvolvePsi(C.AGENT[agent],direction)
switch recv.Phase {
case C.TICK:
C.AGENT[agent].V[direction] = recv.Value
send.Value = C.AGENT[agent].Psi
send.Angle = C.AGENT[agent].Theta
send.Phase = C.TICK
C.ConditionalChannelOffer(agent,neighbour,send)
}
}
// If we put a full Laplacian here, we get poor results
}
}
// ****************************************************************
func EvolvePsi(agent C.STAgent,direction int) C.STAgent { // Laplacian
/* The challenge is to stop Psi from growing in amplitude so that differences
no longer matter and the waves eventually stop propagating. It' s very
hard to do this with small integer arithmetic .. which suggests that the smoothness
of quantum phenomena suggest that there is plenty of room at the bottom for large numbers. */
agent.Theta += dTheta(agent,direction) // float64(int(dTheta(agent)+0.5) % PERIOD)
agent.Psi += dPsi(agent)
return agent
}
// ******************************************************************
func dTheta(agent C.STAgent,di int) float64 { // Laplacian
var d2 float64 = 0
const dt = 0.01
const mass = 2.0
// Velocity = laplaciant gradient
d2 += agent.V[di] - agent.Psi
// This is negative when Psi is higher than neighbours
dtheta := dt * d2 / float64(C.N * mass)
return dtheta
}
// ******************************************************************
func dPsi(agent C.STAgent) float64 { // Laplacian
const dt = 0.01
deltaPsi := agent.Theta * dt
return deltaPsi
}