The following code is used to solve the incompressible flow. The computaional domain is as follows
My question: the variational formulation of the NS equation is correct?
Thank you very much!
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., 0.), dolfin.Point(15.0E-3, 5.0E-3)) +
Rectangle(dolfin.Point(15.0E-3, 0.), dolfin.Point(135.0E-3, 30.0E-3)) +
Rectangle(dolfin.Point(135.0E-3, 0.), 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.0)'
outflow = 'near(x[0], 150.0E-3)'
walls = ('near(x[1], 5.0E-3) || near(x[1], 30.0E-3) || near(x[0],15.0E-3) ||' + 'near(x[0], 135.0E-3)')
symm = 'near(x[1], 0.0)'
#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)
bcu_symm = DirichletBC(W.sub(0).sub(1), Constant(0.0), symm)
bcs = [bcu_noslip, bcu_inflow, bcu_symm, bcp_outflow]
#Define variational forms
v, q = TestFunctions(W)
w = Function(W)
dw= TrialFunction(W)
u, p = split(w)
#Equation
F1 = mu*inner(grad(u),grad(v))*dx + rho*inner(dot(grad(u),u),v)*dx \
- 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()
plot(u)