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)
F = inner(grad(u),grad(v))*dx - f*v*dx

bcs = DirichletBC(V, Constant(0.0), 'on_boundary')
u = Function(V)
solve(lhs(F) == rhs(F), u, bcs)
R = assemble(inner(grad(u),grad(v))*dx - f*v*dx).norm('l2')
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?
R = assemble(inner(grad(u),grad(v))*dx - f*v*dx)
bcs.apply(R, u.vector())
print(R.norm("l2"))​
which gives me 1.852890301179797e-15
written 7 days ago by Nate  
Yes I did! Thank you for your help.
written 7 days ago by OABamford  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »