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  Copyright (C) 2009-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_IMMISCIBLE_PRIMARY_VARIABLES_HH
27 #define EWOMS_IMMISCIBLE_PRIMARY_VARIABLES_HH
28 
29 #include "immiscibleproperties.hh"
30 
33 
34 #include <opm/material/constraintsolvers/ImmiscibleFlash.hpp>
35 #include <opm/material/fluidstates/ImmiscibleFluidState.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, PrimaryVariables) Implementation;
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 
62  typedef typename GET_PROP_TYPE(TypeTag, Indices) Indices;
63 
64  // primary variable indices
65  enum { pressure0Idx = Indices::pressure0Idx };
66  enum { saturation0Idx = Indices::saturation0Idx };
67 
68  enum { numPhases = GET_PROP_VALUE(TypeTag, NumPhases) };
69  enum { numComponents = GET_PROP_VALUE(TypeTag, NumComponents) };
70 
71  typedef typename Opm::MathToolbox<Evaluation> Toolbox;
72  typedef Dune::FieldVector<Scalar, numComponents> ComponentVector;
73  typedef Opm::ImmiscibleFlash<Scalar, FluidSystem> ImmiscibleFlash;
75 
76 public:
80  ImmisciblePrimaryVariables() : ParentType()
81  { Valgrind::SetUndefined(*this); }
82 
88  ImmisciblePrimaryVariables(Scalar value) : ParentType(value)
89  {}
90 
97  : ParentType(value)
98  {}
99 
120  template <class FluidState>
121  void assignMassConservative(const FluidState &fluidState,
122  const MaterialLawParams &matParams,
123  bool isInEquilibrium = false)
124  {
125  ComponentVector globalMolarities(0.0);
126  for (int compIdx = 0; compIdx < numComponents; ++compIdx) {
127  for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
128  globalMolarities[compIdx] +=
129  fluidState.molarity(phaseIdx, compIdx) * fluidState.saturation(phaseIdx);
130  }
131  }
132 
133  Opm::ImmiscibleFluidState<Scalar, FluidSystem> fsFlash;
134  fsFlash.assign(fluidState);
135  typename FluidSystem::ParameterCache paramCache;
136  ImmiscibleFlash::template solve<MaterialLaw>(fsFlash,
137  paramCache,
138  matParams,
139  globalMolarities);
140 
141  assignNaive(fsFlash);
142  }
143 
160  template <class FluidState>
161  void assignNaive(const FluidState &fluidState)
162  {
163  // assign the phase temperatures. this is out-sourced to
164  // the energy module
165  EnergyModule::setPriVarTemperatures(asImp_(), fluidState);
166 
167  (*this)[pressure0Idx] = fluidState.pressure(/*phaseIdx=*/0);
168  for (int phaseIdx = 0; phaseIdx < numPhases - 1; ++phaseIdx)
169  (*this)[saturation0Idx + phaseIdx] = fluidState.saturation(phaseIdx);
170  }
171 
172 private:
173  Implementation &asImp_()
174  { return *static_cast<Implementation *>(this); }
175 };
176 
177 } // namespace Ewoms
178 
179 #endif
ImmisciblePrimaryVariables(Scalar value)
Constructor with assignment from scalar.
Definition: immiscibleprimaryvariables.hh:88
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
Represents the primary variables used by the a model.
Definition: fvbaseprimaryvariables.hh:41
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
Definition: baseauxiliarymodule.hh:35
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:121
void assignNaive(const FluidState &fluidState)
Directly retrieve the primary variables from an arbitrary fluid state.
Definition: immiscibleprimaryvariables.hh:161
Represents the primary variables used by the immiscible multi-phase, model.
Definition: immiscibleprimaryvariables.hh:51
ImmisciblePrimaryVariables(const ImmisciblePrimaryVariables &value)
Copy constructor.
Definition: immiscibleprimaryvariables.hh:96
ImmisciblePrimaryVariables()
Default constructor.
Definition: immiscibleprimaryvariables.hh:80
Contains the classes required to consider energy as a conservation quantity in a multi-phase module...