Hy everybody,I try to solve the Stokes equation. If I define a velocity BC (U on surface ‘bot’) everything works fine and the expected result and the calculated result correspond. But, if I define a pressure BC, the results do not correspond to my expectations. On the surface ‘left’ I defined a pressure of 2 MPa and on the right surface I defined a pressure of 0.2 MPa. The velocity on the other surfaces is 0. My problem is, that after solving the Stokes equation, the pressure field on the left and right surface, does not have the value of the BC. So also, the velocity field is quite strange.So, maybe somebody can help me to define the pressure BC correctly.Many thanks to all of you.
Followed you can find my code:
V = Periodic(VectorH1(mesh,order=3, dirichlet=‘bot|top’)) # velocity
Q = H1(mesh,order=2, dirichlet=‘left|right’) # pressure
X = V * Q
obtain test and trial functions
u, p = X.TrialFunction()
v, q = X.TestFunction()
space for solution data
gfu = GridFunction(X)
boundary condition
#uin = CoefficientFunction((U,0,0))
#gfu.components[0].Set(uin, definedon=mesh.Boundaries(“bot”))
cf = CoefficientFunction([(2) if bc==“left” else (0.2) if bc==“right” else 0 for bc in mesh.GetBoundaries()])
# Set BC
gfu.components[1].Set(cf, definedon=mesh.Boundaries(“left|right”))
nu = (eta/rho) # kinematic viscosity
SetNumThreads(24) #Anzahl der Kerne zum Parallelisieren
with TaskManager():
# right hand side of the equation
f = LinearForm(X)
f.Assemble()
# left hand side of the equation
stokes = nu*InnerProduct(grad(u), grad(v))+div(u)*q+div(v)*p - 1e-10*p*q
a = BilinearForm(X, symmetric=True)
a += stokes*dx
a.Assemble()
# calculate solution data
inv_stokes = a.mat.Inverse(X.FreeDofs(), inverse="sparsecholesky")
res = f.vec.CreateVector()
res.data = f.vec - a.mat*gfu.vec
gfu.vec.data += inv_stokes * res
# calculate drag force
res.data = a.mat*gfu.vec
F_drag_j = InnerProduct(res,gfu_help.vec) * rho
density free pressure → pressure
gfu.components[1].vec.data.FV().NumPy()[:] = gfu.components[1].vec.data.FV().NumPy() * rho
pressure solution field
pressure = gfu.components[1]
Define a coefficient function for val
Draw velocity
#Draw(Norm(gfu.components[0]), mesh, “velocity”,sd=3)
Draw((gfu.components[0]), mesh, “velocity”,sd=3) # Draw velocity
Draw the pressure
#Draw(pressure,mesh) # Draw pressure