Extract Function and Mesh of a subdomain

Asked by Claas Abert

Dear fenics team.

I have a Mesh and a MeshFunction defining some subdomains (I'm using the C++ API):

Mesh mesh("mesh.xml");
MeshFunction<unsigned int> subdomains(mesh, "domains.xml");

Then I'm solving some system:

SomeForm::FunctionSpace V(mesh);
Function u(V);
solve(A, *u.vector(), b);

What I'd like to do now is to extract a Mesh object of a specific subdomain and get the Function u on this extracted Mesh. Is this possible and if so how would I do that?

Thank you in advance, Claas

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Claas Abert
Solved:
Last query:
Last reply:
Revision history for this message
Anders Logg (logg) said :
#1

On Fri, Feb 03, 2012 at 05:50:47PM -0000, Claas Abert wrote:
> New question #186727 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/186727
>
> Dear fenics team.
>
> I have a Mesh and a MeshFunction defining some subdomains (I'm using the C++ API):
>
> Mesh mesh("mesh.xml");
> MeshFunction<unsigned int> subdomains(mesh, "domains.xml");
>
> Then I'm solving some system:
>
> SomeForm::FunctionSpace V(mesh);
> Function u(V);
> solve(A, *u.vector(), b);
>
> What I'd like to do now is to extract a Mesh object of a specific subdomain and get the Function u on this extracted Mesh. Is this possible and if so how would I do that?
>
> Thank you in advance, Claas

1. Extract the submesh:

  SubMesh sub_mesh(mesh, subdomains, <sub domain number>);

2. Define the sub function space:

  SomeForm::FunctionSpace sub_space(sub_mesh);

3. Project or interpolate u to a function defined on sub_space.

--
Anders

Revision history for this message
Claas Abert (cabert) said :
#2

Works perfectly. Thank you very much Anders Logg.