phaseUsageFromDeck.hpp
Go to the documentation of this file.
1
2/*
3 Copyright 2012 SINTEF ICT, Applied Mathematics.
4
5 This file is part of the Open Porous Media project (OPM).
6
7 OPM is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 OPM is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with OPM. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#ifndef OPM_PHASEUSAGEFROMDECK_HEADER_INCLUDED
22#define OPM_PHASEUSAGEFROMDECK_HEADER_INCLUDED
23
25#include <opm/common/ErrorMacros.hpp>
26
27#include <opm/parser/eclipse/Deck/Deck.hpp>
28#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
29#include <opm/parser/eclipse/EclipseState/Runspec.hpp>
30
31
32namespace Opm
33{
34
37 inline PhaseUsage phaseUsageFromDeck(const Opm::EclipseState& eclipseState)
38 {
39 PhaseUsage pu;
41
42 const auto& phase = eclipseState.runspec().phases();
43 // Discover phase usage.
47
48 pu.num_phases = 0;
49 int numActivePhases = 0;
50 for (int phaseIdx = 0; phaseIdx < BlackoilPhases::MaxNumPhases; ++phaseIdx) {
51 if (!pu.phase_used[phaseIdx]) {
52 pu.phase_pos[phaseIdx] = -1;
53 }
54 else {
55 pu.phase_pos[phaseIdx] = numActivePhases;
56 ++ numActivePhases;
57 pu.num_phases = numActivePhases;
58 }
59 }
60
61 // Only 2 or 3 phase systems handled.
62 if (pu.num_phases < 2 || pu.num_phases > 3) {
63 OPM_THROW(std::runtime_error, "Cannot handle cases with " << pu.num_phases << " phases.");
64 }
65
66 // We need oil systems, since we do not support the keywords needed for
67 // water-gas systems.
69 OPM_THROW(std::runtime_error, "Cannot handle cases with no OIL, i.e. water-gas systems.");
70 }
71
72 // Add solvent info
73 pu.has_solvent = phase.active(Phase::SOLVENT);
74 if (pu.has_solvent) {
75 // this is quite a hack: even though solvent is not considered as in
76 // MaxNumPhases and pu.num_phases because this would break a lot of
77 // assumptions in old code, it is nevertheless an index to be translated
78 // to. solvent and solvent are even larger hacks because not even this can be
79 // done for them.
80 pu.phase_pos[BlackoilPhases::Solvent] = numActivePhases;
81 ++ numActivePhases;
82 }
83 else
85
86 // Add polymer info
87 pu.has_polymer = phase.active(Phase::POLYMER);
88 if (pu.has_polymer) {
89 // this is quite a hack: even though polymer is not considered as in
90 // MaxNumPhases and pu.num_phases because this would break a lot of
91 // assumptions in old code, it is nevertheless an index to be translated
92 // to. polymer and solvent are even larger hacks because not even this can be
93 // done for them.
94 pu.phase_pos[BlackoilPhases::Polymer] = numActivePhases;
95 ++ numActivePhases;
96 }
97 else
99
100 // Add energy info
101 pu.has_energy = phase.active(Phase::ENERGY);
102 if (pu.has_energy) {
103 // this is quite a hack: even though energy is not considered as in
104 // MaxNumPhases and pu.num_phases because this would break a lot of
105 // assumptions in old code, it is nevertheless an index to be translated
106 // to. polymer and solvent are even larger hacks because not even this can be
107 // done for them.
108 pu.phase_pos[BlackoilPhases::Energy] = numActivePhases;
109 ++ numActivePhases;
110 }
111 else
113
114 return pu;
115 }
116
119 inline PhaseUsage phaseUsageFromDeck(const Opm::Deck& deck)
120 {
121 PhaseUsage pu;
123
124 Runspec runspec( deck );
125 const auto& phase = runspec.phases();
126
127 // Discover phase usage.
128 pu.phase_used[BlackoilPhases::Aqua] = phase.active(Phase::WATER);
129 pu.phase_used[BlackoilPhases::Liquid] = phase.active(Phase::OIL);
130 pu.phase_used[BlackoilPhases::Vapour] = phase.active(Phase::GAS);
131
132 pu.num_phases = 0;
133 int numActivePhases = 0;
134 for (int phaseIdx = 0; phaseIdx < BlackoilPhases::MaxNumPhases; ++phaseIdx) {
135 if (!pu.phase_used[phaseIdx]) {
136 pu.phase_pos[phaseIdx] = -1;
137 }
138 else {
139 pu.phase_pos[phaseIdx] = numActivePhases;
140 ++ numActivePhases;
141 pu.num_phases = numActivePhases;
142 }
143 }
144
145 // Only 2 or 3 phase systems handled.
146 if (pu.num_phases < 2 || pu.num_phases > 3) {
147 OPM_THROW(std::runtime_error, "Cannot handle cases with " << pu.num_phases << " phases.");
148 }
149
150 // We need oil systems, since we do not support the keywords needed for
151 // water-gas systems.
153 OPM_THROW(std::runtime_error, "Cannot handle cases with no OIL, i.e. water-gas systems.");
154 }
155
156 // Add solvent info
157 pu.has_solvent = phase.active(Phase::SOLVENT);
158 if (pu.has_solvent) {
159 // this is quite a hack: even though solvent is not considered as in
160 // MaxNumPhases and pu.num_phases because this would break a lot of
161 // assumptions in old code, it is nevertheless an index to be translated
162 // to. solvent and solvent are even larger hacks because not even this can be
163 // done for them.
164 pu.phase_pos[BlackoilPhases::Solvent] = numActivePhases;
165 ++ numActivePhases;
166 }
167 else
169
170 // Add polymer info
171 pu.has_polymer = phase.active(Phase::POLYMER);
172 if (pu.has_polymer) {
173 // this is quite a hack: even though polymer is not considered as in
174 // MaxNumPhases and pu.num_phases because this would break a lot of
175 // assumptions in old code, it is nevertheless an index to be translated
176 // to. polymer and solvent are even larger hacks because not even this can be
177 // done for them.
178 pu.phase_pos[BlackoilPhases::Polymer] = numActivePhases;
179 ++ numActivePhases;
180 }
181 else
183
184 // Add energy info
185 pu.has_energy = phase.active(Phase::ENERGY);
186 if (pu.has_energy) {
187 // this is quite a hack: even though energy is not considered as in
188 // MaxNumPhases and pu.num_phases because this would break a lot of
189 // assumptions in old code, it is nevertheless an index to be translated
190 // to. polymer and solvent are even larger hacks because not even this can be
191 // done for them.
192 pu.phase_pos[BlackoilPhases::Energy] = numActivePhases;
193 ++ numActivePhases;
194 }
195 else
197
198 return pu;
199 }
200
201}
202
203#endif // OPM_PHASEUSAGEFROMDECK_HEADER_INCLUDED
static const int MaxNumPhases
Definition: BlackoilPhases.hpp:30
static const int NumCryptoPhases
Definition: BlackoilPhases.hpp:37
@ Liquid
Definition: BlackoilPhases.hpp:40
@ Aqua
Definition: BlackoilPhases.hpp:40
@ Vapour
Definition: BlackoilPhases.hpp:40
@ Energy
Definition: BlackoilPhases.hpp:40
@ Solvent
Definition: BlackoilPhases.hpp:40
@ Polymer
Definition: BlackoilPhases.hpp:40
@ OIL
Definition: legacy_well.h:47
@ GAS
Definition: legacy_well.h:47
@ WATER
Definition: legacy_well.h:47
Definition: AnisotropicEikonal.hpp:44
PhaseUsage phaseUsageFromDeck(const Opm::EclipseState &eclipseState)
Definition: phaseUsageFromDeck.hpp:37
Definition: BlackoilPhases.hpp:44
bool has_polymer
Definition: BlackoilPhases.hpp:49
bool has_energy
Definition: BlackoilPhases.hpp:50
int phase_pos[MaxNumPhases+NumCryptoPhases]
Definition: BlackoilPhases.hpp:47
int phase_used[MaxNumPhases+NumCryptoPhases]
Definition: BlackoilPhases.hpp:46
bool has_solvent
Definition: BlackoilPhases.hpp:48
int num_phases
Definition: BlackoilPhases.hpp:45