12#ifndef DUMUX_NAVIERSTOKES_MOMENTUM_FLUXVARIABLES_HH
13#define DUMUX_NAVIERSTOKES_MOMENTUM_FLUXVARIABLES_HH
35template<
class TypeTag>
40 using GridVolumeVariables =
typename GridVariables::GridVolumeVariables;
41 using ElementVolumeVariables =
typename GridVolumeVariables::LocalView;
42 using VolumeVariables =
typename GridVolumeVariables::VolumeVariables;
44 using GridFluxVariablesCache =
typename GridVariables::GridFluxVariablesCache;
45 using ElementFluxVariablesCache =
typename GridFluxVariablesCache::LocalView;
46 using FluxVariablesCache =
typename GridFluxVariablesCache::FluxVariablesCache;
48 using GridGeometry =
typename GridVariables::GridGeometry;
49 using FVElementGeometry =
typename GridGeometry::LocalView;
50 using SubControlVolume =
typename FVElementGeometry::SubControlVolume;
51 using SubControlVolumeFace =
typename FVElementGeometry::SubControlVolumeFace;
56 using GridView =
typename GridGeometry::GridView;
57 using Element =
typename GridView::template Codim<0>::Entity;
60 using Indices =
typename ModelTraits::Indices;
63 using GlobalPosition =
typename Element::Geometry::GlobalCoordinate;
73 const SubControlVolumeFace&
scvFace,
87 ==
static_cast<std::size_t
>(GridView::dimension),
88 "Expects problem.dirichlet to return an array with as many entries as dimensions."
93 {
return *problemPtr_; }
96 {
return *elementPtr_; }
98 const SubControlVolumeFace&
scvFace()
const
99 {
return *scvFacePtr_; }
102 {
return *fvGeometryPtr_; }
105 {
return *elemVolVarsPtr_; }
108 {
return *elemFluxVarsCachePtr_; }
111 {
return *elemBcTypesPtr_; }
118 if (!this->
problem().enableInertiaTerms())
119 return NumEqVector(0.0);
121 if (this->
scvFace().isFrontal())
132 if (this->
scvFace().isFrontal())
158 const auto& scvf = this->
scvFace();
159 assert(scvf.isFrontal());
161 NumEqVector result(0.0);
171 static const bool enableUnsymmetrizedVelocityGradient
172 = getParamFromGroup<bool>(this->
problem().paramGroup(),
"FreeFlow.EnableUnsymmetrizedVelocityGradient",
false);
173 static const Scalar factor = enableUnsymmetrizedVelocityGradient ? 1.0 : 2.0;
176 result -= factor * mu * velGradII * Extrusion::area(
fvGeometry, scvf) *
elemVolVars[scvf.insideScvIdx()].extrusionFactor() * scvf.directionSign();
178 static const bool enableDilatationTerm = getParamFromGroup<bool>(this->
problem().paramGroup(),
"FreeFlow.EnableDilatationTerm",
false);
179 if (enableDilatationTerm)
181 Scalar divergence = velGradII;
184 const auto otherFrontalScvf = *(scvfs(
fvGeometry, scv).begin());
185 assert(otherFrontalScvf.isFrontal() && !otherFrontalScvf.boundary());
186 if (otherFrontalScvf.index() != scvf.index())
190 result += 2.0/3.0 * mu * divergence * scvf.directionSign() * Extrusion::area(
fvGeometry, scvf) *
elemVolVars[scvf.insideScvIdx()].extrusionFactor();
220 const auto& scvf = this->
scvFace();
221 assert(scvf.isLateral());
223 NumEqVector result(0.0);
227 const auto& scv =
fvGeometry.scv(scvf.insideScvIdx());
229 static const bool enableUnsymmetrizedVelocityGradient
230 = getParamFromGroup<bool>(
problem.paramGroup(),
"FreeFlow.EnableUnsymmetrizedVelocityGradient",
false);
238 GlobalPosition gradVn(0.0);
239 gradV.mv(scvf.unitOuterNormal(), gradVn);
240 const Scalar velocityGrad_ij = gradVn[scv.dofAxis()];
241 result -= mu * velocityGrad_ij;
244 if (!enableUnsymmetrizedVelocityGradient)
246 GlobalPosition gradVTransposedN(0.0);
247 gradV.mtv(scvf.unitOuterNormal(), gradVTransposedN);
248 const Scalar velocityGrad_ji = gradVTransposedN[scv.dofAxis()];
249 result -= mu * velocityGrad_ji;
253 return result * Extrusion::area(
fvGeometry, scvf) *
elemVolVars[scvf.insideScvIdx()].extrusionFactor();
274 NumEqVector result(0.0);
275 const auto& scvf = this->
scvFace();
276 if (scvf.isLateral() || scvf.boundary())
292 result -= referencePressure*scvf.area();
295 result *= scvf.directionSign();
319 NumEqVector flux(0.0);
320 const auto& scvf = this->
scvFace();
321 assert(scvf.isFrontal());
325 const auto velocitySelf =
elemVolVars[scvf.insideScvIdx()].velocity();
326 const auto velocityOpposite =
elemVolVars[scvf.outsideScvIdx()].velocity();
329 const Scalar transportingVelocity = (velocitySelf + velocityOpposite) * 0.5;
331 const bool selfIsUpstream = scvf.directionSign() ==
sign(transportingVelocity);
334 static const auto upwindWeight = getParamFromGroup<Scalar>(
problem.paramGroup(),
"Flux.UpwindWeight");
335 const Scalar transportedMomentum = selfIsUpstream ? (upwindWeight * velocitySelf + (1.0 - upwindWeight) * velocityOpposite) *
density
336 : (upwindWeight * velocityOpposite + (1.0 - upwindWeight) * velocitySelf) *
density;
338 return transportingVelocity * transportedMomentum * scvf.directionSign() * Extrusion::area(this->
fvGeometry(), scvf) * extrusionFactor_(
elemVolVars, scvf);
365 NumEqVector flux(0.0);
366 const auto& scvf = this->
scvFace();
367 assert(scvf.isLateral());
374 const Scalar transportingVelocity = [&]()
376 const auto& orthogonalScvf =
fvGeometry.lateralOrthogonalScvf(scvf);
377 const Scalar innerTransportingVelocity =
elemVolVars[orthogonalScvf.insideScvIdx()].velocity();
379 static const bool useOldScheme = getParam<bool>(
"FreeFlow.UseOldTransportingVelocity",
true);
383 if (scvf.boundary() &&
fvGeometry.scv(scvf.insideScvIdx()).boundary())
385 if (this->
elemBcTypes()[scvf.localIndex()].isDirichlet(scvf.normalAxis()))
386 return problem.dirichlet(this->
element(), scvf)[scvf.normalAxis()];
389 return innerTransportingVelocity;
395 if (this->
elemBcTypes()[scvf.localIndex()].isDirichlet(scvf.normalAxis()))
396 return 0.5*(
problem.dirichlet(this->
element(), scvf)[scvf.normalAxis()] + innerTransportingVelocity);
399 if (orthogonalScvf.boundary())
401 if (this->
elemBcTypes()[orthogonalScvf.localIndex()].isDirichlet(scvf.normalAxis()))
402 return 0.5*(
problem.dirichlet(this->element(), scvf)[scvf.normalAxis()] + innerTransportingVelocity);
404 return innerTransportingVelocity;
408 const auto insideVolume =
fvGeometry.scv(orthogonalScvf.insideScvIdx()).
volume();
409 const auto outsideVolume =
fvGeometry.scv(orthogonalScvf.outsideScvIdx()).
volume();
410 const auto outerTransportingVelocity =
elemVolVars[orthogonalScvf.outsideScvIdx()].velocity();
411 return (insideVolume*innerTransportingVelocity + outsideVolume*outerTransportingVelocity) / (insideVolume + outsideVolume);
414 const Scalar transportedMomentum = [&]()
416 const auto& insideScv =
fvGeometry.scv(scvf.insideScvIdx());
418 auto getDirichletMomentumFlux = [&]()
426 if (!this->
elemBcTypes()[scvf.localIndex()].isDirichlet(insideScv.dofAxis()))
427 DUNE_THROW(Dune::InvalidStateException,
"Neither Dirichlet nor Neumann BC set at " << scvf.ipGlobal());
429 return getDirichletMomentumFlux();
433 if (
fvGeometry.scvfIntegrationPointInConcaveCorner(scvf))
436 const auto& outsideScvfWithSameIntegrationPoint =
fvGeometry.outsideScvfWithSameIntegrationPoint(scvf);
437 if (!this->
problem().boundaryTypes(this->
element(), outsideScvfWithSameIntegrationPoint).isDirichlet(insideScv.dofAxis()))
438 DUNE_THROW(Dune::InvalidStateException,
"Neither Dirichlet nor Neumann BC set at " << outsideScvfWithSameIntegrationPoint.ipGlobal());
440 return getDirichletMomentumFlux();
444 const bool selfIsUpstream = scvf.directionSign() ==
sign(transportingVelocity);
446 const auto innerVelocity =
elemVolVars[scvf.insideScvIdx()].velocity();
447 const auto outerVelocity =
elemVolVars[scvf.outsideScvIdx()].velocity();
451 const auto insideMomentum = innerVelocity * rho.first;
452 const auto outsideMomentum = outerVelocity * rho.second;
455 static const auto upwindWeight = getParamFromGroup<Scalar>(
problem.paramGroup(),
"Flux.UpwindWeight");
457 return selfIsUpstream ? (upwindWeight * insideMomentum + (1.0 - upwindWeight) * outsideMomentum)
458 : (upwindWeight * outsideMomentum + (1.0 - upwindWeight) * insideMomentum);
461 return transportingVelocity * transportedMomentum * scvf.directionSign() * Extrusion::area(
fvGeometry, scvf) * extrusionFactor_(
elemVolVars, scvf);
466 template<
class ElementVolumeVariables,
class SubControlVolumeFace>
467 Scalar extrusionFactor_(
const ElementVolumeVariables&
elemVolVars,
const SubControlVolumeFace& scvf)
const
469 const auto& insideVolVars =
elemVolVars[scvf.insideScvIdx()];
470 const auto& outsideVolVars =
elemVolVars[scvf.outsideScvIdx()];
471 return harmonicMean(insideVolVars.extrusionFactor(), outsideVolVars.extrusionFactor());
475 const Problem* problemPtr_;
476 const Element* elementPtr_;
477 const FVElementGeometry* fvGeometryPtr_;
478 const SubControlVolumeFace* scvFacePtr_;
479 const ElementVolumeVariables* elemVolVarsPtr_;
480 const ElementFluxVariablesCache* elemFluxVarsCachePtr_;
481 const ElementBoundaryTypes* elemBcTypesPtr_;
The flux variables class for the Navier-Stokes model using the staggered grid discretization.
Definition: freeflow/navierstokes/momentum/fluxvariables.hh:37
NumEqVector pressureContribution() const
Returns the frontal pressure contribution.
Definition: freeflow/navierstokes/momentum/fluxvariables.hh:272
NumEqVector diffusiveMomentumFlux() const
Returns the diffusive momentum flux due to viscous forces.
Definition: freeflow/navierstokes/momentum/fluxvariables.hh:130
NumEqVector frontalAdvectiveMomentumFlux() const
Returns the frontal part of the momentum flux. This treats the flux over the staggered face at the ce...
Definition: freeflow/navierstokes/momentum/fluxvariables.hh:317
NumEqVector lateralAdvectiveMomentumFlux() const
Returns the advective momentum flux over the staggered face perpendicular to the scvf where the veloc...
Definition: freeflow/navierstokes/momentum/fluxvariables.hh:363
NumEqVector frontalDiffusiveMomentumFlux() const
Returns the frontal part of the momentum flux. This treats the flux over the staggered face at the ce...
Definition: freeflow/navierstokes/momentum/fluxvariables.hh:156
const ElementBoundaryTypes & elemBcTypes() const
Definition: freeflow/navierstokes/momentum/fluxvariables.hh:110
const Problem & problem() const
Definition: freeflow/navierstokes/momentum/fluxvariables.hh:92
const SubControlVolumeFace & scvFace() const
Definition: freeflow/navierstokes/momentum/fluxvariables.hh:98
const FVElementGeometry & fvGeometry() const
Definition: freeflow/navierstokes/momentum/fluxvariables.hh:101
NumEqVector advectiveMomentumFlux() const
Returns the diffusive momentum flux due to viscous forces.
Definition: freeflow/navierstokes/momentum/fluxvariables.hh:116
NavierStokesMomentumFluxVariables(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const SubControlVolumeFace &scvFace, const ElementVolumeVariables &elemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const ElementBoundaryTypes &elemBcTypes)
Definition: freeflow/navierstokes/momentum/fluxvariables.hh:70
const ElementVolumeVariables & elemVolVars() const
Definition: freeflow/navierstokes/momentum/fluxvariables.hh:104
const ElementFluxVariablesCache & elemFluxVarsCache() const
Definition: freeflow/navierstokes/momentum/fluxvariables.hh:107
const Element & element() const
Definition: freeflow/navierstokes/momentum/fluxvariables.hh:95
NumEqVector lateralDiffusiveMomentumFlux() const
Returns the diffusive momentum flux over the staggered face perpendicular to the scvf where the veloc...
Definition: freeflow/navierstokes/momentum/fluxvariables.hh:218
Helper class for calculating the velocity gradients for the Navier-Stokes model using the staggered g...
Definition: momentum/velocitygradients.hh:46
static auto velocityGradient(const FVElementGeometry &fvGeometry, const typename FVElementGeometry::SubControlVolumeFace &scvf, const ElemVolVars &elemVolVars, bool fullGradient=false)
Definition: momentum/velocitygradients.hh:50
static auto velocityGradII(const FVElementGeometry &fvGeometry, const typename FVElementGeometry::SubControlVolumeFace &scvf, const ElemVolVars &elemVolVars)
Returns the in-axis velocity gradient.
Definition: momentum/velocitygradients.hh:146
Defines all properties used in Dumux.
Some exceptions thrown in DuMux
Helper classes to compute the integration elements.
constexpr Scalar harmonicMean(Scalar x, Scalar y, Scalar wx=1.0, Scalar wy=1.0) noexcept
Calculate the (weighted) harmonic mean of two scalar values.
Definition: math.hh:57
constexpr int sign(const ValueType &value) noexcept
Sign or signum function.
Definition: math.hh:629
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:34
auto volume(const Geometry &geo, unsigned int integrationOrder=4)
The volume of a given geometry.
Definition: volume.hh:159
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:296
Define some often used mathematical functions.
The available discretization methods in Dumux.
std::string pressure(int phaseIdx) noexcept
I/O name of pressure for multiphase systems.
Definition: name.hh:22
std::string density(int phaseIdx) noexcept
I/O name of density for multiphase systems.
Definition: name.hh:53
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:166
A helper to deduce a vector with the same size as numbers of equations.
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.