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

Error: Unable to solve linear system using PETSc Krylov solver

0 votes

Hello,

I am trying to simulate the Incompressible Navier-Stokes equations in a cylinder, but after a couple of steps inside the loop, I am getting the following error:

** Error: Unable to solve linear system using PETSc Krylov solver.**
** Reason: Solution failed to converge in 0 iterations (PETSc reason DIVERGED_NANORINF, residual norm ||r|| = inf).
** Where: This error was encountered inside PETScKrylovSolver.cpp.**
** Process: unknown

** DOLFIN version: 1.4.0
** Git changeset: unknown

My code is practically the same as in the demo that FEniCS offers (demo_navier-stokes.py), the only thing I changed was the mesh and boundary conditions as follows:

class Around(SubDomain):
  def inside(self, x, on_boundary):
    return -1 <= x[2] <= 1 and on_boundary

class Outflow(SubDomain):
  def inside(self, x, on_boundary):
    return near(x[2], 1.0) and on_boundary   

class Inflow(SubDomain):
  def inside(self, x, on_boundary):
    return near(x[2], -1.0) and on_boundary

#Mesh from FEniCS:
if not has_cgal():
  print "DOLFIN must be compiled with CGAL to generate the mesh."
  exit(0)
cyl = Cone(Point(0, 0, -1), Point(0, 0, 1), 0.5715, 0.5715)  #Cylinder
g3d = cyl
mesh = Mesh(g3d, 32)

# Create mesh functions over the cell facets
sub_domains = MeshFunction("size_t", mesh, mesh.topology().dim() - 1)
# Mark all facets as sub domain 0
sub_domains.set_all(0)
# Mark Around as sub domain 1
around = Around()
around.mark(sub_domains, 1)
# Mark Inflow as sub domain 2
inflow = Inflow()
inflow.mark(sub_domains, 2)
# Mark Outflow as sub domain 3
outflow = Outflow()
outflow.mark(sub_domains, 3)

# Define pressure boundary conditions
p_in = Constant(10.0) #Inflow value of pressure
p_out=Constant(0.0)   #Outflow value of pressure
# Define velocity boundary conditions
noslip = Constant((0, 0, 0))  # -1 < z < 1
u_in = Constant((0, 0, 1))  #Inflow value of velocity
# Define boundary conditions
bc1 = DirichletBC(V, noslip, sub_domains, 1)
bc2 = DirichletBC(V, u_in, sub_domains, 2)
bc3 = DirichletBC(Q, p_in, sub_domains, 2)
bc4 = DirichletBC(Q, p_out, sub_domains, 3)
bcu = [bc1, bc2]
bcp = [bc3, bc4]

Does anybody can help me in finding the error?

Thank you very much in advance!

asked Aug 5, 2014 by Desirée Cabrera FEniCS Novice (280 points)

You can't demand Dirichlet BC for velocity and pressure at the same part of the boundary. This is not well-posed problem.

Thanks for your answer!
Now I have changed the boundary conditions by removing bc2 so that now bcu = [bc1], but still getting the same error.

1 Answer

+2 votes
 
Best answer

Velocity gets growing and finally it blows-up because of

  • high cell Reynolds number
  • high CFL number

Control your time-step and mesh resolution.

answered Aug 7, 2014 by Jan Blechta FEniCS Expert (51,420 points)
selected Aug 13, 2014 by Desirée Cabrera

Yes you are right, my CFL number was high so I reduced the time-step to dt = 0.005 and the mesh resolution to 16 so now CFL satisfies the condition to be less than 1. But I don't understand how can I control the Reynolds number in order not to get a turbulent flow. Since I am simulating water flow in a pipe, the Reynolds number I get is 6x10^5, with a diameter of 0.1143 meters, the density of the water 993.71 kg/m^3, the dynamic viscosity of the water 0.656x10^(-3) kg/ms and a velocity of 4m/s, but I guess I cannot change the data since in this case my fluid wouldn't be water anymore right?

Even so, I tried it setting the kinematic viscosity nu = 0.1, and it converges, but it's not satisfying the no-slip boundary condition for the velocity.

Yes, Reynolds number is given by the problem itself. I was referring to cell Reynolds number.

Ah ok, sorry. So if I understand it correctly from my searches, to control the high cell Reynolds number the mesh resolution has to be higher, so I set it to 32, and keeping the time-step to dt = 0.0005 and the kinematic viscosity nu = 6.602E-7, the simulation is converging and the pressure looks good, but the velocity is not satisfying the no-slip boundary conditions.
Do you know what am I doing wrong?

Thank you for your help!

Do you know what am I doing wrong?

No, I don't. We would need to get the full code to check it.

I found the problem. Using the program ParaView I could see that the velocity was actually satisfying the no-slip boundary conditions on the wall of the cylinder, it is just that fenics is not drawing the zero vectors, so everything is working now!

Thank you very much for your answers Jan Blechta.

...