3 from numpy
import genfromtxt
11 if (len(sys.argv) == 2):
12 data_dir =
"../" + sys.argv[1] +
"/" 15 c = ConfigParser.ConfigParser()
16 c.readfp(open(data_dir +
'Params.dat',
"r")) 18 xDim = int(c.getfloat('Params',
'xDim'))
19 yDim = int(c.getfloat(
'Params',
'yDim'))
20 gndMaxVal = int(c.getfloat(
'Params',
'gsteps'))
21 evMaxVal = int(c.getfloat(
'Params',
'esteps'))
22 incr = int(c.getfloat(
'Params',
'printSteps'))
23 dx = (c.getfloat(
'Params',
'dx'))
24 dt = (c.getfloat(
'Params',
'dt'))
25 xMax = (c.getfloat(
'Params',
'xMax'))
26 yMax = (c.getfloat(
'Params',
'yMax'))
30 if (evMaxVal % incr == 0):
31 evMaxVal = evMaxVal - incr
64 r = m.sqrt((self.x - vtx.x)**2 + (self.y - vtx.y)**2)
119 def add(self,Vtx,index=None):
128 self.length = self.length +1
130 Vtx.next = self.element(index)
131 self.element(index-1).next = Vtx
132 self.length = self.length + 1
137 dtype = [(
'x',float),(
'y',float),(
'sign',int),(
'uid',int),(
'isOn',int)]
142 data.append([vtx.x, vtx.y, vtx.sign, vtx.uid, vtx.isOn])
150 np.savetxt(data_dir+
'vort_ord_'+str(time)+
'.csv',data,fmt=
'%10.5f,%10.5f,%i,%i,%i',delimiter=
',')
160 while vtx.next !=
None:
163 if r > vtx.dist(vortex):
171 if self.length > 1
and pos > 1:
172 current = self.element(pos-1).next
173 self.element(pos - 1).next = current.next
175 self.length = self.length - 1
179 self.head = self.head.next
180 self.length = self.length - 1
190 vtx_pos = self.vtx_uid(uid_i)
192 self.add(vtx,index=pos_f)
201 vtx.update_next(
None)
208 max_uid = vorts_p.max_uid()
211 self.element(i4).
update_uid(max_uid[0] + counter)
217 v_arr_p=genfromtxt(data_dir+
'vort_arr_' + str(incr),delimiter=
',')
218 for i
in range( start + incr*2, fin + 1, incr):
221 v_arr_c=genfromtxt(data_dir+
'vort_arr_' + str(i), delimiter=
',')
222 if i==start + incr*2:
224 v_arr_p_coords = np.array([a
for a
in v_arr_p[:,[1,3]]])
225 v_arr_c_coords = np.array([a
for a
in v_arr_c[:,[1,3]]])
226 v_arr_p_sign = np.array([a
for a
in v_arr_p[:,4]])
227 v_arr_c_sign = np.array([a
for a
in v_arr_c[:,4]])
229 v_arr_p_coords = np.array([a
for a
in v_arr_p[:,[0,1]]])
230 v_arr_p_sign = np.array([a
for a
in v_arr_p[:,2]])
232 v_arr_c_coords = np.array([a
for a
in v_arr_c[:,[1,3]]])
233 v_arr_c_sign = np.array([a
for a
in v_arr_c[:,4]])
234 for i1
in range(0,v_arr_p_coords.size/2):
235 vtx_p =
Vortex(i1,v_arr_p_coords[i1][0],v_arr_p_coords[i1][1],
True,sign=v_arr_p_sign[i1])
238 for i2
in range(0,v_arr_c_coords.size/2):
239 vtx_c =
Vortex(-1-i2,v_arr_c_coords[i2][0],v_arr_c_coords[i2][1],
True,sign=v_arr_c_sign[i2])
242 for i3
in range(0,vorts_p.length):
243 index_r = vorts_c.idx_min_dist(vorts_p.element(i3))
245 v0c = vorts_c.element(index_r[0]).sign
246 v0p = vorts_p.element(i3).sign
247 v1c = vorts_c.element(index_r[0]).uid
249 if (index_r[1] < 30)
and (vorts_c.element(index_r[0]).sign == vorts_p.element(i3).sign)
and (vorts_c.element(index_r[0]).uid < 0)
and (vorts_p.element(i3).isOn ==
True):
250 vorts_c.element(index_r[0]).
update_uid(vorts_p.element(i3).uid)
251 vorts_c.element(index_r[0]).
update_on(
True)
253 print "Failed to find any matching vortex. Entering interactive mode. Exit with Ctrl+D" 254 from IPython
import embed; embed()
258 uid_c = [[a
for a
in b][3]
for b
in vorts_c.as_np()]
259 uid_p = [[a
for a
in b][3]
for b
in vorts_p.as_np()]
267 vtx_pos_p = np.append(vtx_pos_p,vorts_p.vtx_uid(i5)[0])
269 vtx_pos_c = np.append(vtx_pos_c,vorts_c.vtx_uid(i6)[1])
270 if len(dpc
or dcp) >= 1:
271 vorts_c.vort_decrease(vtx_pos_p,vorts_p)
272 vorts_c.vort_increase(vtx_pos_c,vorts_p)
275 vorts_c_update=sorted(vorts_c.as_np(),key=
lambda vtx: vtx[3])
276 vorts_c.write_out(i,np.asarray(vorts_c_update))
277 print "[" + str(i) +
"]",
"Length of previous=" + str(len(v_arr_p_coords)),
"Length of current=" + str(len(vorts_c_update))
278 v_arr_p=genfromtxt(data_dir+
'vort_ord_' + str(i) +
'.csv',delimiter=
',' )
282 run(0, evMaxVal, incr)
end if(length(DT.vertexAttachments{ii})==5) if plotit plot(x(ii)
def vort_decrease(self, positions, vorts_p)
def write_out(self, time, data)
def add(self, Vtx, index=None)
def update_uid(self, uid)
% set(gca, 'Color', [0 0 0])
def update_on(self, isOn)
def __init__(self, uid, x, y, isOn, sign=1)
def vort_increase(self, positions, vorts_p)
def update_next(self, next)
def swap_uid(self, uid_i, uid_f)
def run(start, fin, incr)
def idx_min_dist(self, vortex, isSelf=False)