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
32
35
36#include <opm/material/constraintsolvers/ImmiscibleFlash.hpp>
37#include <opm/material/fluidstates/ImmiscibleFluidState.hpp>
38#include <opm/material/common/Valgrind.hpp>
39
40#include <dune/common/fvector.hh>
41
42namespace Opm {
43
53template <class TypeTag>
55{
56 using ParentType = FvBasePrimaryVariables<TypeTag>;
57
64
66
67 // primary variable indices
68 enum { pressure0Idx = Indices::pressure0Idx };
69 enum { saturation0Idx = Indices::saturation0Idx };
70
71 enum { numPhases = getPropValue<TypeTag, Properties::NumPhases>() };
72 enum { numComponents = getPropValue<TypeTag, Properties::NumComponents>() };
73
74 using Toolbox = typename Opm::MathToolbox<Evaluation>;
75 using ComponentVector = Dune::FieldVector<Scalar, numComponents>;
76 using ImmiscibleFlash = Opm::ImmiscibleFlash<Scalar, FluidSystem>;
78
79public:
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
207private:
208 Implementation& asImp_()
209 { return *static_cast<Implementation *>(this); }
210};
211
212} // namespace Opm
213
214#endif
Provides the auxiliary methods required for consideration of the energy equation.
Definition: energymodule.hh:48
Represents the primary variables used by the a model.
Definition: fvbaseprimaryvariables.hh:52
Represents the primary variables used by the immiscible multi-phase, model.
Definition: immiscibleprimaryvariables.hh:55
ImmisciblePrimaryVariables & operator=(const ImmisciblePrimaryVariables &value)=default
Assignment operator.
void assignNaive(const FluidState &fluidState)
Directly retrieve the primary variables from an arbitrary fluid state.
Definition: immiscibleprimaryvariables.hh:196
ImmisciblePrimaryVariables(const ImmisciblePrimaryVariables &value)=default
Copy constructor.
ImmisciblePrimaryVariables()
Default constructor.
Definition: immiscibleprimaryvariables.hh:83
ImmisciblePrimaryVariables(Scalar value)
Constructor with assignment from scalar.
Definition: immiscibleprimaryvariables.hh:91
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
Contains the classes required to consider energy as a conservation quantity in a multi-phase module.
Defines the properties required for the immiscible multi-phase model.
Definition: blackoilboundaryratevector.hh:37
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:242