HOW TO EXTRACT data from computing?

I’ve downloaded the software package of OpenLB 0.4r3, and the code runs really good.
However, later when I want to EXTRACT the data from the program to have it analysed by tecplot, I inserted some code into the examples, i.e. the cavity2d.cpp. But I’ve met some problems (the compiler complains that operator<< cannot be found).
I’ve read the USER’S GUIDE, but I found the 7th part “Input / Output” is empty.

Could anyone tell me how could the data be extracted from the program, please?
And the code in function writeGifs in “cavity2d.cpp” I’ve rewritten is as follows: (where I comment with //Appended!!!)
void writeGifs(BlockLattice2D<double,D2Q9Descriptor>& lattice,
LBunits const& converter, int iter)
const int imSize = 600;
ofstream outdata(“outdata.dat”); //Appended!!!
DataAnalysisBase2D<double,D2Q9Descriptor> const& analysis = lattice.getDataAnalysis();

ImageWriter<double> imageWriter("leeloo");
imageWriter.writeScaledGif(createFileName("uz", iter, 6),
                           imSize, imSize );
outdata << analysis.getVelocityNorm() << endl;           //Appended!!!
outdata.close();                                                         //Appended!!!


I inserted this piece of code to get an asci file:

if (iT%converter.nStep(imSave)==0 && iT>0) {
            cout << "Saving Gif ..." << endl;
            writeGifs(lattice, converter, iT); ("exampleu.txt");
			for (bla=0; bla<128; ++bla) {
				T velocity[2];
				myfile << velocity[0] << endl;
				//myfile.write((char *)(&velocity[0]),sizeof(velocity[0]));
			myfile.close(); ("examplev.txt");
			for (bla=0; bla<128; ++bla) {
				T velocity[2];
				myfile << velocity[1] << endl;
				//myfile.write((char *)(&velocity[0]),sizeof(velocity[0]));

Not well written but it does the job. Good luck!

This code will do a great job in serial, but please note that it will not work in parallel (or only very slowly). You may want to have a look at the code posted in the following post, which works both for serial and parallel programs:,126

Thank you, Martin! It works, but can the filename changing with the computing?
I have asked Jonas the same question, he suggested me using the functiong saveData to obtain output data in a VTK file, which I’m still working on.In Mr. Latt’s solution, a function named createFileName is used,which can create files names to correspond to the iteration step,
e.g. saveData(analysis.getVelocityNorm(), createFileName(“velocity”, iter, 6) ).

However, when I changed the code you offered, i.e. I change (“exampleu.txt”) into (string createFileName(“vdata”, iter, 6) ),
the compiler complains that "ERROR: expected primary-expression before “createFileName”. If “string” before createFileName is removed,there is also a error.
Is there some METHOD to get a SERIAL ascii outdata files?

And if I’m going to obtain the streamline using the ascii outdata files, what is supposed to be done in the code? exampleu.txt and examplev.txt are seemed not to be suffient to create streamline of the field. I’m looking forward to any solution or suggestion!

PS: createFileName is in file imageWriter.h:

inline std::string createFileName(std::string name, int number, int width) {
//std::string createFileName(std::string name, int number, int width) {
std::stringstream fNameStream;
fNameStream << name << std::setfill(‘0’) << std::setw(width) << number;
return fNameStream.str();

Hi timolab,

Probably I’m mistaken, but function createFileName is not seen. Probably it’s good to have access from the class member - like:
ImageWriter X;…));

If that is the case of course,

Hi Alex,
I’ve tried your method, but maybe I haven’t got it right, the filename still cannot be created automatically:-(

I’ve finally solved the velocity extracting from the program.
And next, in order to save the pressure data, I inserted the following codes into the main function:
double pressure[1];
pressure = lattice.getDataAnalysis().getPressure();
However, the compiler complains that:
error: incompatible types in assignment of const olb::ScalarFieldBase2D’ to `double[2]’

So the return value’s type is not double, how could I save the pressure data whose type is ScalarFieldBase2D to a ascii file, Could anyone help me?

as you wrote the getPressure() method return a ScalarFieldBase2D. Therefore in order to get the pressure at a given point (say iX,iY) you have to use the get(iX,iY) method. This will return you a scalar of type T that you can save as said before.


Dear Orestis,
Thank you indeed! I’ve followed your suggestion, and it works:-)

1 Like

Hello Dear @timolab,

I am trying to extract pressure data from cavity3d example. Would you have any suggestion to approach this?

Any suggestion would be appreciated it.