From 6403bbf816f6256ade8569114441386ece29d4a5 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 14 Jan 2019 15:51:54 +0100 Subject: Tidy up function parameters by accepting Grid2D --- apps/adrian/poiseuille2d/poiseuille2d.cpp | 117 +++++++++++++----------------- 1 file changed, 51 insertions(+), 66 deletions(-) diff --git a/apps/adrian/poiseuille2d/poiseuille2d.cpp b/apps/adrian/poiseuille2d/poiseuille2d.cpp index 8b8640e..7112f58 100644 --- a/apps/adrian/poiseuille2d/poiseuille2d.cpp +++ b/apps/adrian/poiseuille2d/poiseuille2d.cpp @@ -47,14 +47,15 @@ const T physInterval = 0.25; // interval for the convergence check in s const T residuum = 1e-5; // residuum for the convergence check -void prepareGeometry(UnitConverter const& converter, - SuperGeometry2D& superGeometry) +void prepareGeometry(Grid2D& grid) { - OstreamManager clout(std::cout,"prepareGeometry"); clout << "Prepare Geometry ..." << std::endl; - superGeometry.rename(0,1); + auto& converter = grid.getConverter(); + auto& sGeometry = grid.getSuperGeometry(); + + sGeometry.rename(0,1); const T physSpacing = converter.getPhysDeltaX(); @@ -64,10 +65,10 @@ void prepareGeometry(UnitConverter const& converter, const Vector wallOrigin {-physSpacing/4, -physSpacing/4}; IndicatorCuboid2D lowerWall(wallExtend, wallOrigin); - superGeometry.rename(1,2,lowerWall); + sGeometry.rename(1,2,lowerWall); IndicatorCuboid2D upperWall(wallExtend, wallOrigin + Vector {0,ly}); - superGeometry.rename(1,2,upperWall); + sGeometry.rename(1,2,upperWall); } // Set material number for inflow and outflow @@ -76,46 +77,48 @@ void prepareGeometry(UnitConverter const& converter, const Vector origin {-physSpacing/4, -physSpacing/4}; IndicatorCuboid2D inflow(extend, origin); - superGeometry.rename(1,3,inflow); + sGeometry.rename(1,3,inflow); IndicatorCuboid2D outflow(extend, origin + Vector {lx,0}); - superGeometry.rename(1,4,outflow); + sGeometry.rename(1,4,outflow); } // Set material number for vertically centered obstacle { const Vector origin {1.25, ly/2}; IndicatorCircle2D obstacle(origin, 0.1); - superGeometry.rename(1,2,obstacle); + sGeometry.rename(1,2,obstacle); } - superGeometry.clean(); - superGeometry.innerClean(); - superGeometry.checkForErrors(); - superGeometry.print(); + sGeometry.clean(); + sGeometry.innerClean(); + sGeometry.checkForErrors(); + sGeometry.print(); clout << "Prepare Geometry ... OK" << std::endl; } -void prepareLattice(UnitConverter const& converter, - SuperLattice2D& sLattice, +void prepareLattice(Grid2D& grid, Dynamics& bulkDynamics, - sOnLatticeBoundaryCondition2D& sBoundaryCondition, - SuperGeometry2D& superGeometry) + sOnLatticeBoundaryCondition2D& sBoundaryCondition) { OstreamManager clout(std::cout,"prepareLattice"); clout << "Prepare lattice ..." << std::endl; + auto& converter = grid.getConverter(); + auto& sGeometry = grid.getSuperGeometry(); + auto& sLattice = grid.getSuperLattice(); + const T omega = converter.getLatticeRelaxationFrequency(); - sLattice.defineDynamics(superGeometry, 0, &instances::getNoDynamics()); - sLattice.defineDynamics(superGeometry, 1, &bulkDynamics); // bulk - sLattice.defineDynamics(superGeometry, 2, &instances::getBounceBack()); - sLattice.defineDynamics(superGeometry, 3, &bulkDynamics); // inflow - sLattice.defineDynamics(superGeometry, 4, &bulkDynamics); // outflow + sLattice.defineDynamics(sGeometry, 0, &instances::getNoDynamics()); + sLattice.defineDynamics(sGeometry, 1, &bulkDynamics); // bulk + sLattice.defineDynamics(sGeometry, 2, &instances::getBounceBack()); + sLattice.defineDynamics(sGeometry, 3, &bulkDynamics); // inflow + sLattice.defineDynamics(sGeometry, 4, &bulkDynamics); // outflow - sBoundaryCondition.addVelocityBoundary(superGeometry, 3, omega); - sBoundaryCondition.addVelocityBoundary(superGeometry, 4, omega); + sBoundaryCondition.addVelocityBoundary(sGeometry, 3, omega); + sBoundaryCondition.addVelocityBoundary(sGeometry, 4, omega); const T Lx = converter.getLatticeLength(lx); const T Ly = converter.getLatticeLength(ly); @@ -128,15 +131,15 @@ void prepareLattice(UnitConverter const& converter, std::vector axisDirection{1, 0}; Poiseuille2D u(axisPoint, axisDirection, maxVelocity, radius); - sLattice.defineRhoU(superGeometry, 1, rho, u); - sLattice.iniEquilibrium(superGeometry, 1, rho, u); - sLattice.defineRhoU(superGeometry, 2, rho, u); - sLattice.iniEquilibrium(superGeometry, 2, rho, u); + sLattice.defineRhoU(sGeometry, 1, rho, u); + sLattice.iniEquilibrium(sGeometry, 1, rho, u); + sLattice.defineRhoU(sGeometry, 2, rho, u); + sLattice.iniEquilibrium(sGeometry, 2, rho, u); - sLattice.defineRhoU(superGeometry, 3, rho, u); - sLattice.iniEquilibrium(superGeometry, 3, rho, u); - sLattice.defineRhoU(superGeometry, 4, rho, u); - sLattice.iniEquilibrium(superGeometry, 4, rho, u); + sLattice.defineRhoU(sGeometry, 3, rho, u); + sLattice.iniEquilibrium(sGeometry, 3, rho, u); + sLattice.defineRhoU(sGeometry, 4, rho, u); + sLattice.iniEquilibrium(sGeometry, 4, rho, u); sLattice.initialize(); @@ -144,16 +147,19 @@ void prepareLattice(UnitConverter const& converter, } void getResults(const std::string& prefix, - SuperLattice2D& sLattice, - UnitConverter const& converter, int iT, - SuperGeometry2D& superGeometry, Timer& timer, bool hasConverged) + Grid2D& grid, + int iT, Timer& timer, bool hasConverged) { OstreamManager clout(std::cout,"getResults"); + auto& converter = grid.getConverter(); + auto& sLattice = grid.getSuperLattice(); + auto& sGeometry = grid.getSuperGeometry(); + SuperVTMwriter2D vtmWriter(prefix + "poiseuille2d"); SuperLatticePhysVelocity2D velocity(sLattice, converter); SuperLatticePhysPressure2D pressure(sLattice, converter); - SuperLatticeGeometry2D geometry( sLattice, superGeometry ); + SuperLatticeGeometry2D geometry(sLattice, sGeometry); vtmWriter.addFunctor(geometry); vtmWriter.addFunctor(velocity); vtmWriter.addFunctor(pressure); @@ -187,13 +193,13 @@ int main(int argc, char* argv[]) IndicatorCuboid2D coarseCuboid(coarseExtend, coarseOrigin); Grid2D coarseGrid(coarseCuboid, N, baseTau, Re); - prepareGeometry(coarseGrid.getConverter(), coarseGrid.getSuperGeometry()); + prepareGeometry(coarseGrid); const Vector fineExtend {3.0, 1.5}; const Vector fineOrigin {0.8, (ly-fineExtend[1])/2}; auto& fineGrid = coarseGrid.refine(fineOrigin, fineExtend); - prepareGeometry(fineGrid.getConverter(), fineGrid.getSuperGeometry()); + prepareGeometry(fineGrid); auto refinedOverlap = fineGrid.getRefinedOverlap(); coarseGrid.getSuperGeometry().rename(1,0,*refinedOverlap); @@ -206,12 +212,7 @@ int main(int argc, char* argv[]) sOnLatticeBoundaryCondition2D coarseSBoundaryCondition(coarseGrid.getSuperLattice()); createLocalBoundaryCondition2D(coarseSBoundaryCondition); - prepareLattice( - coarseGrid.getConverter(), - coarseGrid.getSuperLattice(), - coarseBulkDynamics, - coarseSBoundaryCondition, - coarseGrid.getSuperGeometry()); + prepareLattice(coarseGrid, coarseBulkDynamics, coarseSBoundaryCondition); BGKdynamics fineBulkDynamics( fineGrid.getConverter().getLatticeRelaxationFrequency(), @@ -224,18 +225,13 @@ int main(int argc, char* argv[]) const Vector fineOrigin2 {1.05, (ly-fineExtend2[1])/2}; auto& fineGrid2 = fineGrid.refine(fineOrigin2, fineExtend2); - prepareGeometry(fineGrid2.getConverter(), fineGrid2.getSuperGeometry()); + prepareGeometry(fineGrid2); auto refinedOverlap2 = fineGrid2.getRefinedOverlap(); fineGrid.getSuperGeometry().rename(1,0,*refinedOverlap2); fineGrid.getSuperGeometry().rename(2,0,*refinedOverlap2); - prepareLattice( - fineGrid.getConverter(), - fineGrid.getSuperLattice(), - fineBulkDynamics, - fineSBoundaryCondition, - fineGrid.getSuperGeometry()); + prepareLattice(fineGrid, fineBulkDynamics, fineSBoundaryCondition); BGKdynamics fineBulkDynamics2( fineGrid2.getConverter().getLatticeRelaxationFrequency(), @@ -244,12 +240,7 @@ int main(int argc, char* argv[]) sOnLatticeBoundaryCondition2D fineSBoundaryCondition2(fineGrid2.getSuperLattice()); createLocalBoundaryCondition2D(fineSBoundaryCondition2); - prepareLattice( - fineGrid2.getConverter(), - fineGrid2.getSuperLattice(), - fineBulkDynamics2, - fineSBoundaryCondition2, - fineGrid2.getSuperGeometry()); + prepareLattice(fineGrid2, fineBulkDynamics2, fineSBoundaryCondition2); clout << "starting simulation..." << endl; Timer timer( @@ -270,26 +261,20 @@ int main(int argc, char* argv[]) getResults( "coarse_", - coarseGrid.getSuperLattice(), - coarseGrid.getConverter(), + coarseGrid, iT, - coarseGrid.getSuperGeometry(), timer, converge.hasConverged()); getResults( "fine_", - fineGrid.getSuperLattice(), - fineGrid.getConverter(), + fineGrid, iT, - fineGrid.getSuperGeometry(), timer, converge.hasConverged()); getResults( "fine2_", - fineGrid2.getSuperLattice(), - fineGrid2.getConverter(), + fineGrid2, iT, - fineGrid2.getSuperGeometry(), timer, converge.hasConverged()); -- cgit v1.2.3