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