Commit 4a6a389f authored by Thomas Fetzer's avatar Thomas Fetzer
Browse files

[rans][oneeq] Add first compiling version of the one-equation Spalart-Allmaras model

parent db9799d7
......@@ -190,6 +190,12 @@
* \brief Zero-equation or algebraic turbulence models
* \copydetails ./freeflow/rans/zeroeq/model.hh
*/
/*!
* \ingroup RANSModel
* \defgroup OneEqModel 1-Eq. Models
* \brief One-equation turbulence model by Spalart-Allmaras
* \copydetails ./freeflow/oneeq/model.hh
*/
/*!
* \ingroup RANSModel
* \defgroup TwoEqModel 2-Eq. Models
......
add_subdirectory(oneeq)
add_subdirectory(twoeq)
add_subdirectory(zeroeq)
......
add_subdirectory(staggered)
install(FILES
fluxvariables.hh
indices.hh
localresidual.hh
model.hh
problem.hh
volumevariables.hh
vtkoutputfields.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dumux/freeflow/rans/oneeq)
// -*- 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 OneEqModel
* \copydoc Dumux::OneEqFluxVariables
*/
#ifndef DUMUX_ONEEQFLUXVARIABLES_HH
#define DUMUX_ONEEQFLUXVARIABLES_HH
#include <dumux/common/properties.hh>
#include <dumux/freeflow/navierstokes/fluxvariables.hh>
#include <dumux/freeflow/rans/oneeq/staggered/fluxvariables.hh>
namespace Dumux
{
// forward declaration
template<class TypeTag, class BaseFluxVariables, DiscretizationMethod discMethod>
class OneEqFluxVariablesImpl;
/*!
* \ingroup OneEqModel
* \brief The flux variables class for the one-equation turbulence model by Spalart-Allmaras.
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 OneEqFluxVariables = OneEqFluxVariablesImpl<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 OneEqModel
* \copydoc Dumux::OneEqIndices
*/
#ifndef DUMUX_ONEEQ_INDICES_HH
#define DUMUX_ONEEQ_INDICES_HH
#include <dumux/freeflow/navierstokes/indices.hh>
namespace Dumux {
// \{
/*!
* \ingroup OneEqModel
* \brief The common indices for the isothermal one-equation turbulence model by Spalart-Allmaras
*
* \tparam dimension The dimension of the problem
* \tparam numComponents The number of considered transported components
*/
template<int dimension, int numComponents>
struct OneEqIndices : public NavierStokesIndices<dimension>
{
public:
static constexpr auto viscosityTildeEqIdx = dimension + numComponents;
static constexpr auto viscosityTildeIdx = viscosityTildeEqIdx;
};
// \}
} // 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 OneEqModel
* \copydoc Dumux::OneEqResidual
*/
#ifndef DUMUX_ONEEQ_LOCAL_RESIDUAL_HH
#define DUMUX_ONEEQ_LOCAL_RESIDUAL_HH
#include <dumux/common/properties.hh>
#include <dumux/discretization/methods.hh>
#include <dumux/freeflow/navierstokes/localresidual.hh>
#include <dumux/freeflow/rans/oneeq/staggered/localresidual.hh>
namespace Dumux
{
// forward declaration
template<class TypeTag, class BaseLocalResidual, DiscretizationMethod discMethod>
class OneEqResidualImpl;
/*!
* \ingroup OneEqModel
* \brief The local residual class for the one-equation turbulence model by Spalart-Allmaras
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 OneEqResidual = OneEqResidualImpl<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 OneEqModel
*
* \brief A single-phase, isothermal one-equation turbulence model by Spalart-Allmaras
*
* \copydoc RANSModel
*
* \todo please doc me
*/
#ifndef DUMUX_ONEEQ_MODEL_HH
#define DUMUX_ONEEQ_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 OneEqModel
* \brief Traits for the Spalart-Allmaras model
*/
template<int dimension>
struct OneEqModelTraits : 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+1; }
//! The number of components
static constexpr int numComponents() { return 1; }
//! the indices
using Indices = OneEqIndices<dim(), numComponents()>;
};
///////////////////////////////////////////////////////////////////////////
// default property values for the isothermal Spalart-Allmaras model
///////////////////////////////////////////////////////////////////////////
//! The type tag for the single-phase, isothermal Spalart-Allmaras model
NEW_TYPE_TAG(OneEq, INHERITS_FROM(RANS));
//!< states some specifics of the isothermal Spalart-Allmaras model
SET_PROP(OneEq, ModelTraits)
{
private:
using GridView = typename GET_PROP_TYPE(TypeTag, FVGridGeometry)::GridView;
static constexpr int dim = GridView::dimension;
public:
using type = OneEqModelTraits<dim>;
};
//! The flux variables
SET_PROP(OneEq, FluxVariables)
{
private:
using BaseFluxVariables = NavierStokesFluxVariables<TypeTag>;
public:
using type = OneEqFluxVariables<TypeTag, BaseFluxVariables>;
};
//! The local residual
SET_PROP(OneEq, LocalResidual)
{
private:
using BaseLocalResidual = NavierStokesResidual<TypeTag>;
public:
using type = OneEqResidual<TypeTag, BaseLocalResidual>;
};
//! Set the volume variables property
SET_PROP(OneEq, 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 = OneEqVolumeVariables<Traits, NSVolVars>;
};
//! The specific vtk output fields
SET_PROP(OneEq, VtkOutputFields)
{
private:
using FVGridGeometry = typename GET_PROP_TYPE(TypeTag, FVGridGeometry);
public:
using type = OneEqVtkOutputFields<FVGridGeometry>;
};
//////////////////////////////////////////////////////////////////
// default property values for the non-isothermal Spalart-Allmaras model
//////////////////////////////////////////////////////////////////
//! The type tag for the single-phase, isothermal Spalart-Allmaras model
NEW_TYPE_TAG(OneEqNI, INHERITS_FROM(RANSNI));
//! The model traits of the non-isothermal model
SET_PROP(OneEqNI, ModelTraits)
{
private:
using GridView = typename GET_PROP_TYPE(TypeTag, FVGridGeometry)::GridView;
static constexpr int dim = GridView::dimension;
using IsothermalTraits = OneEqModelTraits<dim>;
public:
using type = FreeflowNIModelTraits<IsothermalTraits>;
};
//! Set the volume variables property
SET_PROP(OneEqNI, 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 = OneEqVolumeVariables<Traits, NSVolVars>;
};
//! The specific non-isothermal vtk output fields
SET_PROP(OneEqNI, VtkOutputFields)
{
private:
using ModelTraits = typename GET_PROP_TYPE(TypeTag, ModelTraits);
using FVGridGeometry = typename GET_PROP_TYPE(TypeTag, FVGridGeometry);
using IsothermalFields = OneEqVtkOutputFields<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 OneEqModel
* \copydoc Dumux::OneEqProblem
*/
#ifndef DUMUX_ONEEQ_PROBLEM_HH
#define DUMUX_ONEEQ_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 OneEqModel
* \brief One-equation turbulence problem base class.
*
* This implements some base functionality for one-equation Spalart-Allmaras model.
*/
template<class TypeTag>
class OneEqProblem : public RANSProblem<TypeTag>
{
using ParentType = RANSProblem<TypeTag>;
using Implementation = typename GET_PROP_TYPE(TypeTag, Problem);
using GridView = typename GET_PROP_TYPE(TypeTag, GridView);
using Grid = typename GridView::Grid;
using Scalar = typename GET_PROP_TYPE(TypeTag, Scalar);
using DimVector = Dune::FieldVector<Scalar, Grid::dimension>;
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.
OneEqProblem(std::shared_ptr<const FVGridGeometry> fvGridGeometry)
: ParentType(fvGridGeometry)
{
useStoredEddyViscosity_ = getParamFromGroup<bool>(this->paramGroup(),
"RANS.UseStoredEddyViscosity", false);
}
/*!
* \brief Correct size of the static (solution independent) wall variables
*/
void updateStaticWallProperties()
{
ParentType::updateStaticWallProperties();
// update size and initial values of the global vectors
storedDynamicEddyViscosity_.resize(this->fvGridGeometry().elementMapper().size(), 0.0);
storedViscosityTilde_.resize(this->fvGridGeometry().elementMapper().size(), 0.0);
storedViscosityTildeGradient_.resize(this->fvGridGeometry().elementMapper().size(), DimVector(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
storedViscosityTilde_[elementID] = elemSol[0][Indices::viscosityTildeIdx];
// NOTE: then update the volVars
VolumeVariables volVars;
volVars.update(elemSol, asImp_(), element, scv);
storedDynamicEddyViscosity_[elementID] = volVars.calculateEddyViscosity();
}
}
// calculate cell-center-averaged velocity gradients, maximum, and minimum values
for (const auto& element : elements(this->fvGridGeometry().gridView()))
{
unsigned int elementID = this->fvGridGeometry().elementMapper().index(element);
for (unsigned int dimIdx = 0; dimIdx < Grid::dimension; ++dimIdx)
{
storedViscosityTildeGradient_[elementID][dimIdx]
= (storedViscosityTilde_[ParentType::neighborID_[elementID][dimIdx][1]]
- storedViscosityTilde_[ParentType::neighborID_[elementID][dimIdx][0]])
/ (ParentType::cellCenter_[ParentType::neighborID_[elementID][dimIdx][1]][dimIdx]
- ParentType::cellCenter_[ParentType::neighborID_[elementID][dimIdx][0]][dimIdx]);
}
auto fvGeometry = localView(this->fvGridGeometry());
fvGeometry.bindElement(element);
for (auto&& scvf : scvfs(fvGeometry))
{
unsigned int normDim = scvf.directionIndex();
if (scvf.boundary() && asImp_().boundaryTypes(element, scvf).isDirichlet(Indices::viscosityTildeIdx))
{
// face Value
Scalar dirichletViscosityTilde = asImp_().dirichlet(element, scvf)[Indices::viscosityTildeIdx];
unsigned int neighborID = ParentType::neighborID_[elementID][normDim][0];
if (scvf.center()[normDim] < ParentType::cellCenter_[elementID][normDim])
neighborID = ParentType::neighborID_[elementID][normDim][1];
storedViscosityTildeGradient_[elementID][normDim]
= (storedViscosityTilde_[neighborID] - dirichletViscosityTilde)
/ (ParentType::cellCenter_[neighborID][normDim] - scvf.center()[normDim]);
}
}
}
}
public:
std::vector<Scalar> storedDynamicEddyViscosity_;
std::vector<Scalar> storedViscosityTilde_;
std::vector<DimVector> storedViscosityTildeGradient_;
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(FILES
fluxvariables.hh
localresidual.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dumux/freeflow/rans/oneeq/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 OneEqModel
* \copydoc Dumux::OneEqFluxVariablesImpl
*/
#ifndef DUMUX_ONEEQ_STAGGERED_FLUXVARIABLES_HH
#define DUMUX_ONEEQ_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/oneeq/fluxvariables.hh>
namespace Dumux
{
// forward declaration
template<class TypeTag, class BaseFluxVariables, DiscretizationMethod discMethod>
class OneEqFluxVariablesImpl;
/*!
* \ingroup OneEqModel
* \brief The flux variables class for the one-equation model by Spalart-Allmaras
* using the staggered grid discretization.
*/
template<class TypeTag, class BaseFluxVariables>
class OneEqFluxVariablesImpl<TypeTag, BaseFluxVariables, DiscretizationMethod::staggered>
: public BaseFluxVariables
{
using ParentType = BaseFluxVariables;
using GridVariables = typename GET_PROP_TYPE(TypeTag, GridVariables);
using GridVolumeVariables = typename GridVariables::GridVolumeVariables;
using ElementVolumeVariables = typename GridVolumeVariables::LocalView;
using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
using GridFluxVariablesCache = typename GridVariables::GridFluxVariablesCache;
using FluxVariablesCache = typename GridFluxVariablesCache::FluxVariablesCache;
using GridFaceVariables = typename GridVariables::GridFaceVariables;
using ElementFaceVariables = typename GridFaceVariables::LocalView;
using FaceVariables = typename GridFaceVariables::FaceVariables;