 # The solver did not converge when solving the N-S eqation with large inlet velocity

The solver converged with the inlet velocity of 0.01 m/s, while it did not converge with the inlet velocity of 0.1 m/s. I checked the Re number. The flow is laminar. Who can help me? Thank you!
The following is the error message and code.
*** -------------------------------------------------------------------------
*** Error: Unable to solve nonlinear system with NewtonSolver.
*** Reason: Newton solver did not converge because maximum number of iterations reached.
*** Where: This error was encountered inside NewtonSolver.cpp.
*** Process: 0

*** DOLFIN version: 2019.1.0

from dolfin import *
import mshr
import matplotlib.pyplot as plt
from mshr import *
from fenics import *

mu = 1.05E-3
rho = 1000
#Generate mesh with mshr

domain = (Rectangle(dolfin.Point(0., -5.0E-3), dolfin.Point(15.0E-3, 5.0E-3)) +
Rectangle(dolfin.Point(15.0E-3, -30.0E-3), dolfin.Point(135.0E-3, 30.0E-3)) +
Rectangle(dolfin.Point(135.0E-3, -5.0E-3), dolfin.Point(150.0E-3, 5.0E-3)))
mesh = generate_mesh(domain, 100)
V = VectorElement(‘P’, mesh.ufl_cell(), 2)
Q = FiniteElement(‘P’, mesh.ufl_cell(), 1)
TH = MixedElement([V, Q])
W = FunctionSpace(mesh, TH)
#Defining the boundary
#plot(mesh)
inflow = ‘near(x, 0.0)’
outflow = ‘near(x, 150.0E-3)’
walls = (‘near(x, 5.0E-3) || near(x, 30.0E-3) || near(x,15.0E-3) || near(x, -5.0E-3) ||’ +
‘near(x, 135.0E-3) || near(x, -30.0E-3)’)

#Defining boundary conditions
bcu_inflow = DirichletBC(W.sub(0), Constant((0.1, 0.0)), inflow)
bcp_outflow = DirichletBC(W.sub(1), Constant(0), outflow)
bcu_noslip = DirichletBC(W.sub(0), Constant((0.0, 0.0)), walls)
bcs = [bcu_noslip, bcu_inflow, bcp_outflow]

#Define variational forms

v, q = TestFunctions(W)
w = Function(W)
dw= TrialFunction(W)
u, p = split(w)
#Equation
- inner(p, div(v))*dx - inner(q, div(u))*dx
J = derivative(F1, w, dw)
newton_solver_parameters={“nonlinear_solver”: “newton”,
“newton_solver” :{“linear_solver” : “mumps”,
“maximum_iterations”: 50,
“report”: True,
“error_on_nonconvergence”: True
}
}
problem = NonlinearVariationalProblem(F1, w, bcs, J)
solver = NonlinearVariationalSolver(problem)
solver.parameters.update(newton_solver_parameters)
solver.solve()
u, p = split(w)
plot(u)

``````from dolfin import *
import mshr
import matplotlib.pyplot as plt
from mshr import *
from fenics import *

mu = 1.05E-3
rho = 1000
#Generate mesh with mshr

domain = (Rectangle(dolfin.Point(0., -5.0E-3), dolfin.Point(15.0E-3, 5.0E-3)) +
Rectangle(dolfin.Point(15.0E-3, -30.0E-3), dolfin.Point(135.0E-3, 30.0E-3)) +
Rectangle(dolfin.Point(135.0E-3, -5.0E-3), dolfin.Point(150.0E-3, 5.0E-3)))
mesh = generate_mesh(domain, 100)
V = VectorElement('P', mesh.ufl_cell(), 2)
Q = FiniteElement('P', mesh.ufl_cell(), 1)
TH = MixedElement([V, Q])
W = FunctionSpace(mesh, TH)
#Defining the boundary
#plot(mesh)
inflow = 'near(x, 0.0)'
outflow = 'near(x, 150.0E-3)'
walls = ('near(x, 5.0E-3) || near(x, 30.0E-3) || near(x,15.0E-3) || near(x, -5.0E-3) ||' +
'near(x, 135.0E-3) || near(x, -30.0E-3)')

#Defining boundary conditions
#plot(mesh)
bcu_inflow = DirichletBC(W.sub(0), Constant((0.01, 0.0)), inflow)
bcp_outflow = DirichletBC(W.sub(1), Constant(0), outflow)
bcu_noslip = DirichletBC(W.sub(0), Constant((0.0, 0.0)), walls)
bcs = [bcu_noslip, bcu_inflow, bcp_outflow]
#Define variational forms

v, q = TestFunctions(W)
w = Function(W)
dw= TrialFunction(W)
u, p = split(w)
#Equation

- inner(p, div(v))*dx - inner(q, div(u))*dx
J = derivative(F1, w, dw)

newton_solver_parameters={"nonlinear_solver": "newton",
"newton_solver"     :{"linear_solver"  : "mumps",
"maximum_iterations": 50,
"report": True,
"error_on_nonconvergence": True
}
}

problem = NonlinearVariationalProblem(F1, w, bcs, J)
solver = NonlinearVariationalSolver(problem)
solver.parameters.update(newton_solver_parameters)

(itera, converged) = solver.solve()

(u, p) = w.split()
``````

Sorry, I did not know how to post the code. You should modify some symbols if you want to run the code.

To post the code in an appropriate way, use 3x` encapsulation. Also make sure all indentation is correct

Thanks for your suggestion. I updated my code.