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

OK, can the same thing be done for cells

0 votes

In other words: Does

FunctionSpace(mesh,'CG',1).dofmap().cell_dofs(i)

exist in a version where i is an array of cell numbers?

asked Dec 3, 2013 by KristianE FEniCS Expert (12,900 points)

1 Answer

+1 vote
 
Best answer

No, but you can compile an extension module which does it for you:

from dolfin import *
import numpy as np

mesh = UnitSquareMesh(10,10)
V = FunctionSpace(mesh, "CG", 1)

code = """
void cell_dofs(boost::shared_ptr<GenericDofMap> dofmap,
               const std::vector<std::size_t>& cell_indices,
               std::vector<std::size_t>& dofs)
{
  assert(dofmap);
  std::size_t local_dof_size = dofmap->cell_dofs(0).size();
  const std::size_t size = cell_indices.size()*local_dof_size;
  dofs.resize(size);
  for (std::size_t i=0; i<cell_indices.size(); i++)
     for (std::size_t j=0; j<local_dof_size;j++)
         dofs[i*local_dof_size+j] = dofmap->cell_dofs(cell_indices[i])[j];
}
"""

module = compile_extension_module(code)
indices = np.array([4,6,8,9], dtype=np.uintp)
print module.cell_dofs(V.dofmap(), indices)
answered Dec 3, 2013 by johanhake FEniCS Expert (22,480 points)
selected Dec 3, 2013 by KristianE
...