From ecc8133d27ba756388caee6a0d583633bbff83c3 Mon Sep 17 00:00:00 2001 From: Ned Coltman Date: Tue, 5 May 2020 17:56:21 +0200 Subject: [PATCH 1/6] [test][rans][ransnc] unify setBCtypes with if constexpr --- test/freeflow/rans/problem.hh | 44 ++++++++++++++++----------------- test/freeflow/ransnc/problem.hh | 44 ++++++++++++++++----------------- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/test/freeflow/rans/problem.hh b/test/freeflow/rans/problem.hh index 1c4246d16f..221f3caad4 100644 --- a/test/freeflow/rans/problem.hh +++ b/test/freeflow/rans/problem.hh @@ -226,8 +226,7 @@ public: #endif // turbulence model-specific boundary types - static constexpr auto numEq = numTurbulenceEq(ModelTraits::turbulenceModel()); - setBcTypes_(values, globalPos, Dune::index_constant{}); + setBcTypes_(values, globalPos); return values; } @@ -377,31 +376,32 @@ private: } } - //! Boundary condition types for the zero-eq turbulence model (none) - void setBcTypes_(BoundaryTypes& values, const GlobalPosition& pos, Dune::index_constant<0>) const {} - //! Boundary condition types for the one-eq turbulence model - void setBcTypes_(BoundaryTypes& values, const GlobalPosition& pos, Dune::index_constant<1>) const + void setBcTypes_(BoundaryTypes& values, const GlobalPosition& pos) const { - if(isOutlet_(pos)) - values.setOutflow(Indices::viscosityTildeIdx); - else // walls and inflow - values.setDirichlet(Indices::viscosityTildeIdx); - } - - //! Boundary condition types for the komega, kepsilon and lowrekepsilon turbulence models - void setBcTypes_(BoundaryTypes& values,const GlobalPosition& pos, Dune::index_constant<2>) const - { - if(isOutlet_(pos)) + if constexpr (numTurbulenceEq(ModelTraits::turbulenceModel()) == 0) // zero equation models + return; + else if constexpr (numTurbulenceEq(ModelTraits::turbulenceModel()) == 1) // one equation models { - values.setOutflow(Indices::turbulentKineticEnergyEqIdx); - values.setOutflow(Indices::dissipationEqIdx); + if(isOutlet_(pos)) + values.setOutflow(Indices::viscosityTildeIdx); + else // walls and inflow + values.setDirichlet(Indices::viscosityTildeIdx); } - else + else // two equation models { - // walls and inflow - values.setDirichlet(Indices::turbulentKineticEnergyIdx); - values.setDirichlet(Indices::dissipationIdx); + static_assert(numTurbulenceEq(ModelTraits::turbulenceModel()) == 2, "Only reached by 2eq models"); + if(isOutlet_(pos)) + { + values.setOutflow(Indices::turbulentKineticEnergyEqIdx); + values.setOutflow(Indices::dissipationEqIdx); + } + else + { + // walls and inflow + values.setDirichlet(Indices::turbulentKineticEnergyIdx); + values.setDirichlet(Indices::dissipationIdx); + } } } diff --git a/test/freeflow/ransnc/problem.hh b/test/freeflow/ransnc/problem.hh index a304d53b40..1489864aef 100644 --- a/test/freeflow/ransnc/problem.hh +++ b/test/freeflow/ransnc/problem.hh @@ -206,8 +206,7 @@ public: BoundaryTypes values; // turbulence model-specific boundary types - static constexpr auto numEq = numTurbulenceEq(ModelTraits::turbulenceModel()); - setBcTypes_(values, globalPos, Dune::index_constant{}); + setBcTypes_(values, globalPos); if(isInlet_(globalPos)) { @@ -396,31 +395,32 @@ private: } } - //! Boundary condition types for the zero-eq turbulence model (none) - void setBcTypes_(BoundaryTypes& values, const GlobalPosition& pos, Dune::index_constant<0>) const {} - //! Boundary condition types for the one-eq turbulence model - void setBcTypes_(BoundaryTypes& values, const GlobalPosition& pos, Dune::index_constant<1>) const - { - if(isOutlet_(pos)) - values.setOutflow(Indices::viscosityTildeIdx); - else // walls and inflow - values.setDirichlet(Indices::viscosityTildeIdx); - } - - //! Boundary condition types for the komega, kepsilon and lowrekepsilon turbulence models - void setBcTypes_(BoundaryTypes& values,const GlobalPosition& pos, Dune::index_constant<2>) const + void setBcTypes_(BoundaryTypes& values, const GlobalPosition& pos) const { - if(isOutlet_(pos)) + if constexpr (numTurbulenceEq(ModelTraits::turbulenceModel()) == 0) // zero equation models + return; + else if constexpr (numTurbulenceEq(ModelTraits::turbulenceModel()) == 1) // one equation models { - values.setOutflow(Indices::turbulentKineticEnergyEqIdx); - values.setOutflow(Indices::dissipationEqIdx); + if(isOutlet_(pos)) + values.setOutflow(Indices::viscosityTildeIdx); + else // walls and inflow + values.setDirichlet(Indices::viscosityTildeIdx); } - else + else // two equation models { - // walls and inflow - values.setDirichlet(Indices::turbulentKineticEnergyIdx); - values.setDirichlet(Indices::dissipationIdx); + static_assert(numTurbulenceEq(ModelTraits::turbulenceModel()) == 2, "Only reached by 2eq models"); + if(isOutlet_(pos)) + { + values.setOutflow(Indices::turbulentKineticEnergyEqIdx); + values.setOutflow(Indices::dissipationEqIdx); + } + else + { + // walls and inflow + values.setDirichlet(Indices::turbulentKineticEnergyIdx); + values.setDirichlet(Indices::dissipationIdx); + } } } -- GitLab From b9a22a06cf3cdc5074ac731dd1793a17ed72e5af Mon Sep 17 00:00:00 2001 From: Ned Coltman Date: Wed, 6 May 2020 09:21:37 +0200 Subject: [PATCH 2/6] [test][rans][ransnc] unify turbulent initial ctds with if constexpr --- test/freeflow/rans/problem.hh | 39 ++++++++++++++++----------------- test/freeflow/ransnc/problem.hh | 39 ++++++++++++++++----------------- 2 files changed, 38 insertions(+), 40 deletions(-) diff --git a/test/freeflow/rans/problem.hh b/test/freeflow/rans/problem.hh index 221f3caad4..21f812c220 100644 --- a/test/freeflow/rans/problem.hh +++ b/test/freeflow/rans/problem.hh @@ -324,9 +324,7 @@ public: #endif // turbulence model-specific initial conditions - static constexpr auto numEq = numTurbulenceEq(ModelTraits::turbulenceModel()); - setInitialAtPos_(values, globalPos, Dune::index_constant{}); - + setInitialAtPos_(values, globalPos); return values; } @@ -353,26 +351,27 @@ private: return globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_; } - //! Initial conditions for the zero-eq turbulence model (none) - void setInitialAtPos_(PrimaryVariables& values, const GlobalPosition &globalPos, Dune::index_constant<0>) const {} - - //! Initial conditions for the one-eq turbulence model - void setInitialAtPos_(PrimaryVariables& values, const GlobalPosition &globalPos, Dune::index_constant<1>) const - { - values[Indices::viscosityTildeIdx] = viscosityTilde_; - if (isOnWallAtPos(globalPos)) - values[Indices::viscosityTildeIdx] = 0.0; - } - //! Initial conditions for the komega, kepsilon and lowrekepsilon turbulence models - void setInitialAtPos_(PrimaryVariables& values, const GlobalPosition &globalPos, Dune::index_constant<2>) const + void setInitialAtPos_(PrimaryVariables& values, const GlobalPosition &globalPos) const { - values[Indices::turbulentKineticEnergyIdx] = turbulentKineticEnergy_; - values[Indices::dissipationIdx] = dissipation_; - if (isOnWallAtPos(globalPos)) + if constexpr (numTurbulenceEq(ModelTraits::turbulenceModel()) == 0) // zero equation models + return; + else if constexpr (numTurbulenceEq(ModelTraits::turbulenceModel()) == 1) // one equation models + { + values[Indices::viscosityTildeIdx] = viscosityTilde_; + if (isOnWallAtPos(globalPos)) + values[Indices::viscosityTildeIdx] = 0.0; + } + else // two equation models { - values[Indices::turbulentKineticEnergyIdx] = 0.0; - values[Indices::dissipationIdx] = 0.0; + static_assert(numTurbulenceEq(ModelTraits::turbulenceModel()) == 2, "Only reached by 2eq models"); + values[Indices::turbulentKineticEnergyIdx] = turbulentKineticEnergy_; + values[Indices::dissipationIdx] = dissipation_; + if (isOnWallAtPos(globalPos)) + { + values[Indices::turbulentKineticEnergyIdx] = 0.0; + values[Indices::dissipationIdx] = 0.0; + } } } diff --git a/test/freeflow/ransnc/problem.hh b/test/freeflow/ransnc/problem.hh index 1489864aef..4af9a105e3 100644 --- a/test/freeflow/ransnc/problem.hh +++ b/test/freeflow/ransnc/problem.hh @@ -343,9 +343,7 @@ public: values[Indices::velocityYIdx] = 0.0; // turbulence model-specific initial conditions - static constexpr auto numEq = numTurbulenceEq(ModelTraits::turbulenceModel()); - setInitialAtPos_(values, globalPos, Dune::index_constant{}); - + setInitialAtPos_(values, globalPos); return values; } @@ -372,26 +370,27 @@ private: return globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_; } - //! Initial conditions for the zero-eq turbulence model (none) - void setInitialAtPos_(PrimaryVariables& values, const GlobalPosition &globalPos, Dune::index_constant<0>) const {} - - //! Initial conditions for the one-eq turbulence model - void setInitialAtPos_(PrimaryVariables& values, const GlobalPosition &globalPos, Dune::index_constant<1>) const - { - values[Indices::viscosityTildeIdx] = viscosityTilde_; - if (isOnWallAtPos(globalPos)) - values[Indices::viscosityTildeIdx] = 0.0; - } - //! Initial conditions for the komega, kepsilon and lowrekepsilon turbulence models - void setInitialAtPos_(PrimaryVariables& values, const GlobalPosition &globalPos, Dune::index_constant<2>) const + void setInitialAtPos_(PrimaryVariables& values, const GlobalPosition &globalPos) const { - values[Indices::turbulentKineticEnergyIdx] = turbulentKineticEnergy_; - values[Indices::dissipationIdx] = dissipation_; - if (isOnWallAtPos(globalPos)) + if constexpr (numTurbulenceEq(ModelTraits::turbulenceModel()) == 0) // zero equation models + return; + else if constexpr (numTurbulenceEq(ModelTraits::turbulenceModel()) == 1) // one equation models + { + values[Indices::viscosityTildeIdx] = viscosityTilde_; + if (isOnWallAtPos(globalPos)) + values[Indices::viscosityTildeIdx] = 0.0; + } + else // two equation models { - values[Indices::turbulentKineticEnergyIdx] = 0.0; - values[Indices::dissipationIdx] = 0.0; + static_assert(numTurbulenceEq(ModelTraits::turbulenceModel()) == 2, "Only reached by 2eq models"); + values[Indices::turbulentKineticEnergyIdx] = turbulentKineticEnergy_; + values[Indices::dissipationIdx] = dissipation_; + if (isOnWallAtPos(globalPos)) + { + values[Indices::turbulentKineticEnergyIdx] = 0.0; + values[Indices::dissipationIdx] = 0.0; + } } } -- GitLab From 51b1cbdc81c7c5975710b90a17eb597fa3fcd37a Mon Sep 17 00:00:00 2001 From: Ned Coltman Date: Tue, 5 May 2020 18:03:31 +0200 Subject: [PATCH 3/6] [test][rans][ransnc] unify isDirichletCell function with if constexpr --- test/freeflow/rans/problem.hh | 100 +++++++------------------------- test/freeflow/ransnc/problem.hh | 44 ++++++-------- 2 files changed, 41 insertions(+), 103 deletions(-) diff --git a/test/freeflow/rans/problem.hh b/test/freeflow/rans/problem.hh index 21f812c220..4bfef43a54 100644 --- a/test/freeflow/rans/problem.hh +++ b/test/freeflow/rans/problem.hh @@ -244,11 +244,7 @@ public: const FVElementGeometry& fvGeometry, const SubControlVolume& scv, int pvIdx) const - { - using IsKOmegaKEpsilon = std::integral_constant; - return isDirichletCell_(element, fvGeometry, scv, pvIdx, IsKOmegaKEpsilon{}); - } + { return isDirichletCell_(element, fvGeometry, scv, pvIdx); } /*! * \brief Evaluate the boundary conditions for a dirichlet values at the boundary. @@ -404,84 +400,32 @@ private: } } - //! Forward to ParentType - template - bool isDirichletCell_(const Element& element, - const FVElementGeometry& fvGeometry, - const SubControlVolume& scv, - int pvIdx, - std::false_type) const - { - return ParentType::isDirichletCell(element, fvGeometry, scv, pvIdx); - } - - //! Specialization for the KOmega and KEpsilon Models template bool isDirichletCell_(const Element& element, const FVElementGeometry& fvGeometry, const SubControlVolume& scv, - int pvIdx, - std::true_type) const - { - using SetDirichletCellForBothTurbEq = std::integral_constant; - return isDirichletCellTurbulentTwoEq_(element, fvGeometry, scv, pvIdx, SetDirichletCellForBothTurbEq{}); - } - - //! Specialization for the KEpsilon Model - template - bool isDirichletCellTurbulentTwoEq_(const Element& element, - const FVElementGeometry& fvGeometry, - const SubControlVolume& scv, - int pvIdx, - std::true_type) const - { - const auto eIdx = this->gridGeometry().elementMapper().index(element); - - // set a fixed turbulent kinetic energy and dissipation near the wall - if (this->inNearWallRegion(eIdx)) - return pvIdx == Indices::turbulentKineticEnergyEqIdx || pvIdx == Indices::dissipationEqIdx; - - // set a fixed dissipation at the matching point - if (this->isMatchingPoint(eIdx)) - return pvIdx == Indices::dissipationEqIdx;// set a fixed dissipation (omega) for all cells at the wall - - return false; - } - - //! Specialization for the KOmega Model - template - bool isDirichletCellTurbulentTwoEq_(const Element& element, - const FVElementGeometry& fvGeometry, - const SubControlVolume& scv, - int pvIdx, - std::false_type) const + const int& pvIdx) const { - // set a fixed dissipation (omega) for all cells at the wall - for (const auto& scvf : scvfs(fvGeometry)) - if (isOnWallAtPos(scvf.center()) && pvIdx == Indices::dissipationIdx) - return true; - - return false; - - } - - //! Specialization for the kepsilon - template - PrimaryVariables dirichletTurbulentTwoEq_(const Element& element, - const SubControlVolume& scv, - std::true_type) const - { - const auto globalPos = scv.center(); - PrimaryVariables values(initialAtPos(globalPos)); - unsigned int elementIdx = this->gridGeometry().elementMapper().index(element); - - // fixed value for the turbulent kinetic energy - values[Indices::turbulentKineticEnergyEqIdx] = this->turbulentKineticEnergyWallFunction(elementIdx); - - // fixed value for the dissipation - values[Indices::dissipationEqIdx] = this->dissipationWallFunction(elementIdx); - - return values; + if constexpr (ModelTraits::turbulenceModel() == TurbulenceModel::kepsilon) + { + const auto eIdx = this->gridGeometry().elementMapper().index(element); + // For the kepsilon model we set fixed values within the matching point and at the wall + if (this->inNearWallRegion(eIdx)) + return pvIdx == Indices::turbulentKineticEnergyEqIdx || pvIdx == Indices::dissipationEqIdx; + if (this->isMatchingPoint(eIdx)) + return pvIdx == Indices::dissipationEqIdx; + return false; + } + else if constexpr (ModelTraits::turbulenceModel() == TurbulenceModel::komega) + { + // For the komega model we set a fixed dissipation (omega) for all cells at the wall + for (const auto& scvf : scvfs(fvGeometry)) + if (isOnWallAtPos(scvf.center()) && pvIdx == Indices::dissipationIdx) + return true; + return false; + } + else + return ParentType::isDirichletCell(element, fvGeometry, scv, pvIdx); } //! Specialization for the KOmega diff --git a/test/freeflow/ransnc/problem.hh b/test/freeflow/ransnc/problem.hh index 4af9a105e3..530776ea87 100644 --- a/test/freeflow/ransnc/problem.hh +++ b/test/freeflow/ransnc/problem.hh @@ -483,41 +483,35 @@ private: return false; } - - //! Specialization for the kepsilon - template - PrimaryVariables dirichletTurbulentTwoEq_(const Element& element, - const SubControlVolume& scv, - std::true_type) const { - const auto globalPos = scv.center(); - PrimaryVariables values(initialAtPos(globalPos)); - unsigned int elementIdx = this->gridGeometry().elementMapper().index(element); - - // fixed value for the turbulent kinetic energy - values[Indices::turbulentKineticEnergyEqIdx] = this->turbulentKineticEnergyWallFunction(elementIdx); - - // fixed value for the dissipation - values[Indices::dissipationEqIdx] = this->dissipationWallFunction(elementIdx); - - return values; } - //! Specialization for the KOmega + //! Specialization for the kepsilon and komega template PrimaryVariables dirichletTurbulentTwoEq_(const Element& element, - const SubControlVolume& scv, - std::false_type) const + const SubControlVolume& scv) const { const auto globalPos = scv.center(); PrimaryVariables values(initialAtPos(globalPos)); unsigned int elementIdx = this->gridGeometry().elementMapper().index(element); - const auto wallDistance = ParentType::wallDistance_[elementIdx]; - using std::pow; - values[Indices::dissipationEqIdx] = 6.0 * ParentType::kinematicViscosity_[elementIdx] - / (ParentType::betaOmega() * pow(wallDistance, 2)); - return values; + if constexpr (ModelTraits::turbulenceModel() == TurbulenceModel::kepsilon) + { + // For the kepsilon model we set a fixed value for the turbulent kinetic energy and the dissipation + values[Indices::turbulentKineticEnergyEqIdx] = this->turbulentKineticEnergyWallFunction(elementIdx); + values[Indices::dissipationEqIdx] = this->dissipationWallFunction(elementIdx); + return values; + } + else + { + static_assert(ModelTraits::turbulenceModel() == TurbulenceModel::komega, "Only valid for Komega"); + // For the komega model we set a fixed value for the dissipation + const auto wallDistance = ParentType::wallDistance_[elementIdx]; + using std::pow; + values[Indices::dissipationEqIdx] = 6.0 * ParentType::kinematicViscosity_[elementIdx] + / (ParentType::betaOmega() * pow(wallDistance, 2)); + return values; + } } const Scalar eps_; -- GitLab From e404635611efddff35690a74b985b03423cfcc74 Mon Sep 17 00:00:00 2001 From: Ned Coltman Date: Tue, 5 May 2020 18:04:41 +0200 Subject: [PATCH 4/6] [test][rans][ransnc] unify twoeq dirichlet conditions with if constexpr --- test/freeflow/rans/problem.hh | 59 ++++++++-------- test/freeflow/ransnc/problem.hh | 117 +++++++++----------------------- 2 files changed, 60 insertions(+), 116 deletions(-) diff --git a/test/freeflow/rans/problem.hh b/test/freeflow/rans/problem.hh index 4bfef43a54..6245a4d044 100644 --- a/test/freeflow/rans/problem.hh +++ b/test/freeflow/rans/problem.hh @@ -272,31 +272,17 @@ public: * \param scv the sub control volume * \note used for cell-centered discretization schemes */ - template = 0> PrimaryVariables dirichlet(const Element& element, const SubControlVolume& scv) const { - const auto globalPos = scv.center(); - PrimaryVariables values(initialAtPos(globalPos)); - return values; - } - - /*! - * \brief Evaluate the boundary conditions for fixed values at cell centers - * - * \param element The finite element - * \param scv the sub control volume - * \note used for cell-centered discretization schemes - */ - template = 0> - PrimaryVariables dirichlet(const Element& element, const SubControlVolume& scv) const - { - using SetDirichletCellForBothTurbEq = std::integral_constant; - - return dirichletTurbulentTwoEq_(element, scv, SetDirichletCellForBothTurbEq{}); + if constexpr (ModelTraits::turbulenceModel() == TurbulenceModel::kepsilon + || ModelTraits::turbulenceModel() == TurbulenceModel::komega) + return dirichletTurbulentTwoEq_(element, scv); + else + { + const auto globalPos = scv.center(); + PrimaryVariables values(initialAtPos(globalPos)); + return values; + } } /*! @@ -428,21 +414,32 @@ private: return ParentType::isDirichletCell(element, fvGeometry, scv, pvIdx); } - //! Specialization for the KOmega + //! Specialization for the kepsilon and komega template PrimaryVariables dirichletTurbulentTwoEq_(const Element& element, - const SubControlVolume& scv, - std::false_type) const + const SubControlVolume& scv) const { const auto globalPos = scv.center(); PrimaryVariables values(initialAtPos(globalPos)); unsigned int elementIdx = this->gridGeometry().elementMapper().index(element); - const auto wallDistance = ParentType::wallDistance_[elementIdx]; - using std::pow; - values[Indices::dissipationEqIdx] = 6.0 * ParentType::kinematicViscosity_[elementIdx] - / (ParentType::betaOmega() * pow(wallDistance, 2)); - return values; + if constexpr (ModelTraits::turbulenceModel() == TurbulenceModel::kepsilon) + { + // For the kepsilon model we set a fixed value for the turbulent kinetic energy and the dissipation + values[Indices::turbulentKineticEnergyEqIdx] = this->turbulentKineticEnergyWallFunction(elementIdx); + values[Indices::dissipationEqIdx] = this->dissipationWallFunction(elementIdx); + return values; + } + else + { + static_assert(ModelTraits::turbulenceModel() == TurbulenceModel::komega, "Only valid for Komega"); + // For the komega model we set a fixed value for the dissipation + const auto wallDistance = ParentType::wallDistance_[elementIdx]; + using std::pow; + values[Indices::dissipationEqIdx] = 6.0 * ParentType::kinematicViscosity_[elementIdx] + / (ParentType::betaOmega() * wallDistance * wallDistance); + return values; + } } Scalar eps_; diff --git a/test/freeflow/ransnc/problem.hh b/test/freeflow/ransnc/problem.hh index 530776ea87..92d41877b9 100644 --- a/test/freeflow/ransnc/problem.hh +++ b/test/freeflow/ransnc/problem.hh @@ -253,11 +253,7 @@ public: const FVElementGeometry& fvGeometry, const SubControlVolume& scv, int pvIdx) const - { - using IsKOmegaKEpsilon = std::integral_constant; - return isDirichletCell_(element, fvGeometry, scv, pvIdx, IsKOmegaKEpsilon{}); - } + { return isDirichletCell_(element, fvGeometry, scv, pvIdx); } /*! * \brief Evaluate the boundary conditions for a dirichlet values at the boundary. @@ -295,31 +291,17 @@ public: * \param scv the sub control volume * \note used for cell-centered discretization schemes */ - template = 0> - PrimaryVariables dirichlet(const Element& element, const SubControlVolume& scv) const - { - const auto globalPos = scv.center(); - PrimaryVariables values(initialAtPos(globalPos)); - return values; - } - - /*! - * \brief Evaluate the boundary conditions for fixed values at cell centers - * - * \param element The finite element - * \param scv the sub control volume - * \note used for cell-centered discretization schemes - */ - template = 0> PrimaryVariables dirichlet(const Element& element, const SubControlVolume& scv) const { - using SetDirichletCellForBothTurbEq = std::integral_constant; - - return dirichletTurbulentTwoEq_(element, scv, SetDirichletCellForBothTurbEq{}); + if constexpr (ModelTraits::turbulenceModel() == TurbulenceModel::kepsilon + || ModelTraits::turbulenceModel() == TurbulenceModel::komega) + return dirichletTurbulentTwoEq_(element, scv); + else + { + const auto globalPos = scv.center(); + PrimaryVariables values(initialAtPos(globalPos)); + return values; + } } /*! @@ -423,67 +405,32 @@ private: } } - //! Forward to ParentType template bool isDirichletCell_(const Element& element, const FVElementGeometry& fvGeometry, const SubControlVolume& scv, - int pvIdx, - std::false_type) const - { - return ParentType::isDirichletCell(element, fvGeometry, scv, pvIdx); - } - - //! Specialization for the KOmega and KEpsilon Models - template - bool isDirichletCell_(const Element& element, - const FVElementGeometry& fvGeometry, - const SubControlVolume& scv, - int pvIdx, - std::true_type) const - { - using SetDirichletCellForBothTurbEq = std::integral_constant; - return isDirichletCellTurbulentTwoEq_(element, fvGeometry, scv, pvIdx, SetDirichletCellForBothTurbEq{}); - } - - //! Specialization for the KEpsilon Model - template - bool isDirichletCellTurbulentTwoEq_(const Element& element, - const FVElementGeometry& fvGeometry, - const SubControlVolume& scv, - int pvIdx, - std::true_type) const - { - const auto eIdx = this->gridGeometry().elementMapper().index(element); - - // set a fixed turbulent kinetic energy and dissipation near the wall - if (this->inNearWallRegion(eIdx)) - return pvIdx == Indices::turbulentKineticEnergyEqIdx || pvIdx == Indices::dissipationEqIdx; - - // set a fixed dissipation at the matching point - if (this->isMatchingPoint(eIdx)) - return pvIdx == Indices::dissipationEqIdx;// set a fixed dissipation (omega) for all cells at the wall - - return false; - } - - //! Specialization for the KOmega Model - template - bool isDirichletCellTurbulentTwoEq_(const Element& element, - const FVElementGeometry& fvGeometry, - const SubControlVolume& scv, - int pvIdx, - std::false_type) const - { - // set a fixed dissipation (omega) for all cells at the wall - for (const auto& scvf : scvfs(fvGeometry)) - if (isOnWallAtPos(scvf.center()) && pvIdx == Indices::dissipationIdx) - return true; - - return false; - - } + const int& pvIdx) const { + if constexpr (ModelTraits::turbulenceModel() == TurbulenceModel::kepsilon) + { + const auto eIdx = this->gridGeometry().elementMapper().index(element); + // For the kepsilon model we set fixed values within the matching point and at the wall + if (this->inNearWallRegion(eIdx)) + return pvIdx == Indices::turbulentKineticEnergyEqIdx || pvIdx == Indices::dissipationEqIdx; + if (this->isMatchingPoint(eIdx)) + return pvIdx == Indices::dissipationEqIdx; + return false; + } + else if constexpr (ModelTraits::turbulenceModel() == TurbulenceModel::komega) + { + // For the komega model we set a fixed dissipation (omega) for all cells at the wall + for (const auto& scvf : scvfs(fvGeometry)) + if (isOnWallAtPos(scvf.center()) && pvIdx == Indices::dissipationIdx) + return true; + return false; + } + else + return ParentType::isDirichletCell(element, fvGeometry, scv, pvIdx); } //! Specialization for the kepsilon and komega @@ -509,7 +456,7 @@ private: const auto wallDistance = ParentType::wallDistance_[elementIdx]; using std::pow; values[Indices::dissipationEqIdx] = 6.0 * ParentType::kinematicViscosity_[elementIdx] - / (ParentType::betaOmega() * pow(wallDistance, 2)); + / (ParentType::betaOmega() * wallDistance * wallDistance); return values; } } -- GitLab From fc9414678cd8e48fabb85a323de11d067ca4168c Mon Sep 17 00:00:00 2001 From: Ned Coltman Date: Wed, 6 May 2020 09:18:07 +0200 Subject: [PATCH 5/6] [test][rans][ransnc] clean up spacing style --- test/freeflow/rans/problem.hh | 24 +++++------------------- test/freeflow/ransnc/problem.hh | 22 +++++----------------- 2 files changed, 10 insertions(+), 36 deletions(-) diff --git a/test/freeflow/rans/problem.hh b/test/freeflow/rans/problem.hh index 6245a4d044..f4ef334132 100644 --- a/test/freeflow/rans/problem.hh +++ b/test/freeflow/rans/problem.hh @@ -72,7 +72,6 @@ struct PipeLauferNILowReKEpsilon { using InheritsFrom = std::tuple; }; } // end namespace TTag - // the fluid system template struct FluidSystem @@ -181,9 +180,7 @@ public: } Scalar sandGrainRoughnessAtPos(const GlobalPosition &globalPos) const - { - return sandGrainRoughness_; - } + { return sandGrainRoughness_; } /*! * \brief Returns the temperature [K] within the domain for the isothermal model. @@ -224,7 +221,6 @@ public: else values.setDirichlet(Indices::temperatureIdx); #endif - // turbulence model-specific boundary types setBcTypes_(values, globalPos); @@ -300,11 +296,9 @@ public: : time() / initializationTime_ * inletVelocity_; if (isOnWallAtPos(globalPos)) values[Indices::velocityXIdx] = 0.0; - #if NONISOTHERMAL values[Indices::temperatureIdx] = isOnWallAtPos(globalPos) ? wallTemperature_ : inletTemperature_; #endif - // turbulence model-specific initial conditions setInitialAtPos_(values, globalPos); return values; @@ -313,25 +307,17 @@ public: // \} void setTimeLoop(TimeLoopPtr timeLoop) - { - timeLoop_ = timeLoop; - } + { timeLoop_ = timeLoop; } Scalar time() const - { - return timeLoop_->time(); - } + { return timeLoop_->time(); } private: bool isInlet_(const GlobalPosition& globalPos) const - { - return globalPos[0] < this->gridGeometry().bBoxMin()[0] + eps_; - } + { return globalPos[0] < this->gridGeometry().bBoxMin()[0] + eps_; } bool isOutlet_(const GlobalPosition& globalPos) const - { - return globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_; - } + { return globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_; } //! Initial conditions for the komega, kepsilon and lowrekepsilon turbulence models void setInitialAtPos_(PrimaryVariables& values, const GlobalPosition &globalPos) const diff --git a/test/freeflow/ransnc/problem.hh b/test/freeflow/ransnc/problem.hh index 92d41877b9..b7f657915b 100644 --- a/test/freeflow/ransnc/problem.hh +++ b/test/freeflow/ransnc/problem.hh @@ -177,9 +177,7 @@ public: // \{ bool isOnWallAtPos(const GlobalPosition& globalPos) const - { - return globalPos[1] < eps_; - } + { return globalPos[1] < eps_; } /*! * \brief Returns the temperature within the domain in [K]. @@ -273,7 +271,6 @@ public: { values[transportCompIdx] = (time() > 10.0) ? inletMoleFraction_ : 0.0; } - #if NONISOTHERMAL if (time() > 10.0 && isOnWallAtPos(globalPos)) { @@ -317,7 +314,6 @@ public: #if NONISOTHERMAL values[Indices::temperatureIdx] = temperature(); #endif - // block velocity profile values[Indices::velocityXIdx] = 0.0; if (!isOnWallAtPos(globalPos)) @@ -332,25 +328,17 @@ public: // \} void setTimeLoop(TimeLoopPtr timeLoop) - { - timeLoop_ = timeLoop; - } + { timeLoop_ = timeLoop; } Scalar time() const - { - return timeLoop_->time(); - } + { return timeLoop_->time(); } private: bool isInlet_(const GlobalPosition& globalPos) const - { - return globalPos[0] < eps_; - } + { return globalPos[0] < eps_; } bool isOutlet_(const GlobalPosition& globalPos) const - { - return globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_; - } + { return globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_; } //! Initial conditions for the komega, kepsilon and lowrekepsilon turbulence models void setInitialAtPos_(PrimaryVariables& values, const GlobalPosition &globalPos) const -- GitLab From de9cfc6fd6c7a2f1e7384457272961b669a44097 Mon Sep 17 00:00:00 2001 From: Ned Coltman Date: Thu, 7 May 2020 17:27:39 +0200 Subject: [PATCH 6/6] [test][rans][ransnc] add maybe_unused to appease compiler warnings --- test/freeflow/rans/problem.hh | 14 ++++++++------ test/freeflow/ransnc/problem.hh | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/test/freeflow/rans/problem.hh b/test/freeflow/rans/problem.hh index f4ef334132..9f1ff50c56 100644 --- a/test/freeflow/rans/problem.hh +++ b/test/freeflow/rans/problem.hh @@ -268,7 +268,7 @@ public: * \param scv the sub control volume * \note used for cell-centered discretization schemes */ - PrimaryVariables dirichlet(const Element& element, const SubControlVolume& scv) const + PrimaryVariables dirichlet([[maybe_unused]] const Element& element, const SubControlVolume& scv) const { if constexpr (ModelTraits::turbulenceModel() == TurbulenceModel::kepsilon || ModelTraits::turbulenceModel() == TurbulenceModel::komega) @@ -320,7 +320,8 @@ private: { return globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_; } //! Initial conditions for the komega, kepsilon and lowrekepsilon turbulence models - void setInitialAtPos_(PrimaryVariables& values, const GlobalPosition &globalPos) const + void setInitialAtPos_([[maybe_unused]] PrimaryVariables& values, + [[maybe_unused]] const GlobalPosition &globalPos) const { if constexpr (numTurbulenceEq(ModelTraits::turbulenceModel()) == 0) // zero equation models return; @@ -344,7 +345,8 @@ private: } //! Boundary condition types for the one-eq turbulence model - void setBcTypes_(BoundaryTypes& values, const GlobalPosition& pos) const + void setBcTypes_([[maybe_unused]] BoundaryTypes& values, + [[maybe_unused]] const GlobalPosition& pos) const { if constexpr (numTurbulenceEq(ModelTraits::turbulenceModel()) == 0) // zero equation models return; @@ -373,14 +375,14 @@ private: } template - bool isDirichletCell_(const Element& element, + bool isDirichletCell_([[maybe_unused]] const Element& element, const FVElementGeometry& fvGeometry, - const SubControlVolume& scv, + [[maybe_unused]] const SubControlVolume& scv, const int& pvIdx) const { if constexpr (ModelTraits::turbulenceModel() == TurbulenceModel::kepsilon) { - const auto eIdx = this->gridGeometry().elementMapper().index(element); + const auto eIdx = fvGeometry.gridGeometry().elementMapper().index(element); // For the kepsilon model we set fixed values within the matching point and at the wall if (this->inNearWallRegion(eIdx)) return pvIdx == Indices::turbulentKineticEnergyEqIdx || pvIdx == Indices::dissipationEqIdx; diff --git a/test/freeflow/ransnc/problem.hh b/test/freeflow/ransnc/problem.hh index b7f657915b..e5eb177b19 100644 --- a/test/freeflow/ransnc/problem.hh +++ b/test/freeflow/ransnc/problem.hh @@ -288,7 +288,7 @@ public: * \param scv the sub control volume * \note used for cell-centered discretization schemes */ - PrimaryVariables dirichlet(const Element& element, const SubControlVolume& scv) const + PrimaryVariables dirichlet([[maybe_unused]] const Element& element, const SubControlVolume& scv) const { if constexpr (ModelTraits::turbulenceModel() == TurbulenceModel::kepsilon || ModelTraits::turbulenceModel() == TurbulenceModel::komega) @@ -341,7 +341,8 @@ private: { return globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_; } //! Initial conditions for the komega, kepsilon and lowrekepsilon turbulence models - void setInitialAtPos_(PrimaryVariables& values, const GlobalPosition &globalPos) const + void setInitialAtPos_([[maybe_unused]] PrimaryVariables& values, + [[maybe_unused]] const GlobalPosition &globalPos) const { if constexpr (numTurbulenceEq(ModelTraits::turbulenceModel()) == 0) // zero equation models return; @@ -365,7 +366,8 @@ private: } //! Boundary condition types for the one-eq turbulence model - void setBcTypes_(BoundaryTypes& values, const GlobalPosition& pos) const + void setBcTypes_([[maybe_unused]] BoundaryTypes& values, + [[maybe_unused]] const GlobalPosition& pos) const { if constexpr (numTurbulenceEq(ModelTraits::turbulenceModel()) == 0) // zero equation models return; @@ -394,14 +396,14 @@ private: } template - bool isDirichletCell_(const Element& element, + bool isDirichletCell_([[maybe_unused]] const Element& element, const FVElementGeometry& fvGeometry, - const SubControlVolume& scv, + [[maybe_unused]] const SubControlVolume& scv, const int& pvIdx) const { if constexpr (ModelTraits::turbulenceModel() == TurbulenceModel::kepsilon) { - const auto eIdx = this->gridGeometry().elementMapper().index(element); + const auto eIdx = fvGeometry.gridGeometry().elementMapper().index(element); // For the kepsilon model we set fixed values within the matching point and at the wall if (this->inNearWallRegion(eIdx)) return pvIdx == Indices::turbulentKineticEnergyEqIdx || pvIdx == Indices::dissipationEqIdx; -- GitLab