This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Surprising order of degrees of freedom with periodic boundary conditions in dolfin 1.5 - bug or expected behaviour?

+5 votes

The following code, which gives an order of degrees of freedom in the case of periodic boundary conditions, gives different results for dolfin 1.4 and dolfin 1.5, depending on the different value of parameters.reorder_serial_dofs=True/False.

import dolfin as df

df.parameters.reorder_dofs_serial = False

mesh = df.IntervalMesh(4, 1, 5)

class PeriodicBoundary(df.SubDomain):

    def inside(self, x, on_boundary):
        return bool(x[0] < 1+df.DOLFIN_EPS and x[0] > 1-df.DOLFIN_EPS and on_boundary)

    def map(self, x, y):
        y[0] = x[0] - 4.0

# Create periodic boundary condition                                            
pbc = PeriodicBoundary()

fspace = df.VectorFunctionSpace(mesh, 'CG', 1, 3, constrained_domain=pbc)

expression = df.Expression(['x[0]+0.1', 'x[0]+0.2', 'x[0]+0.3'])

f = df.interpolate(expression, fspace)

print f.vector().array()

On dolfin 1.4 with parameters.reorder_serial_dofs=True the order of degrees of freedom is:

[ 5.1 5.2 5.3 2.1 2.2 2.3 3.1 3.2 3.3 4.1 4.2 4.3]

where all vector components at a single node are grouped together, e.g. [mx1, my1, mz1, mx2, my2, mz2, mx3, my3, mz3, ….]. In this example, the first number is the mesh node and the second is the component of a three-dimensional vector field (for instance, 3.2 is the y components at mesh node 3 - my3). On the other hand, with parameters.reorder_serial_dofs=False, all values of a single vector component at all mesh nodes are grouped together like [mx1, mx2, mx3, … my1, my2, my3, … mz1, mz2, mz3, …]:

[ 5.1 2.1 3.1 4.1 5.2 2.2 3.2 4.2 5.3 2.3 3.3 4.3]

However, with dolfin 1.5, this order with parameters.reorder_serial_dofs=False is:

[5.1, 2.1, 5.2, 2.2, 5.3, 2.3, 3.1, 3.2, 3.3, 4.1, 4.2, 4.3]

which is a bit surprising. Is this the dolfin bug or within expected behaviour of dolfin 1.5?

asked Feb 4, 2015 by mb1a15 FEniCS Novice (260 points)

1 Answer

+1 vote

It is not a bug and you cannot make any assumptions about the ordering of dofs. Use dof_to_vertex_map or vertex_to_dof_map instead if you need to operate at this level.

answered Feb 5, 2015 by mikael-mortensen FEniCS Expert (29,340 points)
...