Extract velocity, pressure, and density data on lattices without interpolation
OpenLB – Open Source Lattice Boltzmann Code › Forums › on OpenLB › General Topics › Extract velocity, pressure, and density data on lattices without interpolation
- This topic has 9 replies, 2 voices, and was last updated 11 months, 3 weeks ago by achodankar.
-
AuthorPosts
-
August 10, 2021 at 6:34 pm #5911achodankarParticipant
Hello Developers,
I have been using two methods to extract the velocity values. In both the cases, the velocity values are interpolated from the lattices. Even the pvd file used in paraview will extract the interpolated values. I followed the same procedure for pressure and density. How do I obtain the actual lattice value only and not the interpolated values?-
Method 1
SuperLatticePhysVelocity2D<T, DESCRIPTOR> velocity_phys( sLattice, converter );
AnalyticalFfromSuperF2D<T> intpolateVelocity_phys( velocity_phys, true );
intpolateVelocity_phys( numerical_phys,point );-
Method 2
{
SuperLatticePhysVelocity2D<T,DESCRIPTOR> velocityF(sLattice, converter);
BlockReduction2D2D<T> velocityPlane(velocityF,200, BlockDataSyncMode::ReduceOnly);//12
cout<<“The no of points of nx are “<<velocityPlane.getBlockStructure().getNx()<<std::endl;
cout<<“The no of points of ny are “<<velocityPlane.getBlockStructure().getNy()<<std::endl;
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[1])
{
T vel[2] { };
velocityPlane(vel, latticeR);
myfile1 << latticeR[0] << “,” << latticeR[1] << “,”<< vel[0] << “,”<< vel[1] << std::endl;
}
}
myfile1.close();}
In the past, I was shown a method to extract the force values from each cell. Is there some similar method to extract the velocity, pressure, and density values?
Code snippet:
Cell<T,DESCRIPTOR> cell = sLattice.getBlockLattice(iC).get(iX,iY);
Vector<T,2> force = cell.template getField<descriptors::FORCE>();I would appreciate your help in this matter.
Thank you.
Yours sincerely,
Abhijeet C.
August 13, 2021 at 8:51 am #5916jjessbergerParticipantHello Abhijeet,
The functors SuperLatticePhysVelocity2D etc. do not interpolate any data. The interpolation happens when you convert them into analytical functors or when you use some BlockReduction. Also paraview interpolates in its visualization.
You may pass the lattice functors directly to the vtm writer, as it is done e.g. in poiseuille2d. Concerning paraview, you should take care that you watch your functor values precisely at mesh points and not in between. The “point” visualization style helps in doing so.Similarly to your code snippet for the force, you may also apply the computeU/ computeRho methods of the cell if you want to get the velocity at some specific cell.
Yours,
Julius J.August 13, 2021 at 6:29 pm #5919achodankarParticipantHello Julius,
Your feedback has been of great help to me. Thank you. Without using interpolation techniques(analytical functors & Blockreduction techniques), how I can store the velocity data from functors in a csv file. What would be the syntax for it? My coding background is weak for advanced C++ like functors. In the vtmwriter, I can view the results in Paraview, but for plotting my data, I would need the raw data in the form of csv files. I have been saving the data in csv files using interpolation methods in the past.
In regard to the cell method, how would the syntax be to extract the velocity/pressure/density values?(as you mentioned computeU and computeRho)?Thank you.
Your sincerely
Abhijeet C.
August 13, 2021 at 7:41 pm #5920jjessbergerParticipantWell I’m not an expert for file formats and csv, if it is not much data it is probably the easiest solution to use the c++ iostream functionalities for creating your csv file.
You may check out the computeU/ computeRho methods from the “Cell” class for velocity/ density. If you want to compute the pressure like that, you need to compute it “by hand” using c_s^2 * rho.
August 13, 2021 at 7:45 pm #5921achodankarParticipantHello Julius,
I can manage the csv file format. I don’t understand the part of how to extract the values from functors.From example:
After defining this statement,SuperLatticeVelocity2D<T, DESCRIPTOR> velocity_lat( sLattice);
Normally in arrays, I access the values using the index, but I am not aware how to go about it with functors. This has been a bottleneck issue for me presently.
Thank you.
Yours sincerely,
Abhijeet C.
August 13, 2021 at 7:51 pm #5922jjessbergerParticipantAfter defining the functor “SuperLatticeVelocity2D<T, DESCRIPTOR> velocity_lat( sLattice);”, you may call it via “velocity_lat(output, input)”, where output, input are appropriate arrays:
T[d] output gets the result; int[d] input contains the coordinates.
Cf. the chapter about functors in the user guide and the definition of SuperLatticeVelocity2D.operator()August 13, 2021 at 7:56 pm #5924achodankarParticipantHello Julius,
Thank you very much for your help. I will try it out.Thank you.
Yours sincerely,
Abhijeet C.
August 13, 2021 at 9:01 pm #5925achodankarParticipantHello Julius,
I tried this out, but I obtain zero values for velocity in all files. Also, the points passed out as input are lattice coordinates, Correct?{
int Ly = converter.getLatticeLength( ly );
int Lx = converter.getLatticeLength( lx );for (int iX=0; iX<Lx; iX++)
{ofstream mfile1;
mfile1.open(“v_nointerpolate_lat_”+ std::to_string(iX)+ “_”+ std::to_string(iT) + “.csv”);
mfile1 <<“x,” << “y_lattice,” << “U_lattice,”<< “y_phys,”<<“U_phys,”<<std::endl;T num_phys[Ly],num_lat[Ly];
int y[Ly],x[1];for ( int iY=0; iY<=Ly; ++iY )
{
int point[2];
point[0] = iX;
point[1] = iY;//Store Lattice Velocity (Numerical)
T numerical_lat[2];SuperLatticeVelocity2D<T, DESCRIPTOR> velocity_lat( sLattice);
velocity_lat( numerical_lat,point );
//Store Physical Velocity (Numerical and Analytical)
T numerical_phys[2];SuperLatticePhysVelocity2D<T, DESCRIPTOR> velocity_phys( sLattice, converter );
velocity_phys( numerical_phys,point );
//storing data
mfile1 << point[0] <<“,”<< point[1]<<“,” <<numerical_lat[0]<<“,”<<point[1]*converter.getConversionFactorLength()<<“,”<<numerical_phys[0]<<endl;
}
mfile1.close();}
August 16, 2021 at 9:08 am #5926jjessbergerParticipantHello Abhijeet,
input contains the cuboid number and then the lattice coordinates, so, effectively, it is an array of length 3. For technical reasons, output also needs to have length 3 (dimension+1).
If you want to get processable data (in contrast to debugging purposes), you also need communication on the block overlaps. Therefore, the usage of BlockReduction and physical functors is strongly recommended, because it executes these steps for you.
August 17, 2021 at 4:46 pm #5927achodankarParticipantHello Julius,
I followed your suggestion and the issue is fixed now.Thank you very much!!! You have been of great help.
Yours sincerely,
Abhijeet C.
-
AuthorPosts
- You must be logged in to reply to this topic.