### A question regarding residuals

48

views

0

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)$(∇

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)$

where $\phi_i$

Many thanks!

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$∀`v`∈`V`_{h}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)$

`R`_{i}=(∇`u`,∇`ϕ`_{i})−(`ƒ`,∇`ϕ`_{i}) ,where $\phi_i$

`ϕ`_{i}are the basis functions of $V_h$`V`_{h}, 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

Please login to add an answer/comment or follow this question.

which gives me

`1.852890301179797e-15`