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

partial derivatives and error of the numerical solution at boundaries

0 votes

Hello,

While trying to figure out how to write a partial derivative $\partial_x u$, I wrote the following piece of code to solve $-\partial_x^2 u(x,y)=-x-y^2$ in 2D with boundary conditions $u_0 = \tfrac{x^3}{6}+\tfrac{x^2y^2}{2}$:

V = FunctionSpace(mesh, 'Lagrange', 2)
#a = inner(nabla_grad(u)[0], nabla_grad(v)[0])*dx
a = inner(u.dx(0), v.dx(0))*dx
L = f*v*dx

Here are the questions:
1) do both forms nabla_grad(u)[0] and u.dx(0) represent the partial derivative in the x direction? Is there any difference between the two?
2) I have noticed that the difference between the numerical and the exact solution $u_0$ is largest (of order $10^{-5}$ relative) at the boundaries, which is puzzling because the boundaries are imposed. What is the reason for this?

asked Aug 16, 2013 by michele.zaffalon FEniCS Novice (450 points)

1 Answer

+1 vote

1) for scalar u both are the same.

2) Exact solution $u_0$ is degree 4 polynomial hence is not exactly representable by any function from V.

No need to use inner here - ordinary multiplication * will suffice.

answered Aug 17, 2013 by Jan Blechta FEniCS Expert (51,420 points)

$u_0$ is a 4th order polynomial also inside the domain, but here the error is much smaller.
But you are right: Increasing the order of the function space V to 4th makes the error negligible everywhere.

...