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

extract solution on a surface boundary from a volume discrete function and then assemble it

+1 vote

Hi,

I am new to Fenics, mqybe you can help me on this.

Let's assume we have a scalar field solution u = Function(V) calculated over mesh = UnitCubeMesh(4,4,4) and V = FunctionSpace(mesh, 'Lagrange', 1).
How can I extract the field solution in the plane x=0 (i.e one boundary of the domain)
What i want to do ultimately is to calculate the integral:

sum_ = assemble(u_extracteddx(mesh_extracted))
or
sum_ = assemble(u_extracted
dx)

with u_exracted the solution extracted on the plane x=0, dx the elements of this plane, and mesh_extracted the plane x=0

Any help would be appreciated!

Regards,

asked Sep 24, 2016 by fussegli FEniCS Novice (700 points)

1 Answer

+1 vote

Hi,
consider this:

from dolfin import *

# mesh and function space
mesh = BoxMesh(Point(0.0,0.0,0.0), Point(1.0,1.0,1.0), 5, 5, 5)
V = FunctionSpace(mesh, "CG", 1)

# Domain of interest (face of cube at plane x=0)
class CubeFace(SubDomain):
  def inside(self, x, on_boundary):
    return x[0] < DOLFIN_EPS and on_boundary

# Mark boundary
ff = FacetFunction("size_t", mesh)
CubeFace().mark(ff, 1)

# Define measure
ds = Measure("ds")[ff]

# Integrating over the face of the cube
u = interpolate(Expression("exp(x[0]*x[1]*x[2])"), V)
a = assemble(u*ds(1))
print "assembled integral: ", a
answered Sep 25, 2016 by hernan_mella FEniCS Expert (19,460 points)

If you want to extract the boundary mesh and the solution at the plane take a look to the documentation of SubMesh, BoundaryMesh and this question in the forum.

Thanks you, it works perfectly.

...