symmetric iterative linear solver malfunction?
I just set up a simple Poisson test problem with varying diffusion coefficient, and then trying to solve this with a Krylov solver.
I added Dirichlet boundary conditions to the problem so in principle it's not symmetric, but since the boundary conditions are homogeneous and I assume that the starting value of CG is zeros(n) (right?), CG should also converge.
However, it doesn't. :)
Try flipping "symmetric" from True to False in the following script:
================= *snip* =================
from dolfin import *
class Left(SubDomain):
def inside(self, x, on_boundary):
return x[0] <= 0.5
class Right(SubDomain):
def inside(self, x, on_boundary):
return 0.5 < x[0]
left = Left()
right = Right()
mesh = UnitSquareMesh(2, 2)
domains = CellFunction(
domains.set_all(0)
left.mark(domains, 1)
right.mark(domains, 2)
f = Constant(1.0)
V = FunctionSpace(mesh, 'CG', 1)
bcs = DirichletBC(V, 0.0, 'on_boundary')
dx = Measure(
K = {0: 1.0,
1: 2.0,
2: 1.0}
u = TrialFunction(V)
v = TestFunction(V)
a = zero() * dx(0)
L = zero() * dx(0)
for i in [0,1,2]:
a += inner(K[i]*grad(u), grad(v)) * dx(i)
L += f*v*dx(i)
# Solve problem
u = Function(V)
solve(a == L, u, bcs=bcs,
solver_
# Compute the residual norm.
r = zero() * dx(0)
for i in [0,1,2]:
r += inner(K[i]*grad(u), grad(v)) * dx(i) \
- f*v*dx(i)
R = assemble(r, bcs=bcs)
print(norm(R))
plot(u, title='u')
interactive()
================= *snap* =================
Anyways, I assume that something is going wrong since CG reports a residual norm of 0 while explicit calculation reveals it's not.
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- DOLFIN Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- Nico Schlömer
- Solved:
- Last query:
- Last reply: