# varying Dirichlet BC on curved boundary

Asked by Lyuda Vynnytska on 2013-03-01

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):

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:
2013-03-05
Last query:
2013-03-05
2013-03-05
 Jan Domurath (jan-domurath) said on 2013-03-05: #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()

Cheers,

Jan

 Lyuda Vynnytska (lyudav) said on 2013-03-05: #2

Jan, many thanks for finding this mistake!

 Lyuda Vynnytska (lyudav) said on 2013-03-05: #3

Thanks Jan Domurath, that solved my question.