From b5fd6d62b1ea3717f6196fc4322dbaf6fc19868b Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 7 Jan 2019 20:05:48 +0100 Subject: Basic subgrid construction, coupling automatization --- apps/adrian/poiseuille2d/poiseuille2d.cpp | 135 ++++++++++++++++++------------ 1 file changed, 83 insertions(+), 52 deletions(-) (limited to 'apps') diff --git a/apps/adrian/poiseuille2d/poiseuille2d.cpp b/apps/adrian/poiseuille2d/poiseuille2d.cpp index f551820..9f92c2a 100644 --- a/apps/adrian/poiseuille2d/poiseuille2d.cpp +++ b/apps/adrian/poiseuille2d/poiseuille2d.cpp @@ -197,6 +197,9 @@ void getResults(const std::string& prefix, } } +template class DESCRIPTOR> class FineCoupler; +template class DESCRIPTOR> class CoarseCoupler; + template class DESCRIPTOR> class Grid { private: @@ -206,6 +209,11 @@ private: std::unique_ptr> _geometry; std::unique_ptr> _lattice; + std::vector>> _fineGrids; + + std::vector>> _fineCouplers; + std::vector>> _coarseCouplers; + public: static std::unique_ptr> make(IndicatorF2D& domainF, int resolution, T tau, int re) { @@ -274,15 +282,78 @@ public: return 1./getScalingFactor(); } - std::unique_ptr> refine(IndicatorF2D& domainF) + void collideAndStream() { - return std::unique_ptr>( - new Grid( - domainF, - 2*getConverter().getResolution(), - 2.0*getConverter().getLatticeRelaxationTime() - 0.5, - getConverter().getReynoldsNumber() - )); + for ( auto& fineCoupler : _fineCouplers ) { + fineCoupler->store(); + } + + this->getSuperLattice().collideAndStream(); + + for ( auto& fineGrid : _fineGrids ) { + fineGrid->getSuperLattice().collideAndStream(); + } + + for ( auto& fineCoupler : _fineCouplers ) { + fineCoupler->interpolate(); + fineCoupler->couple(); + } + + for ( auto& fineGrid : _fineGrids ) { + fineGrid->getSuperLattice().collideAndStream(); + } + + for ( auto& fineCoupler : _fineCouplers ) { + fineCoupler->store(); + fineCoupler->couple(); + } + + for ( auto& coarseCoupler : _coarseCouplers ) { + coarseCoupler->couple(); + } + } + + Grid* refine(Vector origin, Vector extend) + { + IndicatorCuboid2D fineCuboid(extend, origin); + _fineGrids.emplace_back( + new Grid( + fineCuboid, + 2*getConverter().getResolution(), + 2.0*getConverter().getLatticeRelaxationTime() - 0.5, + getConverter().getReynoldsNumber() + )); + Grid* const fineGrid = _fineGrids.back().get(); + + const T coarseDeltaX = getConverter().getPhysDeltaX(); + + _fineCouplers.emplace_back( + new FineCoupler( + *this, *fineGrid, origin, Vector {0,extend[1]})); + _fineCouplers.emplace_back( + new FineCoupler( + *this, *fineGrid, origin + Vector {extend[0],0}, Vector {0,extend[1]})); + _fineCouplers.emplace_back( + new FineCoupler( + *this, *fineGrid, origin + Vector(0,extend[1]), Vector {extend[0],0})); + _fineCouplers.emplace_back( + new FineCoupler( + *this, *fineGrid, origin, Vector {extend[0],0})); + + _coarseCouplers.emplace_back( + new CoarseCoupler( + *this, *fineGrid, origin + coarseDeltaX, Vector {0,extend[1]-2*coarseDeltaX})); + _coarseCouplers.emplace_back( + new CoarseCoupler( + *this, *fineGrid, origin + Vector(extend[0]-coarseDeltaX,coarseDeltaX), Vector {0,extend[1]-2*coarseDeltaX})); + _coarseCouplers.emplace_back( + new CoarseCoupler( + *this, *fineGrid, origin + Vector {coarseDeltaX,extend[1]-coarseDeltaX}, Vector {extend[0]-2*coarseDeltaX,0})); + _coarseCouplers.emplace_back( + new CoarseCoupler( + *this, *fineGrid, origin + coarseDeltaX, Vector {extend[0]-2*coarseDeltaX,0})); + + return fineGrid; } }; @@ -619,12 +690,11 @@ int main(int argc, char* argv[]) Vector coarseExtend { lx, ly }; IndicatorCuboid2D coarseCuboid(coarseExtend, coarseOrigin); - Vector fineOrigin { 0.25 * lx, 0.3 }; - Vector fineExtend { 0.5 * lx, 0.4 }; - IndicatorCuboid2D fineCuboid(fineExtend, fineOrigin); + Vector fineOrigin { 0.25 * lx, 0.2 }; + Vector fineExtend { 0.6 * lx, 0.6 }; auto coarseGrid = Grid::make(coarseCuboid, N, 0.8, Re); - auto fineGrid = coarseGrid->refine(fineCuboid); + auto fineGrid = coarseGrid->refine(fineOrigin, fineExtend); prepareGeometry(coarseGrid->getConverter(), coarseGrid->getSuperGeometry()); prepareGeometry(fineGrid->getConverter(), fineGrid->getSuperGeometry()); @@ -675,52 +745,13 @@ int main(int argc, char* argv[]) residuum); timer.start(); - FineCoupler fineCoupler0(*coarseGrid, *fineGrid, fineOrigin, Vector {0,fineExtend[1]}); - FineCoupler fineCoupler1(*coarseGrid, *fineGrid, fineOrigin + Vector {fineExtend[0],0}, Vector {0,fineExtend[1]}); - FineCoupler fineCoupler2(*coarseGrid, *fineGrid, fineOrigin + Vector(0,fineExtend[1]), Vector {fineExtend[0],0}); - FineCoupler fineCoupler3(*coarseGrid, *fineGrid, fineOrigin, Vector {fineExtend[0],0}); - - CoarseCoupler coarseCoupler0(*coarseGrid, *fineGrid, fineOrigin + coarseDeltaX, Vector {0,fineExtend[1]-2*coarseDeltaX}); - CoarseCoupler coarseCoupler1(*coarseGrid, *fineGrid, fineOrigin + Vector(fineExtend[0]-coarseDeltaX,coarseDeltaX), Vector {0,fineExtend[1]-2*coarseDeltaX}); - CoarseCoupler coarseCoupler2(*coarseGrid, *fineGrid, fineOrigin + Vector {coarseDeltaX,fineExtend[1]-coarseDeltaX}, Vector {fineExtend[0]-2*coarseDeltaX,0}); - CoarseCoupler coarseCoupler3(*coarseGrid, *fineGrid, fineOrigin + coarseDeltaX, Vector {fineExtend[0]-2*coarseDeltaX,0}); - for (int iT = 0; iT < coarseGrid->getConverter().getLatticeTime(maxPhysT); ++iT) { if (converge.hasConverged()) { clout << "Simulation converged." << endl; break; } - fineCoupler0.store(); - fineCoupler1.store(); - fineCoupler2.store(); - fineCoupler3.store(); - coarseGrid->getSuperLattice().collideAndStream(); - - fineGrid->getSuperLattice().collideAndStream(); - fineCoupler0.interpolate(); - fineCoupler0.couple(); - fineCoupler1.interpolate(); - fineCoupler1.couple(); - fineCoupler2.interpolate(); - fineCoupler2.couple(); - fineCoupler3.interpolate(); - fineCoupler3.couple(); - - fineGrid->getSuperLattice().collideAndStream(); - fineCoupler0.store(); - fineCoupler0.couple(); - fineCoupler1.store(); - fineCoupler1.couple(); - fineCoupler2.store(); - fineCoupler2.couple(); - fineCoupler3.store(); - fineCoupler3.couple(); - - coarseCoupler0.couple(); - coarseCoupler1.couple(); - coarseCoupler2.couple(); - coarseCoupler3.couple(); + coarseGrid->collideAndStream(); getResults( "coarse_", -- cgit v1.2.3