### A question regarding residuals

48
views
0
7 days ago by
Hello all,

I just wanted to clarify something that has confused me when using FEniCS, and may represent either a mathematical misunderstanding, or one related to using FEniCS.

If we solve the linear problem:
$\left(\nabla u,\nabla v\right)=\left(f,v\right)$(u,∇v)=(ƒ ,v)        $\forall v\in V_h$vVh
with, say, homogeneous Dirchlet BCs, and then assemble the vector
$R_i=\left(\nabla u,\nabla\phi_i\right)-\left(f,\nabla\phi_i\right)$Ri=(u,∇ϕi)(ƒ ,∇ϕi) ,
where  $\phi_i$ϕi  are the basis functions of $V_h$Vh , should we not have that every element of  $R$R  is equal to zero (within machine precision)? The code below is given as an example:
from fenics import *
import numpy as np

mesh = UnitSquareMesh(10,10)
V = FunctionSpace(mesh, 'CG', 1)
v = TestFunction(V)
u = TrialFunction(V)

f = Constant(2.0)

bcs = DirichletBC(V, Constant(0.0), 'on_boundary')
u = Function(V)
solve(lhs(F) == rhs(F), u, bcs)
Here, R comes out at about 0.3. Could anyone tell me why this is?

Many thanks!
Community: FEniCS Project
1
Did you forget to apply your homogenous BCs to the residual vector?