From dd658eec1f3d716fa18ceb990b924b38721ecdeb Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Fri, 11 Jan 2019 11:20:10 +0100 Subject: Improve grid refinement interface By deriving RefiningGrid2D from Grid2D to provide methods specific to refining subgrids. --- src/refinement/grid2D.cpp | 1 + src/refinement/grid2D.h | 32 +++++++++++--- src/refinement/grid2D.hh | 104 +++++++++++++++++++++++++++++++--------------- 3 files changed, 98 insertions(+), 39 deletions(-) (limited to 'src/refinement') diff --git a/src/refinement/grid2D.cpp b/src/refinement/grid2D.cpp index b371d0c..86ca284 100644 --- a/src/refinement/grid2D.cpp +++ b/src/refinement/grid2D.cpp @@ -30,5 +30,6 @@ namespace olb { template class Grid2D; +template class RefiningGrid2D; } diff --git a/src/refinement/grid2D.h b/src/refinement/grid2D.h index 1d15170..d782651 100644 --- a/src/refinement/grid2D.h +++ b/src/refinement/grid2D.h @@ -34,23 +34,27 @@ #include "geometry/superGeometry2D.h" #include "communication/loadBalancer.h" #include "functors/analytical/indicator/indicatorF2D.h" +#include "utilities/functorPtr.h" namespace olb { template class DESCRIPTOR> class FineCoupler2D; template class DESCRIPTOR> class CoarseCoupler2D; +template class DESCRIPTOR> class RefiningGrid2D; template class DESCRIPTOR> class Grid2D { -private: +protected: + FunctorPtr> _domainF; + std::unique_ptr> _converter; std::unique_ptr> _cuboids; std::unique_ptr> _balancer; std::unique_ptr> _geometry; std::unique_ptr> _lattice; - std::vector>> _fineGrids; + std::vector>> _fineGrids; std::vector>> _fineCouplers; std::vector>> _coarseCouplers; @@ -58,7 +62,7 @@ private: public: static std::unique_ptr> make(IndicatorF2D& domainF, int resolution, T tau, int re); - Grid2D(IndicatorF2D& domainF, int resolution, T tau, int re); + Grid2D(FunctorPtr>&& domainF, int resolution, T tau, int re); UnitConverter& getConverter(); CuboidGeometry2D& getCuboidGeometry(); @@ -76,8 +80,26 @@ public: Vector alignOriginToGrid(Vector physR) const; Vector alignExtendToGrid(Vector physR) const; - Grid2D& refine(IndicatorF2D& domainF); - Grid2D& refine(Vector origin, Vector extend); + RefiningGrid2D& refine(Vector origin, Vector extend, bool addCouplers=true); + +}; + +template class DESCRIPTOR> +class RefiningGrid2D : public Grid2D { +private: + const Vector _origin; + const Vector _extend; + + Grid2D& _parentGrid; + +public: + RefiningGrid2D(Grid2D& parentGrid, Vector origin, Vector extend); + + Vector getOrigin() const; + Vector getExtend() const; + + /// Indicates the subdomain of the coarse grid rendered moot by refinement + std::unique_ptr> getRefinedOverlap() const; }; diff --git a/src/refinement/grid2D.hh b/src/refinement/grid2D.hh index 99a2563..aa82240 100644 --- a/src/refinement/grid2D.hh +++ b/src/refinement/grid2D.hh @@ -27,6 +27,7 @@ #include "grid2D.h" #include "coupler2D.hh" +#include "utilities/vectorHelpers.h" #include "communication/heuristicLoadBalancer.h" namespace olb { @@ -43,7 +44,8 @@ std::unique_ptr> Grid2D::make( } template class DESCRIPTOR> -Grid2D::Grid2D(IndicatorF2D& domainF, int resolution, T tau, int re): +Grid2D::Grid2D(FunctorPtr>&& domainF, int resolution, T tau, int re): + _domainF(std::move(domainF)), _converter(new UnitConverterFromResolutionAndRelaxationTime( resolution, // resolution: number of voxels per charPhysL tau, // latticeRelaxationTime: relaxation time, has to be greater than 0.5! @@ -53,7 +55,7 @@ Grid2D::Grid2D(IndicatorF2D& domainF, int resolution, T tau, in T{1}, // physDensity: physical density in __kg / m^3__ T{1})), _cuboids(new CuboidGeometry2D( - domainF, + *_domainF, _converter->getConversionFactorLength(), #ifdef PARALLEL_MODE_MPI singleton::mpi().getSize() @@ -155,19 +157,6 @@ CoarseCoupler2D& Grid2D::addCoarseCoupling( return *_coarseCouplers.back(); } -template class DESCRIPTOR> -Grid2D& Grid2D::refine(IndicatorF2D& domainF) -{ - _fineGrids.emplace_back( - new Grid2D( - domainF, - 2*getConverter().getResolution(), - 2*getConverter().getLatticeRelaxationTime() - 0.5, - getConverter().getReynoldsNumber() - )); - return *_fineGrids.back(); -} - template class DESCRIPTOR> Vector Grid2D::alignOriginToGrid(Vector physR) const { @@ -180,37 +169,84 @@ template class DESCRIPTOR> Vector Grid2D::alignExtendToGrid(Vector extend) const { const T deltaX = _converter->getPhysDeltaX(); - return floor(extend / deltaX) * deltaX; + return util::floor(extend / deltaX) * deltaX; } template class DESCRIPTOR> -Grid2D& Grid2D::refine(Vector origin, Vector extend) +RefiningGrid2D& Grid2D::refine( + Vector wantedOrigin, Vector wantedExtend, bool addCouplers) { - IndicatorCuboid2D fineCuboid(extend, origin); - auto& fineGrid = refine(fineCuboid); + if (addCouplers) { + auto& fineGrid = refine(wantedOrigin, wantedExtend, false); + + const Vector origin = fineGrid.getOrigin(); + const Vector extend = fineGrid.getExtend(); + + const Vector extendX = {extend[0],0}; + const Vector extendY = {0,extend[1]}; - const Vector extendX = {extend[0],0}; - const Vector extendY = {0,extend[1]}; + addFineCoupling(fineGrid, origin, extendY); + addFineCoupling(fineGrid, origin + extendX, extendY); + addFineCoupling(fineGrid, origin + extendY, extendX); + addFineCoupling(fineGrid, origin, extendX); - addFineCoupling(fineGrid, origin, extendY); - addFineCoupling(fineGrid, origin + extendX, extendY); - addFineCoupling(fineGrid, origin + extendY, extendX); - addFineCoupling(fineGrid, origin, extendX); + const T coarseDeltaX = getConverter().getPhysDeltaX(); + const Vector innerOrigin = origin + coarseDeltaX; + const Vector innerExtendX = extendX - Vector {2*coarseDeltaX,0}; + const Vector innerExtendY = extendY - Vector {0,2*coarseDeltaX}; - const T coarseDeltaX = getConverter().getPhysDeltaX(); - const Vector innerOrigin = origin + coarseDeltaX; - const Vector innerExtendX = extendX - Vector {2*coarseDeltaX,0}; - const Vector innerExtendY = extendY - Vector {0,2*coarseDeltaX}; + addCoarseCoupling(fineGrid, innerOrigin, innerExtendY); + addCoarseCoupling(fineGrid, innerOrigin + innerExtendX, innerExtendY); + addCoarseCoupling(fineGrid, innerOrigin + innerExtendY, innerExtendX); + addCoarseCoupling(fineGrid, innerOrigin, innerExtendX); - addCoarseCoupling(fineGrid, innerOrigin, innerExtendY); - addCoarseCoupling(fineGrid, innerOrigin + innerExtendX, innerExtendY); - addCoarseCoupling(fineGrid, innerOrigin + innerExtendY, innerExtendX); - addCoarseCoupling(fineGrid, innerOrigin, innerExtendX); + return fineGrid; + } + else { + const Vector origin = alignOriginToGrid(wantedOrigin); + const Vector extend = alignExtendToGrid(wantedExtend); - return fineGrid; + _fineGrids.emplace_back( + new RefiningGrid2D(*this, origin, extend)); + return *_fineGrids.back(); + } } +template class DESCRIPTOR> +RefiningGrid2D::RefiningGrid2D( + Grid2D& parentGrid, Vector origin, Vector extend): + Grid2D( + std::unique_ptr>(new IndicatorCuboid2D(extend, origin)), + 2*parentGrid.getConverter().getResolution(), + 2*parentGrid.getConverter().getLatticeRelaxationTime() - 0.5, + parentGrid.getConverter().getReynoldsNumber()), + _origin(origin), + _extend(extend), + _parentGrid(parentGrid) +{ } + +template class DESCRIPTOR> +Vector RefiningGrid2D::getOrigin() const +{ + return _origin; +} + +template class DESCRIPTOR> +Vector RefiningGrid2D::getExtend() const +{ + return _extend; +} + +template class DESCRIPTOR> +std::unique_ptr> RefiningGrid2D::getRefinedOverlap() const +{ + const T coarseDeltaX = _parentGrid.getConverter().getPhysDeltaX(); + + return std::unique_ptr>( + new IndicatorCuboid2D(_extend - 4*coarseDeltaX, _origin + 2*coarseDeltaX)); +} + } #endif -- cgit v1.2.3