immisciblelocalresidual.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 This file is part of the Open Porous Media project (OPM).
5
6 OPM 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 2 of the License, or
9 (at your option) any later version.
10
11 OPM 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 OPM. If not, see <http://www.gnu.org/licenses/>.
18
19 Consult the COPYING file in the top-level source directory of this
20 module for the precise wording of the license and the list of
21 copyright holders.
22*/
28#ifndef EWOMS_IMMISCIBLE_LOCAL_RESIDUAL_BASE_HH
29#define EWOMS_IMMISCIBLE_LOCAL_RESIDUAL_BASE_HH
30
32
34
35#include <opm/material/common/Valgrind.hpp>
36
37namespace Opm {
44template <class TypeTag>
45class ImmiscibleLocalResidual : public GetPropType<TypeTag, Properties::DiscLocalResidual>
46{
48
57
58 enum { conti0EqIdx = Indices::conti0EqIdx };
59 enum { numEq = getPropValue<TypeTag, Properties::NumEq>() };
60 enum { numPhases = getPropValue<TypeTag, Properties::NumPhases>() };
61 enum { enableEnergy = getPropValue<TypeTag, Properties::EnableEnergy>() };
62
64 using Toolbox = Opm::MathToolbox<Evaluation>;
65
66public:
75 template <class LhsEval>
76 void addPhaseStorage(Dune::FieldVector<LhsEval, numEq>& storage,
77 const ElementContext& elemCtx,
78 unsigned dofIdx,
79 unsigned timeIdx,
80 unsigned phaseIdx) const
81 {
82 // retrieve the intensive quantities for the SCV at the specified
83 // point in time
84 const IntensiveQuantities& intQuants = elemCtx.intensiveQuantities(dofIdx, timeIdx);
85 const auto& fs = intQuants.fluidState();
86
87 storage[conti0EqIdx + phaseIdx] =
88 Toolbox::template decay<LhsEval>(intQuants.porosity())
89 * Toolbox::template decay<LhsEval>(fs.saturation(phaseIdx))
90 * Toolbox::template decay<LhsEval>(fs.density(phaseIdx));
91
92 EnergyModule::addPhaseStorage(storage, intQuants, phaseIdx);
93 }
94
98 template <class LhsEval>
99 void computeStorage(Dune::FieldVector<LhsEval, numEq>& storage,
100 const ElementContext& elemCtx,
101 unsigned dofIdx,
102 unsigned timeIdx) const
103 {
104 storage = 0.0;
105 for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
106 asImp_().addPhaseStorage(storage, elemCtx, dofIdx, timeIdx, phaseIdx);
107
108 EnergyModule::addSolidEnergyStorage(storage, elemCtx.intensiveQuantities(dofIdx, timeIdx));
109 }
110
114 void computeFlux(RateVector& flux,
115 const ElementContext& elemCtx,
116 unsigned scvfIdx,
117 unsigned timeIdx) const
118 {
119 flux = 0.0;
120 asImp_().addAdvectiveFlux(flux, elemCtx, scvfIdx, timeIdx);
121 asImp_().addDiffusiveFlux(flux, elemCtx, scvfIdx, timeIdx);
122 }
123
129 void addAdvectiveFlux(RateVector& flux,
130 const ElementContext& elemCtx,
131 unsigned scvfIdx,
132 unsigned timeIdx) const
133 {
134 const ExtensiveQuantities& extQuants = elemCtx.extensiveQuantities(scvfIdx, timeIdx);
135
137 // advective fluxes of all components in all phases
139 unsigned focusDofIdx = elemCtx.focusDofIndex();
140 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
141 // data attached to upstream DOF of the current phase.
142 unsigned upIdx = static_cast<unsigned>(extQuants.upstreamIndex(phaseIdx));
143
144 const IntensiveQuantities& up = elemCtx.intensiveQuantities(upIdx, /*timeIdx=*/0);
145
146 // add advective flux of current component in current phase.
147 const Evaluation& rho = up.fluidState().density(phaseIdx);
148 if (focusDofIdx == upIdx)
149 flux[conti0EqIdx + phaseIdx] += extQuants.volumeFlux(phaseIdx)*rho;
150 else
151 flux[conti0EqIdx + phaseIdx] += extQuants.volumeFlux(phaseIdx)*Toolbox::value(rho);
152 }
153
154 EnergyModule::addAdvectiveFlux(flux, elemCtx, scvfIdx, timeIdx);
155 }
156
165 void addDiffusiveFlux(RateVector& flux,
166 const ElementContext& elemCtx,
167 unsigned scvfIdx,
168 unsigned timeIdx) const
169 {
170 // no diffusive mass fluxes for the immiscible model
171
172 // thermal conduction
173 EnergyModule::addDiffusiveFlux(flux, elemCtx, scvfIdx, timeIdx);
174 }
175
182 void computeSource(RateVector& source,
183 const ElementContext& elemCtx,
184 unsigned dofIdx,
185 unsigned timeIdx) const
186 {
187 Opm::Valgrind::SetUndefined(source);
188 elemCtx.problem().source(source, elemCtx, dofIdx, timeIdx);
189 Opm::Valgrind::CheckDefined(source);
190 }
191
192private:
193 const Implementation& asImp_() const
194 { return *static_cast<const Implementation *>(this); }
195};
196
197} // namespace Opm
198
199#endif
Provides the auxiliary methods required for consideration of the energy equation.
Definition: energymodule.hh:50
Calculates the local residual of the immiscible multi-phase model.
Definition: immisciblelocalresidual.hh:46
void computeStorage(Dune::FieldVector< LhsEval, numEq > &storage, const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx) const
Evaluate the amount all conservation quantities (e.g. phase mass) within a finite sub-control volume.
Definition: immisciblelocalresidual.hh:99
void addAdvectiveFlux(RateVector &flux, const ElementContext &elemCtx, unsigned scvfIdx, unsigned timeIdx) const
Add the advective mass flux at a given flux integration point.
Definition: immisciblelocalresidual.hh:129
void computeSource(RateVector &source, const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx) const
Calculate the source term of the equation.
Definition: immisciblelocalresidual.hh:182
void addDiffusiveFlux(RateVector &flux, const ElementContext &elemCtx, unsigned scvfIdx, unsigned timeIdx) const
Adds the diffusive flux at a given flux integration point.
Definition: immisciblelocalresidual.hh:165
void addPhaseStorage(Dune::FieldVector< LhsEval, numEq > &storage, const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx, unsigned phaseIdx) const
Adds the amount all conservation quantities (e.g. phase mass) within a single fluid phase.
Definition: immisciblelocalresidual.hh:76
void computeFlux(RateVector &flux, const ElementContext &elemCtx, unsigned scvfIdx, unsigned timeIdx) const
Evaluates the total mass flux of all conservation quantities over a face of a sub-control volume.
Definition: immisciblelocalresidual.hh:114
Contains the classes required to consider energy as a conservation quantity in a multi-phase module.
Defines the properties required for the immiscible multi-phase model.
Definition: blackoilboundaryratevector.hh:37
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:235