Ordering of the stiffness matrix?

Hi all,

I am wanting to edit (possibly reordering and replacing some of the values) of the stiffness matrix to apply custom boundary conditions. However, I am unsure of how the stiffness matrix is constructed when calling the assemble() function. In particular, I am interested in the elements of the matrix that represent boundary nodes interacting with the neighboring boundary nodes. Any insight into the ordering of the stiffness matrix would be very appreciated! I have been following the demos pretty closely, so here’s what I have:

from dolfin import *

mesh = UnitSquareMesh(32, 32)
V = FunctionSpace(mesh, "CG", 1)

u = TrialFunction(V)
v = TestFunction(V)

a = dot(grad(u), grad(v))*dx

A = PETScMatrix()
assemble(a, tensor=A)

eigensolver = SLEPcEigenSolver(A)
eigensolver.solve()

r, c, rx, cx = eigensolver.get_eigenpair(0)

u = Function(V)
u.vector()[:] = rx

plot(u, interative=True)

You typically do not want to fiddle with out dolfin decides to order the rows in the matrix. A better alternative would be to locate the rows/cols which need to be changed to account for your custom procedure. See for instance How to find the coordinate where a vector function is max? - #2 by dokken , and several other posts in this forum is you search with the name of that function.

Hello,

Thank you for your reply! Locating the rows/columns which need to be changed does sound like a better approach - however, I am still unsure on how the matrix is ordered in dolfin… if I want to find an element of the matrix that corresponds to a specific dof, is there a nice way to do that?

in serial the row number is the dof number, so once you have determined the dof number you have all you need.
in parallel it’s slightly more complicated than that, but basically the statement remains true if you refer to the local numbering rather than the global one.

This is very insightful, thank you. If the rows correspond to the dof number, what do the columns correspond to?

The same, otherwise on the diagonal you would not have the entry at position (dof, dof) that anyone would expect. In other words, the ordering of the dofs is the test function and in the trial function is the same.

Thank you!

I have one more question. In your first response, you said that it is not recommended to mess around with how dolfin orders the rows/columns of the matrix. Why is that?

Because if you start changing them, usage of DOLFIN after changing them would mean that you need to reverse the change so that it fits into the DOLFIN dofmap structure.

Secondly, as DOLFIN can be executed can be executed in parallel, using MPI, data will be distributed across multiple processes, which makes manual modification non-trival.