A question regarding residuals
7 days ago by
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∈Vh
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:
Here, R comes out at about 0.3. Could anyone tell me why this is?
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')
Community: FEniCS Project
Please login to add an answer/comment or follow this question.