3.3.0
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
flux/staggered/freeflow/fickslaw.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 *****************************************************************************/
25#ifndef DUMUX_DISCRETIZATION_STAGGERED_FICKS_LAW_HH
26#define DUMUX_DISCRETIZATION_STAGGERED_FICKS_LAW_HH
27
28#include <numeric>
29#include <dune/common/fvector.hh>
30
33#include <dumux/common/math.hh>
34
40
41
42namespace Dumux {
43
44// forward declaration
45template<class TypeTag, DiscretizationMethod discMethod, ReferenceSystemFormulation referenceSystem>
46class FicksLawImplementation;
47
52template <class TypeTag, ReferenceSystemFormulation referenceSystem>
53class FicksLawImplementation<TypeTag, DiscretizationMethod::staggered, referenceSystem>
54{
57 using FVElementGeometry = typename GridGeometry::LocalView;
58 using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace;
59 using Extrusion = Extrusion_t<GridGeometry>;
61 using GridView = typename GridGeometry::GridView;
62 using Element = typename GridView::template Codim<0>::Entity;
64 using Indices = typename ModelTraits::Indices;
66
67 static constexpr int numComponents = ModelTraits::numFluidComponents();
68 static constexpr int numPhases = ModelTraits::numFluidPhases();
69
70 using NumEqVector = Dune::FieldVector<Scalar, numComponents>;
71
72 static_assert(ModelTraits::numFluidPhases() == 1, "Only one phase supported!");
73
74public:
75 // state the discretization method this implementation belongs to
77 //return the reference system
79 { return referenceSystem; }
80
84
86
93 template<class Problem, class ElementVolumeVariables>
94 static NumEqVector flux(const Problem& problem,
95 const Element& element,
96 const FVElementGeometry& fvGeometry,
97 const ElementVolumeVariables& elemVolVars,
98 const SubControlVolumeFace &scvf)
99 {
100 NumEqVector flux(0.0);
101
102 // There is no diffusion over outflow boundaries (grad x == 0).
103 // We assume that if an outflow BC is set for the first transported component, this
104 // also holds for all other components.
105 if (scvf.boundary() && problem.boundaryTypes(element, scvf).isOutflow(Indices::conti0EqIdx + 1))
106 return flux;
107
108 const int phaseIdx = 0;
109
110 const auto& insideScv = fvGeometry.scv(scvf.insideScvIdx());
111 const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()];
112 const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()];
113
114 const Scalar insideDistance = (insideScv.dofPosition() - scvf.ipGlobal()).two_norm();
115 const Scalar insideDensity = massOrMolarDensity(insideVolVars, referenceSystem, phaseIdx);
116
117 for (int compIdx = 0; compIdx < numComponents; ++compIdx)
118 {
119 if (compIdx == FluidSystem::getMainComponent(phaseIdx))
120 continue;
121
122 const Scalar massOrMoleFractionInside = massOrMoleFraction(insideVolVars, referenceSystem, phaseIdx, compIdx);
123 const Scalar massOrMoleFractionOutside = massOrMoleFraction(outsideVolVars, referenceSystem, phaseIdx, compIdx);
124 const Scalar insideD = getEffectiveDiffusionCoefficient_(insideVolVars, phaseIdx, compIdx) * insideVolVars.extrusionFactor();
125
126 if (scvf.boundary())
127 {
128 flux[compIdx] = insideDensity * insideD
129 * (massOrMoleFractionInside - massOrMoleFractionOutside) / insideDistance;
130 }
131 else
132 {
133 const auto& outsideScv = fvGeometry.scv(scvf.outsideScvIdx());
134 const Scalar outsideD = getEffectiveDiffusionCoefficient_(outsideVolVars, phaseIdx, compIdx)
135 * outsideVolVars.extrusionFactor();
136 const Scalar outsideDistance = (outsideScv.dofPosition() - scvf.ipGlobal()).two_norm();
137 const Scalar outsideDensity = massOrMolarDensity(outsideVolVars, referenceSystem, phaseIdx);
138
139 const Scalar avgDensity = 0.5*(insideDensity + outsideDensity);
140 const Scalar avgD = harmonicMean(insideD, outsideD, insideDistance, outsideDistance);
141
142 flux[compIdx] = avgDensity * avgD
143 * (massOrMoleFractionInside - massOrMoleFractionOutside) / (insideDistance + outsideDistance);
144 }
145 }
146
147 // Fick's law (for binary systems) states that the net flux of mass within the bulk phase has to be zero:
148 const Scalar cumulativeFlux = std::accumulate(flux.begin(), flux.end(), 0.0);
149 flux[FluidSystem::getMainComponent(0)] = -cumulativeFlux;
150
151 flux *= Extrusion::area(scvf);
152
153 return flux;
154 }
155
156private:
157 static Scalar getEffectiveDiffusionCoefficient_(const VolumeVariables& volVars, const int phaseIdx, const int compIdx)
158 {
159 return volVars.effectiveDiffusionCoefficient(phaseIdx, FluidSystem::getMainComponent(phaseIdx), compIdx);
160 }
161};
162} // end namespace Dumux
163
164#endif
Define some often used mathematical functions.
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
The available discretization methods in Dumux.
Helper classes to compute the integration elements.
The reference frameworks and formulations available for splitting total fluxes into a advective and d...
Container storing the diffusion coefficients required by Fick's law. Uses the minimal possible contai...
Classes related to flux variables caching.
DiscretizationMethod
The available discretization methods in Dumux.
Definition: method.hh:37
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:66
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:55
ReferenceSystemFormulation
The formulations available for Fick's law related to the reference system.
Definition: referencesystemformulation.hh:45
constexpr Scalar harmonicMean(Scalar x, Scalar y, Scalar wx=1.0, Scalar wy=1.0) noexcept
Calculate the (weighted) harmonic mean of two scalar values.
Definition: math.hh:68
Definition: adapt.hh:29
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:177
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:149
forward declaration of the method-specific implemetation
Definition: flux/box/fickslaw.hh:43
Container storing the diffusion coefficients required by Fick's law. Uses the minimal possible contai...
Definition: fickiandiffusioncoefficients.hh:44
Definition: fluxvariablescaching.hh:64
static NumEqVector flux(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolumeFace &scvf)
Returns the diffusive fluxes of all components within a fluid phase across the given sub-control volu...
Definition: flux/staggered/freeflow/fickslaw.hh:94
static constexpr ReferenceSystemFormulation referenceSystemFormulation()
Definition: flux/staggered/freeflow/fickslaw.hh:78
Declares all properties used in Dumux.