Hi everyone, I need to check some residuals but I didn’t see convergence. After some tests, I figured that there is a strange behavior, that I report below. Perhaps it is stupid, but thanks for the help.
from dolfin import *
Mesh
N = 10
mesh = UnitSquareMesh(N, N)Functions
V = FunctionSpace(mesh, ‘CG’, 1)
bc = DirichletBC(V, Constant(0), ‘on_boundary’)u = Function(V)
v = TestFunction(V)f = Constant(1)
Residual and matrices
aa = dot(grad(u), grad(v))
ff = f*v
F = (aa - ff)*dx
dF = derivative(F, u, TrialFunction(V))
A_res = assemble(dF)
b_res = assemble(-F)aa = dot(grad(TrialFunction(V)), grad(v))
A = assemble(aadx)
b = assemble(ffdx)
for obj in (A, b, A_res, b_res):
bc.apply(obj)sol_res = Function(V)
sol = Function(V)solve(A_res, sol_res.vector(), b_res)
solve(A, sol.vector(), b)Compute residual norms
Fvec = PETScVector()
assemble(F, tensor=Fvec)
print(“Difference:”, (sol.vector() - sol_res.vector()).vec().norm()) # 0
print(“Residual F”, Fvec.vec().norm()) # 0.09
print(“Residual Ax-b”, (A*sol.vector()-b).vec().norm()) # 1e-16
Thanks in advance