From 2a4a135fe58db52ba55b85c53a239186070e55d1 Mon Sep 17 00:00:00 2001
From: Thomas Fetzer <thomas.fetzer@iws.uni-stuttgart.de>
Date: Wed, 23 May 2018 13:25:24 +0200
Subject: [PATCH] [lowrekepsilon] Improve usage of indices

---
 .../lowrekepsilon/staggered/fluxvariables.hh   | 18 ++++++++----------
 .../lowrekepsilon/staggered/localresidual.hh   |  8 +++-----
 2 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/dumux/freeflow/rans/twoeq/lowrekepsilon/staggered/fluxvariables.hh b/dumux/freeflow/rans/twoeq/lowrekepsilon/staggered/fluxvariables.hh
index 7abc55a283..49fd961eca 100644
--- a/dumux/freeflow/rans/twoeq/lowrekepsilon/staggered/fluxvariables.hh
+++ b/dumux/freeflow/rans/twoeq/lowrekepsilon/staggered/fluxvariables.hh
@@ -71,10 +71,8 @@ class LowReKEpsilonFluxVariablesImpl<TypeTag, BaseFluxVariables, DiscretizationM
     using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
     using CellCenterPrimaryVariables = typename GET_PROP_TYPE(TypeTag, CellCenterPrimaryVariables);
 
-    enum {
-        turbulentKineticEnergyEqIdx = Indices::turbulentKineticEnergyEqIdx,
-        dissipationEqIdx = Indices::dissipationEqIdx,
-    };
+    static constexpr int turbulentKineticEnergyEqIdx = Indices::turbulentKineticEnergyEqIdx - ModelTraits::dim();
+    static constexpr int dissipationEqIdx = Indices::dissipationEqIdx - ModelTraits::dim();
 
 public:
 
@@ -102,9 +100,9 @@ public:
             return volVars.dissipationTilde();
         };
 
-        flux[turbulentKineticEnergyEqIdx - ModelTraits::dim()]
+        flux[turbulentKineticEnergyEqIdx]
             = ParentType::advectiveFluxForCellCenter(problem, elemVolVars, elemFaceVars, scvf, upwindTermK);
-        flux[dissipationEqIdx - ModelTraits::dim()]
+        flux[dissipationEqIdx]
             = ParentType::advectiveFluxForCellCenter(problem, elemVolVars, elemFaceVars, scvf, upwindTermEpsilon);
 
         // calculate diffusive flux
@@ -147,18 +145,18 @@ public:
         }
 
         const auto bcTypes = problem.boundaryTypes(element, scvf);
-        if (!(scvf.boundary() && (bcTypes.isOutflow(turbulentKineticEnergyEqIdx)
+        if (!(scvf.boundary() && (bcTypes.isOutflow(Indices::turbulentKineticEnergyEqIdx)
                                   || bcTypes.isSymmetry())))
         {
-            flux[turbulentKineticEnergyEqIdx - ModelTraits::dim()]
+            flux[turbulentKineticEnergyEqIdx]
                 += coeff_k / distance
                    * (insideVolVars.turbulentKineticEnergy() - outsideVolVars.turbulentKineticEnergy())
                    * scvf.area();
         }
-        if (!(scvf.boundary() && (bcTypes.isOutflow(dissipationEqIdx)
+        if (!(scvf.boundary() && (bcTypes.isOutflow(Indices::dissipationEqIdx)
                                   || bcTypes.isSymmetry())))
         {
-            flux[dissipationEqIdx - ModelTraits::dim()]
+            flux[dissipationEqIdx]
                 += coeff_e / distance
                    * (insideVolVars.dissipationTilde() - outsideVolVars.dissipationTilde())
                    * scvf.area();
diff --git a/dumux/freeflow/rans/twoeq/lowrekepsilon/staggered/localresidual.hh b/dumux/freeflow/rans/twoeq/lowrekepsilon/staggered/localresidual.hh
index df8afddffe..41f4137db2 100644
--- a/dumux/freeflow/rans/twoeq/lowrekepsilon/staggered/localresidual.hh
+++ b/dumux/freeflow/rans/twoeq/lowrekepsilon/staggered/localresidual.hh
@@ -69,6 +69,9 @@ class LowReKEpsilonResidualImpl<TypeTag, BaseLocalResidual, DiscretizationMethod
     using BoundaryTypes = typename GET_PROP_TYPE(TypeTag, BoundaryTypes);
     using ModelTraits = typename GET_PROP_TYPE(TypeTag, ModelTraits);
 
+    static constexpr int turbulentKineticEnergyEqIdx = Indices::turbulentKineticEnergyEqIdx - ModelTraits::dim();
+    static constexpr int dissipationEqIdx = Indices::dissipationEqIdx - ModelTraits::dim();
+
 public:
     using ParentType::ParentType;
 
@@ -79,8 +82,6 @@ public:
     {
         CellCenterPrimaryVariables storage = ParentType::computeStorageForCellCenter(problem, scv, volVars);
 
-        static constexpr int turbulentKineticEnergyEqIdx = Indices::turbulentKineticEnergyEqIdx - ModelTraits::dim();
-        static constexpr int dissipationEqIdx = Indices::dissipationEqIdx - ModelTraits::dim();
         storage[turbulentKineticEnergyEqIdx] = volVars.turbulentKineticEnergy();
         storage[dissipationEqIdx] = volVars.dissipationTilde();
 
@@ -99,9 +100,6 @@ public:
 
         const auto& volVars = elemVolVars[scv];
 
-        static constexpr int turbulentKineticEnergyEqIdx = Indices::turbulentKineticEnergyEqIdx - ModelTraits::dim();
-        static constexpr int dissipationEqIdx = Indices::dissipationEqIdx - ModelTraits::dim();
-
         // production
         source[turbulentKineticEnergyEqIdx] += 2.0 * volVars.kinematicEddyViscosity()
                                                * volVars.stressTensorScalarProduct();
-- 
GitLab