3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
scheidegger.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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_MATERIAL_FLUIDMATRIX_DISPERSIONTENSORS_SCHEIDEGGER_HH
25#define DUMUX_MATERIAL_FLUIDMATRIX_DISPERSIONTENSORS_SCHEIDEGGER_HH
26
27#include <algorithm>
28#include <cmath>
29#include <dune/common/math.hh>
30#include <dune/common/std/type_traits.hh>
31#include <dune/common/fmatrix.hh>
36#include <dumux/flux/traits.hh>
37
38namespace Dumux {
39
40namespace Detail {
41template <class Problem, class SubControlVolumeFace>
42using HasVelocityInSpatialParams = decltype(std::declval<Problem>().spatialParams().velocity(std::declval<SubControlVolumeFace>()));
43
44template<class Problem, class SubControlVolumeFace>
45static constexpr bool hasVelocityInSpatialParams()
46{ return Dune::Std::is_detected<HasVelocityInSpatialParams, Problem, SubControlVolumeFace>::value; }
47}
48
53template<class TypeTag>
55{
58 using FVElementGeometry = typename GridGeometry::LocalView;
59 using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace;
60 using ElementVolumeVariables = typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView;
61
64 static const int dimWorld = GridView::dimensionworld;
65 using DimWorldMatrix = Dune::FieldMatrix<Scalar, dimWorld, dimWorld>;
66
68 using FluxTraits = typename Dumux::FluxTraits<FluxVariables>;
69 static constexpr bool stationaryVelocityField = FluxTraits::hasStationaryVelocityField();
70
71public:
72 template <class ElementFluxVariablesCache>
73 static DimWorldMatrix compositionalDispersionTensor(const Problem& problem,
74 const SubControlVolumeFace& scvf,
75 const FVElementGeometry& fvGeometry,
76 const ElementVolumeVariables& elemVolVars,
77 const ElementFluxVariablesCache& elemFluxVarsCache,
78 const int phaseIdx,
79 const int compIdx)
80 {
81 DimWorldMatrix dispersionTensor(0.0);
82
83 // Get the velocity either from the reconstruction, or from the spatialparams
84 auto velocity = dispersionVelocity_(problem, scvf, fvGeometry, elemVolVars, elemFluxVarsCache);
85
86 // collect the dispersion alphas at this location
87 std::array<Scalar,2> dispersivity = problem.spatialParams().dispersionAlphas(scvf.center(), phaseIdx, compIdx);
88
89 return scheideggerTensor_(dispersivity, velocity);
90 }
91
92 template <class ElementFluxVariablesCache>
93 static DimWorldMatrix thermalDispersionTensor(const Problem& problem,
94 const SubControlVolumeFace& scvf,
95 const FVElementGeometry& fvGeometry,
96 const ElementVolumeVariables& elemVolVars,
97 const ElementFluxVariablesCache& elemFluxVarsCache,
98 const int phaseIdx)
99 {
100 DimWorldMatrix dispersionTensor(0.0);
101
102 // Get the velocity either from the reconstruction, or from the spatialparams
103 auto velocity = dispersionVelocity_(problem, scvf, fvGeometry, elemVolVars, elemFluxVarsCache);
104
105 // collect the dispersion alphas at this location
106 std::array<Scalar,2> dispersivity = problem.spatialParams().dispersionAlphas(scvf.center(), phaseIdx); //TODO: fix this?
107
108 return scheideggerTensor_(dispersivity, velocity);
109 }
110
111private:
112
113 template <class ElementFluxVariablesCache>
114 static Dune::FieldVector<Scalar, dimWorld> dispersionVelocity_(const Problem& problem,
115 const SubControlVolumeFace& scvf,
116 [[maybe_unused]] const FVElementGeometry& fvGeometry,
117 [[maybe_unused]] const ElementVolumeVariables& elemVolVars,
118 [[maybe_unused]] const ElementFluxVariablesCache& elemFluxVarsCache)
119 {
120 // Calculate Darcy's velocity
121 Dune::FieldVector<Scalar, dimWorld> velocity(0.0);
122 if constexpr (stationaryVelocityField)
123 {
124 if constexpr (!Detail::hasVelocityInSpatialParams<Problem,SubControlVolumeFace>() )
125 DUNE_THROW(Dune::NotImplemented, "\n Please provide the stationary velocity field in the spatialparams via a velocity function.");
126 else
127 velocity = problem.spatialParams().velocity(scvf);
128 }
129 else
130 {
131 if constexpr (FVElementGeometry::GridGeometry::discMethod == DiscretizationMethods::box)
132 {
133 const auto& fluxVarsCache = elemFluxVarsCache[scvf];
134 const auto& shapeValues = fluxVarsCache.shapeValues();
135
136 // get inside and outside permeability tensors and calculate the harmonic mean
137 const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()];
138 const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()];
139 const auto K = faceTensorAverage(insideVolVars.permeability(),
140 outsideVolVars.permeability(),
141 scvf.unitOuterNormal());
142
143 // evaluate gradP - rho*g at integration point
144 Dune::FieldVector<Scalar, dimWorld> gradP(0.0);
145 Scalar rho(0.0);
146 static const bool enableGravity = getParamFromGroup<bool>(problem.paramGroup(), "Problem.EnableGravity");
147 for (auto&& scv : scvs(fvGeometry))
148 {
149 const auto& volVars = elemVolVars[scv];
150
151 if (enableGravity)
152 rho += volVars.density(0)*shapeValues[scv.indexInElement()][0];
153 // the global shape function gradient
154 gradP.axpy(volVars.pressure(0), fluxVarsCache.gradN(scv.indexInElement()));
155 }
156
157 if (enableGravity)
158 gradP.axpy(-rho, problem.spatialParams().gravity(scvf.center()));
159
160 velocity = gradP;
161 velocity *= K;
162
163 velocity /= -0.5 * (insideVolVars.viscosity() + outsideVolVars.viscosity());
164 }
165 else
166 DUNE_THROW(Dune::NotImplemented, "\n Scheidegger Dispersion for compositional models without given constant velocity field is only implemented using the Box method.");
167 }
168
169 return velocity;
170 }
171
172 static DimWorldMatrix scheideggerTensor_(const std::array<Scalar,2>& dispersivity,
173 const Dune::FieldVector<Scalar, dimWorld>& velocity)
174 {
175 DimWorldMatrix scheideggerTensor(0.0);
176
177 //matrix multiplication of the velocity at the interface: vv^T
178 for (int i=0; i < dimWorld; i++)
179 for (int j = 0; j < dimWorld; j++)
180 scheideggerTensor[i][j] = velocity[i]*velocity[j];
181
182 //normalize velocity product --> vv^T/||v||, [m/s]
183 Scalar vNorm = velocity.two_norm();
184
185 scheideggerTensor /= vNorm;
186 if (vNorm < 1e-20)
187 scheideggerTensor = 0;
188
189 //multiply with dispersivity difference: vv^T/||v||*(alphaL - alphaT), [m^2/s] --> alphaL = longitudinal disp., alphaT = transverse disp.
190 scheideggerTensor *= (dispersivity[0] - dispersivity[1]);
191
192 //add ||v||*alphaT to the main diagonal:vv^T/||v||*(alphaL - alphaT) + ||v||*alphaT, [m^2/s]
193 for (int i = 0; i < dimWorld; i++)
194 scheideggerTensor[i][i] += vNorm*dispersivity[1];
195
196 return scheideggerTensor;
197 }
198
199};
200
201} // end namespace Dumux
202
203#endif
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
The available discretization methods in Dumux.
A free function to average a Tensor at an interface.
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:180
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:41
decltype(std::declval< Problem >().spatialParams().velocity(std::declval< SubControlVolumeFace >())) HasVelocityInSpatialParams
Definition: scheidegger.hh:42
static constexpr bool hasVelocityInSpatialParams()
Definition: scheidegger.hh:45
constexpr Box box
Definition: method.hh:136
Traits of a flux variables type.
Definition: flux/traits.hh:44
static constexpr bool hasStationaryVelocityField()
Definition: flux/traits.hh:45
Scheidegger's dispersion tensor.
Definition: scheidegger.hh:55
static DimWorldMatrix compositionalDispersionTensor(const Problem &problem, const SubControlVolumeFace &scvf, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const int phaseIdx, const int compIdx)
Definition: scheidegger.hh:73
static DimWorldMatrix thermalDispersionTensor(const Problem &problem, const SubControlVolumeFace &scvf, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const int phaseIdx)
Definition: scheidegger.hh:93
Declares all properties used in Dumux.
Defines the flux traits.