Best way to connect domain data from xml file with mesh

Asked by Claas Abert

I'm using the Python interface of dolfin-dev. I created a mesh with several subdomains with Gmsh and converted it with dolfin-convert which gives me two file: mesh.xml and mesh_physical_region.xml.

How can I create a mesh object, where the subdomain data is included, so I can use dx(0),dx(1),... in my forms?
I tried something like

mesh = Mesh("mesh.xml")
domains = MeshFunction("uint", mesh, "mesh_physical_region.xml")
domain_collection = MeshValueCollection("uint", domains)
mesh.domains().init(3)
mesh.domains().markers(3).assign(collection)

But this does not work and seams to be pretty complicated.

Best regards, Claas

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Johan Hake
Solved:
Last query:
Last reply:
Revision history for this message
Best Johan Hake (johan-hake) said :
#1

On 12/14/2012 12:50 PM, Claas Abert wrote:
> New question #216788 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/216788
>
> I'm using the Python interface of dolfin-dev. I created a mesh with several subdomains with Gmsh and converted it with dolfin-convert which gives me two file: mesh.xml and mesh_physical_region.xml.
>
> How can I create a mesh object, where the subdomain data is included, so I can use dx(0),dx(1),... in my forms?
> I tried something like
>
> mesh = Mesh("mesh.xml")
> domains = MeshFunction("uint", mesh, "mesh_physical_region.xml")
> domain_collection = MeshValueCollection("uint", domains)
> mesh.domains().init(3)
> mesh.domains().markers(3).assign(collection)

Try:

 mesh = Mesh("mesh.xml")
 domains = MeshFunction("uint", mesh, "mesh_physical_region.xml")
 mesh.domains().init(3)
 mesh.domains().markers(3).assign(domains)

> But this does not work and seams to be pretty complicated.

Yes, working with mesh.domains() is fairly recently added and the syntax
is still not really worked out.

In stead of attaching the domain to the mesh you can also create a new
integral measure:

  dxx = dx[domains]

then use:

  dxx(0),dxx(1)

in your forms.

Johan

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

Thanks Johan for the quick reply,

the problem was the "uint". I got it working with "sizet" as MeshFunction type:

mesh = Mesh("mesh.xml")
domains = MeshFunction("sizet", mesh, "mesh_physical_region.xml")
mesh.domains().init(3)
mesh.domains().markers(3).assign(domains)

Best regards, Claas

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

Thanks Johan Hake, that solved my question.

Revision history for this message
Anders Logg (logg) said :
#4

On Fri, Dec 14, 2012 at 04:25:58PM -0000, Claas Abert wrote:
> Question #216788 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/216788
>
> Status: Answered => Solved
>
> Claas Abert confirmed that the question is solved:
> Thanks Johan for the quick reply,
>
> the problem was the "uint". I got it working with "sizet" as
> MeshFunction type:
>
> mesh = Mesh("mesh.xml")
> domains = MeshFunction("sizet", mesh, "mesh_physical_region.xml")
> mesh.domains().init(3)
> mesh.domains().markers(3).assign(domains)

Note that "sizet" has been changed to "size_t".

--
Anders