def plotxx (wdir='.', type='ck1', dx = 0.2, time = 0): f1 = ida.paradata(wdir,'f1',time) f2 = ida.paradata(wdir,'f2',time) c2 = ida.paradata(wdir,'c2',time) c1 = ida.paradata(wdir,'c1',time) nx,ny = c1.shape[0],c1.shape[1] f1x = np.zeros(nx) f2x = np.zeros(nx) c1x = np.zeros(nx) c2x = np.zeros(nx) X = np.zeros(nx) for x in range(nx): f1x[x] = f1[x,:].sum()/float(ny) f2x[x] = f2[x,:].sum()/float(ny) c1x[x] = c1[x,:].sum()/float(ny) c2x[x] = c2[x,:].sum()/float(ny) X[x] = x*dx cx = c1x+c2x dcx = np.diff(cx) flux = c1x[0:nx-1]+c2x[0:nx-1]-dcx/dx plt.plot(X,c1x,label=r'Coupling ion $X$ concentration $c_X$',color='red') plt.hold=True plt.plot(X,c2x,label=r'Secondary ion $A_S$ concentration $c_S$',color='green') plt.hold=True plt.plot(X,f2x,label=r'Primary specific volume $f_P$',color='blue') plt.hold=True plt.plot(X,f1x,'o',markersize=3, markeredgecolor='#9502f9', label=r'Secondary specific volume $f_S$',color='#9502f9') #plt.hold=True #plt.plot(X,cx,'o',color='black',markersize=3,markeredgecolor='black',label=r'$(c_X+c_S)$') #plt.hold=True #plt.plot(X[0:nx-1],flux,'o',color='m',markersize=3,markeredgecolor='m',label=r'$c_S+c_X-Pe^{-1}d(c_S+c_X)/dx$') plt.axis([0,20,-0.1,2]) plt.legend(loc='upper right',prop={'size':10}) plt.grid(True) fn = ida.fname(wdir,type,time) plt.savefig(fn[2]+'-x.png',format='png') plt.close()
def difference(wdir=".", type = "c", time = 0): cn = ida.paradata(wdir,type,time) ws = wdir+'-seed' cs = ida.paradata(ws,type,time) dc = cs - cn return dc
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