A question about the offset in DofMap

Hello, I want to ask a question regarding the DofMap class

I used to work in the old version DOLFINx (v0.6.0), and now I just want to update my codes into v0.7.3,
my question is that, in the old version, the object “DofMap” has the function “list()” which returns to the dofmap data, as shown here

but the issue is that this function is replaced in the newest version, see

so now, I don’t know how could get the offset of the dofmap? For example, in the old version, if I want to create an AdjacenList base on a function space, I can easily do

dolfinx::graph::AdjacencyList<int> adjacencyList(V->dofmap()->list().array(), v>dofmap()->list().offsets());

But now, it doesn’t work anymore, since I can not really access the offset of the dofmap.

Also, I wonder that what is this “offset” function used for, does it just the record the number of dofs in each cell?


The change from 0.6.x to 0.7.x is that each dofmap has a fixed width, i.e. for each cell in the dofmap, there is a constant number of degrees of freedom.
This was actually the case for all DOLFINx codes prior to 0.7.x as well, but the optimization of representing it as a fixed width, 2 dimensional array was not exploited.

Assuming that you are working in C++, you can use

    const std::size_t width = list.extent(1);
    std::vector<std::int32_t> data(list.size());
    for (std::size_t i = 0; i < list.extent(0); ++i)
      for (std::size_t j = 0; j < list.extent(1); ++j)
        data[i * width + j] = list(i, j);
    std::vector<std::int32_t> offsets(list.extent(0) + 1);
    std::iota(offsets.begin(), offsets.end(), 0);
    std::for_each(offsets.begin(), offsets.end(),
                  [width](auto& idx) { idx *= width; });
    auto adj = dolfinx::graph::AdjacencyList(data, offsets);

1 Like