### Extracting coordinates/dof indices without looping?

95

views

0

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

`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.

`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.