Global assembled matrix entries and dof numbering

Hello everyone,

I have assembled a 24x24 PETScMatrix from a cube, which has only eight nodes.

Is there a way that we can find the dof number of an entry in the global assembled matrix, M?

from fenics import *
from ufl import j
import numpy as np

mesh = BoxMesh(Point(0,0,0), Point(1, 1, 1), 1, 1, 1)

Ve = VectorElement("CG", mesh.ufl_cell(), 1)
Space = FunctionSpace(mesh, Ve)
delta_u = TestFunction(Space)
u = TrialFunction(Space)

M = PETScMatrix()
assemble(delta_u[j]*u[j]*dx , tensor = M)

What do you you mean by the dof number? It is defined by what row or column the entry is in.
You can easily extract either the dense matrix or a CSR matrix

So when I run the code below, the dof number and its coordinate is printed.

But, I am not sure if M’s rows and columns are indexed as in the same order as printed dof numbers.

dm = Space.dofmap()
for i in list(zip(dm.dofs() , Space.tabulate_dof_coordinates())):
    print(i)

Result of the above code:

(0, array([0., 0., 1.]))
(1, array([0., 0., 1.]))
(2, array([0., 0., 1.]))
(3, array([0., 0., 0.]))
(4, array([0., 0., 0.]))
(5, array([0., 0., 0.]))
(6, array([1., 1., 1.]))
(7, array([1., 1., 1.]))
(8, array([1., 1., 1.]))
(9, array([1., 0., 1.]))
(10, array([1., 0., 1.]))
(11, array([1., 0., 1.]))
(12, array([0., 1., 1.]))
(13, array([0., 1., 1.]))
(14, array([0., 1., 1.]))
(15, array([1., 0., 0.]))
(16, array([1., 0., 0.]))
(17, array([1., 0., 0.]))
(18, array([1., 1., 0.]))
(19, array([1., 1., 0.]))
(20, array([1., 1., 0.]))
(21, array([0., 1., 0.]))
(22, array([0., 1., 0.]))
(23, array([0., 1., 0.]))

The matrix had the same indexing as the dofmap.

Thanks a lot @dokken for the clarification.

Hello,

Above a vector field is described, and the three dofs per node correspond to the components of this vector. I suppose the ordering of the components are aligned with the ordering of associated spatial coordinates.

If we are solving for a mixed space, and say we have a vector field and a scalar field giving four dofs per node, how can we figure out the correct ordering of the dofs? Does the nodal dof numbering follow the construction of the mixed field?