postprocessing 3D fields in matlab

Hi!

One can write the data in VTK format out of the OpenLB but I did not find a matlab script that can read VTK format. I need matlab to do some postprocessing of the resulting 3D fields. Does any one know a solution to this issue? Thanks.

Best regards,
Marwan.

One thing you can do is save the data in pure text format instead of VTK. Here’s a routine which flushes the content of a lattice or a data field into a text file:


template<typename T>
void saveAsciiData(Serializable<T> const& object, std::string fName) {
    std :: ofstream* ostr = 0;
    if (singleton::mpi().isMainProcessor()) {
        ostr = new std :: ofstream(fName.c_str());
        OLB_PRECONDITION( *ostr );
    }
    DataSerializer<T> const& serializer = object.getSerializer(IndexOrdering::memorySaving);
    while (!serializer.isEmpty()) {
        int bufferSize;
        const T* dataBuffer = serializer.getNextDataBuffer(bufferSize);
        if (singleton::mpi().isMainProcessor()) {
            for (int iData=0; iData<bufferSize; ++iData) {
                *ostr << dataBuffer[iData] << endl;
            }
        }
    }
    delete ostr;
}

You can use it as follows:
saveAsciiData(lattice, “lattice.dat” ) ;

or as follows:
saveAsciiData(lattice.getDataAnalysis().getVelocityNorm(), “velocityNorm.dat” ) ;

Once in Matlab, I think that’s approximately what you need to do:


load velocityNorm.dat;
velocityNorm = reshape(velocityNorm, nz, ny, nx);

I don’t know of any interface which reads VTK data into Matlab. But I guess it would be easy to write one, using the VTK library and the Matlab native code support (“mex files” ).

Hope this helps.

I forgot to mention: the routine works for serial as well as for parallel program execution.