Cell node labeling

Hey there!
We know that in FEM mesh generating , the nodes of a triangular or quadrilateral element on 2D domains are labelled in a counter-clockwise manner , and nodes on a face of the tetrahedral element or on the quadrilateral base of the pyramid element are labelled following the right-hand grip rule pointing towards the apex, as shown in the figure below:

But the function cell=mesh.cells() only get the node labeling from low to high in each cell.
How can I get the cell node labeling array whose nodes are labelled in expected manner?
Any suggestions?

It would be great if you could supply a minimal code example that shows the input ordering of your mesh (i.e. the cell topology) and how the resulting cell topology looks like in dolfin.

dolfin re-orders the mesh when it is read in (The reasons for this is explained in this preprint).

You can avoid reodering by explicitly using the mesh editor, see minimal example below:

from dolfin import *
import numpy as np
outfile = File("mesh.pvd")

points = np.array([[0,0],[1,0],[0,1], [1,1]])
cells = np.array([[0,1,2],[1,3,2]], dtype=np.int32)

def create_mesh(order):
    # Initialize mesh and mesh editor for a 2D mesh of first order triangles
    mesh = Mesh(MPI.comm_world)
    editor = MeshEditor()
    editor.open(mesh, "triangle", gdim=2, tdim=2, degree=1)

    # Add vertices
    editor.init_vertices(points.shape[0]);
    for i, point in enumerate(points):
        editor.add_vertex(i, point)
    # Add cells
    editor.init_cells(cells.shape[0]);
    for i, cell in enumerate(cells):
        editor.add_cell(i, cell)
    # Finalize and possibly reorder mesh
    editor.close(order=order)

    # Print cell ordering
    print("-"*5, "Order:{0:b}".format(order), "-"*5 )
    print("Input")
    print(cells)
    
    print("In dolfin")
    print(mesh.cells())
    outfile << mesh

create_mesh(True)
create_mesh(False)

which generates the output:

----- Order:1 -----
Input
[[0 1 2]
 [1 3 2]]
In dolfin
[[0 1 2]
 [1 2 3]]
----- Order:0 -----
Input
[[0 1 2]
 [1 3 2]]
In dolfin
[[0 1 2]
 [1 3 2]]

Thanks for your kind reply. I just use the build-in mesh generate function and output the cells array like this:

from dolfin import *
import matplotlib.pyplot as plt
N=2
mesh = UnitSquareMesh(N, N, "left")
print("Plotting a UnitSquareMesh "+str(N))
plt.figure()
plot(mesh, title="UnitSquareMesh")
plt.show()
coor=mesh.coordinates()
cell=mesh.cells()

The coor array is exact what I want , but the node labels of the cell array are not labelled in a
counter-clockwise manner:

array([[0, 1, 3],
       [1, 3, 4],
       [1, 2, 4],
       [2, 4, 5],
       [3, 4, 6],
       [4, 6, 7],
       [4, 5, 7],
       [5, 7, 8]], dtype=uint32)

I wonder if there is a simple way to tackle the problem.

Why do you need the ordering to be counter-clockwise?

Note that such an ordering would not work for higher order elements (as explained in the preprint I linked to above). Therefore dolfin reorders nodes to cope with this. If you absolutely want to use an unordered mesh, you need to build it as shown above using MeshEditor.

Does the node label returned by mesh.cells corresponding to the order in the returns from mesh.coordinates? For example, refer to the last post, for the first cell, the node labels are 0, 1, and 3. Then does the first row of coor contains the coordinates for node 0, the second row of coor contains the coordinates for node 1, and the forth row for node 3?

Yes, that is correct