void restoreOPM_XWELKeyword(const std::string& restart_filename, int reportstep, bool unified, WellState& wellstate) { const char * keyword = "OPM_XWEL"; const char* filename = restart_filename.c_str(); ecl_file_type* file_type = ecl_file_open(filename, 0); if (file_type != NULL) { bool block_selected = unified ? ecl_file_select_rstblock_report_step(file_type , reportstep) : true; if (block_selected) { ecl_kw_type* xwel = ecl_file_iget_named_kw(file_type , keyword, 0); const double* xwel_data = ecl_kw_get_double_ptr(xwel); std::copy_n(xwel_data + wellstate.getRestartTemperatureOffset(), wellstate.temperature().size(), wellstate.temperature().begin()); std::copy_n(xwel_data + wellstate.getRestartBhpOffset(), wellstate.bhp().size(), wellstate.bhp().begin()); std::copy_n(xwel_data + wellstate.getRestartPerfPressOffset(), wellstate.perfPress().size(), wellstate.perfPress().begin()); std::copy_n(xwel_data + wellstate.getRestartPerfRatesOffset(), wellstate.perfRates().size(), wellstate.perfRates().begin()); std::copy_n(xwel_data + wellstate.getRestartWellRatesOffset(), wellstate.wellRates().size(), wellstate.wellRates().begin()); } else { std::string error_str = "Restart file " + restart_filename + " does not contain data for report step " + std::to_string(reportstep) + "!\n"; throw std::runtime_error(error_str); } ecl_file_close(file_type); } else { std::string error_str = "Restart file " + restart_filename + " not found!\n"; throw std::runtime_error(error_str); } }
void SimulatorBase<Implementation>::computeRESV(const std::size_t step, const Wells* wells, const BlackoilState& x, WellState& xw) { typedef SimFIBODetails::WellMap WellMap; const std::vector<WellConstPtr>& w_ecl = eclipse_state_->getSchedule()->getWells(step); const WellMap& wmap = SimFIBODetails::mapWells(w_ecl); const std::vector<int>& resv_wells = SimFIBODetails::resvWells(wells, step, wmap); if (! resv_wells.empty()) { const PhaseUsage& pu = props_.phaseUsage(); const std::vector<double>::size_type np = props_.numPhases(); rateConverter_.defineState(x); std::vector<double> distr (np); std::vector<double> hrates(np); std::vector<double> prates(np); for (std::vector<int>::const_iterator rp = resv_wells.begin(), e = resv_wells.end(); rp != e; ++rp) { WellControls* ctrl = wells->ctrls[*rp]; const bool is_producer = wells->type[*rp] == PRODUCER; // RESV control mode, all wells { const int rctrl = SimFIBODetails::resv_control(ctrl); if (0 <= rctrl) { const std::vector<double>::size_type off = (*rp) * np; if (is_producer) { // Convert to positive rates to avoid issues // in coefficient calculations. std::transform(xw.wellRates().begin() + (off + 0*np), xw.wellRates().begin() + (off + 1*np), prates.begin(), std::negate<double>()); } else { std::copy(xw.wellRates().begin() + (off + 0*np), xw.wellRates().begin() + (off + 1*np), prates.begin()); } const int fipreg = 0; // Hack. Ignore FIP regions. rateConverter_.calcCoeff(prates, fipreg, distr); well_controls_iset_distr(ctrl, rctrl, & distr[0]); } } // RESV control, WCONHIST wells. A bit of duplicate // work, regrettably. if (is_producer && wells->name[*rp] != 0) { WellMap::const_iterator i = wmap.find(wells->name[*rp]); if (i != wmap.end()) { WellConstPtr wp = i->second; const WellProductionProperties& p = wp->getProductionProperties(step); if (! p.predictionMode) { // History matching (WCONHIST/RESV) SimFIBODetails::historyRates(pu, p, hrates); const int fipreg = 0; // Hack. Ignore FIP regions. rateConverter_.calcCoeff(hrates, fipreg, distr); // WCONHIST/RESV target is sum of all // observed phase rates translated to // reservoir conditions. Recall sign // convention: Negative for producers. const double target = - std::inner_product(distr.begin(), distr.end(), hrates.begin(), 0.0); well_controls_clear(ctrl); well_controls_assert_number_of_phases(ctrl, int(np)); const int ok_resv = well_controls_add_new(RESERVOIR_RATE, target, & distr[0], ctrl); // For WCONHIST/RESV the BHP limit is set to 1 atm. // TODO: Make it possible to modify the BHP limit using // the WELTARG keyword const int ok_bhp = well_controls_add_new(BHP, unit::convert::from(1.0, unit::atm), NULL, ctrl); if (ok_resv != 0 && ok_bhp != 0) { xw.currentControls()[*rp] = 0; well_controls_set_current(ctrl, 0); } } } } } } }
void SimulatorBase<Implementation>::computeRESV(const std::size_t step, const Wells* wells, const BlackoilState& x, WellState& xw) { typedef SimFIBODetails::WellMap WellMap; const std::vector<WellConstPtr>& w_ecl = eclipse_state_->getSchedule()->getWells(step); const WellMap& wmap = SimFIBODetails::mapWells(w_ecl); const std::vector<int>& resv_wells = SimFIBODetails::resvWells(wells, step, wmap); const std::size_t number_resv_wells = resv_wells.size(); std::size_t global_number_resv_wells = number_resv_wells; #if HAVE_MPI if ( solver_.parallelInformation().type() == typeid(ParallelISTLInformation) ) { const auto& info = boost::any_cast<const ParallelISTLInformation&>(solver_.parallelInformation()); global_number_resv_wells = info.communicator().sum(global_number_resv_wells); if ( global_number_resv_wells ) { // At least one process has resv wells. Therefore rate converter needs // to calculate averages over regions that might cross process // borders. This needs to be done by all processes and therefore // outside of the next if statement. rateConverter_.defineState(x, boost::any_cast<const ParallelISTLInformation&>(solver_.parallelInformation())); } } else #endif { if ( global_number_resv_wells ) { rateConverter_.defineState(x); } } if (! resv_wells.empty()) { const PhaseUsage& pu = props_.phaseUsage(); const std::vector<double>::size_type np = props_.numPhases(); std::vector<double> distr (np); std::vector<double> hrates(np); std::vector<double> prates(np); for (std::vector<int>::const_iterator rp = resv_wells.begin(), e = resv_wells.end(); rp != e; ++rp) { WellControls* ctrl = wells->ctrls[*rp]; const bool is_producer = wells->type[*rp] == PRODUCER; // RESV control mode, all wells { const int rctrl = SimFIBODetails::resv_control(ctrl); if (0 <= rctrl) { const std::vector<double>::size_type off = (*rp) * np; if (is_producer) { // Convert to positive rates to avoid issues // in coefficient calculations. std::transform(xw.wellRates().begin() + (off + 0*np), xw.wellRates().begin() + (off + 1*np), prates.begin(), std::negate<double>()); } else { std::copy(xw.wellRates().begin() + (off + 0*np), xw.wellRates().begin() + (off + 1*np), prates.begin()); } const int fipreg = 0; // Hack. Ignore FIP regions. rateConverter_.calcCoeff(prates, fipreg, distr); well_controls_iset_distr(ctrl, rctrl, & distr[0]); } } // RESV control, WCONHIST wells. A bit of duplicate // work, regrettably. if (is_producer && wells->name[*rp] != 0) { WellMap::const_iterator i = wmap.find(wells->name[*rp]); if (i != wmap.end()) { WellConstPtr wp = i->second; const WellProductionProperties& p = wp->getProductionProperties(step); if (! p.predictionMode) { // History matching (WCONHIST/RESV) SimFIBODetails::historyRates(pu, p, hrates); const int fipreg = 0; // Hack. Ignore FIP regions. rateConverter_.calcCoeff(hrates, fipreg, distr); // WCONHIST/RESV target is sum of all // observed phase rates translated to // reservoir conditions. Recall sign // convention: Negative for producers. const double target = - std::inner_product(distr.begin(), distr.end(), hrates.begin(), 0.0); well_controls_clear(ctrl); well_controls_assert_number_of_phases(ctrl, int(np)); static const double invalid_alq = -std::numeric_limits<double>::max(); static const int invalid_vfp = -std::numeric_limits<int>::max(); const int ok_resv = well_controls_add_new(RESERVOIR_RATE, target, invalid_alq, invalid_vfp, & distr[0], ctrl); // For WCONHIST the BHP limit is set to 1 atm. // or a value specified using WELTARG double bhp_limit = (p.BHPLimit > 0) ? p.BHPLimit : unit::convert::from(1.0, unit::atm); const int ok_bhp = well_controls_add_new(BHP, bhp_limit, invalid_alq, invalid_vfp, NULL, ctrl); if (ok_resv != 0 && ok_bhp != 0) { xw.currentControls()[*rp] = 0; well_controls_set_current(ctrl, 0); } } } } } } if( wells ) { for (int w = 0, nw = wells->number_of_wells; w < nw; ++w) { WellControls* ctrl = wells->ctrls[w]; const bool is_producer = wells->type[w] == PRODUCER; if (!is_producer && wells->name[w] != 0) { WellMap::const_iterator i = wmap.find(wells->name[w]); if (i != wmap.end()) { WellConstPtr wp = i->second; const WellInjectionProperties& injector = wp->getInjectionProperties(step); if (!injector.predictionMode) { //History matching WCONINJEH static const double invalid_alq = -std::numeric_limits<double>::max(); static const int invalid_vfp = -std::numeric_limits<int>::max(); // For WCONINJEH the BHP limit is set to a large number // or a value specified using WELTARG double bhp_limit = (injector.BHPLimit > 0) ? injector.BHPLimit : std::numeric_limits<double>::max(); const int ok_bhp = well_controls_add_new(BHP, bhp_limit, invalid_alq, invalid_vfp, NULL, ctrl); if (!ok_bhp) { OPM_THROW(std::runtime_error, "Failed to add well control."); } } } } } } }