From d834ddee6e1a75c42f097dc3217151e5da115a79 Mon Sep 17 00:00:00 2001
From: Thomas Fetzer <thomas.fetzer@iws.uni-stuttgart.de>
Date: Fri, 12 Jan 2018 20:09:02 +0100
Subject: [PATCH] [rans][zeroeq] Implement a generic zeroeq model framework

---
 dumux/common/parameters.hh                    |   3 +
 dumux/freeflow/rans/CMakeLists.txt            |   2 +
 dumux/freeflow/rans/volumevariables.hh        |  47 ++++--
 dumux/freeflow/rans/zeroeq/CMakeLists.txt     |   6 +
 dumux/freeflow/rans/zeroeq/indices.hh         |  49 +++++++
 dumux/freeflow/rans/zeroeq/model.hh           |  79 ++++++++++
 dumux/freeflow/rans/zeroeq/volumevariables.hh | 138 ++++++++++++++++++
 test/freeflow/rans/pipelauferproblem.hh       |   4 +-
 test/freeflow/rans/test_pipe_laufer.input     |   3 +
 9 files changed, 317 insertions(+), 14 deletions(-)
 create mode 100644 dumux/freeflow/rans/zeroeq/CMakeLists.txt
 create mode 100644 dumux/freeflow/rans/zeroeq/indices.hh
 create mode 100644 dumux/freeflow/rans/zeroeq/model.hh
 create mode 100644 dumux/freeflow/rans/zeroeq/volumevariables.hh

diff --git a/dumux/common/parameters.hh b/dumux/common/parameters.hh
index d954c3e98f..3ca91d5bbd 100644
--- a/dumux/common/parameters.hh
+++ b/dumux/common/parameters.hh
@@ -259,6 +259,9 @@ private:
 
         // parameters in the mpfa group
         params["Mpfa.Q"] = "0.0";
+
+        // parameters in the freeflow group
+        params["FreeFlow.EddyViscosityModel"] = "1";
     }
 };
 
diff --git a/dumux/freeflow/rans/CMakeLists.txt b/dumux/freeflow/rans/CMakeLists.txt
index 386564fc51..b1ccda770b 100644
--- a/dumux/freeflow/rans/CMakeLists.txt
+++ b/dumux/freeflow/rans/CMakeLists.txt
@@ -1,3 +1,5 @@
+add_subdirectory("zeroeq")
+
 #install headers
 install(FILES
 model.hh
diff --git a/dumux/freeflow/rans/volumevariables.hh b/dumux/freeflow/rans/volumevariables.hh
index 2f90b5859f..a6b3d8ab52 100644
--- a/dumux/freeflow/rans/volumevariables.hh
+++ b/dumux/freeflow/rans/volumevariables.hh
@@ -83,9 +83,16 @@ public:
                 const SubControlVolume& scv)
     {
         ParentType::update(elemSol, problem, element, scv);
-        dynamicEddyViscosity_ = std::max(0.0, scv.dofPosition()[1] * (0.2469 - scv.dofPosition()[1])); // TODO preliminary
+        setDynamicEddyViscosity(0.0);
     };
 
+    /*!
+     * \brief Set the values of the dynamic eddy viscosity \f$\mathrm{[Pa s]}\f$ within the
+     *        control volume.
+     */
+    void setDynamicEddyViscosity(Scalar value)
+    { dynamicEddyViscosity_ = value; }
+
     /*!
      * \brief Return the dynamic eddy viscosity \f$\mathrm{[Pa s]}\f$ of the flow within the
      *        control volume.
@@ -110,7 +117,6 @@ private:
     { return *static_cast<const Implementation *>(this); }
 
 protected:
-    FluidState fluidState_;
     Scalar dynamicEddyViscosity_;
 };
 
@@ -155,28 +161,42 @@ public:
                 const Element &element,
                 const SubControlVolume &scv)
     {
-        update(elemSol, problem, element, scv);
+        ParentTypeIsothermal::update(elemSol, problem, element, scv);
+        ParentTypeNonIsothermal::update(elemSol, problem, element, scv);
+        calculateEddyViscosity(elemSol, problem, element, scv);
     }
 
     /*!
-     * \brief Update the fluid state
+     * \brief Calculate the eddy thermal conductivity
+     *
+     * \param elemSol A vector containing all primary variables connected to the element
+     * \param problem The object specifying the problem which ought to
+     *                be simulated
+     * \param element An element which contains part of the control volume
+     * \param scv The sub-control volume
      */
-    static void completeFluidState(const ElementSolutionVector& elemSol,
-                                   const Problem& problem,
-                                   const Element& element,
-                                   const SubControlVolume& scv,
-                                   FluidState& fluidState)
+    void calculateEddyViscosity(const ElementSolutionVector &elemSol,
+                                const Problem &problem,
+                                const Element &element,
+                                const SubControlVolume &scv)
     {
-        ParentTypeIsothermal::completeFluidState(elemSol, problem, element, scv, fluidState);
-        ParentTypeNonIsothermal::completeFluidState(elemSol, problem, element, scv, fluidState);
+        // TODO convert mit Prandtl number etc.
+        eddyThermalConductivity_(ParentTypeIsothermal::dynamicEddyViscosity_());
     }
 
+    /*!
+     * \brief Sets the eddy thermal conductivity \f$\mathrm{[W/(m*K)]}\f$
+     *        of the flow phase in the sub-control volume.
+     */
+    void setEddyThermalConductivity(Scalar value)
+    { eddyThermalConductivity_ = value; }
+
     /*!
      * \brief Returns the eddy thermal conductivity \f$\mathrm{[W/(m*K)]}\f$
      *        of the flow phase in the sub-control volume.
      */
     Scalar eddyThermalConductivity() const
-    { return ParentTypeIsothermal::dynamicEddyViscosity_(); }
+    { return eddyThermalConductivity_; }
 
     /*!
      * \brief Returns the effective thermal conductivity \f$\mathrm{[W/(m*K)]}\f$
@@ -187,6 +207,9 @@ public:
         return FluidSystem::thermalConductivity(this->fluidState_, defaultPhaseIdx)
                + eddyThermalConductivity();
     }
+
+protected:
+    Scalar eddyThermalConductivity_;
 };
 }
 
diff --git a/dumux/freeflow/rans/zeroeq/CMakeLists.txt b/dumux/freeflow/rans/zeroeq/CMakeLists.txt
new file mode 100644
index 0000000000..811156a459
--- /dev/null
+++ b/dumux/freeflow/rans/zeroeq/CMakeLists.txt
@@ -0,0 +1,6 @@
+#install headers
+install(FILES
+indices.hh
+model.hh
+volumevariables.hh
+DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dumux/freeflow/rans/zeroeq)
diff --git a/dumux/freeflow/rans/zeroeq/indices.hh b/dumux/freeflow/rans/zeroeq/indices.hh
new file mode 100644
index 0000000000..1ed103ffe9
--- /dev/null
+++ b/dumux/freeflow/rans/zeroeq/indices.hh
@@ -0,0 +1,49 @@
+// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+// vi: set et ts=4 sw=4 sts=4:
+/*****************************************************************************
+ *   See the file COPYING for full copying permissions.                      *
+ *                                                                           *
+ *   This program is free software: you can redistribute it and/or modify    *
+ *   it under the terms of the GNU General Public License as published by    *
+ *   the Free Software Foundation, either version 2 of the License, or       *
+ *   (at your option) any later version.                                     *
+ *                                                                           *
+ *   This program is distributed in the hope that it will be useful,         *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
+ *   GNU General Public License for more details.                            *
+ *                                                                           *
+ *   You should have received a copy of the GNU General Public License       *
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
+ *****************************************************************************/
+/*!
+ * \file
+ * \ingroup ZeroEqModel
+ * \copydoc Dumux::ZeroEqIndices
+ */
+#ifndef DUMUX_ZEROEQ_INDICES_HH
+#define DUMUX_ZEROEQ_INDICES_HH
+
+#include <dumux/freeflow/navierstokes/indices.hh>
+
+namespace Dumux
+{
+// \{
+/*!
+ * \ingroup ZeroEqModel
+ * \brief The common indices for the isothermal ZeroEq model.
+ *
+ * \tparam PVOffset The first index in a primary variable vector.
+ */
+template <class TypeTag, int PVOffset = 0>
+struct ZeroEqIndices
+    : NavierStokesIndices<TypeTag, PVOffset>
+{
+    static constexpr int noEddyViscosityModel = 0;
+    static constexpr int prandtl = 1;
+};
+
+// \}
+} // end namespace
+
+#endif
diff --git a/dumux/freeflow/rans/zeroeq/model.hh b/dumux/freeflow/rans/zeroeq/model.hh
new file mode 100644
index 0000000000..5fe8773552
--- /dev/null
+++ b/dumux/freeflow/rans/zeroeq/model.hh
@@ -0,0 +1,79 @@
+// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+// vi: set et ts=4 sw=4 sts=4:
+/*****************************************************************************
+ *   See the file COPYING for full copying permissions.                      *
+ *                                                                           *
+ *   This program is free software: you can redistribute it and/or modify    *
+ *   it under the terms of the GNU General Public License as published by    *
+ *   the Free Software Foundation, either version 2 of the License, or       *
+ *   (at your option) any later version.                                     *
+ *                                                                           *
+ *   This program is distributed in the hope that it will be useful,         *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
+ *   GNU General Public License for more details.                            *
+ *                                                                           *
+ *   You should have received a copy of the GNU General Public License       *
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
+ *****************************************************************************/
+/*!
+ * \file
+ * \ingroup ZeroEqModel
+ *
+ * \brief A single-phase, isothermal Reynolds-Averaged Navier-Stokes 0-Eq. model
+ *
+ * These models calculate the eddy viscosity without solving additional PDEs,
+ * only based on the wall distance and the velocity gradient.
+ * The following models are available:
+ * \todo list implemented 0-Eq. models
+ */
+
+#ifndef DUMUX_ZEROEQ_MODEL_HH
+#define DUMUX_ZEROEQ_MODEL_HH
+
+#include <dumux/common/properties.hh>
+#include <dumux/freeflow/properties.hh>
+#include <dumux/freeflow/rans/model.hh>
+
+#include "indices.hh"
+#include "volumevariables.hh"
+// #include "vtkoutputfields.hh"
+
+namespace Dumux
+{
+
+// \{
+///////////////////////////////////////////////////////////////////////////
+// properties for the single-phase Reynolds-Averaged Navier-Stokes 0-Eq. model
+///////////////////////////////////////////////////////////////////////////
+namespace Properties {
+
+//////////////////////////////////////////////////////////////////
+// Type tags
+//////////////////////////////////////////////////////////////////
+
+//! The type tag for the single-phase, isothermal Reynolds-Averaged Navier-Stokes 0-Eq. model
+NEW_TYPE_TAG(ZeroEq, INHERITS_FROM(RANS));
+
+//! The type tag for the corresponding non-isothermal model
+NEW_TYPE_TAG(ZeroEqNI, INHERITS_FROM(ZeroEq, RANSNI));
+
+///////////////////////////////////////////////////////////////////////////
+// default property values for the isothermal single phase model
+///////////////////////////////////////////////////////////////////////////
+
+//! use the global group as default for the model's parameter group
+// SET_STRING_PROP(ModelProperties, ModelParameterGroup, "ZeroEq");
+
+//! The indices
+SET_TYPE_PROP(ZeroEq, Indices, ZeroEqIndices<TypeTag>);
+
+//! The volume variables
+SET_TYPE_PROP(ZeroEq, VolumeVariables, ZeroEqVolumeVariables<TypeTag>);
+
+// \}
+}
+
+} // end namespace
+
+#endif // DUMUX_ZEROEQ_MODEL_HH
diff --git a/dumux/freeflow/rans/zeroeq/volumevariables.hh b/dumux/freeflow/rans/zeroeq/volumevariables.hh
new file mode 100644
index 0000000000..48d660ab61
--- /dev/null
+++ b/dumux/freeflow/rans/zeroeq/volumevariables.hh
@@ -0,0 +1,138 @@
+// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+// vi: set et ts=4 sw=4 sts=4:
+/*****************************************************************************
+ *   See the file COPYING for full copying permissions.                      *
+ *                                                                           *
+ *   This program is free software: you can redistribute it and/or modify    *
+ *   it under the terms of the GNU General Public License as published by    *
+ *   the Free Software Foundation, either version 2 of the License, or       *
+ *   (at your option) any later version.                                     *
+ *                                                                           *
+ *   This program is distributed in the hope that it will be useful,         *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
+ *   GNU General Public License for more details.                            *
+ *                                                                           *
+ *   You should have received a copy of the GNU General Public License       *
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
+ *****************************************************************************/
+/*!
+ * \file
+ * \ingroup ZeroEqModel
+ *
+ * \copydoc Dumux::ZEROEQVolumeVariables
+ */
+#ifndef DUMUX_ZEROEQ_VOLUME_VARIABLES_HH
+#define DUMUX_ZEROEQ_VOLUME_VARIABLES_HH
+
+#include <dumux/common/properties.hh>
+#include <dumux/material/fluidstates/immiscible.hh>
+
+namespace Dumux
+{
+
+// forward declaration
+template <class TypeTag, bool enableEnergyBalance>
+class ZeroEqVolumeVariablesImplementation;
+
+/*!
+ * \ingroup Reynolds-Averaged NavierStokesModel
+ * \brief Volume variables for the single-phase Reynolds-Averaged Navier-Stokes model.
+ *        The class is specialized for isothermal and non-isothermal models.
+ */
+template <class TypeTag>
+using ZeroEqVolumeVariables = ZeroEqVolumeVariablesImplementation<TypeTag, GET_PROP_VALUE(TypeTag, EnableEnergyBalance)>;
+
+/*!
+ * \ingroup Reynolds-Averaged NavierStokesModel
+ * \brief Volume variables for the isothermal single-phase Reynolds-Averaged Navier-Stokes model.
+ */
+template <class TypeTag>
+class ZeroEqVolumeVariablesImplementation<TypeTag, false>
+: public RANSVolumeVariablesImplementation<TypeTag, false>
+{
+    using ParentType = NavierStokesVolumeVariablesImplementation<TypeTag, false>;
+    using Implementation = typename GET_PROP_TYPE(TypeTag, VolumeVariables);
+    using Scalar = typename GET_PROP_TYPE(TypeTag, Scalar);
+    using Problem = typename GET_PROP_TYPE(TypeTag, Problem);
+    using SubControlVolume = typename GET_PROP_TYPE(TypeTag, SubControlVolume);
+    using ElementSolutionVector = typename GET_PROP_TYPE(TypeTag, ElementSolutionVector);
+    using Indices = typename GET_PROP_TYPE(TypeTag, Indices);
+    using FluidSystem = typename GET_PROP_TYPE(TypeTag, FluidSystem);
+    using GridView = typename GET_PROP_TYPE(TypeTag, GridView);
+    using Element = typename GridView::template Codim<0>::Entity;
+
+    static const int defaultPhaseIdx = GET_PROP_VALUE(TypeTag, PhaseIdx);
+
+public:
+    ZeroEqVolumeVariablesImplementation()
+    {
+        eddyViscosityModel_ = getParamFromGroup<int>(GET_PROP_VALUE(TypeTag, ModelParameterGroup),
+                                                     "FreeFlow.EddyViscosityModel");
+    }
+
+    /*!
+     * \brief Update all quantities for a given control volume
+     *
+     * \param elemSol A vector containing all primary variables connected to the element
+     * \param problem The object specifying the problem which ought to
+     *                be simulated
+     * \param element An element which contains part of the control volume
+     * \param scv The sub-control volume
+     */
+    void update(const ElementSolutionVector &elemSol,
+                const Problem &problem,
+                const Element &element,
+                const SubControlVolume& scv)
+    {
+        ParentType::update(elemSol, problem, element, scv);
+        calculateEddyViscosity(elemSol, problem, element, scv);
+    };
+
+
+    /*!
+     * \brief Calculate the eddy viscosity
+     *
+     * \param elemSol A vector containing all primary variables connected to the element
+     * \param problem The object specifying the problem which ought to
+     *                be simulated
+     * \param element An element which contains part of the control volume
+     * \param scv The sub-control volume
+     */
+    void calculateEddyViscosity(const ElementSolutionVector &elemSol,
+                                const Problem &problem,
+                                const Element &element,
+                                const SubControlVolume& scv)
+    {
+        Scalar kinematicEddyViscosity = 0.0;
+        if (eddyViscosityModel_ == Indices::prandtl)
+        {
+            kinematicEddyViscosity = std::max(0.0, scv.dofPosition()[1] * (0.2469 - scv.dofPosition()[1])); // TODO preliminary
+        }
+        asImp_().setDynamicEddyViscosity(kinematicEddyViscosity * asImp_().density(defaultPhaseIdx));
+    }
+
+private:
+    //! Returns the implementation of the problem (i.e. static polymorphism)
+    Implementation &asImp_()
+    { return *static_cast<Implementation *>(this); }
+
+    //! \copydoc asImp_()
+    const Implementation &asImp_() const
+    { return *static_cast<const Implementation *>(this); }
+
+protected:
+    int eddyViscosityModel_;
+};
+
+/*!
+ * \ingroup ZeroEqModel
+ * \brief Volume variables for the non-isothermal single-phase Reynolds-Averaged Navier-Stokes model.
+ */
+template <class TypeTag>
+class ZeroEqVolumeVariablesImplementation<TypeTag, true>
+: public RANSVolumeVariablesImplementation<TypeTag, true>
+{ };
+}
+
+#endif
diff --git a/test/freeflow/rans/pipelauferproblem.hh b/test/freeflow/rans/pipelauferproblem.hh
index 80bae39c73..b5b95fca96 100644
--- a/test/freeflow/rans/pipelauferproblem.hh
+++ b/test/freeflow/rans/pipelauferproblem.hh
@@ -30,7 +30,7 @@
 #include <dumux/material/fluidsystems/gasphase.hh>
 #include <dumux/material/components/air.hh>
 
-#include <dumux/freeflow/rans/model.hh>
+#include <dumux/freeflow/rans/zeroeq/model.hh>
 #include <dumux/freeflow/rans/problem.hh>
 #include <dumux/discretization/staggered/freeflow/properties.hh>
 
@@ -41,7 +41,7 @@ class PipeLauferProblem;
 
 namespace Properties
 {
-NEW_TYPE_TAG(PipeLauferProblem, INHERITS_FROM(StaggeredFreeFlowModel, RANS));
+NEW_TYPE_TAG(PipeLauferProblem, INHERITS_FROM(StaggeredFreeFlowModel, ZeroEq));
 
 // the fluid system
 SET_PROP(PipeLauferProblem, FluidSystem)
diff --git a/test/freeflow/rans/test_pipe_laufer.input b/test/freeflow/rans/test_pipe_laufer.input
index e479e08600..46ac807569 100644
--- a/test/freeflow/rans/test_pipe_laufer.input
+++ b/test/freeflow/rans/test_pipe_laufer.input
@@ -17,6 +17,9 @@ Name = test_pipe_laufer # name passed to the output routines
 InletVelocity = 2.5 # [m/s]
 EnableGravity = false
 
+[FreeFlow]
+EddyViscosityModel = 1
+
 [Newton]
 MaxSteps = 10
 MaxRelativeShift = 1e-5
-- 
GitLab