opm-common
BlackOilFluidState.hpp
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 OPM_BLACK_OIL_FLUID_STATE_HH
29 #define OPM_BLACK_OIL_FLUID_STATE_HH
30 
31 #include <type_traits>
32 
33 #include <opm/common/utility/gpuDecorators.hpp>
34 #include <opm/material/fluidsystems/BlackOilFluidSystem.hpp>
36 
39 
40 namespace Opm {
41 
42 OPM_GENERATE_HAS_MEMBER(pvtRegionIndex, ) // Creates 'HasMember_pvtRegionIndex<T>'.
43 
44 template <class FluidState>
45 OPM_HOST_DEVICE unsigned getPvtRegionIndex_(typename std::enable_if<HasMember_pvtRegionIndex<FluidState>::value,
46  const FluidState&>::type fluidState)
47 { return fluidState.pvtRegionIndex(); }
48 
49 template <class FluidState>
50 OPM_HOST_DEVICE unsigned getPvtRegionIndex_(typename std::enable_if<!HasMember_pvtRegionIndex<FluidState>::value,
51  const FluidState&>::type)
52 { return 0; }
53 
54 OPM_GENERATE_HAS_MEMBER(invB, /*phaseIdx=*/0) // Creates 'HasMember_invB<T>'.
55 
56 template <class FluidSystem, class FluidState, class LhsEval>
57 OPM_HOST_DEVICE
58 auto getInvB_(typename std::enable_if<HasMember_invB<FluidState>::value,
59  const FluidState&>::type fluidState,
60  unsigned phaseIdx,
61  unsigned,
62  [[maybe_unused]] const FluidSystem& fluidSystem = FluidSystem{})
63  -> decltype(decay<LhsEval>(fluidState.invB(phaseIdx)))
64 { return decay<LhsEval>(fluidState.invB(phaseIdx)); }
65 
66 template <class FluidSystem, class FluidState, class LhsEval>
67 OPM_HOST_DEVICE
68 LhsEval getInvB_(typename std::enable_if<!HasMember_invB<FluidState>::value,
69  const FluidState&>::type fluidState,
70  unsigned phaseIdx,
71  unsigned pvtRegionIdx,
72  const FluidSystem& fluidSystem = FluidSystem{})
73 {
74  const auto& rho = fluidState.density(phaseIdx);
75  const auto& Xsolvent =
76  fluidState.massFraction(phaseIdx, fluidSystem.solventComponentIndex(phaseIdx));
77 
78  return
79  decay<LhsEval>(rho)
80  *decay<LhsEval>(Xsolvent)
81  /fluidSystem.referenceDensity(phaseIdx, pvtRegionIdx);
82 }
83 
84 OPM_GENERATE_HAS_MEMBER(saltConcentration, ) // Creates 'HasMember_saltConcentration<T>'.
85 
86 template <class FluidState>
87 OPM_HOST_DEVICE auto getSaltConcentration_(typename std::enable_if<HasMember_saltConcentration<FluidState>::value,
88  const FluidState&>::type fluidState)
89 { return fluidState.saltConcentration(); }
90 
91 template <class FluidState>
92 OPM_HOST_DEVICE auto getSaltConcentration_(typename std::enable_if<!HasMember_saltConcentration<FluidState>::value,
93  const FluidState&>::type)
94 { return 0.0; }
95 
96 OPM_GENERATE_HAS_MEMBER(saltSaturation, ) // Creates 'HasMember_saltSaturation<T>'.
97 
98 template <class FluidState>
99 OPM_HOST_DEVICE auto getSaltSaturation_(typename std::enable_if<HasMember_saltSaturation<FluidState>::value,
100  const FluidState&>::type fluidState)
101 { return fluidState.saltSaturation(); }
102 
103 
104 template <class FluidState>
105 OPM_HOST_DEVICE auto getSaltSaturation_(typename std::enable_if<!HasMember_saltSaturation<FluidState>::value,
106  const FluidState&>::type)
107 { return 0.0; }
108 
109 OPM_GENERATE_HAS_MEMBER(solventSaturation, ) // Creates 'HasMember_solventSaturation<T>'.
110 
111 template <class FluidState>
112 OPM_HOST_DEVICE auto getSolventSaturation_(typename std::enable_if<HasMember_solventSaturation<FluidState>::value,
113  const FluidState&>::type fluidState)
114 { return fluidState.solventSaturation(); }
115 
116 template <class FluidState>
117 OPM_HOST_DEVICE auto getSolventSaturation_(typename std::enable_if<!HasMember_solventSaturation<FluidState>::value,
118  const FluidState&>::type)
119 { return 0.0; }
120 
128 template <class ValueT,
129  class FluidSystemT,
130  bool storeTemperature = false,
131  bool storeEnthalpy = false,
132  bool enableDissolution = true,
133  bool enableVapwat = false,
134  bool enableBrine = false,
135  bool enableSaltPrecipitation = false,
136  bool enableDissolutionInWater = false,
137  bool enableSolvent = false,
138  unsigned numStoragePhases = FluidSystemT::numPhases>
140 {
141 public:
142 
143 template <class OtherScalarT,
144  class OtherFluidSystemT,
145  bool otherStoreTemperature,
146  bool otherStoreEnthalpy,
147  bool otherEnableDissolution,
148  bool otherEnableVapwat,
149  bool otherEnableBrine,
150  bool otherEnableSaltPrecipitation,
151  bool otherEnableDissolutionInWater,
152  bool otherEnableSolvent,
153  unsigned otherNumStoragePhases>
154 friend class BlackOilFluidState;
155 
156  using FluidSystem = FluidSystemT;
157  using ValueType = ValueT;
158 
159  static constexpr int waterPhaseIdx = FluidSystem::waterPhaseIdx;
160  static constexpr int gasPhaseIdx = FluidSystem::gasPhaseIdx;
161  static constexpr int oilPhaseIdx = FluidSystem::oilPhaseIdx;
162 
163  static constexpr int waterCompIdx = FluidSystem::waterCompIdx;
164  static constexpr int gasCompIdx = FluidSystem::gasCompIdx;
165  static constexpr int oilCompIdx = FluidSystem::oilCompIdx;
166 
167  static constexpr int numPhases = FluidSystem::numPhases;
168  static constexpr int numComponents = FluidSystem::numComponents;
169 
170  static constexpr bool fluidSystemIsStatic = std::is_empty_v<FluidSystem>;
171 
177  explicit OPM_HOST_DEVICE BlackOilFluidState(const FluidSystem& fluidSystem)
178  {
179  if constexpr (!fluidSystemIsStatic) {
180  fluidSystemPtr_ = &fluidSystem;
181  }
182  }
183 
190  template<class OtherFluidSystemType>
191  auto withOtherFluidSystem(const OtherFluidSystemType& other) const
192  {
193  using FS = std::decay_t<OtherFluidSystemType>;
194 
195  auto bfstate = BlackOilFluidState<
196  ValueType,
197  FS,
198  storeTemperature,
199  storeEnthalpy,
200  enableDissolution,
201  enableVapwat,
202  enableBrine,
203  enableSaltPrecipitation,
204  enableDissolutionInWater,
205  enableSolvent,
206  numStoragePhases
207  >(other);
208 
209  bfstate.assign(*this);
210  return bfstate;
211  }
212 
218  OPM_HOST_DEVICE BlackOilFluidState()
219  {
220  static_assert(fluidSystemIsStatic);
221  }
222 
231  void checkDefined() const
232  {
233 #ifndef NDEBUG
234  Valgrind::CheckDefined(pvtRegionIdx_);
235 
236  for (unsigned storagePhaseIdx = 0; storagePhaseIdx < numStoragePhases; ++ storagePhaseIdx) {
237  Valgrind::CheckDefined(saturation_[storagePhaseIdx]);
238  Valgrind::CheckDefined(pressure_[storagePhaseIdx]);
239  Valgrind::CheckDefined(density_[storagePhaseIdx]);
240  Valgrind::CheckDefined(invB_[storagePhaseIdx]);
241 
242  if constexpr (storeEnthalpy)
243  Valgrind::CheckDefined((*enthalpy_)[storagePhaseIdx]);
244  }
245 
246  if constexpr (enableDissolution) {
247  Valgrind::CheckDefined(*Rs_);
248  Valgrind::CheckDefined(*Rv_);
249  }
250 
251  if constexpr (enableVapwat) {
252  Valgrind::CheckDefined(*Rvw_);
253  }
254 
255  if constexpr (enableDissolutionInWater) {
256  Valgrind::CheckDefined(*Rsw_);
257  }
258 
259  if constexpr (enableBrine) {
260  Valgrind::CheckDefined(*saltConcentration_);
261  }
262 
263  if constexpr (enableSaltPrecipitation) {
264  Valgrind::CheckDefined(*saltSaturation_);
265  }
266 
267  if constexpr (enableSolvent) {
268  Valgrind::CheckDefined(*solventSaturation_);
269  Valgrind::CheckDefined(*solventDensity_);
270  Valgrind::CheckDefined(*solventInvB_);
271  Valgrind::CheckDefined(*rsSolw_);
272  }
273 
274  if constexpr (storeTemperature)
275  Valgrind::CheckDefined(*temperature_);
276 #endif // NDEBUG
277  }
278 
283  template <class FluidState>
284  OPM_HOST_DEVICE void assign(const FluidState& fs)
285  {
286  if constexpr (storeTemperature)
287  setTemperature(fs.temperature(/*phaseIdx=*/0));
288 
289  unsigned pvtRegionIdx = getPvtRegionIndex_<FluidState>(fs);
290  setPvtRegionIndex(pvtRegionIdx);
291 
292  setTotalSaturation(fs.totalSaturation());
293 
294  if constexpr (enableDissolution) {
295  setRs(BlackOil::getRs_<FluidSystem, FluidState, ValueType>(fs, pvtRegionIdx));
296  setRv(BlackOil::getRv_<FluidSystem, FluidState, ValueType>(fs, pvtRegionIdx));
297  }
298  if constexpr (enableVapwat) {
299  setRvw(BlackOil::getRvw_<FluidSystem, FluidState, ValueType>(fs, pvtRegionIdx));
300  }
301  if constexpr (enableDissolutionInWater) {
302  setRsw(BlackOil::getRsw_<FluidSystem, FluidState, ValueType>(fs, pvtRegionIdx));
303  }
304  if constexpr (enableBrine){
305  setSaltConcentration(BlackOil::getSaltConcentration_<FluidState, ValueType>(fs, pvtRegionIdx));
306  }
307  if constexpr (enableSaltPrecipitation){
308  setSaltSaturation(BlackOil::getSaltSaturation_<FluidSystem, FluidState, ValueType>(fs, pvtRegionIdx));
309  }
310  if constexpr (enableSolvent) {
311  setSolventSaturation(BlackOil::getSolventSaturation_<FluidState, ValueType>(fs, pvtRegionIdx));
312  setSolventDensity(BlackOil::getSolventDensity_<FluidState, ValueType>(fs, pvtRegionIdx));
313  setSolventInvB(BlackOil::getSolventInvB_<FluidState, ValueType>(fs, pvtRegionIdx));
314  setRsSolw(BlackOil::getRsSolw_<FluidState, ValueType>(fs, pvtRegionIdx));
315  }
316  for (unsigned int storagePhaseIdx = 0; storagePhaseIdx < numStoragePhases; ++storagePhaseIdx) {
317  // No need to use setXXX as we would just have to convert index to canonical index and then back.
318  pressure_[storagePhaseIdx] = fs.pressure_[storagePhaseIdx];
319  saturation_[storagePhaseIdx] = fs.saturation_[storagePhaseIdx];
320  density_[storagePhaseIdx] = fs.density_[storagePhaseIdx];
321  invB_[storagePhaseIdx] = fs.invB_[storagePhaseIdx];
322  if constexpr (storeEnthalpy)
323  (*enthalpy_)[storagePhaseIdx] = (*fs.enthalpy_)[storagePhaseIdx];
324  }
325  }
326 
333  OPM_HOST_DEVICE void setPvtRegionIndex(unsigned newPvtRegionIdx)
334  { pvtRegionIdx_ = static_cast<unsigned short>(newPvtRegionIdx); }
335 
339  OPM_HOST_DEVICE void setPressure(unsigned phaseIdx, const ValueType& p)
340  { pressure_[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())] = p; }
341 
345  OPM_HOST_DEVICE void setSaturation(unsigned phaseIdx, const ValueType& S)
346  { saturation_[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())] = S; }
347 
351  OPM_HOST_DEVICE void setTotalSaturation(const ValueType& value)
352  {
353  totalSaturation_ = value;
354  }
355 
362  OPM_HOST_DEVICE void setTemperature(const ValueType& value)
363  {
364  assert(storeTemperature);
365 
366  (*temperature_) = value;
367  }
368 
375  OPM_HOST_DEVICE void setEnthalpy(unsigned phaseIdx, const ValueType& value)
376  {
377  assert(storeEnthalpy);
378 
379  (*enthalpy_)[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())] = value;
380  }
381 
385  OPM_HOST_DEVICE void setInvB(unsigned phaseIdx, const ValueType& b)
386  { invB_[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())] = b; }
387 
391  OPM_HOST_DEVICE void setDensity(unsigned phaseIdx, const ValueType& rho)
392  { density_[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())] = rho; }
393 
399  OPM_HOST_DEVICE void setRs(const ValueType& newRs)
400  { *Rs_ = newRs; }
401 
407  OPM_HOST_DEVICE void setRv(const ValueType& newRv)
408  { *Rv_ = newRv; }
409 
415  OPM_HOST_DEVICE void setRvw(const ValueType& newRvw)
416  { *Rvw_ = newRvw; }
417 
423  OPM_HOST_DEVICE void setRsw(const ValueType& newRsw)
424  { *Rsw_ = newRsw; }
425 
429  OPM_HOST_DEVICE void setSaltConcentration(const ValueType& newSaltConcentration)
430  { *saltConcentration_ = newSaltConcentration; }
431 
435  OPM_HOST_DEVICE void setSaltSaturation(const ValueType& newSaltSaturation)
436  { *saltSaturation_ = newSaltSaturation; }
437 
441  OPM_HOST_DEVICE void setSolventSaturation(const ValueType& newSolventSaturation)
442  { *solventSaturation_ = newSolventSaturation; }
443 
447  OPM_HOST_DEVICE void setSolventDensity(const ValueType& newSolventDensity)
448  { *solventDensity_ = newSolventDensity; }
449 
453  OPM_HOST_DEVICE void setSolventInvB(const ValueType& newSolventInvB)
454  { *solventInvB_ = newSolventInvB; }
455 
459  OPM_HOST_DEVICE void setRsSolw(const ValueType& newRsSolw)
460  { *rsSolw_ = newRsSolw; }
461 
465  OPM_HOST_DEVICE const ValueType& pressure(unsigned phaseIdx) const
466  { return pressure_[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())]; }
467 
471  OPM_HOST_DEVICE const ValueType& saturation(unsigned phaseIdx) const
472  { return saturation_[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())]; }
473 
477  OPM_HOST_DEVICE const ValueType& totalSaturation() const
478  {
479  return totalSaturation_;
480  }
481 
485  OPM_HOST_DEVICE ValueType temperature(unsigned) const
486  {
487  if constexpr (storeTemperature) {
488  return *temperature_;
489  } else {
490  return fluidSystem().reservoirTemperature(pvtRegionIdx_);
491  }
492  }
493 
500  OPM_HOST_DEVICE const ValueType& invB(unsigned phaseIdx) const
501  { return invB_[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())]; }
502 
510  OPM_HOST_DEVICE ValueType Rs() const
511  {
512  if constexpr (enableDissolution) {
513  return *Rs_;
514  } else {
515  return ValueType{0.0};
516  }
517  }
518 
526  OPM_HOST_DEVICE ValueType Rv() const
527  {
528  if constexpr (!enableDissolution) {
529  return ValueType{0.0};
530  } else {
531  return *Rv_;
532  }
533  }
534 
542  OPM_HOST_DEVICE ValueType Rvw() const
543  {
544  if constexpr (enableVapwat) {
545  return *Rvw_;
546  } else {
547  return ValueType{0.0};
548  }
549  }
550 
558  OPM_HOST_DEVICE ValueType Rsw() const
559  {
560  if constexpr (enableDissolutionInWater) {
561  return *Rsw_;
562  } else {
563  return ValueType{0.0};
564  }
565  }
566 
570  OPM_HOST_DEVICE ValueType saltConcentration() const
571  {
572  if constexpr (enableBrine) {
573  return *saltConcentration_;
574  } else {
575  return ValueType{0.0};
576  }
577  }
578 
582  OPM_HOST_DEVICE ValueType saltSaturation() const
583  {
584  if constexpr (enableSaltPrecipitation) {
585  return *saltSaturation_;
586  } else {
587  return ValueType{0.0};
588  }
589  }
590 
594  OPM_HOST_DEVICE ValueType solventSaturation() const
595  {
596  if constexpr (enableSolvent) {
597  return *solventSaturation_;
598  } else {
599  return ValueType{0.0};
600  }
601  }
602 
606  OPM_HOST_DEVICE ValueType solventDensity() const
607  {
608  if constexpr (enableSolvent) {
609  return *solventDensity_;
610  } else {
611  return ValueType{0.0};
612  }
613  }
614 
618  OPM_HOST_DEVICE ValueType solventInvB() const
619  {
620  if constexpr (enableSolvent) {
621  return *solventInvB_;
622  } else {
623  return ValueType{0.0};
624  }
625  }
626 
630  OPM_HOST_DEVICE ValueType rsSolw() const
631  {
632  if constexpr (enableSolvent) {
633  return *rsSolw_;
634  } else {
635  return ValueType{0.0};
636  }
637  }
638 
643  OPM_HOST_DEVICE unsigned short pvtRegionIndex() const
644  { return pvtRegionIdx_; }
645 
649  OPM_HOST_DEVICE ValueType density(unsigned phaseIdx) const
650  { return density_[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())]; }
651 
658  OPM_HOST_DEVICE const ValueType& enthalpy(unsigned phaseIdx) const
659  { return (*enthalpy_)[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())]; }
660 
667  OPM_HOST_DEVICE ValueType internalEnergy(unsigned phaseIdx) const
668  { auto energy = (*enthalpy_)[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())];
669  if(!fluidSystem().enthalpyEqualEnergy()){
670  energy -= pressure(phaseIdx)/density(phaseIdx);
671  }
672  return energy;
673  }
674 
676  // slow methods
678 
682  OPM_HOST_DEVICE ValueType molarDensity(unsigned phaseIdx) const
683  {
684  const auto& rho = density(phaseIdx);
685 
686  if (phaseIdx == waterPhaseIdx)
687  return rho/fluidSystem().molarMass(waterCompIdx, pvtRegionIdx_);
688 
689  return
690  rho*(moleFraction(phaseIdx, gasCompIdx)/fluidSystem().molarMass(gasCompIdx, pvtRegionIdx_)
691  + moleFraction(phaseIdx, oilCompIdx)/fluidSystem().molarMass(oilCompIdx, pvtRegionIdx_));
692 
693  }
694 
700  OPM_HOST_DEVICE ValueType molarVolume(unsigned phaseIdx) const
701  { return 1.0/molarDensity(phaseIdx); }
702 
706  OPM_HOST_DEVICE ValueType viscosity(unsigned phaseIdx) const
707  { return fluidSystem().viscosity(*this, phaseIdx, pvtRegionIdx_); }
708 
712  OPM_HOST_DEVICE ValueType massFraction(unsigned phaseIdx, unsigned compIdx) const
713  {
714  switch (phaseIdx) {
715  case waterPhaseIdx:
716  if (compIdx == waterCompIdx)
717  return 1.0;
718  return 0.0;
719 
720  case oilPhaseIdx:
721  if (compIdx == waterCompIdx)
722  return 0.0;
723  else if (compIdx == oilCompIdx)
724  return 1.0 - fluidSystem().convertRsToXoG(Rs(), pvtRegionIdx_);
725  else {
726  assert(compIdx == gasCompIdx);
727  return fluidSystem().convertRsToXoG(Rs(), pvtRegionIdx_);
728  }
729  break;
730 
731  case gasPhaseIdx:
732  if (compIdx == waterCompIdx)
733  return 0.0;
734  else if (compIdx == oilCompIdx)
735  return fluidSystem().convertRvToXgO(Rv(), pvtRegionIdx_);
736  else {
737  assert(compIdx == gasCompIdx);
738  return 1.0 - fluidSystem().convertRvToXgO(Rv(), pvtRegionIdx_);
739  }
740  break;
741  }
742 
743  OPM_THROW(std::logic_error, "Invalid phase or component index!");
744  }
745 
749  OPM_HOST_DEVICE ValueType moleFraction(unsigned phaseIdx, unsigned compIdx) const
750  {
751  switch (phaseIdx) {
752  case waterPhaseIdx:
753  if (compIdx == waterCompIdx)
754  return 1.0;
755  return 0.0;
756 
757  case oilPhaseIdx:
758  if (compIdx == waterCompIdx)
759  return 0.0;
760  else if (compIdx == oilCompIdx)
761  return 1.0 - fluidSystem().convertXoGToxoG(fluidSystem().convertRsToXoG(Rs(), pvtRegionIdx_),
762  pvtRegionIdx_);
763  else {
764  assert(compIdx == gasCompIdx);
765  return fluidSystem().convertXoGToxoG(fluidSystem().convertRsToXoG(Rs(), pvtRegionIdx_),
766  pvtRegionIdx_);
767  }
768  break;
769 
770  case gasPhaseIdx:
771  if (compIdx == waterCompIdx)
772  return 0.0;
773  else if (compIdx == oilCompIdx)
774  return fluidSystem().convertXgOToxgO(fluidSystem().convertRvToXgO(Rv(), pvtRegionIdx_),
775  pvtRegionIdx_);
776  else {
777  assert(compIdx == gasCompIdx);
778  return 1.0 - fluidSystem().convertXgOToxgO(fluidSystem().convertRvToXgO(Rv(), pvtRegionIdx_),
779  pvtRegionIdx_);
780  }
781  break;
782  }
783 
784  OPM_THROW(std::logic_error, "Invalid phase or component index!");
785  }
786 
790  OPM_HOST_DEVICE ValueType molarity(unsigned phaseIdx, unsigned compIdx) const
791  { return moleFraction(phaseIdx, compIdx)*molarDensity(phaseIdx); }
792 
796  OPM_HOST_DEVICE ValueType averageMolarMass(unsigned phaseIdx) const
797  {
798  ValueType result{0.0};
799  for (unsigned compIdx = 0; compIdx < numComponents; ++ compIdx)
800  result += fluidSystem().molarMass(compIdx, pvtRegionIdx_)*moleFraction(phaseIdx, compIdx);
801  return result;
802  }
803 
807  OPM_HOST_DEVICE ValueType fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
808  { return fluidSystem().fugacityCoefficient(*this, phaseIdx, compIdx, pvtRegionIdx_); }
809 
813  OPM_HOST_DEVICE ValueType fugacity(unsigned phaseIdx, unsigned compIdx) const
814  {
815  return
816  fugacityCoefficient(phaseIdx, compIdx)
817  *moleFraction(phaseIdx, compIdx)
818  *pressure(phaseIdx);
819  }
820 
828  OPM_HOST_DEVICE bool phaseIsActive(int phaseIdx) const
829  {
830  return fluidSystem().phaseIsActive(phaseIdx);
831  }
832 
840  OPM_HOST_DEVICE const FluidSystem& fluidSystem() const
841  {
842  if constexpr (fluidSystemIsStatic) {
843  static FluidSystem instance;
844  return instance;
845  } else {
846  return **fluidSystemPtr_;
847  }
848  }
849 
850 private:
851  OPM_HOST_DEVICE static unsigned storageToCanonicalPhaseIndex_(unsigned storagePhaseIdx, const FluidSystem& fluidSystem)
852  {
853  if constexpr (numStoragePhases == 3)
854  return storagePhaseIdx;
855  else
856  return fluidSystem.activeToCanonicalPhaseIdx(storagePhaseIdx);
857  }
858 
859  OPM_HOST_DEVICE static unsigned canonicalToStoragePhaseIndex_(unsigned canonicalPhaseIdx, const FluidSystem& fluidSystem)
860  {
861  if constexpr (numStoragePhases == 3)
862  return canonicalPhaseIdx;
863  else
864  return fluidSystem.canonicalToActivePhaseIdx(canonicalPhaseIdx);
865  }
866 
867  ConditionalStorage<storeTemperature, ValueType> temperature_{};
868  ConditionalStorage<storeEnthalpy, std::array<ValueType, numStoragePhases> > enthalpy_{};
869  ValueType totalSaturation_{};
870  std::array<ValueType, numStoragePhases> pressure_{};
871  std::array<ValueType, numStoragePhases> saturation_{};
872  std::array<ValueType, numStoragePhases> invB_{};
873  std::array<ValueType, numStoragePhases> density_{};
874  ConditionalStorage<enableDissolution,ValueType> Rs_{};
875  ConditionalStorage<enableDissolution, ValueType> Rv_{};
876  ConditionalStorage<enableVapwat,ValueType> Rvw_{};
877  ConditionalStorage<enableDissolutionInWater,ValueType> Rsw_{};
878  ConditionalStorage<enableBrine, ValueType> saltConcentration_{};
879  ConditionalStorage<enableSaltPrecipitation, ValueType> saltSaturation_{};
880  ConditionalStorage<enableSolvent, ValueType> solventSaturation_{};
881  ConditionalStorage<enableSolvent, ValueType> solventDensity_{};
882  ConditionalStorage<enableSolvent, ValueType> solventInvB_{};
883  ConditionalStorage<enableSolvent, ValueType> rsSolw_{};
884 
885  unsigned short pvtRegionIdx_{};
886 
887  // If we have a non-static fluid system, we need to store a pointer
888  // to it. Otherwise, we do not need to store anything.
889  ConditionalStorage<!fluidSystemIsStatic, FluidSystem const*> fluidSystemPtr_;
890 };
891 
892 } // namespace Opm
893 
894 #endif
OPM_HOST_DEVICE void setSolventInvB(const ValueType &newSolventInvB)
Set the solvent inverse formation volume factor [-].
Definition: BlackOilFluidState.hpp:453
OPM_HOST_DEVICE void setDensity(unsigned phaseIdx, const ValueType &rho)
\ brief Set the density of a fluid phase
Definition: BlackOilFluidState.hpp:391
OPM_HOST_DEVICE const ValueType & invB(unsigned phaseIdx) const
Return the inverse formation volume factor of a fluid phase [-].
Definition: BlackOilFluidState.hpp:500
auto withOtherFluidSystem(const OtherFluidSystemType &other) const
Create a new fluid state object with a different fluid system.
Definition: BlackOilFluidState.hpp:191
OPM_HOST_DEVICE unsigned short pvtRegionIndex() const
Return the PVT region where the current fluid state is assumed to be part of.
Definition: BlackOilFluidState.hpp:643
OPM_HOST_DEVICE void setEnthalpy(unsigned phaseIdx, const ValueType &value)
Set the specific enthalpy [J/kg] of a given fluid phase.
Definition: BlackOilFluidState.hpp:375
OPM_HOST_DEVICE ValueType viscosity(unsigned phaseIdx) const
Return the dynamic viscosity of a fluid phase [Pa s].
Definition: BlackOilFluidState.hpp:706
OPM_HOST_DEVICE ValueType Rs() const
Return the gas dissolution factor of oil [m^3/m^3].
Definition: BlackOilFluidState.hpp:510
OPM_HOST_DEVICE void setRv(const ValueType &newRv)
Set the oil vaporization factor [m^3/m^3] of the gas phase.
Definition: BlackOilFluidState.hpp:407
A simple class which only stores a given member attribute if a boolean condition is true...
Definition: ConditionalStorage.hpp:49
OPM_HOST_DEVICE ValueType temperature(unsigned) const
Return the temperature [K].
Definition: BlackOilFluidState.hpp:485
OPM_HOST_DEVICE void setSolventSaturation(const ValueType &newSolventSaturation)
Set the solvent saturation.
Definition: BlackOilFluidState.hpp:441
OPM_HOST_DEVICE void setSaltConcentration(const ValueType &newSaltConcentration)
Set the salt concentration.
Definition: BlackOilFluidState.hpp:429
OPM_HOST_DEVICE void setRvw(const ValueType &newRvw)
Set the water vaporization factor [m^3/m^3] of the gas phase.
Definition: BlackOilFluidState.hpp:415
OPM_HOST_DEVICE void setSaltSaturation(const ValueType &newSaltSaturation)
Set the solid salt saturation.
Definition: BlackOilFluidState.hpp:435
#define OPM_GENERATE_HAS_MEMBER(MEMBER_NAME,...)
This macro generates a class HasMember_${MEMBER_NAME} which can be used for template specialization...
Definition: HasMemberGeneratorMacros.hpp:49
OPM_HOST_DEVICE BlackOilFluidState()
Construct a fluid state object.
Definition: BlackOilFluidState.hpp:218
OPM_HOST_DEVICE void setTemperature(const ValueType &value)
Set the temperature [K].
Definition: BlackOilFluidState.hpp:362
OPM_HOST_DEVICE ValueType Rvw() const
Return the water vaporization factor of gas [m^3/m^3].
Definition: BlackOilFluidState.hpp:542
OPM_HOST_DEVICE ValueType Rv() const
Return the oil vaporization factor of gas [m^3/m^3].
Definition: BlackOilFluidState.hpp:526
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
OPM_HOST_DEVICE ValueType massFraction(unsigned phaseIdx, unsigned compIdx) const
Return the mass fraction of a component in a fluid phase [-].
Definition: BlackOilFluidState.hpp:712
Implements a "tailor-made" fluid state class for the black-oil model.
Definition: BlackOilFluidState.hpp:139
OPM_HOST_DEVICE ValueType molarity(unsigned phaseIdx, unsigned compIdx) const
Return the partial molar density of a component in a fluid phase [mol / m^3].
Definition: BlackOilFluidState.hpp:790
OPM_HOST_DEVICE const ValueType & pressure(unsigned phaseIdx) const
Return the pressure of a fluid phase [Pa].
Definition: BlackOilFluidState.hpp:465
OPM_HOST_DEVICE BlackOilFluidState(const FluidSystem &fluidSystem)
Construct a fluid state object.
Definition: BlackOilFluidState.hpp:177
This macro generates a class HasMember_${MEMBER_NAME} which can be used for template specialization...
OPM_HOST_DEVICE ValueType solventSaturation() const
Return the solvent saturation [-].
Definition: BlackOilFluidState.hpp:594
OPM_HOST_DEVICE const ValueType & totalSaturation() const
Return the total saturation needed for sequential.
Definition: BlackOilFluidState.hpp:477
OPM_HOST_DEVICE ValueType density(unsigned phaseIdx) const
Return the density [kg/m^3] of a given fluid phase.
Definition: BlackOilFluidState.hpp:649
OPM_HOST_DEVICE ValueType averageMolarMass(unsigned phaseIdx) const
Return the partial molar density of a fluid phase [kg / mol].
Definition: BlackOilFluidState.hpp:796
OPM_HOST_DEVICE ValueType saltSaturation() const
Return the saturation of solid salt.
Definition: BlackOilFluidState.hpp:582
OPM_HOST_DEVICE const FluidSystem & fluidSystem() const
Return the fluid system used by this fluid state.
Definition: BlackOilFluidState.hpp:840
OPM_HOST_DEVICE ValueType Rsw() const
Return the gas dissolution factor of water [m^3/m^3].
Definition: BlackOilFluidState.hpp:558
OPM_HOST_DEVICE void setPvtRegionIndex(unsigned newPvtRegionIdx)
Set the index of the fluid region.
Definition: BlackOilFluidState.hpp:333
OPM_HOST_DEVICE void setRsSolw(const ValueType &newRsSolw)
Set the solvent dissolution factor in water [m^3/m^3].
Definition: BlackOilFluidState.hpp:459
OPM_HOST_DEVICE const ValueType & enthalpy(unsigned phaseIdx) const
Return the specific enthalpy [J/kg] of a given fluid phase.
Definition: BlackOilFluidState.hpp:658
A simple class which only stores a given member attribute if a boolean condition is true...
OPM_HOST_DEVICE void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition: BlackOilFluidState.hpp:284
OPM_HOST_DEVICE const ValueType & saturation(unsigned phaseIdx) const
Return the saturation of a fluid phase [-].
Definition: BlackOilFluidState.hpp:471
OPM_HOST_DEVICE ValueType saltConcentration() const
Return the concentration of salt in water.
Definition: BlackOilFluidState.hpp:570
OPM_HOST_DEVICE ValueType internalEnergy(unsigned phaseIdx) const
Return the specific internal energy [J/kg] of a given fluid phase.
Definition: BlackOilFluidState.hpp:667
Some templates to wrap the valgrind client request macros.
OPM_HOST_DEVICE ValueType moleFraction(unsigned phaseIdx, unsigned compIdx) const
Return the mole fraction of a component in a fluid phase [-].
Definition: BlackOilFluidState.hpp:749
OPM_HOST_DEVICE ValueType molarDensity(unsigned phaseIdx) const
Return the molar density of a fluid phase [mol/m^3].
Definition: BlackOilFluidState.hpp:682
OPM_HOST_DEVICE void setInvB(unsigned phaseIdx, const ValueType &b)
\ brief Set the inverse formation volume factor of a fluid phase
Definition: BlackOilFluidState.hpp:385
OPM_HOST_DEVICE void setSaturation(unsigned phaseIdx, const ValueType &S)
Set the saturation of a fluid phase [-].
Definition: BlackOilFluidState.hpp:345
OPM_HOST_DEVICE void setPressure(unsigned phaseIdx, const ValueType &p)
Set the pressure of a fluid phase [-].
Definition: BlackOilFluidState.hpp:339
OPM_HOST_DEVICE void setSolventDensity(const ValueType &newSolventDensity)
Set the solvent density [kg/m^3].
Definition: BlackOilFluidState.hpp:447
OPM_HOST_DEVICE void setRs(const ValueType &newRs)
Set the gas dissolution factor [m^3/m^3] of the oil phase.
Definition: BlackOilFluidState.hpp:399
OPM_HOST_DEVICE void setTotalSaturation(const ValueType &value)
Set the total saturation used for sequential methods.
Definition: BlackOilFluidState.hpp:351
void checkDefined() const
Make sure that all attributes are defined.
Definition: BlackOilFluidState.hpp:231
OPM_HOST_DEVICE bool phaseIsActive(int phaseIdx) const
Return if a phase is active (via the FluidSystem).
Definition: BlackOilFluidState.hpp:828
OPM_HOST_DEVICE ValueType fugacity(unsigned phaseIdx, unsigned compIdx) const
Return the fugacity of a component in a fluid phase [Pa].
Definition: BlackOilFluidState.hpp:813
OPM_HOST_DEVICE void setRsw(const ValueType &newRsw)
Set the gas dissolution factor [m^3/m^3] of the water phase.
Definition: BlackOilFluidState.hpp:423
OPM_HOST_DEVICE ValueType rsSolw() const
Return the solvent dissolution factor in water [m^3/m^3].
Definition: BlackOilFluidState.hpp:630
OPM_HOST_DEVICE ValueType molarVolume(unsigned phaseIdx) const
Return the molar volume of a fluid phase [m^3/mol].
Definition: BlackOilFluidState.hpp:700
OPM_HOST_DEVICE ValueType solventDensity() const
Return the solvent density [kg/m^3].
Definition: BlackOilFluidState.hpp:606
OPM_HOST_DEVICE ValueType solventInvB() const
Return the solvent inverse formation volume factor [-].
Definition: BlackOilFluidState.hpp:618
OPM_HOST_DEVICE ValueType fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
Return the fugacity coefficient of a component in a fluid phase [-].
Definition: BlackOilFluidState.hpp:807