00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef OPM_SIM_FIBO_DETAILS_HPP
00022 #define OPM_SIM_FIBO_DETAILS_HPP
00023
00024 #include <utility>
00025 #include <algorithm>
00026 #include <locale>
00027 #include <opm/parser/eclipse/EclipseState/Schedule/Events.hpp>
00028 #include <opm/core/utility/initHydroCarbonState.hpp>
00029 #include <opm/core/well_controls.h>
00030 #include <opm/core/wells/DynamicListEconLimited.hpp>
00031
00032 namespace Opm
00033 {
00034 namespace SimFIBODetails {
00035 typedef std::unordered_map<std::string, const Well* > WellMap;
00036
00037 inline WellMap
00038 mapWells(const std::vector< const Well* >& wells)
00039 {
00040 WellMap wmap;
00041
00042 for (std::vector< const Well* >::const_iterator
00043 w = wells.begin(), e = wells.end();
00044 w != e; ++w)
00045 {
00046 wmap.insert(std::make_pair((*w)->name(), *w));
00047 }
00048
00049 return wmap;
00050 }
00051
00052 inline int
00053 resv_control(const WellControls* ctrl)
00054 {
00055 int i, n = well_controls_get_num(ctrl);
00056
00057 bool match = false;
00058 for (i = 0; (! match) && (i < n); ++i) {
00059 match = well_controls_iget_type(ctrl, i) == RESERVOIR_RATE;
00060 }
00061
00062 if (! match) { i = 0; }
00063
00064 return i - 1;
00065 }
00066
00067 inline bool
00068 is_resv(const Wells& wells,
00069 const int w)
00070 {
00071 return (0 <= resv_control(wells.ctrls[w]));
00072 }
00073
00074 inline bool
00075 is_resv(const WellMap& wmap,
00076 const std::string& name,
00077 const std::size_t step)
00078 {
00079 bool match = false;
00080
00081 WellMap::const_iterator i = wmap.find(name);
00082
00083 if (i != wmap.end()) {
00084 const Well* wp = i->second;
00085
00086 match = (wp->isProducer(step) &&
00087 wp->getProductionProperties(step)
00088 .hasProductionControl(WellProducer::RESV))
00089 || (wp->isInjector(step) &&
00090 wp->getInjectionProperties(step)
00091 .hasInjectionControl(WellInjector::RESV));
00092 }
00093
00094 return match;
00095 }
00096
00097 inline std::vector<int>
00098 resvWells(const Wells* wells,
00099 const std::size_t step,
00100 const WellMap& wmap)
00101 {
00102 std::vector<int> resv_wells;
00103 if( wells )
00104 {
00105 for (int w = 0, nw = wells->number_of_wells; w < nw; ++w) {
00106 if (is_resv(*wells, w) ||
00107 ((wells->name[w] != 0) &&
00108 is_resv(wmap, wells->name[w], step)))
00109 {
00110 resv_wells.push_back(w);
00111 }
00112 }
00113 }
00114
00115 return resv_wells;
00116 }
00117
00118 inline void
00119 historyRates(const PhaseUsage& pu,
00120 const WellProductionProperties& p,
00121 std::vector<double>& rates)
00122 {
00123 assert (! p.predictionMode);
00124 assert (rates.size() ==
00125 std::vector<double>::size_type(pu.num_phases));
00126
00127 if (pu.phase_used[ BlackoilPhases::Aqua ]) {
00128 const std::vector<double>::size_type
00129 i = pu.phase_pos[ BlackoilPhases::Aqua ];
00130
00131 rates[i] = p.WaterRate;
00132 }
00133
00134 if (pu.phase_used[ BlackoilPhases::Liquid ]) {
00135 const std::vector<double>::size_type
00136 i = pu.phase_pos[ BlackoilPhases::Liquid ];
00137
00138 rates[i] = p.OilRate;
00139 }
00140
00141 if (pu.phase_used[ BlackoilPhases::Vapour ]) {
00142 const std::vector<double>::size_type
00143 i = pu.phase_pos[ BlackoilPhases::Vapour ];
00144
00145 rates[i] = p.GasRate;
00146 }
00147 }
00148 }
00149 }
00150
00151 #endif // OPM_SIM_FIBO_DETAILS_HPP