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  Copyright (C) 2009-2013 by Andreas Lauser
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 2 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
26 #ifndef EWOMS_IMMISCIBLE_LOCAL_RESIDUAL_BASE_HH
27 #define EWOMS_IMMISCIBLE_LOCAL_RESIDUAL_BASE_HH
28 
29 #include "immiscibleproperties.hh"
30 
32 
33 namespace Ewoms {
40 template <class TypeTag>
41 class ImmiscibleLocalResidual : public GET_PROP_TYPE(TypeTag, DiscLocalResidual)
42 {
43  typedef typename GET_PROP_TYPE(TypeTag, LocalResidual) Implementation;
44 
45  typedef typename GET_PROP_TYPE(TypeTag, Evaluation) Evaluation;
46  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
47  typedef typename GET_PROP_TYPE(TypeTag, ExtensiveQuantities) ExtensiveQuantities;
48  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
49  typedef typename GET_PROP_TYPE(TypeTag, Indices) Indices;
50  typedef typename GET_PROP_TYPE(TypeTag, EqVector) EqVector;
51  typedef typename GET_PROP_TYPE(TypeTag, RateVector) RateVector;
52 
53  enum { conti0EqIdx = Indices::conti0EqIdx };
54  enum { numEq = GET_PROP_VALUE(TypeTag, NumEq) };
55  enum { numPhases = GET_PROP_VALUE(TypeTag, NumPhases) };
56  enum { enableEnergy = GET_PROP_VALUE(TypeTag, EnableEnergy) };
57 
59  typedef Opm::MathToolbox<Evaluation> Toolbox;
60 
61 public:
70  template <class LhsEval>
71  void addPhaseStorage(Dune::FieldVector<LhsEval, numEq> &storage,
72  const ElementContext &elemCtx,
73  int dofIdx,
74  int timeIdx,
75  int phaseIdx) const
76  {
77  // retrieve the intensive quantities for the SCV at the specified
78  // point in time
79  const IntensiveQuantities &intQuants = elemCtx.intensiveQuantities(dofIdx, timeIdx);
80  const auto &fs = intQuants.fluidState();
81 
82  storage[conti0EqIdx + phaseIdx] =
83  Toolbox::template toLhs<LhsEval>(intQuants.porosity())
84  * Toolbox::template toLhs<LhsEval>(fs.saturation(phaseIdx))
85  * Toolbox::template toLhs<LhsEval>(fs.density(phaseIdx));
86 
87  EnergyModule::addPhaseStorage(storage, intQuants, phaseIdx);
88  }
89 
93  template <class LhsEval>
94  void computeStorage(Dune::FieldVector<LhsEval, numEq> &storage,
95  const ElementContext &elemCtx,
96  int dofIdx,
97  int timeIdx) const
98  {
99  typedef Opm::MathToolbox<LhsEval> LhsToolbox;
100 
101  storage = LhsToolbox::createConstant(0.0);
102  for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
103  asImp_().addPhaseStorage(storage, elemCtx, dofIdx, timeIdx, phaseIdx);
104 
105  EnergyModule::addSolidHeatStorage(storage, elemCtx.intensiveQuantities(dofIdx, timeIdx));
106  }
107 
111  void computeFlux(RateVector &flux, const ElementContext &elemCtx,
112  int scvfIdx, int timeIdx) const
113  {
114  flux = Toolbox::createConstant(0.0);
115  asImp_().addAdvectiveFlux(flux, elemCtx, scvfIdx, timeIdx);
116  asImp_().addDiffusiveFlux(flux, elemCtx, scvfIdx, timeIdx);
117  }
118 
124  void addAdvectiveFlux(RateVector &flux,
125  const ElementContext &elemCtx,
126  int scvfIdx,
127  int timeIdx) const
128  {
129  const ExtensiveQuantities &extQuants = elemCtx.extensiveQuantities(scvfIdx, timeIdx);
130 
132  // advective fluxes of all components in all phases
134  int interiorIdx = extQuants.interiorIndex();
135  for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
136  // data attached to upstream DOF of the current phase.
137  int upIdx = extQuants.upstreamIndex(phaseIdx);
138 
139  const IntensiveQuantities &up = elemCtx.intensiveQuantities(upIdx, /*timeIdx=*/0);
140 
141  // add advective flux of current component in current phase. This is slightly
142  // hacky because it is specific to the element-centered finite volume method.
143  const Evaluation& rho = up.fluidState().density(phaseIdx);
144  if (interiorIdx == upIdx)
145  flux[conti0EqIdx + phaseIdx] += extQuants.volumeFlux(phaseIdx)*rho;
146  else
147  flux[conti0EqIdx + phaseIdx] += extQuants.volumeFlux(phaseIdx)*Toolbox::value(rho);
148  }
149 
150  EnergyModule::addAdvectiveFlux(flux, elemCtx, scvfIdx, timeIdx);
151  }
152 
162  void addDiffusiveFlux(RateVector &flux, const ElementContext &elemCtx,
163  int scvfIdx, int timeIdx) const
164  {
165  // no diffusive mass fluxes for the immiscible model
166 
167  // heat conduction
168  EnergyModule::addDiffusiveFlux(flux, elemCtx, scvfIdx, timeIdx);
169  }
170 
177  void computeSource(RateVector &source,
178  const ElementContext &elemCtx,
179  int dofIdx,
180  int timeIdx) const
181  {
182  Valgrind::SetUndefined(source);
183  elemCtx.problem().source(source, elemCtx, dofIdx, timeIdx);
184  Valgrind::CheckDefined(source);
185  }
186 
187 private:
188  const Implementation &asImp_() const
189  { return *static_cast<const Implementation *>(this); }
190 };
191 
192 } // namespace Ewoms
193 
194 #endif
#define GET_PROP_VALUE(TypeTag, PropTagName)
Access the value attribute of a property for a type tag.
Definition: propertysystem.hh:468
#define GET_PROP_TYPE(TypeTag, PropTagName)
Access the type attribute of a property for a type tag.
Definition: propertysystem.hh:485
Calculates the local residual of the immiscible multi-phase model.
Definition: immisciblelocalresidual.hh:41
Defines the properties required for the immiscible multi-phase model.
void computeFlux(RateVector &flux, const ElementContext &elemCtx, int scvfIdx, int timeIdx) const
Evaluates the total mass flux of all conservation quantities over a face of a sub-control volume...
Definition: immisciblelocalresidual.hh:111
Provides the auxiliary methods required for consideration of the energy equation. ...
Definition: energymodule.hh:54
Definition: baseauxiliarymodule.hh:35
void computeSource(RateVector &source, const ElementContext &elemCtx, int dofIdx, int timeIdx) const
Calculate the source term of the equation.
Definition: immisciblelocalresidual.hh:177
void addAdvectiveFlux(RateVector &flux, const ElementContext &elemCtx, int scvfIdx, int timeIdx) const
Add the advective mass flux at a given flux integration point.
Definition: immisciblelocalresidual.hh:124
void addPhaseStorage(Dune::FieldVector< LhsEval, numEq > &storage, const ElementContext &elemCtx, int dofIdx, int timeIdx, int phaseIdx) const
Adds the amount all conservation quantities (e.g. phase mass) within a single fluid phase...
Definition: immisciblelocalresidual.hh:71
void addDiffusiveFlux(RateVector &flux, const ElementContext &elemCtx, int scvfIdx, int timeIdx) const
Adds the diffusive flux at a given flux integration point.
Definition: immisciblelocalresidual.hh:162
void computeStorage(Dune::FieldVector< LhsEval, numEq > &storage, const ElementContext &elemCtx, int dofIdx, int timeIdx) const
Evaluate the amount all conservation quantities (e.g. phase mass) within a finite sub-control volume...
Definition: immisciblelocalresidual.hh:94
Contains the classes required to consider energy as a conservation quantity in a multi-phase module...