version 3.11-dev
Loading...
Searching...
No Matches
flux/cvfe/darcyslaw.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//
16#ifndef DUMUX_DISCRETIZATION_CVFE_DARCYS_LAW_HH
17#define DUMUX_DISCRETIZATION_CVFE_DARCYS_LAW_HH
18
19#include <dumux/common/math.hh>
26
27namespace Dumux {
28
37template<class Scalar, class GridGeometry, class GravityTermDensity = PhaseDensityInGravityTerm>
39{
40 using FVElementGeometry = typename GridGeometry::LocalView;
41 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
42 using Extrusion = Extrusion_t<GridGeometry>;
43 using GridView = typename GridGeometry::GridView;
44 using Element = typename GridView::template Codim<0>::Entity;
45
46 static constexpr int dim = GridView::dimension;
47 static constexpr int dimWorld = GridView::dimensionworld;
48
49public:
50
61 template<class Problem, class ElementVolumeVariables, class ElementFluxVarsCache>
62 static Scalar flux(const Problem& problem,
63 const Element& element,
64 const FVElementGeometry& fvGeometry,
65 const ElementVolumeVariables& elemVolVars,
66 const SubControlVolumeFace& scvf,
67 const int phaseIdx,
68 const ElementFluxVarsCache& elemFluxVarCache)
69 {
70 const auto& fluxVarCache = elemFluxVarCache[scvf];
71 const auto& insideScv = fvGeometry.scv(scvf.insideScvIdx());
72 const auto& outsideScv = fvGeometry.scv(scvf.outsideScvIdx());
73 const auto& insideVolVars = elemVolVars[insideScv];
74 const auto& outsideVolVars = elemVolVars[outsideScv];
75
76 auto insideK = insideVolVars.permeability();
77 auto outsideK = outsideVolVars.permeability();
78
79 // scale with correct extrusion factor
80 insideK *= insideVolVars.extrusionFactor();
81 outsideK *= outsideVolVars.extrusionFactor();
82
83 const auto K = faceTensorAverage(insideK, outsideK, scvf.unitOuterNormal());
84 const auto gradPotential = potentialGradient(problem, fvGeometry, elemVolVars, scvf, phaseIdx, fluxVarCache);
85
86 // apply the permeability and return the flux
87 return -1.0*vtmv(scvf.unitOuterNormal(), K, gradPotential)*Extrusion::area(fvGeometry, scvf);
88 }
89
94 template<class Problem, class ElementVolumeVariables, class FluxVarCache>
95 static Dune::FieldVector<Scalar, dimWorld> potentialGradient(const Problem& problem,
96 const FVElementGeometry& fvGeometry,
97 const ElementVolumeVariables& elemVolVars,
98 const SubControlVolumeFace& scvf,
99 const int phaseIdx,
100 const FluxVarCache& fluxVarCache)
101 {
102 static const bool enableGravity = getParamFromGroup<bool>(problem.paramGroup(), "Problem.EnableGravity");
103
104 const auto& shapeValues = fluxVarCache.shapeValues();
105
106 Dune::FieldVector<Scalar, dimWorld> gradP(0.0);
107 Scalar rho(0.0);
108 for (auto&& scv : scvs(fvGeometry))
109 {
110 const auto& volVars = elemVolVars[scv];
111
112 if (enableGravity)
113 rho += GravityTermDensity::density(problem, volVars, phaseIdx)*shapeValues[scv.indexInElement()][0];
114
115 // the global shape function gradient
116 gradP.axpy(volVars.pressure(phaseIdx), fluxVarCache.gradN(scv.indexInElement()));
117 }
118
119 if (enableGravity)
120 gradP.axpy(-rho, problem.spatialParams().gravity(scvf.center()));
121
122 return gradP;
123 }
124
125 // compute transmissibilities ti for analytical Jacobians
126 template<class Problem, class ElementVolumeVariables, class FluxVarCache>
127 static std::vector<Scalar> calculateTransmissibilities(const Problem& problem,
128 const Element& element,
129 const FVElementGeometry& fvGeometry,
130 const ElementVolumeVariables& elemVolVars,
131 const SubControlVolumeFace& scvf,
132 const FluxVarCache& fluxVarCache)
133 {
134 const auto& insideScv = fvGeometry.scv(scvf.insideScvIdx());
135 const auto& outsideScv = fvGeometry.scv(scvf.outsideScvIdx());
136 const auto& insideVolVars = elemVolVars[insideScv];
137 const auto& outsideVolVars = elemVolVars[outsideScv];
138
139 auto insideK = insideVolVars.permeability();
140 auto outsideK = outsideVolVars.permeability();
141
142 // scale with correct extrusion factor
143 insideK *= insideVolVars.extrusionFactor();
144 outsideK *= outsideVolVars.extrusionFactor();
145
146 const auto K = faceTensorAverage(insideK, outsideK, scvf.unitOuterNormal());
147
148 std::vector<Scalar> ti(fvGeometry.numScv());
149 for (const auto& scv : scvs(fvGeometry))
150 ti[scv.indexInElement()] =
151 -1.0*Extrusion::area(fvGeometry, scvf)*vtmv(scvf.unitOuterNormal(), K, fluxVarCache.gradN(scv.indexInElement()));
152
153 return ti;
154 }
155};
156
157// forward declaration
158template<class TypeTag, class DiscretizationMethod>
159class DarcysLawImplementation;
160
165template<class TypeTag, class DM>
167: public CVFEDarcysLaw<GetPropType<TypeTag, Properties::Scalar>, GetPropType<TypeTag, Properties::GridGeometry>>
168{};
169
170} // end namespace Dumux
171
172#endif
Darcy's law for control-volume finite element schemes.
Definition flux/cvfe/darcyslaw.hh:39
static Scalar flux(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolumeFace &scvf, const int phaseIdx, const ElementFluxVarsCache &elemFluxVarCache)
Returns the advective flux of a fluid phase across the given sub-control volume face.
Definition flux/cvfe/darcyslaw.hh:62
static std::vector< Scalar > calculateTransmissibilities(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolumeFace &scvf, const FluxVarCache &fluxVarCache)
Definition flux/cvfe/darcyslaw.hh:127
static Dune::FieldVector< Scalar, dimWorld > potentialGradient(const Problem &problem, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolumeFace &scvf, const int phaseIdx, const FluxVarCache &fluxVarCache)
Returns of a fluid phase at the integration point of the given sub-control volume face.
Definition flux/cvfe/darcyslaw.hh:95
forward declaration of the method-specific implementation
Definition flux/ccmpfa/darcyslaw.hh:27
Defines all properties used in Dumux.
Helper classes to compute the integration elements.
A free function to average a Tensor at an interface.
The density in the gravity term of Darcy's law.
Dune::DenseMatrix< MAT >::value_type vtmv(const Dune::DenseVector< V1 > &v1, const Dune::DenseMatrix< MAT > &M, const Dune::DenseVector< V2 > &v2)
Evaluates the scalar product of a vector v2, projected by a matrix M, with a vector v1.
Definition math.hh:880
T getParamFromGroup(Args &&... args)
A free function to get a parameter from the parameter tree singleton with a model group.
Definition parameters.hh:165
Define some often used mathematical functions.
The available discretization methods in Dumux.
Definition interpolate.hh:27
Definition method.hh:20
Definition adapt.hh:17
std::ranges::range auto scvs(const FVElementGeometry &fvGeometry, const LocalDof &localDof)
Definition localdof.hh:82
Scalar faceTensorAverage(const Scalar T1, const Scalar T2, const Dune::FieldVector< Scalar, dim > &normal)
Average of a discontinuous scalar field at discontinuity interface (for compatibility reasons with th...
Definition facetensoraverage.hh:29
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition extrusion.hh:257
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.