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

Solving non linear problem with gmres and mpirun

0 votes

Hello. I am trying to use GMRES to solve a problem with mpi run but am getting the following error

*** Error:   Unable to successfully call PETSc function 'PCHYPRESetType'.
*** Reason:  PETSc error code is: 86.
*** Where:   This error was encountered inside        
   /home/fenics/build/src/dolfin/dolfin/la/PETScPreconditioner.cpp.

Bellow is an example with nonlinear poisson equation, this is using the latest Fenics build in Docker. For the preconditioner I am using hypre_euclid as recommended in another post. If check for the available solvers and preconditioners, both grmes and hypre_euclid are available. Code is bellow, and any help would be appreciated.

"""
FEniCS tutorial demo program:
Nonlinear Poisson equation with Dirichlet conditions
in x-direction and homogeneous Neumann (symmetry) conditions
in all other directions. The domain is the unit hypercube in
of a given dimension.

-div(q(u)*nabla_grad(u)) = 0,
u = 0 at x=0, u=1 at x=1, du/dn=0 at all other boundaries.
q(u) = (1+u)^m

Solution method: automatic, i.e., by a NonlinearVariationalProblem/Solver
(Newton method).
"""

from dolfin import *
import numpy, sys
print list_krylov_solver_preconditioners()
#print ttt
iterative_solver = True

# Create mesh and define function space
degree = 2
divisions = [int(arg) for arg in sys.argv[4:]]
d = len(divisions)
mesh = UnitSquareMesh(32, 32)

V = FunctionSpace(mesh, 'Lagrange', degree)


# Define boundary conditions
tol = 1E-14
def left_boundary(x, on_boundary):
    return on_boundary and abs(x[0]) < tol

def right_boundary(x, on_boundary):
    return on_boundary and abs(x[0]-1) < tol

Gamma_0 = DirichletBC(V, Constant(0.0), left_boundary)
Gamma_1 = DirichletBC(V, Constant(1.0), right_boundary)
bcs = [Gamma_0, Gamma_1]

# Choice of nonlinear coefficient
m = 2

def q(u):
    return (1+u)**m

def Dq(u):
    return m*(1+u)**(m-1)

# Define variational problem
v  = TestFunction(V)
u  = TrialFunction(V)
F  = inner(q(u)*nabla_grad(u), nabla_grad(v))*dx
u_ = Function(V)  # most recently computed solution
F  = action(F, u_)

J = derivative(F, u_, u)

# Compute solution
problem = NonlinearVariationalProblem(F, u_, bcs, J)
solver  = NonlinearVariationalSolver(problem)
prm = solver.parameters
#info(prm, True)
prm['newton_solver']['absolute_tolerance'] = 1E-8
prm['newton_solver']['relative_tolerance'] = 1E-7
prm['newton_solver']['maximum_iterations'] = 25
prm['newton_solver']['relaxation_parameter'] = 1.0
if True:
    prm['newton_solver']['linear_solver'] = 'gmres'
    prm['newton_solver']['preconditioner'] = 'hypre_euclid'
    prm['newton_solver']['krylov_solver']['absolute_tolerance'] = 1E-9
    prm['newton_solver']['krylov_solver']['relative_tolerance'] = 1E-7
    prm['newton_solver']['krylov_solver']['maximum_iterations'] = 1000
    prm['newton_solver']['krylov_solver']['monitor_convergence'] = True
    prm['newton_solver']['krylov_solver']['nonzero_initial_guess'] = True
    prm['newton_solver']['krylov_solver']['gmres']['restart'] = 40
    #prm['newton_solver']['krylov_solver']['preconditioner']['same_nonzero_pattern'] = True
    prm['newton_solver']['krylov_solver']['preconditioner']['ilu']['fill_level'] = 0
PROGRESS = 16
info(prm, True)
set_log_level(PROGRESS)
solver.solve()

print """
Solution of the nonlinear Poisson problem div(q(u)*nabla_grad(u)) = f,
with f=0, q(u) = (1+u)^m, u=0 at x=0 and u=1 at x=1.
%s
""" % mesh

# Find max error
u_exact = Expression('pow((pow(2, m+1)-1)*x[0] + 1, 1.0/(m+1)) - 1', m=m)
u_e = interpolate(u_exact, V)
import numpy
diff = numpy.abs(u_e.vector().array() - u_.vector().array()).max()
print 'Max error:', diff
asked May 10, 2016 by soviet911 FEniCS Novice (180 points)

Just to add to the above I am able to solve this now useing hypre_amg preconditioner. But since my goal is to solve stationary navier-stokes equation ( low velocity 0.001-0.05 m/s with the fluid being water) I am unable to get an actual solution, even though the iterative solver seems to converge.

...