The MMS works great for 2D but fails to show quadratic convergence in 1D - wondering why?
#Testing MMS on Heat Equation system - works well (in 2-D)!
from dolfin import *
from math import log
def Heat(n):
#Define mesh and geometry
#mesh = Rectangle(0,0,5,5,n,n)
mesh = Interval(n,0,1)
# Define function spaces
V = FunctionSpace(mesh, "CG" , 1)
Y = MixedFunctionSpace([V, V])
# Time variables
dt = Constant(0.02); t = float(dt); T = 0.09
#a_expr = "1 + x[0]*x[0] + A*x[1]*x[1] + B*t" #exact solution 2D
#b_expr = "1 + x[0]*x[0] + A*x[1]*x[1] + B*t"
a_expr = "1 + A*x[1]*x[1] + B*t" #exact solution 1D
b_expr = "1 + A*x[1]*x[1] + B*t"
aexact = Expression(a_expr, A=3.0, B=1.2, t=0)
bexact = Expression(b_expr, A=3.0, B=1.2, t=0)
abexact = Expression((a_expr,b_expr), A=3.0, B=1.2, t=0)
#f = Constant(1.2 - 2. - 2*3.0) #MMS Source term 2D
f = Constant(1.2 - 2*3.0) #MMS Source term 1D
# Previous solution
gamma0 = interpolate(abexact,Y)
(alpha0,beta0) = split(gamma0)
#Define Function and TestFunctions
gamma = Function(Y); (alpha, beta) = split(gamma) #current solution
(v, w) = split(TestFunction(Y))
# Define variational form
F = (alpha*v + dt*inner(grad(alpha),grad(v)) - alpha0*v - dt*f*v + beta*w + dt*inner(grad(beta),grad(w)) - beta0*w - dt*f*w)*dx #uncoupled system
#Boundary Conditions
bcs_a = DirichletBC(Y.sub(0), aexact, DomainBoundary())
bcs_b = DirichletBC(Y.sub(1), bexact, DomainBoundary())
bcs = [bcs_a, bcs_b]
# Solve problem
while t <= T:
aexact.t = t
bexact.t = t
solve(F == 0 , gamma, bcs=bcs)
gamma0.assign(gamma)
t += float(dt)
alpha, beta = gamma.split()
error1 = errornorm(alpha,aexact,"L2",mesh = mesh)
error2 = errornorm(beta,bexact,"L2",mesh = mesh)
return error1
Err = [0,0]
Err[0] = Heat(50)
Err[1] = Heat(100)
print "errors:(%s,%s)" % (Err[0],Err[1])
print (log(Err[0]/Err[1],2))#, log(Err[1]/Err[2],2))