3.1-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
porousmediumflow/3pwateroil/localresidual.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 *****************************************************************************/
26#ifndef DUMUX_3P2CNI_LOCAL_RESIDUAL_HH
27#define DUMUX_3P2CNI_LOCAL_RESIDUAL_HH
28
31
32namespace Dumux {
38template<class TypeTag>
39class ThreePWaterOilLocalResidual : public GetPropType<TypeTag, Properties::BaseLocalResidual>
40{
41protected:
46 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
47 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
53 using Element = typename GridView::template Codim<0>::Entity;
58
59 enum {
62
63 conti0EqIdx = Indices::conti0EqIdx,
65
66 wPhaseIdx = FluidSystem::wPhaseIdx,
67 nPhaseIdx = FluidSystem::nPhaseIdx,
68 gPhaseIdx = FluidSystem::gPhaseIdx,
69
70 wCompIdx = FluidSystem::wCompIdx,
71 nCompIdx = FluidSystem::nCompIdx,
72 };
73
75 static constexpr bool useMoles = getPropValue<TypeTag, Properties::UseMoles>();
76public:
77 using ParentType::ParentType;
78
91 const SubControlVolume& scv,
92 const VolumeVariables& volVars) const
93 {
94 NumEqVector storage(0.0);
95
96 const auto massOrMoleDensity = [](const auto& volVars, const int phaseIdx)
97 { return useMoles ? volVars.molarDensity(phaseIdx) : volVars.density(phaseIdx); };
98
99 const auto massOrMoleFraction= [](const auto& volVars, const int phaseIdx, const int compIdx)
100 { return useMoles ? volVars.moleFraction(phaseIdx, compIdx) : volVars.massFraction(phaseIdx, compIdx); };
101
102 // compute storage term of all components within all phases
103 for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
104 {
105 for (int compIdx = 0; compIdx < numComponents; ++compIdx)
106 {
107 int eqIdx = (compIdx == wCompIdx) ? conti0EqIdx : conti1EqIdx;
108 storage[eqIdx] += volVars.porosity()
109 * volVars.saturation(phaseIdx)
110 * massOrMoleDensity(volVars, phaseIdx)
111 * massOrMoleFraction(volVars, phaseIdx, compIdx);
112 }
113
115 EnergyLocalResidual::fluidPhaseStorage(storage, scv, volVars, phaseIdx);
116 }
117
119 EnergyLocalResidual::solidPhaseStorage(storage, scv, volVars);
120
121 return storage;
122 }
123
136 const Element& element,
137 const FVElementGeometry& fvGeometry,
138 const ElementVolumeVariables& elemVolVars,
139 const SubControlVolumeFace& scvf,
140 const ElementFluxVariablesCache& elemFluxVarsCache) const
141 {
142 FluxVariables fluxVars;
143 fluxVars.init(problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache);
144
145 // get upwind weights into local scope
146 NumEqVector flux(0.0);
147
148 const auto massOrMoleDensity = [](const auto& volVars, const int phaseIdx)
149 { return useMoles ? volVars.molarDensity(phaseIdx) : volVars.density(phaseIdx); };
150
151 const auto massOrMoleFraction= [](const auto& volVars, const int phaseIdx, const int compIdx)
152 { return useMoles ? volVars.moleFraction(phaseIdx, compIdx) : volVars.massFraction(phaseIdx, compIdx); };
153
154 // advective fluxes
155 for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
156 {
157 for (int compIdx = 0; compIdx < numComponents; ++compIdx)
158 {
159 const auto upwindTerm = [&massOrMoleDensity, &massOrMoleFraction, phaseIdx, compIdx] (const auto& volVars)
160 { return massOrMoleDensity(volVars, phaseIdx)*massOrMoleFraction(volVars, phaseIdx, compIdx)*volVars.mobility(phaseIdx); };
161
162 // get equation index
163 auto eqIdx = conti0EqIdx + compIdx;
164 flux[eqIdx] += fluxVars.advectiveFlux(phaseIdx, upwindTerm);
165 }
166
168 EnergyLocalResidual::heatConvectionFlux(flux, fluxVars, phaseIdx);
169 }
170
172 EnergyLocalResidual::heatConductionFlux(flux, fluxVars);
173
174 // diffusive fluxes
175 static constexpr auto referenceSystemFormulation = FluxVariables::MolecularDiffusionType::referenceSystemFormulation();
176 const auto diffusionFluxesWPhase = fluxVars.molecularDiffusionFlux(wPhaseIdx);
177 Scalar jNW = diffusionFluxesWPhase[nCompIdx];
178 // check for the reference system and adapt units of the diffusive flux accordingly.
179 if (referenceSystemFormulation == ReferenceSystemFormulation::massAveraged)
180 jNW /= FluidSystem::molarMass(nCompIdx);
181 const Scalar jWW = -jNW;
182
183 const auto diffusionFluxesGPhase = fluxVars.molecularDiffusionFlux(gPhaseIdx);
184 Scalar jWG = diffusionFluxesGPhase[wCompIdx];
185 // check for the reference system and adapt units of the diffusive flux accordingly.
186 if (referenceSystemFormulation == ReferenceSystemFormulation::massAveraged)
187 jWG /= FluidSystem::molarMass(wCompIdx);
188 const Scalar jNG = -jWG;
189
190 const auto diffusionFluxesNPhase = fluxVars.molecularDiffusionFlux(nPhaseIdx);
191 Scalar jWN = diffusionFluxesNPhase[wCompIdx];
192 // check for the reference system and adapt units of the diffusive flux accordingly.
193 if (referenceSystemFormulation == ReferenceSystemFormulation::massAveraged)
194 jWN /= FluidSystem::molarMass(wCompIdx);
195 const Scalar jNN = -jWN;
196
197 flux[conti0EqIdx] += jWW+jWG+jWN;
198 flux[conti1EqIdx] += jNW+jNG+jNN;
199
200 return flux;
201 }
202};
203
204} // end namespace Dumux
205
206#endif
The reference frameworks and formulations available for splitting total fluxes into a advective and d...
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
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
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
Element-wise calculation of the local residual for problems using the ThreePWaterOil fully implicit m...
Definition: porousmediumflow/3pwateroil/localresidual.hh:40
typename GetPropType< TypeTag, Properties::GridGeometry >::LocalView FVElementGeometry
Definition: porousmediumflow/3pwateroil/localresidual.hh:45
GetPropType< TypeTag, Properties::NumEqVector > NumEqVector
Definition: porousmediumflow/3pwateroil/localresidual.hh:48
NumEqVector computeFlux(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolumeFace &scvf, const ElementFluxVariablesCache &elemFluxVarsCache) const
Evaluates the total flux of all conservation quantities over a face of a sub-control volume.
Definition: porousmediumflow/3pwateroil/localresidual.hh:135
@ numComponents
Definition: porousmediumflow/3pwateroil/localresidual.hh:61
@ conti0EqIdx
Index of the mass conservation equation for the water component.
Definition: porousmediumflow/3pwateroil/localresidual.hh:63
@ nPhaseIdx
Definition: porousmediumflow/3pwateroil/localresidual.hh:67
@ gPhaseIdx
Definition: porousmediumflow/3pwateroil/localresidual.hh:68
@ conti1EqIdx
Index of the mass conservation equation for the contaminant component.
Definition: porousmediumflow/3pwateroil/localresidual.hh:64
@ wPhaseIdx
Definition: porousmediumflow/3pwateroil/localresidual.hh:66
@ nCompIdx
Definition: porousmediumflow/3pwateroil/localresidual.hh:71
@ numPhases
Definition: porousmediumflow/3pwateroil/localresidual.hh:60
@ wCompIdx
Definition: porousmediumflow/3pwateroil/localresidual.hh:70
typename GetPropType< TypeTag, Properties::GridFluxVariablesCache >::LocalView ElementFluxVariablesCache
Definition: porousmediumflow/3pwateroil/localresidual.hh:50
GetPropType< TypeTag, Properties::VolumeVariables > VolumeVariables
Definition: porousmediumflow/3pwateroil/localresidual.hh:55
NumEqVector computeStorage(const Problem &problem, const SubControlVolume &scv, const VolumeVariables &volVars) const
Evaluates the amount of all conservation quantities (e.g. phase mass) within a sub-control volume.
Definition: porousmediumflow/3pwateroil/localresidual.hh:90
typename GridView::template Codim< 0 >::Entity Element
Definition: porousmediumflow/3pwateroil/localresidual.hh:53
GetPropType< TypeTag, Properties::Problem > Problem
Definition: porousmediumflow/3pwateroil/localresidual.hh:43
typename GetPropType< TypeTag, Properties::ModelTraits >::Indices Indices
Definition: porousmediumflow/3pwateroil/localresidual.hh:51
typename GetPropType< TypeTag, Properties::GridVolumeVariables >::LocalView ElementVolumeVariables
Definition: porousmediumflow/3pwateroil/localresidual.hh:54
GetPropType< TypeTag, Properties::FluxVariables > FluxVariables
Definition: porousmediumflow/3pwateroil/localresidual.hh:49
GetPropType< TypeTag, Properties::BaseLocalResidual > ParentType
Definition: porousmediumflow/3pwateroil/localresidual.hh:42
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: porousmediumflow/3pwateroil/localresidual.hh:57
typename FVElementGeometry::SubControlVolumeFace SubControlVolumeFace
Definition: porousmediumflow/3pwateroil/localresidual.hh:47
GetPropType< TypeTag, Properties::EnergyLocalResidual > EnergyLocalResidual
Definition: porousmediumflow/3pwateroil/localresidual.hh:56
static constexpr bool useMoles
Property that defines whether mole or mass fractions are used.
Definition: porousmediumflow/3pwateroil/localresidual.hh:75
GetPropType< TypeTag, Properties::GridView > GridView
Definition: porousmediumflow/3pwateroil/localresidual.hh:52
typename FVElementGeometry::SubControlVolume SubControlVolume
Definition: porousmediumflow/3pwateroil/localresidual.hh:46
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: porousmediumflow/3pwateroil/localresidual.hh:44
Declares all properties used in Dumux.