def mass_test(N,alpha,beta,scale=1.,shift=0.,tol=1e-8): tests = ValidationContainer() jargs = dict(N=N,alpha=alpha,beta=beta,scale=scale,shift=shift) def dgen1(**kwargs): from spyctral.jacobi.quad import gq from spyctral.jacobi.eval import jacobi_polynomial [r,w] = gq(**kwargs) ps = jacobi_polynomial(r,range(N),alpha=alpha,beta=beta,scale=scale,shift=shift) return [w,ps] def val1(data,**kwargs): from numpy import dot, eye from numpy.linalg import norm [w,ps] = data mass = dot(ps.conj().T*w, ps) return norm(mass - eye(N))<tol tests.append(ValidationTest(\ description = "Jacobi Orthonormal poly mass matrix", parameters = jargs, data_generator = dgen1, validator = val1)) return tests
def gauss_radau_test(N,alpha,beta,r0=-1.,scale=1.,shift=0.,tol=1e-8): from spyctral.jacobi.quad import grq from numpy import max, abs, all tests = ValidationContainer() jargs = dict(N=N,alpha=alpha,beta=beta,scale=scale,shift=shift,r0=r0) def val1(data,**kwargs): r = data[0] return max(abs(r-shift)/scale)<=1+tol tests.append(ValidationTest(\ description = "Jacobi Gauss-Radau nodes inside interval", parameters = jargs, data_generator = grq, validator = val1)) def val2(data,**kwargs): r = data[0] return any(abs(r-r0)<tol) tests.append(ValidationTest(\ description = "Jacobi Gauss-Radau node", parameters = jargs, data_generator = grq, validator = val2)) def val3(data,**kwargs): w = data[1] return all(w>=-tol) tests.append(ValidationTest(\ description = "Jacobi Gauss-Radau weights positive", parameters = jargs, data_generator = grq, validator = val3)) def dgen1(**kwargs): from spyctral.jacobi.eval import jacobi_polynomial from spyctral.jacobi.quad import grq [x,w] = grq(**kwargs) ps = jacobi_polynomial(x,range(2*N-1),alpha=alpha,beta=beta,scale=scale,shift=shift) ps[:,0] = 0 return [w,ps] def val4(data,**kwargs): from numpy import dot [w,ps] = data errs = dot(w.conj().T,ps) return max(abs(errs))<tol tests.append(ValidationTest(\ description = "Jacobi Gauss-Radau quadrature integration accuracy", parameters = jargs, data_generator = dgen1, validator = val4)) return tests
def mass_test(N,alpha,scale=1.,shift=0.,tol=1e-8): tests = ValidationContainer() jargs = dict(N=N,alpha=alpha,scale=scale,shift=shift) def dgen1(**kwargs): from spyctral.laguerre.quad import gq from spyctral.laguerre.eval import laguerre_polynomial [r,w] = gq(**kwargs) ps = laguerre_polynomial(r,range(N),alpha=alpha,scale=scale,shift=shift) return [w,ps] def val1(data,**kwargs): from numpy import dot, eye from numpy.linalg import norm [w,ps] = data mass = dot(ps.conj().T*w, ps) temp = min([N,10]) return norm(mass[:temp,:temp] - eye(temp))<tol tests.append(ValidationTest(\ description = "Laguerre Orthonormal poly mass matrix", parameters = jargs, data_generator = dgen1, validator = val1)) def dgen2(**kwargs): from spyctral.laguerre.quad import pgq from spyctral.laguerre.eval import laguerre_function [r,w] = pgq(**kwargs) ps = laguerre_function(r,range(N),alpha=alpha,scale=scale,shift=shift) return [w,ps] def val2(data,**kwargs): from numpy import dot, eye from numpy.linalg import norm [w,ps] = data mass = dot(ps.conj().T*w, ps) temp = min([N,50]) return norm(mass[:temp,:temp] - eye(temp))<tol return tests
def pi_gauss_test(N,alpha,scale=1.,shift=0.,tol=1e-8): """ Defines all the tests for pi-Gauss quadrature nodes. Returns a ValidationContainer. """ from spyctral.laguerre.quad import pgq from numpy import abs, max, all tests = ValidationContainer() def val1(data,**kwargs): from spyctral.laguerre.misc import interval r = data[0] lint = interval(scale=scale,shift=shift) return all((r-lint[0])>-tol) jargs = dict(N=N,alpha=alpha,scale=scale,shift=shift) tests.append(ValidationTest(\ description="Laguerre pi-Gauss quadrature points inside interval", parameters = jargs, data_generator = pgq, validator = val1)) def val2(data,**kwargs): w = data[1] return all(w>=-tol) tests.append(ValidationTest(\ description = "Laguerre pi-Gauss quadrature weights positive", parameters = jargs, data_generator = pgq, validator = val2)) def dgen1(**kwargs): from spyctral.laguerre.eval import laguerre_function from spyctral.laguerre.weights import sqrt_weight [x,w] = pgq(**kwargs) ps = laguerre_function(x,range(2*N),alpha=alpha,scale=scale,shift=shift) ps[:,0] = 0 ps = (ps.T*sqrt_weight(x,alpha=alpha,scale=scale,shift=shift)).T return [w,ps] def val3(data,**kwargs): from numpy import dot [w,ps] = data errs = dot(w.conj().T,ps) return max(abs(errs))<tol tests.append(ValidationTest(\ description = "Laguerre pi-Gauss quadrature integration accuracy", parameters = jargs, data_generator = dgen1, validator = val3)) return tests
def gauss_test(N,alpha,beta,scale=1.,shift=0.,tol=1e-8): """ Defines all the tests for Gauss quadrature nodes. Returns a ValidationContainer. """ from spyctral.jacobi.quad import gq from numpy import abs, max, all tests = ValidationContainer() def val1(data,**kwargs): r = data[0] return max(abs(r-shift)/scale)<1+tol jargs = dict(N=N,alpha=alpha,beta=beta,scale=scale,shift=shift) tests.append(ValidationTest(\ description="Jacobi Gauss quadrature points inside interval", parameters = jargs, data_generator = gq, validator = val1)) def val2(data,**kwargs): w = data[1] return all(w>=-tol) tests.append(ValidationTest(\ description = "Jacobi Gauss quadrature weights positive", parameters = jargs, data_generator = gq, validator = val2)) def dgen1(**kwargs): from spyctral.jacobi.eval import jacobi_polynomial [x,w] = gq(**kwargs) ps = jacobi_polynomial(x,range(2*N),alpha=alpha,beta=beta,scale=scale,shift=shift) ps[:,0] = 0 return [w,ps] def val3(data,**kwargs): from numpy import dot [w,ps] = data errs = dot(w.conj().T,ps) return max(abs(errs))<tol tests.append(ValidationTest(\ description = "Jacobi Gauss quadrature integration accuracy", parameters = jargs, data_generator = dgen1, validator = val3)) return tests