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  using FluidSystem = FluidSystemT;
143  using ValueType = ValueT;
144 
145  static constexpr int waterPhaseIdx = FluidSystem::waterPhaseIdx;
146  static constexpr int gasPhaseIdx = FluidSystem::gasPhaseIdx;
147  static constexpr int oilPhaseIdx = FluidSystem::oilPhaseIdx;
148 
149  static constexpr int waterCompIdx = FluidSystem::waterCompIdx;
150  static constexpr int gasCompIdx = FluidSystem::gasCompIdx;
151  static constexpr int oilCompIdx = FluidSystem::oilCompIdx;
152 
153  static constexpr int numPhases = FluidSystem::numPhases;
154  static constexpr int numComponents = FluidSystem::numComponents;
155 
156  static constexpr bool fluidSystemIsStatic = std::is_empty_v<FluidSystem>;
157 
163  explicit OPM_HOST_DEVICE BlackOilFluidState(const FluidSystem& fluidSystem)
164  {
165  if constexpr (!fluidSystemIsStatic) {
166  fluidSystemPtr_ = &fluidSystem;
167  }
168  }
169 
170  // This is intended to be used when we are converting fluid
171  // state from a version that uses the static fluidsystem to
172  // a version that uses a dynamic fluid system.
173  template<class OtherFluidSystemType>
174  auto withOtherFluidSystem(const OtherFluidSystemType& other) const
175  {
176  auto bfstate = BlackOilFluidState<ValueType, OtherFluidSystemType,
177  storeTemperature,
178  storeEnthalpy,
179  enableDissolution,
180  enableVapwat,
181  enableBrine,
182  enableSaltPrecipitation,
183  enableDissolutionInWater,
184  enableSolvent,
185  numStoragePhases>(other);
186  bfstate.assign(*this);
187  return bfstate;
188  }
189 
195  OPM_HOST_DEVICE BlackOilFluidState()
196  {
197  static_assert(fluidSystemIsStatic);
198  }
199 
208  void checkDefined() const
209  {
210 #ifndef NDEBUG
211  Valgrind::CheckDefined(pvtRegionIdx_);
212 
213  for (unsigned storagePhaseIdx = 0; storagePhaseIdx < numStoragePhases; ++ storagePhaseIdx) {
214  Valgrind::CheckDefined(saturation_[storagePhaseIdx]);
215  Valgrind::CheckDefined(pressure_[storagePhaseIdx]);
216  Valgrind::CheckDefined(density_[storagePhaseIdx]);
217  Valgrind::CheckDefined(invB_[storagePhaseIdx]);
218 
219  if constexpr (storeEnthalpy)
220  Valgrind::CheckDefined((*enthalpy_)[storagePhaseIdx]);
221  }
222 
223  if constexpr (enableDissolution) {
224  Valgrind::CheckDefined(*Rs_);
225  Valgrind::CheckDefined(*Rv_);
226  }
227 
228  if constexpr (enableVapwat) {
229  Valgrind::CheckDefined(*Rvw_);
230  }
231 
232  if constexpr (enableDissolutionInWater) {
233  Valgrind::CheckDefined(*Rsw_);
234  }
235 
236  if constexpr (enableBrine) {
237  Valgrind::CheckDefined(*saltConcentration_);
238  }
239 
240  if constexpr (enableSaltPrecipitation) {
241  Valgrind::CheckDefined(*saltSaturation_);
242  }
243 
244  if constexpr (enableSolvent) {
245  Valgrind::CheckDefined(*solventSaturation_);
246  Valgrind::CheckDefined(*solventDensity_);
247  Valgrind::CheckDefined(*solventInvB_);
248  Valgrind::CheckDefined(*rsSolw_);
249  }
250 
251  if constexpr (storeTemperature)
252  Valgrind::CheckDefined(*temperature_);
253 #endif // NDEBUG
254  }
255 
260  template <class FluidState>
261  OPM_HOST_DEVICE void assign(const FluidState& fs)
262  {
263  if constexpr (storeTemperature)
264  setTemperature(fs.temperature(/*phaseIdx=*/0));
265 
266  unsigned pvtRegionIdx = getPvtRegionIndex_<FluidState>(fs);
267  setPvtRegionIndex(pvtRegionIdx);
268 
269  setTotalSaturation(fs.totalSaturation());
270 
271  if constexpr (enableDissolution) {
272  setRs(BlackOil::getRs_<FluidSystem, FluidState, ValueType>(fs, pvtRegionIdx));
273  setRv(BlackOil::getRv_<FluidSystem, FluidState, ValueType>(fs, pvtRegionIdx));
274  }
275  if constexpr (enableVapwat) {
276  setRvw(BlackOil::getRvw_<FluidSystem, FluidState, ValueType>(fs, pvtRegionIdx));
277  }
278  if constexpr (enableDissolutionInWater) {
279  setRsw(BlackOil::getRsw_<FluidSystem, FluidState, ValueType>(fs, pvtRegionIdx));
280  }
281  if constexpr (enableBrine){
282  setSaltConcentration(BlackOil::getSaltConcentration_<FluidState, ValueType>(fs, pvtRegionIdx));
283  }
284  if constexpr (enableSaltPrecipitation){
285  setSaltSaturation(BlackOil::getSaltSaturation_<FluidSystem, FluidState, ValueType>(fs, pvtRegionIdx));
286  }
287  if constexpr (enableSolvent) {
288  setSolventSaturation(BlackOil::getSolventSaturation_<FluidState, ValueType>(fs, pvtRegionIdx));
289  setSolventDensity(BlackOil::getSolventDensity_<FluidState, ValueType>(fs, pvtRegionIdx));
290  setSolventInvB(BlackOil::getSolventInvB_<FluidState, ValueType>(fs, pvtRegionIdx));
291  setRsSolw(BlackOil::getRsSolw_<FluidState, ValueType>(fs, pvtRegionIdx));
292  }
293  for (unsigned storagePhaseIdx = 0; storagePhaseIdx < numStoragePhases; ++storagePhaseIdx) {
294  unsigned phaseIdx = storageToCanonicalPhaseIndex_(storagePhaseIdx, fluidSystem());
295  setSaturation(phaseIdx, fs.saturation(phaseIdx));
296  setPressure(phaseIdx, fs.pressure(phaseIdx));
297  setDensity(phaseIdx, fs.density(phaseIdx));
298 
299  if constexpr (storeEnthalpy)
300  setEnthalpy(phaseIdx, fs.enthalpy(phaseIdx));
301 
302  setInvB(phaseIdx, getInvB_<FluidSystem, FluidState, ValueType>(fs, phaseIdx, pvtRegionIdx, fluidSystem()));
303  }
304  }
305 
312  OPM_HOST_DEVICE void setPvtRegionIndex(unsigned newPvtRegionIdx)
313  { pvtRegionIdx_ = static_cast<unsigned short>(newPvtRegionIdx); }
314 
318  OPM_HOST_DEVICE void setPressure(unsigned phaseIdx, const ValueType& p)
319  { pressure_[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())] = p; }
320 
324  OPM_HOST_DEVICE void setSaturation(unsigned phaseIdx, const ValueType& S)
325  { saturation_[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())] = S; }
326 
330  OPM_HOST_DEVICE void setTotalSaturation(const ValueType& value)
331  {
332  totalSaturation_ = value;
333  }
334 
341  OPM_HOST_DEVICE void setTemperature(const ValueType& value)
342  {
343  assert(storeTemperature);
344 
345  (*temperature_) = value;
346  }
347 
354  OPM_HOST_DEVICE void setEnthalpy(unsigned phaseIdx, const ValueType& value)
355  {
356  assert(storeEnthalpy);
357 
358  (*enthalpy_)[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())] = value;
359  }
360 
364  OPM_HOST_DEVICE void setInvB(unsigned phaseIdx, const ValueType& b)
365  { invB_[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())] = b; }
366 
370  OPM_HOST_DEVICE void setDensity(unsigned phaseIdx, const ValueType& rho)
371  { density_[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())] = rho; }
372 
378  OPM_HOST_DEVICE void setRs(const ValueType& newRs)
379  { *Rs_ = newRs; }
380 
386  OPM_HOST_DEVICE void setRv(const ValueType& newRv)
387  { *Rv_ = newRv; }
388 
394  OPM_HOST_DEVICE void setRvw(const ValueType& newRvw)
395  { *Rvw_ = newRvw; }
396 
402  OPM_HOST_DEVICE void setRsw(const ValueType& newRsw)
403  { *Rsw_ = newRsw; }
404 
408  OPM_HOST_DEVICE void setSaltConcentration(const ValueType& newSaltConcentration)
409  { *saltConcentration_ = newSaltConcentration; }
410 
414  OPM_HOST_DEVICE void setSaltSaturation(const ValueType& newSaltSaturation)
415  { *saltSaturation_ = newSaltSaturation; }
416 
420  OPM_HOST_DEVICE void setSolventSaturation(const ValueType& newSolventSaturation)
421  { *solventSaturation_ = newSolventSaturation; }
422 
426  OPM_HOST_DEVICE void setSolventDensity(const ValueType& newSolventDensity)
427  { *solventDensity_ = newSolventDensity; }
428 
432  OPM_HOST_DEVICE void setSolventInvB(const ValueType& newSolventInvB)
433  { *solventInvB_ = newSolventInvB; }
434 
438  OPM_HOST_DEVICE void setRsSolw(const ValueType& newRsSolw)
439  { *rsSolw_ = newRsSolw; }
440 
444  OPM_HOST_DEVICE const ValueType& pressure(unsigned phaseIdx) const
445  { return pressure_[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())]; }
446 
450  OPM_HOST_DEVICE const ValueType& saturation(unsigned phaseIdx) const
451  { return saturation_[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())]; }
452 
456  OPM_HOST_DEVICE const ValueType& totalSaturation() const
457  {
458  return totalSaturation_;
459  }
460 
464  OPM_HOST_DEVICE ValueType temperature(unsigned) const
465  {
466  if constexpr (storeTemperature) {
467  return *temperature_;
468  } else {
469  return fluidSystem().reservoirTemperature(pvtRegionIdx_);
470  }
471  }
472 
479  OPM_HOST_DEVICE const ValueType& invB(unsigned phaseIdx) const
480  { return invB_[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())]; }
481 
489  OPM_HOST_DEVICE ValueType Rs() const
490  {
491  if constexpr (enableDissolution) {
492  return *Rs_;
493  } else {
494  return ValueType{0.0};
495  }
496  }
497 
505  OPM_HOST_DEVICE ValueType Rv() const
506  {
507  if constexpr (!enableDissolution) {
508  return ValueType{0.0};
509  } else {
510  return *Rv_;
511  }
512  }
513 
521  OPM_HOST_DEVICE ValueType Rvw() const
522  {
523  if constexpr (enableVapwat) {
524  return *Rvw_;
525  } else {
526  return ValueType{0.0};
527  }
528  }
529 
537  OPM_HOST_DEVICE ValueType Rsw() const
538  {
539  if constexpr (enableDissolutionInWater) {
540  return *Rsw_;
541  } else {
542  return ValueType{0.0};
543  }
544  }
545 
549  OPM_HOST_DEVICE ValueType saltConcentration() const
550  {
551  if constexpr (enableBrine) {
552  return *saltConcentration_;
553  } else {
554  return ValueType{0.0};
555  }
556  }
557 
561  OPM_HOST_DEVICE ValueType saltSaturation() const
562  {
563  if constexpr (enableSaltPrecipitation) {
564  return *saltSaturation_;
565  } else {
566  return ValueType{0.0};
567  }
568  }
569 
573  OPM_HOST_DEVICE ValueType solventSaturation() const
574  {
575  if constexpr (enableSolvent) {
576  return *solventSaturation_;
577  } else {
578  return ValueType{0.0};
579  }
580  }
581 
585  OPM_HOST_DEVICE ValueType solventDensity() const
586  {
587  if constexpr (enableSolvent) {
588  return *solventDensity_;
589  } else {
590  return ValueType{0.0};
591  }
592  }
593 
597  OPM_HOST_DEVICE ValueType solventInvB() const
598  {
599  if constexpr (enableSolvent) {
600  return *solventInvB_;
601  } else {
602  return ValueType{0.0};
603  }
604  }
605 
609  OPM_HOST_DEVICE ValueType rsSolw() const
610  {
611  if constexpr (enableSolvent) {
612  return *rsSolw_;
613  } else {
614  return ValueType{0.0};
615  }
616  }
617 
622  OPM_HOST_DEVICE unsigned short pvtRegionIndex() const
623  { return pvtRegionIdx_; }
624 
628  OPM_HOST_DEVICE ValueType density(unsigned phaseIdx) const
629  { return density_[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())]; }
630 
637  OPM_HOST_DEVICE const ValueType& enthalpy(unsigned phaseIdx) const
638  { return (*enthalpy_)[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())]; }
639 
646  OPM_HOST_DEVICE ValueType internalEnergy(unsigned phaseIdx) const
647  { auto energy = (*enthalpy_)[canonicalToStoragePhaseIndex_(phaseIdx, fluidSystem())];
648  if(!fluidSystem().enthalpyEqualEnergy()){
649  energy -= pressure(phaseIdx)/density(phaseIdx);
650  }
651  return energy;
652  }
653 
655  // slow methods
657 
661  OPM_HOST_DEVICE ValueType molarDensity(unsigned phaseIdx) const
662  {
663  const auto& rho = density(phaseIdx);
664 
665  if (phaseIdx == waterPhaseIdx)
666  return rho/fluidSystem().molarMass(waterCompIdx, pvtRegionIdx_);
667 
668  return
669  rho*(moleFraction(phaseIdx, gasCompIdx)/fluidSystem().molarMass(gasCompIdx, pvtRegionIdx_)
670  + moleFraction(phaseIdx, oilCompIdx)/fluidSystem().molarMass(oilCompIdx, pvtRegionIdx_));
671 
672  }
673 
679  OPM_HOST_DEVICE ValueType molarVolume(unsigned phaseIdx) const
680  { return 1.0/molarDensity(phaseIdx); }
681 
685  OPM_HOST_DEVICE ValueType viscosity(unsigned phaseIdx) const
686  { return fluidSystem().viscosity(*this, phaseIdx, pvtRegionIdx_); }
687 
691  OPM_HOST_DEVICE ValueType massFraction(unsigned phaseIdx, unsigned compIdx) const
692  {
693  switch (phaseIdx) {
694  case waterPhaseIdx:
695  if (compIdx == waterCompIdx)
696  return 1.0;
697  return 0.0;
698 
699  case oilPhaseIdx:
700  if (compIdx == waterCompIdx)
701  return 0.0;
702  else if (compIdx == oilCompIdx)
703  return 1.0 - fluidSystem().convertRsToXoG(Rs(), pvtRegionIdx_);
704  else {
705  assert(compIdx == gasCompIdx);
706  return fluidSystem().convertRsToXoG(Rs(), pvtRegionIdx_);
707  }
708  break;
709 
710  case gasPhaseIdx:
711  if (compIdx == waterCompIdx)
712  return 0.0;
713  else if (compIdx == oilCompIdx)
714  return fluidSystem().convertRvToXgO(Rv(), pvtRegionIdx_);
715  else {
716  assert(compIdx == gasCompIdx);
717  return 1.0 - fluidSystem().convertRvToXgO(Rv(), pvtRegionIdx_);
718  }
719  break;
720  }
721 
722  OPM_THROW(std::logic_error, "Invalid phase or component index!");
723  }
724 
728  OPM_HOST_DEVICE ValueType moleFraction(unsigned phaseIdx, unsigned compIdx) const
729  {
730  switch (phaseIdx) {
731  case waterPhaseIdx:
732  if (compIdx == waterCompIdx)
733  return 1.0;
734  return 0.0;
735 
736  case oilPhaseIdx:
737  if (compIdx == waterCompIdx)
738  return 0.0;
739  else if (compIdx == oilCompIdx)
740  return 1.0 - fluidSystem().convertXoGToxoG(fluidSystem().convertRsToXoG(Rs(), pvtRegionIdx_),
741  pvtRegionIdx_);
742  else {
743  assert(compIdx == gasCompIdx);
744  return fluidSystem().convertXoGToxoG(fluidSystem().convertRsToXoG(Rs(), pvtRegionIdx_),
745  pvtRegionIdx_);
746  }
747  break;
748 
749  case gasPhaseIdx:
750  if (compIdx == waterCompIdx)
751  return 0.0;
752  else if (compIdx == oilCompIdx)
753  return fluidSystem().convertXgOToxgO(fluidSystem().convertRvToXgO(Rv(), pvtRegionIdx_),
754  pvtRegionIdx_);
755  else {
756  assert(compIdx == gasCompIdx);
757  return 1.0 - fluidSystem().convertXgOToxgO(fluidSystem().convertRvToXgO(Rv(), pvtRegionIdx_),
758  pvtRegionIdx_);
759  }
760  break;
761  }
762 
763  OPM_THROW(std::logic_error, "Invalid phase or component index!");
764  }
765 
769  OPM_HOST_DEVICE ValueType molarity(unsigned phaseIdx, unsigned compIdx) const
770  { return moleFraction(phaseIdx, compIdx)*molarDensity(phaseIdx); }
771 
775  OPM_HOST_DEVICE ValueType averageMolarMass(unsigned phaseIdx) const
776  {
777  ValueType result{0.0};
778  for (unsigned compIdx = 0; compIdx < numComponents; ++ compIdx)
779  result += fluidSystem().molarMass(compIdx, pvtRegionIdx_)*moleFraction(phaseIdx, compIdx);
780  return result;
781  }
782 
786  OPM_HOST_DEVICE ValueType fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
787  { return fluidSystem().fugacityCoefficient(*this, phaseIdx, compIdx, pvtRegionIdx_); }
788 
792  OPM_HOST_DEVICE ValueType fugacity(unsigned phaseIdx, unsigned compIdx) const
793  {
794  return
795  fugacityCoefficient(phaseIdx, compIdx)
796  *moleFraction(phaseIdx, compIdx)
797  *pressure(phaseIdx);
798  }
799 
807  bool phaseIsActive(int phaseIdx) const
808  {
809  return fluidSystem().phaseIsActive(phaseIdx);
810  }
811 
819  OPM_HOST_DEVICE const FluidSystem& fluidSystem() const
820  {
821  if constexpr (fluidSystemIsStatic) {
822  static FluidSystem instance;
823  return instance;
824  } else {
825  return **fluidSystemPtr_;
826  }
827  }
828 
829 private:
830  OPM_HOST_DEVICE static unsigned storageToCanonicalPhaseIndex_(unsigned storagePhaseIdx, const FluidSystem& fluidSystem)
831  {
832  if constexpr (numStoragePhases == 3)
833  return storagePhaseIdx;
834  else
835  return fluidSystem.activeToCanonicalPhaseIdx(storagePhaseIdx);
836  }
837 
838  OPM_HOST_DEVICE static unsigned canonicalToStoragePhaseIndex_(unsigned canonicalPhaseIdx, const FluidSystem& fluidSystem)
839  {
840  if constexpr (numStoragePhases == 3)
841  return canonicalPhaseIdx;
842  else
843  return fluidSystem.canonicalToActivePhaseIdx(canonicalPhaseIdx);
844  }
845 
846  ConditionalStorage<storeTemperature, ValueType> temperature_{};
847  ConditionalStorage<storeEnthalpy, std::array<ValueType, numStoragePhases> > enthalpy_{};
848  ValueType totalSaturation_{};
849  std::array<ValueType, numStoragePhases> pressure_{};
850  std::array<ValueType, numStoragePhases> saturation_{};
851  std::array<ValueType, numStoragePhases> invB_{};
852  std::array<ValueType, numStoragePhases> density_{};
853  ConditionalStorage<enableDissolution,ValueType> Rs_{};
854  ConditionalStorage<enableDissolution, ValueType> Rv_{};
855  ConditionalStorage<enableVapwat,ValueType> Rvw_{};
856  ConditionalStorage<enableDissolutionInWater,ValueType> Rsw_{};
857  ConditionalStorage<enableBrine, ValueType> saltConcentration_{};
858  ConditionalStorage<enableSaltPrecipitation, ValueType> saltSaturation_{};
859  ConditionalStorage<enableSolvent, ValueType> solventSaturation_{};
860  ConditionalStorage<enableSolvent, ValueType> solventDensity_{};
861  ConditionalStorage<enableSolvent, ValueType> solventInvB_{};
862  ConditionalStorage<enableSolvent, ValueType> rsSolw_{};
863 
864  unsigned short pvtRegionIdx_{};
865 
866  // If we have a non-static fluid system, we need to store a pointer
867  // to it. Otherwise, we do not need to store anything.
868  ConditionalStorage<!fluidSystemIsStatic, FluidSystem const*> fluidSystemPtr_;
869 };
870 
871 } // namespace Opm
872 
873 #endif
OPM_HOST_DEVICE void setSolventInvB(const ValueType &newSolventInvB)
Set the solvent inverse formation volume factor [-].
Definition: BlackOilFluidState.hpp:432
OPM_HOST_DEVICE void setDensity(unsigned phaseIdx, const ValueType &rho)
\ brief Set the density of a fluid phase
Definition: BlackOilFluidState.hpp:370
OPM_HOST_DEVICE const ValueType & invB(unsigned phaseIdx) const
Return the inverse formation volume factor of a fluid phase [-].
Definition: BlackOilFluidState.hpp:479
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:622
OPM_HOST_DEVICE void setEnthalpy(unsigned phaseIdx, const ValueType &value)
Set the specific enthalpy [J/kg] of a given fluid phase.
Definition: BlackOilFluidState.hpp:354
OPM_HOST_DEVICE ValueType viscosity(unsigned phaseIdx) const
Return the dynamic viscosity of a fluid phase [Pa s].
Definition: BlackOilFluidState.hpp:685
OPM_HOST_DEVICE ValueType Rs() const
Return the gas dissolution factor of oil [m^3/m^3].
Definition: BlackOilFluidState.hpp:489
OPM_HOST_DEVICE void setRv(const ValueType &newRv)
Set the oil vaporization factor [m^3/m^3] of the gas phase.
Definition: BlackOilFluidState.hpp:386
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:464
OPM_HOST_DEVICE void setSolventSaturation(const ValueType &newSolventSaturation)
Set the solvent saturation.
Definition: BlackOilFluidState.hpp:420
OPM_HOST_DEVICE void setSaltConcentration(const ValueType &newSaltConcentration)
Set the salt concentration.
Definition: BlackOilFluidState.hpp:408
OPM_HOST_DEVICE void setRvw(const ValueType &newRvw)
Set the water vaporization factor [m^3/m^3] of the gas phase.
Definition: BlackOilFluidState.hpp:394
OPM_HOST_DEVICE void setSaltSaturation(const ValueType &newSaltSaturation)
Set the solid salt saturation.
Definition: BlackOilFluidState.hpp:414
#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:195
OPM_HOST_DEVICE void setTemperature(const ValueType &value)
Set the temperature [K].
Definition: BlackOilFluidState.hpp:341
OPM_HOST_DEVICE ValueType Rvw() const
Return the water vaporization factor of gas [m^3/m^3].
Definition: BlackOilFluidState.hpp:521
OPM_HOST_DEVICE ValueType Rv() const
Return the oil vaporization factor of gas [m^3/m^3].
Definition: BlackOilFluidState.hpp:505
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:691
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:769
OPM_HOST_DEVICE const ValueType & pressure(unsigned phaseIdx) const
Return the pressure of a fluid phase [Pa].
Definition: BlackOilFluidState.hpp:444
OPM_HOST_DEVICE BlackOilFluidState(const FluidSystem &fluidSystem)
Construct a fluid state object.
Definition: BlackOilFluidState.hpp:163
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:573
OPM_HOST_DEVICE const ValueType & totalSaturation() const
Return the total saturation needed for sequential.
Definition: BlackOilFluidState.hpp:456
OPM_HOST_DEVICE ValueType density(unsigned phaseIdx) const
Return the density [kg/m^3] of a given fluid phase.
Definition: BlackOilFluidState.hpp:628
OPM_HOST_DEVICE ValueType averageMolarMass(unsigned phaseIdx) const
Return the partial molar density of a fluid phase [kg / mol].
Definition: BlackOilFluidState.hpp:775
bool phaseIsActive(int phaseIdx) const
Return if a phase is active (via the FluidSystem).
Definition: BlackOilFluidState.hpp:807
OPM_HOST_DEVICE ValueType saltSaturation() const
Return the saturation of solid salt.
Definition: BlackOilFluidState.hpp:561
OPM_HOST_DEVICE const FluidSystem & fluidSystem() const
Return the fluid system used by this fluid state.
Definition: BlackOilFluidState.hpp:819
OPM_HOST_DEVICE ValueType Rsw() const
Return the gas dissolution factor of water [m^3/m^3].
Definition: BlackOilFluidState.hpp:537
OPM_HOST_DEVICE void setPvtRegionIndex(unsigned newPvtRegionIdx)
Set the index of the fluid region.
Definition: BlackOilFluidState.hpp:312
OPM_HOST_DEVICE void setRsSolw(const ValueType &newRsSolw)
Set the solvent dissolution factor in water [m^3/m^3].
Definition: BlackOilFluidState.hpp:438
OPM_HOST_DEVICE const ValueType & enthalpy(unsigned phaseIdx) const
Return the specific enthalpy [J/kg] of a given fluid phase.
Definition: BlackOilFluidState.hpp:637
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:261
OPM_HOST_DEVICE const ValueType & saturation(unsigned phaseIdx) const
Return the saturation of a fluid phase [-].
Definition: BlackOilFluidState.hpp:450
OPM_HOST_DEVICE ValueType saltConcentration() const
Return the concentration of salt in water.
Definition: BlackOilFluidState.hpp:549
OPM_HOST_DEVICE ValueType internalEnergy(unsigned phaseIdx) const
Return the specific internal energy [J/kg] of a given fluid phase.
Definition: BlackOilFluidState.hpp:646
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:728
OPM_HOST_DEVICE ValueType molarDensity(unsigned phaseIdx) const
Return the molar density of a fluid phase [mol/m^3].
Definition: BlackOilFluidState.hpp:661
OPM_HOST_DEVICE void setInvB(unsigned phaseIdx, const ValueType &b)
\ brief Set the inverse formation volume factor of a fluid phase
Definition: BlackOilFluidState.hpp:364
OPM_HOST_DEVICE void setSaturation(unsigned phaseIdx, const ValueType &S)
Set the saturation of a fluid phase [-].
Definition: BlackOilFluidState.hpp:324
OPM_HOST_DEVICE void setPressure(unsigned phaseIdx, const ValueType &p)
Set the pressure of a fluid phase [-].
Definition: BlackOilFluidState.hpp:318
OPM_HOST_DEVICE void setSolventDensity(const ValueType &newSolventDensity)
Set the solvent density [kg/m^3].
Definition: BlackOilFluidState.hpp:426
OPM_HOST_DEVICE void setRs(const ValueType &newRs)
Set the gas dissolution factor [m^3/m^3] of the oil phase.
Definition: BlackOilFluidState.hpp:378
OPM_HOST_DEVICE void setTotalSaturation(const ValueType &value)
Set the total saturation used for sequential methods.
Definition: BlackOilFluidState.hpp:330
void checkDefined() const
Make sure that all attributes are defined.
Definition: BlackOilFluidState.hpp:208
OPM_HOST_DEVICE ValueType fugacity(unsigned phaseIdx, unsigned compIdx) const
Return the fugacity of a component in a fluid phase [Pa].
Definition: BlackOilFluidState.hpp:792
OPM_HOST_DEVICE void setRsw(const ValueType &newRsw)
Set the gas dissolution factor [m^3/m^3] of the water phase.
Definition: BlackOilFluidState.hpp:402
OPM_HOST_DEVICE ValueType rsSolw() const
Return the solvent dissolution factor in water [m^3/m^3].
Definition: BlackOilFluidState.hpp:609
OPM_HOST_DEVICE ValueType molarVolume(unsigned phaseIdx) const
Return the molar volume of a fluid phase [m^3/mol].
Definition: BlackOilFluidState.hpp:679
OPM_HOST_DEVICE ValueType solventDensity() const
Return the solvent density [kg/m^3].
Definition: BlackOilFluidState.hpp:585
OPM_HOST_DEVICE ValueType solventInvB() const
Return the solvent inverse formation volume factor [-].
Definition: BlackOilFluidState.hpp:597
OPM_HOST_DEVICE ValueType fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
Return the fugacity coefficient of a component in a fluid phase [-].
Definition: BlackOilFluidState.hpp:786