problems writng VTK output

Hi all,

I am trying to modify the multicomponent2d example in the palabos source files, so that instead of producing only .GIF images it produces a VTK output with the densities at each timestep. So I tried to include the following piece of code:

[code=“cpp”]
void writeVTK(MultiBlockLattice2D<T,DESCRIPTOR>& heavyFluid,
MultiBlockLattice2D<T,DESCRIPTOR>& lightFluid,
plint nx, plint ny, plint iter)
{

Array<T,15> Hprofile;
Array<T,15> Lprofile;
Array<T,15> Fprofile;
for (int iY=0; iY<15; ++iY){
    Box2D(0, 100*iY, nx-1, 100*iY) slice;
    Hprofile[iY]=computeAverageDensity(heavyFluid, slice);
    Lprofile[iY]=computeAverageDensity(lightFluid, slice);
    Fprofile[iY]=Lprofile[iY]+Hprofile[iY]
}
std::auto_ptr<ScalarField2D<T> > heavyDensity(computeDensity(heavyFluid,heavyFluid.getBoundingBox()));
std::auto_ptr<ScalarField2D<T> > lightDensity(computeDensity(lightFluid,lightFluid.getBoundingBox()));

VtkImageOutput2D<T> vtkOut(createFileName("vtk", iter, 6), 1);
vtkOut.writeData<1,T>(*heavyDensity, "Densityheavy",1.);
vtkOut.writeData<1,T>(*lightDensity, "Densitylight",1.);
vtkOut.writeData<15,T>(Hprofile, "DensityProfileHeavy", 1);
vtkOut.writeData<15,T>(Lprofile, "DensityProfileLight", 1);
vtkOut.writeData<15,T>(Fprofile, "DensityProfileTotal", 1);

}


With this code, I was trying to store in the VTK file not only the density of both fluids, but also an array with average densities calculated in 'slices' of fluid. I am not familiar with C++, so I'm getting several errors out of this. Chief among them, I get:

 cannot convert ‘heavyDensity.std::auto_ptr<_Tp>::operator*<plb::ScalarField2D<double> >()’ (type ‘std::auto_ptr<plb::ScalarField2D<double> >::element_type {aka plb::ScalarField2D<double>}’) to type ‘plb::TensorField2D<double, 1>&’

I understand what it is trying to say, but I don't know how to correct it. Can someone please help me?
Also, if instead I wanted to analyze this data (for instance the array created here) on MATLAB, how could I export it?

Hi Asususer,

  1. You have twisted the syntax for the use of the Box2D command. The correct way is

[code=“cpp”]
Box2D name (x0,x1,y0,y1) ;



2) There is semicolon missing in the last line of your for-loop

3) In this case, computeDensity requires a MultiScalarField2D

4) If you want to write a scalarfield into your vtk, you do not pass a template argument for the dimension (1 in your case), which is most likely the reason for the error you mentioned.

These are the errors I see so far. I do not really understand what you are trying to achieve with the profile variables. If we leave those out and correct the points mentioned above, the function works fine:

[code="cpp"]
void writeVTK(MultiBlockLattice2D<T,DESCRIPTOR>& heavyFluid,
              MultiBlockLattice2D<T,DESCRIPTOR>& lightFluid,
              plint nx, plint ny, plint iter) {
 
	std::auto_ptr<MultiScalarField2D<T> > heavyDensity(computeDensity(heavyFluid,heavyFluid.getBoundingBox()));
	std::auto_ptr<MultiScalarField2D<T> > lightDensity(computeDensity(lightFluid,lightFluid.getBoundingBox()));
 
	VtkImageOutput2D<T> vtkOut(createFileName("vtk", iter, 6), 1);
	vtkOut.writeData<T>(*heavyDensity, "Densityheavy",1.);
	vtkOut.writeData<T>(*lightDensity, "Densitylight",1.);
}

To your last question, you can stream data into a file using plb_ofstream and afterwards load this file in Matlab (see tutorial 4: http://www.palabos.org/documentation/tutorial/first-steps.html#tutorial-1-4-data-analysis ).

Even though this does not solve all your problems, I hope it helps.

Regards,

kk