From 5a0e359141b214faf15f5057e64e8529f535c5c1 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 3 Feb 2019 19:45:36 +0100 Subject: Allow customization of Grid2D's physical dimensionalization --- src/refinement/grid2D.h | 36 +++++++++++++++++-- src/refinement/grid2D.hh | 90 ++++++++++++++++++++++++++++++++++-------------- 2 files changed, 99 insertions(+), 27 deletions(-) (limited to 'src/refinement') diff --git a/src/refinement/grid2D.h b/src/refinement/grid2D.h index 95324f7..c90078b 100644 --- a/src/refinement/grid2D.h +++ b/src/refinement/grid2D.h @@ -66,10 +66,29 @@ using RelaxationTime = NamedType; template using LatticeVelocity = NamedType; +template +struct Characteristics { + Characteristics(T l, T u, T nu, T rho): + length(l), + velocity(u), + viscosity(nu), + density(rho) { } + + Characteristics(int Re): + Characteristics(1.0, 1.0, 1.0/Re, 1.0) { } + + const T length; + const T velocity; + const T viscosity; + const T density; +}; + + template class DESCRIPTOR> class Grid2D { protected: FunctorPtr> _domainF; + const Characteristics _characteristics; std::unique_ptr> _converter; std::unique_ptr> _cuboids; @@ -79,6 +98,7 @@ protected: std::vector>> _dynamics; std::vector>> _onLatticeBoundaryConditions; + std::vector>> _offLatticeBoundaryConditions; std::vector>> _fineGrids; @@ -86,8 +106,19 @@ protected: std::vector>> _coarseCouplers; public: - Grid2D(FunctorPtr>&& domainF, int resolution, RelaxationTime tau, int re); - Grid2D(FunctorPtr>&& domainF, int resolution, LatticeVelocity uMax, int re); + Grid2D(FunctorPtr>&& domainF, + RelaxationTime tau, + int resolution, + Characteristics characteristics); + Grid2D(FunctorPtr>&& domainF, + LatticeVelocity latticeVelocity, + int resolution, + Characteristics characteristics); + + Grid2D(FunctorPtr>&& domainF, RelaxationTime tau, int resolution, int re); + Grid2D(FunctorPtr>&& domainF, LatticeVelocity uMax, int resolution, int re); + + Characteristics getCharacteristics() const; UnitConverter& getConverter(); CuboidGeometry2D& getCuboidGeometry(); @@ -97,6 +128,7 @@ public: Dynamics& addDynamics(std::unique_ptr>&& dynamics); sOnLatticeBoundaryCondition2D& getOnLatticeBoundaryCondition(); + sOffLatticeBoundaryCondition2D& getOffLatticeBoundaryCondition(); void collideAndStream(); diff --git a/src/refinement/grid2D.hh b/src/refinement/grid2D.hh index 504808a..6e9405e 100644 --- a/src/refinement/grid2D.hh +++ b/src/refinement/grid2D.hh @@ -34,19 +34,19 @@ namespace olb { template class DESCRIPTOR> -Grid2D::Grid2D( - FunctorPtr>&& domainF, - int resolution, - RelaxationTime tau, - int re): +Grid2D::Grid2D(FunctorPtr>&& domainF, + RelaxationTime tau, + int resolution, + Characteristics characteristics): _domainF(std::move(domainF)), + _characteristics(characteristics), _converter(new UnitConverterFromResolutionAndRelaxationTime( resolution, // resolution: number of voxels per charPhysL tau, // latticeRelaxationTime: relaxation time, has to be greater than 0.5! - T{1}, // charPhysLength: reference length of simulation geometry - T{1}, // charPhysVelocity: maximal/highest expected velocity during simulation in __m / s__ - T{1./re}, // physViscosity: physical kinematic viscosity in __m^2 / s__ - T{1})), // physDensity: physical density in __kg / m^3__ + characteristics.length, // charPhysLength: reference length of simulation geometry + characteristics.velocity, // charPhysVelocity: maximal/highest expected velocity during simulation in __m / s__ + characteristics.viscosity, // physViscosity: physical kinematic viscosity in __m^2 / s__ + characteristics.density)), // physDensity: physical density in __kg / m^3__ _cuboids(new CuboidGeometry2D( *_domainF, _converter->getConversionFactorLength(), @@ -69,19 +69,19 @@ Grid2D::Grid2D( } template class DESCRIPTOR> -Grid2D::Grid2D( - FunctorPtr>&& domainF, - int resolution, - LatticeVelocity velocity, - int re): +Grid2D::Grid2D(FunctorPtr>&& domainF, + LatticeVelocity latticeVelocity, + int resolution, + Characteristics characteristics): _domainF(std::move(domainF)), + _characteristics(characteristics), _converter(new UnitConverterFromResolutionAndLatticeVelocity( - resolution, // resolution: number of voxels per charPhysL - velocity, // maxLatticeVelocity - T{1}, // charPhysLength: reference length of simulation geometry - T{1}, // charPhysVelocity: maximal/highest expected velocity during simulation in __m / s__ - T{1./re}, // physViscosity: physical kinematic viscosity in __m^2 / s__ - T{1})), // physDensity: physical density in __kg / m^3__ + resolution, // resolution: number of voxels per charPhysL + latticeVelocity, // charLatticeVelocity + characteristics.length, // charPhysLength: reference length of simulation geometry + characteristics.velocity, // charPhysVelocity: maximal/highest expected velocity during simulation in __m / s__ + characteristics.viscosity, // physViscosity: physical kinematic viscosity in __m^2 / s__ + characteristics.density)), // physDensity: physical density in __kg / m^3__ _cuboids(new CuboidGeometry2D( *_domainF, _converter->getConversionFactorLength(), @@ -103,6 +103,36 @@ Grid2D::Grid2D( _converter->print(); } +template class DESCRIPTOR> +Grid2D::Grid2D( + FunctorPtr>&& domainF, + RelaxationTime tau, + int resolution, + int re): + Grid2D(std::forward(domainF), + tau, + resolution, + Characteristics(re)) +{ } + +template class DESCRIPTOR> +Grid2D::Grid2D( + FunctorPtr>&& domainF, + LatticeVelocity latticeVelocity, + int resolution, + int re): + Grid2D(std::forward(domainF), + latticeVelocity, + resolution, + Characteristics(re)) +{ } + +template class DESCRIPTOR> +Characteristics Grid2D::getCharacteristics() const +{ + return _characteristics; +} + template class DESCRIPTOR> UnitConverter& Grid2D::getConverter() { @@ -150,6 +180,14 @@ sOnLatticeBoundaryCondition2D& Grid2D::getOnLatticeB return *_onLatticeBoundaryConditions.back(); } +template class DESCRIPTOR> +sOffLatticeBoundaryCondition2D& Grid2D::getOffLatticeBoundaryCondition() +{ + _offLatticeBoundaryConditions.emplace_back( + new sOffLatticeBoundaryCondition2D(getSuperLattice())); + return *_offLatticeBoundaryConditions.back(); +} + template class DESCRIPTOR> void Grid2D::collideAndStream() { @@ -214,7 +252,10 @@ template class DESCRIPTOR> Vector Grid2D::alignExtendToGrid(Vector extend) const { const T deltaX = _converter->getPhysDeltaX(); - return util::floor(extend / deltaX) * deltaX; + return { + static_cast(std::floor(extend[0] / deltaX)) * deltaX, + static_cast(std::floor(extend[1] / deltaX)) * deltaX + }; } template class DESCRIPTOR> @@ -273,13 +314,12 @@ RefiningGrid2D::RefiningGrid2D( Grid2D& parentGrid, Vector origin, Vector extend): Grid2D( std::unique_ptr>(new IndicatorCuboid2D(extend, origin)), - 2*parentGrid.getConverter().getResolution(), RelaxationTime(2*parentGrid.getConverter().getLatticeRelaxationTime() - 0.5), - parentGrid.getConverter().getReynoldsNumber()), + 2*parentGrid.getConverter().getResolution(), + parentGrid.getCharacteristics()), _origin(origin), _extend(extend), - _parentGrid(parentGrid) -{ } + _parentGrid(parentGrid) { } template class DESCRIPTOR> Vector RefiningGrid2D::getOrigin() const -- cgit v1.2.3