Extracting coordinates/dof indices without looping?


95
views
0
6 weeks ago by
medaka  

I'm extracting all dof indexes and corresponding coordinates with this loop over cells. For dense meshes it becomes a bottleneck and takes a lot of time, is there a way to extract all coordinates/dof indices at once (vectorized)?

element = V.element()
dofmap  = V.dofmap()
coords  = np.empty([0, 2], dtype="float64")
cinds   = np.empty([0, 6], dtype="int32")
for cell in cells(mesh):
    coords = np.vstack((coords, element.tabulate_dof_coordinates(cell)))
    cinds  = np.vstack((cinds, dofmap.cell_dofs(cell.index())))
Community: FEniCS Project
I suspecy you already know this, but just in case: there is a quick way to get all the DOF coordinates, as a vector ordered by their global indexes:

     lcoords = np.reshape(fs.tabulate_dof_coordinates(), (-1, dim))

Here fs is the relevant FunctionSpace. The problem with this is that it doesn't tell you which cell each DOF belongs to. I haven't been able to find any way to do that that doesn't involve an explicit loop over cells. You would think the DofMap would have some function that would list the cell index of every Dof, ordered by global DOF index. But if that function exists, I have not found it.
written 6 weeks ago by Leon Avery  
Interesting. fs.print_dofmap() seems to print out most of the lacking information: a table of all DOF indexes, with one cell to a row. You would think there would be a way to get that info as a numpy array without explicitly looping over all cells!
written 4 weeks ago by Leon Avery  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »