12#ifndef DUMUX_NAVIERSTOKES_MOMENTUM_CVFE_FE_LOCAL_RESIDUAL_HELPER_HH
13#define DUMUX_NAVIERSTOKES_MOMENTUM_CVFE_FE_LOCAL_RESIDUAL_HELPER_HH
15#include <dune/geometry/quadraturerules.hh>
16#include <dumux/common/typetraits/localdofs_.hh>
29template<
class Scalar,
class NumEqVector,
class LocalBasis,
class Extrusion>
32 using RangeType =
typename LocalBasis::Traits::RangeType;
45 template<
class Res
idualVector,
class Problem,
class FVElementGeometry,
class ElementVariables>
47 const Problem& problem,
48 const FVElementGeometry& fvGeometry,
49 const ElementVariables& prevElemVars,
50 const ElementVariables& curElemVars,
51 const Scalar timeStepSize)
53 if constexpr (Detail::LocalDofs::hasNonCVLocalDofsInterface<FVElementGeometry>())
56 if (nonCVLocalDofs(fvGeometry).empty())
59 const auto& localBasis = fvGeometry.feLocalBasis();
60 std::vector<RangeType> integralShapeFunctions(localBasis.size(), RangeType(0.0));
63 const auto& geometry = fvGeometry.elementGeometry();
64 const auto& element = fvGeometry.element();
65 using GlobalPosition =
typename FVElementGeometry::GridGeometry::GlobalCoordinate;
70 const auto& ipData = qpData.ipData();
72 FeIpData feIpData(geometry, ipData.local(), ipData.global(), localBasis);
75 for (
const auto& localDof : nonCVLocalDofs(fvGeometry))
76 integralShapeFunctions[localDof.index()] += qpData.weight() * feIpData.shapeValue(localDof.index());
79 for (
const auto& localDof : nonCVLocalDofs(fvGeometry))
81 const auto localDofIdx = localDof.index();
82 const auto& data = ipData(fvGeometry, localDof);
83 const auto curDensity = problem.density(element, fvGeometry, data,
false);
84 const auto prevDensity = problem.density(element, fvGeometry, data,
true);
85 const auto curVelocity = curElemVars[localDofIdx].velocity();
86 const auto prevVelocity = prevElemVars[localDofIdx].velocity();
87 auto timeDeriv = (curDensity*curVelocity - prevDensity*prevVelocity);
88 timeDeriv /= timeStepSize;
91 for (
int eqIdx = 0; eqIdx < NumEqVector::dimension; ++eqIdx)
92 residual[localDofIdx][eqIdx] += integralShapeFunctions[localDofIdx]*timeDeriv[eqIdx];
105 template<
class Res
idualVector,
class Problem,
class FVElementGeometry,
class ElementVariables>
107 const Problem& problem,
108 const FVElementGeometry& fvGeometry,
109 const ElementVariables& elemVars)
111 if constexpr (Detail::LocalDofs::hasNonCVLocalDofsInterface<FVElementGeometry>())
114 if (nonCVLocalDofs(fvGeometry).empty())
117 if constexpr (
requires { problem.pointSources(); })
119 if (!problem.pointSources().empty())
120 DUNE_THROW(Dune::NotImplemented,
"Point sources are not implemented for hybrid momentum schemes.");
123 static const bool enableUnsymmetrizedVelocityGradient
126 const auto& element = fvGeometry.element();
127 using Cache =
typename ElementVariables::InterpolationPointData;
131 const auto& ipData = qpData.ipData();
133 const auto& ipCache = cache(elemVars, ipData);
134 FluxFunctionContext context(problem, fvGeometry, elemVars, ipCache);
135 const auto& v = context.velocity();
136 const auto& gradV = context.gradVelocity();
139 const Scalar mu = problem.effectiveViscosity(element, fvGeometry, ipData);
141 const Scalar density = problem.density(element, fvGeometry, ipData);
143 for (
const auto& localDof : nonCVLocalDofs(fvGeometry))
145 const auto localDofIdx = localDof.index();
148 if (problem.enableInertiaTerms())
149 fluxAndSourceTerm -= density*(v*ipCache.gradN(localDofIdx))*v;
152 fluxAndSourceTerm += enableUnsymmetrizedVelocityGradient ?
153 mu*
mv(gradV, ipCache.gradN(localDofIdx))
157 fluxAndSourceTerm -= problem.pressure(element, fvGeometry, ipData) * ipCache.gradN(localDofIdx);
160 auto sourceAtIp = problem.source(fvGeometry, elemVars, ipData);
162 sourceAtIp += density * problem.gravity();
164 const auto& shapeValues = ipCache.shapeValues();
165 for (
int eqIdx = 0; eqIdx < NumEqVector::dimension; ++eqIdx)
167 fluxAndSourceTerm[eqIdx] -= shapeValues[localDofIdx] * sourceAtIp[eqIdx];
168 residual[localDofIdx][eqIdx] += qpData.weight()*fluxAndSourceTerm[eqIdx];
181template<
class TypeTag>
188 using GridVariablesCache =
typename GridVariables::GridVariablesCache;
189 using ElementVariables =
typename GridVariablesCache::LocalView;
194 using ElementDiscretization =
typename GridDiscretization::LocalView;
195 using GridView =
typename GridDiscretization::GridView;
196 using Element =
typename GridView::template Codim<0>::Entity;
202 using LocalBasis =
typename GridDiscretization::FeCache::FiniteElementType::Traits::LocalBasisType;
207 using ParentType::ParentType;
210 const Problem& problem,
211 const Element& element,
212 const ElementDiscretization& elemDisc,
213 const ElementVariables& prevElemVolVars,
214 const ElementVariables& curElemVolVars)
const
217 residual, problem, elemDisc, prevElemVolVars, curElemVolVars, this->timeLoop().timeStepSize()
222 const Problem& problem,
223 const Element& element,
224 const ElementDiscretization& elemDisc,
225 const ElementVariables& elemVars)
const
228 residual, problem, elemDisc, elemVars
Boundary flag to store e.g. in sub control volume faces.
Definition fem/interpolationpointdata.hh:21
Element-wise calculation of the Navier-Stokes residual for models using FE discretizations.
Definition felocalresidual.hh:184
typename ParentType::ElementResidualVector ElementResidualVector
Definition felocalresidual.hh:206
void addToElementFluxAndSourceResidual(ElementResidualVector &residual, const Problem &problem, const Element &element, const ElementDiscretization &elemDisc, const ElementVariables &elemVars) const
Definition felocalresidual.hh:221
void addToElementStorageResidual(ElementResidualVector &residual, const Problem &problem, const Element &element, const ElementDiscretization &elemDisc, const ElementVariables &prevElemVolVars, const ElementVariables &curElemVolVars) const
Definition felocalresidual.hh:209
Helper class for evaluating FE-based local residuals.
Definition felocalresidual.hh:31
static void addFluxAndSourceTerms(ResidualVector &residual, const Problem &problem, const FVElementGeometry &fvGeometry, const ElementVariables &elemVars)
Add flux and source residual contribution for non-CV local dofs.
Definition felocalresidual.hh:106
static void addStorageTerms(ResidualVector &residual, const Problem &problem, const FVElementGeometry &fvGeometry, const ElementVariables &prevElemVars, const ElementVariables &curElemVars, const Scalar timeStepSize)
Add storage residual contribution for non-CV local dofs.
Definition felocalresidual.hh:46
Context for interpolating data on interpolation points.
Definition flux.hh:99
Helper classes to compute the integration elements.
Shape functions and gradients at an interpolation point.
The flux variables class for the Navier-Stokes model using control-volume finite element schemes.
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
Dune::DenseVector< V >::derived_type mv(const Dune::DenseMatrix< MAT > &M, const Dune::DenseVector< V > &v)
Returns the result of the projection of a vector v with a Matrix M.
Definition math.hh:829
Dune::FieldMatrix< Scalar, n, m > getTransposed(const Dune::FieldMatrix< Scalar, m, n > &M)
Transpose a FieldMatrix.
Definition math.hh:712
T getParamFromGroup(Args &&... args)
A free function to get a parameter from the parameter tree singleton with a model group.
Definition parameters.hh:149
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition propertysystem.hh:296
auto quadratureRule(const FVElementGeometry &fvGeometry, const typename FVElementGeometry::SubControlVolume &scv, QuadratureRules::MidpointQuadrature)
Midpoint quadrature for scv.
Definition quadraturerules.hh:159
typename Detail::DiscretizationDefaultLocalOperator< TypeTag >::type DiscretizationDefaultLocalOperator
Definition defaultlocaloperator.hh:26
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition extrusion.hh:257