Commit d930b63f authored by Thomas Fetzer's avatar Thomas Fetzer
Browse files

[kepsilon] First implementation (identical to low-Re k-epsilon)

parent 2a4a135f
......@@ -196,6 +196,12 @@
* \brief Two-equation turbulence models
* \copydetails ./freeflow/rans/model.hh
*/
/*!
* \ingroup TwoEqModel
* \defgroup KEpsilonModel K-epsilon model
* \brief K-epsilon model
* \copydetails ./freeflow/rans/twoeq/kepsilon/model.hh
*/
/*!
* \ingroup TwoEqModel
* \defgroup LowReKEpsilonModel Low-Re k-epsilon model
......
add_subdirectory("kepsilon")
add_subdirectory("lowrekepsilon")
#install headers
install(FILES
fluxvariables.hh
indices.hh
localresidual.hh
model.hh
# models.hh
problem.hh
volumevariables.hh
vtkoutputfields.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dumux/freeflow/rans/twoeq/kepsilon)
// -*- 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 KEpsilonModel
* \copydoc Dumux::KEpsilonFluxVariables
*/
#ifndef DUMUX_KEPSILON_FLUXVARIABLES_HH
#define DUMUX_KEPSILON_FLUXVARIABLES_HH
#include <dumux/common/properties.hh>
#include <dumux/freeflow/rans/twoeq/kepsilon/staggered/fluxvariables.hh>
namespace Dumux
{
// forward declaration
template<class TypeTag, class BaseFluxVariables, DiscretizationMethod discMethod>
class KEpsilonFluxVariablesImpl;
/*!
* \ingroup KEpsilonModel
* \brief The flux variables class for the k-epsilon model.
This is a convenience alias for that actual,
discretization-specific flux variables.
* \note Not all specializations are currently implemented
*/
template<class TypeTag, class BaseFluxVariables>
using KEpsilonFluxVariables = KEpsilonFluxVariablesImpl<TypeTag, BaseFluxVariables, GET_PROP_TYPE(TypeTag, FVGridGeometry)::discMethod>;
} // end namespace
#endif
// -*- 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 KEpsilonModel
* \copydoc Dumux::KEpsilonIndices
*/
#ifndef DUMUX_KEPSILON_INDICES_HH
#define DUMUX_KEPSILON_INDICES_HH
#include <dumux/freeflow/navierstokes/indices.hh>
namespace Dumux {
// \{
/*!
* \ingroup KEpsilonModel
* \brief The common indices for the isothermal k-epsilon model.
*
* \tparam dimension The dimension of the problem
* \tparam numComponents The number of considered transported components
*/
template<int dimension, int numComponents>
struct KEpsilonIndices : public NavierStokesIndices<dimension>
{
public:
static constexpr auto turbulentKineticEnergyEqIdx = dimension + numComponents;
static constexpr auto turbulentKineticEnergyIdx = turbulentKineticEnergyEqIdx;
static constexpr auto dissipationEqIdx = turbulentKineticEnergyEqIdx + 1;
static constexpr auto dissipationIdx = dissipationEqIdx;
};
// \}
} // end namespace
#endif
// -*- 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 KEpsilonModel
* \copydoc Dumux::KEpsilonResidual
*/
#ifndef DUMUX_KEPSILON_LOCAL_RESIDUAL_HH
#define DUMUX_KEPSILON_LOCAL_RESIDUAL_HH
#include <dumux/common/properties.hh>
#include <dumux/discretization/methods.hh>
#include <dumux/freeflow/navierstokes/localresidual.hh>
#include <dumux/freeflow/rans/twoeq/kepsilon/staggered/localresidual.hh>
namespace Dumux
{
// forward declaration
template<class TypeTag, class BaseLocalResidual, DiscretizationMethod discMethod>
class KEpsilonResidualImpl;
/*!
* \ingroup KEpsilonModel
* \brief The local residual class for the k-epsilon model.
This is a convenience alias for the actual,
discretization-specific local residual.
* \note Not all specializations are currently implemented
*/
template<class TypeTag, class BaseLocalResidual>
using KEpsilonResidual = KEpsilonResidualImpl<TypeTag, BaseLocalResidual, GET_PROP_TYPE(TypeTag, FVGridGeometry)::discMethod>;
}
#endif
// -*- 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 KEpsilonModel
*
* \brief A single-phase, isothermal k-epsilon model
*
* \copydoc RANSModel
*
* The k-epsilon models calculate the eddy viscosity with two additional PDEs,
* one for the turbulent kinetic energy (k) and for the dissipation (\f$ \varepsilon \f$).
* \todo fix everything below here
* The model uses the one proposed by Chien \cite Chien1982a.
* A good overview and additional models are given in Patel et al. \cite Patel1985a.
*
* The turbulent kinetic energy balance is identical with the one from the k-epsilon model,
* but the dissipation includes a dampening function (\f$ D_\varepsilon \f$):
* \f$ \varepsilon = \tilde{\varepsilon} + D_\varepsilon \f$:
*
* \f[
* \frac{\partial \left( k \right)}{\partial t}
* + \nabla \cdot \left( \textbf{v} k \right)
* - \nabla \cdot \left( \left( \nu + \frac{\nu_\text{t}}{\sigma_\text{k}} \right) \nabla k \right)
* - 2 \nu_\text{t} \textbf{S} \cdot \textbf{S}
* + \tilde{\varepsilon}
* + D_\varepsilon
* = 0
* \f].
*
* The dissipation balance is changed by introducing additional functions
* (\f$ E_\text{k}\f$, \f$ f_1 \f$, and \f$ f_2 \f$) to account for a dampening towards the wall:
* \f[
* \frac{\partial \left( \tilde{\varepsilon} \right)}{\partial t}
* + \nabla \cdot \left( \textbf{v} \tilde{\varepsilon} \right)
* - \nabla \cdot \left( \left( \nu + \frac{\nu_\text{t}}{\sigma_{\varepsilon}} \right) \nabla \tilde{\varepsilon} \right)
* - C_{1\tilde{\varepsilon}} f_1 \frac{\tilde{\varepsilon}}{k} 2 \nu_\text{t} \textbf{S} \cdot \textbf{S}
* + C_{2\tilde{\varepsilon}} f_2 \frac{\tilde{\varepsilon}^2}{k}
* - E_\text{k}
* = 0
* \f].
*
* The kinematic eddy viscosity \f$ \nu_\text{t} \f$ is dampened by \f$ f_\mu \f$:
* \f[
* \nu_\text{t} = C_\mu f_\mu \frac{k^2}{\tilde{\varepsilon}}
* \f].
*
* The auxiliary and dampening functions are defined as:
* \f[ D_\varepsilon = 2 \nu \nicefrac{k}{y^2} \f]
* \f[ E_\text{k} = -2 \nu \frac{\tilde{\varepsilon}}{y^2} \exp \left( -0.5 y^+ \right) \f]
* \f[ f_1 = 1 \f]
* \f[ f_2 = 1 - 0.22 \exp \left( - \left( \frac{\mathit{Re}_\text{t}}{6} \right)^2 \right) \f]
* \f[ f_\mu = 1 - \exp \left( -0.0115 y^+ \right) \f]
* \f[ \mathit{Re}_\text{t} = \frac{k^2}{\nu \tilde{\varepsilon}} \f]
* .
*
* Finally, the model is closed with the following constants:
* \f[ \sigma_\text{k} = 1.00 \f]
* \f[ \sigma_\varepsilon =1.30 \f]
* \f[ C_{1\tilde{\varepsilon}} = 1.35 \f]
* \f[ C_{2\tilde{\varepsilon}} = 1.80 \f]
* \f[ C_\mu = 0.09 \f]
*/
#ifndef DUMUX_KEPSILON_MODEL_HH
#define DUMUX_KEPSILON_MODEL_HH
#include <dumux/common/properties.hh>
#include <dumux/freeflow/properties.hh>
#include <dumux/freeflow/rans/model.hh>
#include "fluxvariables.hh"
#include "indices.hh"
#include "localresidual.hh"
#include "volumevariables.hh"
#include "vtkoutputfields.hh"
namespace Dumux
{
namespace Properties {
/*!
* \ingroup KEpsilonModel
* \brief Traits for the k-epsilon model
*/
template<int dimension>
struct KEpsilonModelTraits : RANSModelTraits<dimension>
{
//! The dimension of the model
static constexpr int dim() { return dimension; }
//! There are as many momentum balance equations as dimensions,
//! one mass balance equation and two turbulent transport equations
static constexpr int numEq() { return dim()+1+2; }
//! The number of components
static constexpr int numComponents() { return 1; }
//! the indices
using Indices = KEpsilonIndices<dim(), numComponents()>;
};
///////////////////////////////////////////////////////////////////////////
// default property values for the isothermal k-epsilon model
///////////////////////////////////////////////////////////////////////////
//! The type tag for the single-phase, isothermal k-epsilon model
NEW_TYPE_TAG(KEpsilon, INHERITS_FROM(RANS));
//!< states some specifics of the isothermal k-epsilon model
SET_PROP(KEpsilon, ModelTraits)
{
private:
using GridView = typename GET_PROP_TYPE(TypeTag, FVGridGeometry)::GridView;
static constexpr int dim = GridView::dimension;
public:
using type = KEpsilonModelTraits<dim>;
};
//! The flux variables
SET_PROP(KEpsilon, FluxVariables)
{
private:
using BaseFluxVariables = NavierStokesFluxVariables<TypeTag>;
public:
using type = KEpsilonFluxVariables<TypeTag, BaseFluxVariables>;
};
//! The local residual
SET_PROP(KEpsilon, LocalResidual)
{
private:
using BaseLocalResidual = NavierStokesResidual<TypeTag>;
public:
using type = KEpsilonResidual<TypeTag, BaseLocalResidual>;
};
//! Set the volume variables property
SET_PROP(KEpsilon, VolumeVariables)
{
private:
using PV = typename GET_PROP_TYPE(TypeTag, PrimaryVariables);
using FSY = typename GET_PROP_TYPE(TypeTag, FluidSystem);
using FST = typename GET_PROP_TYPE(TypeTag, FluidState);
using MT = typename GET_PROP_TYPE(TypeTag, ModelTraits);
using Traits = NavierStokesVolumeVariablesTraits<PV, FSY, FST, MT>;
using NSVolVars = NavierStokesVolumeVariables<Traits>;
public:
using type = KEpsilonVolumeVariables<Traits, NSVolVars>;
};
//! The specific vtk output fields
SET_PROP(KEpsilon, VtkOutputFields)
{
private:
using FVGridGeometry = typename GET_PROP_TYPE(TypeTag, FVGridGeometry);
public:
using type = KEpsilonVtkOutputFields<FVGridGeometry>;
};
//////////////////////////////////////////////////////////////////
// default property values for the non-isothermal k-epsilon model
//////////////////////////////////////////////////////////////////
//! The type tag for the single-phase, isothermal k-epsilon model
NEW_TYPE_TAG(KEpsilonNI, INHERITS_FROM(RANSNI));
//! The model traits of the non-isothermal model
SET_PROP(KEpsilonNI, ModelTraits)
{
private:
using GridView = typename GET_PROP_TYPE(TypeTag, FVGridGeometry)::GridView;
static constexpr int dim = GridView::dimension;
using IsothermalTraits = KEpsilonModelTraits<dim>;
public:
using type = FreeflowNIModelTraits<IsothermalTraits>;
};
//! Set the volume variables property
SET_PROP(KEpsilonNI, VolumeVariables)
{
private:
using PV = typename GET_PROP_TYPE(TypeTag, PrimaryVariables);
using FSY = typename GET_PROP_TYPE(TypeTag, FluidSystem);
using FST = typename GET_PROP_TYPE(TypeTag, FluidState);
using MT = typename GET_PROP_TYPE(TypeTag, ModelTraits);
using Traits = NavierStokesVolumeVariablesTraits<PV, FSY, FST, MT>;
using NSVolVars = NavierStokesVolumeVariables<Traits>;
public:
using type = KEpsilonVolumeVariables<Traits, NSVolVars>;
};
//! The specific non-isothermal vtk output fields
SET_PROP(KEpsilonNI, VtkOutputFields)
{
private:
using ModelTraits = typename GET_PROP_TYPE(TypeTag, ModelTraits);
using FVGridGeometry = typename GET_PROP_TYPE(TypeTag, FVGridGeometry);
using IsothermalFields = KEpsilonVtkOutputFields<FVGridGeometry>;
public:
using type = FreeflowNonIsothermalVtkOutputFields<IsothermalFields, ModelTraits>;
};
// \}
}
} // end namespace
#endif
// -*- 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 KEpsilonModel
* \copydoc Dumux::KEpsilonProblem
*/
#ifndef DUMUX_REKEPSILON_PROBLEM_HH
#define DUMUX_REKEPSILON_PROBLEM_HH
#include <dumux/common/properties.hh>
#include <dumux/common/staggeredfvproblem.hh>
#include <dumux/discretization/localview.hh>
#include <dumux/discretization/staggered/elementsolution.hh>
#include <dumux/discretization/methods.hh>
#include <dumux/freeflow/rans/problem.hh>
#include "model.hh"
namespace Dumux
{
/*!
* \ingroup KEpsilonModel
* \brief K-epsilon turbulence problem base class.
*
* This implements some base functionality for k-epsilon models.
*/
template<class TypeTag>
class KEpsilonProblem : public RANSProblem<TypeTag>
{
using ParentType = RANSProblem<TypeTag>;
using Implementation = typename GET_PROP_TYPE(TypeTag, Problem);
using Scalar = typename GET_PROP_TYPE(TypeTag, Scalar);
using FVGridGeometry = typename GET_PROP_TYPE(TypeTag, FVGridGeometry);
using FVElementGeometry = typename GET_PROP_TYPE(TypeTag, FVGridGeometry)::LocalView;
using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
using VolumeVariables = typename GET_PROP_TYPE(TypeTag, VolumeVariables);
using SolutionVector = typename GET_PROP_TYPE(TypeTag, SolutionVector);
using PrimaryVariables = typename GET_PROP_TYPE(TypeTag, PrimaryVariables);
using CellCenterPrimaryVariables = typename GET_PROP_TYPE(TypeTag, CellCenterPrimaryVariables);
using Indices = typename GET_PROP_TYPE(TypeTag, ModelTraits)::Indices;
public:
//! The constructor sets the gravity, if desired by the user.
KEpsilonProblem(std::shared_ptr<const FVGridGeometry> fvGridGeometry)
: ParentType(fvGridGeometry)
{
useStoredEddyViscosity_ = getParamFromGroup<bool>(this->paramGroup(), "RANS.UseStoredEddyViscosity", true);
}
/*!
* \brief Correct size of the static (solution independent) wall variables
*/
void updateStaticWallProperties()
{
ParentType::updateStaticWallProperties();
// update size and initial values of the global vectors
storedDissipationTilde_.resize(this->fvGridGeometry().elementMapper().size(), 0.0);
storedDynamicEddyViscosity_.resize(this->fvGridGeometry().elementMapper().size(), 0.0);
storedTurbulentKineticEnergy_.resize(this->fvGridGeometry().elementMapper().size(), 0.0);
}
/*!
* \brief Update the dynamic (solution dependent) relations to the walls
*
* \param curSol The solution vector.
*/
void updateDynamicWallProperties(const SolutionVector& curSol)
{
ParentType::updateDynamicWallProperties(curSol);
for (const auto& element : elements(this->fvGridGeometry().gridView()))
{
unsigned int elementID = this->fvGridGeometry().elementMapper().index(element);
auto fvGeometry = localView(this->fvGridGeometry());
fvGeometry.bindElement(element);
for (auto&& scv : scvs(fvGeometry))
{
const int dofIdx = scv.dofIndex();
const auto& cellCenterPriVars = curSol[FVGridGeometry::cellCenterIdx()][dofIdx];
PrimaryVariables priVars = makePriVarsFromCellCenterPriVars<PrimaryVariables>(cellCenterPriVars);
auto elemSol = elementSolution<typename FVGridGeometry::LocalView>(std::move(priVars));
// NOTE: first update the turbulence quantities
storedDissipationTilde_[elementID] = elemSol[0][Indices::dissipationEqIdx];
storedTurbulentKineticEnergy_[elementID] = elemSol[0][Indices::turbulentKineticEnergyEqIdx];
// NOTE: then update the volVars
VolumeVariables volVars;
volVars.update(elemSol, asImp_(), element, scv);
storedDynamicEddyViscosity_[elementID] = volVars.calculateEddyViscosity();
}
}
}
public:
std::vector<Scalar> storedDissipationTilde_;
std::vector<Scalar> storedDynamicEddyViscosity_;
std::vector<Scalar> storedTurbulentKineticEnergy_;
bool useStoredEddyViscosity_;
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); }
};
}
#endif
#install headers
install(FILES
fluxvariables.hh
localresidual.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dumux/freeflow/rans/twoeq/kepsilon/staggered)
// -*- 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 KEpsilonModel
* \copydoc Dumux::KEpsilonFluxVariablesImpl
*/
#ifndef DUMUX_KEPSILON_STAGGERED_FLUXVARIABLES_HH
#define DUMUX_KEPSILON_STAGGERED_FLUXVARIABLES_HH
#include <numeric>
#include <dumux/common/properties.hh>
#include <dumux/discretization/fluxvariablesbase.hh>
#include <dumux/discretization/methods.hh>
#include <dumux/freeflow/navierstokes/fluxvariables.hh>
#include <dumux/freeflow/rans/twoeq/kepsilon/fluxvariables.hh>
namespace Dumux
{
// forward declaration
template<class TypeTag, class BaseFluxVariables, DiscretizationMethod discMethod>
class KEpsilonFluxVariablesImpl;
/*!
* \ingroup KEpsilonModel
* \brief The flux variables class for the k-epsilon model using the staggered grid discretization.
*/
template<class TypeTag, class BaseFluxVariables>
class KEpsilonFluxVariablesImpl<TypeTag, BaseFluxVariables, DiscretizationMethod::staggered>
: public BaseFluxVariables
{
using ParentType = BaseFluxVariables;