opm-simulators
richardsintensivequantities.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_RICHARDS_INTENSIVE_QUANTITIES_HH
29 #define EWOMS_RICHARDS_INTENSIVE_QUANTITIES_HH
30 
31 #include <dune/common/fmatrix.hh>
32 #include <dune/common/fvector.hh>
33 
34 #include <opm/material/common/MathToolbox.hpp>
35 #include <opm/material/fluidstates/ImmiscibleFluidState.hpp>
36 
39 
40 #include <array>
41 
42 namespace Opm {
43 
50 template <class TypeTag>
52  : public GetPropType<TypeTag, Properties::DiscIntensiveQuantities>
53  , public GetPropType<TypeTag, Properties::FluxModule>::FluxIntensiveQuantities
54 {
63 
65  enum { pressureWIdx = Indices::pressureWIdx };
66  enum { numPhases = FluidSystem::numPhases };
67  enum { liquidPhaseIdx = getPropValue<TypeTag, Properties::LiquidPhaseIndex>() };
68  enum { gasPhaseIdx = getPropValue<TypeTag, Properties::GasPhaseIndex>() };
69  enum { dimWorld = GridView::dimensionworld };
70 
71  using FluxIntensiveQuantities = typename FluxModule::FluxIntensiveQuantities;
72  using DimMatrix = Dune::FieldMatrix<Scalar, dimWorld, dimWorld>;
73  using ScalarPhaseVector = Dune::FieldVector<Scalar, numPhases>;
74  using PhaseVector = Dune::FieldVector<Evaluation, numPhases>;
75  using Toolbox = MathToolbox<Evaluation>;
76 
77 public:
79  using FluidState = ImmiscibleFluidState<Evaluation, FluidSystem>;
80 
81  RichardsIntensiveQuantities() = default;
82 
84 
85  RichardsIntensiveQuantities& operator=(const RichardsIntensiveQuantities& other) = default;
86 
90  void update(const ElementContext& elemCtx, unsigned dofIdx, unsigned timeIdx)
91  {
92  ParentType::update(elemCtx, dofIdx, timeIdx);
93 
94  const auto& T = elemCtx.problem().temperature(elemCtx, dofIdx, timeIdx);
95  fluidState_.setTemperature(T);
96 
97  // material law parameters
98  const auto& problem = elemCtx.problem();
99  const typename MaterialLaw::Params& materialParams =
100  problem.materialLawParams(elemCtx, dofIdx, timeIdx);
101  const auto& priVars = elemCtx.primaryVars(dofIdx, timeIdx);
102 
104  // calculate the pressures
106 
107  // first, we have to find the minimum capillary pressure (i.e. Sw = 0)
108  fluidState_.setSaturation(liquidPhaseIdx, 1.0);
109  fluidState_.setSaturation(gasPhaseIdx, 0.0);
110  ScalarPhaseVector pC;
111  MaterialLaw::capillaryPressures(pC, materialParams, fluidState_);
112 
113  // non-wetting pressure can be larger than the
114  // reference pressure if the medium is fully
115  // saturated by the wetting phase
116  const Evaluation& pW = priVars.makeEvaluation(pressureWIdx, timeIdx);
117  const Evaluation pN =
118  Toolbox::max(elemCtx.problem().referencePressure(elemCtx, dofIdx, /*timeIdx=*/0),
119  pW + (pC[gasPhaseIdx] - pC[liquidPhaseIdx]));
120 
122  // calculate the saturations
124  fluidState_.setPressure(liquidPhaseIdx, pW);
125  fluidState_.setPressure(gasPhaseIdx, pN);
126 
127  PhaseVector sat;
128  MaterialLaw::saturations(sat, materialParams, fluidState_);
129  fluidState_.setSaturation(liquidPhaseIdx, sat[liquidPhaseIdx]);
130  fluidState_.setSaturation(gasPhaseIdx, sat[gasPhaseIdx]);
131 
132  typename FluidSystem::template ParameterCache<Evaluation> paramCache;
133  paramCache.updateAll(fluidState_);
134 
135  // compute and set the wetting phase viscosity
136  const Evaluation& mu = FluidSystem::viscosity(fluidState_, paramCache, liquidPhaseIdx);
137  fluidState_.setViscosity(liquidPhaseIdx, mu);
138  fluidState_.setViscosity(gasPhaseIdx, 1e-20);
139 
140  // compute and set the wetting phase density
141  const Evaluation& rho = FluidSystem::density(fluidState_, paramCache, liquidPhaseIdx);
142  fluidState_.setDensity(liquidPhaseIdx, rho);
143  fluidState_.setDensity(gasPhaseIdx, 1e-20);
144 
145  // relperms
146  MaterialLaw::relativePermeabilities(relativePermeability_, materialParams, fluidState_);
147 
148  // mobilities
149  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
150  mobility_[phaseIdx] = relativePermeability_[phaseIdx] / fluidState_.viscosity(phaseIdx);
151  }
152 
153  // porosity
154  porosity_ = problem.porosity(elemCtx, dofIdx, timeIdx);
155 
156  // intrinsic permeability
157  intrinsicPerm_ = problem.intrinsicPermeability(elemCtx, dofIdx, timeIdx);
158 
159  // update the quantities specific for the velocity model
160  FluxIntensiveQuantities::update_(elemCtx, dofIdx, timeIdx);
161  }
162 
166  const FluidState& fluidState() const
167  { return fluidState_; }
168 
172  const Evaluation& porosity() const
173  { return porosity_; }
174 
178  const DimMatrix& intrinsicPermeability() const
179  { return intrinsicPerm_; }
180 
184  const Evaluation& relativePermeability(unsigned phaseIdx) const
185  { return relativePermeability_[phaseIdx]; }
186 
190  const Evaluation& mobility(unsigned phaseIdx) const
191  { return mobility_[phaseIdx]; }
192 
193 private:
194  FluidState fluidState_;
195  DimMatrix intrinsicPerm_;
196  std::array<Evaluation,numPhases> relativePermeability_;
197  std::array<Evaluation,numPhases> mobility_;
198  Evaluation porosity_;
199 };
200 
201 } // namespace Opm
202 
203 #endif
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:233
const Evaluation & porosity() const
Returns the average porosity within the control volume.
Definition: richardsintensivequantities.hh:172
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
ImmiscibleFluidState< Evaluation, FluidSystem > FluidState
The type returned by the fluidState() method.
Definition: richardsintensivequantities.hh:79
Declare the properties used by the infrastructure code of the finite volume discretizations.
const DimMatrix & intrinsicPermeability() const
Returns the intrinsic permeability tensor a degree of freedom.
Definition: richardsintensivequantities.hh:178
const Evaluation & relativePermeability(unsigned phaseIdx) const
Returns the relative permeability of a given phase within the control volume.
Definition: richardsintensivequantities.hh:184
Contains the property declarations for the Richards model.
const Evaluation & mobility(unsigned phaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: richardsintensivequantities.hh:190
Intensive quantities required by the Richards model.
Definition: richardsintensivequantities.hh:51
void update(const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx)
Definition: richardsintensivequantities.hh:90
const FluidState & fluidState() const
Returns the phase state for the control-volume.
Definition: richardsintensivequantities.hh:166