Printing velocity data
OpenLB – Open Source Lattice Boltzmann Code › Forums › on OpenLB › General Topics › Printing velocity data
- This topic has 5 replies, 2 voices, and was last updated 4 years, 6 months ago by Adrian.
-
AuthorPosts
-
March 18, 2020 at 6:41 pm #4850sthavishthaParticipant
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
March 18, 2020 at 9:15 pm #4851AdrianKeymasterOne 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 ingetResults
.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; } }
March 19, 2020 at 8:04 am #4854sthavishthaParticipantDear 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;
^
March 19, 2020 at 1:48 pm #4856AdrianKeymasterIndeed, I mistook
BlockData2D
for the functorBlockDataF2D
when looking up the available methods forBlockReduction2D2D
.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; } }
March 20, 2020 at 5:14 pm #4861sthavishthaParticipantDear 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 inblockReduction2D2D.h/blockReduction2D2D.hh
which is of the formatBlockReduction2D2D(T[], int[])
?Additionally, for the case of 3D, wouldn’t it be just replacing
BlockReduction2D2D
withBlockReduction3D2D
and proceeding as per your snippet itself?Thanks
Regards
SthavishthaMarch 20, 2020 at 6:34 pm #4864AdrianKeymasterFunctors such as
BlockReduction2D2D
are function objects, i.e. they implement C++’s function call operatoroperator()
.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 theBlockDataF2D
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. -
AuthorPosts
- You must be logged in to reply to this topic.