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

how to update domain().markers(2) when refining mesh?

+1 vote

Hi All,
I have a mesh file (generated from vmtk) which, along with the mesh information, also contains the subdomain markers (i.e. inlet/outlet/surface of an Lshape pipe) inside the mesh file. However, when I refine the mesh, these markers are lost. Is there a way to update it for the new mesh and write this data to the new refined mesh file? I have tried the solution posted here but could not achieve this. I have also searched through Q&A but could not find exactly what I was looking for.

Below is a simple example using a small mesh I generated. Since I am not able to attach it here, I can email it to anyone interested. I output the subdomain information for original and refined mesh, and compute inlet and outlet areas for both.

from dolfin import *

mesh1=Mesh("./data/lshape_2.xml")
subdomain1=mesh1.domains().markers(2) #Boundary Markers in mesh
outputfile=File("markers1.xml")          
outputfile<<subdomain1                #File contains Markers

#Refine Mesh Uniformly
mesh2=refine(mesh1)                   #Refined mesh
subdomain2=mesh2.domains().markers(2) #Markers?
outputfile=File("markers2.xml")                 
outputfile<<subdomain2                #Empty file

#Compute Inlet and Outlet Areas for both meshes
#Facet Domains
fd1=mesh1.domains().facet_domains()
fd2=mesh2.domains().facet_domains()
#Areas
Area1=[assemble(Constant(1)*ds[fd1](i),mesh=mesh1) for i in range (3)] 
#Original Mesh: [30.96,3.02,3.03] ==> surface,inlet,outlet
Area2=[assemble(Constant(1)*ds[fd2](i),mesh=mesh2) for i in range (3)]
#Refined Mesh: [0,0,0]

Any help would be greatly appreciated :)

asked Jan 31, 2014 by owais.khan FEniCS Novice (130 points)

Did you try adapt_markers() ?

Hi MiroK,
Thank you very much for your response. I was not aware of "adapt_markers()". Since I am not a FEniCS expert, I tried to find an example online on how to use this function but could not find much. I found the following on the FEniCS website:

void adapt_markers(std::vector<std::pair<std::size_t, std::size_t>>& refined_markers, const Mesh& adapted_mesh, const std::vector<std::pair<std::size_t, std::size_t>>& markers, const Mesh& mesh)
Helper function for refinement of boundary conditions

I could not understand what this means. However, not knowing much, I tried the following:

mesh1=Mesh("lshape_2.xml")
mesh2=refine(mesh1)
fd1=mesh1.domains().facet_domains()
fd2=mesh2.domains().facet_domains()
adapt_markers(fd2,mesh2,fd1,mesh1)

And got the following error:

ValueError: invalid null reference in method 'adapt_markers', argument 1 of type 'std::vector< std::pair< std::size_t,std::size_t > > &'

If you have used this function before, could you please guide on how to use this function correctly?

Thanks a bunch in advance :)

Hi, sorry I spoke too soon - adapt_markers does not work with the kind of markers you are after. Based on the name, I thought it did.

2 Answers

0 votes

'refine' does not, by design, refine anything other than the mesh (not the domains for instance).

The free function 'adapt' is intended to however. Try instead

mesh2 = adapt(mesh1) 

Then all information associated with the mesh is supposed to be adapted as well. However, it might very well be that there is an issue here and that domains associated with a mesh are not adapted even if you use the above (I seem to remember a bug on this in the Launchpad days.) If that is the case, please report an issue with dolfin at Bitbucket.

You should be able to use adapt_markers directly (as you tried above) however.

answered Feb 3, 2014 by Marie E. Rognes FEniCS User (5,380 points)
...