Exemplo n.º 1
0
def swimmerOnlyComp(vebasename,vebasedir,stbasename,stbasedir,swimdir):
    plt.close()
    mydictve = fileops.loadPickle(basename=vebasename,basedir=vebasedir)
    mydictst = fileops.loadPickle(basename=stbasename,basedir=stbasedir)
    fname = os.path.expanduser(vebasedir +vebasename +'/comp2stokesframe')
    myvars = swimmerVars(mydictve)
    vefpts = mydictve['fpts']
    stfpts = mydictst['fpts']
    if swimdir == 'right':
        barind = -2
    elif swimdir == 'left':
        barind = 0
    else:
        print('Swimming direction not recognized. Choose "left" or "right".')
        raise(SystemExit)
    fig=plt.figure()
    for k in range(len(mydictve['t'])):
        plt.plot([vefpts[0][barind],vefpts[0][barind]],[myvars[4],myvars[5]],'b',linewidth=4.0)
        plt.plot(stfpts[k][:-1:2],stfpts[k][1::2],'r',linewidth=4.0,label='Stokes')
        plt.plot(vefpts[k][:-1:2],vefpts[k][1::2],'k',linewidth=4.0,label='OB')
        plt.axis(myvars[:4])
        plt.legend(loc='upper right')
        plt.title('Time = '+str(mydictve['t'][k]))
        plt.savefig(os.path.expanduser(fname+'%03d' % k))
        plt.clf()
    plt.close()
Exemplo n.º 2
0
def checkSwimmerLength(basename,basedir):   
    plt.close()
    mydict = fileops.loadPickle(basename=basename,basedir=basedir)
    fpts = mydict['fpts']
    plt.figure()
    L = mydict['pdict']['forcedict']['L']
    h = mydict['pdict']['forcedict']['h']
    critterlen=[]
    hmax = []
    hmin = []
    for k in range(len(mydict['t'])):
        clen = np.sqrt((fpts[k][2:-1:2] - fpts[k][:-3:2])**2 + (fpts[k][3::2] - fpts[k][1:-2:2])**2)
        critterlen.append( clen.sum() / L )
        hmax.append(np.max(clen) / h)
        hmin.append(np.min(clen) / h)
    plt.plot(mydict['t'],critterlen)
    plt.xlabel('Time')
    plt.ylabel('Normalized length')
    plt.title('Swimmer length vs time')
    plt.savefig(basedir+basename+'/SwimmerLengthvsTime.pdf')
    plt.clf()
    plt.plot(mydict['t'],hmax)
    plt.xlabel('Time')
    plt.ylabel('Normalized max segment')
    plt.title('Max segment length vs time')
    plt.savefig(basedir+basename+'/MaxSegLengthvsTime.pdf')
    plt.clf()
    plt.plot(mydict['t'],hmin)
    plt.xlabel('Time')
    plt.ylabel('Normalized min segment')
    plt.title('Min segment length vs time')
    plt.savefig(basedir+basename+'/MinSegLengthvsTime.pdf')
Exemplo n.º 3
0
def stressComponentsMaxMin(basename,basedir):
    plt.close()
    mydict = fileops.loadPickle(basename=basename,basedir=basedir)
    fname = os.path.expanduser(basedir + basename + '/4RMCompsOverTime')
    S11 = np.zeros((len(mydict['t']),2))
    S12 = np.zeros((len(mydict['t']),2))
    S22 = np.zeros((len(mydict['t']),2))
    for k in range(0,len(mydict['t'])):
        S11[k,0]=np.max(mydict['S'][k][:,:,0,0])
        S11[k,1]=np.min(mydict['S'][k][:,:,0,0])
        S12[k,0]=np.max(mydict['S'][k][:,:,0,1])
        S12[k,1]=np.min(mydict['S'][k][:,:,0,1])
        S22[k,0]=np.max(mydict['S'][k][:,:,1,1])
        S22[k,1]=np.min(mydict['S'][k][:,:,1,1])
    plt.plot(mydict['t'],S11[:,0],'k-',label='S11 max')
    plt.plot(mydict['t'],S11[:,1],'k--',label='S11 min')
    plt.plot(mydict['t'],S22[:,0],'b-', label='S22 max')
    plt.plot(mydict['t'],S22[:,1],'b--', label='S22 min')
    plt.plot(mydict['t'],S12[:,0],'r-', label='S12 max')
    plt.plot(mydict['t'],S12[:,1],'r--', label='S12 min')
    xmin,xmax, ymin, ymax = plt.axis()
    plt.ylim(ymin - (ymax-ymin)/10.,ymax)
    plt.legend( bbox_to_anchor=(0., 0., 1., .102), loc=3,
       ncol=3, mode="expand", borderaxespad=0. )
    plt.title('Stress components over time')
    plt.savefig(fname)
    plt.clf()
Exemplo n.º 4
0
def stressTrace(basename,basedir,swimdir):
    '''
    FIXME: Rewrite so that swimmer can be plotted over any of the other plots. Maybe pass function handle.
    '''
    plt.close()
    mydict = fileops.loadPickle(basename=basename,basedir=basedir)
    fname = os.path.expanduser(basedir +basename +'/traceframe')
    myvars = stressVars(mydict)
    myswimvars = swimmerVars(mydict)
    if swimdir == 'right':
        barind = -2
    elif swimdir == 'left':
        barind = 0
    else:
        print('Swimming direction not recognized. Choose "left" or "right".')
        sys.exit()
    fig=plt.figure()
    for k in range(len(mydict['t'])):
        ph = plt.pcolor(mydict['l'][k][:,:,0],mydict['l'][k][:,:,1],mydict['Strace'][k][:,:],vmin=myvars[4],vmax=myvars[5],cmap=cm.RdGy)
        fig.colorbar(ph)
        plt.plot([mydict['fpts'][0][barind],mydict['fpts'][0][barind]],[myswimvars[4],myswimvars[5]],'w',linewidth=4.0)
        plt.plot(mydict['fpts'][k][:-1:2],mydict['fpts'][k][1::2],'k',linewidth=4.0)
        plt.axis(myvars[:4])
#        plt.axis([-0.2,1.8,-0.4,1.0])
#        plt.axis('equal')
        plt.title('Time = '+str(mydict['t'][k]))
        plt.savefig(os.path.expanduser(fname+'%03d' % k))
        plt.clf()
def simresults(basename, basedir):
    '''Retrieve approximate solution from saved output'''
    mydict = fileops.loadPickle(basename=basename, basedir=basedir)
    l = mydict['l']
    S = mydict['S']
    F = []
    Finv = []
    P = []
    N = l[0].shape[0]
    M = l[0].shape[1]
    for k in range(len(mydict['t'])):
        Ft = SD2D.vectorGrad(l[k], mydict['pdict']['gridspc'], N, M)
        Ftemp = np.reshape(Ft, (N * M, 2, 2))
        Ftinv = CM.matinv2x2(Ftemp)
        Ftinv = np.reshape(Ftinv, (N, M, 2, 2))
        F.append(Ft.copy())
        Finv.append(Ftinv.copy())
        stress = np.zeros((N, M, 2, 2))
        for j in range(N):
            for m in range(M):
                stress[j,
                       m, :, :] = S[k][j,
                                       m, :, :] * Ftinv[j,
                                                        m, :, :].transpose()
        P.append(stress.copy())
    return l, P, S, F, Finv, mydict
Exemplo n.º 6
0
def plotFinalPositionUnnormalized(basedir,bnamelist,xvals,xlab,fnameend): 
    xf =[]
    for k in range(len(bnamelist)):
        print(xvals[k])
        basename = bnamelist[k]
        mydict = fileops.loadPickle(basename=basename,basedir=basedir)
        xf.append(np.abs(np.max(mydict['fpts'][0][:-1:2])-np.max(mydict['fpts'][-1][:-1:2])))
    plt.close()
    plt.plot(xvals,xf,linewidth=2)
    plt.xlabel(xlab)
    plt.ylabel('dist')
    plt.title('Distance traveled in x at time %.01f' % mydict['t'][-1])
    plt.savefig(basedir+'finaldistance'+fnameend+'.pdf')
    return xf
Exemplo n.º 7
0
def stressTraceExtension(basename,basedir):
    plt.close()
    mydict = fileops.loadPickle(basename=basename,basedir=basedir)
    fname = os.path.expanduser(basedir+basename +'/traceframe')
    myvars = stressVars(mydict)
    for k in range(0,len(mydict['t'])):
        ph = plt.pcolor(mydict['l'][k][:,:,0],mydict['l'][k][:,:,1],mydict['Strace'][k][:,:],vmin=myvars[4],vmax=myvars[5],cmap=cm.RdGy)
        plt.colorbar(ph)
#        plt.axis('equal')
        plt.axis(myvars[:4])
#        plt.axis('off')
        plt.title('Time = '+str(mydict['t'][k]))
        plt.savefig(fname+'%03d' % k + '.pdf')
        plt.clf()
Exemplo n.º 8
0
def stressComponentsPColor(basename,basedir,i,j):
    '''
    S[i,j] = indices of stress component, S_{i+1,j+1} in matrix indices
    '''
    plt.clf()
    mydict = fileops.loadPickle(basename=basename,basedir=basedir)
    fname=os.path.expanduser(basedir + basename + '/S%d%d_' % (i+1,j+1))
    myvars = stressVars(mydict)
    for k in range(0,len(mydict['t'])/2):
        vmin=np.min(mydict['S'][k][:,:,i,j])
        vmax=np.max(mydict['S'][k][:,:,i,j])
        ph = plt.pcolor(mydict['l'][k][:,:,0],mydict['l'][k][:,:,1],mydict['S'][k][:,:,i,j],vmin=vmin,vmax=vmax,cmap=cm.RdGy)
        plt.colorbar(ph)
#        plt.axis('equal')
#        plt.axis(myvars[:4])
        plt.title('Time = '+str(mydict['t'][k]))
        plt.savefig(fname+'%03d' % k)
        plt.clf()
Exemplo n.º 9
0
def stressTraceContour(basename,basedir):
    plt.close()
    mydict = fileops.loadPickle(basename=basename,basedir=basedir)
    myvars = stressVars(mydict)
    fname = os.path.expanduser(basedir+basename+'/tracecontourframe')
    for k in range(1,len(mydict['t'])):
#        ph=plt.contour(mydict['l'][k][:,:,0],mydict['l'][k][:,:,1],mydict['Strace'][k][:,:],30,cmap=cm.cool)
        ph2=plt.contourf(mydict['l'][k][:,:,0],mydict['l'][k][:,:,1],mydict['Strace'][k][:,:],np.arange(myvars[4],myvars[5]+0.1,(myvars[5]-myvars[4])/50),cmap=cm.cool)
#        ph2.set_clim(myvars[4],myvars[5])
        ph2.set_clim(2,3)
        plt.colorbar(ph2)
        plt.plot([mydict['fpts'][0][0],mydict['fpts'][0][0]],[myvars[6],myvars[7]],'w',linewidth=2.0)
        plt.plot(mydict['fpts'][k][:-1:2],mydict['fpts'][k][1::2],'k',linewidth=2.0)
#        plt.axis('equal')
        plt.axis(myvars[:4])
        plt.title('Time = '+str(mydict['t'][k]))
        plt.savefig(os.path.expanduser(basedir+fname+'%03d' % k))
        plt.clf()
Exemplo n.º 10
0
def makeEllipses(basedir,basename):
    plt.close()
    fname = os.path.expanduser(basedir +basename +'/ellipseframe')
    mydict = fileops.loadPickle(basename=basename,basedir=basedir)
    myvars = stressVars(mydict)
    fpts = mydict['fpts']
    gridspc = mydict['pdict']['gridspc']
    Nt = len(mydict['t'])
    N = mydict['S'][0].shape[0]
    M = mydict['S'][0].shape[1]
    fig = plt.figure()
    for i in range(Nt):
        S = mydict['S'][i]
        l = mydict['l'][i]
        ax = fig.add_subplot(111) #,aspect='equal'
        ax.set_xlim(myvars[:2])
        ax.set_ylim(myvars[2:4])
        ells=[]
        for j in range(N):
            for k in range(M):
#                S = 1/np.sqrt(2)*np.array([[1,2],[-1,2]])
#                w,V = np.linalg.eigh(S)
                w, V = np.linalg.eigh(S[j,k,:,:]) 
#                print('Eigenvalues')
#                print(w)
#                print('Eigenvector dot prod')
#                print(np.dot(V[:,0],V[:,1]))
                center = l[j,k,:]
                ind = np.nonzero(w == np.max(w))
                ind=ind[0][0]
                horzdist = w[ind] * gridspc #put major eigval on x-axis and scale by the grid spacing (to fit in graph)
                vertdist = w[np.mod(ind+1,2)] * gridspc
                ang = np.arccos(V[0,ind]*1 + V[1,ind]*0) #calculate angle of rotation from eigenvector (using orthogonality of eigvecs here)
                ells.append(mpl.patches.Ellipse(xy=center, width=horzdist, height=vertdist, angle=ang*180/np.pi))
        for e in ells:
            ax.add_artist(e)
            e.set_clip_box(ax.bbox)
            e.set_facecolor('w')
        plt.plot(fpts[i][:-1:2],fpts[i][1::2],'k',linewidth=4.0)
        plt.title('Time = '+str(mydict['t'][i]))
        plt.savefig(os.path.expanduser(fname+'%03d' % i))
        plt.clf()
Exemplo n.º 11
0
def stressTrace4RMContour(basename,basedir):
    plt.close()
    mydict = fileops.loadPickle(basename=basename,basedir=basedir)
    fname=os.path.expanduser(basedir + basename + '/tracecontourframe')
#    vmax=np.max(mydict['Strace'])
#    x = mydict['l'][:,:,:,0]
#    y = mydict['l'][:,:,:,1]
    xmin = np.min(mydict['l'][-1][:,:,0])+0.5
    xmax = np.max(mydict['l'][-1][:,:,0])+0.5
    ymin = np.min(mydict['l'][-1][:,:,1])+0.5
    ymax = np.max(mydict['l'][-1][:,:,1])+0.5
    for k in range(0,len(mydict['t']),100):
        lvls = np.linspace(np.min(mydict['Strace'][k][:,:]),np.max(mydict['Strace'][k][:,:]),21)
        ph=plt.contour(mydict['l'][k][:,:,0],mydict['l'][k][:,:,1],mydict['Strace'][k][:,:],levels=lvls)
#        plt.clabel(ph, inline=1, fontsize=10)        
#        plt.axis('equal')
#        plt.axis([xmin,xmax,ymin,ymax])
        plt.title('Time = '+str(mydict['t'][k]))
        plt.savefig(fname+'%03d' % k)
        plt.clf()
Exemplo n.º 12
0
def swimmerOnly(basename,basedir,swimdir):
    plt.close()
    mydict = fileops.loadPickle(basename=basename,basedir=basedir)
    myvars = swimmerVars(mydict)
    fpts = mydict['fpts']
    if swimdir == 'right':
        barind = -2
    elif swimdir == 'left':
        barind = 0
    else:
        print('Swimming direction not recognized. Choose "left" or "right".')
        raise(SystemExit)
    fig=plt.figure()
    for k in range(len(mydict['t'])):
        plt.plot([fpts[0][barind],fpts[0][barind]],[myvars[4],myvars[5]],'b',linewidth=4.0)
        plt.plot(fpts[k][:-1:2],fpts[k][1::2],'r',linewidth=4.0)
        plt.axis('equal')
        plt.xlim(myvars[:2])
        plt.title('Time = '+str(mydict['t'][k]))
        plt.savefig(basedir+basename+'/frame%03d' % k)
        plt.clf()
    plt.close()
Exemplo n.º 13
0
def plotQuiverDiff(basename,basedir,velfunc):
    '''
    Don't use with regridded data sets.    
    '''
    plt.close()
    mydict = fileops.loadPickle(basename=basename,basedir=basedir)
    fname = os.path.expanduser(basedir+basename +'/quivframe')
    myvars = stressVars(mydict)
    for k in range(1,len(mydict['t'])-1):
        lk = mydict['l'][k]
        lkm1 = mydict['l'][k-1]
        lkp1 = mydict['l'][k+1]
        if lkm1.shape == lkp1.shape:
            l2col = np.reshape(lk,(lk.shape[0]*lk.shape[1],2))
            u, junk = velfunc(mydict['pdict'],lk.flatten(),l2col)
            unum = (lkp1 - lkm1)/(2*mydict['dt']) 
            unum = np.reshape(unum, (unum.shape[0]*unum.shape[1],2))
            plt.quiver(l2col[::4,0],l2col[1::4,1],u[::8],u[1::8],color='r')#, units='x', linewidths=(2,), edgecolors=('k'), headaxislength=5)
            plt.quiver(l2col[::4,0],l2col[1::4,1],unum[::4,0],unum[::4,1],color='b')#, units='x',linewidths=(2,), edgecolors=('k'), headaxislength=5)
            plt.axis(myvars[:4])
            plt.title('Time = %03f' % mydict['t'][k])
            plt.savefig(os.path.expanduser(basedir+basename +fname+'%03d.pdf') % k)
            plt.clf()
def simresults(basename, basedir):
    '''Retrieve approximate solution from saved output'''
    mydict = fileops.loadPickle(basename=basename, basedir=basedir)
    l = mydict['l']
    S=mydict['S']
    F=[]
    Finv=[]
    P=[]
    N = l[0].shape[0]
    M = l[0].shape[1]
    for k in range(len(mydict['t'])):
        Ft = SD2D.vectorGrad(l[k],mydict['pdict']['gridspc'],N,M)
        Ftemp = np.reshape(Ft,(N*M,2,2))
        Ftinv = CM.matinv2x2(Ftemp)
        Ftinv = np.reshape(Ftinv,(N,M,2,2))
        F.append(Ft.copy())
        Finv.append(Ftinv.copy())
        stress = np.zeros((N,M,2,2))
        for j in range(N):
            for m in range(M):
                stress[j,m,:,:] = S[k][j,m,:,:]*Ftinv[j,m,:,:].transpose()
        P.append(stress.copy())
    return l, P, S, F, Finv, mydict
Exemplo n.º 15
0
def pointTraj(basename,basedir):
    '''
    Don't use with regridded data sets.    
    '''
    plt.close()
    mydict = fileops.loadPickle(basename=basename,basedir=basedir)
    myvars = stressVars(mydict)
    l = mydict['l']
    ksave = [0]
    k = -1
    while k < len(mydict['t'])-1:
        x = np.zeros((len(mydict['t']),l[ksave[-1]].shape[0],l[ksave[-1]].shape[1]))
        y = np.zeros((len(mydict['t']),l[ksave[-1]].shape[0],l[ksave[-1]].shape[1]))
        for k in range(ksave[-1],len(mydict['t'])):
            print(k)
            if k == ksave[-1] or l[k-1].shape == l[k].shape:
                x[k,:,:] = l[k][:,:,0]
                y[k,:,:] = l[k][:,:,1]
            else:
                ksave.append(k) 
                print('regridding changed size of domain')               
                break
        fname = os.path.expanduser(basedir+basename +'/0traj_%03d' % (k-1,) )
        if k == len(mydict['t'])-1:
            ksave.append(len(mydict['t']))
        for i in range(0,l[0].shape[0],2):
                for j in range(0,l[0].shape[1],2):
                    plt.plot(x[ksave[-2]:ksave[-1],i,j],y[ksave[-2]:ksave[-1],i,j],'k')
        plt.axis(myvars[:4])
#        plt.setp(plt.gca().get_xticklabels(), visible=False)
#        plt.setp(plt.gca().get_yticklabels(), visible=False)
#        plt.gca().xaxis.set_ticks( [] )
#        plt.gca().yaxis.set_ticks( [] )
        print(ksave)
        plt.title('Time %03f to time %03f' % (mydict['t'][ksave[-2]],mydict['t'][ksave[-1]-1]))
        plt.savefig(fname+'.pdf')
        plt.clf()
Exemplo n.º 16
0
def specificPointTraj(basename,basedir):
    '''
    Don't use with regridded data sets.    
    '''
    plt.close()
    mydict = fileops.loadPickle(basename=basename,basedir=basedir)
    myvars = stressVars(mydict)
    l = mydict['l']
#    pts = [(0,0),(5,0),(0,5),(-5,0),(0,-5),(5,10),(10,5),(-5,10),(10,-5),
#           (5,-10),(-10,5),(-5,-10),(-10,-5)]
    pts = [(0,0),(-5,5),(5,-5),(-10,10),(10,-10),(-15,15),(15,-15)]
#    pts=[(15,20)]
    x = np.zeros((len(pts),len(mydict['t'])))
    y = np.zeros((len(pts),len(mydict['t'])))
    for k in range(len(mydict['t'])):
        ind = l[k].shape[0]/2
        for p in range(len(pts)):
            x[p,k] = l[k][ind+pts[p][0],ind+pts[p][1],0]
            y[p,k] = l[k][ind+pts[p][0],ind+pts[p][1],1]
    for p in range(len(pts)):
        plt.plot(x[p,:],y[p,:],'k')
        plt.plot(x[p,0],y[p,0],'ro')
    plt.title('Time %03f to time %03f' % (mydict['t'][0],mydict['t'][-1]))
    plt.savefig(os.path.expanduser(basedir+basename +'/0trajlinenoregrid.pdf'))