version 3.11-dev
Loading...
Searching...
No Matches
freeflow/navierstokes/mass/1p/localresidual.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_FREEFLOW_NAVIERSTOKES_MASS_1P_LOCAL_RESIDUAL_HH
13#define DUMUX_FREEFLOW_NAVIERSTOKES_MASS_1P_LOCAL_RESIDUAL_HH
14
15#include <type_traits>
16
20#include <dumux/common/concepts/variables_.hh>
25
26namespace Dumux {
27
33template<class Problem>
35: public std::false_type
36{};
37
42template<class TypeTag>
45{
48 using GridVariablesCache = Concept::GridVariablesCache_t<GridVariables>;
49 using ElementVariables = typename GridVariablesCache::LocalView;
50 using Variables = Concept::Variables_t<GridVariables>;
51
55 using ElementDiscretization = typename GridGeometry::LocalView;
56 using SubControlVolume = typename ElementDiscretization::SubControlVolume;
57 using SubControlVolumeFace = typename ElementDiscretization::SubControlVolumeFace;
58 using GridView = typename GridGeometry::GridView;
59 using Element = typename GridView::template Codim<0>::Entity;
62
63 using Extrusion = Extrusion_t<GridGeometry>;
65
66public:
68 using ParentType::ParentType;
69
73 template<class ElementResidualVector>
74 void addToElementStorage(ElementResidualVector& storage,
75 const Problem& problem,
76 const Element& element,
77 const ElementDiscretization& elemDisc,
78 const ElementVariables& elemVars,
79 bool isPreviousTimeLevel) const
80 {
81 FeResidual::addStorageTerms(storage, problem, elemDisc, elemVars, isPreviousTimeLevel);
82 }
83
87 template<class ElementResidualVector>
88 void addToElementFluxAndSourceResidual(ElementResidualVector& residual,
89 const Problem& problem,
90 const Element& element,
91 const ElementDiscretization& elemDisc,
92 const ElementVariables& elemVars) const
93 {
94 FeResidual::addFluxAndSourceTerms(residual, problem, elemDisc, elemVars);
95 }
96
100 NumEqVector computeStorage(const Problem& problem,
101 const SubControlVolume& scv,
102 const Variables& vars) const
103 {
104 NumEqVector storage(0.0);
105 storage[ModelTraits::Indices::conti0EqIdx] = vars.density();
106
107 // consider energy storage for non-isothermal models
108 if constexpr (ModelTraits::enableEnergyBalance())
109 storage[ModelTraits::Indices::energyEqIdx] = vars.density() * vars.internalEnergy();
110
111 return storage;
112 }
113
123 NumEqVector storageIntegral(const ElementDiscretization& elemDisc,
124 const ElementVariables& elemVars,
125 const SubControlVolume& scv,
126 bool isPreviousTimeLevel) const
127 {
128 const auto& vars = elemVars[scv];
129 // We apply mass lumping here
130 NumEqVector storage(0.0);
131 storage[ModelTraits::Indices::conti0EqIdx] = vars.density();
132
133 // consider energy storage for non-isothermal models
134 if constexpr (ModelTraits::enableEnergyBalance())
135 storage[ModelTraits::Indices::energyEqIdx] = vars.density() * vars.internalEnergy();
136
137 storage *= Extrusion::volume(elemDisc, scv) * vars.extrusionFactor();
138
139 return storage;
140 }
141
152 template<class ElementFluxVariablesCache>
153 NumEqVector computeFlux(const Problem& problem,
154 const Element& element,
155 const ElementDiscretization& elemDisc,
156 const ElementVariables& elemVars,
157 const SubControlVolumeFace& scvf,
158 const ElementFluxVariablesCache& elemFluxVarsCache) const
159 {
161 FluxVariables fluxVars;
162 fluxVars.init(problem, element, elemDisc, elemVars, scvf, elemFluxVarsCache);
163 auto flux = fluxVars.flux(0);
164
165 // the auxiliary flux is enabled if the trait is specialized for the problem
166 // this can be used, for example, to implement flux stabilization terms
168 flux += problem.auxiliaryFlux(element, elemDisc, elemVars, elemFluxVarsCache, scvf);
169
170 return flux;
171 }
172
181 NumEqVector fluxIntegral(const ElementDiscretization& elemDisc,
182 const ElementVariables& elemVars,
183 const SubControlVolumeFace& scvf) const
184 {
185 static_assert(!ModelTraits::enableEnergyBalance(),
186 "The flux integral does not include the energy balance");
187
188 const auto& problem = this->asImp().problem();
189 Scalar volumeFlux = 0.0;
190 for (const auto& qpData : CVFE::quadratureRule(elemDisc, scvf))
191 {
192 const auto& faceIpData = qpData.ipData();
193 volumeFlux += qpData.weight() * (problem.velocity(elemDisc, faceIpData) * faceIpData.unitOuterNormal());
194 }
195
196 static const auto upwindWeight
197 = getParamFromGroup<Scalar>(this->problem().paramGroup(), "Flux.UpwindWeight", 1.0);
198
199 const auto& insideVars = elemVars[elemDisc.scv(scvf.insideScvIdx())];
200 const auto& outsideVars = elemVars[elemDisc.scv(scvf.outsideScvIdx())];
201 const bool insideIsUpwind = volumeFlux > 0.0;
202 const auto& upwindVars = insideIsUpwind ? insideVars : outsideVars;
203 const auto& downwindVars = insideIsUpwind ? outsideVars : insideVars;
204
205 NumEqVector flux(0.0);
206 flux[ModelTraits::Indices::conti0EqIdx]
207 = volumeFlux * (upwindWeight * upwindVars.density() + (1.0 - upwindWeight) * downwindVars.density());
208
209 // the auxiliary flux is enabled if the trait is specialized for the problem
210 // this can be used, for example, to implement flux stabilization terms
212 flux += problem.auxiliaryFlux(elemDisc.element(), elemDisc, elemVars, scvf);
213
214 return flux * insideVars.extrusionFactor();
215 }
216};
217
218} // end namespace Dumux
219
220#endif
Helper class for evaluating FE-based local residuals.
Definition mass/1p/felocalresidual.hh:35
static void addStorageTerms(ResidualVector &storage, const Problem &problem, const ElementDiscretization &elemDisc, const ElementVariables &elemVars, const bool isPreviousTimeLevel)
Definition mass/1p/felocalresidual.hh:47
static void addFluxAndSourceTerms(ResidualVector &residual, const Problem &problem, const ElementDiscretization &elemDisc, const ElementVariables &elemVars)
Definition mass/1p/felocalresidual.hh:89
Element-wise calculation of the Navier-Stokes residual for single-phase flow.
Definition freeflow/navierstokes/mass/1p/localresidual.hh:45
NumEqVector fluxIntegral(const ElementDiscretization &elemDisc, const ElementVariables &elemVars, const SubControlVolumeFace &scvf) const
Calculates the flux integral over a face of a sub control volume.
Definition freeflow/navierstokes/mass/1p/localresidual.hh:181
NumEqVector computeFlux(const Problem &problem, const Element &element, const ElementDiscretization &elemDisc, const ElementVariables &elemVars, const SubControlVolumeFace &scvf, const ElementFluxVariablesCache &elemFluxVarsCache) const
Evaluate the mass flux over a face of a sub control volume.
Definition freeflow/navierstokes/mass/1p/localresidual.hh:153
NumEqVector computeStorage(const Problem &problem, const SubControlVolume &scv, const Variables &vars) const
Calculate the storage term of the equation.
Definition freeflow/navierstokes/mass/1p/localresidual.hh:100
void addToElementFluxAndSourceResidual(ElementResidualVector &residual, const Problem &problem, const Element &element, const ElementDiscretization &elemDisc, const ElementVariables &elemVars) const
Add flux and source residual contribution for non-CV local dofs.
Definition freeflow/navierstokes/mass/1p/localresidual.hh:88
void addToElementStorage(ElementResidualVector &storage, const Problem &problem, const Element &element, const ElementDiscretization &elemDisc, const ElementVariables &elemVars, bool isPreviousTimeLevel) const
Add the storage of non-CV local dofs at one time level.
Definition freeflow/navierstokes/mass/1p/localresidual.hh:74
NumEqVector storageIntegral(const ElementDiscretization &elemDisc, const ElementVariables &elemVars, const SubControlVolume &scv, bool isPreviousTimeLevel) const
Calculate the storage term of the equation.
Definition freeflow/navierstokes/mass/1p/localresidual.hh:123
Defines all properties used in Dumux.
The default local operator than can be specialized for each discretization scheme.
Helper classes to compute the integration elements.
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
T getParamFromGroup(Args &&... args)
A free function to get a parameter from the parameter tree singleton with a model group.
Definition parameters.hh:165
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition propertysystem.hh:296
Element-wise calculation of the Navier-Stokes mass residual for single-phase flow when using fe discr...
auto quadratureRule(const FVElementGeometry &fvGeometry, const typename FVElementGeometry::SubControlVolume &scv, QuadratureRules::MidpointQuadrature)
Midpoint quadrature for scv.
Definition quadraturerules.hh:160
Definition adapt.hh:17
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
A helper to deduce a vector with the same size as numbers of equations.
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
Quadrature rules over sub-control volumes and sub-control volume faces.
Traits class to be specialized for problems to add auxiliary fluxes.
Definition freeflow/navierstokes/mass/1p/localresidual.hh:36