diff --git a/opm/core/newwells.h b/opm/core/newwells.h index 710df7c73..f16675b6c 100644 --- a/opm/core/newwells.h +++ b/opm/core/newwells.h @@ -100,6 +100,7 @@ struct Wells double *WI; /** Well productivity index, same size and structure as well_cells. */ struct WellControls **ctrls; /** Well controls, one set of controls for each well. */ + char **name; /** Well names. One string for each well. */ void *data; /** Internal management structure. */ }; @@ -168,6 +169,7 @@ create_wells(int nphases, int nwells, int nperf); * \param[in] cells Grid cells in which well is perforated. Should * ideally be track ordered. * \param[in] WI Well production index per perforation, or NULL. + * \param[in] name Name of new well. NULL if no name. * \param[in,out] W Existing set of wells to which new well will * be added. * @@ -180,6 +182,7 @@ add_well(enum WellType type , const double *comp_frac, const int *cells , const double *WI , + const char *name , struct Wells *W ); diff --git a/opm/core/simulator/SimulatorReport.cpp b/opm/core/simulator/SimulatorReport.cpp index 3d8e0c048..1fa264597 100644 --- a/opm/core/simulator/SimulatorReport.cpp +++ b/opm/core/simulator/SimulatorReport.cpp @@ -40,7 +40,7 @@ namespace Opm { os << "Total time taken: " << total_time << "\n Pressure time: " << pressure_time - << "\n Transport time: " << total_time << std::endl; + << "\n Transport time: " << transport_time << std::endl; } diff --git a/opm/core/wells/WellsGroup.cpp b/opm/core/wells/WellsGroup.cpp index 3da16f776..afa17f12d 100644 --- a/opm/core/wells/WellsGroup.cpp +++ b/opm/core/wells/WellsGroup.cpp @@ -737,7 +737,9 @@ namespace Opm void WellNode::shutWell() { if (shut_well_) { - set_current_control(self_index_, -1, wells_); + // We set the tilde of the current control + // set_current_control(self_index_, -1, wells_); + wells_->ctrls[self_index_]->current = ~ wells_->ctrls[self_index_]->current; } else { const double target = 0.0; @@ -755,7 +757,7 @@ namespace Opm wells_->ctrls[self_index_]->target[group_control_index_] = target; std::copy(distr, distr + np, wells_->ctrls[self_index_]->distr + np * group_control_index_); } - set_current_control(self_index_, -1, wells_); + wells_->ctrls[self_index_]->current = ~ wells_->ctrls[self_index_]->current; } } diff --git a/opm/core/wells/WellsManager.cpp b/opm/core/wells/WellsManager.cpp index 985df5f81..0215b053e 100644 --- a/opm/core/wells/WellsManager.cpp +++ b/opm/core/wells/WellsManager.cpp @@ -28,7 +28,13 @@ #include #include +#include +#include #include +#include +#include +#include +#include // Helper structs and functions for the implementation. @@ -56,25 +62,41 @@ namespace { enum Mode { ORAT, WRAT, GRAT, LRAT, CRAT, RESV, - BHP, THP, GRUP }; + BHP , THP , GRUP }; + + namespace Details { + std::map + init_mode_map() { + std::map m; + + m.insert(std::make_pair("ORAT", ORAT)); + m.insert(std::make_pair("WRAT", WRAT)); + m.insert(std::make_pair("GRAT", GRAT)); + m.insert(std::make_pair("LRAT", LRAT)); + m.insert(std::make_pair("CRAT", CRAT)); + m.insert(std::make_pair("RESV", RESV)); + m.insert(std::make_pair("BHP" , BHP )); + m.insert(std::make_pair("THP" , THP )); + m.insert(std::make_pair("GRUP", GRUP)); + + return m; + } + } // namespace Details + Mode mode(const std::string& control) { - const int num_prod_control_modes = 9; - static std::string prod_control_modes[num_prod_control_modes] = - {std::string("ORAT"), std::string("WRAT"), std::string("GRAT"), - std::string("LRAT"), std::string("CRAT"), std::string("RESV"), - std::string("BHP"), std::string("THP"), std::string("GRUP") }; - int m = -1; - for (int i=0; i + mode_map = Details::init_mode_map(); + + std::map::iterator + p = mode_map.find(control); + + if (p != mode_map.end()) { + return p->second; } - if (m >= 0) { - return static_cast(m); - } else { - THROW("Unknown well control mode = " << control << " in input file"); + else { + THROW("Unknown well control mode = " + << control << " in input file"); } } } // namespace ProductionControl @@ -84,24 +106,36 @@ namespace { enum Mode { RATE, RESV, BHP, THP, GRUP }; + + namespace Details { + std::map + init_mode_map() { + std::map m; + + m.insert(std::make_pair("RATE", RATE)); + m.insert(std::make_pair("RESV", RESV)); + m.insert(std::make_pair("BHP" , BHP )); + m.insert(std::make_pair("THP" , THP )); + m.insert(std::make_pair("GRUP", GRUP)); + + return m; + } + } // namespace Details + Mode mode(const std::string& control) { - const int num_inje_control_modes = 5; - static std::string inje_control_modes[num_inje_control_modes] = - {std::string("RATE"), std::string("RESV"), std::string("BHP"), - std::string("THP"), std::string("GRUP") }; - int m = -1; - for (int i=0; i + mode_map = Details::init_mode_map(); - if (m >= 0) { - return static_cast(m); - } else { - THROW("Unknown well control mode = " << control << " in input file"); + std::map::iterator + p = mode_map.find(control); + + if (p != mode_map.end()) { + return p->second; + } + else { + THROW("Unknown well control mode = " + << control << " in input file"); } } } // namespace InjectionControl @@ -408,10 +442,10 @@ namespace Opm } else { THROW("Unseen well name: " << lines[i].well_ << " first seen in WCONPROD"); } - + } } - + // Add wells. for (int w = 0; w < num_wells; ++w) { const int w_num_perf = wellperf_data[w].size(); @@ -425,7 +459,7 @@ namespace Opm // We initialize all wells with a null component fraction, // and must (for injection wells) overwrite it later. int ok = add_well(well_data[w].type, well_data[w].reference_bhp_depth, w_num_perf, - comp_frac, &perf_cells[0], &perf_prodind[0], w_); + comp_frac, &perf_cells[0], &perf_prodind[0], well_names[w].c_str(), w_); if (!ok) { THROW("Failed adding well " << well_names[w] << " to Wells data structure."); } @@ -486,10 +520,14 @@ namespace Opm THROW("Failure occured appending controls for well " << well_names[wix]); } InjectionControl::Mode mode = InjectionControl::mode(wci_line.control_mode_); - const int cpos = control_pos[mode]; + int cpos = control_pos[mode]; if (cpos == -1 && mode != InjectionControl::GRUP) { THROW("Control for " << wci_line.control_mode_ << " not specified in well " << well_names[wix]); } + // We need to check if the well is shut or not + if (wci_line.open_shut_flag_ == "SHUT") { + cpos = ~cpos; + } set_current_control(wix, cpos, w_); // Set well component fraction. @@ -610,10 +648,14 @@ namespace Opm THROW("Failure occured appending controls for well " << well_names[wix]); } ProductionControl::Mode mode = ProductionControl::mode(wcp_line.control_mode_); - const int cpos = control_pos[mode]; + int cpos = control_pos[mode]; if (cpos == -1 && mode != ProductionControl::GRUP) { THROW("Control mode type " << mode << " not present in well " << well_names[wix]); } + // If it's shut, we complement the cpos + if (wcp_line.open_shut_flag_ == "SHUT") { + cpos = ~cpos; // So we can easily retrieve the cpos later + } set_current_control(wix, cpos, w_); } } @@ -673,6 +715,34 @@ namespace Opm */ #endif + if (deck.hasField("WELOPEN")) { + const WELOPEN& welopen = deck.getWELOPEN(); + + for (size_t i = 0; i < welopen.welopen.size(); ++i) { + WelopenLine line = welopen.welopen[i]; + std::string wellname = line.well_; + std::map::const_iterator it = well_names_to_index.find(wellname); + if (it == well_names_to_index.end()) { + THROW("Trying to open/shut well with name: \"" << wellname<<"\" but it's not registered under WELSPECS."); + } + int index = it->second; + if (line.openshutflag_ == "SHUT") { + // We currently don't care if the well is open or not. + /// \TODO Should this perhaps be allowed? I.e. should it be if(well_shut) { shutwell(); } else { /* do nothing*/ }? + //ASSERT(w_->ctrls[index]->current < 0); + } else if (line.openshutflag_ == "OPEN") { + //ASSERT(w_->ctrls[index]->current >= 0); + } else { + THROW("Unknown Open/close keyword: \"" << line.openshutflag_<< "\". Allowed values: OPEN, SHUT."); + } + + // We revert back to it's original control. + // Note that this is OK as ~~ = id. + w_->ctrls[index]->current = ~w_->ctrls[index]->current; + + + } + } // Build the well_collection_ well group hierarchy. if (deck.hasField("GRUPTREE")) {