# 2.6 Stokes equation

https://docu.ngsolve.org/latest/i-tutorials/unit-2.6-stokes/stokes.html

Good morning,

I was trying to copy this code to run it. But it does not give me the same results. I pinpointed that my problem starts when I “Set inhomogeneous Dirichlet boundary condition only on inlet boundary”. I await an answer.

Thank you very much!

Hi,

could you please specify the issue with a bit more detail? When I download the notebook and run it locally, I get the same results as on the website. Maybe there’s just a copy/paste error sliced in somewhere?

Best, Henry

Sorry, I keep trying to upload the code or a picture of the result, but it does not allow me. This is the code from the website that I copied over. I ran it in the terminal, but the Netgen solution result was a grey figure, which is not what is displayed in the site. Am I missing something?

I think it might be because of this: “Including OpenCascade geometry kerneloptfile ./ng.opt does not exist - using default values”

from ngsolve import *
from ngsolve.webgui import Draw
from netgen.geom2d import SplineGeometry

geo = SplineGeometry()
geo.AddRectangle( (0, 0), (2, 0.41), bcs = (“wall”, “outlet”, “wall”, “inlet”))
geo.AddCircle ( (0.2, 0.2), r=0.05, leftdomain=0, rightdomain=1, bc=“cyl”)
mesh = Mesh( geo.GenerateMesh(maxh=0.05))
mesh.Curve(3)
Draw (mesh)

V = H1(mesh, order=2, dirichlet=“wall|inlet|cyl”)
Q = H1(mesh, order=1)
X = VVQ

ux,uy,p = X.TrialFunction()
vx,vy,q = X.TestFunction()

a = BilinearForm(X)
a.Assemble()

#Set inhomogeneous Dirichlet boundary condition only on inlet boundary:

gfu = GridFunction(X)
uin = 1.54y*(0.41-y)/(0.41*0.41)
gfu.components[0].Set(uin, definedon=mesh.Boundaries(“inlet”))
velocity = CoefficientFunction(gfu.components[0:2])
Draw(velocity, mesh, “vel”)
SetVisualization(max=2)

res = gfu.vec.CreateVector()
res.data = -a.mat * gfu.vec
inv = a.mat.Inverse(freedofs=X.FreeDofs(), inverse=“umfpack”)
gfu.vec.data += inv * res
Draw(velocity, mesh, “vel”)

Hi,

in line 2 of your code, the Netgen GUI Draw is replaced with webgui.Draw. This was needed in the notebook, to do the visualisation in the browser window. You just need to remove this line so that the Netgen GUI does the visualisation and then in Netgen go Visual->Scalar Function → func (vel) to see the norm of the vector solution in the Netgen GUI.

Best,
Henry

Great, that worked! Thank you!