Hi all,
I guess the Expression
s in FEniCS are only evaluated on the mesh grid points but not on the interior degrees of freedom? For example, when evaluating the |x|
on a single quadratic reference element returns the line of x = 1
, and I think that may lead to the Expression
always be the piecewise linear polynomials no matter how high the element degree is.
I found this when trying to reproduce the Runge phenomenon on a single element, and I am wondering if there is any way to force the Expression
to take accounts for all the degrees of freedom?
Thanks
My guess is that you’re trying to plot to check, which always interpolates to linears. You can see the various behaviors of Expression
in the following example:
from dolfin import *
# Mesh with one element:
mesh = IntervalMesh(1,-1,1)
# Create quadratically-interpolated Expression for |x|:
absx = Expression("fabs(x[0])",degree=2)
# Evaluating it directly works as expected:
from numpy import array
print(absx(array([-1+DOLFIN_EPS,])))
print(absx(array([0,])))
print(absx(array([1-DOLFIN_EPS,])))
print(absx(array([0.5,]))) # Clearly NOT interpolated to quadratic space!
# The "degree" comes into play when using it in integrands; you can see that
# this is not the correct integral of |x|, but rather of x^2, which is the
# interpolant of |x| into a finite element space of the specified degree:
print(assemble(absx*dx(domain=mesh)))
# Plotting always interpolates to linears:
from matplotlib import pyplot as plt
plot(absx,mesh=mesh)
plt.show()
2 Likes