copySerializedBlock problem [SOLVED]


I’am trying to copy the results of a successful 3D simulation using D3Q19 MRT model from the MultiBlockLattice3D structure to a simple one dimensional C array in the main MPI thread.

The concerned parts are in the next code fragment:

TensorField3D<T,3> localVelocity(nx, ny, nz);
copySerializedBlock(*computeVelocity(lattice), localVelocity, IndexOrdering::forward);

if(global::mpi().isMainProcessor()) {

    double *data = new double[nx*ny*nz*3];

    for(int i = 0; i < localVelocity.getNx(); i++) 
        for(int j = 0; j < localVelocity.getNy(); j++)
            for(int k = 0; k < localVelocity.getNz(); k++)
                int idx = (i*nx*nz+j*nz+k)*3;

                Array<T, 3> locVel = localVelocity.get(i, j, k);
                data[idx]   = locVel[0];
                data[idx+1] = locVel[1];
                data[idx+2] = locVel[2];


The “lattice” variable is a MultiBlockLattice3D structure consisting of 668 atomic blocks.
The code seems to work with one strange behaviour:
The coordinates above a certain Y value get mixed up. Just as if atomic blocks over that Y value would use different indexing (like the X-Z coordinates are switched).
If I’am outputting the data from computeVelocity() using the overloaded '<< ’ operator of pcout then it’s working fine.

One quick visualization of the problem(showing some of the wall cells):
Indexing problem

The cells above Y=0.8 are incorrect, as if they would be sliced off and rotated.
(var01 is the Y axis)

If you could suggest some solution other than using the pcout, or describe some other workaround that is sure to work, it would be great.

Thanks in advance,

Okay, it’s a bit embarrassing, but it was a quite simple indexing problem compared to the IndexOrdering::forward.
Actually it was just a typo. (Naturally I tried many things EXCEPT for the most obvious one).
The correct form is:

int idx = (i*ny*nz+j*nz+k)*3;

Sorry for the confusion,