Dear Fenics community,
I am new to fenics and PDEs overall. I am using dolphin version 2019.2.0.dev0. and I am trying to solve a simple time dependant lid-driven cavity flow problem using a non linear Navier Stokes with SUPG, PSPG and LSIC stabilizers to handle big Reynolds numbers, but I feel that the code works better without the stabilizers. I want to know if I am doing something wrong.
Thank you in advance!
from dolfin import *
# Set up mesh and finite element spaces
N = 32
mesh = UnitSquareMesh(N, N)
V = VectorElement("CG", triangle, 2)
P = FiniteElement("CG", triangle, 1)
W = FunctionSpace(mesh, V * P)
# Time-stepping parameters
dt = 0.01 # Time step size
T = 1.0 # Total simulation time
# Define boundary conditions for velocity and pressure
noslip = Constant((0, 0))
bc_wall = DirichletBC(W.sub(0), noslip, 'on_boundary && x[1] > DOLFIN_EPS')
lid_velocity = Constant((1, 0))
bc_lid = DirichletBC(W.sub(0), lid_velocity, 'near(x[1], 1)')
bc_p = DirichletBC(W.sub(1), 0, "x[0] < DOLFIN_EPS && x[1] < DOLFIN_EPS", "pointwise")
bcs = [bc_wall, bc_lid, bc_p]
# Define functions for the current and previous time step
w = Function(W) # Current solution
w_n = Function(W) # Previous solution
# Split mixed functions
u, p = split(w)
u_n, p_n = split(w_n)
v, q = TestFunctions(W)
# Define Reynolds number and viscosity
Reynolds = 1_000.0
nu = 1.0 / Reynolds
# Define mesh size and velocity magnitude for stabilization parameters
h = CellDiameter(mesh)
u_magnitude = sqrt(dot(u_n, u_n))
# Stabilization parameters (tau)
tau_SUPG = 1.0 / sqrt((2.0 / dt)**2 + (u_magnitude / h)**2 + (4.0 * nu / h**2)**2)
tau_PSPG = tau_SUPG # Often, PSPG uses the same tau as SUPG
tau_LSIC = h**2 / nu # Typically related to the mesh size and viscosity
# Define stabilization terms
# SUPG stabilization of convective term
SUPG_term = tau_SUPG * inner(dot(grad(u), u), dot(grad(v), u)) * dx
# PSPG stabilization of pressure term
PSPG_term = tau_PSPG * inner(grad(q), grad(p)) * dx
# LSIC stabilization to enforce incompressibility
LSIC_term = tau_LSIC * inner(div(u), div(v)) * dx
# Define variational problem with stabilization terms
F = (inner(u - u_n, v) / dt * dx # Time derivative
+ nu * inner(grad(u), grad(v)) * dx # Diffusion
+ inner(dot(grad(u), u), v) * dx # Non-linear convection
- div(v) * p * dx # Pressure term
+ q * div(u) * dx # Continuity equation
# Add stabilization terms
+ SUPG_term # SUPG for convective stabilization
+ PSPG_term # PSPG for pressure stabilization
+ LSIC_term) # LSIC for incompressibility
# Compute Jacobian
J = derivative(F, w)
# Time-stepping loop
t = 0.0
cont = 0
while t < T:
t += dt
# Solve for the current time step
solve(F == 0, w, bcs, J=J)
# Update the previous solution
w_n.assign(w)
cont +=1
if ( cont % 10 == 0 ):
print(f"Time: {t}")
# Optionally plot the results
plot(u, title="Velocity")
plt.show()
plot(p, title="Pressure")
plt.show()