immiscibleprimaryvariables.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_IMMISCIBLE_PRIMARY_VARIABLES_HH
29 #define EWOMS_IMMISCIBLE_PRIMARY_VARIABLES_HH
30 
31 #include "immiscibleproperties.hh"
32 
35 
36 #include <opm/material/constraintsolvers/ImmiscibleFlash.hpp>
37 #include <opm/material/fluidstates/ImmiscibleFluidState.hpp>
38 #include <opm/common/Valgrind.hpp>
39 
40 #include <dune/common/fvector.hh>
41 
42 namespace Ewoms {
43 
53 template <class TypeTag>
55 {
56  typedef FvBasePrimaryVariables<TypeTag> ParentType;
57 
58  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
59  typedef typename GET_PROP_TYPE(TypeTag, Evaluation) Evaluation;
60  typedef typename GET_PROP_TYPE(TypeTag, PrimaryVariables) Implementation;
61  typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
62  typedef typename GET_PROP_TYPE(TypeTag, MaterialLaw) MaterialLaw;
63  typedef typename GET_PROP_TYPE(TypeTag, MaterialLawParams) MaterialLawParams;
64 
65  typedef typename GET_PROP_TYPE(TypeTag, Indices) Indices;
66 
67  // primary variable indices
68  enum { pressure0Idx = Indices::pressure0Idx };
69  enum { saturation0Idx = Indices::saturation0Idx };
70 
71  enum { numPhases = GET_PROP_VALUE(TypeTag, NumPhases) };
72  enum { numComponents = GET_PROP_VALUE(TypeTag, NumComponents) };
73 
74  typedef typename Opm::MathToolbox<Evaluation> Toolbox;
75  typedef Dune::FieldVector<Scalar, numComponents> ComponentVector;
76  typedef Opm::ImmiscibleFlash<Scalar, FluidSystem> ImmiscibleFlash;
78 
79 public:
83  ImmisciblePrimaryVariables() : ParentType()
84  { Opm::Valgrind::SetUndefined(*this); }
85 
91  ImmisciblePrimaryVariables(Scalar value) : ParentType(value)
92  {}
93 
100 
107 
128  template <class FluidState>
129  void assignMassConservative(const FluidState& fluidState,
130  const MaterialLawParams& matParams,
131  bool isInEquilibrium = false)
132  {
133  #ifndef NDEBUG
134  // make sure the temperature is the same in all fluid phases
135  for (unsigned phaseIdx = 1; phaseIdx < numPhases; ++phaseIdx) {
136  assert(std::abs(fluidState.temperature(0) - fluidState.temperature(phaseIdx)) < 1e-30);
137  }
138 #endif // NDEBUG
139 
140  // for the equilibrium case, we don't need complicated
141  // computations.
142  if (isInEquilibrium) {
143  assignNaive(fluidState);
144  return;
145  }
146 
147  // use a flash calculation to calculate a fluid state in
148  // thermodynamic equilibrium
149  typename FluidSystem::template ParameterCache<Scalar> paramCache;
150  Opm::ImmiscibleFluidState<Scalar, FluidSystem> fsFlash;
151 
152  // use the externally given fluid state as initial value for
153  // the flash calculation
154  fsFlash.assign(fluidState);
155 
156  // calculate the phase densities
157  paramCache.updateAll(fsFlash);
158  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
159  Scalar rho = FluidSystem::density(fsFlash, paramCache, phaseIdx);
160  fsFlash.setDensity(phaseIdx, rho);
161  }
162 
163  // calculate the "global molarities"
164  ComponentVector globalMolarities(0.0);
165  for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
166  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
167  globalMolarities[compIdx] +=
168  fsFlash.saturation(phaseIdx) * fsFlash.molarity(phaseIdx, compIdx);
169  }
170  }
171 
172  // run the flash calculation
173  ImmiscibleFlash::template solve<MaterialLaw>(fsFlash, matParams, paramCache, globalMolarities);
174 
175  // use the result to assign the primary variables
176  assignNaive(fsFlash);
177  }
178 
195  template <class FluidState>
196  void assignNaive(const FluidState& fluidState)
197  {
198  // assign the phase temperatures. this is out-sourced to
199  // the energy module
200  EnergyModule::setPriVarTemperatures(asImp_(), fluidState);
201 
202  (*this)[pressure0Idx] = fluidState.pressure(/*phaseIdx=*/0);
203  for (unsigned phaseIdx = 0; phaseIdx < numPhases - 1; ++phaseIdx)
204  (*this)[saturation0Idx + phaseIdx] = fluidState.saturation(phaseIdx);
205  }
206 
207 private:
208  Implementation& asImp_()
209  { return *static_cast<Implementation *>(this); }
210 };
211 
212 } // namespace Ewoms
213 
214 #endif
void assignNaive(const FluidState &fluidState)
Directly retrieve the primary variables from an arbitrary fluid state.
Definition: immiscibleprimaryvariables.hh:196
Definition: baseauxiliarymodule.hh:37
ImmisciblePrimaryVariables(Scalar value)
Constructor with assignment from scalar.
Definition: immiscibleprimaryvariables.hh:91
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
Contains the classes required to consider energy as a conservation quantity in a multi-phase module...
ImmisciblePrimaryVariables()
Default constructor.
Definition: immiscibleprimaryvariables.hh:83
ImmisciblePrimaryVariables & operator=(const ImmisciblePrimaryVariables &value)=default
Assignment operator.
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: immiscibleprimaryvariables.hh:129
Represents the primary variables used by the a model.
Definition: fvbaseprimaryvariables.hh:48
Represents the primary variables used by the a model.
Defines the properties required for the immiscible multi-phase model.
Represents the primary variables used by the immiscible multi-phase, model.
Definition: immiscibleprimaryvariables.hh:54