opm-simulators
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 <dune/common/fvector.hh>
32 
36 
37 #include <opm/material/common/Valgrind.hpp>
38 #include <opm/material/constraintsolvers/ImmiscibleFlash.hpp>
39 #include <opm/material/fluidstates/ImmiscibleFluidState.hpp>
40 
41 namespace Opm {
42 
52 template <class TypeTag>
54 {
56 
63 
65 
66  // primary variable indices
67  enum { pressure0Idx = Indices::pressure0Idx };
68  enum { saturation0Idx = Indices::saturation0Idx };
69 
70  enum { numPhases = getPropValue<TypeTag, Properties::NumPhases>() };
71  enum { numComponents = getPropValue<TypeTag, Properties::NumComponents>() };
72 
73  using Toolbox = typename Opm::MathToolbox<Evaluation>;
74  using ComponentVector = Dune::FieldVector<Scalar, numComponents>;
75  using ImmiscibleFlash = Opm::ImmiscibleFlash<Scalar, FluidSystem>;
77 
78 public:
83  { Opm::Valgrind::SetUndefined(*this); }
84 
91 
98 
99  using ParentType::operator=;
100 
121  template <class FluidState>
122  void assignMassConservative(const FluidState& fluidState,
123  const MaterialLawParams& matParams,
124  bool isInEquilibrium = false)
125  {
126  #ifndef NDEBUG
127  // make sure the temperature is the same in all fluid phases
128  for (unsigned phaseIdx = 1; phaseIdx < numPhases; ++phaseIdx) {
129  assert(std::abs(fluidState.temperature(0) - fluidState.temperature(phaseIdx)) < 1e-30);
130  }
131 #endif // NDEBUG
132 
133  // for the equilibrium case, we don't need complicated
134  // computations.
135  if (isInEquilibrium) {
136  assignNaive(fluidState);
137  return;
138  }
139 
140  // use a flash calculation to calculate a fluid state in
141  // thermodynamic equilibrium
142  typename FluidSystem::template ParameterCache<Scalar> paramCache;
143  Opm::ImmiscibleFluidState<Scalar, FluidSystem> fsFlash;
144 
145  // use the externally given fluid state as initial value for
146  // the flash calculation
147  fsFlash.assign(fluidState);
148 
149  // calculate the phase densities
150  paramCache.updateAll(fsFlash);
151  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
152  Scalar rho = FluidSystem::density(fsFlash, paramCache, phaseIdx);
153  fsFlash.setDensity(phaseIdx, rho);
154  }
155 
156  // calculate the "global molarities"
157  ComponentVector globalMolarities(0.0);
158  for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
159  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
160  globalMolarities[compIdx] +=
161  fsFlash.saturation(phaseIdx) * fsFlash.molarity(phaseIdx, compIdx);
162  }
163  }
164 
165  // run the flash calculation
166  ImmiscibleFlash::template solve<MaterialLaw>(fsFlash, matParams, paramCache, globalMolarities);
167 
168  // use the result to assign the primary variables
169  assignNaive(fsFlash);
170  }
171 
188  template <class FluidState>
189  void assignNaive(const FluidState& fluidState)
190  {
191  // assign the phase temperatures. this is out-sourced to
192  // the energy module
193  EnergyModule::setPriVarTemperatures(asImp_(), fluidState);
194 
195  (*this)[pressure0Idx] = fluidState.pressure(/*phaseIdx=*/0);
196  for (unsigned phaseIdx = 0; phaseIdx < numPhases - 1; ++phaseIdx)
197  (*this)[saturation0Idx + phaseIdx] = fluidState.saturation(phaseIdx);
198  }
199 
200 private:
201  Implementation& asImp_()
202  { return *static_cast<Implementation *>(this); }
203 };
204 
205 } // namespace Opm
206 
207 #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
void assignNaive(const FluidState &fluidState)
Directly retrieve the primary variables from an arbitrary fluid state.
Definition: immiscibleprimaryvariables.hh:189
Contains the classes required to consider energy as a conservation quantity in a multi-phase module...
void assignMassConservative(const FluidState &fluidState, const MaterialLawParams &matParams, bool isInEquilibrium=false)
< Import base class assignment operators.
Definition: immiscibleprimaryvariables.hh:122
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
Represents the primary variables used by the a model.
Definition: fvbaseprimaryvariables.hh:51
ImmisciblePrimaryVariables & operator=(const ImmisciblePrimaryVariables &value)=default
Assignment operator.
ImmisciblePrimaryVariables()
Default constructor.
Definition: immiscibleprimaryvariables.hh:82
Represents the primary variables used by the immiscible multi-phase, model.
Definition: immiscibleprimaryvariables.hh:53
Represents the primary variables used by the a model.
Defines the properties required for the immiscible multi-phase model.
Provides the auxiliary methods required for consideration of the energy equation. ...
Definition: energymodule.hh:54