How to extract values in a surface of 3D mesh to another 2D mesh?

Thank you for viewing my question.
I’m trying to extract interpolated values in a surface of 3D mesh to another 2D mesh with same surface area, but I have no idea how to achieve this. Following is a simple example:

from dolfin import *

#define mesh
mesh1=UnitSquareMesh(10,10)
mesh2=UnitCubeMesh(10,10,10)

#define FunctionSpace
V1=FunctionSpace(mesh1,'CG',1)
V2=FunctionSpace(mesh2,'CG',1)

#define u1 and u2
u1=interpolate(Constant(0),V1)
u2_ex=Expression('x[0]+x[1]+x[2]',degree=1)
u2=interpolate(u2_ex,V2)

#define SubDomain
class Surface1(SubDomain):
    def inside(self, x, on_boundary):
        return x[0]<0.5 and x[1]<0.5  
class Surface2(SubDomain):
    def inside(self, x, on_boundary):
        return x[0]<0.5 and x[1]<0.5 and x[2]>1-DOLFIN_EPS
surface1=Surface1()
surface2=Surface2()

# next to do what to extract u2 values in the SubDomain surface2 of V2 to 
# u1 for the SubDomain surface1 of V1?

I would suggest having a look at: Project creates different results - #18 by dokken

Hi, dokken. Thanks for replying. But I’m still confused about extrating values in a certain facet after carefully reading the topic you suggested. Is there another typical example you can suggest for me? And also, where can I find the «parts of domain» you refered in that topic?

What I am suggesting is to use a restricted measure, i.e.

ds = Measure("ds", domain=mesh1, subdomain_data=meshfunction_2D, subdomain_id=surface_id)

see for instance: Poisson equation with multiple subdomains — DOLFIN documentation for more info regarding subdomains.
Then you can simply do a restricted projection.

u, v = TrialFunction(V1), TestFunction(V1)
a = inner(u, v)*ds
A = assemble(a)
l = inner(u2, v)*ds
b = assemble(b)
A.ident_zeros()
u_2D = Function(V1)
solve(A, u_2D.vector(), b)
2 Likes