david
June 23, 2019, 7:06pm
1
Hi! I am new to FEniCS and I have solved a variational problem using finite elements and a time-discretisation. Some of the code is below:
mesh = IntervalMesh(num_x_steps, 0.0, x_max)
V = FunctionSpace(mesh, "Lagrange", 1)
u = Function(V)
u_prevs = Function(V)
x_expression = Expression('x[0]', degree=1)
F = (inner(u, v) * dx
- inner(u_prevs, v) * dx
+ dt * inner(x_expression * x_expression * u.dx(0), v.dx(0)) * dx
+ dt * inner(x_expression * u.dx(0), v) * dx)
solve(F == 0, u, bc)
This is working well and now I am trying to compute the error (L2 norm). I am trying to find the error between the vectors
\frac{π’βπ’_{ππππ£π }}{ππ‘}
and
β\frac{1}{2}x^2 \frac{\partial^2u}{\partial x^2}.
So far I am thinkingβ¦
errornorm((u-u_prevs)/dt, 0.5*...
but am unsure how to proceed. Any help would be appreciated, thanks
If I understand correctly, this is not a well-defined quantity, since, if u is a function in a C^0 finite element space, then its second spatial derivatives are not in L^2 . (\partial_x u will be discontinuous at nodes and constant on elements, so \partial^2_x u will be a collection of Dirac delta distributions located at the finite element nodes.)
david
June 24, 2019, 8:29pm
3
Ah I see (and agree)⦠would you be able to help me understand what the following two lines of code are doing please�
e = ((u - u_prevs)/dt) - 0.5 * sigma * sigma * x_expression * x_expression * u.dx(0).dx(0)
print(assemble(e**2*dx(mesh)))
This is what I came up with before I had seen your comment. Thanks
The dx
measure integrates over interiors of cells, where \partial^2_x u is well-defined, but zero. It should give the same result as defining
e = ((u - u_prevs)/dt)
because u.dx(0).dx(0)
is zero on the interiors of the cells.