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

Does repeated MeshFunction adaptation work properly in Dolfin 1.6?

+2 votes

Hi,

I have trouble with the following code

from dolfin import *
dolfin.parameters["refinement_algorithm"] = "plaza_with_parent_facets"

mesh = UnitSquareMesh(8,8)

mf = CellFunction("size_t", mesh)
for cell in cells(mesh):
  if cell.index() % 2 == 0:
    mf[cell.index()] = 1

plot(mf, interactive=True)

# Workaround for memory management issue with repeatedly adapted MeshFunctions
# (workaround from
#   https://bitbucket.org/fenics-project/dolfin/issues/319/faulty-memory-management-in-adapt
# involving custom adapt wrapper doesn't compile for me).
persistence = []

for i in range(2):
  cell_markers = CellFunction("bool", mesh, True)

  uniformly_refined_mesh = adapt(mesh, cell_markers)
  print
  print "Uniformly refined mesh (", i, "): "
  info(uniformly_refined_mesh)
  print

  persistence.append(mf)
  mf = adapt(mf, uniformly_refined_mesh)
  plot(mf, interactive=True)

  # OMITTED:
  # Use the MeshFunction mf on the uniformly_refined_mesh as input data for computing a solution
  # Project the solution to the coarse mesh, compute gradients, assemble cell_markers

  cell_markers = CellFunction("bool", mesh, False)
  for cell in cells(mesh):
    if cell.index() % 2 == 0:
      cell_markers[cell.index()] = True

  persistence.append(mesh)
  mesh = adapt(mesh, cell_markers)
  print
  print "Adapted mesh (", i, "): "
  info(mesh)
  print

  persistence.append(mf)
  mf = adapt(mf, mesh)
  plot(mf, interactive=True)

The second cell_markers in the loop seem to be ignored and the mesh is again refined uniformly. Moreover, the MeshFunction is not adapted to that new mesh correctly.

Changing adapt(mesh,...) to refine(mesh,...) produces different, but still wrong results.

I'm using Dolfin 1.5 under OSX 10.9.5. I'm hesitant to update to Dolfin 1.6 as I would also need to update OSX -- can someone please test if the code still behaves unexpectedly in the current version of Dolfin? If it does, I would then create a new issue in Bitbucket.

Thanks,

Milan

asked Jan 16, 2016 by mhanus FEniCS Novice (930 points)

You may need to cal object.clear_child() to unadapt it. Objects are not adapted if finer version object.child() is already present, and child is returned instead.

Check also https://bitbucket.org/fenics-project/dolfin/issues/319/faulty-memory-management-in-adapt for new workaround.

...