Esempio n. 1
0
def avgQ(qx,qy,h):
	nx,ny = h.shape[0], h.shape[1]
	tx,ty = ida.tipcoord(h)
	ch=[]
	lp=0
	Q = np.zeros(tx)
	for x in range(tx):
		vec = h[x,:]
		ch.append([x for i in vec if i>2.0])
		if(np.size(ch[x])==ny):
			lp=x
	#ch = np.array(ch)
	for x in range(tx):
		for y in range(ny):
			if x <= lp:
				Q[x] += (math.sqrt((qx[x][y]**2.0+qy[x][y]**2.0)))/ny
				#Q[x] += p[x][y]/ny
			else:
				break
	for x in range(lp+1,tx):
		for y in range(ty-200,ty+200):
				if h[x][y] > 2.0:
					Q[x] += (math.sqrt((qx[x][y]**2.0+qy[x][y]**2.0)))#/np.size(ch[x])
				#	Q[x] += p[x][y]/np.size(ch[x])
	#plt.plot(Q)
	#plt.show()
	return Q
Esempio n. 2
0
def cline(qx,qy,h):
    """Finds the center-line flow in the channel, i.e. the path of the maximum flow rate in a     channel. It uses quadratic interpolation to find the exact location where the flow rate is max    imum between two pixels.

    Usage: cline(qx_data, qy_data, h_data)
    """
    tx,ty = ida.tipcoord(h)
    print tx,ty
    nx, ny = qx.shape[0], qx.shape[1]
    Q = np.sqrt(np.matrix(qx**2.0 + qy**2.0))
    Qmax = np.zeros(tx)
    ymax = np.zeros(tx)
    ymax2 = np.zeros(tx)
    for x in range(tx):
        Qmax[x] = Q[x,:].max()
        for y in range(ny):
            if Q[x,y] == Qmax[x]:
                ymax[x] = y
        A = np.matrix([[(ymax[x]-1)**2,ymax[x]-1,1],[(ymax[x])**2,ymax[x],1],[(ymax[x]+1)**2,ymax[x]+1,1]])
        B = np.matrix([[(Q[x,(ymax[x]-1)])],[(Q[x,(ymax[x])])],[(Q[x,(ymax[x]+1)])]])
        X = np.linalg.solve(A,B)
        ymax2[x] = (-X[1]/(2*X[0]))
    plt.plot(ymax2,Qmax)
    #plt.axis([0,h.shape[0],ymax2[0]-5,ymax2[0]+5])
    plt.show()
    return ymax2
Esempio n. 3
0
def chline(h, hcrit=2.0):
    nx,ny = h.shape[0], h.shape[1]
    tx,ty = ida.tipcoord(h)
    ch = np.zeros(nx*ny)
    ch.shape = (nx,ny)
    for x in range(tx):
        for y in range(ny):
            if(h[x][y])<hcrit:
                ch[x][y]=0
            else:
                ch[x][y]=1
    return ch
Esempio n. 4
0
def lpdata(h):
    nx,ny = h.shape[0], h.shape[1]
    tx,ty = ida.tipcoord(h)
    ch=[]
    lp=0
    avgd = np.zeros(tx)
    for x in range(tx):
        vec = h[x,:]
        ch.append([x for i in vec if i>2.0])
        if(np.size(ch[x])==ny):
            lp=x
    return lp,tx,ty
Esempio n. 5
0
def interp(data, h):
    """Quadratic Interpolation of data
    """
    nx, ny = data.shape[0], data.shape[1]
    #data = np.matrix(data)
    tx,ty = ida.tipcoord(h)
    ymax = np.zeros(tx)
    ymax2 = np.zeros(tx)
    datam = np.zeros(tx)
    for x in range(tx):
        datam[x] = data[x,:].max()
        for y in range(ny):
            if data[x,y] == datam[x]:
                ymax[x] = y
        A = np.matrix([[(ymax[x]-1)**2,ymax[x]-1,1],[(ymax[x])**2,ymax[x],1],[(ymax[x]+1)**2,ymax[x]+1,1]])
        B = np.matrix([[(data[x,(ymax[x]-1)])],[(data[x,(ymax[x])])],[(data[x,(ymax[x]+1)])]])
        X = np.linalg.solve(A,B)
        ymax2[x] = (-X[1]/(2*X[0]))
    #plt.plot(ymax2)
    #plt.axis([0,nx,0,ny])
    #plt.show()
    return ymax2
Esempio n. 6
0
def Bplot(inputs):
    """Batch contour plots

    Usage: python bplot 'wdir', 'times'
        Examples: wdir  = '/work/dissoltest'
                  times = '0,10,2'  (t=0, t=2, t=4, t=6, t=8)
    Makes a contour plot from wdir/name_time.dat.
    Output (png) file wdir/imgs/name_num-c.png
    Optional args (must be entered in order):
        'lim', 'names', 'types', 'func', 'xval'
    Limits for contour plots are: h [1,lim], qy [-lim,lim]; else [0,lim]
    """

    import os
    import ida
    import matplotlib as plt

#    Defaults
    names = ['c1']                            # concentration
    types = ['C']                            # contour plot
    lim   = None                            # limit on contours
    xval = '0.2,0.4,0.6,0.8'                # list for yplot

#    Mandatory arguments
    args  = len(inputs) - 1                    # Argument count
    if (args < 2):
        print "Usage: python bplot 'sim', 'times'"
        return

    sim  = inputs[1]
    times = inputs[2].split(',')
    times = range(int(times[0]), int(times[1])+1, int(times[2]))

#    Optional arguments
    if (args > 2): lim   = [float(x) for x in inputs[3].split(',')]
    if (args > 3): names = inputs[4].split(',')
    if (args > 4): types = inputs[5].split(',')
    if (args > 5): xval  = [float(x) for x in inputs[6].split(',')]

#    Make directories
    wdir = '/work/viratu/'+sim
    ldir = '/home/ladd/viratu/code/porous/'+sim
    os.system('mkdir -p '+wdir+'/imgs '+wdir+'/plts')
    #wdir = ldir
    #print(wdir)
#    Make plots
    n = 0
    Tip = []
    N = []
    for name in names:
        if (lim == None):
            clim = lim
        else:
            clim = lim[n]
            n = n + 1

        for time in times:
            print name, time
            #if ('N' in types):
            #    wdir = ldir
            if ('A' not in types):
                data = ida.paradata(wdir, name, time)
                Nm = ida.fname(wdir, name, time)
            #if time == 0:
             #   data = data+1
            if ('N' in types):
                Nact = ida.chactive(data,0.1,40)
                N = np.append(N,Nact)
                print Nact
            if ('D' in types):
                dc = ida.difference(wdir, name, time)
                nd = name + '-diff'
                plotc(dc, wdir, nd, time, clim)
            if ('V' in types):
                tipp = ida.tipcoord(data)
                Tip = np.append(Tip,tipp)
            if ('C' in types): plotc(data, wdir, name, time, clim)
            if ('X' in types): plotx(data, wdir, name, time)
            if ('Y' in types): ploty(data, wdir, name, time, xval)
            if ('A' in types): 
                dx = clim
                ida.plotxx(wdir, name, dx, time)
            if ('Z' in types):
                os.system('mkdir -p '+ldir+'/vtk')
                tm = np.str(time)
                znm = ldir+'/vtk/'+name + tm + '.vtk'
                ida.vtk_format(data,znm)
            #if ('N' not in types):
            #os.system('rm '+ Nm[0] + '*')    #Remove the files from work directory
            if ('D' in types):
                Nmd = ida.fname(wdir+'-seed', name, time)
                os.system('rm '+ Nmd[0] + '*')
        if ('V' in types):
            np.savetxt(wdir+"/Tip.dat",Tip)
            np.savetxt(ldir+"/Tip.dat",Tip)
        if ('N' in types):
            np.savetxt(ldir+"/Nact.dat",N)
    os.system('cp -r '+wdir+'/imgs '+ldir+'/')
    os.system('cp -r '+wdir+'/plts '+ldir+'/')
    return