Skip to content

Reply To: Storing velocity data in csv file

#5775
achodankar
Participant

I 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;
}