The polymesh format used by OpenFOAM requires that for a polyhedron’s face, the points are listed in order definining the circumference of a face, and such that the normal (from the right hand rule) is to the cell with a higher index or outside of the domain. It has been inconvenient to construct and maintain the correct point ordering, so I have switched to doing it in post. It took a while to think of a good algorithm so I’m writing it down. This requires some level of ‘niceness’ to the face but that’s true of CFD in general too.

The first point in an unordered list can be used unchanged. A vector normal to the plane the points roughly lie on (faces can be skew) can be calculated with the cross product of the vectors between one point and any other two points. The rest of the points can be sorted by the angle from the first point to their projection into the normal plane.

For example, given 5 points indexed 0-4, the 0th point will not change. A normal vector to the plane can be calculated with 3-0 cross 3-2 or any other pair. The center of mass of the face is just the average coordinate of {0…4}. The points can be sorted by the angle from their projection into the plane to 0 through the center of mass.