I'm trying to understand what happens when we specify the flag degree
in an Expression
. In particular, I'd like to understand what impact it has
on convergence and how to interpret it in terms of quadrature rules.
For this purpose, I've experimented with the following code, which
estimates FE convergence in $H^1$. When constructing the expression of rhs
,
it is sufficient to set its degree
to be $\geq 2$ to maintain cubic convergence.
On the other hand, the order of convergence decreases to 2 when degree
is set it to 0 or 1.
Bonus question: how to manually impose the order of the quadrature rule to
be employed when assembling the stiffness matrix and the rhs in the variational
form?
from dolfin import *
import numpy as np
import sympy as sy
from sympy.printing import ccode
#build reference solution
x_ = sy.Symbol('x[0]')
y_ = sy.Symbol('x[1]')
uref_ = sy.sin(x_ + 2*y_)
rhs_ = - sy.diff(uref_, x_, x_) - sy.diff(uref_, y_, y_)
uref = Expression(ccode(uref_), degree=10)
rhs = Expression(ccode(rhs_), degree=10)
err_h1 = []
iMax = 4
nElem = [20*2**ii for ii in range(iMax)]
for N in nElem:
mesh = UnitSquareMesh(N, N)
U = FunctionSpace(mesh, "CG", 3)
u = Function(U)
v = TestFunction(U)
F = inner(grad(v), grad(u))*dx - rhs*v*dx
bc = DirichletBC(U, uref, "on_boundary")
solve(F == 0, u, bc)
err_h1.append(errornorm(uref, u, 'H1'))
print "H1 error: ", err_h1
#estimate rate of convergence
errh1 = np.array(err_h1)
quotient = errh1[:-1]/errh1[1:]
rateh1 = np.log(quotient)/np.log(2)
print "rate: ", rateh1