Hello,
I use FEniCS with Docker on Ubuntu 18.04. I am trying to solve the steady Stokes problem on the unit square \Omega = (0,1)² :
with the prescribed body force f(x,y) = (-4 {\pi}^2 \sin(2 \pi y), -16{\pi}^2 \sin(2 \pi x) \cos(2 \pi y) + 4 {\pi}^2 \sin(2 \pi x)) corresponding to the manufactured solutions
I want to use P^2 - P^0 mixed finite elements for the velocity v and the pressure p.
Here is my code :
from dolfin import *
# Load mesh
mesh = UnitSquareMesh(32, 32)
# Define function spaces
Elem_u = VectorElement("CG", mesh.ufl_cell(), 2)
Elem_p = FiniteElement("DG", mesh.ufl_cell(), 0)
W = FunctionSpace(mesh, Elem_u * Elem_p)
# Define Dirichlet boundary
def boundary(x):
return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS or x[1] < DOLFIN_EPS or x[1] > 1.0 - DOLFIN_EPS
# Boundary conditions for velocity and pressure
bc0 = DirichletBC(W.sub(0), Constant((0.0, 0.0)), boundary)
bc1 = DirichletBC(W.sub(1), Constant(0.0), boundary, "pointwise")
bcs = [bc0, bc1]
# Define variational problem
(u, p) = TrialFunctions(W)
(v, q) = TestFunctions(W)
f = Expression(("-4*pi*pi*sin(2*pi*x[1])","-16*pi*pi*sin(2*pi*x[0])*cos(2*pi*x[1]) + 4*pi*pi*sin(2*pi*x[0])"), degree=2)
a = (inner(grad(u), grad(v)) - div(v)*p + q*div(u))*dx
L = inner(f, v)*dx
# Compute solution
w = Function(W)
solve(a == L, w, bcs)
There is no error message but the pressure obtained does not correspond to the manufactured solution. Indeed, it seems that the zero boundary condition for the pressure (bc1
in the code) is not correctly imposed, as illustrates the following plot :
Do you know where the problem could come from ?
Note that if I use P^2 - P^1 elements I get the correct solution, so that I really think the problem comes from imposing a Dirichlet boundary conditions on P^0 elements.
Thank you in advance for your help