All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
31 #include "immiscibleproperties.hh"
32 
34 
35 #include <opm/common/Valgrind.hpp>
36 
37 namespace Ewoms {
44 template <class TypeTag>
45 class ImmiscibleLocalResidual : public GET_PROP_TYPE(TypeTag, DiscLocalResidual)
46 {
47  typedef typename GET_PROP_TYPE(TypeTag, LocalResidual) Implementation;
48 
49  typedef typename GET_PROP_TYPE(TypeTag, Evaluation) Evaluation;
50  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
51  typedef typename GET_PROP_TYPE(TypeTag, ExtensiveQuantities) ExtensiveQuantities;
52  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
53  typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
54  typedef typename GET_PROP_TYPE(TypeTag, Indices) Indices;
55  typedef typename GET_PROP_TYPE(TypeTag, EqVector) EqVector;
56  typedef typename GET_PROP_TYPE(TypeTag, RateVector) RateVector;
57 
58  enum { conti0EqIdx = Indices::conti0EqIdx };
59  enum { numEq = GET_PROP_VALUE(TypeTag, NumEq) };
60  enum { numPhases = GET_PROP_VALUE(TypeTag, NumPhases) };
61  enum { enableEnergy = GET_PROP_VALUE(TypeTag, EnableEnergy) };
62 
64  typedef Opm::MathToolbox<Evaluation> Toolbox;
65 
66 public:
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::addSolidHeatStorage(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 
166  void addDiffusiveFlux(RateVector& flux,
167  const ElementContext& elemCtx,
168  unsigned scvfIdx,
169  unsigned timeIdx) const
170  {
171  // no diffusive mass fluxes for the immiscible model
172 
173  // heat conduction
174  EnergyModule::addDiffusiveFlux(flux, elemCtx, scvfIdx, timeIdx);
175  }
176 
183  void computeSource(RateVector& source,
184  const ElementContext& elemCtx,
185  unsigned dofIdx,
186  unsigned timeIdx) const
187  {
188  Opm::Valgrind::SetUndefined(source);
189  elemCtx.problem().source(source, elemCtx, dofIdx, timeIdx);
190  Opm::Valgrind::CheckDefined(source);
191  }
192 
193 private:
194  const Implementation& asImp_() const
195  { return *static_cast<const Implementation *>(this); }
196 };
197 
198 } // namespace Ewoms
199 
200 #endif
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:166
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
Provides the auxiliary methods required for consideration of the energy equation. ...
Definition: energymodule.hh:59
#define GET_PROP_VALUE(TypeTag, PropTagName)
Access the value attribute of a property for a type tag.
Definition: propertysystem.hh:469
Contains the classes required to consider energy as a conservation quantity in a multi-phase module...
#define GET_PROP_TYPE(TypeTag, PropTagName)
Access the type attribute of a property for a type tag.
Definition: propertysystem.hh:486
void computeStorage(Dune::FieldVector< LhsEval, numEq > &storage, const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx) const
Evaluate the amount all conservation quantities (e.g.
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:183
Defines the properties required for the immiscible multi-phase model.
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.
Definition: immisciblelocalresidual.hh:76
Calculates the local residual of the immiscible multi-phase model.
Definition: immisciblelocalresidual.hh:45