My Project
Loading...
Searching...
No Matches
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 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_NCP_PRIMARY_VARIABLES_HH
29#define EWOMS_NCP_PRIMARY_VARIABLES_HH
30
31#include <dune/common/fvector.hh>
32
36
37#include <opm/material/constraintsolvers/NcpFlash.hpp>
38#include <opm/material/densead/Math.hpp>
39#include <opm/material/fluidstates/CompositionalFluidState.hpp>
40
41namespace Opm {
42
52template <class TypeTag>
54{
56
62
64 enum { pressure0Idx = Indices::pressure0Idx };
65 enum { saturation0Idx = Indices::saturation0Idx };
66 enum { fugacity0Idx = Indices::fugacity0Idx };
67
69 enum { numComponents = getPropValue<TypeTag, Properties::NumComponents>() };
70 using ComponentVector = Dune::FieldVector<Scalar, numComponents>;
71
74
76 using Toolbox = Opm::MathToolbox<Evaluation>;
77
78public:
80 {}
81
87 NcpPrimaryVariables& operator=(const NcpPrimaryVariables& value) = default;
88
89 using ParentType::operator=;
90
94 template <class FluidState>
95 void assignMassConservative(const FluidState& fluidState,
96 const MaterialLawParams& matParams,
97 bool isInEquilibrium = false)
98 {
100
101#ifndef NDEBUG
102 // make sure the temperature is the same in all fluid phases
103 for (unsigned 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::template ParameterCache<Scalar> paramCache;
119
120 // use the externally given fluid state as initial value for
121 // the flash calculation
122 fsFlash.assign(fluidState);
123
124 // calculate the phase densities
125 paramCache.updateAll(fsFlash);
126 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
127 Scalar rho = FluidSystem::density(fsFlash, paramCache, phaseIdx);
128 fsFlash.setDensity(phaseIdx, rho);
129 }
130
131 // calculate the "global molarities"
132 ComponentVector globalMolarities(0.0);
133 for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
134 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
136 FsToolbox::value(fsFlash.saturation(phaseIdx))
137 * FsToolbox::value(fsFlash.molarity(phaseIdx, compIdx));
138 }
139 }
140
141 // run the flash calculation
143
144 // use the result to assign the primary variables
146 }
147
151 template <class FluidState>
152 void assignNaive(const FluidState& fluidState, unsigned refPhaseIdx = 0)
153 {
155
156 // assign the phase temperatures. this is out-sourced to
157 // the energy module
158 EnergyModule::setPriVarTemperatures(*this, fluidState);
159
160 // assign fugacities.
161 typename FluidSystem::template ParameterCache<Scalar> paramCache;
162 paramCache.updatePhase(fluidState, refPhaseIdx);
163 Scalar pRef = FsToolbox::value(fluidState.pressure(refPhaseIdx));
164 for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
165 // we always compute the fugacities because they are quite exotic quantities
166 // and this easily forgotten to be specified
167 Scalar fugCoeff =
168 FluidSystem::template fugacityCoefficient<FluidState, Scalar>(fluidState,
171 compIdx);
172 (*this)[fugacity0Idx + compIdx] =
173 fugCoeff*fluidState.moleFraction(refPhaseIdx, compIdx)*pRef;
174 }
175
176 // assign pressure of first phase
177 (*this)[pressure0Idx] = FsToolbox::value(fluidState.pressure(/*phaseIdx=*/0));
178
179 // assign first M - 1 saturations
180 for (unsigned phaseIdx = 0; phaseIdx < numPhases - 1; ++phaseIdx)
181 (*this)[saturation0Idx + phaseIdx] = FsToolbox::value(fluidState.saturation(phaseIdx));
182 }
183};
184
185} // namespace Opm
186
187#endif
Provides the auxiliary methods required for consideration of the energy equation.
Definition energymodule.hh:50
Represents the primary variables used by the a model.
Definition fvbaseprimaryvariables.hh:52
Represents the primary variables used by the compositional multi-phase NCP model.
Definition ncpprimaryvariables.hh:54
void assignNaive(const FluidState &fluidState, unsigned refPhaseIdx=0)
Directly retrieve the primary variables from an arbitrary fluid state.
Definition ncpprimaryvariables.hh:152
void assignMassConservative(const FluidState &fluidState, const MaterialLawParams &matParams, bool isInEquilibrium=false)
< Import base class assignment operators.
Definition ncpprimaryvariables.hh:95
NcpPrimaryVariables(const NcpPrimaryVariables &value)=default
Contains the classes required to consider energy as a conservation quantity in a multi-phase module.
Represents the primary variables used by the a model.
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilboundaryratevector.hh:37
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242
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:235
Declares the properties required for the NCP compositional multi-phase model.