Comment 1 for bug 521507

Revision history for this message
Garth Wells (garth-wells) wrote :

Here's another solver that leaks. It doesn't use Expressions.

from dolfin import *

class MyProblem(NonlinearProblem):
    def __init__(self, a, L):
        NonlinearProblem.__init__(self)
        self.L = L
        self.a = a
    def F(self, b, x):
        assemble(self.L, tensor=b)
    def J(self, A, x):
        assemble(self.a, tensor=A)

mesh = UnitSquare(8, 8, "crossed")
BDM = FunctionSpace(mesh, "Brezzi-Douglas-Marini", 1)
DG = FunctionSpace(mesh, "Discontinuous Lagrange", 0)
mixed_space = MixedFunctionSpace([BDM, DG, DG])

V = TestFunction(mixed_space)
dU = TrialFunction(mixed_space)
U = Function(mixed_space)
U0 = Function(mixed_space)
v, q, r = split(V)
u, p, s = split(U)
u0, p0, s0 = split(U0)

L = inner(v, u)*dx - div(v)*p*dx + v[0]*dx + q*div(u)*dx + r*(s - s0)*dx
a = derivative(L, U, dU)

for level0 in xrange(1000):
    for level in xrange(10):

        A = Matrix();
        b = Vector();

        # This does not appear to leak
        problem = MyProblem(a, L)
        problem.F(b, U.vector())
        problem.J(A, U.vector())

        # This does leak
        #solver = NewtonSolver()
        #solver.solve(problem, U.vector())

        # This does leak (goes through call-back to Python)
        lu = LUSolver()
        lu.solve(A, U.vector(), b)

        U.vector().zero()
    print "End inner loop"