-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWaves.go
236 lines (179 loc) · 7.38 KB
/
Waves.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
///////////////////////////////////////////////////////////////
//
// Cellular automaton version of spherical waves emanating from
// a source
// with no intentional conservation, just transmitted vector
// This one with smoother waveforms
//
///////////////////////////////////////////////////////////////
package main
import (
C "Cellibrium"
)
// **********************************************************
const DoF = 11000.0
const MAXTIME = 100000
const WAVESCALE = 10
// ****************************************************************
func main () {
C.MODEL_NAME = "Waves"
var st [C.Ylim]string
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] = "*...................................|"
st[28] = "*...................................|"
st[29] = "*...................................|"
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] = "*************************************"
// Keep the data structures for agents global too for convenience
C.Initialize(st,DoF)
C.ShowState(st,1,37,66,"+")
EquilGuideRail()
//C.ShowState(st,MAXTIME,37,66,"+")
C.ShowAffinity(st,MAXTIME,37,66)
}
// ****************************************************************
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.Phase = C.TICK
C.CHANNEL[agent][neighbour] = breaker
}
}
const PsiQuant = 1
C.CausalIndependence(true)
for t := 0; t < 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
}
// We need to wait for a positive signal indicating a new transfer to avoid double/empty reading
recv = C.AcceptFromChannel(neighbour,agent)
// ****************** PROCESS *********************
switch recv.Phase {
case C.TICK:
C.AGENT[agent].V[direction] = recv.Value
send.Value = C.AGENT[agent].Psi
send.Phase = C.TICK
C.ConditionalChannelOffer(agent,neighbour,send)
}
}
// Now we have updated messages from our neighbours for their Psi[N]
C.AGENT[agent] = EvolvePsiTypeI(C.AGENT[agent])
}
}
// ****************************************************************
func EvolvePsiTypeI(agent C.STAgent) 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.
The spin case converges over about 100 iterations with a simple two state model, so for
waves with interference */
const affinity = 10
const mass = 9 // odd number 3,5,7
var d2 float64 = 0
var newagent C.STAgent = agent
for di := 0; di < C.N; di++ {
d2 += (agent.V[di] - agent.Psi)
}
// To shorten the wavelength increase v2 - even/odd numbers play a role due to the discrete scale
wavelength := C.WAVELENGTH * WAVESCALE
newtheta := (int(agent.Theta+0.5) + wavelength/8) % C.WAVELENGTH
dpsi := C.WAVE[newtheta] * d2/mass
newagent.Psi = agent.Psi + dpsi
newagent.Theta = float64(newtheta)
return newagent
}
// ****************************************************************
func EvolvePsiTypeII(agent C.STAgent) C.STAgent { // Laplacian
const affinity = 10
const mass = 5 // odd number
var d2 float64 = 0
var newagent C.STAgent = agent
for di := 0; di < C.N; di++ {
d2 += (agent.V[di] - agent.Psi)
}
// To shorten the wavelength increase v2 - even/odd numbers play a role due to the discrete scale
newtheta := (int(agent.Theta+0.5 + d2/mass)) % C.WAVELENGTH;
for offset := C.WAVELENGTH; newtheta < 0; offset += C.WAVELENGTH {
newtheta = (int(agent.Theta+0.5 + d2) + offset) % C.WAVELENGTH;
}
drho := C.WAVE[newtheta] * d2/ mass / C.N
newagent.Psi = agent.Psi + drho
newagent.Theta = float64(newtheta)
return newagent
}