All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
initHydroCarbonState.hpp
1 #ifndef INITHYDROCARBONSTATE_HPP
2 #define INITHYDROCARBONSTATE_HPP
3 
4 #include "opm/core/simulator/BlackoilState.hpp"
5 
6 namespace Opm
7 {
8 
9 inline void initHydroCarbonState(BlackoilState& state, const PhaseUsage& pu, const int num_cells, const bool has_disgas, const bool has_vapoil) {
10  enum { Oil = BlackoilPhases::Liquid, Gas = BlackoilPhases::Vapour, Water = BlackoilPhases::Aqua };
11  // hydrocarbonstate is only used when gas and oil is present
12  assert(pu.phase_used[Oil]);
13  std::vector<HydroCarbonState>& hydroCarbonState = state.hydroCarbonState();
14  hydroCarbonState.resize(num_cells);
15  if (!pu.phase_used[Gas]) {
16  // hydroCarbonState should only be used when oil and gas is present. Return OilOnly to avoid potential trouble.
17  std::fill(hydroCarbonState.begin(), hydroCarbonState.end(), HydroCarbonState::OilOnly);
18  return;
19  }
20  const int np = pu.num_phases;
21  std::fill(hydroCarbonState.begin(), hydroCarbonState.end(), HydroCarbonState::GasAndOil);
22 
23  // set hydrocarbon state
24  const double epsilon = std::sqrt(std::numeric_limits<double>::epsilon());
25  const std::vector<double>& saturation = state.saturation();
26  for (int c = 0; c < num_cells; ++c) {
27  if (pu.phase_used[Water]) {
28  if ( saturation[c*np + pu.phase_pos[ Water ]] > (1.0 - epsilon)) {
29  continue; // cases (almost) filled with water is treated as GasAndOil case;
30  }
31  }
32  if ( saturation[c*np + pu.phase_pos[ Gas ]] == 0.0 && has_disgas) {
33  hydroCarbonState[c] = HydroCarbonState::OilOnly;
34  continue;
35  }
36  if ( saturation[c*np + pu.phase_pos[ Oil ]] == 0.0 && has_vapoil) {
37  hydroCarbonState[c] = HydroCarbonState::GasOnly;
38  }
39  }
40 }
41 
42 
43 } // namespace Opm
44 #endif // INITHYDROCARBONSTATE_HPP