-
Notifications
You must be signed in to change notification settings - Fork 0
/
p.py
193 lines (106 loc) · 4.05 KB
/
p.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
185
186
187
188
189
190
191
import matplotlib.pyplot as plt
import math
import numpy as np
import cmath
import time
import pyopencl as cl
imsized = 10 #4 - 10
rcore = 0.1
List_Strengh_Vortexes = np.array([1.0, -1.0,1.0, -1.0])
List_of_Vort = np.array([-1.0- 0.5j, -1.0 + 0.5j, -0.5 - 0.5j, -0.5 + 0.5j])
kvortexes = len(List_of_Vort)
N = 100 #30 - 1000
#steps = 10 #10 - 300
tmax = 0.7
dt = 0.01
steps = int(tmax/dt)
def RungeUpdateVortInTime(listofz):
#listofz - list of vortices
k1 = dt * value_of_interaction_matrix(listofz)
k2 = dt * value_of_interaction_matrix(listofz + k1/2)
k3 = dt * value_of_interaction_matrix(listofz + k2/2)
k4 = dt * value_of_interaction_matrix(listofz + k3)
#return list [z1 n+1, z2 n+1, z3 n+1, z4 n+1]
return (k1 + 2*k2 + 2*k3 + k4)/6 + listofz
def functionValue(K, z, z0):
r2 = abs(z - z0)**2
temp = K * (z0 - z) / r2 * (1 - math.exp((-r2)/(rcore**2))) * complex(0, 1)
#temp = K * (z0 - z) / (r2 * (1 - cmath.exp((-r2)/(rcore**2)))) * complex(0, 1)
return temp
def value_of_interaction_matrix(Zlist):
#matrixValues = np.zeros((kvortexes, kvortexes), dtype=np.complex128)
matrixSum = np.zeros((kvortexes), dtype=np.complex128)
for i in range(kvortexes):
for j in range(kvortexes):
if i != j:
matrixSum[i] += functionValue(List_Strengh_Vortexes[j], Zlist[i], Zlist[j])
return matrixSum
def caclulateMatrixVortexesInTime():
matrixVortInTime = np.zeros((steps +1, kvortexes), dtype=np.complex128)
matrixVortInTime[0, :] = List_of_Vort
#print(matrixVortInTime)
for i in range(1, steps+1):
matrixVortInTime[i, :] = RungeUpdateVortInTime(matrixVortInTime[i - 1, :])
#print(matrixVortInTime[1, :])
#print(matrixVortInTime[steps - 1, :])
#print(matrixVortInTime[steps, :])
return matrixVortInTime
def evalOnTimeGrid(z, listofZ):
#listofZ - list of vortices
temp = 0
for i in range(kvortexes):
temp += functionValue(List_Strengh_Vortexes[i], z, listofZ[i])
#return complex value
return temp
def RungeEvalInDim(z, listofZ):
#z - poit on the grid, x + iy, y[-2.5, 2.5], x[-2.5, 2.5] or somethinng like that
#listofZ = listofZ[::-1]
k1 = dt * evalOnTimeGrid(z, listofZ)
k2 = dt * evalOnTimeGrid(z + k1/2, listofZ)
k3 = dt * evalOnTimeGrid(z + k2/2, listofZ)
k4 = dt * evalOnTimeGrid(z + k3, listofZ)
#returned complex value to display
return (k1 + 2*k2 + 2*k3 + k4)/6
def display(mesh):
cmap = 'plasma'
plt.figure(num = None, figsize=(imsized, imsized), dpi=300)
plt.axis('off')
#plot = plt.imshow(mesh, cmap = cmap, interpolation='lanczos' )
plot = plt.imshow(mesh, cmap = cmap, interpolation='lanczos')
####
filenameImage = f'test{N}_{steps}_{tmax}_{rcore}_{cmap}_{List_of_Vort[0]}_{List_of_Vort[1]}_{List_of_Vort[2]}_{List_of_Vort[3]}.png'
plt.savefig(filenameImage, bbox_inches = 'tight')
####
plt.show()
plt.close()
def test():
print('0')
def run():
print('start')
# {y, -1.125, 1.125, 2.25/n}, {x, -0.35, 1.9, 2.25/n}
#ListDensityPlot[Map[Sign[Im[#]]Arg[#] &, image, {2}]
VortMesh = caclulateMatrixVortexesInTime()
n = N
mesh = np.zeros((n, n))
xm = -2
ym = -2
arrX = np.linspace(xm, xm + 4, num = n)
arrY = np.linspace(ym, ym + 4, num = n)
value = 0
for i in range(n):
print(i)
for j in range(n):
value = (complex(arrX[i], arrY[j]) - 1)/(3*complex(arrX[i], arrY[j]) + 2)
for t in range(steps, -1, -1):
value -= RungeEvalInDim(value, VortMesh[t, :])
mesh[j, i] = cmath.phase(value) * math.copysign(1, value.imag)
#mesh[j, i] = value
#mesh = np.rot90(mesh, k = 3)
#print(mesh)
#mesh = np.rot90(np.flip(mesh), k = 3)
filenameArr = f'ArrNP{N}_{steps}_{tmax}_{rcore}_{List_of_Vort[0]}_{List_of_Vort[1]}_{List_of_Vort[2]}_{List_of_Vort[3]}'
np.save(filenameArr, mesh)
print('done')
display(mesh)
if __name__ == '__main__':
run()