HDG method for the Stokes with non-homogeneous Dirichlet boundary condition

Hello everyone,

I try to use the HDG (or MCS) method to solve the Stokes equations in velocity gradient-velocity-pressure formulation, where non-homogeneous Dirichlet boundary condition is imposed over the whole boundary (say the domain is unit square), and the codes work well for homogeneous Dirichlet boundary condition. However, the solution is not correct for non-homogeneous Dirichlet boundary conditions. I attach the following codes that address the enforcement of non-homogeneous Dirichlet boundary conditions.

def tang(vec):
return vec - (vec*n)*n

uexact = CoefficientFunction((cos(xpi)sin(ypi),-cos(ypi)sin(xpi)))

gfu = GridFunction(fes)

#impose non-homogeneous Dirichlet Boundary condition

gfu.components[4].Set((uexact*n)*n,BND). #diri for velocity

gfu.components[5].Set(tang(uexact),BND)#diri for tangential facet

r = f.vec -a.mat * gfu.vec
gfu.vec.data = a.mat.Inverse(fes.FreeDofs()) * r

I do not know which part is wrong, anyone can help? Many thanks.

Best regards,

Hi Lina,


gfu.vec.data += a.mat.Inverse(fes.FreeDofs()) * r

(note the += instead of the =).
Otherwise (with your code) you will have zero values at the Dirichlet dofs.


Hello Christoph,

Thank you so much for your kind reply. It is working now.

Best regards,