def convergence(): f = open("sc.final.dat", "w") f.write("k,N,e,ee,dofs\n") points, weights = pu.cubequadrature(12) up, ddup = pep.poisson(30, points[:,np.array([1,2])]) l2 = lambda f: math.sqrt(np.sum(f.flatten() **2 * weights.flatten())) l2up = l2(up) print l2up # for N in range(2,15): # for k in range(1,10): for (k,N) in [(1,2),(2,2),(3,2),(4,2),(5,2),(6,2),(1,3),(2,3),(3,3),(4,3),(1,4),(2,4),(3,4),(1,5),(2,5),(1,6),(2,6),(1,7),(2,7),(1,8),(1,9),(1,10),(1,11)]: meshevents = lambda m: pps.stokescubemesh(N, m) u, dofs = pps.stokespressure(k,meshevents,{pps.inputbdytag:pps.pfn(-0.5), pps.outputbdytag:pps.pfn(0.5)}, points, True,N==1) pt = points.transpose() ut = u.transpose() e = [l2(ut[0] - up)/l2up, l2(ut[1])/l2up, l2(ut[2])/l2up] ee = math.sqrt(e[0]**2 + e[1]**2 + e[2]**2) print k, N, e, ee, dofs f.write("%s, %s, %s, %s, %s\n"%(k,N,e,ee, dofs)) f.flush() # if dofs > 30000: break f.close()
def crosssection(x, NP, k, N, pN): points2 = pu.uniformsquarepoints(NP) points3 = np.hstack((np.ones((NP*NP,1)) * x, points2)) meshevents = lambda m: pps.stokescubemesh(N, m) u, p = pps.stokespressure(k,meshevents,{pps.inputbdytag:pps.pfn(0), pps.outputbdytag:pps.pfn(1.0)}, points3, False, N==1) ur, _ = pep.poisson(pN, points2) pp = points2.reshape(NP,NP,2).transpose(2,0,1) mpl.figure(facecolor='white') c = mpl.contour(pp[0], pp[1], u[:,0].reshape(NP,NP), fontsize=14) mpl.clabel(c, inline=1, fontsize = 14) mpl.figure(facecolor='white') c = mpl.contourf(pp[0], pp[1], ur.reshape(NP,NP) - u[:,0].reshape(NP,NP), fontsize=14, colors = None, cmap=mpl.get_cmap('Greys')) mpl.colorbar(c, shrink=0.8) # mpl.clabel(c, inline=1, fontsize = 14) mpl.figure(facecolor='white') c = mpl.contourf(pp[0], pp[1], p.reshape(NP,NP), fontsize=14, colors = None, cmap=mpl.get_cmap('Greys')) mpl.colorbar(c, shrink=0.8)
mpl.figure(facecolor='white') c = mpl.contourf(pp[0], pp[1], p.reshape(NP,NP), fontsize=14, colors = None, cmap=mpl.get_cmap('Greys')) mpl.colorbar(c, shrink=0.8) # mpl.clabel(c, inline=1, fontsize = 14) # mpl.show() if __name__ == "__main__": k = 4 N = 2 NP = 12 points = pu.uniformcubepoints(NP) v = [[1,1,1]] # v = [[0,0,0]] meshevents = lambda m: pps.stokescubemesh(N, m) # OT = 'obstructiontag' # meshevents = lambda m: pps.cubeobstruction(m, OT) mp = MeshPlotter() meshevents(mp) emm.figure(bgcolor=(1,1,1)) u, p = pps.stokespressure(k,meshevents,{pps.inputbdytag:pps.pfn(0), pps.outputbdytag:pps.pfn(1.0)}, points, False, N==1) pt = points.reshape(NP,NP,NP,3).transpose((3,0,1,2)) ut = u.reshape(NP,NP,NP,3).transpose((3,0,1,2)) emm.quiver3d(pt[0],pt[1],pt[2], ut[0],ut[1],ut[2], opacity = 0.4) # emm.flow(pt[0],pt[1],pt[2], ut[0],ut[1],ut[2], seedtype='plane', seed_resolution=10, seed_visible=True, scalars=p.reshape(NP,NP,NP)) mp.plot(emm.gcf()) mp.plotbdy(emm.gcf(), pps.closedbdytag)