def calcFourier(x,y,z,a,alph,freq,mu,c,U,tvec): soln_u = np.zeros((len(x),len(tvec)),dtype=np.complex128) soln_v = np.zeros((len(x),len(tvec)),dtype=np.complex128) soln_w = np.zeros((len(x),len(tvec)),dtype=np.complex128) for k in range(len(tvec)): out = lES.sphere3DOscillating(x,y,z,a,alph,freq,mu,c,U,tvec[k]) soln_u[:,k] = out[0] soln_v[:,k] = out[1] soln_w[:,k] = out[2] return soln_u, soln_v, soln_w
def calcFourier(x, y, z, a, alph, freq, mu, c, U, tvec): soln_u = np.zeros((len(x), len(tvec)), dtype=np.complex128) soln_v = np.zeros((len(x), len(tvec)), dtype=np.complex128) soln_w = np.zeros((len(x), len(tvec)), dtype=np.complex128) for k in range(len(tvec)): out = lES.sphere3DOscillating(x, y, z, a, alph, freq, mu, c, U, tvec[k]) soln_u[:, k] = out[0] soln_v[:, k] = out[1] soln_w[:, k] = out[2] return soln_u, soln_v, soln_w
def testOscillatingSphere3D_Drag(): ''' Checks total drag on the sphere (scalar value). ''' print('Test case: Oscillating sphere in 3D, testing drag (takes a very long time)...') a = 0.25 freq = 71 t=0 mu = 1.0 nu = 1.1 alph = np.sqrt(1j*2*np.pi*freq/nu) tN = 400 dtheta = 2*np.pi/tN theta = np.arange(dtheta/2,2*np.pi,dtheta) phi = np.arange(dtheta/2,np.pi,dtheta) xs = np.zeros((tN**2/2,)) ys = np.zeros((tN**2/2,)) zs = np.zeros((tN**2/2,)) for i in range(tN): th = theta[i] xs[i*tN/2:(i+1)*tN/2] = a*np.cos(theta[i])*np.sin(phi) ys[i*tN/2:(i+1)*tN/2] = a*np.sin(theta[i])*np.sin(phi) zs[i*tN/2:(i+1)*tN/2] = a*np.cos(phi) spts = np.column_stack([xs,ys,zs]) u,v,w,p,xdrag,ydrag,zdrag = lES.sphere3DOscillating(spts[:,0],spts[:,1],spts[:,2],a,alph,freq,mu) myfactor = 1.4 elist = [a/(4*(myfactor**k)) for k in range(0,3)] # elist = [a/(2*(myfactor**k)) for k in range(0,3)] errdragG = np.zeros((len(elist),3)) errdragE = np.zeros((len(elist),3)) for k in range(len(elist)): eps = elist[k] rsd = RS.Brinkman3DGaussianStokesletsAndDipolesSphericalBCs(eps,mu,alph,a) xdragreg, ydragreg, zdragreg = regOscillatingSphere3D_Drag(rsd,spts,phi,dtheta,a,freq) errdragG[k,:] = [np.abs(xdrag-xdragreg)/np.abs(xdrag),np.abs(ydrag-ydragreg),np.abs(zdrag-zdragreg)] if np.all(errdragG < 2.e-4): print("Gaussian blob, drag passed") else: print("Gaussian blob, drag failed") # print("Drag error should be small:") # print(errdragG) myfactor = 1.4 elist = [a/(12*(myfactor**k)) for k in range(2,5)] # elist = [a/(6*(myfactor**k)) for k in range(2,5)] for k in range(len(elist)): eps = elist[k] rsd = RS.Brinkman3DNegExpStokesletsAndDipolesSphericalBCs(eps,mu,alph,a) xdragreg, ydragreg, zdragreg = regOscillatingSphere3D_Drag(rsd,spts,phi,dtheta,a,freq) errdragE[k,:] = [np.abs(xdrag-xdragreg)/np.abs(xdrag),np.abs(ydrag-ydragreg),np.abs(zdrag-zdragreg)] if np.all(errdragE < 2.e-4): print("Negative exponential blob, drag passed") else: print("Negative exponential blob, drag failed")
def testOscillatingSphere3D_Drag(): ''' Checks total drag on the sphere (scalar value). ''' print( 'Test case: Oscillating sphere in 3D, testing drag (takes a very long time)...' ) a = 0.25 freq = 71 t = 0 mu = 1.0 nu = 1.1 alph = np.sqrt(1j * 2 * np.pi * freq / nu) tN = 400 dtheta = 2 * np.pi / tN theta = np.arange(dtheta / 2, 2 * np.pi, dtheta) phi = np.arange(dtheta / 2, np.pi, dtheta) xs = np.zeros((tN**2 / 2, )) ys = np.zeros((tN**2 / 2, )) zs = np.zeros((tN**2 / 2, )) for i in range(tN): th = theta[i] xs[i * tN / 2:(i + 1) * tN / 2] = a * np.cos(theta[i]) * np.sin(phi) ys[i * tN / 2:(i + 1) * tN / 2] = a * np.sin(theta[i]) * np.sin(phi) zs[i * tN / 2:(i + 1) * tN / 2] = a * np.cos(phi) spts = np.column_stack([xs, ys, zs]) u, v, w, p, xdrag, ydrag, zdrag = lES.sphere3DOscillating( spts[:, 0], spts[:, 1], spts[:, 2], a, alph, freq, mu) myfactor = 1.4 elist = [a / (4 * (myfactor**k)) for k in range(0, 3)] # elist = [a/(2*(myfactor**k)) for k in range(0,3)] errdragG = np.zeros((len(elist), 3)) errdragE = np.zeros((len(elist), 3)) for k in range(len(elist)): eps = elist[k] rsd = RS.Brinkman3DGaussianStokesletsAndDipolesSphericalBCs( eps, mu, alph, a) xdragreg, ydragreg, zdragreg = regOscillatingSphere3D_Drag( rsd, spts, phi, dtheta, a, freq) errdragG[k, :] = [ np.abs(xdrag - xdragreg) / np.abs(xdrag), np.abs(ydrag - ydragreg), np.abs(zdrag - zdragreg) ] if np.all(errdragG < 2.e-4): print("Gaussian blob, drag passed") else: print("Gaussian blob, drag failed") # print("Drag error should be small:") # print(errdragG) myfactor = 1.4 elist = [a / (12 * (myfactor**k)) for k in range(2, 5)] # elist = [a/(6*(myfactor**k)) for k in range(2,5)] for k in range(len(elist)): eps = elist[k] rsd = RS.Brinkman3DNegExpStokesletsAndDipolesSphericalBCs( eps, mu, alph, a) xdragreg, ydragreg, zdragreg = regOscillatingSphere3D_Drag( rsd, spts, phi, dtheta, a, freq) errdragE[k, :] = [ np.abs(xdrag - xdragreg) / np.abs(xdrag), np.abs(ydrag - ydragreg), np.abs(zdrag - zdragreg) ] if np.all(errdragE < 2.e-4): print("Negative exponential blob, drag passed") else: print("Negative exponential blob, drag failed")
def testOscillatingSphere3D(): ''' Checks velocity outside of a sphere using L2 error; checks pressure outside of a sphere using L2 error; checks pointwise surface traction on the sphere using L-infinity error. ''' print( 'Test case: Oscillating sphere in 3D (be patient, this may take a few minutes)...' ) a = 0.25 h = a / 5. X = np.mgrid[-2 * a + h / 2:2 * a:h, -2 * a + h / 2:2 * a:h, -2 * a:2 * a + h / 2:h] M = X.shape[-1] N = np.floor(M / 2.0) zlev = X[2, 0, 0, N] xg = X[0, :, :, N] yg = X[1, :, :, N] x = X[0, :, :, :].flatten() y = X[1, :, :, :].flatten() z = X[2, :, :, :].flatten() obspts = np.column_stack([x, y, z]) freq = 71 t = 0 mu = 1.0 nu = 1.1 alph = np.sqrt(1j * 2 * np.pi * freq / nu) # spts = a*np.loadtxt(os.path.join(os.path.split(__file__)[0], 'voronoivertices0300.dat')) tN = 50 dtheta = 2 * np.pi / tN theta = np.arange(dtheta / 2, 2 * np.pi, dtheta) phi = np.arange(dtheta / 2, np.pi, dtheta) xs = np.zeros((tN**2 / 2, )) ys = np.zeros((tN**2 / 2, )) zs = np.zeros((tN**2 / 2, )) for i in range(tN): th = theta[i] xs[i * tN / 2:(i + 1) * tN / 2] = a * np.cos(theta[i]) * np.sin(phi) ys[i * tN / 2:(i + 1) * tN / 2] = a * np.sin(theta[i]) * np.sin(phi) zs[i * tN / 2:(i + 1) * tN / 2] = a * np.cos(phi) spts = np.column_stack([xs, ys, zs]) u, v, w, p, xdrag, ydrag, zdrag = lES.sphere3DOscillating( x, y, z, a, alph, freq, mu) t1, t2, t3 = lES.sphere3DOscillatingSurfaceTraction( spts[:, 0], spts[:, 1], spts[:, 2], a, alph, freq, mu) # umlevs=vRS.contourCircle(xg,yg,a,np.abs(u.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestuabs.pdf' ),None, "|u| for sphere at z=%f" % zlev) # vmlevs=vRS.contourCircle(xg,yg,a,np.abs(v.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestvabs.pdf'),None, "|v| for sphere at z=%f" % zlev) # ualevs=vRS.contourCircle(xg,yg,a,np.angle(u.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestuang.pdf'),None,"angle(u) for sphere at z=%f" % zlev) # valevs=vRS.contourCircle(xg,yg,a,np.angle(v.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestvang.pdf'),None,"angle(v) for sphere at z=%f" % zlev) # pmlevs=vRS.contourCircle(xg,yg,a,np.abs(p.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestpabs.pdf'),None, "|p| for sphere at z=%f" % zlev) # palevs=vRS.contourCircle(xg,yg,a,np.angle(p.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestpang.pdf'),None,"angle(p) for sphere at z=%f" % zlev) # print("exact soln") # print(xdrag,ydrag,zdrag) myfactor = 1.4 elist = [a / (4 * (myfactor**k)) for k in range(0, 3)] # elist = [a/(2*(myfactor**k)) for k in range(0,3)] errmagG = np.zeros((len(elist), )) errangG = np.zeros((len(elist), )) errmagE = np.zeros((len(elist), )) errangE = np.zeros((len(elist), )) errpmagG = np.zeros((len(elist), )) errpangG = np.zeros((len(elist), )) errpmagE = np.zeros((len(elist), )) errpangE = np.zeros((len(elist), )) errtmagG = np.zeros((len(elist), 3)) errtangG = np.zeros((len(elist), 3)) errtmagE = np.zeros((len(elist), 3)) errtangE = np.zeros((len(elist), 3)) for k in range(len(elist)): eps = elist[k] rsd = RS.Brinkman3DGaussianStokesletsAndDipolesSphericalBCs( eps, mu, alph, a) ureg, vreg, wreg, preg, t1reg, t2reg, t3reg = regOscillatingSphere3D( rsd, obspts, spts, a, freq) # vRS.contourCircle(xg,yg,a,np.abs(ureg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittesturegabs%02d.pdf' % k ),umlevs, "Reg |u| for sphere at z=%f" % zlev) # vRS.contourCircle(xg,yg,a,np.abs(vreg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestvregabs%02d.pdf' % k),vmlevs, "Reg |v| for sphere at z=%f" % zlev) # vRS.contourCircle(xg,yg,a,np.angle(ureg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittesturegang%02d.pdf' % k),ualevs,"Reg angle(u) for sphere at z=%f" % zlev) # vRS.contourCircle(xg,yg,a,np.angle(vreg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestvregang%02d.pdf' % k),valevs,"Reg angle(v) for sphere at z=%f" % zlev) # vRS.contourCircle(xg,yg,a,np.abs(preg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestpregabs%02d.pdf' % k),pmlevs, "Reg |p| for sphere at z=%f" % zlev) # vRS.contourCircle(xg,yg,a,np.angle(preg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestpregang%02d.pdf' % k),palevs,"Reg angle(p) for sphere at z=%f" % zlev) # print("Gaussian approx -- drag") # print(xdragreg,ydragreg,zdragreg) ind = np.nonzero(x**2 + y**2 + z**2 > a**2) L2errmag = h**(1.5) * np.sqrt( ((np.abs(u[ind]) - np.abs(ureg[ind]))**2).sum() + ((np.abs(v[ind]) - np.abs(vreg[ind]))**2).sum() + ((np.abs(w[ind]) - np.abs(wreg[ind]))**2).sum()) L2errang = h**(1.5) * np.sqrt( ((np.angle(u[ind]) - np.angle(ureg[ind]))**2).sum() + ((np.angle(v[ind]) - np.angle(vreg[ind]))**2).sum() + ((np.angle(w[ind]) - np.angle(wreg[ind]))**2).sum()) errmagG[k] = L2errmag errangG[k] = L2errang L2errpmag = h**(1.5) * np.sqrt( ((np.abs(p[ind]) - np.abs(preg[ind]))**2).sum()) L2errpang = h**(1.5) * np.sqrt( ((np.angle(p[ind]) - np.angle(preg[ind]))**2).sum()) errpmagG[k] = L2errpmag errpangG[k] = L2errpang L2errtmag = [ np.max(np.abs((np.abs(t1) - np.abs(t1reg))) / np.abs(t1)), np.max(np.abs((np.abs(t2) - np.abs(t2reg))) / np.abs(t2)), np.max(np.abs((np.abs(t3) - np.abs(t3reg))) / np.abs(t3)) ] L2errtang = [ np.max(np.abs((np.angle(t1) - np.angle(t1reg)) / np.angle(t1))), np.max(np.abs((np.angle(t2) - np.angle(t2reg)) / np.angle(t2))), np.max(np.abs((np.angle(t3) - np.angle(t3reg)) / np.angle(t3))) ] errtmagG[k, :] = L2errtmag errtangG[k, :] = L2errtang convmagG = np.zeros((len(elist) - 1, )) convangG = np.zeros((len(elist) - 1, )) convpmagG = np.zeros((len(elist) - 1, )) convpangG = np.zeros((len(elist) - 1, )) for k in range(len(elist) - 1): convmagG[k] = np.log(errmagG[k] / errmagG[k + 1]) / np.log(myfactor) convangG[k] = np.log(errangG[k] / errangG[k + 1]) / np.log(myfactor) convpmagG[k] = np.log(errpmagG[k] / errpmagG[k + 1]) / np.log(myfactor) convpangG[k] = np.log(errpangG[k] / errpangG[k + 1]) / np.log(myfactor) if np.all(errmagG < 2.e-4) and np.all(errangG < 2.e-4): print("Gaussian blob, velocity passed") else: print("Gaussian blob, velocity failed") if np.all(errpmagG < 2.e-4) and np.all(errpangG < 2.e-4): print("Gaussian blob, pressure passed") else: print("Gaussian blob, pressure failed") if np.all(errtmagG < 2.e-4) and np.all(errtangG < 2.e-4): print("Gaussian blob, surface traction passed") else: print("Gaussian blob, surface traction failed") print("Surface traction error should be small:") print(errtmagG) print(errtangG) print("Vel L2 error should be small:") print(errmagG) print(errangG) print("Vel convergence rates should be high: ") print(convmagG) print(convangG) print("Pressure L2 error should be small:") print(errpmagG) print(errpangG) print("Pressure convergence rates should be high: ") print(convpmagG) print(convpangG) myfactor = 1.4 elist = [a / (12 * (myfactor**k)) for k in range(2, 5)] # elist = [a/(6*(myfactor**k)) for k in range(2,5)] for k in range(len(elist)): eps = elist[k] rsd = RS.Brinkman3DNegExpStokesletsAndDipolesSphericalBCs( eps, mu, alph, a) ureg, vreg, wreg, preg, t1reg, t2reg, t3reg = regOscillatingSphere3D( rsd, obspts, spts, a, freq) # vRS.contourCircle(xg,yg,a,np.abs(ureg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittesturegabs%02d.pdf' % k ),umlevs, "Reg |u| for sphere at z=%f" % zlev) # vRS.contourCircle(xg,yg,a,np.abs(vreg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestvregabs%02d.pdf' % k),vmlevs, "Reg |v| for sphere at z=%f" % zlev) # vRS.contourCircle(xg,yg,a,np.angle(ureg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittesturegang%02d.pdf' % k),ualevs,"Reg angle(u) for sphere at z=%f" % zlev) # vRS.contourCircle(xg,yg,a,np.angle(vreg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestvregang%02d.pdf' % k),valevs,"Reg angle(v) for sphere at z=%f" % zlev) # vRS.contourCircle(xg,yg,a,np.abs(preg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestpregabs%02d.pdf' % k),pmlevs, "Reg |p| for sphere at z=%f" % zlev) # vRS.contourCircle(xg,yg,a,np.angle(preg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestpregang%02d.pdf' % k),palevs,"Reg angle(p) for sphere at z=%f" % zlev) # print("Neg exp approx") # print(xdragreg,ydragreg,zdragreg) ind = np.nonzero(x**2 + y**2 + z**2 > a**2) L2errmag = h**(1.5) * np.sqrt( ((np.abs(u[ind]) - np.abs(ureg[ind]))**2).sum() + ((np.abs(v[ind]) - np.abs(vreg[ind]))**2).sum() + ((np.abs(w[ind]) - np.abs(wreg[ind]))**2).sum()) L2errang = h**(1.5) * np.sqrt( ((np.angle(u[ind]) - np.angle(ureg[ind]))**2).sum() + ((np.angle(v[ind]) - np.angle(vreg[ind]))**2).sum() + ((np.angle(w[ind]) - np.angle(wreg[ind]))**2).sum()) errmagE[k] = L2errmag errangE[k] = L2errang L2errpmag = h**(1.5) * np.sqrt( ((np.abs(p[ind]) - np.abs(preg[ind]))**2).sum()) L2errpang = h**(1.5) * np.sqrt( ((np.angle(p[ind]) - np.angle(preg[ind]))**2).sum()) errpmagE[k] = L2errpmag errpangE[k] = L2errpang L2errtmag = [ np.max(np.abs((np.abs(t1) - np.abs(t1reg))) / np.abs(t1)), np.max(np.abs((np.abs(t2) - np.abs(t2reg))) / np.abs(t2)), np.max(np.abs((np.abs(t3) - np.abs(t3reg))) / np.abs(t3)) ] L2errtang = [ np.max(np.abs((np.angle(t1) - np.angle(t1reg)) / np.angle(t1))), np.max(np.abs((np.angle(t2) - np.angle(t2reg)) / np.angle(t2))), np.max(np.abs((np.angle(t3) - np.angle(t3reg)) / np.angle(t3))) ] errtmagE[k, :] = L2errtmag errtangE[k, :] = L2errtang convmagE = np.zeros((len(elist) - 1, )) convangE = np.zeros((len(elist) - 1, )) convpmagE = np.zeros((len(elist) - 1, )) convpangE = np.zeros((len(elist) - 1, )) for k in range(len(elist) - 1): convmagE[k] = np.log(errmagE[k] / errmagE[k + 1]) / np.log(myfactor) convangE[k] = np.log(errangE[k] / errangE[k + 1]) / np.log(myfactor) convpmagE[k] = np.log(errpmagE[k] / errpmagE[k + 1]) / np.log(myfactor) convpangE[k] = np.log(errpangE[k] / errpangE[k + 1]) / np.log(myfactor) if np.all(errmagE < 2.e-4) and np.all(errangE < 2.e-4): print("Negative exponential blob, velocity passed") else: print("Negative exponential blob, velocity failed") if np.all(errpmagE < 2.e-4) and np.all(errpangE < 2.e-4): print("Negative exponential blob, pressure passed") else: print("Negative exponential blob, pressure failed") if np.all(errtmagE < 2.e-4) and np.all(errtangE < 2.e-4): print("Negative exponential blob, surface traction passed") else: print("Negative exponential blob, surface traction failed") print("Surface traction error should be small:") print(errtmagE) print(errtangE) print("Vel L2 error should be small:") print(errmagE) print(errangE) print("Vel convergence rates should be high: ") print(convmagE) print(convangE) print("Pressure L2 error should be small:") print(errpmagE) print(errpangE) print("Pressure convergence rates should be high: ") print(convpmagE) print(convpangE)
def testOscillatingSphere3D(): ''' Checks velocity outside of a sphere using L2 error; checks pressure outside of a sphere using L2 error; checks pointwise surface traction on the sphere using L-infinity error. ''' print('Test case: Oscillating sphere in 3D (be patient, this may take a few minutes)...') a = 0.25 h = a/5. X = np.mgrid[-2*a+h/2:2*a:h,-2*a+h/2:2*a:h,-2*a:2*a+h/2:h] M = X.shape[-1] N = np.floor(M/2.0) zlev = X[2,0,0,N] xg = X[0,:,:,N] yg = X[1,:,:,N] x = X[0,:,:,:].flatten() y = X[1,:,:,:].flatten() z = X[2,:,:,:].flatten() obspts = np.column_stack([x,y,z]) freq = 71 t=0 mu = 1.0 nu = 1.1 alph = np.sqrt(1j*2*np.pi*freq/nu) # spts = a*np.loadtxt(os.path.join(os.path.split(__file__)[0], 'voronoivertices0300.dat')) tN = 50 dtheta = 2*np.pi/tN theta = np.arange(dtheta/2,2*np.pi,dtheta) phi = np.arange(dtheta/2,np.pi,dtheta) xs = np.zeros((tN**2/2,)) ys = np.zeros((tN**2/2,)) zs = np.zeros((tN**2/2,)) for i in range(tN): th = theta[i] xs[i*tN/2:(i+1)*tN/2] = a*np.cos(theta[i])*np.sin(phi) ys[i*tN/2:(i+1)*tN/2] = a*np.sin(theta[i])*np.sin(phi) zs[i*tN/2:(i+1)*tN/2] = a*np.cos(phi) spts = np.column_stack([xs,ys,zs]) u,v,w,p,xdrag,ydrag,zdrag = lES.sphere3DOscillating(x,y,z,a,alph,freq,mu) t1,t2,t3 = lES.sphere3DOscillatingSurfaceTraction(spts[:,0],spts[:,1],spts[:,2],a,alph,freq,mu) # umlevs=vRS.contourCircle(xg,yg,a,np.abs(u.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestuabs.pdf' ),None, "|u| for sphere at z=%f" % zlev) # vmlevs=vRS.contourCircle(xg,yg,a,np.abs(v.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestvabs.pdf'),None, "|v| for sphere at z=%f" % zlev) # ualevs=vRS.contourCircle(xg,yg,a,np.angle(u.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestuang.pdf'),None,"angle(u) for sphere at z=%f" % zlev) # valevs=vRS.contourCircle(xg,yg,a,np.angle(v.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestvang.pdf'),None,"angle(v) for sphere at z=%f" % zlev) # pmlevs=vRS.contourCircle(xg,yg,a,np.abs(p.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestpabs.pdf'),None, "|p| for sphere at z=%f" % zlev) # palevs=vRS.contourCircle(xg,yg,a,np.angle(p.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestpang.pdf'),None,"angle(p) for sphere at z=%f" % zlev) # print("exact soln") # print(xdrag,ydrag,zdrag) myfactor = 1.4 elist = [a/(4*(myfactor**k)) for k in range(0,3)] # elist = [a/(2*(myfactor**k)) for k in range(0,3)] errmagG = np.zeros((len(elist),)) errangG = np.zeros((len(elist),)) errmagE = np.zeros((len(elist),)) errangE = np.zeros((len(elist),)) errpmagG = np.zeros((len(elist),)) errpangG = np.zeros((len(elist),)) errpmagE = np.zeros((len(elist),)) errpangE = np.zeros((len(elist),)) errtmagG = np.zeros((len(elist),3)) errtangG = np.zeros((len(elist),3)) errtmagE = np.zeros((len(elist),3)) errtangE = np.zeros((len(elist),3)) for k in range(len(elist)): eps = elist[k] rsd = RS.Brinkman3DGaussianStokesletsAndDipolesSphericalBCs(eps,mu,alph,a) ureg, vreg, wreg, preg,t1reg,t2reg,t3reg = regOscillatingSphere3D(rsd,obspts,spts,a,freq) # vRS.contourCircle(xg,yg,a,np.abs(ureg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittesturegabs%02d.pdf' % k ),umlevs, "Reg |u| for sphere at z=%f" % zlev) # vRS.contourCircle(xg,yg,a,np.abs(vreg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestvregabs%02d.pdf' % k),vmlevs, "Reg |v| for sphere at z=%f" % zlev) # vRS.contourCircle(xg,yg,a,np.angle(ureg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittesturegang%02d.pdf' % k),ualevs,"Reg angle(u) for sphere at z=%f" % zlev) # vRS.contourCircle(xg,yg,a,np.angle(vreg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestvregang%02d.pdf' % k),valevs,"Reg angle(v) for sphere at z=%f" % zlev) # vRS.contourCircle(xg,yg,a,np.abs(preg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestpregabs%02d.pdf' % k),pmlevs, "Reg |p| for sphere at z=%f" % zlev) # vRS.contourCircle(xg,yg,a,np.angle(preg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestpregang%02d.pdf' % k),palevs,"Reg angle(p) for sphere at z=%f" % zlev) # print("Gaussian approx -- drag") # print(xdragreg,ydragreg,zdragreg) ind = np.nonzero(x**2+y**2+z**2 > a**2) L2errmag = h**(1.5)*np.sqrt( ((np.abs(u[ind])-np.abs(ureg[ind]))**2).sum() + ((np.abs(v[ind])-np.abs(vreg[ind]))**2).sum() + ((np.abs(w[ind])-np.abs(wreg[ind]))**2).sum() ) L2errang = h**(1.5)*np.sqrt( ((np.angle(u[ind])-np.angle(ureg[ind]))**2).sum() + ((np.angle(v[ind])-np.angle(vreg[ind]))**2).sum() + ((np.angle(w[ind])-np.angle(wreg[ind]))**2).sum() ) errmagG[k] = L2errmag errangG[k] = L2errang L2errpmag = h**(1.5)*np.sqrt( ((np.abs(p[ind])-np.abs(preg[ind]))**2).sum() ) L2errpang = h**(1.5)*np.sqrt( ((np.angle(p[ind])-np.angle(preg[ind]))**2).sum() ) errpmagG[k] = L2errpmag errpangG[k] = L2errpang L2errtmag = [np.max(np.abs((np.abs(t1)-np.abs(t1reg)))/np.abs(t1)),np.max(np.abs((np.abs(t2)-np.abs(t2reg)))/np.abs(t2)),np.max(np.abs((np.abs(t3)-np.abs(t3reg)))/np.abs(t3))] L2errtang = [np.max(np.abs((np.angle(t1)-np.angle(t1reg))/np.angle(t1))),np.max(np.abs((np.angle(t2)-np.angle(t2reg))/np.angle(t2))),np.max(np.abs((np.angle(t3)-np.angle(t3reg))/np.angle(t3)))] errtmagG[k,:] = L2errtmag errtangG[k,:] = L2errtang convmagG = np.zeros((len(elist)-1,)) convangG = np.zeros((len(elist)-1,)) convpmagG = np.zeros((len(elist)-1,)) convpangG = np.zeros((len(elist)-1,)) for k in range(len(elist)-1): convmagG[k]=np.log(errmagG[k]/errmagG[k+1])/np.log(myfactor) convangG[k]=np.log(errangG[k]/errangG[k+1])/np.log(myfactor) convpmagG[k]=np.log(errpmagG[k]/errpmagG[k+1])/np.log(myfactor) convpangG[k]=np.log(errpangG[k]/errpangG[k+1])/np.log(myfactor) if np.all(errmagG < 2.e-4) and np.all(errangG < 2.e-4): print("Gaussian blob, velocity passed") else: print("Gaussian blob, velocity failed") if np.all(errpmagG < 2.e-4) and np.all(errpangG < 2.e-4): print("Gaussian blob, pressure passed") else: print("Gaussian blob, pressure failed") if np.all(errtmagG < 2.e-4) and np.all(errtangG < 2.e-4): print("Gaussian blob, surface traction passed") else: print("Gaussian blob, surface traction failed") print("Surface traction error should be small:") print(errtmagG) print(errtangG) print("Vel L2 error should be small:") print(errmagG) print(errangG) print("Vel convergence rates should be high: ") print(convmagG) print(convangG) print("Pressure L2 error should be small:") print(errpmagG) print(errpangG) print("Pressure convergence rates should be high: ") print(convpmagG) print(convpangG) myfactor = 1.4 elist = [a/(12*(myfactor**k)) for k in range(2,5)] # elist = [a/(6*(myfactor**k)) for k in range(2,5)] for k in range(len(elist)): eps = elist[k] rsd = RS.Brinkman3DNegExpStokesletsAndDipolesSphericalBCs(eps,mu,alph,a) ureg, vreg, wreg, preg,t1reg,t2reg,t3reg = regOscillatingSphere3D(rsd,obspts,spts,a,freq) # vRS.contourCircle(xg,yg,a,np.abs(ureg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittesturegabs%02d.pdf' % k ),umlevs, "Reg |u| for sphere at z=%f" % zlev) # vRS.contourCircle(xg,yg,a,np.abs(vreg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestvregabs%02d.pdf' % k),vmlevs, "Reg |v| for sphere at z=%f" % zlev) # vRS.contourCircle(xg,yg,a,np.angle(ureg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittesturegang%02d.pdf' % k),ualevs,"Reg angle(u) for sphere at z=%f" % zlev) # vRS.contourCircle(xg,yg,a,np.angle(vreg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestvregang%02d.pdf' % k),valevs,"Reg angle(v) for sphere at z=%f" % zlev) # vRS.contourCircle(xg,yg,a,np.abs(preg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestpregabs%02d.pdf' % k),pmlevs, "Reg |p| for sphere at z=%f" % zlev) # vRS.contourCircle(xg,yg,a,np.angle(preg.reshape((M-1,M-1,M))[:,:,N]),os.path.expanduser('~/scratch/unittestpregang%02d.pdf' % k),palevs,"Reg angle(p) for sphere at z=%f" % zlev) # print("Neg exp approx") # print(xdragreg,ydragreg,zdragreg) ind = np.nonzero(x**2+y**2+z**2 > a**2) L2errmag = h**(1.5)*np.sqrt( ((np.abs(u[ind])-np.abs(ureg[ind]))**2).sum() + ((np.abs(v[ind])-np.abs(vreg[ind]))**2).sum() + ((np.abs(w[ind])-np.abs(wreg[ind]))**2).sum() ) L2errang = h**(1.5)*np.sqrt( ((np.angle(u[ind])-np.angle(ureg[ind]))**2).sum() + ((np.angle(v[ind])-np.angle(vreg[ind]))**2).sum() + ((np.angle(w[ind])-np.angle(wreg[ind]))**2).sum() ) errmagE[k] = L2errmag errangE[k] = L2errang L2errpmag = h**(1.5)*np.sqrt( ((np.abs(p[ind])-np.abs(preg[ind]))**2).sum() ) L2errpang = h**(1.5)*np.sqrt( ((np.angle(p[ind])-np.angle(preg[ind]))**2).sum() ) errpmagE[k] = L2errpmag errpangE[k] = L2errpang L2errtmag = [np.max(np.abs((np.abs(t1)-np.abs(t1reg)))/np.abs(t1)),np.max(np.abs((np.abs(t2)-np.abs(t2reg)))/np.abs(t2)),np.max(np.abs((np.abs(t3)-np.abs(t3reg)))/np.abs(t3))] L2errtang = [np.max(np.abs((np.angle(t1)-np.angle(t1reg))/np.angle(t1))),np.max(np.abs((np.angle(t2)-np.angle(t2reg))/np.angle(t2))),np.max(np.abs((np.angle(t3)-np.angle(t3reg))/np.angle(t3)))] errtmagE[k,:] = L2errtmag errtangE[k,:] = L2errtang convmagE = np.zeros((len(elist)-1,)) convangE = np.zeros((len(elist)-1,)) convpmagE = np.zeros((len(elist)-1,)) convpangE = np.zeros((len(elist)-1,)) for k in range(len(elist)-1): convmagE[k]=np.log(errmagE[k]/errmagE[k+1])/np.log(myfactor) convangE[k]=np.log(errangE[k]/errangE[k+1])/np.log(myfactor) convpmagE[k]=np.log(errpmagE[k]/errpmagE[k+1])/np.log(myfactor) convpangE[k]=np.log(errpangE[k]/errpangE[k+1])/np.log(myfactor) if np.all(errmagE < 2.e-4) and np.all(errangE < 2.e-4): print("Negative exponential blob, velocity passed") else: print("Negative exponential blob, velocity failed") if np.all(errpmagE < 2.e-4) and np.all(errpangE < 2.e-4): print("Negative exponential blob, pressure passed") else: print("Negative exponential blob, pressure failed") if np.all(errtmagE < 2.e-4) and np.all(errtangE < 2.e-4): print("Negative exponential blob, surface traction passed") else: print("Negative exponential blob, surface traction failed") print("Surface traction error should be small:") print(errtmagE) print(errtangE) print("Vel L2 error should be small:") print(errmagE) print(errangE) print("Vel convergence rates should be high: ") print(convmagE) print(convangE) print("Pressure L2 error should be small:") print(errpmagE) print(errpangE) print("Pressure convergence rates should be high: ") print(convpmagE) print(convpangE)