ncpprimaryvariables.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_NCP_PRIMARY_VARIABLES_HH
27 #define EWOMS_NCP_PRIMARY_VARIABLES_HH
28 
29 #include "ncpproperties.hh"
30 
33 
34 #include <opm/material/constraintsolvers/NcpFlash.hpp>
35 #include <opm/material/fluidstates/CompositionalFluidState.hpp>
36 
37 #include <dune/common/fvector.hh>
38 
39 namespace Ewoms {
40 
50 template <class TypeTag>
52 {
53  typedef FvBasePrimaryVariables<TypeTag> ParentType;
54 
55  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
56  typedef typename GET_PROP_TYPE(TypeTag, Evaluation) Evaluation;
57  typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
58  typedef typename GET_PROP_TYPE(TypeTag, MaterialLaw) MaterialLaw;
59  typedef typename GET_PROP_TYPE(TypeTag, MaterialLawParams) MaterialLawParams;
60 
61  typedef typename GET_PROP_TYPE(TypeTag, Indices) Indices;
62  enum { pressure0Idx = Indices::pressure0Idx };
63  enum { saturation0Idx = Indices::saturation0Idx };
64  enum { fugacity0Idx = Indices::fugacity0Idx };
65 
66  enum { numPhases = GET_PROP_VALUE(TypeTag, NumPhases) };
67  enum { numComponents = GET_PROP_VALUE(TypeTag, NumComponents) };
68  typedef Dune::FieldVector<Scalar, numComponents> ComponentVector;
69 
70  enum { enableEnergy = GET_PROP_VALUE(TypeTag, EnableEnergy) };
72 
73  typedef Opm::NcpFlash<Scalar, FluidSystem> NcpFlash;
74  typedef Opm::MathToolbox<Evaluation> Toolbox;
75 
76 public:
77  NcpPrimaryVariables() : ParentType()
78  {}
79 
83  NcpPrimaryVariables(Scalar value) : ParentType(value)
84  {}
85 
90  NcpPrimaryVariables(const NcpPrimaryVariables &value) : ParentType(value)
91  {}
92 
96  template <class FluidState>
97  void assignMassConservative(const FluidState &fluidState,
98  const MaterialLawParams &matParams,
99  bool isInEquilibrium = false)
100  {
101 #ifndef NDEBUG
102  // make sure the temperature is the same in all fluid phases
103  for (int phaseIdx = 1; phaseIdx < numPhases; ++phaseIdx) {
104  assert(fluidState.temperature(0) == fluidState.temperature(phaseIdx));
105  }
106 #endif // NDEBUG
107 
108  // for the equilibrium case, we don't need complicated
109  // computations.
110  if (isInEquilibrium) {
111  assignNaive(fluidState);
112  return;
113  }
114 
115  // use a flash calculation to calculate a fluid state in
116  // thermodynamic equilibrium
117  typename FluidSystem::ParameterCache paramCache;
118  Opm::CompositionalFluidState<Scalar, FluidSystem> fsFlash;
119 
120  // calculate the "global molarities"
121  ComponentVector globalMolarities(0.0);
122  for (int compIdx = 0; compIdx < numComponents; ++compIdx) {
123  for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
124  globalMolarities[compIdx] +=
125  fluidState.saturation(phaseIdx) * fluidState.molarity(phaseIdx, compIdx);
126  }
127  }
128 
129  // use the externally given fluid state as initial value for
130  // the flash calculation
131  fsFlash.assign(fluidState);
132  // NcpFlash::guessInitial(fsFlash, paramCache, globalMolarities);
133 
134  // run the flash calculation
135  NcpFlash::template solve<MaterialLaw>(fsFlash, paramCache, matParams, globalMolarities);
136 
137  // use the result to assign the primary variables
138  assignNaive(fsFlash);
139  }
140 
144  template <class FluidState>
145  void assignNaive(const FluidState &fluidState)
146  {
147  // assign the phase temperatures. this is out-sourced to
148  // the energy module
149  EnergyModule::setPriVarTemperatures(*this, fluidState);
150 
151  // assign fugacities
152  for (int compIdx = 0; compIdx < numComponents; ++compIdx) {
153  (*this)[fugacity0Idx + compIdx] = fluidState.fugacity(/*phaseIdx=*/0, compIdx);
154  }
155 
156  // assign pressure of first phase
157  (*this)[pressure0Idx] = fluidState.pressure(/*phaseIdx=*/0);
158 
159  // assign first M - 1 saturations
160  for (int phaseIdx = 0; phaseIdx < numPhases - 1; ++phaseIdx)
161  (*this)[saturation0Idx + phaseIdx] = fluidState.saturation(phaseIdx);
162  }
163 };
164 
165 } // namespace Ewoms
166 
167 #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
void assignNaive(const FluidState &fluidState)
Directly retrieve the primary variables from an arbitrary fluid state.
Definition: ncpprimaryvariables.hh:145
Represents the primary variables used by the a model.
Definition: fvbaseprimaryvariables.hh:41
Provides the auxiliary methods required for consideration of the energy equation. ...
Definition: energymodule.hh:54
Definition: baseauxiliarymodule.hh:35
NcpPrimaryVariables(Scalar value)
Constructor with assignment from scalar.
Definition: ncpprimaryvariables.hh:83
NcpPrimaryVariables()
Definition: ncpprimaryvariables.hh:77
NcpPrimaryVariables(const NcpPrimaryVariables &value)
Default constructor.
Definition: ncpprimaryvariables.hh:90
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: ncpprimaryvariables.hh:97
Declares the properties required for the NCP compositional multi-phase model.
Represents the primary variables used by the compositional multi-phase NCP model. ...
Definition: ncpprimaryvariables.hh:51
Contains the classes required to consider energy as a conservation quantity in a multi-phase module...