I have solved a simple problem on Openfoam, which is a 3D rectangular parallelopiped, filled with rectangular hexahedrons as mesh elements. The structured, mapped mesh was made in ICEM and solved in OF. But the mesh and data, are in unstructured format i.e. they are represented with connectivity. I now want to convert the unstructured data to a structured data w/o connectivity i.e. the mesh should be represented with loop like

  //access elements...

I have tried to write a code for the same, but have failed. A simple workaround involved involved sorting the array of elements, but that won't work for geometries like bifurcation and stuff. Is there a code available, or a software to import the OF mesh and spit out a structured mesh?

  • 1
    $\begingroup$ In general you are going to need a general 3D interpolation algorithm the simplest of which would be a nearest neighbor search. The basic idea would be to represent your previous grid as a point cloud. Python (numpy and scipy) can provide you something to do this. $\endgroup$ Oct 14, 2017 at 2:53

1 Answer 1


I think you can do it in a fairly straightforward way, as I do in PETSc. You find all the faces between cells, which gives you the mesh topology. To find the faces, you loop over cells and each of the 6 faces uses the hash for the 4 vertices (i,j,k,l) in sorted order. Then you just read out the hash table at the end. My code is here


Its a little longer because I first count everything so I can statically allocate the structure to hold it.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.