immiscibleintensivequantities.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_INTENSIVE_QUANTITIES_HH
29 #define EWOMS_IMMISCIBLE_INTENSIVE_QUANTITIES_HH
30 
31 #include "immiscibleproperties.hh"
32 
34 
35 #include <opm/material/fluidstates/ImmiscibleFluidState.hpp>
36 #include <opm/common/Valgrind.hpp>
37 
38 #include <dune/common/fvector.hh>
39 #include <dune/common/fmatrix.hh>
40 
41 namespace Ewoms {
49 template <class TypeTag>
51  : public GET_PROP_TYPE(TypeTag, DiscIntensiveQuantities)
52  , public EnergyIntensiveQuantities<TypeTag, GET_PROP_VALUE(TypeTag, EnableEnergy)>
53  , public GET_PROP_TYPE(TypeTag, FluxModule)::FluxIntensiveQuantities
54 {
55  typedef typename GET_PROP_TYPE(TypeTag, DiscIntensiveQuantities) ParentType;
56 
57  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
58  typedef typename GET_PROP_TYPE(TypeTag, Evaluation) Evaluation;
59  typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
60  typedef typename GET_PROP_TYPE(TypeTag, MaterialLaw) MaterialLaw;
61  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
62  typedef typename GET_PROP_TYPE(TypeTag, Indices) Indices;
63  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
64  typedef typename GET_PROP_TYPE(TypeTag, FluxModule) FluxModule;
65 
66  enum { numPhases = GET_PROP_VALUE(TypeTag, NumPhases) };
67  enum { pressure0Idx = Indices::pressure0Idx };
68  enum { saturation0Idx = Indices::saturation0Idx };
69  enum { enableEnergy = GET_PROP_VALUE(TypeTag, EnableEnergy) };
70  enum { dimWorld = GridView::dimensionworld };
71 
72  typedef Opm::MathToolbox<Evaluation> Toolbox;
73  typedef Dune::FieldMatrix<Scalar, dimWorld, dimWorld> DimMatrix;
74  typedef Dune::FieldVector<Scalar, numPhases> PhaseVector;
75  typedef Dune::FieldVector<Evaluation, numPhases> EvalPhaseVector;
76 
77  typedef typename FluxModule::FluxIntensiveQuantities FluxIntensiveQuantities;
79  typedef Opm::ImmiscibleFluidState<Evaluation, FluidSystem,
80  /*storeEnthalpy=*/enableEnergy> FluidState;
81 
82 public:
84  { }
85 
87 
88  ImmiscibleIntensiveQuantities& operator=(const ImmiscibleIntensiveQuantities& other) = default;
89 
93  void update(const ElementContext& elemCtx, unsigned dofIdx, unsigned timeIdx)
94  {
95  ParentType::update(elemCtx, dofIdx, timeIdx);
96  EnergyIntensiveQuantities::updateTemperatures_(fluidState_, elemCtx, dofIdx, timeIdx);
97 
98  // material law parameters
99  typedef typename GET_PROP_TYPE(TypeTag, MaterialLaw) MaterialLaw;
100  const auto& problem = elemCtx.problem();
101  const typename MaterialLaw::Params& materialParams =
102  problem.materialLawParams(elemCtx, dofIdx, timeIdx);
103  const auto& priVars = elemCtx.primaryVars(dofIdx, timeIdx);
104  Opm::Valgrind::CheckDefined(priVars);
105 
106  Evaluation sumSat = 0.0;
107  for (unsigned phaseIdx = 0; phaseIdx < numPhases - 1; ++phaseIdx) {
108  const Evaluation& Salpha = priVars.makeEvaluation(saturation0Idx + phaseIdx, timeIdx);
109  fluidState_.setSaturation(phaseIdx, Salpha);
110  sumSat += Salpha;
111  }
112  fluidState_.setSaturation(numPhases - 1, 1 - sumSat);
113 
114  EvalPhaseVector pC;
115  MaterialLaw::capillaryPressures(pC, materialParams, fluidState_);
116  Opm::Valgrind::CheckDefined(pC);
117 
118  // calculate relative permeabilities
119  MaterialLaw::relativePermeabilities(relativePermeability_, materialParams, fluidState_);
120  Opm::Valgrind::CheckDefined(relativePermeability_);
121 
122  const Evaluation& p0 = priVars.makeEvaluation(pressure0Idx, timeIdx);
123  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
124  fluidState_.setPressure(phaseIdx, p0 + (pC[phaseIdx] - pC[0]));
125 
126  typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
127  typename FluidSystem::template ParameterCache<Evaluation> paramCache;
128  paramCache.updateAll(fluidState_);
129 
130  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
131  // compute and set the viscosity
132  const Evaluation& mu = FluidSystem::viscosity(fluidState_, paramCache, phaseIdx);
133  fluidState_.setViscosity(phaseIdx, mu);
134 
135  // compute and set the density
136  const Evaluation& rho = FluidSystem::density(fluidState_, paramCache, phaseIdx);
137  fluidState_.setDensity(phaseIdx, rho);
138 
139  mobility_[phaseIdx] = relativePermeability_[phaseIdx]/mu;
140  }
141 
142  // porosity
143  porosity_ = problem.porosity(elemCtx, dofIdx, timeIdx);
144 
145  // intrinsic permeability
146  intrinsicPerm_ = problem.intrinsicPermeability(elemCtx, dofIdx, timeIdx);
147 
148  // energy related quantities
149  EnergyIntensiveQuantities::update_(fluidState_, paramCache, elemCtx, dofIdx, timeIdx);
150 
151  // update the quantities specific for the velocity model
152  FluxIntensiveQuantities::update_(elemCtx, dofIdx, timeIdx);
153  }
154 
158  const FluidState& fluidState() const
159  { return fluidState_; }
160 
164  const DimMatrix& intrinsicPermeability() const
165  { return intrinsicPerm_; }
166 
173  const Evaluation& relativePermeability(unsigned phaseIdx) const
174  { return relativePermeability_[phaseIdx]; }
175 
182  const Evaluation& mobility(unsigned phaseIdx) const
183  { return mobility_[phaseIdx]; }
184 
188  const Evaluation& porosity() const
189  { return porosity_; }
190 
191 protected:
192  FluidState fluidState_;
193  Evaluation porosity_;
194  DimMatrix intrinsicPerm_;
195  Evaluation relativePermeability_[numPhases];
196  Evaluation mobility_[numPhases];
197 };
198 
199 } // namespace Ewoms
200 
201 #endif
const Evaluation & porosity() const
Returns the average porosity within the control volume.
Definition: immiscibleintensivequantities.hh:188
void update(const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx)
Definition: immiscibleintensivequantities.hh:93
Contains the quantities which are are constant within a finite volume for the immiscible multi-phase ...
Definition: immiscibleintensivequantities.hh:50
Definition: baseauxiliarymodule.hh:37
#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
const DimMatrix & intrinsicPermeability() const
Returns the intrinsic permeability tensor a degree of freedom.
Definition: immiscibleintensivequantities.hh:164
Provides the volumetric quantities required for the energy equation.
Definition: energymodule.hh:539
const Evaluation & mobility(unsigned phaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: immiscibleintensivequantities.hh:182
Defines the properties required for the immiscible multi-phase model.
const FluidState & fluidState() const
Returns the phase state for the control-volume.
Definition: immiscibleintensivequantities.hh:158
const Evaluation & relativePermeability(unsigned phaseIdx) const
Returns the relative permeability of a given phase within the control volume.
Definition: immiscibleintensivequantities.hh:173