24#ifndef DUMUX_FLUX_SHALLOW_WATER_VISCOUS_FLUX_HH
25#define DUMUX_FLUX_SHALLOW_WATER_VISCOUS_FLUX_HH
33#include <dune/common/std/type_traits.hh>
34#include <dune/common/exceptions.hh>
45template <
typename T,
typename ...Ts>
46using FrictionLawDetector =
decltype(std::declval<T>().frictionLaw(std::declval<Ts>()...));
48template<
class T,
typename ...Args>
49static constexpr bool implementsFrictionLaw()
50{
return Dune::Std::is_detected<FrictionLawDetector, T, Args...>::value; }
60template<
class NumEqVector,
typename std::enable_if_t<NumEqVector::size() == 3,
int> = 0>
82 template<
class Problem,
class FVElementGeometry,
class ElementVolumeVariables>
84 const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
85 const FVElementGeometry& fvGeometry,
86 const ElementVolumeVariables& elemVolVars,
87 const typename FVElementGeometry::SubControlVolumeFace& scvf)
89 using Scalar =
typename NumEqVector::value_type;
90 using FluidSystem =
typename ElementVolumeVariables::VolumeVariables::FluidSystem;
95 const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()];
96 const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()];
98 const auto& insideScv = fvGeometry.scv(scvf.insideScvIdx());
99 const auto& outsideScv = fvGeometry.scv(scvf.outsideScvIdx());
101 const auto gradVelocity = [&]()
104 const auto velocityXLeft = insideVolVars.velocity(0);
105 const auto velocityYLeft = insideVolVars.velocity(1);
106 const auto velocityXRight = outsideVolVars.velocity(0);
107 const auto velocityYRight = outsideVolVars.velocity(1);
111 const auto& cellCenterToCellCenter = outsideScv.center() - insideScv.center();
112 const auto distance = cellCenterToCellCenter.two_norm();
113 const auto&
unitNormal = scvf.unitOuterNormal();
115 return std::array<Scalar, 2>{
116 (velocityXRight-velocityXLeft)*direction/
distance,
117 (velocityYRight-velocityYLeft)*direction/
distance
122 const auto waterDepthLeft = insideVolVars.waterDepth();
123 const auto waterDepthRight = outsideVolVars.waterDepth();
124 const auto averageDepth = 2.0*(waterDepthLeft*waterDepthRight)/(waterDepthLeft + waterDepthRight);
127 const Scalar turbViscosity = [&]()
130 static const auto turbBGViscosity = getParamFromGroup<Scalar>(problem.paramGroup(),
"ShallowWater.TurbulentViscosity", 1.0e-6);
133 static const auto useMixingLengthTurbulenceModel = getParamFromGroup<bool>(problem.paramGroup(),
"ShallowWater.UseMixingLengthTurbulenceModel",
false);
136 if (!useMixingLengthTurbulenceModel)
137 return turbBGViscosity;
139 using SpatialParams =
typename Problem::SpatialParams;
140 using E =
typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity;
141 using SCV =
typename FVElementGeometry::SubControlVolume;
142 if constexpr (!Detail::implementsFrictionLaw<SpatialParams, E, SCV>())
143 DUNE_THROW(Dune::IOError,
"Mixing length turbulence model enabled but spatial parameters do not implement the frictionLaw interface!");
149 static const auto turbConstV = getParamFromGroup<Scalar>(problem.paramGroup(),
"ShallowWater.VerticalCoefficientOfMixingLengthModel", 1.0);
150 static const auto turbConstH = getParamFromGroup<Scalar>(problem.paramGroup(),
"ShallowWater.HorizontalCoefficientOfMixingLengthModel", 0.1);
158 constexpr Scalar kappa = 0.41;
160 const Scalar ustar = [&]()
164 const auto& bottomShearStressInside = problem.spatialParams().frictionLaw(element, insideScv).bottomShearStress(insideVolVars);
165 const auto& bottomShearStressOutside = problem.spatialParams().frictionLaw(element, outsideScv).bottomShearStress(outsideVolVars);
166 const auto bottomShearStressInsideMag = bottomShearStressInside.two_norm();
167 const auto bottomShearStressOutsideMag = bottomShearStressOutside.two_norm();
171 const auto averageBottomShearStress = 2.0*(bottomShearStressInsideMag*bottomShearStressOutsideMag)
172 / max(1.0e-8,bottomShearStressInsideMag + bottomShearStressOutsideMag);
176 static_assert(!FluidSystem::isCompressible(0),
177 "The shallow water model assumes incompressible fluids"
181 return sqrt(averageBottomShearStress/insideVolVars.density());
184 const auto turbViscosityV = turbConstV * (kappa/6.0) * ustar * averageDepth;
211 const auto [gradU, gradV] = gradVelocity;
212 const auto mixingLengthSquared = turbConstH * turbConstH * averageDepth * averageDepth;
213 const auto turbViscosityH = mixingLengthSquared * sqrt(2.0*gradU*gradU + 2.0*gradV*gradV);
216 return turbBGViscosity + sqrt(turbViscosityV*turbViscosityV + turbViscosityH*turbViscosityH);
223 const auto freeSurfaceInside = insideVolVars.waterDepth() + insideVolVars.bedSurface();
224 const auto freeSurfaceOutside = outsideVolVars.waterDepth() + outsideVolVars.bedSurface();
225 const auto interfaceWaterDepth = max(min(freeSurfaceInside , freeSurfaceOutside) - max(insideVolVars.bedSurface(),outsideVolVars.bedSurface()),0.0);
226 const auto& [gradU, gradV] = gradVelocity;
227 const auto uViscousFlux = turbViscosity * interfaceWaterDepth * gradU;
228 const auto vViscousFlux = turbViscosity * interfaceWaterDepth * gradV;
231 localFlux[1] = -uViscousFlux * scvf.area();
232 localFlux[2] = -vViscousFlux * scvf.area();
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
Function to limit the fluxes.
Classes related to flux variables caching.
static ctype distance(const Dune::FieldVector< ctype, dimWorld > &a, const Dune::FieldVector< ctype, dimWorld > &b)
Compute the shortest distance between two points.
Definition: distance.hh:292
Vector unitNormal(const Vector &v)
Create a vector normal to the given one (v is expected to be non-zero)
Definition: normal.hh:68
static NumEqVector flux(const Problem &problem, const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const typename FVElementGeometry::SubControlVolumeFace &scvf)
Compute the viscous momentum flux contribution from the interface shear stress.
Definition: shallowwaterviscousflux.hh:83
typename NumEqVectorTraits< PrimaryVariables >::type NumEqVector
A vector with the same size as numbers of equations This is the default implementation and has to be ...
Definition: numeqvector.hh:46
The empty filler class corresponding to EmptyCache.
Definition: fluxvariablescaching.hh:32
Definition: fluxvariablescaching.hh:67
Computes the shallow water viscous momentum flux due to (turbulent) viscosity by adding all surroundi...
Definition: shallowwaterviscousflux.hh:62