def test_laplacian(): ''' SEM on the plane: laplacian(), f=x^3+2*y^2 on [-1,1]^2 ''' ngq = 4 gq_pts, gq_wts = gausslobatto(ngq-1) x = gq_pts[:,np.newaxis] y = gq_pts[np.newaxis,:] scalar = np.zeros((ngq,ngq), 'f8') ret = np.zeros((ngq,ngq), 'f8') sep = SpectralElementPlane(ngq) scalar[:] = x*x*x + 2*y*y sep.laplacian(scalar, ret) aa_equal(ret, 6*x+0*y+4, 13)
def test_vorticity(): ''' SEM on the plane: vorticity(), F=(2*y^2,x^3) on [-1,1]^2 ''' ngq = 4 gq_pts, gq_wts = gausslobatto(ngq-1) x = gq_pts[:,np.newaxis] y = gq_pts[np.newaxis,:] vector = np.zeros((ngq,ngq,2), 'f8') ret = np.zeros((ngq,ngq), 'f8') sep = SpectralElementPlane(ngq) vector[:,:,0] = 2*y*y vector[:,:,1] = x*x*x sep.vorticity(vector, ret) aa_equal(ret, 3*x*x-4*y, 15)
def test_divergence(): ''' SEM on the plane: divergence(), F=(x^3,2*y^2) on [-1,1]^2 ''' ngq = 4 gq_pts, gq_wts = gausslobatto(ngq-1) x = gq_pts[:,np.newaxis] y = gq_pts[np.newaxis,:] vector = np.zeros((ngq,ngq,2), 'f8') ret = np.zeros((ngq,ngq), 'f8') sep = SpectralElementPlane(ngq) vector[:,:,0] = x*x*x vector[:,:,1] = 2*y*y sep.divergence(vector, ret) aa_equal(ret, 3*x*x+4*y, 15)
def test_gradient(): ''' SEM on the plane: gradient(), f=x^2+2*y^2 on [-1,1]^2 ''' ngq = 4 gq_pts, gq_wts = gausslobatto(ngq-1) x = gq_pts[:,np.newaxis] y = gq_pts[np.newaxis,:] scalar = np.zeros((ngq,ngq), 'f8') ret = np.zeros((ngq,ngq,2), 'f8') sep = SpectralElementPlane(ngq) scalar[:] = x*x + 2*y*y sep.gradient(scalar, ret) aa_equal(ret[:,:,0], 2*x+0*y, 15) aa_equal(ret[:,:,1], 0*x+4*y, 15)
def init_dvv(self): ngq = self.ngq p_order = ngq-1 gq_pts, gq_wts = gausslobatto(p_order) dvv = self.dvv for i in xrange(ngq): for j in xrange(ngq): if i != j: dvv[i,j] = 1/(gq_pts[i] - gq_pts[j]) * \ ( legendre(p_order,gq_pts[i]) / legendre(p_order,gq_pts[j]) ) else: if i == 0: dvv[i,j] = - p_order*(p_order+1)/4 elif i == p_order: dvv[i,j] = p_order*(p_order+1)/4 elif 0 < i < p_order: dvv[i,j] = 0
sep.laplacian(scalar, ret) aa_equal(ret, 6*x+0*y+4, 13) def test_zero_identity(): ''' SEM on the plane: zero identity, vorticity(gradient())=0 ''' ngq = 4 sep = SpectralElementPlane(ngq) scalar = np.random.rand(ngq,ngq) ret1 = np.zeros((ngq,ngq,2), 'f8') ret2 = np.zeros((ngq,ngq), 'f8') sep.gradient(scalar, ret1) sep.vorticity(ret1, ret2) aa_equal(ret2, np.zeros((ngq,ngq), 'f8'), 14) if __name__ == '__main__': ngq = 4 gq_pts, gq_wts = gausslobatto(ngq-1) sep = SpectralElementPlane(ngq) print 'derivative matrix (dvvT)\n', sep.dvv.T