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

help with refering the measure of subdomain

+1 vote

I'm novice in FEniCS, need some help with below issue.
I create subdomain containing one middle point of the unit interval. So, I want to assemble the given function over that subdomain, but it seems to be not working correctly.

mesh = UnitIntervalMesh(10)
V = FunctionSpace(mesh, 'CG', 1)
boundary_parts = \
    MeshFunction('size_t', mesh, mesh.topology().dim() - 1)
left  = CompiledSubDomain('near(x[0], 0.)')
right = CompiledSubDomain('near(x[0], 1.)')
middle = CompiledSubDomain('near(x[0], 0.5)')
left.mark(boundary_parts, 0)
right.mark(boundary_parts, 1)
middle.mark(boundary_parts, 2)
ds = Measure('ds', domain = mesh, subdomain_data = boundary_parts)
f = interpolate(Expression('3*x[0]', degree = 1), V)
print assemble(f*ds(0))
print assemble(f*ds(1))
print assemble(f*ds(2))

My output is

0.0
3.0
0.0

The last line should be 1.5.

asked Feb 26, 2017 by Djulus.Ivanov FEniCS Novice (180 points)
edited Feb 26, 2017 by Djulus.Ivanov

1 Answer

+1 vote
 
Best answer

Hi!

Assemble over internal facets requires the use of dS (interior_facet) instead of ds (exterior_facet).
So if you add


dS = Measure('dS', domain = mesh, subdomain_data = boundary_parts)

and change the last line to:


print assemble(f*dS(2))

you get the right output

answered Feb 27, 2017 by meron FEniCS User (2,340 points)
selected Feb 27, 2017 by Djulus.Ivanov

Thanks, meron!
It's exactly what I wanted.

...