Exact solution of the PDE problem and the discrete equations: \( \uex (x,t) = x(L-x)(1+{\half}t) \)
import nose.tools as nt
def test_quadratic():
"""Check that u(x,t)=x(L-x)(1+t/2) is exactly reproduced."""
def exact_solution(x, t):
return x*(L-x)*(1 + 0.5*t)
def I(x):
return exact_solution(x, 0)
def V(x):
return 0.5*exact_solution(x, 0)
def f(x, t):
return 2*(1 + 0.5*t)*c**2
L = 2.5
c = 1.5
Nx = 3 # Very coarse mesh
C = 0.75
T = 18
u, x, t, cpu = solver(I, V, f, c, L, Nx, C, T)
u_e = exact_solution(x, t[-1])
diff = abs(u - u_e).max()
nt.assert_almost_equal(diff, 0, places=14)