Skip to content

Commit

Permalink
minor reorg
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahdhn committed Jan 29, 2024
1 parent f91f0f3 commit 0bbbe75
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 65 deletions.
6 changes: 4 additions & 2 deletions apps/lbmMultiRes/lbmMultiRes.cu
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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)",
Expand Down
64 changes: 4 additions & 60 deletions apps/lbmMultiRes/lbmMultiRes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, Q>(grid, depth, fout, cellType, vel, rho, slice, fileName, params.vtk && t != 0, psDrawable, psHex, psHexVert);
postProcess<T, Q>(grid, depth, fout, cellType, vel, rho, slice, fileName, params.vtk && t != 0, params.binary && t != 0, psDrawable, psHex, psHexVert);
#ifdef NEON_USE_POLYSCOPE
postProcessPolyscope<T>(psDrawable, vel, psColor, fileName, params.gui, t == 0);
#endif
Expand Down Expand Up @@ -486,20 +486,20 @@ 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) {
int precision = 4;
std::ostringstream suffix;
suffix << std::setw(precision) << std::setfill('0') << params.numIter;
std::string fileName = "Velocity_" + suffix.str();
postProcess<T, Q>(grid, depth, fout, cellType, vel, rho, slice, fileName, params.vtk, psDrawable, psHex, psHexVert);
postProcess<T, Q>(grid, depth, fout, cellType, vel, rho, slice, fileName, params.vtk, params.binary, psDrawable, psHex, psHexVert);
#ifdef NEON_USE_POLYSCOPE
postProcessPolyscope<T>(psDrawable, vel, psColor, fileName, params.gui, false);
#endif
} else if (verify) {
postProcess<T, Q>(grid, depth, fout, cellType, vel, rho, slice, "", false, psDrawable, psHex, psHexVert);
postProcess<T, Q>(grid, depth, fout, cellType, vel, rho, slice, "", false, false, psDrawable, psHex, psHexVert);
}

if (verify) {
Expand All @@ -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<float> ioBuffer(grid4D.x * grid4D.y * grid4D.z * grid4D.w);
float* ioBufferPtr = ioBuffer.data();

for (int l = 0; l < grid.getDescriptor().getDepth(); ++l) {

grid.newContainer<Neon::Execution::host>("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<int, float> 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");
}
}
62 changes: 59 additions & 3 deletions apps/lbmMultiRes/postProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void postProcess(Neon::domain::mGrid&
const Neon::int8_3d slice,
std::string fileName,
bool outputFile,
bool outoutFileBinary,
const std::vector<std::pair<Neon::domain::mGrid::Idx, int8_t>>& psDrawable,
const std::vector<std::array<int, 8>>& psHex,
const std::vector<Neon::float_3d>& psHexVert)
Expand All @@ -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];
Expand Down Expand Up @@ -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";

Expand All @@ -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<float> ioBuffer(grid4D.x * grid4D.y * grid4D.z * grid4D.w);
float* ioBufferPtr = ioBuffer.data();

for (int l = 0; l < grid.getDescriptor().getDepth(); ++l) {

grid.newContainer<Neon::Execution::host>("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<int, float> 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);
}
}
}


Expand Down

0 comments on commit 0bbbe75

Please sign in to comment.