[firedrake] Accessing adjacency matrix of graph of given mesh

David Ham David.Ham at imperial.ac.uk
Thu Nov 5 14:42:54 GMT 2015


Hi George,

There are some simple answers which might help if the problems you wish to
solve are relatively small. If your problems are large enough that looping
over the mesh in Python is too slow, or if you plan to run in MPI parallel
then this will be somewhat more complex.

Firedrake does not explicitly store the vertex-vertex adjacency
relationship because it's not needed for any of the common finite element
computations. What is readily available is the cell to node adjacency list.
For the FunctionSpace CG1, the nodes correspond to the vertices. This
adjacency is available as a Numpy array in V.cell_node_list (it's also
available as a PyOP2 Map as V.cell_node_map() but that's probably not what
you currently want). If you really want the vertex-vertex adjacency, then
it's pretty easy to derive from  V.cell_node_list.

If you need to do this at a scale where performance is really important,
then adjacency relationships can be derived using the underlying PETSc
DMPlex, but this is a much more involved process.

In parallel, the cell_node_list will contain indices in the local numbering
of the current process. This is probably what you want, but it is useful to
be aware that this happens.

Regards,

David

On Thu, 5 Nov 2015 at 13:28 George Ovchinnikov <lives9 at gmail.com> wrote:

> Dear all,
>
> I have a mesh, say
>
> mesh = UnitSquareMesh(size, size)
>
> and a function interpolated on this mesh:
>
> V = FunctionSpace(mesh, "CG", 1)
> w = Function(V)
> w.interpolate(Expression("1"))
>
> Considering the graph corresponding to the mesh, I want to think about
> function w as a function on this graph's vertices and work with the
> graph with weighted vertices. But I cannot find any convenient graph's
> representation like adjacency matrix. The best I could do it to access
> vertices coordinates:
>
> mesh.coordinates.vector().array().reshape((-1, 2))
>
> and probably rebuild a adjacency matrix from it, but this seems like a
> very bad way of doing this. Is there a better way to get mesh's
> adjacency matrix?
>
> I would like to be able to do conversion both ways:
> get adjacency matrix corresponding to the mesh and form k-th element of
>
> w.vector().array()
>
> get vertex index in this adjacency matrix and vice verse from
> i-th vertex of mesh's graph adjacency matrix get corresponding index for
> w.vector().array()
>
> Sincerely,
> George
>
> _______________________________________________
> firedrake mailing list
> firedrake at imperial.ac.uk
> https://mailman.ic.ac.uk/mailman/listinfo/firedrake
>
-------------- next part --------------
HTML attachment scrubbed and removed


More information about the firedrake mailing list