How can I integrate on a subdomain?


267
views
2
6 months ago by
Hi,

I am having difficulties trying to integrate over just a part of the domain. I have defined the following sub-domains
mesh = UnitCubeMesh(8, 8, 8)
V = VectorFunctionSpace(mesh, 'P', 1)

down =  CompiledSubDomain('near(x[2], side) && on_boundary', side = 0.0)
up = CompiledSubDomain('near(x[2], side) && on_boundary', side = 1.0)​

v  = TestFunction(V)            
u  = Function(V) 
T  = Constant((0.1,  0.0, 0.0))

and I want to integrate dot(T,u)*ds on the boundary except for 'down' and 'up'. Any help would be much appreciated.

Community: FEniCS Project

1 Answer


4
6 months ago by
Nate  
Give this a whirl:

from dolfin import *

mesh = UnitCubeMesh(8, 8, 8)
V = VectorFunctionSpace(mesh, 'P', 1)

down = CompiledSubDomain("near(x[2], side) && on_boundary", side=0.0)
up = CompiledSubDomain("near(x[2], side) && on_boundary", side=1.0)

v  = TestFunction(V)            
u  = Function(V) 
T  = Constant((0.1, 0.0, 0.0))

# Facet function, entity dimension 2 (facets) and initial values 0.
exterior = CompiledSubDomain("on_boundary")
facet_function = MeshFunction("size_t", mesh, 2, 0)

# Mark the whole exterior boundary with 2
exterior.mark(facet_function, 2)

# Mark up and down with 1
down.mark(facet_function, 1)
up.mark(facet_function, 1)

# Construct integration measure using these markers
ds = Measure("ds", subdomain_data=facet_function)

# Integrate on the exterior, excluding "up" and "down". 
# These are the facets labelled 2
functional_value = assemble(dot(u, T)*ds(2))

print(functional_value)​
Thank you so much. It helped.
written 6 months ago by Navid Mirzaei  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »