yn = 641
zn = 51

time = np.asarray(range(dayi,dayf,days))*1440

S_avg = []
S_time = []

for tt in range(len(time)):
 print tt
 tlabel = str(tt)
 while len(tlabel) < 3: tlabel = '0'+tlabel
 #
 file1 = label+'_' + tlabel
 #
 U = fio.read_Scalar('./Velocity_CG/Velocity_CG_0_'+label+'_'+str(tt)+'.csv',xn,yn,zn)
 V = fio.read_Scalar('./Velocity_CG/Velocity_CG_1_'+label+'_'+str(tt)+'.csv',xn,yn,zn)
 #
 S_avg.append(np.mean(np.sqrt(U**2+V**2)))
 S_time.append(time[tt])

import csv

f = open('./Savg_'+label+'.csv','w')
writer = csv.writer(f)
for tt in range(len(time)):
 writer.writerow((S_time[tt],S_avg[tt]))

f.close()

Xlist = np.linspace(0,8000,xn)# x co-ordinates of the desired array shape
Zlist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2] 
Zlist = np.linspace(0,-50,zn)
Ylist = np.linspace(0,8000,yn)# y co-ordinates of the desired array shape
[X,Y] = np.meshgrid(Xlist,Ylist)

time = range(dayi,dayf,days)

t = 0

for tt in time:
 tlabel = str(tt)
 while len(tlabel) < 3: tlabel = '0'+tlabel
 #
 file1 = label+'_' + tlabel
 #
 Temp = fio.read_Scalar('./Temperature_CG/Temperature_CG_'+label+'_'+str(tt)+'.csv',xn,yn,zn)
 #
 for z in [0]:
  # determine speed direction
   #
  plt.figure()
  plt.contourf(Xlist,Ylist,Temp[:,:,0],50,extend='both',cmap=plt.cm.PiYG)
  plt.colorbar()
  plt.ylabel('Y [Km]',fontsize=18)
  plt.xlabel('X [Km]',fontsize=18)
  plt.savefig('./plot/'+label+'/T_'+str(z)+'_'+file1+'.png')
  plt.close()
  print       './plot/'+label+'/T_'+str(z)+'_'+file1+'.png'
fd = open(filename, "wb")

for p in range(pt):
    fd.write(str(x0[p]) + ", " + str(y0[p]) + ", " + str(-1.0 * z0[p]) + ", " + str(time[0]) + "\n")

import random

for t in range(len(time) - 1):
    print "time:", time[t]

    file0 = path + "Velocity_CG_0_" + label + "_" + str(time[t]) + ".csv"
    file1 = path + "Velocity_CG_1_" + label + "_" + str(time[t]) + ".csv"
    file2 = path + "Velocity_CG_2_" + label + "_" + str(time[t]) + ".csv"

    Ut0 = fio.read_Scalar(file0, xn, yn, zn)
    Vt0 = fio.read_Scalar(file1, xn, yn, zn)
    Wt0 = -1.0 * fio.read_Scalar(file2, xn, yn, zn)  # 0*Ut0

    file0 = path + "Velocity_CG_0_" + label + "_" + str(time[t + 1]) + ".csv"
    file1 = path + "Velocity_CG_1_" + label + "_" + str(time[t + 1]) + ".csv"
    file2 = path + "Velocity_CG_2_" + label + "_" + str(time[t + 1]) + ".csv"

    Ut1 = fio.read_Scalar(file0, xn, yn, zn)
    Vt1 = fio.read_Scalar(file1, xn, yn, zn)
    Wt1 = -1.0 * fio.read_Scalar(file2, xn, yn, zn)  # 0*Ut0

    # subcycling
    nt = 20
    ds = 1.0 * dt / nt
    # for st in range(nt+1):
dx, dy = np.meshgrid(np.gradient(Xlist),np.gradient(Ylist))

for time in range(dayi,dayf,days):
 print 'time:', time
 tlabel = str(time)
 while len(tlabel) < 3: tlabel = '0'+tlabel
 #Temperature_CG_m_50_6e_9.csv
 fileU = path+'Velocity_CG_0_'+label+'_'+str(time+480)+'.csv'
 fileV = path+'Velocity_CG_1_'+label+'_'+str(time+480)+'.csv'
 fileT = '../../Detectors/Tracer_CG/Tracer_1_CG_'+label+'_'+str(time-dayi)+'.csv'
 print fileT
 file1 = 'DivTr_'+label+'_'+str(time)
 #

 U = fio.read_Scalar(fileU,xn,yn,zn)
 V = fio.read_Scalar(fileV,xn,yn,zn)
 T = fio.read_Scalar(fileT,xn,yn,zn)

 for k in range(1):
  dU  = np.asarray(np.gradient(U[:,:,k]))
  dV  = np.asarray(np.gradient(V[:,:,k]))
  Div = dU[0,:,:]/dx + dV[1,:,:]/dy
  fig = plt.figure(figsize=(8,8))
  plt.contourf(Xlist/1000,Ylist/1000,Div,np.linspace(-0.0008,0.0008,30),extend='both',cmap=plt.cm.PiYG)
  plt.colorbar(ticks=np.linspace(-0.0008,0.0008,5))
  plt.contour(Xlist/1000,Ylist/1000,np.mean(T[:,:,:],2),10,colors='k')
  plt.xlabel('X [km]',fontsize=18)
  plt.ylabel('Y [km]',fontsize=18)
  plt.axes().set_aspect('equal')
  plt.xlim(0,2)
fd = open(filename,'wb')

for p in range(pt):
 fd.write(str(x0[p])+', '+str(y0[p])+', '+str(-1.*z0[p])+', '+str(time[0])+'\n')

import random

for t in range(len(time)-1):
 print 'time:', time[t]

 file0 = path+'Velocity_CG_0_'+label+'_'+str(time[t])+'.csv'
 file1 = path+'Velocity_CG_1_'+label+'_'+str(time[t])+'.csv'
 file2 = path+'Velocity_CG_2_'+label+'_'+str(time[t])+'.csv'

 Ut0 = fio.read_Scalar(file0,xn,yn,zn)
 Vt0 = fio.read_Scalar(file1,xn,yn,zn)
 Wt0 = 0*Ut0 #-1.*fio.read_Scalar(file2,xn,yn,zn) #0*Ut0

 file0 = path+'Velocity_CG_0_'+label+'_'+str(time[t+1])+'.csv'
 file1 = path+'Velocity_CG_1_'+label+'_'+str(time[t+1])+'.csv'
 file2 = path+'Velocity_CG_2_'+label+'_'+str(time[t+1])+'.csv'

 Ut1 = fio.read_Scalar(file0,xn,yn,zn)
 Vt1 = fio.read_Scalar(file1,xn,yn,zn)
 Wt1 = 0*Ut0 #-1.*fio.read_Scalar(file2,xn,yn,zn) #0*Ut0

 # subcycling
 nt = 20 
 ds = 1.*dt / nt
# for st in range(nt+1):
Example #6
0
zn = len(Zlist)

time = range(dayi,dayf,days)

t = 0

for tt in time:
 tlabel = str(tt)
 while len(tlabel) < 3: tlabel = '0'+tlabel
 #
 file1 = './vts/'+basename+'_'+label+'_' + tlabel
 print file1

 var = np.zeros((xn,yn,zn))
 x = np.zeros((xn,yn,zn))
 y = np.zeros((xn,yn,zn))
 z = np.zeros((xn,yn,zn))
 #
 Temp = fio.read_Scalar(path+'/'+basename+'_'+label+'_'+str(tt)+'.csv',xn,yn,zn)
 #
 for k in range(len(Zlist)):
  for i in range(len(Xlist)):
   for j in range(len(Ylist)):
    var[i,j,k] = Temp[i,j,k]
    x[i,j,k] = Xlist[i]
    y[i,j,k] = Ylist[j]
    z[i,j,k] = Zlist[k] 

 gridToVTK(file1, x,y,z, pointData = {basename : var})

 print 'time:', time
 tlabel = str(timeT[time])
 while len(tlabel) < 3: tlabel = '0'+tlabel
 #Temperature_CG_m_50_6e_9.csv
 fileU_B = path+'Velocity_CG_0_'+label_BV+'_'+str(timeT[time])+'.csv' #+480
 fileV_B = path+'Velocity_CG_1_'+label_BV+'_'+str(timeT[time])+'.csv' #+480
 fileT_B = '../RST/Tracer_CG/Tracer_1_CG_'+label_B+'_'+str(timeT[time])+'.csv' #-960
 fileU_BW = path+'Velocity_CG_0_'+label_BWV+'_'+str(timeT[time])+'.csv' #+480
 fileV_BW = path+'Velocity_CG_1_'+label_BWV+'_'+str(timeT[time])+'.csv' #+480
 fileT_BW = '../RST/Tracer_CG/Tracer_1_CG_'+label_BW+'_'+str(timeT[time])+'.csv' #-960
 print fileT_BW, fileT_B
 file1_B = 'DivTr_'+label_B+'_'+str(timeT[time])
 file1_BW = 'DivTr_'+label_BW+'_'+str(timeT[time])
 #

 U_B = fio.read_Scalar(fileU_B,xn_B,yn_B,zn)
 V_B = fio.read_Scalar(fileV_B,xn_B,yn_B,zn)
 T_B = fio.read_Scalar(fileT_B,xn_B,yn_B,zn)
 U_BW = fio.read_Scalar(fileU_BW,xn_BW,yn_BW,zn)
 V_BW = fio.read_Scalar(fileV_BW,xn_BW,yn_BW,zn)
 T_BW = fio.read_Scalar(fileT_BW,xn_BW,yn_BW,zn)
# U_BW = U_B
# V_BW = V_B
# T_BW = T_B

# for k in [0]:
#  print 'depth',Zlist[k]
#  dU_B  = np.asarray(np.gradient(np.mean(U_B[:,:,2:3],2)))
#  dV_B  = np.asarray(np.gradient(np.mean(V_B[:,:,2:3],2)))
#  Div_B = dU_B[0,:,:]/dx_B + dV_B[1,:,:]/dy_B
#  T_B = np.mean(T_B[:,:,2:3],2)
for d in days:
 T = []
 W = []
 DT= []
 for t in day:
  print 'time:', t
  tlabel = str(t)
  while len(tlabel) < 3: tlabel = '0'+tlabel
  #Temperature_CG_m_50_6e_9.csv
  #fileT = '../RST/Temperature_CG/Temperature_CG_'+label+'_'+str(t+d*240+481)+'.csv'
  #fileW = path+'Velocity_CG_2_'+label+'_'+str(t+d*240+481)+'.csv'
  fileT = '../RST/Temperature_CG/Temperature_CG_'+label+'_'+str(t+d*60)+'.csv'
  fileW = path+'Velocity_CG_2_'+label+'_'+str(t+d*60)+'.csv'
  print fileT
  #
  Ttemp = fio.read_Scalar(fileT,xn,yn,zn)+274.5
  T.append(Ttemp)
  W.append(fio.read_Scalar(fileW,xn,yn,zn))
  DT.append(np.mean(np.mean(Ttemp[:,:,-1]-Ttemp[:,:,0],0),0))


 T = np.asarray(T) 
 W = np.asarray(W)
 DT= np.asarray(DT)
 T = np.mean(T,3) 
 W = np.mean(W,3)
 DT= np.mean(DT)
 H = 50
 
 Nu.append(1 + np.mean(np.mean(np.mean(W[:,:,:]*T[:,:,:],0),0),0)/DT*H/alpha)
 Ra.append(beta*DT*9.81*H**3/(alpha*nu))
U = np.zeros((xn_25,yn_25,zn,len(time)))
V = np.zeros((xn_25,yn_25,zn,len(time)))
W = np.zeros((xn_25,yn_25,zn,len(time)))

for t in range(len(time)):
 print 'time:', time[t]
 tlabel = str(time[t])
 while len(tlabel) < 3: tlabel = '0'+tlabel
 #Velocity_CG_m_50_6e_9.csv
 file0_U = path+'Velocity_CG_0_'+label_25+'_'+str(time[t])+'.csv'
 file0_V = path+'Velocity_CG_1_'+label_25+'_'+str(time[t])+'.csv'
 file0_W = path+'Velocity_CG_2_'+label_25+'_'+str(time[t])+'.csv'
 file1 = 'drate_'+label+'_'+str(time[t])
 file1_25 = 'drate_'+label_25

 U[:,:,:,t] = fio.read_Scalar(file0_U,xn_25,yn_25,zn)
 V[:,:,:,t] = fio.read_Scalar(file0_V,xn_25,yn_25,zn)
 W[:,:,:,t] = fio.read_Scalar(file0_W,xn_25,yn_25,zn)

# remove mean
 mU = mU + U[:,:,:,t]*time1    
 mV = mV + V[:,:,:,t]*time1    
 mW = mW + W[:,:,:,t]*time1    

for t in range(len(time)):
 print 'time:', time[t]

 Ua = U[:,:,:,t] - mU
 Va = V[:,:,:,t] - mV
 Wa = W[:,:,:,t] - mW
    Q = Q_0 / (1027.0 * 4000.0) - 245.64 / (1027.0 * 4000.0)
    return Q


for t in time:
    if t * 360.0 / 3600.0 % 24 / 6 >= 3:
        print "time:", t
        tlabel = str(t)
        while len(tlabel) < 3:
            tlabel = "0" + tlabel
        # Temperature_CG_m_50_6e_9.csv
        fileT = "../RST/Temperature_CG/Temperature_CG_" + label + "_" + str(t) + ".csv"
        fileW = path + "Velocity_CG_2_" + label + "_" + str(t) + ".csv"
        print fileT
        #
        T = fio.read_Scalar(fileT, xn, yn, zn) + 274.5
        #  W = fio.read_Scalar(fileW,xn,yn,zn)

        DT = -np.mean(np.mean(T[:, :, 0] - T[:, :, -1], 0), 0)
        #  Q0.append(-np.mean(np.mean(T[:,:,0]))*np.mean(np.mean(W[:,:,0])))
        H = 50.0
        Q1.append(-Q_surf(t))  # np.mean(np.mean(W[:,:,0]*T[:,:,0],0),0) # -1*Q_surf(t)
        Nu.append(1 + Q1[-1] / DT * H / alpha)
        Ra.append(beta * DT * 9.81 * H ** 3 / (alpha * nu))
        #  print 'Q0:', Q0[-1], 'Q1:', Q1[-1]
        # for k in range(zn):
        #  DT = np.mean(np.mean(T[:,:,k]-T[:,:,0],0),0)
        #  H = Zlist[k]
        #  Q = -1*Q_surf(t)
        #  print Q
        #  Nu.append(1 + Q/DT*H/alpha)
Ylist = np.linspace(0,2000,161)
dl = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1]
Zlist = 1.*np.cumsum(dl)

xn = len(Xlist)
yn = len(Ylist)
zn = len(Zlist)

for t in range(0,len(time),10):
 tlabel = str(t)
 while len(tlabel) < 3: tlabel = '0'+tlabel
 #
 for z in [1]:
  file0 = path+'Tracer_'+str(z)+'_CG_'+label+'_'+str(time[t])+'.csv'
  #print file0
  T = fio.read_Scalar(file0,xn,yn,zn)
  #
  v = np.linspace(0, 1, 30, endpoint=True)
  vl = np.linspace(0, 1, 5, endpoint=True)
  #
  fig = plt.figure(figsize=(6,5))
  plt.contourf(Ylist/1000,-1*Zlist,np.transpose(np.mean(T,0)),30,extend='both',cmap=plt.cm.PiYG)
  plt.colorbar()
#  plt.colorbar(ticks=vl)
  plt.title(str(np.round(10*(time[t]*1200/3600.0+24*6))/10.0)+'h')
  plt.ylabel('Z [m]',fontsize=16)
  plt.xlabel('X [km]',fontsize=16)
  plt.savefig('./plot/'+label+'/Tracer_'+str(z)+'_CG_'+label+'_'+str(time[t])+'_v.eps')
  plt.close()
  print       './plot/'+label+'/Tracer_'+str(z)+'_CG_'+label+'_'+str(time[t])+'_v.eps'
yn_b = len(Ylist_b)
zn = len(Zlist)

for time in range(dayi,dayf,days):
 print 'time:', time
 tlabel = str(time)
 while len(tlabel) < 3: tlabel = '0'+tlabel
 #Temperature_CG_m_50_6e_9.csv
 fileU_w = path+'Velocity_CG_0_'+label_w+'_'+str(time)+'.csv'
 fileV_w = path+'Velocity_CG_1_'+label_w+'_'+str(time)+'.csv'
 fileU_b = path+'Velocity_CG_0_'+label_b+'_'+str(time)+'.csv'
 fileV_b = path+'Velocity_CG_1_'+label_b+'_'+str(time)+'.csv'
 file1 = 'Shear_v_'+label+'_'+str(time)
 #

 U_w = fio.read_Scalar(fileU_w,xn_w,yn_w,zn)
 V_w = fio.read_Scalar(fileV_w,xn_w,yn_w,zn)
 U_b = fio.read_Scalar(fileU_b,xn_b,yn_b,zn)
 V_b = fio.read_Scalar(fileV_b,xn_b,yn_b,zn)

 S_w = []
 S_b = []

 for i in range(xn_w):
  for j in range(yn_w):
   S_w.append((np.gradient(U_w[i,j,:])/np.gradient(Zlist))**2+(np.gradient(V_w[i,j,:])/np.gradient(Zlist))**2)

 for i in range(xn_b):
  for j in range(yn_b):
   S_b.append((np.gradient(U_b[i,j,:])/np.gradient(Zlist))**2+(np.gradient(V_b[i,j,:])/np.gradient(Zlist))**2)
#mld_25 = np.zeros(len(range(dayi,dayf,days)))
nu_h = 0.05
nu_v = 0.0005 
for t in range(len(time)):
 print 'time:', time[t]
 tlabel = str(time[t])
 while len(tlabel) < 3: tlabel = '0'+tlabel
 #Velocity_CG_m_50_6e_9.csv
 file0_U = path+'Velocity_CG_0_'+label_25+'_'+str(time[t])+'.csv'
 file0_V = path+'Velocity_CG_1_'+label_25+'_'+str(time[t])+'.csv'
 file0_W = path+'Velocity_CG_2_'+label_25+'_'+str(time[t])+'.csv'
 file1 = 'drate_'+label+'_'+str(time[t])
 file1_25 = 'drate_'+label_25

 U_25 = fio.read_Scalar(file0_U,xn_25,yn_25,zn)
 V_25 = fio.read_Scalar(file0_V,xn_25,yn_25,zn)
 W_25 = fio.read_Scalar(file0_W,xn_25,yn_25,zn)

 for i in range(0,len(Xlist_25),50):
  for j in range(0,len(Ylist_25),50):
   #FW_25[j,i,:,t] = 0.5*nu_h*((np.gradient(U_25[i,j,:]-np.mean(U_25[i,j,:]))/dz_25)**2 + (np.gradient(V_25[i,j,:]-np.mean(V_25[i,j,:]))/dz_25)**2) + 0.5*nu_v*((np.gradient(W_25[i,j,:]-np.mean(W_25[i,j,:]))/dz_25)**2)
   FW_25[j,i,:,t] = 0.5*nu_h*((np.gradient(U_25[i,j,:])/dz_25)**2 + (np.gradient(V_25[i,j,:])/dz_25)**2) + 0.5*nu_v*(np.gradient(W_25[i,j,:])/dz_25)**2

 FW_t25 = np.mean(np.mean(FW_25,0),0)

# plt.figure(figsize=(4,8))
# p25, = plt.semilogx(7.5*0.05*FW_t25[:,t],Zlist,'k--',linewidth=2)

FW_m = -11
FW_M = -7
Example #14
0
xn_b = len(Xlist_b)
yn_b = len(Ylist_b)
zn = len(Zlist)

for time in range(dayi,dayf,days):
 print 'time:', time
 tlabel = str(time)
 while len(tlabel) < 3: tlabel = '0'+tlabel
 #Temperature_CG_m_50_6e_9.csv
 fileT_w = path+'Temperature_CG_'+label_w+'_'+str(time)+'.csv'
 fileT_b = path+'Temperature_CG_'+label_b+'_'+str(time)+'.csv'
 file1 = 'T_v_'+label+'_'+str(time)
 file2 = 'T_vgrad_'+label+'_'+str(time)
 #

 T_w = fio.read_Scalar(fileT_w,xn_w,yn_w,zn)
 T_b = fio.read_Scalar(fileT_b,xn_b,yn_b,zn)

 Tm_w = []
 Tm_b = []

 Tm_w = np.mean(np.mean(T_w,0),0)
 Tm_b = np.mean(np.mean(T_b,0),0)

 Tg_b = np.gradient(Tm_b)/np.gradient(Zlist)
 Tg_w = np.gradient(Tm_w)/np.gradient(Zlist)


 Tmin = 19.2
 Tmax = 20.2
dayf = 241
days = 1

basename = 'Velocity_CG_2_m_25_2b_particles'
#basename = 'drate_m_25_1b_particles'

#Xlist = np.linspace(0,10000,801)
#Ylist = np.linspace(0,4000,321)
Xlist = np.linspace(0,8000,641)
Ylist = np.linspace(0,8000,641)
dl = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1]
Zlist = 1.*np.cumsum(dl)

xn = yn = 641
zn = 36

timeD = range(dayi,dayf,days)

for t in timeD:
 print 'read drate', t
 # read
 file_W = './Velocity_CG/'+basename+'_'+str(t)+'.csv'
 W = fio.read_Scalar(file_W,xn,yn,zn)
 Wz = np.mean(np.mean(W,0),0)
 print Wz

 f = open('./Velocity_CG/z/'+basename+'_'+str(t)+'_z.csv','w')
 writer = csv.writer(f)
 writer.writerow((list(Wz)))
 f.close()

for time in range(dayi,dayf,days):
 tlabel = str(time)
 while len(tlabel) < 3: tlabel = '0'+tlabel
 #
 #

 file0u = path+'Velocity_CG_0_'+label+'_'+str(time)+'.csv'
 file0v = path+'Velocity_CG_1_'+label+'_'+str(time)+'.csv'
 file0w = path+'Velocity_CG_2_'+label+'_'+str(time)+'.csv'
 file1 = 'Velocity_CG_'+label+'_'+str(time)
 print file1
 #

 u = fio.read_Scalar(file0u,xn,yn,zn)
 v = fio.read_Scalar(file0v,xn,yn,zn)
 w = fio.read_Scalar(file0w,xn,yn,zn)
 #
 dt = 1 # s
 mu = np.mean(np.mean(u,0),0)
 mv = np.mean(np.mean(v,0),0)
 mw = np.mean(np.mean(w,0),0)
 dx = mu*dt
 dy = mv*dt
 dz = mw*dt

 fd = open('./UVW_'+file1+'.csv','w')
 fd.write('x, y, z, u, v, w \n')
 for z in range(len(Zlist)):
  fd.write('0, 0, '+str(Zlist[z])+', '+str(mu[z])+', '+str(mv[z])+', '+str(mw[z])+'\n')