diff --git a/apps/lbmMultiRes/lbmMultiRes.cu b/apps/lbmMultiRes/lbmMultiRes.cu index 66bd37f7..1f1681c5 100644 --- a/apps/lbmMultiRes/lbmMultiRes.cu +++ b/apps/lbmMultiRes/lbmMultiRes.cu @@ -1,7 +1,7 @@ #include "Neon/core/tools/clipp.h" -#define BGK -//#define KBC +//#define BGK +#define KBC #include "Neon/Neon.h" #include "Neon/Report.h" @@ -31,6 +31,7 @@ struct Params int sliceY = -1; int sliceZ = 1; bool vtk = false; + bool binary = false; bool gui = false; int scale = 2; std::string dataType = "float"; @@ -65,6 +66,7 @@ int main(int argc, char** argv) (clipp::option("--visual").set(params.benchmark, false) % "Run export partial data")), clipp::option("--vtk").set(params.vtk, true) % "Output VTK files. Active only with if 'visual' is true", + clipp::option("--binary").set(params.binary, true) % "Output binary (down-sampled) files. Active only with if 'visual' is true", clipp::option("--gui").set(params.gui, true) % "Show Polyscope gui. Active only with if 'visual' is true", clipp::option("--freq") & clipp::integers("freq", params.freq) % "Output frequency (only works with visual mode)", diff --git a/apps/lbmMultiRes/lbmMultiRes.h b/apps/lbmMultiRes/lbmMultiRes.h index 2b013d95..1143f422 100644 --- a/apps/lbmMultiRes/lbmMultiRes.h +++ b/apps/lbmMultiRes/lbmMultiRes.h @@ -369,7 +369,7 @@ void runNonUniformLBM(Neon::domain::mGrid& grid, suffix << std::setw(precision) << std::setfill('0') << t; std::string fileName = "Velocity_" + suffix.str(); - postProcess(grid, depth, fout, cellType, vel, rho, slice, fileName, params.vtk && t != 0, psDrawable, psHex, psHexVert); + postProcess(grid, depth, fout, cellType, vel, rho, slice, fileName, params.vtk && t != 0, params.binary && t != 0, psDrawable, psHex, psHexVert); #ifdef NEON_USE_POLYSCOPE postProcessPolyscope(psDrawable, vel, psColor, fileName, params.gui, t == 0); #endif @@ -486,7 +486,7 @@ void runNonUniformLBM(Neon::domain::mGrid& grid, report.addMember("ENumVoxels", gridDim.rMul()); //output - report.write("MultiResLBM_" + reportSuffix(), true); + //report.write("MultiResLBM_" + reportSuffix(), true); //post process if (!params.benchmark) { @@ -494,12 +494,12 @@ void runNonUniformLBM(Neon::domain::mGrid& grid, std::ostringstream suffix; suffix << std::setw(precision) << std::setfill('0') << params.numIter; std::string fileName = "Velocity_" + suffix.str(); - postProcess(grid, depth, fout, cellType, vel, rho, slice, fileName, params.vtk, psDrawable, psHex, psHexVert); + postProcess(grid, depth, fout, cellType, vel, rho, slice, fileName, params.vtk, params.binary, psDrawable, psHex, psHexVert); #ifdef NEON_USE_POLYSCOPE postProcessPolyscope(psDrawable, vel, psColor, fileName, params.gui, false); #endif } else if (verify) { - postProcess(grid, depth, fout, cellType, vel, rho, slice, "", false, psDrawable, psHex, psHexVert); + postProcess(grid, depth, fout, cellType, vel, rho, slice, "", false, false, psDrawable, psHex, psHexVert); } if (verify) { @@ -510,60 +510,4 @@ void runNonUniformLBM(Neon::domain::mGrid& grid, params.numIter, velocity.x); } - - if (!params.benchmark) { - NEON_INFO("Started Binary VTK"); - - //the level at which we will do the sampling - const int theLevel = depth - 1; - - const Neon::index_4d grid4D(gridDim.x / (1 << theLevel), gridDim.y / (1 << theLevel), gridDim.z / (1 << theLevel), 3); - std::vector ioBuffer(grid4D.x * grid4D.y * grid4D.z * grid4D.w); - float* ioBufferPtr = ioBuffer.data(); - - for (int l = 0; l < grid.getDescriptor().getDepth(); ++l) { - - grid.newContainer("Viz", l, [=](Neon::set::Loader& loader) { - auto& v = vel.load(loader, l, Neon::MultiResCompute::MAP); - - return [=](const typename Neon::domain::mGrid::Idx& cell) mutable { - if (!v.hasChildren(cell)) { - Neon::index_3d loc = v.getGlobalIndex(cell); - - if (loc.x % (1 << theLevel) != 0 || loc.y % (1 << theLevel) != 0 || loc.z % (1 << theLevel) != 0) { - return; - } - - loc.x /= (1 << theLevel); - loc.y /= (1 << theLevel); - loc.z /= (1 << theLevel); - - - for (int c = 0; c < 3; ++c) { - - const float val = v(cell, c); - - - Neon::index_4d loc4D(loc.x, loc.y, loc.z, c); - ioBufferPtr[loc4D.mPitch(grid4D)] = val; - } - } - }; - }) - .run(0); - } - - { - Neon::index_3d nodeDim(grid4D.x + 1, grid4D.y + 1, grid4D.z + 1); - Neon::IoToVTK io("BinVelocity", nodeDim, {1, 1, 1}, {0, 0, 0}, Neon::IoFileType::BINARY); - - io.addField([=](Neon::index_3d idx, int card) { - Neon::index_4d loc4D(idx.x, idx.y, idx.z, card); - return ioBufferPtr[loc4D.mPitch(grid4D)]; - }, - 3, "V", Neon::ioToVTKns::VtiDataType_e::voxel); - } - - NEON_INFO("Finished Binary VTK"); - } } diff --git a/apps/lbmMultiRes/postProcess.h b/apps/lbmMultiRes/postProcess.h index 2526141e..bf7a59e2 100644 --- a/apps/lbmMultiRes/postProcess.h +++ b/apps/lbmMultiRes/postProcess.h @@ -22,6 +22,7 @@ void postProcess(Neon::domain::mGrid& const Neon::int8_3d slice, std::string fileName, bool outputFile, + bool outoutFileBinary, const std::vector>& psDrawable, const std::vector>& psHex, const std::vector& psHexVert) @@ -41,7 +42,7 @@ void postProcess(Neon::domain::mGrid& return [=] NEON_CUDA_HOST_DEVICE(const typename Neon::domain::mGrid::Idx& cell) mutable { if (!pop.hasChildren(cell)) { - if (type(cell, 0) == CellType::bulk ) { + if (type(cell, 0) == CellType::bulk) { //fin T ins[Q]; @@ -144,10 +145,10 @@ void postProcess(Neon::domain::mGrid& for (size_t t = 0; t < psDrawable.size(); ++t) { const auto id = psDrawable[t].first; int level = psDrawable[t].second; - + for (int d = 0; d < 3; ++d) { T v = vel(id, d, level); - file << v << " "; + file << v << " "; } file << "\n"; @@ -161,6 +162,61 @@ void postProcess(Neon::domain::mGrid& file.close(); } + + if (outoutFileBinary) { + //the level at which we will do the sampling + const int depth = grid.getDescriptor().getDepth(); + const auto gridDim = grid.getDimension(); + const int theLevel = depth - 1; + + const Neon::index_4d grid4D(gridDim.x / (1 << theLevel), gridDim.y / (1 << theLevel), gridDim.z / (1 << theLevel), 3); + std::vector ioBuffer(grid4D.x * grid4D.y * grid4D.z * grid4D.w); + float* ioBufferPtr = ioBuffer.data(); + + for (int l = 0; l < grid.getDescriptor().getDepth(); ++l) { + + grid.newContainer("Viz", l, [=](Neon::set::Loader& loader) { + auto& v = vel.load(loader, l, Neon::MultiResCompute::MAP); + + return [=](const typename Neon::domain::mGrid::Idx& cell) mutable { + if (!v.hasChildren(cell)) { + Neon::index_3d loc = v.getGlobalIndex(cell); + + if (loc.x % (1 << theLevel) != 0 || loc.y % (1 << theLevel) != 0 || loc.z % (1 << theLevel) != 0) { + return; + } + + loc.x /= (1 << theLevel); + loc.y /= (1 << theLevel); + loc.z /= (1 << theLevel); + + + for (int c = 0; c < 3; ++c) { + + const float val = v(cell, c); + + + Neon::index_4d loc4D(loc.x, loc.y, loc.z, c); + ioBufferPtr[loc4D.mPitch(grid4D)] = val; + } + } + }; + }) + .run(0); + } + + { + Neon::index_3d nodeDim(grid4D.x + 1, grid4D.y + 1, grid4D.z + 1); + + Neon::IoToVTK io("Bin" + fileName, nodeDim, {1, 1, 1}, {0, 0, 0}, Neon::IoFileType::BINARY); + + io.addField([=](Neon::index_3d idx, int card) { + Neon::index_4d loc4D(idx.x, idx.y, idx.z, card); + return ioBufferPtr[loc4D.mPitch(grid4D)]; + }, + 3, "V", Neon::ioToVTKns::VtiDataType_e::voxel); + } + } }