def test_l2_h1_1(): eps = 1e-12 eps_low = 1e-10 func = lambda x: sin(x) mesh1 = Mesh1D((0, pi), (20,)) mesh2 = Mesh1D((0, pi/2, pi), (20, 20)) mesh3 = Mesh1D((0, pi/2), (20,)) f = Function(func, mesh1) g = Function(func, mesh2) h = Function(func, mesh3) assert abs(f.l2_norm(method="Fekete")-sqrt(pi/2)) < eps assert abs(g.l2_norm(method="Fekete")-sqrt(pi/2)) < eps assert abs(h.l2_norm(method="Fekete")-sqrt(pi/4)) < eps assert abs(f.l2_norm(method="FE")-sqrt(pi/2)) < eps assert abs(g.l2_norm(method="FE")-sqrt(pi/2)) < eps assert abs(h.l2_norm(method="FE")-sqrt(pi/4)) < eps assert abs(f.h1_norm()-sqrt(pi)) < eps_low assert abs(g.h1_norm()-sqrt(pi)) < eps_low assert abs(h.h1_norm()-sqrt(pi/2)) < eps_low func = lambda x: cos(x) mesh1 = Mesh1D((0, pi/4, pi/2, 3*pi/4, pi), (20, 20, 20, 20)) f = Function(func, mesh1) assert abs(f.l2_norm(method="Fekete")-sqrt(pi/2)) < eps assert abs(f.l2_norm(method="FE")-sqrt(pi/2)) < eps assert abs(f.h1_norm()-sqrt(pi)) < eps
def test_l2_h1_1(): eps = 1e-12 eps_low = 1e-10 func = lambda x: sin(x) mesh1 = Mesh1D((0, pi), (20, )) mesh2 = Mesh1D((0, pi / 2, pi), (20, 20)) mesh3 = Mesh1D((0, pi / 2), (20, )) f = Function(func, mesh1) g = Function(func, mesh2) h = Function(func, mesh3) assert abs(f.l2_norm(method="Fekete") - sqrt(pi / 2)) < eps assert abs(g.l2_norm(method="Fekete") - sqrt(pi / 2)) < eps assert abs(h.l2_norm(method="Fekete") - sqrt(pi / 4)) < eps assert abs(f.l2_norm(method="FE") - sqrt(pi / 2)) < eps assert abs(g.l2_norm(method="FE") - sqrt(pi / 2)) < eps assert abs(h.l2_norm(method="FE") - sqrt(pi / 4)) < eps assert abs(f.h1_norm() - sqrt(pi)) < eps_low assert abs(g.h1_norm() - sqrt(pi)) < eps_low assert abs(h.h1_norm() - sqrt(pi / 2)) < eps_low func = lambda x: cos(x) mesh1 = Mesh1D((0, pi / 4, pi / 2, 3 * pi / 4, pi), (20, 20, 20, 20)) f = Function(func, mesh1) assert abs(f.l2_norm(method="Fekete") - sqrt(pi / 2)) < eps assert abs(f.l2_norm(method="FE") - sqrt(pi / 2)) < eps assert abs(f.h1_norm() - sqrt(pi)) < eps
def test_l2_h1_2(): eps = 1e-9 func = lambda x: log(x) mesh1 = Mesh1D((1, 1.5, 2, 2.5, e), (20, 20, 20, 20)) f = Function(func, mesh1) l2_norm_exact = sqrt(e-2) h1_norm_exact = sqrt(e-1-exp(-1)) assert abs(f.l2_norm(method="Fekete")-l2_norm_exact) < eps assert abs(f.l2_norm(method="FE")-l2_norm_exact) < eps assert abs(f.h1_norm()-h1_norm_exact) < eps
def test_l2_h1_2(): eps = 1e-9 func = lambda x: log(x) mesh1 = Mesh1D((1, 1.5, 2, 2.5, e), (20, 20, 20, 20)) f = Function(func, mesh1) l2_norm_exact = sqrt(e - 2) h1_norm_exact = sqrt(e - 1 - exp(-1)) assert abs(f.l2_norm(method="Fekete") - l2_norm_exact) < eps assert abs(f.l2_norm(method="FE") - l2_norm_exact) < eps assert abs(f.h1_norm() - h1_norm_exact) < eps