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):
  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:
2013-03-05
Last query:
2013-03-05
Last reply:
2013-03-05
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

Lyuda Vynnytska (lyudav) said : #2

Jan, many thanks for finding this mistake!

Lyuda Vynnytska (lyudav) said : #3

Thanks Jan Domurath, that solved my question.