opm-common
ThreeComponentFluidSystem.hh
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 2022 SINTEF Digital, Mathematics and Cybernetics.
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 
21  Consult the COPYING file in the top-level source directory of this
22  module for the precise wording of the license and the list of
23  copyright holders.
24 */
25 
26 #ifndef OPM_THREECOMPONENTFLUIDSYSTEM_HH
27 #define OPM_THREECOMPONENTFLUIDSYSTEM_HH
28 
29 #include <opm/material/eos/CubicEOS.hpp>
34 
35 #include <string_view>
36 
37 
38 // TODO: this is something else need to check
41 
42 namespace Opm {
50  template<class Scalar>
52  : public Opm::BaseFluidSystem<Scalar, ThreeComponentFluidSystem<Scalar> > {
53  public:
54  // TODO: I do not think these should be constant in fluidsystem, will try to make it non-constant later
55  static constexpr int numPhases=2;
56  static constexpr int numComponents = 3;
57  static constexpr int numMisciblePhases=2;
58  static constexpr int numMiscibleComponents = 3;
59  static constexpr bool waterEnabled = false;
60  // TODO: phase location should be more general
61  static constexpr int oilPhaseIdx = 0;
62  static constexpr int gasPhaseIdx = 1;
63  static constexpr int waterPhaseIdx = -1;
64 
65  static constexpr int Comp0Idx = 0;
66  static constexpr int Comp1Idx = 1;
67  static constexpr int Comp2Idx = 2;
68 
69  // TODO: needs to be more general
70  using Comp0 = SimpleCO2<Scalar>;
71  using Comp1 = C1<Scalar>;
72  using Comp2 = C10<Scalar>;
73 
74  template <class ValueType>
78 
79  static bool phaseIsActive(unsigned phaseIdx)
80  {
81  return phaseIdx == oilPhaseIdx || phaseIdx == gasPhaseIdx;
82  }
83 
89  static Scalar acentricFactor(unsigned compIdx)
90  {
91  switch (compIdx) {
92  case Comp0Idx: return Comp0::acentricFactor();
93  case Comp1Idx: return Comp1::acentricFactor();
94  case Comp2Idx: return Comp2::acentricFactor();
95  default: throw std::runtime_error("Illegal component index for acentricFactor");
96  }
97  }
103  static Scalar criticalTemperature(unsigned compIdx)
104  {
105  switch (compIdx) {
106  case Comp0Idx: return Comp0::criticalTemperature();
107  case Comp1Idx: return Comp1::criticalTemperature();
108  case Comp2Idx: return Comp2::criticalTemperature();
109  default: throw std::runtime_error("Illegal component index for criticalTemperature");
110  }
111  }
117  static Scalar criticalPressure(unsigned compIdx) {
118  switch (compIdx) {
119  case Comp0Idx: return Comp0::criticalPressure();
120  case Comp1Idx: return Comp1::criticalPressure();
121  case Comp2Idx: return Comp2::criticalPressure();
122  default: throw std::runtime_error("Illegal component index for criticalPressure");
123  }
124  }
130  static Scalar criticalVolume(unsigned compIdx)
131  {
132  switch (compIdx) {
133  case Comp0Idx: return Comp0::criticalVolume();
134  case Comp1Idx: return Comp1::criticalVolume();
135  case Comp2Idx: return Comp2::criticalVolume();
136  default: throw std::runtime_error("Illegal component index for criticalVolume");
137  }
138  }
139 
141  static Scalar molarMass(unsigned compIdx)
142  {
143  switch (compIdx) {
144  case Comp0Idx: return Comp0::molarMass();
145  case Comp1Idx: return Comp1::molarMass();
146  case Comp2Idx: return Comp2::molarMass();
147  default: throw std::runtime_error("Illegal component index for molarMass");
148  }
149  }
150 
155  static Scalar interactionCoefficient(unsigned /*comp1Idx*/, unsigned /*comp2Idx*/)
156  {
157  return 0.0;
158  }
159 
161  static std::string_view phaseName(unsigned phaseIdx)
162  {
163  static const std::string_view name[] = {"o", // oleic phase
164  "g"}; // gas phase
165 
166  assert(phaseIdx < 2);
167  return name[phaseIdx];
168  }
169 
171  static std::string_view componentName(unsigned compIdx)
172  {
173  static const std::string_view name[] = {
174  Comp0::name(),
175  Comp1::name(),
176  Comp2::name(),
177  };
178 
179  assert(compIdx < 3);
180  return name[compIdx];
181  }
182 
186  template <class FluidState, class LhsEval = typename FluidState::ValueType, class ParamCacheEval = LhsEval>
187  static LhsEval density(const FluidState& fluidState,
188  const ParameterCache<ParamCacheEval>& paramCache,
189  unsigned phaseIdx)
190  {
191  assert(phaseIdx == oilPhaseIdx || phaseIdx == gasPhaseIdx); // This is a oil + gas only two-phase system
192  return decay<LhsEval>(fluidState.averageMolarMass(phaseIdx) / paramCache.molarVolume(phaseIdx));
193  }
194 
196  template <class FluidState, class LhsEval = typename FluidState::ValueType, class ParamCacheEval = LhsEval>
197  static LhsEval viscosity(const FluidState& fluidState,
198  const ParameterCache<ParamCacheEval>& paramCache,
199  unsigned phaseIdx)
200  {
201  // Use LBC method to calculate viscosity
202  return decay<LhsEval>(ViscosityModel::LBC(fluidState, paramCache, phaseIdx));
203  }
204 
206  template <class FluidState, class LhsEval = typename FluidState::ValueType, class ParamCacheEval = LhsEval>
207  static LhsEval fugacityCoefficient(const FluidState& fluidState,
208  const ParameterCache<ParamCacheEval>& paramCache,
209  unsigned phaseIdx,
210  unsigned compIdx)
211  {
212  assert(phaseIdx < numPhases);
213  assert(compIdx < numComponents);
214 
215  return decay<LhsEval>(CubicEOS::computeFugacityCoefficient(fluidState, paramCache, phaseIdx, compIdx));
216  }
217 
219  static bool isCompressible([[maybe_unused]] unsigned phaseIdx)
220  {
221  assert(phaseIdx < numPhases);
222 
223  return true;
224  }
225 
227  static bool isIdealMixture([[maybe_unused]] unsigned phaseIdx)
228  {
229  assert(phaseIdx < numPhases);
230 
231  return false;
232  }
233 
235  static bool isLiquid(unsigned phaseIdx)
236  {
237  assert(phaseIdx < numPhases);
238 
239  return (phaseIdx == 0);
240  }
241 
243  static bool isIdealGas(unsigned phaseIdx)
244  {
245  assert(phaseIdx < numPhases);
246 
247  return (phaseIdx == 1);
248  }
249  };
250 }
251 #endif //OPM_THREECOMPONENTFLUIDSYSTEM_HH
static std::string_view name()
A human readable name for NDecane.
Definition: C10.hpp:57
A simplistic class representing the fluid properties.
static bool isCompressible([[maybe_unused]] unsigned phaseIdx)
Returns true if and only if a fluid phase is assumed to be compressible.
Definition: ThreeComponentFluidSystem.hh:219
Specifies the parameter cache used by the SPE-5 fluid system.
Definition: PTFlashParameterCache.hpp:49
Properties of pure molecular n-Decane .
Definition: C10.hpp:49
static Scalar molarMass()
The molar mass in of molecular n-Decane.
Definition: C10.hpp:63
static Scalar acentricFactor()
Acentric factor of .
Definition: SimpleCO2.hpp:87
Definition: LBC.hpp:39
static std::string_view phaseName(unsigned phaseIdx)
Return the human readable name of a fluid phase.
Definition: ThreeComponentFluidSystem.hh:161
Properties of pure molecular n-Decane .
static bool isIdealGas(unsigned phaseIdx)
Returns true if and only if a fluid phase is assumed to be an ideal gas.
Definition: ThreeComponentFluidSystem.hh:243
static std::string_view name()
A human readable name for the component.
Definition: SimpleCO2.hpp:57
static Scalar criticalTemperature()
Returns the critical temperature of molecular methane.
Definition: C1.hpp:70
static Scalar criticalPressure()
Returns the critical pressure of .
Definition: SimpleCO2.hpp:75
static LhsEval fugacityCoefficient(const FluidState &fluidState, const ParameterCache< ParamCacheEval > &paramCache, unsigned phaseIdx, unsigned compIdx)
Calculate the fugacity coefficient [Pa] of an individual component in a fluid phase.
Definition: ThreeComponentFluidSystem.hh:207
Properties of pure molecular methane .
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Scalar molarVolume(unsigned phaseIdx) const
Returns the molar volume of a phase [m^3/mol].
Definition: PTFlashParameterCache.hpp:283
static std::string_view componentName(unsigned compIdx)
Return the human readable name of a component.
Definition: ThreeComponentFluidSystem.hh:171
Definition: CubicEOS.hpp:33
Properties of pure molecular methane .
Definition: C1.hpp:50
static Scalar criticalTemperature()
Returns the critical temperature of .
Definition: SimpleCO2.hpp:69
static Scalar molarMass(unsigned compIdx)
Return the molar mass of a component in [kg/mol].
Definition: ThreeComponentFluidSystem.hh:141
static Scalar molarMass()
The molar mass in of the component.
Definition: SimpleCO2.hpp:63
static Scalar acentricFactor()
Acentric factor of .
Definition: C10.hpp:86
static Scalar criticalPressure()
Returns the critical pressure of molecular n-Decane.
Definition: C10.hpp:75
static Scalar criticalTemperature()
Returns the critical temperature of molecular n-Decane.
Definition: C10.hpp:69
static Scalar criticalTemperature(unsigned compIdx)
Critical temperature of a component [K].
Definition: ThreeComponentFluidSystem.hh:103
The base class for all fluid systems.
Definition: BaseFluidSystem.hpp:42
static Scalar criticalVolume()
Critical volume of [m3/kmol].
Definition: C10.hpp:81
static std::string_view name()
A human readable name for NDecane.
Definition: C1.hpp:58
static bool isIdealMixture([[maybe_unused]] unsigned phaseIdx)
Returns true if and only if a fluid phase is assumed to be an ideal mixture.
Definition: ThreeComponentFluidSystem.hh:227
static Scalar molarMass()
The molar mass in of molecular methane.
Definition: C1.hpp:64
A two phase three component fluid system with components CO2, Methane and NDekan. ...
Definition: ThreeComponentFluidSystem.hh:51
static Scalar criticalVolume(unsigned compIdx)
Critical volume of a component [m3].
Definition: ThreeComponentFluidSystem.hh:130
static LhsEval density(const FluidState &fluidState, const ParameterCache< ParamCacheEval > &paramCache, unsigned phaseIdx)
Calculate the density [kg/m^3] of a fluid phase.
Definition: ThreeComponentFluidSystem.hh:187
static Scalar criticalPressure(unsigned compIdx)
Critical pressure of a component [Pa].
Definition: ThreeComponentFluidSystem.hh:117
static Scalar acentricFactor()
Acentric factor of .
Definition: C1.hpp:87
static Scalar criticalPressure()
Returns the critical pressure of molecular methane.
Definition: C1.hpp:76
static Scalar criticalVolume()
Critical volume of [m2/kmol].
Definition: SimpleCO2.hpp:93
static LhsEval viscosity(const FluidState &fluidState, const ParameterCache< ParamCacheEval > &paramCache, unsigned phaseIdx)
Calculate the dynamic viscosity of a fluid phase [Pa*s].
Definition: ThreeComponentFluidSystem.hh:197
Scalar Scalar
The type used for scalar quantities.
Definition: BaseFluidSystem.hpp:48
static bool isLiquid(unsigned phaseIdx)
Return whether a phase is liquid.
Definition: ThreeComponentFluidSystem.hh:235
static Scalar acentricFactor(unsigned compIdx)
The acentric factor of a component [].
Definition: ThreeComponentFluidSystem.hh:89
static Scalar interactionCoefficient(unsigned, unsigned)
Returns the interaction coefficient for two components.
Definition: ThreeComponentFluidSystem.hh:155
static Scalar criticalVolume()
Critical volume of [m3/kmol].
Definition: C1.hpp:82
A simplistic class representing the fluid properties.
Definition: SimpleCO2.hpp:49
Specifies the parameter cache used by the SPE-5 fluid system.
The base class for all fluid systems.