### How to find the coordinates of the dofs of a cell given only an element type and the cell coordinates (i.e. without using a function space or a mesh)?

121

views

1

Given the coordinates of the vertices of a cell and a finite element type (e.g. continuous Lagrange, degree 3) I would need to find the cell dofs coordinates without defining a mesh or a function space (I only access the vertices of only one cell at a time and I cannot/do not want to store the whole mesh).

Basically, I want to do something like:

Basically, I want to do something like:

```
from dolfin import *
import numpy as np
editor = MeshEditor()
mesh = Mesh()
editor.open(mesh, "triangle", 2, 2)
editor.init_vertices(3)
editor.init_cells(1)
editor.add_vertex(0, np.array([0.,0.]))
editor.add_vertex(1, np.array([1.,0.]))
editor.add_vertex(2, np.array([0.,1.]))
editor.add_cell(0, np.arange(3).astype(np.uintp))
editor.close()
V = FunctionSpace(mesh, "CG", 3)
dof_coor = V.tabulate_dof_coordinates().reshape((-1,2))
cell_dofs = dof_coor[V.dofmap().cell_dofs(0),:]
```

without creating a mesh or a function space, given only the vertex coordinates (0,0), (0,1), (1,0) and the fact that I want the dofs of a P3 element. Is there an easy, efficient way to do this (apart from computing the dof coordinates myself), at least for continuous and discontinuous scalar Lagrange elements (of any degree)? Thanks a lot!

Community: FEniCS Project

### 1 Answer

6

You can create the FIAT element (e.g., using

Alternatively one can use code generated by

returns two integers which are pointers to instances of

`ffc.fiatinterface.create_element(ufl_element)`

) from which you can query coordinates on reference cell using FIAT's interface. For affine transformed cells (simplices) you get physical coordinates by affine transformation (matrix multiplication). For quads/hexes the transformation is tensor product.Alternatively one can use code generated by

`ffc.jit`

. For example`ffc.jit(ufl.FiniteElement("P", ufl.triangle, 2))`

returns two integers which are pointers to instances of

`ufc::finite_element`

and `ufc::dofmap`

. By some `ctypes`

trickery one should be able to get to generated `tabulate_dof_coordinates`

which does exactly what you want and its calls should within Numba loop, for example, would be fast. But that's quite tricky to make it working. (Moreover this functionality might be completely different in future FEniCS which will probably abandon UFC. That's why first FIAT solution should be preferable in most circumstances.)
1

I thought that you could get the

`nodes`

from instance of `FIAT.FiniteElement`

. That works for any element.

```
import ufl, ffc
import itertools
e = ufl.FiniteElement("RT", ufl.triangle, 2)
fe = ffc.fiatinterface.create_element(e)
nodes = list(itertools.chain(*(iter(node.get_point_dict().keys()) for node in fe.dual_basis())))
```

written
3 months ago by
Jan Blechta

Please login to add an answer/comment or follow this question.

Here is a simple testing routine using mshr:

This works for Lagrange elements of any degree apart from P0 (but the P0 case is straightforward).