This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

plot Nuss over circle boundary

–1 vote

Hi,
How to extract and plot over the subdomain boundary

from dolfin import*
from mshr import *

# Create mesh 
H =  0.41
Lstart = -0.2
Lend = 2.0
rc= Rectangle(Point(Lstart, 0.0), Point(Lend, 0.41))
c = Circle(Point(0.2,0.25), 0.1)
geometry = rc-c
mesh = generate_mesh(geometry, 10)

#def Function Spaces
V = VectorFunctionSpace(mesh, "CG", 2)
Q = FunctionSpace(mesh, "CG", 1)
W = V*Q

#def Boundary
class NoSlipDomain(SubDomain):
    def inside(self, x, on_boundary):
        return (near(x[1],0) or near(x[1],H) 
        or on_boundary and not inflow_boundary(x) and not outflow_boundary(x))

def inflow_boundary(x):
    return near(x[0],Lstart)

def outflow_boundary(x):
    return near(x[0],Lend)

noslip_boundary= NoSlipDomain()

#def Boundary condition
bc0 = DirichletBC(W.sub(0), (0.0,0.0), noslip_boundary)
inflow = Expression(("-sin(x[1]*pi)", "0.0"))
bc1 = DirichletBC(W.sub(0), inflow, inflow_boundary)
outflow = Constant(0.0)
bc2 = DirichletBC(W.sub(1), outflow, outflow_boundary )
bcs = [bc0, bc1, bc2]

#def variational forms
(u, p) = TrialFunctions(W)
(v, q) = TestFunctions(W)
f = Constant((0.0,0.0))
a = inner(grad(u), grad(v))*dx
L = inner(f,v)*dx
w = Function(W)

#solve problem
solve(a == L, w, bcs)
(u,p) = w.split(True)

#mesh function for circle boundary
boundary_parts = MeshFunction("size_t", mesh, mesh.topology().dim()-1)

Circle = AutoSubDomain(lambda x, on_boundary: on_boundary and not
                       (near(x[0], Lstart) or near(x[0], Lend) or near(x[1], 0.0) or near(x[1], H)))

Cirlce.mark(boundary_parts, 0)

n = FacetNormal(mesh)

#Projection of u to du/dn

du_n = TrialFunction(V)
phi = TestFunction(V)

#desired Function: du_n, integration only on surface of circle
a_n = inner(du_n, phi)*ds(0)

#gradient of velocity_field u  with normal vector field n
L_n = inner(dot(nabla_grad(u), n), phi)*ds(0)
Nuss = Function(V)
solve(a_n == L_n, Nuss)

Thank you
palraj

asked Dec 29, 2014 by palraj j FEniCS Novice (190 points)
edited Dec 29, 2014 by palraj j
...