Hello,
I am recently new to using fenics. I would like to solve the stationary Navier-Stokes equations. I have found some posts from the legacy fenics, but it seems that in the new fenics it is not as straight-forward.
My starting point is a working example of the Stokes equation with an inlet and outlet like so
from mpi4py import MPI
from petsc4py import PETSc
from dolfinx import fem, io
import dolfinx.fem.petsc
import ufl
msh, cell_markers, facet_markers = io.gmshio.read_from_msh("mesh/DFG.msh", MPI.COMM_WORLD, gdim=2)
P2 = ufl.VectorElement("Lagrange", msh.topology.cell_types[0].name, degree=2)
P1 = ufl.FiniteElement("Lagrange", msh.topology.cell_types[0].name, degree=1)
V, Q = fem.functionspace(msh, P2), fem.functionspace(msh, P1)
u, p = ufl.TrialFunction(V), ufl.TrialFunction(Q)
v, q = ufl.TestFunction(V), ufl.TestFunction(Q)
a_uu = ufl.inner(ufl.grad(u), ufl.grad(v)) * ufl.dx
a_up = ufl.inner(p, ufl.div(v)) * ufl.dx
a_pu = ufl.inner(ufl.div(u), q) * ufl.dx
a = fem.form([[a_uu, a_up], [a_pu, fem.Constant(msh, PETSc.ScalarType(0))*p*q*ufl.dx]])
f = fem.Constant(domain, (PETSc.ScalarType(0), PETSc.ScalarType(0)))
L = fem.form([ufl.inner(f, v) * ufl.dx,
ufl.inner(fem.Constant(msh, PETSc.ScalarType(0)), q) * ufl.dx])
bc = []
tdim = msh.topology.dim
noslip = fem.Constant(domain, [0., 0.])
noslip_facet_id = 110 # Gmsh facet marker
noslip_facets = fem.locate_dofs_topological(V, tdim - 1, facet_markers.find(noslip_facet_id))
bc.append(fem.dirichletbc(noslip, noslip_facets, V))
inlet = fem.Constant(domain, [5., 0.])
inlet_facet_id = 111 # Gmsh facet marker
inlet_facets = fem.locate_dofs_topological(V, tdim - 1, facet_markers.find(inlet_facet_id))
bc.append(fem.dirichletbc(inlet, inlet_facets, V))
outlet = PETSc.ScalarType(0)
outlet_facet_id = 100 # Gmsh facet marker
outlet_facets = fem.locate_dofs_topological(Q, tdim - 1, facet_markers.find(outlet_facet_id))
bc.append(fem.dirichletbc(outlet, outlet_facets, Q))
A = fem.petsc.assemble_matrix_nest(a, bcs=bc)
A.assemble()
b = fem.petsc.assemble_vector_nest(L)
fem.petsc.apply_lifting_nest(b, a, bcs=bc)
for b_sub in b.getNestSubVecs():
b_sub.ghostUpdate(addv=PETSc.InsertMode.ADD, mode=PETSc.ScatterMode.REVERSE)
spaces = fem.extract_function_spaces(L)
bcs0 = fem.bcs_by_block(spaces, bc)
fem.petsc.set_bc_nest(b, bcs0)
ksp = PETSc.KSP().create(comm)
ksp.setOperators(A)
ksp.setType("minres")
ksp.setTolerances(rtol=1e-9)
ksp.getPC().setType("fieldsplit")
ksp.getPC().setFieldSplitType(PETSc.PC.CompositeType.ADDITIVE)
pc = ksp.getPC()
pc.setType("lu")
pc.setFactorSolverType("mumps")
pc.setFactorSetUpSolverType()
pc.getFactorMatrix().setMumpsIcntl(icntl=24, ival=1)
pc.getFactorMatrix().setMumpsIcntl(icntl=25, ival=0)
u, p = fem.Function(V), fem.Function(Q)
w = PETSc.Vec().createNest([u.vector, p.vector])
ksp.solve(b, w)
Now for the stationary Navier-Stokes equation, if I simply add the convective nonlinear term to the bilinear form like this
a_uu = ufl.inner(ufl.grad(u), ufl.grad(v)) * ufl.dx + ufl.dot(ufl.dot(u, ufl.grad(u)), v)*ufl.dx
I get this error regarding to the creation of the bilinear form
Exception has occurred: TypeError
cannot unpack non-iterable bool object
So I assume that the nonlinear term has to somehow be linearized, so maybe there has to be a linerization loop, but I am not quite sure how exactly.