All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ncpintensivequantities.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_NCP_INTENSIVE_QUANTITIES_HH
29 #define EWOMS_NCP_INTENSIVE_QUANTITIES_HH
30 
31 #include "ncpproperties.hh"
32 
35 
36 #include <opm/material/constraintsolvers/NcpFlash.hpp>
37 #include <opm/material/fluidstates/CompositionalFluidState.hpp>
38 #include <opm/material/constraintsolvers/CompositionFromFugacities.hpp>
39 #include <opm/common/Valgrind.hpp>
40 
41 #include <dune/common/fvector.hh>
42 #include <dune/common/fmatrix.hh>
43 
44 namespace Ewoms {
52 template <class TypeTag>
54  : public GET_PROP_TYPE(TypeTag, DiscIntensiveQuantities)
55  , public DiffusionIntensiveQuantities<TypeTag, GET_PROP_VALUE(TypeTag, EnableDiffusion) >
56  , public EnergyIntensiveQuantities<TypeTag, GET_PROP_VALUE(TypeTag, EnableEnergy) >
57  , public GET_PROP_TYPE(TypeTag, FluxModule)::FluxIntensiveQuantities
58 {
59  typedef typename GET_PROP_TYPE(TypeTag, DiscIntensiveQuantities) ParentType;
60 
61  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
62  typedef typename GET_PROP_TYPE(TypeTag, Evaluation) Evaluation;
63  typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
64  typedef typename GET_PROP_TYPE(TypeTag, MaterialLaw) MaterialLaw;
65  typedef typename GET_PROP_TYPE(TypeTag, MaterialLawParams) MaterialLawParams;
66  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
67  typedef typename GET_PROP_TYPE(TypeTag, Indices) Indices;
68 
69  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
70  typedef typename GET_PROP_TYPE(TypeTag, FluxModule) FluxModule;
71 
72  enum { numPhases = GET_PROP_VALUE(TypeTag, NumPhases) };
73  enum { numComponents = GET_PROP_VALUE(TypeTag, NumComponents) };
74  enum { enableEnergy = GET_PROP_VALUE(TypeTag, EnableEnergy) };
75  enum { enableDiffusion = GET_PROP_VALUE(TypeTag, EnableDiffusion) };
76  enum { fugacity0Idx = Indices::fugacity0Idx };
77  enum { saturation0Idx = Indices::saturation0Idx };
78  enum { pressure0Idx = Indices::pressure0Idx };
79  enum { dimWorld = GridView::dimensionworld };
80 
81  typedef Opm::CompositionFromFugacities<Scalar, FluidSystem, Evaluation>
82  CompositionFromFugacitiesSolver;
83  typedef Opm::CompositionalFluidState<Evaluation, FluidSystem,
84  /*storeEnthalpy=*/enableEnergy> FluidState;
85  typedef Dune::FieldVector<Evaluation, numComponents> ComponentVector;
86  typedef Dune::FieldMatrix<Scalar, dimWorld, dimWorld> DimMatrix;
89  typedef typename FluxModule::FluxIntensiveQuantities FluxIntensiveQuantities;
90 
91 public:
93  {}
94 
95  NcpIntensiveQuantities(const NcpIntensiveQuantities& other) = default;
96 
97  NcpIntensiveQuantities& operator=(const NcpIntensiveQuantities& other) = default;
98 
102  void update(const ElementContext& elemCtx,
103  unsigned dofIdx,
104  unsigned timeIdx)
105  {
106  ParentType::update(elemCtx, dofIdx, timeIdx);
107  ParentType::checkDefined();
108 
109  typename FluidSystem::template ParameterCache<Evaluation> paramCache;
110  const auto& priVars = elemCtx.primaryVars(dofIdx, timeIdx);
111 
112  // set the phase saturations
113  Evaluation sumSat = 0;
114  for (unsigned phaseIdx = 0; phaseIdx < numPhases - 1; ++phaseIdx) {
115  const Evaluation& val = priVars.makeEvaluation(saturation0Idx + phaseIdx, timeIdx);
116  fluidState_.setSaturation(phaseIdx, val);
117  sumSat += val;
118  }
119  fluidState_.setSaturation(numPhases - 1, 1.0 - sumSat);
120  Opm::Valgrind::CheckDefined(sumSat);
121 
122  // set the fluid phase temperature
123  EnergyIntensiveQuantities::updateTemperatures_(fluidState_, elemCtx, dofIdx, timeIdx);
124 
125  // retrieve capillary pressure parameters
126  const auto& problem = elemCtx.problem();
127  const MaterialLawParams& materialParams =
128  problem.materialLawParams(elemCtx, dofIdx, timeIdx);
129  // calculate capillary pressures
130  Evaluation capPress[numPhases];
131  MaterialLaw::capillaryPressures(capPress, materialParams, fluidState_);
132  // add to the pressure of the first fluid phase
133  const Evaluation& pressure0 = priVars.makeEvaluation(pressure0Idx, timeIdx);
134  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
135  fluidState_.setPressure(phaseIdx, pressure0 + (capPress[phaseIdx] - capPress[0]));
136 
137  ComponentVector fug;
138  // retrieve component fugacities
139  for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx)
140  fug[compIdx] = priVars.makeEvaluation(fugacity0Idx + compIdx, timeIdx);
141 
142  // calculate phase compositions
143  const auto *hint = elemCtx.thermodynamicHint(dofIdx, timeIdx);
144  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
145  // initial guess
146  if (hint) {
147  for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
148  // use the hint for the initial mole fraction!
149  const Evaluation& moleFracIJ = hint->fluidState().moleFraction(phaseIdx, compIdx);
150  fluidState_.setMoleFraction(phaseIdx, compIdx, moleFracIJ);
151  }
152  }
153  else // !hint
154  CompositionFromFugacitiesSolver::guessInitial(fluidState_, phaseIdx, fug);
155 
156  // calculate the phase composition from the component
157  // fugacities
158  CompositionFromFugacitiesSolver::solve(fluidState_, paramCache, phaseIdx, fug);
159  }
160 
161  // porosity
162  porosity_ = problem.porosity(elemCtx, dofIdx, timeIdx);
163  Opm::Valgrind::CheckDefined(porosity_);
164 
165  // relative permeabilities
166  MaterialLaw::relativePermeabilities(relativePermeability_, materialParams, fluidState_);
167 
168  // dynamic viscosities
169  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
170  // viscosities
171  const Evaluation& mu = FluidSystem::viscosity(fluidState_, paramCache, phaseIdx);
172  fluidState_.setViscosity(phaseIdx, mu);
173 
174  mobility_[phaseIdx] = relativePermeability_[phaseIdx]/mu;
175  }
176 
177  // intrinsic permeability
178  intrinsicPerm_ = problem.intrinsicPermeability(elemCtx, dofIdx, timeIdx);
179 
180  // update the quantities specific for the velocity model
181  FluxIntensiveQuantities::update_(elemCtx, dofIdx, timeIdx);
182 
183  // energy related quantities
184  EnergyIntensiveQuantities::update_(fluidState_, paramCache, elemCtx, dofIdx, timeIdx);
185 
186  // update the diffusion specific quantities of the intensive quantities
187  DiffusionIntensiveQuantities::update_(fluidState_, paramCache, elemCtx, dofIdx, timeIdx);
188 
189  checkDefined();
190  }
191 
195  const FluidState& fluidState() const
196  { return fluidState_; }
197 
201  const DimMatrix& intrinsicPermeability() const
202  { return intrinsicPerm_; }
203 
207  const Evaluation& relativePermeability(unsigned phaseIdx) const
208  { return relativePermeability_[phaseIdx]; }
209 
213  const Evaluation& mobility(unsigned phaseIdx) const
214  { return mobility_[phaseIdx]; }
215 
219  const Evaluation& porosity() const
220  { return porosity_; }
221 
225  void checkDefined() const
226  {
227 #if !defined NDEBUG && HAVE_VALGRIND
228  ParentType::checkDefined();
229 
230  Opm::Valgrind::CheckDefined(porosity_);
231  Opm::Valgrind::CheckDefined(relativePermeability_);
232 
233  fluidState_.checkDefined();
234 #endif
235  }
236 
237 private:
238  DimMatrix intrinsicPerm_;
239  FluidState fluidState_;
240  Evaluation porosity_;
241  Evaluation relativePermeability_[numPhases];
242  Evaluation mobility_[numPhases];
243 };
244 
245 } // namespace Ewoms
246 
247 #endif
void checkDefined() const
IntensiveQuantities::checkDefined.
Definition: ncpintensivequantities.hh:225
Provides the volumetric quantities required for the calculation of molecular diffusive fluxes...
Definition: diffusionmodule.hh:146
#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...
const Evaluation & porosity() const
ImmiscibleIntensiveQuantities::porosity.
Definition: ncpintensivequantities.hh:219
#define GET_PROP_TYPE(TypeTag, PropTagName)
Access the type attribute of a property for a type tag.
Definition: propertysystem.hh:486
Contains the quantities which are are constant within a finite volume in the compositional multi-phas...
Definition: ncpintensivequantities.hh:53
Provides the volumetric quantities required for the energy equation.
Definition: energymodule.hh:539
Declares the properties required for the NCP compositional multi-phase model.
const DimMatrix & intrinsicPermeability() const
ImmiscibleIntensiveQuantities::intrinsicPermeability.
Definition: ncpintensivequantities.hh:201
const Evaluation & mobility(unsigned phaseIdx) const
ImmiscibleIntensiveQuantities::mobility.
Definition: ncpintensivequantities.hh:213
const FluidState & fluidState() const
ImmiscibleIntensiveQuantities::fluidState.
Definition: ncpintensivequantities.hh:195
const Evaluation & relativePermeability(unsigned phaseIdx) const
ImmiscibleIntensiveQuantities::relativePermeability.
Definition: ncpintensivequantities.hh:207
void update(const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx)
IntensiveQuantities::update.
Definition: ncpintensivequantities.hh:102
Classes required for molecular diffusion.