From e415cc0cc2baedaade019693f69b6e1ed0dd4c2b Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Thu, 10 Jan 2019 20:23:30 +0100 Subject: Cache lattice positions for grid coupling --- src/refinement/coupler2D.h | 12 ++++--- src/refinement/coupler2D.hh | 76 +++++++++++++++++++++------------------------ 2 files changed, 43 insertions(+), 45 deletions(-) (limited to 'src/refinement') diff --git a/src/refinement/coupler2D.h b/src/refinement/coupler2D.h index b218eff..e911575 100644 --- a/src/refinement/coupler2D.h +++ b/src/refinement/coupler2D.h @@ -39,12 +39,14 @@ protected: const int _fineSize; const bool _vertical; - Vector _physOrigin; - Vector _coarseOrigin; - Vector _fineOrigin; + Vector _physOrigin; - Vector getFineLatticeR(int y) const; - Vector getCoarseLatticeR(int y) const; + const Vector& getFineLatticeR(int y) const; + const Vector& getCoarseLatticeR(int y) const; + +private: + std::vector> _coarseLatticeR; + std::vector> _fineLatticeR; public: Coupler2D(Grid2D& coarse, Grid2D& fine, diff --git a/src/refinement/coupler2D.hh b/src/refinement/coupler2D.hh index ab082f4..5614d16 100644 --- a/src/refinement/coupler2D.hh +++ b/src/refinement/coupler2D.hh @@ -32,37 +32,15 @@ namespace olb { template class DESCRIPTOR> -Vector Coupler2D::getFineLatticeR(int y) const +const Vector& Coupler2D::getFineLatticeR(int y) const { - if (_vertical) { - const auto physR = _physOrigin + Vector{0, y*_fine.getConverter().getPhysDeltaX()}; - Vector latticeR{}; - _fine.getCuboidGeometry().getLatticeR(physR, latticeR); - return latticeR; - } - else { - const auto physR = _physOrigin + Vector{y*_fine.getConverter().getPhysDeltaX(), 0}; - Vector latticeR{}; - _fine.getCuboidGeometry().getLatticeR(physR, latticeR); - return latticeR; - } + return _fineLatticeR[y]; } template class DESCRIPTOR> -Vector Coupler2D::getCoarseLatticeR(int y) const +const Vector& Coupler2D::getCoarseLatticeR(int y) const { - if (_vertical) { - const auto physR = _physOrigin + Vector{0, y*_coarse.getConverter().getPhysDeltaX()}; - Vector latticeR{}; - _coarse.getCuboidGeometry().getLatticeR(physR, latticeR); - return latticeR; - } - else { - const auto physR = _physOrigin + Vector{y*_coarse.getConverter().getPhysDeltaX(), 0}; - Vector latticeR{}; - _coarse.getCuboidGeometry().getLatticeR(physR, latticeR); - return latticeR; - } + return _coarseLatticeR[y]; } template class DESCRIPTOR> @@ -72,7 +50,9 @@ Coupler2D::Coupler2D(Grid2D& coarse, Grid2D::Coupler2D(Grid2D& coarse, Grid2D stepPhysR = _vertical ? Vector{0, deltaX} : Vector{deltaX, 0}; + + for (int i=0; i < _fineSize; ++i) { + if (i % 2 == 0) { + coarseGeometry.getLatticeR(_physOrigin + i*stepPhysR, _coarseLatticeR[i/2]); + } + + fineGeometry.getLatticeR(_physOrigin + i*stepPhysR, _fineLatticeR[i]); + } } @@ -97,9 +85,13 @@ FineCoupler2D::FineCoupler2D(Grid2D& coarse, Grid2D< _c2f_fneq(this->_coarseSize, Vector::q>(T{})) { OstreamManager clout(std::cout,"C2F"); - clout << "coarse origin: " << this->_coarseOrigin[0] << " " << this->_coarseOrigin[1] << " " << this->_coarseOrigin[2] << std::endl; - clout << "fine origin: " << this->_fineOrigin[0] << " " << this->_fineOrigin[1] << " " << this->_fineOrigin[2] << std::endl; - clout << "fine size: " << this->_fineSize << std::endl; + + const auto& coarseOrigin = this->getCoarseLatticeR(0); + const auto& fineOrigin = this->getFineLatticeR(0); + + clout << "coarse origin: " << coarseOrigin[0] << " " << coarseOrigin[1] << " " << coarseOrigin[2] << std::endl; + clout << "fine origin: " << fineOrigin[0] << " " << fineOrigin[1] << " " << fineOrigin[2] << std::endl; + clout << "fine size: " << this->_fineSize << std::endl; } template class DESCRIPTOR> @@ -172,8 +164,8 @@ void FineCoupler2D::couple() auto& fineLattice = this->_fine.getSuperLattice(); for (int y=0; y < this->_coarseSize; ++y) { - const auto coarsePos = this->getCoarseLatticeR(y); - const auto finePos = this->getFineLatticeR(2*y); + const auto& coarsePos = this->getCoarseLatticeR(y); + const auto& finePos = this->getFineLatticeR(2*y); T fEq[DESCRIPTOR::q] {}; Cell coarseCell; @@ -247,7 +239,7 @@ void FineCoupler2D::couple() ); const T uSqr = u[0]*u[0] + u[1]*u[1]; - const auto finePos = this->getFineLatticeR(1); + const auto& finePos = this->getFineLatticeR(1); Cell fineCell; fineLattice.get(finePos, fineCell); @@ -282,7 +274,7 @@ void FineCoupler2D::couple() ); const T uSqr = u[0]*u[0] + u[1]*u[1]; - const auto finePos = this->getFineLatticeR(this->_fineSize-2); + const auto& finePos = this->getFineLatticeR(this->_fineSize-2); Cell fineCell; fineLattice.get(finePos, fineCell); @@ -329,8 +321,12 @@ CoarseCoupler2D::CoarseCoupler2D( Coupler2D(coarse, fine, origin, extend) { OstreamManager clout(std::cout,"F2C"); - clout << "coarse origin: " << this->_coarseOrigin[0] << " " << this->_coarseOrigin[1] << " " << this->_coarseOrigin[2] << std::endl; - clout << "fine origin: " << this->_fineOrigin[0] << " " << this->_fineOrigin[1] << " " << this->_fineOrigin[2] << std::endl; + + const auto& coarseOrigin = this->getCoarseLatticeR(0); + const auto& fineOrigin = this->getFineLatticeR(0); + + clout << "coarse origin: " << coarseOrigin[0] << " " << coarseOrigin[1] << " " << coarseOrigin[2] << std::endl; + clout << "fine origin: " << fineOrigin[0] << " " << fineOrigin[1] << " " << fineOrigin[2] << std::endl; clout << "coarse size: " << this->_coarseSize << std::endl; } @@ -341,8 +337,8 @@ void CoarseCoupler2D::couple() auto& coarseLattice = this->_coarse.getSuperLattice(); for (int y=0; y < this->_coarseSize; ++y) { - const auto finePos = this->getFineLatticeR(2*y); - const auto coarsePos = this->getCoarseLatticeR(y); + const auto& finePos = this->getFineLatticeR(2*y); + const auto& coarsePos = this->getCoarseLatticeR(y); T fEq[DESCRIPTOR::q] {}; Cell fineCell; -- cgit v1.2.3