Equivalence of solve(A, x, b) and solve(a ==L, u)
Hi,
I expected the following two calling sequences to be equivalent (assuming solver_
solve(a == L, u, bcs, solver_
<=>
A = assemble(a)
b = assemble(L)
[bc.apply(A) for bc in bcs]
[bc.apply(b) for bc in bcs]
solve(A, u.vector(), b, solver_
However, it appears that's not the case for certain values of "linear_solver" and "preconditioner", which I was surprised by. For example, consider the following script:
from dolfin import *
import numpy
mesh = Rectangle(0, 0, 2.0, 1.0, 5, 5)
Q = FunctionSpace(mesh, "DG", 1)
W = VectorFunctionS
T_ = Function(Q)
T_.vector()[:] = numpy.array([1.0, 1.0, 0.5000000000767537, 1.0, 0.910936301182697, 0.5000000000767537, 1.0, 1.0, 0.5000000000000719, 1.0, 0.5000000000767537, 0.5000000000000719, 1.0, 1.0, 0.5, 1.0, 0.5000000000000719, 0.5, 1.0, 1.0, 0.5, 1.0, 0.5, 0.5, 1.0, 0.1816901138162
eta = exp(ln(2.0)*(1.0 - triangle.x[1]) )
f = 1.0e6 * T_ * Constant((0.0, -1.0))
def strain(v):
return sym(grad(v))
(u, p) = TrialFunctions(W)
(v, q) = TestFunctions(W)
F = (2.0*eta*
a = lhs(F)
L = rhs(F)
bottom = DirichletBC(
top = DirichletBC(
left = DirichletBC(
right = DirichletBC(
bcs = [bottom, top, left, right]
for (pc, ksp) in [("default", "default"), ("amg", "tfqmr")]:
u = Function(W)
solve(a == L, u, bcs, solver_
u2 = Function(W)
(A, b) = (assemble(a), assemble(L))
[bc.apply(A) for bc in bcs]
[bc.apply(b) for bc in bcs]
solve(A, u2.vector(), b, solver_
print "Norm for (%s, %s): " % (pc, ksp)
print (u2.vector() - u.vector(
It sets up a linear system, and then attempts the two different approaches, with different values of "preconditioner" and "linear_solver". The output on my system is:
[pef@aislinn:
Solving linear variational problem.
Norm for (default, default):
0.0
Solving linear variational problem.
Norm for (amg, tfqmr):
4514505.89407
which I wasn't expecting.
If I want to use (amg, tfqmr), how should I use solve(A, x, b) to get the exact same answer as solve(a == L, u)?
Thanks!
Patrick
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- DOLFIN Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- Patrick Farrell
- Solved:
- Last query:
- Last reply: