This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Solution plot is showing piece wise linear functions even for higher order Lagrange elements

+2 votes

Hi,

Below is a demo Poisson equation solver that was included in the Fenics installation. I have changed function space from CG_1 to CG_2. But the solution plot does not reflects this change. Plot is still showing a piecewise linear function.


from dolfin import *
mesh = UnitSquareMesh(3,3)
V = FunctionSpace(mesh, "CG", 2)
def boundary(x):
return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS

u0 = Constant(0.0)
bc = DirichletBC(V, u0, boundary)
u = TrialFunction(V)
v = TestFunction(V)
f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)")
g = Expression("sin(5*x[0])")
a = inner(grad(u), grad(v))*dx
L = f*v*dx + g*v*ds
u = Function(V)
solve(a == L, u, bc)
plot(u, interactive = True)


Please tell me what am I missing. Thanks in advance.

Ajit

asked Jun 10, 2014 by ajit FEniCS Novice (560 points)

3 Answers

+1 vote
 
Best answer

To my knowledge it's not supported. The bigger 'issue' for me is that it's also not supported by Paraview (or any other post-processor I know of/have access to). The workaround I have been going through is to interpolate the higher order solution onto a finer linear space.

If you need to write the solution on a finer mesh anyway, you could plot and write the finer mesh that's an interpolation of the higher order solution.

answered Jun 10, 2014 by Charles FEniCS User (4,220 points)
selected Jun 13, 2014 by Garth N. Wells

Yes, similar idea was suggested earlier by Oyvinev. Thanks.

+1 vote

I think it is just not supported, so projection to CG1 takes place before plotting. You could try Paraview.

answered Jun 10, 2014 by KristianE FEniCS Expert (12,900 points)

I did try paraview. Still seeing piece wise linear plots only.

+2 votes

As Kristian says, this is not supported. Have a look here for ideas on how to improve the visualization.

answered Jun 10, 2014 by Øyvind Evju FEniCS Expert (17,700 points)

OK. I will try that. Thanks

...