Skip to content

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

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #5911
    achodankar
    Participant

    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.

    #5916
    jjessberger
    Participant

    Hello 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.

    #5919
    achodankar
    Participant

    Hello 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.

    #5920
    jjessberger
    Participant

    Well 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.

    #5921
    achodankar
    Participant

    Hello 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.

    #5922
    jjessberger
    Participant

    After 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()

    #5924
    achodankar
    Participant

    Hello Julius,
    Thank you very much for your help. I will try it out.

    Thank you.

    Yours sincerely,

    Abhijeet C.

    #5925
    achodankar
    Participant

    Hello 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();

    }

    #5926
    jjessberger
    Participant

    Hello 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.

    #5927
    achodankar
    Participant

    Hello 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.

    #7096
    syed
    Participant

    Hi @achodankar, I could output the density and the lattice point’s position using the density functor. But, I am having a problem with the input and output array. Things go fine if I don’t use parallelism but as I increase the ranks I do not get correct values for the output. Can you help me out? It seems that I am not providing correct input, as with more ranks the cuboid number becomes a member.

    #7101
    mathias
    Keymaster

    Check out paraview, there you can analyse the data easily.

    #7104
    syed
    Participant

    Dear Mathias, I initially used Paraview to visualize the data. But, to carry out analysis relevant to my project I need the raw data. I have my codes to extract results. And also I need ensemble averaging by running the code multiple times and gathering the data for statistical averaging.
    I used both ways to create output from the code. I used density functor and tried the () operator which worked fine serially but threw segmentation fault when I ran it parallel. Using block reduction, I got gibberish as I understand it is because of multiple ranks executing the Ofstream object I created.

    Can you please guide me regarding the most probable solutions? Is there any way I can extract and write metadata and the data corresponding to the metadata in a file with parallel implementation?

    #7107
    jjessberger
    Participant

    Dear Syed,

    first, please check that you’re using an appropriate instance of OstreamManager in order to write parallel output only once.

    The input array is expected to be of the form [iCuboid, iX, iY] (resp. [iCuboid, iX, iY, iZ] in three dimensions, cf. the functor chapter in the user guide). Then, a frequent source for segfaults is that the data on cuboid iCuboid are only available on the corresponding rank. Hence, you have to check for the rank before you access the data. Another possible error source is that the cuboids do not necessarily have the same size (-> possible index error).

    The available output options do all respect these typical issues and they all write the data in some csv form into text files (+ some additional information on the form of the data). Hence, if I were you, I would check whether the output in these formats can be fit to your context.
    Btw. what exactly do you mean be metadata?

    Yours,
    Julius

    #7109
    syed
    Participant

    Thank you Julius for your reply, and indeed I was looking for options available in OpenLB, like CSV class, to write the data.
    And with “metadata” I meant the lattice point’s positions over which the density is defined.
    I understand the segmentation fault would have been because of wrong indexing while using the functor.
    Do you think the writing data for each lattice point and the lattice point position itself could be possible using the writeData function of the CSV class?
    And I want to know where exactly the data is stored, like in what object?

Viewing 15 posts - 1 through 15 (of 16 total)
  • You must be logged in to reply to this topic.