version 3.11-dev
Loading...
Searching...
No Matches
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// SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12
13#ifndef DUMUX_MATERIAL_FLUIDMATRIX_DISPERSIONTENSORS_SCHEIDEGGER_HH
14#define DUMUX_MATERIAL_FLUIDMATRIX_DISPERSIONTENSORS_SCHEIDEGGER_HH
15
16#include <algorithm>
17#include <cmath>
18#include <dune/common/math.hh>
19#include <dune/common/std/type_traits.hh>
20#include <dune/common/fmatrix.hh>
23#include <dumux/common/math.hh>
26#include <dumux/flux/traits.hh>
27
28namespace Dumux {
29
30namespace Detail {
31template <class Problem, class SubControlVolumeFace>
32using HasVelocityInSpatialParams = decltype(std::declval<Problem>().spatialParams().velocity(std::declval<SubControlVolumeFace>()));
33
34template<class Problem, class SubControlVolumeFace>
35static constexpr bool hasVelocityInSpatialParams()
36{ return Dune::Std::is_detected<HasVelocityInSpatialParams, Problem, SubControlVolumeFace>::value; }
37}
38
43
60template<class TypeTag>
62{
65 using FVElementGeometry = typename GridGeometry::LocalView;
66 using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace;
67 using ElementVolumeVariables = typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView;
68
71 static const int dimWorld = GridView::dimensionworld;
72 using DimWorldMatrix = Dune::FieldMatrix<Scalar, dimWorld, dimWorld>;
73
76 using FluxTraits = typename Dumux::FluxTraits<FluxVariables>;
77 static constexpr bool stationaryVelocityField = FluxTraits::hasStationaryVelocityField();
78
79public:
80 template <class ElementFluxVariablesCache>
81 static DimWorldMatrix compositionalDispersionTensor(const Problem& problem,
82 const SubControlVolumeFace& scvf,
83 const FVElementGeometry& fvGeometry,
84 const ElementVolumeVariables& elemVolVars,
85 const ElementFluxVariablesCache& elemFluxVarsCache,
86 const int phaseIdx,
87 const int compIdx)
88 {
89 if (phaseIdx > 0)
90 DUNE_THROW(Dune::NotImplemented, "Scheidegger dispersion tensors are only implemented for single phase flows.");
91
92 // Get the velocity either from the reconstruction, or from the spatialparams
93 auto velocity = dispersionVelocity_(problem, scvf, fvGeometry, elemVolVars, elemFluxVarsCache);
94
95 // collect the dispersion alphas at this location
96 std::array<Scalar,2> dispersivity = problem.spatialParams().dispersionAlphas(scvf.center(), phaseIdx, compIdx);
97
98 return scheideggerDispersionTensor_(dispersivity, velocity);
99 }
100
101 template <class ElementFluxVariablesCache>
102 static DimWorldMatrix thermalDispersionTensor(const Problem& problem,
103 const SubControlVolumeFace& scvf,
104 const FVElementGeometry& fvGeometry,
105 const ElementVolumeVariables& elemVolVars,
106 const ElementFluxVariablesCache& elemFluxVarsCache,
107 const int phaseIdx)
108 {
109 if (phaseIdx > 0)
110 DUNE_THROW(Dune::NotImplemented, "Scheidegger dispersion tensors are only implemented for single phase flows.");
111
112 // Get the velocity either from the reconstruction, or from the spatialparams
113 auto velocity = dispersionVelocity_(problem, scvf, fvGeometry, elemVolVars, elemFluxVarsCache);
114
115 // collect the dispersion alphas at this location
116 std::array<Scalar,2> dispersivity = problem.spatialParams().dispersionAlphas(scvf.center(), phaseIdx); //TODO: fix this?
117
118 return scheideggerDispersionTensor_(dispersivity, velocity);
119 }
120
121private:
122
123 template <class ElementFluxVariablesCache>
124 static Dune::FieldVector<Scalar, dimWorld> dispersionVelocity_(const Problem& problem,
125 const SubControlVolumeFace& scvf,
126 [[maybe_unused]] const FVElementGeometry& fvGeometry,
127 [[maybe_unused]] const ElementVolumeVariables& elemVolVars,
128 [[maybe_unused]] const ElementFluxVariablesCache& elemFluxVarsCache)
129 {
130 // Calculate Darcy's velocity
131 Dune::FieldVector<Scalar, dimWorld> velocity(0.0);
132 if constexpr (stationaryVelocityField)
133 {
135 DUNE_THROW(Dune::NotImplemented, "\n Please provide the stationary velocity field in the spatialparams via a velocity function.");
136 else
137 velocity = problem.spatialParams().velocity(scvf);
138 }
139 else
140 {
141 if constexpr (FVElementGeometry::GridGeometry::discMethod == DiscretizationMethods::box)
142 {
143 const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()];
144 const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()];
145 const auto K = faceTensorAverage(insideVolVars.permeability(),
146 outsideVolVars.permeability(),
147 scvf.unitOuterNormal());
148
149 const auto gradPotential = AdvectionType::potentialGradient(problem, fvGeometry, elemVolVars, scvf,
150 0, elemFluxVarsCache[scvf]);
151 velocity = mv(K, gradPotential);
152 velocity /= -0.5 * (insideVolVars.viscosity() + outsideVolVars.viscosity());
153 }
154 else
155 DUNE_THROW(Dune::NotImplemented, "\n Scheidegger Dispersion for compositional models without given constant velocity field is only implemented using the Box method.");
156 }
157
158 return velocity;
159 }
160
161 static DimWorldMatrix scheideggerDispersionTensor_(const std::array<Scalar,2>& dispersivity,
162 const Dune::FieldVector<Scalar, dimWorld>& velocity)
163 {
164 DimWorldMatrix dispersionTensor(0.0);
165
166 //matrix multiplication of the velocity at the interface: vv^T
167 for (int i=0; i < dimWorld; i++)
168 for (int j = 0; j < dimWorld; j++)
169 dispersionTensor[i][j] = velocity[i]*velocity[j];
170
171 //normalize velocity product --> vv^T/||v||, [m/s]
172 const Scalar vNorm = velocity.two_norm();
173 if (vNorm < 1e-20)
174 return DimWorldMatrix(0.0);
175
176 dispersionTensor /= vNorm;
177
178 //multiply with dispersivity difference: vv^T/||v||*(alphaL - alphaT), [m^2/s] --> alphaL = longitudinal disp., alphaT = transverse disp.
179 dispersionTensor *= (dispersivity[0] - dispersivity[1]);
180
181 //add ||v||*alphaT to the main diagonal:vv^T/||v||*(alphaL - alphaT) + ||v||*alphaT, [m^2/s]
182 for (int i = 0; i < dimWorld; i++)
183 dispersionTensor[i][i] += vNorm*dispersivity[1];
184
185 return dispersionTensor;
186 }
187
188};
189
190} // end namespace Dumux
191
192#endif
Scheidegger's dispersion tensor.
Definition scheidegger.hh:62
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:81
static DimWorldMatrix thermalDispersionTensor(const Problem &problem, const SubControlVolumeFace &scvf, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const int phaseIdx)
Definition scheidegger.hh:102
Defines all properties used in Dumux.
A free function to average a Tensor at an interface.
Defines the flux traits.
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
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition propertysystem.hh:296
Define some often used mathematical functions.
The available discretization methods in Dumux.
Definition cvfelocalresidual.hh:25
decltype(std::declval< Problem >().spatialParams().velocity(std::declval< SubControlVolumeFace >())) HasVelocityInSpatialParams
Definition scheidegger.hh:32
static constexpr bool hasVelocityInSpatialParams()
Definition scheidegger.hh:35
constexpr Box box
Definition method.hh:176
Definition adapt.hh:17
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
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
Traits of a flux variables type.
Definition flux/traits.hh:32
static constexpr bool hasStationaryVelocityField()
Definition flux/traits.hh:33