version 3.8
freeflow/navierstokes/momentum/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-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_NAVIERSTOKES_MOMENTUM_LOCAL_RESIDUAL_HH
13#define DUMUX_NAVIERSTOKES_MOMENTUM_LOCAL_RESIDUAL_HH
14
20#include <dune/common/hybridutilities.hh>
21
22namespace Dumux {
23
28template<class TypeTag>
30: public FaceCenteredLocalResidual<TypeTag>
31{
33 friend class FaceCenteredLocalResidual<TypeTag>;
34
36
37 using GridVolumeVariables = typename GridVariables::GridVolumeVariables;
38 using ElementVolumeVariables = typename GridVolumeVariables::LocalView;
39 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
40
41 using GridFluxVariablesCache = typename GridVariables::GridFluxVariablesCache;
42 using ElementFluxVariablesCache = typename GridFluxVariablesCache::LocalView;
43
48 using FVElementGeometry = typename GridGeometry::LocalView;
49 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
50 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
51 using GridView = typename GridGeometry::GridView;
52 using Element = typename GridView::template Codim<0>::Entity;
57
58 using Extrusion = Extrusion_t<GridGeometry>;
59
61
62 static constexpr auto dim = GridView::dimension;
63
64public:
66 using ParentType::ParentType;
67
78 NumEqVector computeStorage(const Problem& problem,
79 const SubControlVolume& scv,
80 const VolumeVariables& volVars,
81 const bool isPreviousStorage = false) const
82 {
83 const auto& element = problem.gridGeometry().element(scv.elementIndex());
84 return problem.density(element, scv, isPreviousStorage) * volVars.velocity();
85 }
86
100 NumEqVector computeSource(const Problem& problem,
101 const Element& element,
102 const FVElementGeometry& fvGeometry,
103 const ElementVolumeVariables& elemVolVars,
104 const SubControlVolume& scv) const
105 {
106 NumEqVector source = ParentType::computeSource(problem, element, fvGeometry, elemVolVars, scv);
107 source += problem.gravity()[scv.dofAxis()] * problem.density(element, scv);
108
109 // Axisymmetric problems in 2D feature an extra source terms arising from the transformation to cylindrical coordinates.
110 // See Ferziger/Peric: Computational methods for fluid dynamics chapter 8.
111 // https://doi.org/10.1007/978-3-540-68228-8 (page 301)
112 if constexpr (dim == 2 && isRotationalExtrusion<Extrusion>)
113 {
114 if (scv.dofAxis() == Extrusion::radialAxis)
115 {
116 const auto r = scv.center()[scv.dofAxis()] - fvGeometry.gridGeometry().bBoxMin()[scv.dofAxis()];
117 const auto& scvf = (*scvfs(fvGeometry, scv).begin()); // the frontal scvf belonging to the scv
118
119 // Velocity term
120 source -= -2.0*problem.effectiveViscosity(element, fvGeometry, scvf) * elemVolVars[scv].velocity() / (r*r);
121
122 // Pressure term (needed because we incorporate pressure in terms of a surface integral).
123 // grad(p) becomes div(pI) + (p/r)*n_r in cylindrical coordinates. The second term
124 // is new with respect to Cartesian coordinates and handled below as a source term.
125 source += problem.pressure(element, fvGeometry, scvf)/r;
126 }
127 }
128
129 return source;
130 }
131
143 NumEqVector computeFlux(const Problem& problem,
144 const Element& element,
145 const FVElementGeometry& fvGeometry,
146 const ElementVolumeVariables& elemVolVars,
147 const SubControlVolumeFace& scvf,
148 const ElementFluxVariablesCache& elemFluxVarsCache,
149 const ElementBoundaryTypes& elemBcTypes) const
150 {
151 FluxVariables fluxVars(problem, element, fvGeometry, scvf, elemVolVars, elemFluxVarsCache, elemBcTypes);
152
153 NumEqVector flux(0.0);
154 flux += fluxVars.advectiveMomentumFlux();
155 flux += fluxVars.diffusiveMomentumFlux();
156 flux += fluxVars.pressureContribution();
157 return flux;
158 }
159
162 NumEqVector maybeHandleDirichletBoundary(const Problem& problem,
163 const Element& element,
164 const FVElementGeometry& fvGeometry,
165 const ElementVolumeVariables& elemVolVars,
166 const ElementBoundaryTypes& elemBcTypes,
167 const ElementFluxVariablesCache& elemFluxVarsCache,
168 const SubControlVolumeFace& scvf) const
169 {
170 if (const auto& scv = fvGeometry.scv(scvf.insideScvIdx()); scv.boundary())
171 {
172 const auto& frontalScvfOnBoundary = fvGeometry.frontalScvfOnBoundary(scv);
173 const auto& bcTypes = elemBcTypes[frontalScvfOnBoundary.localIndex()];
174 if (bcTypes.isDirichlet(scv.dofAxis()))
175 return NumEqVector(0.0); // skip calculation as Dirichlet BC will be incorporated explicitly by assembler.
176 }
177
178 // Default: The scv does not lie on a boundary with a Dirichlet condition for the velocity in normal direction.
179 // Check for a Neumann condition or calculate the flux as normal.
180 if (elemBcTypes.hasNeumann())
181 return this->asImp().maybeHandleNeumannBoundary(problem, element, fvGeometry, elemVolVars, elemBcTypes, elemFluxVarsCache, scvf);
182 else
183 return this->asImp().computeFlux(problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache, elemBcTypes);
184 }
185
188 NumEqVector maybeHandleNeumannBoundary(const Problem& problem,
189 const Element& element,
190 const FVElementGeometry& fvGeometry,
191 const ElementVolumeVariables& elemVolVars,
192 const ElementBoundaryTypes& elemBcTypes,
193 const ElementFluxVariablesCache& elemFluxVarsCache,
194 const SubControlVolumeFace& scvf) const
195 {
196 static_assert(FVElementGeometry::GridGeometry::discMethod == DiscretizationMethods::fcstaggered); // TODO overload this method for different discretizations
197 static_assert(
198 std::decay_t<decltype(
199 problem.neumann(element, fvGeometry, elemVolVars, elemFluxVarsCache, scvf)
200 )>::size() == ModelTraits::dim(),
201 "The momentum model expects problem.neumann to return a vector of size dim. "
202 "When in doubt you should be able to use 'using NumEqVector = typename ParentType::NumEqVector;'."
203 );
204 assert(elemBcTypes.hasNeumann());
205
206 const auto& scv = fvGeometry.scv(scvf.insideScvIdx());
207
208 if (scv.boundary())
209 {
210 // This is the most simple case for a frontal scvf lying directly on the boundary.
211 // Just evaluate the Neumann flux for the normal velocity component.
212 //
213 // ---------------- * || frontal face of staggered half-control-volume
214 // | || # *
215 // | || # * D dof position (coincides with integration point where
216 // | || scv D * the Neumann flux is evaluated, here for x component)
217 // | || # *
218 // | || # * -- element boundaries
219 // ---------------- *
220 // y * domain boundary
221 // ^
222 // | # current scvf over which Neumann flux is evaluated
223 // ----> x
224 //
225 if (scvf.boundary() && scvf.isFrontal())
226 {
227 const auto& bcTypes = elemBcTypes[scvf.localIndex()];
228 if (bcTypes.hasNeumann() && bcTypes.isNeumann(scv.dofAxis()))
229 {
230 const auto neumannFluxes = problem.neumann(element, fvGeometry, elemVolVars, elemFluxVarsCache, scvf);
231 return neumannFluxes[scv.dofAxis()] * Extrusion::area(fvGeometry, scvf) * elemVolVars[scv].extrusionFactor();
232 }
233 }
234 else if (scvf.isLateral())
235 {
236 // If a sub control volume lies on a boundary, Neumann fluxes also need to be considered for its lateral faces,
237 // even though those do not necessarily lie on a boundary (only their edges / integration points are touching the boundary).
238 // We cannot simply calculate momentum fluxes across the lateral boundary in this situation because we might not
239 // have enough information at the boundary to do so.
240 // We first need to find the scv's frontal face on the boundary to check if there actually is a Neumann BC.
241 // Afterwards, we use the actual (lateral) scvf to retrieve the Neumann flux at its integration point intersecting with the boundary.
242 //
243 //
244 // ---------######O * || frontal face of staggered half-control-volume
245 // | || : *
246 // | || : * D dof position
247 // | || scv D *
248 // | || : * -- element boundaries
249 // | || : *
250 // ---------------- * * domain boundary
251 //
252 // y # current scvf over which Neumann flux is evaluated
253 // ^
254 // | : frontal scvf on boundary
255 // ----> x
256 // O integration point at which Neumann flux is evaluated (here for y component)
257 //
258 const auto& frontalScvfOnBoundary = fvGeometry.frontalScvfOnBoundary(scv);
259 assert(frontalScvfOnBoundary.isFrontal() && frontalScvfOnBoundary.boundary());
260 const auto& bcTypes = elemBcTypes[frontalScvfOnBoundary.localIndex()];
261 if (bcTypes.hasNeumann() && bcTypes.isNeumann(scvf.normalAxis()))
262 {
263 const auto neumannFluxes = problem.neumann(element, fvGeometry, elemVolVars, elemFluxVarsCache, scvf);
264 return neumannFluxes[scv.dofAxis()] * Extrusion::area(fvGeometry, scvf) * elemVolVars[scv].extrusionFactor();
265 }
266 }
267 }
268 else if (scvf.boundary())
269 {
270 // Here, the lateral face does lie on a boundary. Retrieve the Neumann flux component for
271 // the corresponding scvs' DOF orientation.
272 //
273 //
274 // *****************
275 // ---------######O || frontal face of staggered half-control-volume
276 // | || :
277 // | || : D dof position
278 // | || scv D
279 // | || : -- element boundaries
280 // | || :
281 // ---------------- * domain boundary
282 //
283 // y # current scvf over which Neumann flux is evaluated
284 // ^
285 // | : frontal scvf on boundary
286 // ----> x
287 // O integration point at which Neumann flux is evaluated (here for x component)
288 //
289 assert(scvf.isLateral());
290 const auto& bcTypes = elemBcTypes[scvf.localIndex()];
291 if (bcTypes.hasNeumann() && bcTypes.isNeumann(scv.dofAxis()))
292 {
293 const auto neumannFluxes = problem.neumann(element, fvGeometry, elemVolVars, elemFluxVarsCache, scvf);
294 return neumannFluxes[scv.dofAxis()] * Extrusion::area(fvGeometry, scvf) * elemVolVars[scv].extrusionFactor();
295 }
296 }
297
298 // Default: Neither the scvf itself nor a lateral one considers a Neumann flux. We just calculate the flux as normal.
299 return this->asImp().computeFlux(problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache, elemBcTypes);
300 }
301
303 Implementation &asImp_()
304 { return *static_cast<Implementation *>(this); }
305
307 const Implementation &asImp_() const
308 { return *static_cast<const Implementation *>(this); }
309};
310
311} // end namespace Dumux
312
313#endif
The element-wise residual for finite volume schemes.
Definition: fvlocalresidual.hh:35
Implementation & asImp()
Definition: fvlocalresidual.hh:487
const Problem & problem() const
the problem
Definition: fvlocalresidual.hh:472
The element-wise residual for the box scheme.
Definition: fclocalresidual.hh:34
NumEqVector computeSource(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolume &scv) const
Calculate the source term of the equation.
Definition: fclocalresidual.hh:100
Element-wise calculation of the Navier-Stokes residual for models using the staggered discretization.
Definition: freeflow/navierstokes/momentum/localresidual.hh:31
NumEqVector maybeHandleNeumannBoundary(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const ElementBoundaryTypes &elemBcTypes, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
Definition: freeflow/navierstokes/momentum/localresidual.hh:188
NumEqVector computeSource(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolume &scv) const
Calculate the source term of the equation.
Definition: freeflow/navierstokes/momentum/localresidual.hh:100
NumEqVector computeFlux(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolumeFace &scvf, const ElementFluxVariablesCache &elemFluxVarsCache, const ElementBoundaryTypes &elemBcTypes) const
Evaluates the mass flux over a face of a sub control volume.
Definition: freeflow/navierstokes/momentum/localresidual.hh:143
Implementation & asImp_()
Returns the implementation of the problem (i.e. static polymorphism)
Definition: freeflow/navierstokes/momentum/localresidual.hh:303
const Implementation & asImp_() const
Returns the implementation of the problem (i.e. static polymorphism)
Definition: freeflow/navierstokes/momentum/localresidual.hh:307
NumEqVector maybeHandleDirichletBoundary(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const ElementBoundaryTypes &elemBcTypes, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
Definition: freeflow/navierstokes/momentum/localresidual.hh:162
NumEqVector computeStorage(const Problem &problem, const SubControlVolume &scv, const VolumeVariables &volVars, const bool isPreviousStorage=false) const
Calculate the source term of the equation.
Definition: freeflow/navierstokes/momentum/localresidual.hh:78
Defines all properties used in Dumux.
Helper classes to compute the integration elements.
Calculates the element-wise residual for the box scheme.
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
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:296
The available discretization methods in Dumux.
constexpr FCStaggered fcstaggered
Definition: method.hh:151
Definition: adapt.hh:17
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.