varying Dirichlet BC on curved boundary

Asked by Lyuda Vynnytska

Hi,

I try to prescribe tangential velocity on the surface of the circle. The following representation invokes PETSC error:

u_bc=Expression(("0.001*sqrt(x[0]*x[0]+x[1]*x[1])/x[1]","-0.001*sqrt(x[0]*x[0]+x[1]*x[1])/x[0]"))
bc = DirichletBC(W.sub(0), u_bc, boun)

Is there any other possibility to implement such type of bc?

Thanks!

# ---------------------------------------------------------------------------------------------------
from dolfin import *

mesh = UnitCircleMesh(10)

V = VectorFunctionSpace(mesh,"CG",2)
P = FunctionSpace(mesh,"CG",1)
W = MixedFunctionSpace([V,P])

T = interpolate(Expression("x[0]*x[0] + x[1]*x[1]"),P)
g = Function(interpolate(Expression(("-x[0]/(sqrt(x[0]*x[0] +x[1]*x[1])+DOLFIN_EPS)", "-x[1]/(sqrt(x[0]*x[0] +x[1]*x[1])+DOLFIN_EPS)"), element=V.ufl_element()), V))
Ra = Constant(100.0)
eta = Constant(1.0)

def strain(v):
  return 0.5*(grad(v) + grad(v).T)

def boun(x, on_boundary):
    return on_boundary

u_bc=Expression(("0.001*sqrt(x[0]*x[0]+x[1]*x[1])/x[1]","-0.001*sqrt(x[0]*x[0]+x[1]*x[1])/x[0]"))
bc = DirichletBC(W.sub(0), u_bc, boun)

(u, p) = TrialFunctions(W)
(v, q) = TestFunctions(W)

F = (2.0*eta*inner(strain(u), strain(v))*dx + div(v)*p*dx + div(u)*q*dx + Ra*T*inner(g, v)*dx)

a = lhs(F)
L = rhs(F)
res = Function(W)
solve(a==L,res,[bc])

u_,p_ = split(res)
plot(u_,interactive=True)

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Jan Domurath
Solved:
Last query:
Last reply:
Revision history for this message
Best Jan Domurath (jan-domurath) said :
#1

Hello Lyuda,

I think your Expression for the tangent vector is upside down, it should be

u_bc=Expression((" 0.001 * x[1] / sqrt(x[0]*x[0]+x[1]*x[1])",
                 "-0.001 * x[0] / sqrt(x[0]*x[0]+x[1]*x[1])"))

Also, you should use

u_,p_ = res.split()

at the end of your program, see: https://answers.launchpad.net/dolfin/+question/207313

Cheers,

Jan

Revision history for this message
Lyuda Vynnytska (lyudav) said :
#2

Jan, many thanks for finding this mistake!

Revision history for this message
Lyuda Vynnytska (lyudav) said :
#3

Thanks Jan Domurath, that solved my question.