firedrakeproject / firedrake

Firedrake is an automated system for the portable solution of partial differential equations using the finite element method (FEM)
https://firedrakeproject.org
Other
513 stars 160 forks source link

Nonlinear solve failed to converge after 0 nonlinear iterations #1029

Closed APaganini closed 7 years ago

APaganini commented 7 years ago

The following code (taken from a firedrake-adjoint test)

from firedrake import *

mesh = UnitCubeMesh(3, 3, 3)

# Define function spaces
PN = FunctionSpace(mesh, "Nedelec 1st kind H(curl)", 1)

# Define test and trial functions
v0 = TestFunction(PN)
u0 = TrialFunction(PN)

# Define functions
dbdt_v = as_vector([0.0, 0.0, 1.0])
zero = Expression(("0.0", "0.0", "0.0"), degree=1)
T = Function(PN)

# Boundary condition
bc = DirichletBC(PN, zero, "on_boundary")

# Solve eddy currents equation (using potential T)
solve(inner(curl(v0), curl(u0))*dx == -inner(v0, dbdt_v)*dx, T, bc,
      solver_parameters={'ksp_type': 'preonly', 'pc_type': 'lu'})

returns the error message

Traceback (most recent call last):
  File "temp.py", line 23, in <module>
    solver_parameters={'ksp_type': 'preonly', 'pc_type': 'lu'})
  File "/Volumes/Scratch/Users/paalbert/Documents/FIREDRAKE/firedrakeAdjoint/src/firedrake/firedrake/solving.py", line 124, in solve
    _solve_varproblem(*args, **kwargs)
  File "/Volumes/Scratch/Users/paalbert/Documents/FIREDRAKE/firedrakeAdjoint/src/firedrake/firedrake/solving.py", line 154, in _solve_varproblem
    solver.solve()
  File "/Volumes/Scratch/Users/paalbert/Documents/FIREDRAKE/firedrakeAdjoint/src/firedrake/firedrake/variational_solver.py", line 223, in solve
    solving_utils.check_snes_convergence(self.snes)
  File "/Volumes/Scratch/Users/paalbert/Documents/FIREDRAKE/firedrakeAdjoint/src/firedrake/firedrake/solving_utils.py", line 160, in check_snes_convergence
    %s""" % (snes.getIterationNumber(), msg))
firedrake.exceptions.ConvergenceError: Nonlinear solve failed to converge after 0 nonlinear iterations.
Reason:
   Inner linear solve failed to converge after 0 iterations with reason: unknown reason (petsc4py enum incomplete?), try with -snes_convered_reason and -ksp_converged_reason

The message doesn't appear if I drop the solver_parameters. The original dolfin-adjoint test case calls the function solve without solver parameters, which in FEniCs corresponds to using a direct solver.

How should I proceed?

wence- commented 7 years ago

The default petsc LU does no pivoting. Try adding "pc_factor_shift_type": "inblocks" to your solver options.

APaganini commented 7 years ago

Adding "pc_factor_shift_type": "inblocks" resolves the issue. thanks