# How to set the tolerance of a solver

I am currently trying to improve the precision of the solution of a mixed formulation of the Navier-Stokes-Problem on a rather large mesh. Therefore it makes sense to consider a Krylov solver I suppose. However setting the absolute and relative tolerance as in the last discussed post,

does not work for me. Does anyone have any idea why?

``````from fenics import *

import numpy as np

solver = KrylovSolver('bicgstab', 'hypre_amg')

solver.parameters['absolute_tolerance'] = 1e-10

solver.parameters['relative_tolerance'] = 1e-10

print(solver.parameters['absolute_tolerance'])

basic_fem = triangle

n=4

dt= 0.01

mesh = RectangleMesh(Point(-1,-1),Point(1,1),n,n)

V = VectorElement('P', basic_fem, 2 , dim=2)

P = FiniteElement('P', basic_fem, 1 )

element = MixedElement(V,P)

TH = FunctionSpace(mesh,element)

(vl1,pl1) = TrialFunctions(TH)

ul = Function(TH)

(vl,pl)=split(ul)

u_test = TestFunction(TH)

(a,h)=split(u_test)

u0 = Function(TH)

(v0,p0)=split(u0)

v_boundary_exp = Expression(("cos(x[0])*sin(x[1])*exp(-2.0*t/Re)",

"-sin(x[0])*cos(x[1])*exp(-2.0*t/Re)"), t=0.0, Re=1,

degree=2)

# - Define boundary location

boundary_str = "x[0] < 100*DOLFIN_EPS | x[0] > 2*DOLFIN_PI - 100*DOLFIN_EPS |                         x[1] < 100*DOLFIN_EPS | x[1] > 2*DOLFIN_PI - 100*DOLFIN_EPS"

velocity_bc  = DirichletBC(TH.sub(0), v_boundary_exp, boundary_str)

bcs = [velocity_bc] #, pressure_bc]

# - define Initial Condition

IC = Expression(("cos(x[0])*sin(x[1])*exp(-2.0*t/Re)",

"-sin(x[0])*cos(x[1])*exp(-2.0*t/Re)", "-1.0/4.0*(cos(2.0*x[0])+cos(2.0*x[1]))*exp(-4.0*t/Re)"), t=0.0, Re=1, element=TH.ufl_element())

u0.assign(interpolate(IC,TH))

F =  inner( (vl1-v0) , a )*dx             + dt*inner(grad(vl1), grad(a))*dx             + dt*inner(dot(v0, nabla_grad(vl1)), a)*dx + dt*0.5*div(v0)*inner(vl1, a)*dx            -dt*inner(pl1,div(a))*dx + div(vl1)*h*dx #\

A= assemble(lhs(F))

b= assemble(rhs(F))

solver.solve(A,ul.vector(),b)

# compute precision of the solution w.r.t to the L-infinity norm

F2 = inner( (vl-v0) , a )*dx             + dt*inner(grad(vl), grad(a))*dx             + dt*inner(dot(v0, nabla_grad(vl)), a)*dx + dt*0.5*div(v0)*inner(vl, a)*dx            -dt*inner(pl,div(a))*dx + div(vl)*h*dx

print(np.max(np.abs(assemble(F2))))
``````

As an output of the computation I obtain 0.011163711044453531 which is much higher than the given absolute tolerance.

Hello, were you able to solve this?