From 5e888fc13f38c94777963d72fc9e391cd4fa477a Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Wed, 30 Jan 2019 20:12:31 +0100 Subject: Manage dynamics, boundary condition memory in Grid2D Mainly to further declutter simulation and refinement setup --- apps/adrian/cylinder2d/cylinder2d.cpp | 51 +++++++++---------------------- apps/adrian/poiseuille2d/poiseuille2d.cpp | 31 ++++++++----------- src/refinement/grid2D.h | 6 ++++ src/refinement/grid2D.hh | 17 +++++++++++ 4 files changed, 49 insertions(+), 56 deletions(-) diff --git a/apps/adrian/cylinder2d/cylinder2d.cpp b/apps/adrian/cylinder2d/cylinder2d.cpp index bf25417..0893928 100644 --- a/apps/adrian/cylinder2d/cylinder2d.cpp +++ b/apps/adrian/cylinder2d/cylinder2d.cpp @@ -108,9 +108,7 @@ void disableRefinedArea(Grid2D& coarseGrid, sGeometry.rename(5,0,*refinedOverlap); } -void prepareLattice(Grid2D& grid, - Dynamics& bulkDynamics, - sOnLatticeBoundaryCondition2D& sBoundaryCondition) +void prepareLattice(Grid2D& grid) { OstreamManager clout(std::cout,"prepareLattice"); clout << "Prepare lattice ..." << std::endl; @@ -119,6 +117,15 @@ void prepareLattice(Grid2D& grid, auto& sGeometry = grid.getSuperGeometry(); auto& sLattice = grid.getSuperLattice(); + Dynamics& bulkDynamics = grid.addDynamics( + std::unique_ptr>( + new BGKdynamics( + grid.getConverter().getLatticeRelaxationFrequency(), + instances::getBulkMomenta()))); + + sOnLatticeBoundaryCondition2D& sBoundaryCondition = grid.getOnLatticeBoundaryCondition(); + createLocalBoundaryCondition2D(sBoundaryCondition); + const T omega = converter.getLatticeRelaxationFrequency(); sLattice.defineDynamics(sGeometry, 0, &instances::getNoDynamics()); @@ -212,13 +219,6 @@ int main(int argc, char* argv[]) Grid2D coarseGrid(coarseCuboid, N, LatticeVelocity(uLat), Re); prepareGeometry(coarseGrid); - BGKdynamics coarseBulkDynamics( - coarseGrid.getConverter().getLatticeRelaxationFrequency(), - instances::getBulkMomenta()); - - sOnLatticeBoundaryCondition2D coarseBoundaryCondition(coarseGrid.getSuperLattice()); - createLocalBoundaryCondition2D(coarseBoundaryCondition); - const auto coarseDeltaX = coarseGrid.getConverter().getPhysDeltaX(); const Vector fineExtend {8*cylinderD, ly-2*coarseDeltaX}; @@ -251,22 +251,6 @@ int main(int argc, char* argv[]) disableRefinedArea(coarseGrid, fineGrid); - BGKdynamics fineBulkDynamics( - fineGrid.getConverter().getLatticeRelaxationFrequency(), - instances::getBulkMomenta()); - - sOnLatticeBoundaryCondition2D fineBoundaryCondition(fineGrid.getSuperLattice()); - createLocalBoundaryCondition2D(fineBoundaryCondition); - - BGKdynamics fineOutflowBulkDynamics( - fineOutflowGrid.getConverter().getLatticeRelaxationFrequency(), - instances::getBulkMomenta()); - - sOnLatticeBoundaryCondition2D fineOutflowBoundaryCondition(fineOutflowGrid.getSuperLattice()); - createLocalBoundaryCondition2D(fineOutflowBoundaryCondition); - - prepareLattice(coarseGrid, coarseBulkDynamics, coarseBoundaryCondition); - const Vector fineExtend2 {4*cylinderD, 2*cylinderD}; const Vector fineOrigin2 {1*cylinderD, 2*cylinderD-fineExtend2[1]/2}; @@ -275,17 +259,10 @@ int main(int argc, char* argv[]) disableRefinedArea(fineGrid, fineGrid2); - BGKdynamics fineBulkDynamics2( - fineGrid2.getConverter().getLatticeRelaxationFrequency(), - instances::getBulkMomenta()); - - sOnLatticeBoundaryCondition2D fineBoundaryCondition2(fineGrid2.getSuperLattice()); - createLocalBoundaryCondition2D(fineBoundaryCondition2); - - prepareLattice(fineGrid, fineBulkDynamics, fineBoundaryCondition); - prepareLattice(fineOutflowGrid, fineOutflowBulkDynamics, fineOutflowBoundaryCondition); - - prepareLattice(fineGrid2, fineBulkDynamics2, fineBoundaryCondition2); + prepareLattice(coarseGrid); + prepareLattice(fineGrid); + prepareLattice(fineOutflowGrid); + prepareLattice(fineGrid2); clout << "Starting simulation..." << endl; Timer timer( diff --git a/apps/adrian/poiseuille2d/poiseuille2d.cpp b/apps/adrian/poiseuille2d/poiseuille2d.cpp index 034fb08..4091905 100644 --- a/apps/adrian/poiseuille2d/poiseuille2d.cpp +++ b/apps/adrian/poiseuille2d/poiseuille2d.cpp @@ -90,9 +90,7 @@ void prepareGeometry(Grid2D& grid) clout << "Prepare Geometry ... OK" << std::endl; } -void prepareLattice(Grid2D& grid, - Dynamics& bulkDynamics, - sOnLatticeBoundaryCondition2D& sBoundaryCondition) +void prepareLattice(Grid2D& grid) { OstreamManager clout(std::cout,"prepareLattice"); clout << "Prepare lattice ..." << std::endl; @@ -101,6 +99,15 @@ void prepareLattice(Grid2D& grid, auto& sGeometry = grid.getSuperGeometry(); auto& sLattice = grid.getSuperLattice(); + Dynamics& bulkDynamics = grid.addDynamics( + std::unique_ptr>( + new BGKdynamics( + grid.getConverter().getLatticeRelaxationFrequency(), + instances::getBulkMomenta()))); + + sOnLatticeBoundaryCondition2D& sBoundaryCondition = grid.getOnLatticeBoundaryCondition(); + createInterpBoundaryCondition2D(sBoundaryCondition); + const T omega = converter.getLatticeRelaxationFrequency(); sLattice.defineDynamics(sGeometry, 0, &instances::getNoDynamics()); @@ -237,23 +244,9 @@ int main(int argc, char* argv[]) prepareGeometry(fineGrid); - BGKdynamics coarseBulkDynamics( - coarseGrid.getConverter().getLatticeRelaxationFrequency(), - instances::getBulkMomenta()); - - sOnLatticeBoundaryCondition2D coarseSBoundaryCondition(coarseGrid.getSuperLattice()); - createInterpBoundaryCondition2D(coarseSBoundaryCondition); - - prepareLattice(coarseGrid, coarseBulkDynamics, coarseSBoundaryCondition); - - BGKdynamics fineBulkDynamics( - fineGrid.getConverter().getLatticeRelaxationFrequency(), - instances::getBulkMomenta()); - - sOnLatticeBoundaryCondition2D fineSBoundaryCondition(fineGrid.getSuperLattice()); - createInterpBoundaryCondition2D(fineSBoundaryCondition); + prepareLattice(coarseGrid); - prepareLattice(fineGrid, fineBulkDynamics, fineSBoundaryCondition); + prepareLattice(fineGrid); clout << "starting simulation..." << endl; Timer timer( diff --git a/src/refinement/grid2D.h b/src/refinement/grid2D.h index f58a4ea..37e764a 100644 --- a/src/refinement/grid2D.h +++ b/src/refinement/grid2D.h @@ -77,6 +77,9 @@ protected: std::unique_ptr> _geometry; std::unique_ptr> _lattice; + std::vector>> _dynamics; + std::vector>> _onLatticeBoundaryConditions; + std::vector>> _fineGrids; std::vector>> _fineCouplers; @@ -92,6 +95,9 @@ public: SuperGeometry2D& getSuperGeometry(); SuperLattice2D& getSuperLattice(); + Dynamics& addDynamics(std::unique_ptr>&& dynamics); + sOnLatticeBoundaryCondition2D& getOnLatticeBoundaryCondition(); + void collideAndStream(); FineCoupler2D& addFineCoupling( diff --git a/src/refinement/grid2D.hh b/src/refinement/grid2D.hh index f1caf84..941bff7 100644 --- a/src/refinement/grid2D.hh +++ b/src/refinement/grid2D.hh @@ -133,6 +133,23 @@ SuperLattice2D& Grid2D::getSuperLattice() return *_lattice; } +template class DESCRIPTOR> +Dynamics& Grid2D::addDynamics( + std::unique_ptr>&& dynamics) +{ + Dynamics& ref = *dynamics; + _dynamics.emplace_back(std::move(dynamics)); + return ref; +} + +template class DESCRIPTOR> +sOnLatticeBoundaryCondition2D& Grid2D::getOnLatticeBoundaryCondition() +{ + _onLatticeBoundaryConditions.emplace_back( + new sOnLatticeBoundaryCondition2D(getSuperLattice())); + return *_onLatticeBoundaryConditions.back(); +} + template class DESCRIPTOR> void Grid2D::collideAndStream() { -- cgit v1.2.3