Commit 61fca81a authored by Kilian Weishaupt's avatar Kilian Weishaupt Committed by Dennis Gläser
Browse files

[freeflow] Introduce ModelTraits for NavierStokes

parent a6ea9aee
......@@ -88,8 +88,6 @@ class StaggeredLocalAssembler<TypeTag,
using FaceSolutionVector = typename GET_PROP_TYPE(TypeTag, FaceSolutionVector);
using FaceSolution = typename GET_PROP_TYPE(TypeTag, StaggeredFaceSolution);
enum { numEq = GET_PROP_TYPE(TypeTag, ModelTraits)::numEq() };
using Indices = typename GET_PROP_TYPE(TypeTag, Indices);
using PrimaryVariables = typename GET_PROP_TYPE(TypeTag, PrimaryVariables);
using FacePrimaryVariables = typename GET_PROP_TYPE(TypeTag, FacePrimaryVariables);
......
......@@ -60,11 +60,13 @@ class FicksLawImplementation<TypeTag, DiscretizationMethod::staggered >
static constexpr int dim = GridView::dimension;
static constexpr int dimWorld = GridView::dimensionworld;
static constexpr int numComponents = GET_PROP_VALUE(TypeTag, NumComponents);
static constexpr int phaseIdx = GET_PROP_VALUE(TypeTag, PhaseIdx);
using ModelTraits = typename GET_PROP_TYPE(TypeTag, ModelTraits);
static constexpr int numComponents = ModelTraits::numComponents();
static constexpr int phaseIdx = Indices::phaseIdx;
static constexpr bool useMoles = GET_PROP_VALUE(TypeTag, UseMoles);
static_assert(GET_PROP_VALUE(TypeTag, NumPhases) == 1, "Only one phase allowed supported!");
static_assert(ModelTraits::numPhases() == 1, "Only one phase allowed supported!");
enum {
pressureIdx = Indices::pressureIdx,
......
......@@ -60,13 +60,15 @@ class MaxwellStefansLawImplementation<TypeTag, DiscretizationMethod::staggered >
static const int dim = GridView::dimension;
static const int dimWorld = GridView::dimensionworld;
static const int numComponents = GET_PROP_VALUE(TypeTag,NumComponents);
using ModelTraits = typename GET_PROP_TYPE(TypeTag, ModelTraits);
static const int numComponents = ModelTraits::numComponents();
static constexpr bool useMoles = GET_PROP_VALUE(TypeTag, UseMoles);
using ReducedComponentVector = Dune::FieldVector<Scalar, numComponents-1>;
using ReducedComponentMatrix = Dune::FieldMatrix<Scalar, numComponents-1, numComponents-1>;
static_assert(GET_PROP_VALUE(TypeTag, NumPhases) == 1, "Only one phase allowed supported!");
static_assert(ModelTraits::numPhases() == 1, "Only one phase allowed supported!");
enum {
pressureIdx = Indices::pressureIdx,
......
......@@ -71,10 +71,11 @@ SET_PROP(StaggeredFreeFlowModel, NumEqCellCenter)
{
private:
using GridView = typename GET_PROP_TYPE(TypeTag, GridView);
using ModelTraits = typename GET_PROP_TYPE(TypeTag, ModelTraits);
static constexpr auto dim = GridView::dimension;
static constexpr auto numEq = GET_PROP_VALUE(TypeTag, NumEq);
static constexpr auto numEq = ModelTraits::numEq();
public:
static constexpr int value = GET_PROP_VALUE(TypeTag, NumEq) - dim;
static constexpr int value = numEq - dim;
};
//! The default fv grid geometry
......
......@@ -86,20 +86,6 @@ SET_TYPE_PROP(StaggeredModel, ElementFluxVariablesCache, StaggeredElementFluxVar
//! Set the face solution type
SET_TYPE_PROP(StaggeredModel, StaggeredFaceSolution, StaggeredFaceSolution<TypeTag>);
//! Dummy model traits struct until the model traits
//! are actually implemented for models using staggered grid
SET_PROP(StaggeredModel, ModelTraits)
{
private:
struct DummyTraits
{
static constexpr int numEq() { return GET_PROP_VALUE(TypeTag, NumEq); }
static constexpr int numPhases() { return GET_PROP_VALUE(TypeTag, NumPhases); }
};
public:
using type = DummyTraits;
};
//! Set the grid variables (volume, flux and face variables)
SET_PROP(StaggeredModel, GridVariables)
{
......
......@@ -65,6 +65,33 @@
namespace Dumux
{
/*!
* \ingroup NavierStokesModel
* \brief Traits for the Navier-Stokes model
*/
template<int dim>
struct NavierStokesModelTraits
{
//! There are as many momentum balance equations as dimensions
//! and one mass balance equation.
static constexpr int numEq() { return dim+1; }
//! The number of phases is 1
static constexpr int numPhases() { return 1; }
//! The number of components is 1
static constexpr int numComponents() { return 1; }
//! Enable advection
static constexpr bool enableAdvection() { return true; }
//! The one-phase model has no molecular diffusion
static constexpr bool enableMolecularDiffusion() { return false; }
//! The model is isothermal
static constexpr bool enableEnergyBalance() { return false; }
};
// \{
///////////////////////////////////////////////////////////////////////////
// properties for the single-phase Navier-Stokes model
......@@ -84,28 +111,18 @@ NEW_TYPE_TAG(NavierStokesNI, INHERITS_FROM(NavierStokes, NavierStokesNonIsotherm
///////////////////////////////////////////////////////////////////////////
// default property values for the isothermal single phase model
///////////////////////////////////////////////////////////////////////////
SET_INT_PROP(NavierStokes, NumPhases, 1); //!< The number of phases in the 1p model is 1
SET_INT_PROP(NavierStokes, NumComponents, 1); //!< The number of components in the 1p model is 1
SET_INT_PROP(NavierStokes, PhaseIdx, 0); //!< The default phase index
SET_BOOL_PROP(NavierStokes, EnableAdvection, true); //!< Enable advection
SET_BOOL_PROP(NavierStokes, EnableMolecularDiffusion, false); //!< The one-phase model has no molecular diffusion
SET_BOOL_PROP(NavierStokes, EnableEnergyBalance, false); //!< The model is isothermal
SET_BOOL_PROP(NavierStokes, EnableInertiaTerms, true); //!< Consider inertia terms by default
SET_BOOL_PROP(NavierStokes, NormalizePressure, true); //!< Normalize the pressure term in the momentum balance by default
/*!
* \brief The number of equations.
* There are as many momentum balance equations as dimensions
* and one mass balance equation.
*/
SET_PROP(NavierStokes, NumEq)
//!< states some specifics of the Navier-Stokes model
SET_PROP(NavierStokes, ModelTraits)
{
private:
using GridView = typename GET_PROP_TYPE(TypeTag, GridView);
static constexpr auto dim = GridView::dimension;
using GridView = typename GET_PROP_TYPE(TypeTag, FVGridGeometry)::GridView;
static constexpr int dim = GridView::dimension;
public:
static constexpr int value = dim + 1;
using type = NavierStokesModelTraits<dim>;
};
/*!
......@@ -138,7 +155,7 @@ SET_TYPE_PROP(NavierStokes, FluxVariablesCache, FreeFlowFluxVariablesCache<TypeT
SET_PROP(NavierStokes, Indices)
{
private:
static constexpr int numEq = GET_PROP_VALUE(TypeTag, NumEq);
static constexpr int numEq = GET_PROP_TYPE(TypeTag, ModelTraits)::numEq();
static constexpr int dim = GET_PROP_TYPE(TypeTag, GridView)::dimension;
public:
using type = NavierStokesIndices<dim, numEq>;
......@@ -155,11 +172,22 @@ public:
//////////////////////////////////////////////////////////////////
// Property values for isothermal model required for the general non-isothermal model
//////////////////////////////////////////////////////////////////
//! The model traits of the isothermal model
SET_PROP(NavierStokesNI, IsothermalModelTraits)
{
private:
using GridView = typename GET_PROP_TYPE(TypeTag, FVGridGeometry)::GridView;
static constexpr int dim = GridView::dimension;
public:
using type = NavierStokesModelTraits<dim>;
};
//! The indices required by the isothermal single-phase model
SET_PROP(NavierStokesNI, IsothermalIndices)
{
private:
static constexpr int numEq = GET_PROP_VALUE(TypeTag, NumEq);
static constexpr int numEq = GET_PROP_TYPE(TypeTag, ModelTraits)::numEq();
static constexpr int dim = GET_PROP_TYPE(TypeTag, GridView)::dimension;
public:
using type = NavierStokesIndices<dim, numEq>;
......@@ -174,15 +202,6 @@ public:
using type = NavierStokesVtkOutputFields<FVGridGeometry>;
};
//! The number of equations for the isothermal model
SET_PROP(NavierStokesNI, IsothermalNumEq)
{
private:
using GridView = typename GET_PROP_TYPE(TypeTag, GridView);
static constexpr auto dim = GridView::dimension;
public:
static constexpr int value = dim + 1;
};
// \}
}
......
......@@ -271,7 +271,7 @@ public:
*/
void calculateVolumeFluxes()
{
const auto isCompositional = std::integral_constant<bool, (GET_PROP_VALUE(TypeTag, NumComponents) > 1) >();
const auto isCompositional = std::integral_constant<bool, (GET_PROP_TYPE(TypeTag, ModelTraits)::numComponents() > 1) >();
calculateVolumeFluxesImpl_(isCompositional);
}
......
......@@ -60,6 +60,7 @@ class NavierStokesFluxVariablesImpl<TypeTag, DiscretizationMethod::staggered>
using FaceVariables = typename GET_PROP_TYPE(TypeTag, FaceVariables);
static constexpr bool enableInertiaTerms = GET_PROP_VALUE(TypeTag, EnableInertiaTerms);
static constexpr bool normalizePressure = GET_PROP_VALUE(TypeTag, NormalizePressure);
using GlobalPosition = Dune::FieldVector<Scalar, GridView::dimensionworld>;
......@@ -224,7 +225,7 @@ public:
// The pressure term.
// If specified, the pressure can be normalized using the initial value on the scfv of interest.
// Can potentially help to improve the condition number of the system matrix.
const Scalar pressure = GET_PROP_VALUE(TypeTag, NormalizePressure) ?
const Scalar pressure = normalizePressure ?
insideVolVars.pressure() - problem.initialAtPos(scvf.center())[Indices::pressureIdx]
: insideVolVars.pressure();
......@@ -513,7 +514,7 @@ private:
}
// Apply a pressure at the boudary.
const Scalar boundaryPressure = GET_PROP_VALUE(TypeTag, NormalizePressure) ?
const Scalar boundaryPressure = normalizePressure ?
(problem.dirichlet(element, scvf)[Indices::pressureIdx] -
problem.initialAtPos(scvf.center())[Indices::pressureIdx])
: problem.dirichlet(element, scvf)[Indices::pressureIdx];
......
......@@ -79,6 +79,8 @@ class NavierStokesResidualImpl<TypeTag, DiscretizationMethod::staggered>
using VolumeVariables = typename GET_PROP_TYPE(TypeTag, VolumeVariables);
using ModelTraits = typename GET_PROP_TYPE(TypeTag, ModelTraits);
public:
//! Use the parent type's constructor
......@@ -97,7 +99,7 @@ public:
CellCenterPrimaryVariables flux = fluxVars.computeFluxForCellCenter(problem, element, fvGeometry, elemVolVars,
elemFaceVars, scvf, elemFluxVarsCache[scvf]);
computeFluxForCellCenterNonIsothermal_(std::integral_constant<bool, GET_PROP_VALUE(TypeTag, EnableEnergyBalance)>(),
computeFluxForCellCenterNonIsothermal_(std::integral_constant<bool, ModelTraits::enableEnergyBalance()>(),
problem, element, fvGeometry, elemVolVars, elemFaceVars, scvf, elemFluxVarsCache, flux);
return flux;
......@@ -132,7 +134,7 @@ public:
CellCenterPrimaryVariables storage;
storage[massBalanceIdx] = volVars.density();
computeStorageForCellCenterNonIsothermal_(std::integral_constant<bool, GET_PROP_VALUE(TypeTag, EnableEnergyBalance) >(),
computeStorageForCellCenterNonIsothermal_(std::integral_constant<bool, ModelTraits::enableEnergyBalance() >(),
problem, scv, volVars, storage);
return storage;
......
......@@ -40,7 +40,7 @@ class NavierStokesVolumeVariablesImplementation;
* The class is specialized for isothermal and non-isothermal models.
*/
template <class TypeTag>
using NavierStokesVolumeVariables = NavierStokesVolumeVariablesImplementation<TypeTag, GET_PROP_VALUE(TypeTag, EnableEnergyBalance)>;
using NavierStokesVolumeVariables = NavierStokesVolumeVariablesImplementation<TypeTag, GET_PROP_TYPE(TypeTag, ModelTraits)::enableEnergyBalance()>;
/*!
* \ingroup NavierStokesModel
......
......@@ -78,8 +78,34 @@
#include <dumux/material/fluidstates/compositional.hh>
namespace Dumux
namespace Dumux {
/*!
* \ingroup NavierStokesModel
* \brief Traits for the Navier-Stokes multi-component model
*/
template<int dim, int nComp>
struct NavierStokesNCModelTraits
{
//! There are as many momentum balance equations as dimensions
//! and as many balance equations as components.
static constexpr int numEq() { return dim+nComp; }
//! The number of phases is always 1
static constexpr int numPhases() { return 1; }
//! The number of components
static constexpr int numComponents() { return nComp; }
//! Enable advection
static constexpr bool enableAdvection() { return true; }
//! The one-phase model has no molecular diffusion
static constexpr bool enableMolecularDiffusion() { return true; }
//! The model is isothermal
static constexpr bool enableEnergyBalance() { return false; }
};
///////////////////////////////////////////////////////////////////////////
// properties for the single-phase, multi-component Navier-Stokes model
......@@ -100,37 +126,19 @@ NEW_TYPE_TAG(NavierStokesNCNI, INHERITS_FROM(NavierStokesNC, NavierStokesNonIsot
// default property values
///////////////////////////////////////////////////////////////////////////
/*!
* \brief Set the property for the number of components.
*
* We just forward the number from the fluid system
*
*/
SET_PROP(NavierStokesNC, NumComponents)
{
private:
using FluidSystem = typename GET_PROP_TYPE(TypeTag, FluidSystem);
public:
static constexpr int value = FluidSystem::numComponents;
};
/*!
* \brief The number of equations.
* There are as many momentum balance equations as dimensions
* and as many balance equations as components.
*/
SET_PROP(NavierStokesNC, NumEq)
//!< states some specifics of the Navier-Stokes model
SET_PROP(NavierStokesNC, ModelTraits)
{
private:
using GridView = typename GET_PROP_TYPE(TypeTag, GridView);
static constexpr auto dim = GridView::dimension;
using GridView = typename GET_PROP_TYPE(TypeTag, FVGridGeometry)::GridView;
static constexpr int dim = GridView::dimension;
using FluidSystem = typename GET_PROP_TYPE(TypeTag, FluidSystem);
static constexpr int numComponents = FluidSystem::numComponents;
public:
static constexpr int value = dim + FluidSystem::numComponents;
using type = NavierStokesNCModelTraits<dim, numComponents>;
};
SET_INT_PROP(NavierStokesNC, PhaseIdx, 0); //!< Defines the phaseIdx
SET_BOOL_PROP(NavierStokesNC, EnableMolecularDiffusion, true); //!< Enable molecular diffusion
SET_BOOL_PROP(NavierStokesNC, UseMoles, false); //!< Defines whether molar (true) or mass (false) density is used
SET_INT_PROP(NavierStokesNC, ReplaceCompEqIdx, 0); //<! Set the ReplaceCompEqIdx to 0 by default
......@@ -147,7 +155,7 @@ SET_TYPE_PROP(NavierStokesNC, FluxVariables, NavierStokesNCFluxVariables<TypeTag
SET_PROP(NavierStokesNC, Indices)
{
private:
static constexpr int numEq = GET_PROP_VALUE(TypeTag, NumEq);
static constexpr int numEq = GET_PROP_TYPE(TypeTag, ModelTraits)::numEq();
static constexpr int dim = GET_PROP_TYPE(TypeTag, GridView)::dimension;
static constexpr int phaseIdx = GET_PROP_VALUE(TypeTag, PhaseIdx);
static constexpr int replaceCompEqIdx = GET_PROP_VALUE(TypeTag, ReplaceCompEqIdx);
......@@ -187,11 +195,24 @@ SET_TYPE_PROP(NavierStokesNC, MolecularDiffusionType, FicksLaw<TypeTag>);
//////////////////////////////////////////////////////////////////
// Property values for isothermal model required for the general non-isothermal model
//////////////////////////////////////////////////////////////////
//! The model traits of the isothermal model
SET_PROP(NavierStokesNCNI, IsothermalModelTraits)
{
private:
using GridView = typename GET_PROP_TYPE(TypeTag, FVGridGeometry)::GridView;
static constexpr int dim = GridView::dimension;
using FluidSystem = typename GET_PROP_TYPE(TypeTag, FluidSystem);
static constexpr int numComponents = FluidSystem::numComponents;
public:
using type = NavierStokesNCModelTraits<dim, numComponents>;
};
//! The isothermal indices
SET_PROP(NavierStokesNCNI, IsothermalIndices)
{
private:
static constexpr int numEq = GET_PROP_VALUE(TypeTag, NumEq);
static constexpr int numEq = GET_PROP_TYPE(TypeTag, ModelTraits)::numEq();
static constexpr int dim = GET_PROP_TYPE(TypeTag, GridView)::dimension;
static constexpr int phaseIdx = GET_PROP_VALUE(TypeTag, PhaseIdx);
static constexpr int replaceCompEqIdx = GET_PROP_VALUE(TypeTag, ReplaceCompEqIdx);
......@@ -211,17 +232,6 @@ public:
using type = NavierStokesNCVtkOutputFields<FVGridGeometry, FluidSystem, phaseIdx>;
};
//! The number of equations for the isothermal model
SET_PROP(NavierStokesNCNI, IsothermalNumEq)
{
private:
using GridView = typename GET_PROP_TYPE(TypeTag, GridView);
static constexpr auto dim = GridView::dimension;
using FluidSystem = typename GET_PROP_TYPE(TypeTag, FluidSystem);
public:
static constexpr int value = dim + FluidSystem::numComponents;
};
// \}
} // end namespace Properties
} // end namespace Dumux
......
......@@ -58,7 +58,7 @@ class NavierStokesNCFluxVariablesImpl<TypeTag, DiscretizationMethod::staggered>
using MolecularDiffusionType = typename GET_PROP_TYPE(TypeTag, MolecularDiffusionType);
static constexpr auto numComponents = GET_PROP_VALUE(TypeTag, NumComponents);
static constexpr auto numComponents = GET_PROP_TYPE(TypeTag, ModelTraits)::numComponents();
static constexpr bool useMoles = GET_PROP_VALUE(TypeTag, UseMoles);
......
......@@ -69,7 +69,9 @@ class NavierStokesNCResidualImpl<TypeTag, DiscretizationMethod::staggered>
using VolumeVariables = typename GET_PROP_TYPE(TypeTag, VolumeVariables);
static constexpr int numComponents = GET_PROP_VALUE(TypeTag, NumComponents);
using ModelTraits = typename GET_PROP_TYPE(TypeTag, ModelTraits);
static constexpr int numComponents =ModelTraits::numComponents();
static constexpr bool useMoles = GET_PROP_VALUE(TypeTag, UseMoles);
public:
......@@ -100,7 +102,7 @@ public:
if(replaceCompEqIdx < numComponents)
storage[replaceCompEqIdx] = density;
this->computeStorageForCellCenterNonIsothermal_(std::integral_constant<bool, GET_PROP_VALUE(TypeTag, EnableEnergyBalance) >(),
this->computeStorageForCellCenterNonIsothermal_(std::integral_constant<bool, ModelTraits::enableEnergyBalance() >(),
problem, scv, volVars, storage);
return storage;
......
......@@ -51,7 +51,7 @@ class NavierStokesNCVolumeVariables : public NavierStokesVolumeVariables<TypeTag
using GridView = typename GET_PROP_TYPE(TypeTag, GridView);
using Element = typename GridView::template Codim<0>::Entity;
enum { numComponents = GET_PROP_VALUE(TypeTag, NumComponents),
enum { numComponents = GET_PROP_TYPE(TypeTag, ModelTraits)::numComponents(),
numPhases = FluidSystem::numPhases,
mainCompIdx = Indices::mainCompIdx,
pressureIdx = Indices::pressureIdx
......
......@@ -40,8 +40,22 @@
#include <dumux/discretization/fourierslaw.hh>
namespace Dumux
namespace Dumux {
/*!
* \ingroup NavierStokesNIModel
* \brief Specifies a number properties of non-isothermal free flow
* flow models based on the specifics of a given isothermal model.
* \tparam IsothermalTraits Model traits of the isothermal model
*/
template<class IsothermalTraits>
struct NavierStokesNIModelTraits : public IsothermalTraits
{
//! We solve for one more equation, i.e. the energy balance
static constexpr int numEq() { return IsothermalTraits::numEq()+1; }
//! We additionally solve for the equation balance
static constexpr bool enableEnergyBalance() { return true; }
};
namespace Properties {
......@@ -52,24 +66,21 @@ NEW_TYPE_TAG(NavierStokesNonIsothermal);
// default property values for the non-isothermal single phase model
///////////////////////////////////////////////////////////////////////////
//! The non-isothermal model has one more balance equation (energy balance) compared to the non-isothermal ones
SET_PROP(NavierStokesNonIsothermal, NumEq)
//! use the non-isothermal model traits
SET_PROP(NavierStokesNonIsothermal, ModelTraits)
{
private:
static constexpr auto isothermalNumEq = GET_PROP_VALUE(TypeTag, IsothermalNumEq);
using IsothermalTraits = typename GET_PROP_TYPE(TypeTag, IsothermalModelTraits);
public:
static constexpr int value = isothermalNumEq + 1;
using type = NavierStokesNIModelTraits<IsothermalTraits>;
};
//! Enable the energy balance
SET_BOOL_PROP(NavierStokesNonIsothermal, EnableEnergyBalance, true);
//! The non-isothermal indices
SET_PROP(NavierStokesNonIsothermal, Indices)
{
private:
static constexpr int dim = GET_PROP_TYPE(TypeTag, GridView)::dimension;
static constexpr int numEq = GET_PROP_VALUE(TypeTag, NumEq);
static constexpr int numEq = GET_PROP_TYPE(TypeTag, ModelTraits)::numEq();
using IsothermalIndices = typename GET_PROP_TYPE(TypeTag, IsothermalIndices);
public:
using type = NavierStokesNonIsothermalIndices<dim, numEq, IsothermalIndices>;
......@@ -89,6 +100,6 @@ SET_TYPE_PROP(NavierStokesNonIsothermal, HeatConductionType, FouriersLaw<TypeTag
} // end namespace Properties
}
} // end namespace Dumux
#endif
......@@ -223,7 +223,7 @@ int main(int argc, char** argv) try
// calculate and print mass fluxes over the planes
flux.calculateMassOrMoleFluxes();
if(GET_PROP_VALUE(TypeTag, EnableEnergyBalance))
if(GET_PROP_TYPE(TypeTag, ModelTraits)::enableEnergyBalance())
{
std::cout << "mass / energy flux at middle is: " << flux.netFlux("middle") << std::endl;
std::cout << "mass / energy flux at outlet is: " << flux.netFlux("outlet") << std::endl;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment