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  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_INTENSIVE_QUANTITIES_HH
27 #define EWOMS_IMMISCIBLE_INTENSIVE_QUANTITIES_HH
28 
29 #include "immiscibleproperties.hh"
30 
32 #include <opm/material/fluidstates/ImmiscibleFluidState.hpp>
33 
34 #include <dune/common/fvector.hh>
35 #include <dune/common/fmatrix.hh>
36 
37 namespace Ewoms {
45 template <class TypeTag>
47  : public GET_PROP_TYPE(TypeTag, DiscIntensiveQuantities)
48  , public EnergyIntensiveQuantities<TypeTag, GET_PROP_VALUE(TypeTag, EnableEnergy)>
49  , public GET_PROP_TYPE(TypeTag, FluxModule)::FluxIntensiveQuantities
50 {
51  typedef typename GET_PROP_TYPE(TypeTag, DiscIntensiveQuantities) ParentType;
52 
53  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
54  typedef typename GET_PROP_TYPE(TypeTag, Evaluation) Evaluation;
55  typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
56  typedef typename GET_PROP_TYPE(TypeTag, MaterialLaw) MaterialLaw;
57  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
58  typedef typename GET_PROP_TYPE(TypeTag, Indices) Indices;
59  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
60  typedef typename GET_PROP_TYPE(TypeTag, FluxModule) FluxModule;
61 
62  enum { numPhases = GET_PROP_VALUE(TypeTag, NumPhases) };
63  enum { pressure0Idx = Indices::pressure0Idx };
64  enum { saturation0Idx = Indices::saturation0Idx };
65  enum { enableEnergy = GET_PROP_VALUE(TypeTag, EnableEnergy) };
66  enum { dimWorld = GridView::dimensionworld };
67 
68  typedef Opm::MathToolbox<Evaluation> Toolbox;
69  typedef Dune::FieldMatrix<Scalar, dimWorld, dimWorld> DimMatrix;
70  typedef Dune::FieldVector<Scalar, numPhases> PhaseVector;
71  typedef Dune::FieldVector<Evaluation, numPhases> EvalPhaseVector;
72 
73  typedef typename FluxModule::FluxIntensiveQuantities FluxIntensiveQuantities;
75  typedef Opm::ImmiscibleFluidState<Evaluation, FluidSystem,
76  /*storeEnthalpy=*/enableEnergy> FluidState;
77 
78 public:
82  void update(const ElementContext &elemCtx, int dofIdx, int timeIdx)
83  {
84  ParentType::update(elemCtx, dofIdx, timeIdx);
85  EnergyIntensiveQuantities::updateTemperatures_(fluidState_, elemCtx, dofIdx, timeIdx);
86 
87  // material law parameters
88  typedef typename GET_PROP_TYPE(TypeTag, MaterialLaw) MaterialLaw;
89  const auto &problem = elemCtx.problem();
90  const typename MaterialLaw::Params &materialParams =
91  problem.materialLawParams(elemCtx, dofIdx, timeIdx);
92  const auto &priVars = elemCtx.primaryVars(dofIdx, timeIdx);
93  Valgrind::CheckDefined(priVars);
94 
95  Evaluation sumSat = Toolbox::createConstant(0.0);
96  for (int phaseIdx = 0; phaseIdx < numPhases - 1; ++phaseIdx) {
97  const Evaluation& Salpha = priVars.makeEvaluation(saturation0Idx + phaseIdx, timeIdx);
98  fluidState_.setSaturation(phaseIdx, Salpha);
99  sumSat += Salpha;
100  }
101  fluidState_.setSaturation(numPhases - 1, 1 - sumSat);
102 
103  EvalPhaseVector pC;
104  MaterialLaw::capillaryPressures(pC, materialParams, fluidState_);
105  Valgrind::CheckDefined(pC);
106 
107  // calculate relative permeabilities
108  MaterialLaw::relativePermeabilities(relativePermeability_, materialParams, fluidState_);
109  Valgrind::CheckDefined(relativePermeability_);
110 
111  const Evaluation& p0 = priVars.makeEvaluation(pressure0Idx, timeIdx);
112  for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
113  fluidState_.setPressure(phaseIdx, p0 + (pC[phaseIdx] - pC[0]));
114 
115  typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
116  typename FluidSystem::ParameterCache paramCache;
117  paramCache.updateAll(fluidState_);
118 
119  for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
120  // compute and set the viscosity
121  const Evaluation& mu = FluidSystem::viscosity(fluidState_, paramCache, phaseIdx);
122  fluidState_.setViscosity(phaseIdx, mu);
123 
124  // compute and set the density
125  const Evaluation& rho = FluidSystem::density(fluidState_, paramCache, phaseIdx);
126  fluidState_.setDensity(phaseIdx, rho);
127 
128  mobility_[phaseIdx] = relativePermeability_[phaseIdx]/mu;
129  }
130 
131  // porosity
132  porosity_ = problem.porosity(elemCtx, dofIdx, timeIdx);
133 
134  // intrinsic permeability
135  intrinsicPerm_ = problem.intrinsicPermeability(elemCtx, dofIdx, timeIdx);
136 
137  // energy related quantities
138  EnergyIntensiveQuantities::update_(fluidState_, paramCache, elemCtx, dofIdx, timeIdx);
139 
140  // update the quantities specific for the velocity model
141  FluxIntensiveQuantities::update_(elemCtx, dofIdx, timeIdx);
142  }
143 
147  const FluidState& fluidState() const
148  { return fluidState_; }
149 
153  const DimMatrix &intrinsicPermeability() const
154  { return intrinsicPerm_; }
155 
162  const Evaluation& relativePermeability(int phaseIdx) const
163  { return relativePermeability_[phaseIdx]; }
164 
171  const Evaluation& mobility(int phaseIdx) const
172  { return mobility_[phaseIdx]; }
173 
177  const Evaluation& porosity() const
178  { return porosity_; }
179 
180 protected:
181  FluidState fluidState_;
182  Evaluation porosity_;
183  DimMatrix intrinsicPerm_;
184  Evaluation relativePermeability_[numPhases];
185  Evaluation mobility_[numPhases];
186 };
187 
188 } // namespace Ewoms
189 
190 #endif
Provides the volumetric quantities required for the energy equation.
Definition: energymodule.hh:530
void update(const ElementContext &elemCtx, int dofIdx, int timeIdx)
Definition: immiscibleintensivequantities.hh:82
#define GET_PROP_VALUE(TypeTag, PropTagName)
Access the value attribute of a property for a type tag.
Definition: propertysystem.hh:468
Evaluation relativePermeability_[numPhases]
Definition: immiscibleintensivequantities.hh:184
#define GET_PROP_TYPE(TypeTag, PropTagName)
Access the type attribute of a property for a type tag.
Definition: propertysystem.hh:485
const FluidState & fluidState() const
Returns the phase state for the control-volume.
Definition: immiscibleintensivequantities.hh:147
Evaluation mobility_[numPhases]
Definition: immiscibleintensivequantities.hh:185
DimMatrix intrinsicPerm_
Definition: immiscibleintensivequantities.hh:183
Defines the properties required for the immiscible multi-phase model.
const Evaluation & mobility(int phaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: immiscibleintensivequantities.hh:171
Definition: baseauxiliarymodule.hh:35
Evaluation porosity_
Definition: immiscibleintensivequantities.hh:182
FluidState fluidState_
Definition: immiscibleintensivequantities.hh:181
const DimMatrix & intrinsicPermeability() const
Returns the intrinsic permeability tensor a degree of freedom.
Definition: immiscibleintensivequantities.hh:153
const Evaluation & relativePermeability(int phaseIdx) const
Returns the relative permeability of a given phase within the control volume.
Definition: immiscibleintensivequantities.hh:162
const Evaluation & porosity() const
Returns the average porosity within the control volume.
Definition: immiscibleintensivequantities.hh:177
Contains the quantities which are are constant within a finite volume for the immiscible multi-phase ...
Definition: immiscibleintensivequantities.hh:46
Contains the classes required to consider energy as a conservation quantity in a multi-phase module...