From 4e8921427d4dd6717ff4ef262e7c04bbbd21a906 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Thu, 11 Oct 2018 21:12:22 +0200 Subject: Rename examples --- CMakeLists.txt | 12 ++-- cavity2d.cc | 90 ---------------------------- cavity2d_with_obstacles.cc | 115 ------------------------------------ lid_driven_cavity.cc | 90 ++++++++++++++++++++++++++++ lid_driven_cavity_with_obstacles.cc | 115 ++++++++++++++++++++++++++++++++++++ 5 files changed, 211 insertions(+), 211 deletions(-) delete mode 100644 cavity2d.cc delete mode 100644 cavity2d_with_obstacles.cc create mode 100644 lid_driven_cavity.cc create mode 100644 lid_driven_cavity_with_obstacles.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 29ad827..4248a32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,22 +27,22 @@ target_link_libraries( ) add_executable( - cavity2d - cavity2d.cc + lid_driven_cavity + lid_driven_cavity.cc ) target_link_libraries( - cavity2d + lid_driven_cavity boltzbub ) add_executable( - cavity2d_with_obstacles - cavity2d_with_obstacles.cc + lid_driven_cavity_with_obstacles + lid_driven_cavity_with_obstacles.cc src/box_obstacle.cc ) target_link_libraries( - cavity2d_with_obstacles + lid_driven_cavity_with_obstacles boltzbub ) diff --git a/cavity2d.cc b/cavity2d.cc deleted file mode 100644 index ca4b030..0000000 --- a/cavity2d.cc +++ /dev/null @@ -1,90 +0,0 @@ -#include -#include -#include -#include - -#include "lbm.h" -#include "boundary_conditions.h" - -constexpr std::size_t dimX = 100; -constexpr std::size_t dimY = dimX; - -constexpr double uLid = 0.4; -constexpr double reynolds = 1000; - -constexpr double tau = 3. * uLid * (dimX-1) / reynolds + 0.5; -constexpr double omega = 1. / tau; - -DataCellBuffer pop(dimX, dimY); -FluidBuffer fluid(dimX, dimY); - -void init() { - for ( std::size_t x = 0; x < dimX; ++x ) { - for ( std::size_t y = 0; y < dimY; ++y ) { - fluid.density(x,y) = 1.0; - fluid.velocity(x,y) = { 0.0, 0.0 }; - - static_cast(pop.curr(x,y)).equilibrize( - fluid.density(x,y), fluid.velocity(x,y)); - static_cast(pop.prev(x,y)).equilibrize( - fluid.density(x,y), fluid.velocity(x,y)); - } - } -} - -void computeLbmStep() { - pop.swap(); - - for ( std::size_t x = 0; x < dimX; ++x ) { - for ( std::size_t y = 0; y < dimY; ++y ) { - streamFluidCell(pop, x, y); - } - } - - // straight wall cell bounce back - for ( std::size_t x = 0; x < dimX; ++x ) { - computeZouHeVelocityWallCell(pop, {x, dimY-1}, { 0,-1}, uLid); - } - for ( std::size_t x = 1; x < dimX-1; ++x ) { - computeWallCell(pop, {x, 0}, { 0, 1}); - } - for ( std::size_t y = 1; y < dimY-1; ++y ) { - computeWallCell(pop, {0, y}, { 1, 0}); - computeWallCell(pop, {dimX-1, y}, {-1, 0}); - } - - // edge wall cell bounce back - computeWallCell(pop, {0, 0 }, { 1, 1}); - computeWallCell(pop, {dimX-1, 0 }, {-1, 1}); - - for ( std::size_t x = 0; x < dimX; ++x ) { - for ( std::size_t y = 0; y < dimY; ++y ) { - Cell& cell = static_cast(pop.curr(x,y)); - fluid.density(x,y) = cell.sum(); - fluid.velocity(x,y) = cell.velocity(fluid.density(x,y)); - - collideFluidCell(omega, pop, fluid, x, y); - } - } -} - -int main() { - init(); - - std::cout << "Re: " << reynolds << std::endl; - std::cout << "uLid: " << uLid << std::endl; - std::cout << "tau: " << tau << std::endl; - std::cout << "omega: " << omega << std::endl; - - for ( std::size_t t = 0; t <= 10000; ++t ) { - computeLbmStep(); - - if ( t % 100 == 0 ) { - std::cout << "."; - std::cout.flush(); - fluid.writeAsVTK("result/data_t" + std::to_string(t) + ".vtk"); - } - } - - std::cout << std::endl; -} diff --git a/cavity2d_with_obstacles.cc b/cavity2d_with_obstacles.cc deleted file mode 100644 index 092814e..0000000 --- a/cavity2d_with_obstacles.cc +++ /dev/null @@ -1,115 +0,0 @@ -#include -#include -#include -#include - -#include "lbm.h" -#include "boundary_conditions.h" -#include "box_obstacle.h" - -constexpr std::size_t dimX = 120; -constexpr std::size_t dimY = dimX; - -constexpr double uLid = 0.3; -constexpr double reynolds = 1000; - -constexpr double tau = 3 * uLid * (dimX-1) / reynolds + 0.5; -constexpr double omega = 1. / tau; - -DataCellBuffer pop(dimX, dimY); -FluidBuffer fluid(dimX, dimY); - -std::vector obstacles{ - {20, 20, 40, 40}, - {50, 20, 70, 40}, - {80, 20, 100, 40}, - {20, 50, 40, 70}, - {50, 50, 70, 70}, - {80, 50, 100, 70}, - {20, 80, 40, 100}, - {50, 80, 70, 100}, - {80, 80, 100, 100}, -}; - -void init() { - for ( std::size_t x = 0; x < dimX; ++x ) { - for ( std::size_t y = 0; y < dimY; ++y ) { - fluid.density(x,y) = 1.0; - fluid.velocity(x,y) = { 0.0, 0.0 }; - - static_cast(pop.curr(x,y)).equilibrize( - fluid.density(x,y), fluid.velocity(x,y)); - static_cast(pop.prev(x,y)).equilibrize( - fluid.density(x,y), fluid.velocity(x,y)); - } - } -} - -void computeLbmStep() { - pop.swap(); - - for ( std::size_t x = 0; x < dimX; ++x ) { - for ( std::size_t y = 0; y < dimY; ++y ) { - if ( std::all_of(obstacles.cbegin(), obstacles.cend(), [x, y](const auto& o) { - return !o.isInside(x, y); - }) ) { - streamFluidCell(pop, x, y); - } - } - } - - // straight wall cell bounce back - for ( std::size_t x = 0; x < dimX; ++x ) { - computeZouHeVelocityWallCell(pop, {x, dimY-1}, { 0,-1}, uLid); - } - for ( std::size_t x = 1; x < dimX-1; ++x ) { - computeWallCell(pop, {x, 0}, { 0, 1}); - } - for ( std::size_t y = 1; y < dimY-1; ++y ) { - computeWallCell(pop, {0, y}, { 1, 0}); - computeWallCell(pop, {dimX-1, y}, {-1, 0}); - } - - // edge wall cell bounce back - computeWallCell(pop, {0, 0 }, { 1, 1}); - computeWallCell(pop, {dimX-1, 0 }, {-1, 1}); - - // obstacles - for ( const auto& box : obstacles ) { - box.applyBoundary(pop); - } - - for ( std::size_t x = 0; x < dimX; ++x ) { - for ( std::size_t y = 0; y < dimY; ++y ) { - Cell& cell = static_cast(pop.curr(x,y)); - fluid.density(x,y) = cell.sum(); - fluid.velocity(x,y) = cell.velocity(fluid.density(x,y)); - - if ( std::all_of(obstacles.cbegin(), obstacles.cend(), [x, y](const auto& o) { - return !o.isInside(x, y); - }) ) { - collideFluidCell(omega, pop, fluid, x, y); - } - } - } -} - -int main() { - init(); - - std::cout << "Re: " << reynolds << std::endl; - std::cout << "uLid: " << uLid << std::endl; - std::cout << "tau: " << tau << std::endl; - - for ( std::size_t t = 0; t <= 6000; ++t ) { - computeLbmStep(); - - if ( t % 100 == 0 ) { - std::cout << "."; - std::cout.flush(); - fluid.writeAsVTK("result/data_t" + std::to_string(t) + ".vtk"); - } - } - - std::cout << std::endl; -} diff --git a/lid_driven_cavity.cc b/lid_driven_cavity.cc new file mode 100644 index 0000000..ca4b030 --- /dev/null +++ b/lid_driven_cavity.cc @@ -0,0 +1,90 @@ +#include +#include +#include +#include + +#include "lbm.h" +#include "boundary_conditions.h" + +constexpr std::size_t dimX = 100; +constexpr std::size_t dimY = dimX; + +constexpr double uLid = 0.4; +constexpr double reynolds = 1000; + +constexpr double tau = 3. * uLid * (dimX-1) / reynolds + 0.5; +constexpr double omega = 1. / tau; + +DataCellBuffer pop(dimX, dimY); +FluidBuffer fluid(dimX, dimY); + +void init() { + for ( std::size_t x = 0; x < dimX; ++x ) { + for ( std::size_t y = 0; y < dimY; ++y ) { + fluid.density(x,y) = 1.0; + fluid.velocity(x,y) = { 0.0, 0.0 }; + + static_cast(pop.curr(x,y)).equilibrize( + fluid.density(x,y), fluid.velocity(x,y)); + static_cast(pop.prev(x,y)).equilibrize( + fluid.density(x,y), fluid.velocity(x,y)); + } + } +} + +void computeLbmStep() { + pop.swap(); + + for ( std::size_t x = 0; x < dimX; ++x ) { + for ( std::size_t y = 0; y < dimY; ++y ) { + streamFluidCell(pop, x, y); + } + } + + // straight wall cell bounce back + for ( std::size_t x = 0; x < dimX; ++x ) { + computeZouHeVelocityWallCell(pop, {x, dimY-1}, { 0,-1}, uLid); + } + for ( std::size_t x = 1; x < dimX-1; ++x ) { + computeWallCell(pop, {x, 0}, { 0, 1}); + } + for ( std::size_t y = 1; y < dimY-1; ++y ) { + computeWallCell(pop, {0, y}, { 1, 0}); + computeWallCell(pop, {dimX-1, y}, {-1, 0}); + } + + // edge wall cell bounce back + computeWallCell(pop, {0, 0 }, { 1, 1}); + computeWallCell(pop, {dimX-1, 0 }, {-1, 1}); + + for ( std::size_t x = 0; x < dimX; ++x ) { + for ( std::size_t y = 0; y < dimY; ++y ) { + Cell& cell = static_cast(pop.curr(x,y)); + fluid.density(x,y) = cell.sum(); + fluid.velocity(x,y) = cell.velocity(fluid.density(x,y)); + + collideFluidCell(omega, pop, fluid, x, y); + } + } +} + +int main() { + init(); + + std::cout << "Re: " << reynolds << std::endl; + std::cout << "uLid: " << uLid << std::endl; + std::cout << "tau: " << tau << std::endl; + std::cout << "omega: " << omega << std::endl; + + for ( std::size_t t = 0; t <= 10000; ++t ) { + computeLbmStep(); + + if ( t % 100 == 0 ) { + std::cout << "."; + std::cout.flush(); + fluid.writeAsVTK("result/data_t" + std::to_string(t) + ".vtk"); + } + } + + std::cout << std::endl; +} diff --git a/lid_driven_cavity_with_obstacles.cc b/lid_driven_cavity_with_obstacles.cc new file mode 100644 index 0000000..092814e --- /dev/null +++ b/lid_driven_cavity_with_obstacles.cc @@ -0,0 +1,115 @@ +#include +#include +#include +#include + +#include "lbm.h" +#include "boundary_conditions.h" +#include "box_obstacle.h" + +constexpr std::size_t dimX = 120; +constexpr std::size_t dimY = dimX; + +constexpr double uLid = 0.3; +constexpr double reynolds = 1000; + +constexpr double tau = 3 * uLid * (dimX-1) / reynolds + 0.5; +constexpr double omega = 1. / tau; + +DataCellBuffer pop(dimX, dimY); +FluidBuffer fluid(dimX, dimY); + +std::vector obstacles{ + {20, 20, 40, 40}, + {50, 20, 70, 40}, + {80, 20, 100, 40}, + {20, 50, 40, 70}, + {50, 50, 70, 70}, + {80, 50, 100, 70}, + {20, 80, 40, 100}, + {50, 80, 70, 100}, + {80, 80, 100, 100}, +}; + +void init() { + for ( std::size_t x = 0; x < dimX; ++x ) { + for ( std::size_t y = 0; y < dimY; ++y ) { + fluid.density(x,y) = 1.0; + fluid.velocity(x,y) = { 0.0, 0.0 }; + + static_cast(pop.curr(x,y)).equilibrize( + fluid.density(x,y), fluid.velocity(x,y)); + static_cast(pop.prev(x,y)).equilibrize( + fluid.density(x,y), fluid.velocity(x,y)); + } + } +} + +void computeLbmStep() { + pop.swap(); + + for ( std::size_t x = 0; x < dimX; ++x ) { + for ( std::size_t y = 0; y < dimY; ++y ) { + if ( std::all_of(obstacles.cbegin(), obstacles.cend(), [x, y](const auto& o) { + return !o.isInside(x, y); + }) ) { + streamFluidCell(pop, x, y); + } + } + } + + // straight wall cell bounce back + for ( std::size_t x = 0; x < dimX; ++x ) { + computeZouHeVelocityWallCell(pop, {x, dimY-1}, { 0,-1}, uLid); + } + for ( std::size_t x = 1; x < dimX-1; ++x ) { + computeWallCell(pop, {x, 0}, { 0, 1}); + } + for ( std::size_t y = 1; y < dimY-1; ++y ) { + computeWallCell(pop, {0, y}, { 1, 0}); + computeWallCell(pop, {dimX-1, y}, {-1, 0}); + } + + // edge wall cell bounce back + computeWallCell(pop, {0, 0 }, { 1, 1}); + computeWallCell(pop, {dimX-1, 0 }, {-1, 1}); + + // obstacles + for ( const auto& box : obstacles ) { + box.applyBoundary(pop); + } + + for ( std::size_t x = 0; x < dimX; ++x ) { + for ( std::size_t y = 0; y < dimY; ++y ) { + Cell& cell = static_cast(pop.curr(x,y)); + fluid.density(x,y) = cell.sum(); + fluid.velocity(x,y) = cell.velocity(fluid.density(x,y)); + + if ( std::all_of(obstacles.cbegin(), obstacles.cend(), [x, y](const auto& o) { + return !o.isInside(x, y); + }) ) { + collideFluidCell(omega, pop, fluid, x, y); + } + } + } +} + +int main() { + init(); + + std::cout << "Re: " << reynolds << std::endl; + std::cout << "uLid: " << uLid << std::endl; + std::cout << "tau: " << tau << std::endl; + + for ( std::size_t t = 0; t <= 6000; ++t ) { + computeLbmStep(); + + if ( t % 100 == 0 ) { + std::cout << "."; + std::cout.flush(); + fluid.writeAsVTK("result/data_t" + std::to_string(t) + ".vtk"); + } + } + + std::cout << std::endl; +} -- cgit v1.2.3