version 3.8
box/dispersionflux.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//
13#ifndef DUMUX_DISCRETIZATION_BOX_DISPERSION_FLUX_HH
14#define DUMUX_DISCRETIZATION_BOX_DISPERSION_FLUX_HH
15
16#include <dune/common/fvector.hh>
17#include <dune/common/fmatrix.hh>
18
19#include <dumux/common/math.hh>
23#include <dumux/flux/traits.hh>
25
26namespace Dumux {
27
28// forward declaration
29template<class TypeTag, class DiscretizationMethod, ReferenceSystemFormulation referenceSystem>
31
36template <class TypeTag, ReferenceSystemFormulation referenceSystem>
37class DispersionFluxImplementation<TypeTag, DiscretizationMethods::Box, referenceSystem>
38{
44 using FVElementGeometry = typename GridGeometry::LocalView;
45 using SubControlVolume = typename GridGeometry::SubControlVolume;
46 using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace;
47 using Extrusion = Extrusion_t<GridGeometry>;
48 using ElementVolumeVariables = typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView;
50 using ElementFluxVariablesCache = typename GridFluxVariablesCache::LocalView;
51 using FluxVarCache = typename GridFluxVariablesCache::FluxVariablesCache;
53 using FluxTraits = typename Dumux::FluxTraits<FluxVariables>;
56 using Element = typename GridView::template Codim<0>::Entity;
58 using Indices = typename ModelTraits::Indices;
59
60 enum { dim = GridView::dimension} ;
61 enum { dimWorld = GridView::dimensionworld} ;
62 enum
63 {
64 numPhases = ModelTraits::numFluidPhases(),
65 numComponents = ModelTraits::numFluidComponents()
66 };
67
68 using DimWorldMatrix = Dune::FieldMatrix<Scalar, dimWorld, dimWorld>;
69 using ComponentFluxVector = Dune::FieldVector<Scalar, numComponents>;
70 using HeatFluxScalar = Scalar;
71
72 static constexpr bool stationaryVelocityField = FluxTraits::hasStationaryVelocityField();
73
74public:
75
76 //return the reference system
78 { return referenceSystem; }
79
86 static ComponentFluxVector compositionalDispersionFlux(const Problem& problem,
87 const Element& element,
88 const FVElementGeometry& fvGeometry,
89 const ElementVolumeVariables& elemVolVars,
90 const SubControlVolumeFace& scvf,
91 const int phaseIdx,
92 const ElementFluxVariablesCache& elemFluxVarsCache)
93 {
94 ComponentFluxVector componentFlux(0.0);
95
96 const auto& fluxVarsCache = elemFluxVarsCache[scvf];
97 const auto& shapeValues = fluxVarsCache.shapeValues();
98
99 // density interpolation
100 Scalar rhoMassOrMole(0.0);
101 for (auto&& scv : scvs(fvGeometry))
102 {
103 const auto rho = massOrMolarDensity(elemVolVars[scv], referenceSystem, phaseIdx);
104 rhoMassOrMole += rho * shapeValues[scv.indexInElement()][0];
105 }
106
107 for (int compIdx = 0; compIdx < numComponents; compIdx++)
108 {
109 // collect the dispersion tensor, the fluxVarsCache and the shape values
110 const auto& dispersionTensor =
111 ModelTraits::CompositionalDispersionModel::compositionalDispersionTensor(problem, scvf, fvGeometry,
112 elemVolVars, elemFluxVarsCache,
113 phaseIdx, compIdx);
114
115 // the mole/mass fraction gradient
116 Dune::FieldVector<Scalar, dimWorld> gradX(0.0);
117 for (auto&& scv : scvs(fvGeometry))
118 {
119 const auto x = massOrMoleFraction(elemVolVars[scv], referenceSystem, phaseIdx, compIdx);
120 gradX.axpy(x, fluxVarsCache.gradN(scv.indexInElement()));
121 }
122
123 // compute the dispersion flux
124 componentFlux[compIdx] = -1.0 * rhoMassOrMole * vtmv(scvf.unitOuterNormal(), dispersionTensor, gradX) * scvf.area();
125 if (BalanceEqOpts::mainComponentIsBalanced(phaseIdx) && !FluidSystem::isTracerFluidSystem())
126 componentFlux[phaseIdx] -= componentFlux[compIdx];
127 }
128 return componentFlux;
129 }
130
135 static HeatFluxScalar thermalDispersionFlux(const Problem& problem,
136 const Element& element,
137 const FVElementGeometry& fvGeometry,
138 const ElementVolumeVariables& elemVolVars,
139 const SubControlVolumeFace& scvf,
140 const int phaseIdx,
141 const ElementFluxVariablesCache& elemFluxVarsCache)
142 {
143 // collect the dispersion tensor
144 const auto& dispersionTensor =
145 ModelTraits::ThermalDispersionModel::thermalDispersionTensor(problem, scvf, fvGeometry,
146 elemVolVars, elemFluxVarsCache,
147 phaseIdx);
148 // compute the temperature gradient with the shape functions
149 const auto& fluxVarsCache = elemFluxVarsCache[scvf];
150 Dune::FieldVector<Scalar, GridView::dimensionworld> gradTemp(0.0);
151 for (auto&& scv : scvs(fvGeometry))
152 gradTemp.axpy(elemVolVars[scv].temperature(), fluxVarsCache.gradN(scv.indexInElement()));
153
154 // compute the heat conduction flux
155 return -1.0*vtmv(scvf.unitOuterNormal(), dispersionTensor, gradTemp)*Extrusion::area(fvGeometry, scvf);
156 }
157
158};
159
160} // end namespace Dumux
161
162#endif
static constexpr ReferenceSystemFormulation referenceSystemFormulation()
Definition: box/dispersionflux.hh:77
static ComponentFluxVector compositionalDispersionFlux(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolumeFace &scvf, const int phaseIdx, const ElementFluxVariablesCache &elemFluxVarsCache)
Returns the dispersive fluxes of all components within a fluid phase across the given sub-control vol...
Definition: box/dispersionflux.hh:86
static HeatFluxScalar thermalDispersionFlux(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolumeFace &scvf, const int phaseIdx, const ElementFluxVariablesCache &elemFluxVarsCache)
Returns the thermal dispersive flux across the given sub-control volume face.
Definition: box/dispersionflux.hh:135
Definition: box/dispersionflux.hh:30
Defines all properties used in Dumux.
Helper classes to compute the integration elements.
Defines the flux traits.
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:851
VolumeVariables::PrimaryVariables::value_type massOrMoleFraction(const VolumeVariables &volVars, ReferenceSystemFormulation referenceSys, const int phaseIdx, const int compIdx)
returns the mass or mole fraction to be used in Fick's law based on the reference system
Definition: referencesystemformulation.hh:54
VolumeVariables::PrimaryVariables::value_type massOrMolarDensity(const VolumeVariables &volVars, ReferenceSystemFormulation referenceSys, const int phaseIdx)
evaluates the density to be used in Fick's law based on the reference system
Definition: referencesystemformulation.hh:43
ReferenceSystemFormulation
The formulations available for Fick's law related to the reference system.
Definition: referencesystemformulation.hh:33
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.
CVFE< CVFEMethods::PQ1 > Box
Definition: method.hh:94
std::string temperature() noexcept
I/O name of temperature for equilibrium models.
Definition: name.hh:39
Definition: adapt.hh:17
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:166
The reference frameworks and formulations available for splitting total fluxes into a advective and d...
Traits of a flux variables type.
Definition: flux/traits.hh:32
static constexpr bool hasStationaryVelocityField()
Definition: flux/traits.hh:33