richardsprimaryvariables.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_PRIMARY_VARIABLES_HH
29 #define EWOMS_RICHARDS_PRIMARY_VARIABLES_HH
30 
31 #include "richardsproperties.hh"
32 
34 
35 #include <opm/material/constraintsolvers/ImmiscibleFlash.hpp>
36 #include <opm/material/fluidstates/ImmiscibleFluidState.hpp>
37 #include <opm/common/Valgrind.hpp>
38 #include <opm/common/Unused.hpp>
39 
40 #include <dune/common/fvector.hh>
41 
42 namespace Ewoms {
43 
52 template <class TypeTag>
54 {
55  typedef FvBasePrimaryVariables<TypeTag> ParentType;
56  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
57  typedef typename GET_PROP_TYPE(TypeTag, Evaluation) Evaluation;
58  typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
59  typedef typename GET_PROP_TYPE(TypeTag, MaterialLaw) MaterialLaw;
60  typedef typename GET_PROP_TYPE(TypeTag, MaterialLawParams) MaterialLawParams;
61  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) EnergyModule;
62  typedef typename GET_PROP_TYPE(TypeTag, Indices) Indices;
63 
64  // primary variable indices
65  enum { pressureWIdx = Indices::pressureWIdx };
66 
67  enum { liquidPhaseIdx = GET_PROP_VALUE(TypeTag, LiquidPhaseIndex) };
68  enum { gasPhaseIdx = GET_PROP_VALUE(TypeTag, GasPhaseIndex) };
69 
70  enum { numPhases = GET_PROP_VALUE(TypeTag, NumPhases) };
71  enum { numComponents = GET_PROP_VALUE(TypeTag, NumComponents) };
72 
73  typedef Dune::FieldVector<Scalar, numComponents> ComponentVector;
74  typedef Dune::FieldVector<Scalar, numPhases> PhaseVector;
75  typedef typename Opm::MathToolbox<Evaluation> Toolbox;
76  typedef Opm::ImmiscibleFlash<Scalar, FluidSystem> ImmiscibleFlash;
77 
78 public:
79  RichardsPrimaryVariables() : ParentType()
80  { Opm::Valgrind::SetUndefined(*this); }
81 
85  RichardsPrimaryVariables(Scalar value) : ParentType(value)
86  {}
87 
92  RichardsPrimaryVariables(const RichardsPrimaryVariables& value) = default;
93  RichardsPrimaryVariables& operator=(const RichardsPrimaryVariables& value) = default;
94 
104  void assignImmiscibleFromWetting(Scalar T, Scalar pw, Scalar Sw,
105  const MaterialLawParams& matParams)
106  {
107  Opm::ImmiscibleFluidState<Scalar, FluidSystem> fs;
108 
109  fs.setTemperature(T);
110  fs.setSaturation(liquidPhaseIdx, Sw);
111  fs.setSaturation(gasPhaseIdx, 1 - Sw);
112 
113  // set phase pressures
114  PhaseVector pC;
115  MaterialLaw::capillaryPressures(pC, matParams, fs);
116 
117  fs.setPressure(liquidPhaseIdx, pw);
118  fs.setPressure(gasPhaseIdx, pw + (pC[gasPhaseIdx] - pC[liquidPhaseIdx]));
119 
120  assignNaive(fs);
121  }
122 
132  void assignImmiscibleFromNonWetting(Scalar T, Scalar pn, Scalar Sn,
133  const MaterialLawParams& matParams)
134  {
135  Opm::ImmiscibleFluidState<Scalar, FluidSystem> fs;
136 
137  fs.setTemperature(T);
138  fs.setSaturation(liquidPhaseIdx, 1 - Sn);
139  fs.setSaturation(gasPhaseIdx, Sn);
140 
141  // set phase pressures
142  PhaseVector pC;
143  MaterialLaw::capillaryPressures(pC, matParams, fs);
144 
145  fs.setPressure(gasPhaseIdx, pn);
146  fs.setPressure(gasPhaseIdx, pn + (pC[liquidPhaseIdx] - pC[gasPhaseIdx]));
147 
148  assignNaive(fs);
149  }
150 
154  template <class FluidState>
155  void assignMassConservative(const FluidState& fluidState,
156  const MaterialLawParams& matParams,
157  bool isInEquilibrium OPM_UNUSED= false)
158  {
159  ComponentVector globalMolarities(0.0);
160  for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
161  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
162  globalMolarities[compIdx] +=
163  fluidState.molarity(phaseIdx, compIdx) * fluidState.saturation(phaseIdx);
164  }
165  }
166 
167  Opm::ImmiscibleFluidState<Scalar, FluidSystem> fsFlash;
168  fsFlash.assign(fluidState);
169  typename FluidSystem::ParameterCache paramCache;
170  ImmiscibleFlash::template solve<MaterialLaw>(fsFlash, paramCache,
171  matParams,
172  globalMolarities);
173 
174  assignNaive(fsFlash);
175  }
176 
180  template <class FluidState>
181  void assignNaive(const FluidState& fluidState)
182  {
183  // assign the phase temperatures. this is out-sourced to
184  // the energy module
185  EnergyModule::setPriVarTemperatures(*this, fluidState);
186 
187  (*this)[pressureWIdx] = fluidState.pressure(liquidPhaseIdx);
188  }
189 };
190 
191 } // namespace Ewoms
192 
193 #endif
Definition: baseauxiliarymodule.hh:37
Provides the auxiliary methods required for consideration of the energy equation. ...
Definition: energymodule.hh:59
#define GET_PROP_VALUE(TypeTag, PropTagName)
Access the value attribute of a property for a type tag.
Definition: propertysystem.hh:469
Represents the primary variables used in the Richards model.
Definition: richardsprimaryvariables.hh:53
Contains the property declarations for the Richards model.
Represents the primary variables used by the a model.
Definition: fvbaseprimaryvariables.hh:48
RichardsPrimaryVariables(Scalar value)
Constructor with assignment from scalar.
Definition: richardsprimaryvariables.hh:85
void assignMassConservative(const FluidState &fluidState, const MaterialLawParams &matParams, bool isInEquilibrium OPM_UNUSED=false)
Set the primary variables from an arbitrary fluid state in a mass conservative way.
Definition: richardsprimaryvariables.hh:155
Represents the primary variables used by the a model.
void assignNaive(const FluidState &fluidState)
Directly retrieve the primary variables from an arbitrary fluid state.
Definition: richardsprimaryvariables.hh:181
void assignImmiscibleFromNonWetting(Scalar T, Scalar pn, Scalar Sn, const MaterialLawParams &matParams)
Set the primary variables with the non-wetting phase pressure, saturation and temperature.
Definition: richardsprimaryvariables.hh:132
void assignImmiscibleFromWetting(Scalar T, Scalar pw, Scalar Sw, const MaterialLawParams &matParams)
Set the primary variables with the wetting phase pressure, saturation and temperature.
Definition: richardsprimaryvariables.hh:104