Storing velocity data in csv file
OpenLB – Open Source Lattice Boltzmann Code › Forums › on OpenLB › General Topics › Storing velocity data in csv file
- This topic has 6 replies, 2 voices, and was last updated 3 years, 2 months ago by achodankar.
-
AuthorPosts
-
June 30, 2021 at 6:19 am #5765achodankarParticipant
Hello Developers,
I followed the steps from “Printing velocity data” post to save the data. I have modified the code to save in csv data format. I get a segmentation fault(core dumped) error after running the code for two time steps. The csv file generated for the two time steps have zero values. I would really appreciate any feedback on this issue.Here is the snippet of it:
{
SuperLatticePhysVelocity2D<T,DESCRIPTOR> velocityF(sLattice, converter);
BlockReduction2D2D<T> velocityPlane(velocityF, 600, BlockDataSyncMode::ReduceOnly);
ofstream myfile1;
myfile1.open(“velocity_”+ std::to_string(iT) + “.csv”);
myfile1 << “i,” << “j,” << “Ux,” <<“Uy”<< std::endl;
int latticeR[2] { };
for (latticeR[0]=0; latticeR[0] < velocityPlane.getBlockStructure().getNx(); ++latticeR[0])
{
for (latticeR[1]=0; latticeR[1] < velocityPlane.getBlockStructure().getNy(); ++latticeR[0])
{
T vel[2] { };
velocityPlane(vel, latticeR);
myfile1 << latticeR[0] << “,” << latticeR[1] << “,”<< vel[0] << “,”<< vel[1] << std::endl;
}
}
myfile1.close();}
Thank you.
Yours sincerely,
Abhijeet
July 1, 2021 at 10:36 am #5767AdrianKeymasterThe increment operation in the nested loop contains a typo, it should be
++latticeR[1]
.July 1, 2021 at 7:56 pm #5773achodankarParticipantHello Adrian,
Thank you. This fixes the problem. I missed on that bug. The velocity values are showing up to be zero for all time steps in the csv files. Is the above way the right way to extract the velocity values?Thank you.
Yours sincerely,
Abhijeet
July 1, 2021 at 8:32 pm #5774AdrianKeymasterWhen is the code snippet called? What are you simulating? Are the functor results correct? (Check using e.g. a debugger).
July 1, 2021 at 8:53 pm #5775achodankarParticipantI am running the dkt2d example. The simulation results are correct when I view it in Paraview and usin ppm images. here is the code snippet:
void getResults(SuperLattice2D<T, DESCRIPTOR>& sLattice,
UnitConverter<T,DESCRIPTOR> const& converter, int iT,
SuperGeometry2D<T>& superGeometry, Timer<double>& timer, SmoothIndicatorF2D<T,T,true> &particle1, SmoothIndicatorF2D<T,T,true> &particle2)
{
OstreamManager clout(std::cout, “getResults”);#ifdef WriteVTK
SuperVTMwriter2D<T> vtkWriter(“sedimentation”);
SuperLatticePhysVelocity2D<T, DESCRIPTOR> velocity(sLattice, converter);
SuperLatticePhysPressure2D<T, DESCRIPTOR> pressure(sLattice, converter);
SuperLatticePhysExternalPorosity2D<T, DESCRIPTOR> externalPor(sLattice, converter);
vtkWriter.addFunctor(velocity);
vtkWriter.addFunctor(pressure);
vtkWriter.addFunctor(externalPor);if (iT == 0) {
converter.write(“dkt”);
SuperLatticeGeometry2D<T, DESCRIPTOR> geometry(sLattice, superGeometry);
SuperLatticeCuboid2D<T, DESCRIPTOR> cuboid(sLattice);
SuperLatticeRank2D<T, DESCRIPTOR> rank(sLattice);
vtkWriter.write(geometry);
vtkWriter.write(cuboid);
vtkWriter.write(rank);
vtkWriter.createMasterFile();}
if (iT % converter.getLatticeTime(iTwrite) == 0) {
vtkWriter.write(iT);
}// Writes the vtk files
const int vtkIter = converter.getLatticeTime( .3 );
if ( iT%vtkIter == 0 && iT > 0 ) {
vtkWriter.write( iT );{
SuperEuklidNorm2D<T, DESCRIPTOR> normVel( velocity );
BlockReduction2D2D<T> planeReduction( normVel, 600, BlockDataSyncMode::ReduceOnly );
// write output as JPEG
heatmap::write(planeReduction, iT);}
//plot a gif of the simulation
{
SuperEuklidNorm2D<T,DESCRIPTOR> normVel( velocity );
BlockReduction2D2D<T> planeReduction( normVel );
//BlockReduction2D2D<T> planeReduction(normVel, sLattice);
BlockGifWriter<T> gifWriter;
//gifWriter.write(planeReduction, 0, 0.7, iT, “vel”); //static scale
gifWriter.write( planeReduction, iT, ” vel ” ); // scaled
//SuperEuklidNorm2D<T,DESCRIPTOR> press( pressure );
//BlockReduction2D2D<T> planeReduction( press );
//gifWriter.write( planeReduction, iT, ” press ” ); // scaled
}
{BlockGifWriter<T> gifWriter;
SuperEuklidNorm2D<T,DESCRIPTOR> press( pressure );
BlockReduction2D2D<T> planeReduction( press );
gifWriter.write( planeReduction, iT, ” press ” ); // scaled
}{
SuperLatticePhysVelocity2D<T,DESCRIPTOR> velocityF(sLattice, converter);
BlockReduction2D2D<T> velocityPlane(velocityF, 600, BlockDataSyncMode::ReduceOnly);
ofstream myfile1;
myfile1.open(“velocity_”+ std::to_string(iT) + “.csv”);
myfile1 << “i,” << “j,” << “Ux,” <<“Uy”<< std::endl;
int latticeR[2] { };
T vel[2] { };
velocityPlane(vel, latticeR);
for (latticeR[0]=0; latticeR[0] < velocityPlane.getBlockStructure().getNx(); ++latticeR[0])
{
for (latticeR[1]=0; latticeR[1] < velocityPlane.getBlockStructure().getNy(); ++latticeR[1])
{
//cout<<“Enter-“<<std::endl;
myfile1 << latticeR[0] << “,” << latticeR[1] << “,”<< vel[0] << “,”<< vel[1] << std::endl;
}
}
myfile1.close();}
}
#endif#ifdef WriteGnuPlot
if (iT % converter.getLatticeTime(iTwrite) == 0) {
if (singleton::mpi().getRank() == 0) {ofstream myfile;
myfile.open (gnuplotFilename.c_str(), ios::app);
myfile
<< converter.getPhysTime(iT) << ” ”
<< std::setprecision(9)
<< particle2.getPos()[1] << ” ”
<< particle1.getPos()[1] << ” ”
<< particle2.getPos()[0] << ” ”
<< particle1.getPos()[0] << endl;
myfile.close();
}
}
#endif/// Writes output on the console
if (iT % converter.getLatticeTime(iTwrite) == 0) {
timer.update(iT);
timer.printStep();
sLattice.getStatistics().print(iT, converter.getPhysTime(iT));
}return;
}July 1, 2021 at 8:57 pm #5776achodankarParticipantThe code snippet is called in the main function while timestepping:
for (std::size_t iT = 0; iT < converter.getLatticeTime(maxPhysT)+10; ++iT) {
particle.simulateTimestep(“verlet”);
getResults(sLattice, converter, iT, superGeometry, timer, circle1, circle2);
sLattice.collideAndStream();
superExt1.communicate();
superExt2.communicate();
superExt3.communicate();}
July 1, 2021 at 10:59 pm #5777achodankarParticipantHello Adrian,
The problem is resolved. I am getting the correct velocity values stored in it. While trying to fix the earlier problem, I put these code lines (T vel[2] { };velocityPlane(vel, latticeR);”) before the for loop. After placing it back in the for loop, it’s working fine. Everything is working now. Thank you very much for your prompt response.Yours sincerely,
Abhijeet
-
AuthorPosts
- You must be logged in to reply to this topic.