This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Why are my PETSc options being ignored?

+2 votes

I recently did a fresh install of ubuntu 16.04 and installed the latest version of Fenics.
Previously, my program runned fine on ubuntu 12.04 (Fenics 1.5).

I want to use the GMRES solver from PETSc with the ILU preconditioner, but I want to define some extra parameters, such as fill level, restart, etc.

However, when I define these parameters, using PETScOptions().set(), they are being ignored.

The strange thing is that
PETScOptions().set("ksp_view")
PETScOptions().set("ksp_converged_reason")
are being executed. This allows me to see, that the other parameters are indeed ignored.

Any ideas on how I can fix this?

Here is a working example that, on my computer, gives as output of --ksp_view:
KSP Object: 1 MPI processes
type: gmres
GMRES: restart=30, using Classical (unmodified) Gram-Schmidt Orthogonalization with no iterative refinement
GMRES: happy breakdown tolerance 1e-30
maximum iterations=10000, initial guess is zero
tolerances: relative=1e-05, absolute=1e-50, divergence=10000
left preconditioning
using PRECONDITIONED norm type for convergence test
PC Object: 1 MPI processes
type: ilu
ILU: out-of-place factorization
0 levels of fill
...

Which shows the default parameters for maximum iterations, tolerance levels, fill levels, etc, in stead of the ones I defined.

from dolfin import *

# Create mesh and define function space
mesh = UnitSquareMesh(20,20)
V = FunctionSpace(mesh, 'Lagrange', 1)

# Define boundary conditions
u0 = Constant(0.0)

def u0_boundary(x, on_boundary):
    return on_boundary

bc = DirichletBC(V, u0, u0_boundary)

# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(-6.0)
a = inner(nabla_grad(u), nabla_grad(v))*dx
L = f*v*dx

#set petsc options
PETScOptions().set("ksp_max_it", 5000)
PETScOptions().set("ksp_rtol", 1e-3)
PETScOptions().set("ksp_atol", 1e-5)
PETScOptions().set("ksp_view")
PETScOptions().set("ksp_converged_reason")
PETScOptions().set("ksp_monitor_true_residual")
PETScOptions().set("ksp_type", "gmres")
PETScOptions().set("pc_type", "ilu")
PETScOptions().set("pc_factor_levels", 3)
PETScOptions().set("ksp_gmres_restart", 200)

# Compute solution
u = Function(V)
A, b = assemble_system(a, L, bc)
solver = PETScKrylovSolver()
solver.solve(A, u.vector(), b)

#show results
plot(u)
interactive()
asked Oct 20, 2016 by tboelens FEniCS Novice (180 points)
edited Oct 20, 2016 by chris_richardson

1 Answer

+4 votes
 
Best answer

I think this is due to some changes in DOLFIN. You need to call solver.set_from_options() now.

answered Oct 20, 2016 by chris_richardson FEniCS Expert (31,740 points)
selected Oct 20, 2016 by tboelens

This indeed solved my problem.

Thank you so much!

...