Skip to content

Printing velocity data

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #4850
    sthavishtha
    Participant

    Dear all

    I wish to print the velocity data into a data file for some analysis. For this purpose, can anyone suggest me how I could extract the velocity data in the context of a parallel/cavity2d.cpp code where slattice is defined as a SuperLattice2D<T, DESCRIPTOR>.

    In the context of sequential/cavity2d.cpp code where slattice is defined as BlockLatticeStructure2D<T,DESCRIPTOR>, something like the following code snippet should work (but not for the form of SuperLattice2D<T, DESCRIPTOR>) :

          ofstream myfile;
          myfile.open (velFilename.c_str(), ios::app);
    
          for ( int iX=0; iX <= resolx - 1; ++iX )
            for ( int iY=0; iY <= resoly - 1; ++iY )
            { 
              T velocity[2];
              sLattice.get(iX, iY).computeU( velocity );
              myfile
                << iX << " " << iY << " "
                << std::setprecision(9)
                << velocity[0] << " "
                << velocity[1] << endl;          
            }
    
          myfile.close();

    Thanks

    #4851
    Adrian
    Keymaster

    One straight forward way of extracting such data from a super lattice into a single block is to use BlockReduction2D2D.

    This is actually used in laminar/cavity2d/parallel and most other examples for extracting image data in getResults.

    Something along these lines should do what you want:

    
      SuperLatticePhysVelocity2D<T,DESCRIPTOR> velocity(sLattice, converter);
      BlockReduction2D2D<T> velocityPlane(velocityF, 600, BlockDataSyncMode::ReduceOnly);
      for (int iX=0; iX < velocityPlane.getNx(); ++iX) {
        for (int iY=0; iY < velocityPlane.getNy(); ++iY) {
          myfile << iX << " " << iY << " "
                 << std::setprecision(9)
                 << velocityPlane.get(iX,iY,0) << " "
                 << velocityPlane.get(iX,iY,1) << std::endl;  
        }
      }
    
    #4854
    sthavishtha
    Participant

    Dear Adrian

    Thanks for the reply. Unfortunately, this doesn’t work as get() is not a member of the class BlockReduction2D2D (see the error below).

    cavity2d.cpp:224:30: error: ‘class olb::BlockReduction2D2D<double>’ has no member named ‘get’
                 << velocityPlane.get(iX, iY, 0) << " "
                                  ^
    cavity2d.cpp:225:30: error: ‘class olb::BlockReduction2D2D<double>’ has no member named ‘get’
                 << velocityPlane.get(iX, iY, 1) << endl;   

    ^

    #4856
    Adrian
    Keymaster

    Indeed, I mistook BlockData2D for the functor BlockDataF2D when looking up the available methods for BlockReduction2D2D.

    You can use the operator:

    
    SuperLatticePhysVelocity2D<T,DESCRIPTOR> velocityF(sLattice, converter);
    BlockReduction2D2D<T> velocityPlane(velocityF, 600, BlockDataSyncMode::ReduceOnly);
    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);
        myfile << latticeR[0] << " " << latticeR[1] << " "
               << std::setprecision(9)
               << vel[0] << " "
               << vel[1] << std::endl;  
      }
    }
    
    #4861
    sthavishtha
    Participant

    Dear Adrian

    Perfect, that works. The question I have is : which member function is invoked when calling velocityPlane(vel, latticeR)? I ask so because, I don’t find any member function in blockReduction2D2D.h/blockReduction2D2D.hh which is of the format BlockReduction2D2D(T[], int[])?

    Additionally, for the case of 3D, wouldn’t it be just replacing BlockReduction2D2D with BlockReduction3D2D and proceeding as per your snippet itself?

    Thanks

    Regards
    Sthavishtha

    #4864
    Adrian
    Keymaster

    Functors such as BlockReduction2D2D are function objects, i.e. they implement C++’s function call operator operator().

    You can look up documentation for BlockReduction2D2D and any other of OpenLB’s classes using DoxyGen (Documentation -> Developer Guide in the navigation, I seem to be unable to post links here). There one can see that for this particular class the function call operator is inherited from the BlockDataF2D functor.

    Your guess at how your goal can be accomplished in 3D is correct. You can use BlockReduction3D2D to reduce a given super functor on arbitrary hyperplanes.

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