1
"""Unit tests for the KrylovSolver interface"""
3
# Copyright (C) 2012 Johan Hake
5
# This file is part of DOLFIN.
7
# DOLFIN is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Lesser General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
12
# DOLFIN is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Lesser General Public License for more details.
17
# You should have received a copy of the GNU Lesser General Public License
18
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
20
# Modified by Anders Logg 2012
22
# First added: 2012-02-21
23
# Last changed: 2014-05-30
29
mesh = UnitSquareMesh(32, 32)
30
V = FunctionSpace(mesh, 'CG', 1)
31
bc = DirichletBC(V, Constant(0.0), lambda x, on_boundary: on_boundary)
37
a, L = inner(grad(u), grad(v))*dx, Constant(1.0)*v*dx
38
a_L = inner(grad(u1), grad(v))*dx
40
# Assemble linear algebra objects
45
if has_linear_algebra_backend("PETSc"):
46
class PETScKrylovSolverTester(unittest.TestCase):
48
def test_krylov_solver(self):
49
"Test PETScKrylovSolver"
54
# Solve first using direct solver
57
#direct_norm = x.norm("l2")
60
#x_petsc = as_backend_type(x)
62
# With simple interface
63
#solver = PETScKrylovSolver("gmres", prec)
64
#solver.solve(A, x_petsc, as_backend_type(b))
65
#self.assertAlmostEqual(x_petsc.norm("l2"), direct_norm, 5)
67
# With PETScPreconditioner interface
68
#solver = PETScKrylovSolver("gmres", PETScPreconditioner(prec))
69
#solver.solve(A, x_petsc, as_backend_type(b))
70
#self.assertAlmostEqual(x_petsc.norm("l2"), direct_norm, 5)
72
if __name__ == "__main__":
74
# Turn off DOLFIN output
78
print "Testing DOLFIN la/KrylovSolver interface"
79
print "----------------------------------------"