def test_integrals(): for N in (10, 11, 12, 13): g = Grid_1D.periodic(N, 0, 2 * pi) pnts = concatenate([g.verts, [g.xmax]]) for f in (sin, cos): reference = deci.slow_integration(g.edges[0], g.edges[1], f) eq(deci.integrate_boole1(pnts, f), reference) eq(integrate_spectral_coarse(pnts, f), reference) eq(integrate_spectral(pnts, f), reference) g = Grid_1D.chebyshev(N, -1, +1) for f in ((lambda x: x), (lambda x: x**3), (lambda x: exp(x))): reference = deci.slow_integration(g.edges[0], g.edges[1], f) eq(deci.integrate_boole1(g.verts, f), reference) eq(integrate_chebyshev(g.verts, f), reference) g = Grid_1D.chebyshev(N, -1, +1) for f in ((lambda x: x), (lambda x: x**3), (lambda x: exp(x))): reference = deci.slow_integration(g.edges_dual[0], g.edges_dual[1], f) x = concatenate(([-1], g.verts_dual, [+1])) eq(deci.integrate_boole1(x, f), reference) eq(integrate_chebyshev_dual(x, f), reference)
def test_integrals(): for N in (10, 11, 12, 13): g = Grid_1D.periodic(N, 0, 2*pi) pnts = concatenate([g.verts, [g.xmax]]) for f in (sin, cos): reference = deci.slow_integration(g.edges[0], g.edges[1], f) eq( deci.integrate_boole1(pnts, f), reference ) eq( integrate_spectral_coarse(pnts, f), reference ) eq( integrate_spectral(pnts, f), reference ) g = Grid_1D.chebyshev(N, -1, +1) for f in ((lambda x: x), (lambda x: x**3), (lambda x: exp(x))): reference = deci.slow_integration(g.edges[0], g.edges[1], f) eq( deci.integrate_boole1(g.verts, f), reference ) eq( integrate_chebyshev(g.verts, f), reference ) g = Grid_1D.chebyshev(N, -1, +1) for f in ((lambda x: x), (lambda x: x**3), (lambda x: exp(x))): reference = deci.slow_integration(g.edges_dual[0], g.edges_dual[1], f) x = concatenate(([-1], g.verts_dual, [+1])) eq( deci.integrate_boole1(x, f), reference ) eq( integrate_chebyshev_dual(x, f), reference )
def projection(cells): P={(0, True) : lambda f: f(cells[0, True]), (0, False) : lambda f: f(cells[0, False]), (1, True) : lambda f: slow_integration(cells[1, True][0], cells[1, True][1], f), (1, False) : lambda f: slow_integration(cells[1, False][0], cells[1, False][1], f),} return P