Merge from upstream

This commit is contained in:
Halvor M. Nilsen 2012-06-19 13:38:51 +02:00
commit ace7ebeed9
4 changed files with 114 additions and 39 deletions

View File

@ -100,6 +100,7 @@ struct Wells
double *WI; /** Well productivity index, same size and structure as well_cells. */ double *WI; /** Well productivity index, same size and structure as well_cells. */
struct WellControls **ctrls; /** Well controls, one set of controls for each well. */ 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. */ 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 * \param[in] cells Grid cells in which well is perforated. Should
* ideally be track ordered. * ideally be track ordered.
* \param[in] WI Well production index per perforation, or NULL. * \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 * \param[in,out] W Existing set of wells to which new well will
* be added. * be added.
* *
@ -180,6 +182,7 @@ add_well(enum WellType type ,
const double *comp_frac, const double *comp_frac,
const int *cells , const int *cells ,
const double *WI , const double *WI ,
const char *name ,
struct Wells *W ); struct Wells *W );

View File

@ -40,7 +40,7 @@ namespace Opm
{ {
os << "Total time taken: " << total_time os << "Total time taken: " << total_time
<< "\n Pressure time: " << pressure_time << "\n Pressure time: " << pressure_time
<< "\n Transport time: " << total_time << std::endl; << "\n Transport time: " << transport_time << std::endl;
} }

View File

@ -737,7 +737,9 @@ namespace Opm
void WellNode::shutWell() void WellNode::shutWell()
{ {
if (shut_well_) { 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 { else {
const double target = 0.0; const double target = 0.0;
@ -755,7 +757,7 @@ namespace Opm
wells_->ctrls[self_index_]->target[group_control_index_] = target; wells_->ctrls[self_index_]->target[group_control_index_] = target;
std::copy(distr, distr + np, wells_->ctrls[self_index_]->distr + np * group_control_index_); 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;
} }
} }

View File

@ -28,7 +28,13 @@
#include <opm/core/fluid/blackoil/phaseUsageFromDeck.hpp> #include <opm/core/fluid/blackoil/phaseUsageFromDeck.hpp>
#include <tr1/array> #include <tr1/array>
#include <algorithm>
#include <cassert>
#include <cmath> #include <cmath>
#include <cstddef>
#include <map>
#include <string>
#include <utility>
// Helper structs and functions for the implementation. // Helper structs and functions for the implementation.
@ -56,25 +62,41 @@ namespace
{ {
enum Mode { ORAT, WRAT, GRAT, enum Mode { ORAT, WRAT, GRAT,
LRAT, CRAT, RESV, LRAT, CRAT, RESV,
BHP, THP, GRUP }; BHP , THP , GRUP };
namespace Details {
std::map<std::string, Mode>
init_mode_map() {
std::map<std::string, Mode> 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) Mode mode(const std::string& control)
{ {
const int num_prod_control_modes = 9; static std::map<std::string, Mode>
static std::string prod_control_modes[num_prod_control_modes] = mode_map = Details::init_mode_map();
{std::string("ORAT"), std::string("WRAT"), std::string("GRAT"),
std::string("LRAT"), std::string("CRAT"), std::string("RESV"), std::map<std::string, Mode>::iterator
std::string("BHP"), std::string("THP"), std::string("GRUP") }; p = mode_map.find(control);
int m = -1;
for (int i=0; i<num_prod_control_modes; ++i) { if (p != mode_map.end()) {
if (control == prod_control_modes[i]) { return p->second;
m = i;
break;
}
} }
if (m >= 0) { else {
return static_cast<Mode>(m); THROW("Unknown well control mode = "
} else { << control << " in input file");
THROW("Unknown well control mode = " << control << " in input file");
} }
} }
} // namespace ProductionControl } // namespace ProductionControl
@ -84,24 +106,36 @@ namespace
{ {
enum Mode { RATE, RESV, BHP, enum Mode { RATE, RESV, BHP,
THP, GRUP }; THP, GRUP };
namespace Details {
std::map<std::string, Mode>
init_mode_map() {
std::map<std::string, Mode> 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) Mode mode(const std::string& control)
{ {
const int num_inje_control_modes = 5; static std::map<std::string, Mode>
static std::string inje_control_modes[num_inje_control_modes] = mode_map = Details::init_mode_map();
{std::string("RATE"), std::string("RESV"), std::string("BHP"),
std::string("THP"), std::string("GRUP") };
int m = -1;
for (int i=0; i<num_inje_control_modes; ++i) {
if (control == inje_control_modes[i]) {
m = i;
break;
}
}
if (m >= 0) { std::map<std::string, Mode>::iterator
return static_cast<Mode>(m); p = mode_map.find(control);
} else {
THROW("Unknown well control mode = " << control << " in input file"); if (p != mode_map.end()) {
return p->second;
}
else {
THROW("Unknown well control mode = "
<< control << " in input file");
} }
} }
} // namespace InjectionControl } // namespace InjectionControl
@ -408,10 +442,10 @@ namespace Opm
} else { } else {
THROW("Unseen well name: " << lines[i].well_ << " first seen in WCONPROD"); THROW("Unseen well name: " << lines[i].well_ << " first seen in WCONPROD");
} }
} }
} }
// Add wells. // Add wells.
for (int w = 0; w < num_wells; ++w) { for (int w = 0; w < num_wells; ++w) {
const int w_num_perf = wellperf_data[w].size(); const int w_num_perf = wellperf_data[w].size();
@ -425,7 +459,7 @@ namespace Opm
// We initialize all wells with a null component fraction, // We initialize all wells with a null component fraction,
// and must (for injection wells) overwrite it later. // 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, 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) { if (!ok) {
THROW("Failed adding well " << well_names[w] << " to Wells data structure."); 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]); THROW("Failure occured appending controls for well " << well_names[wix]);
} }
InjectionControl::Mode mode = InjectionControl::mode(wci_line.control_mode_); 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) { if (cpos == -1 && mode != InjectionControl::GRUP) {
THROW("Control for " << wci_line.control_mode_ << " not specified in well " << well_names[wix]); 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_current_control(wix, cpos, w_);
// Set well component fraction. // Set well component fraction.
@ -610,10 +648,14 @@ namespace Opm
THROW("Failure occured appending controls for well " << well_names[wix]); THROW("Failure occured appending controls for well " << well_names[wix]);
} }
ProductionControl::Mode mode = ProductionControl::mode(wcp_line.control_mode_); 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) { if (cpos == -1 && mode != ProductionControl::GRUP) {
THROW("Control mode type " << mode << " not present in well " << well_names[wix]); 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_); set_current_control(wix, cpos, w_);
} }
} }
@ -673,6 +715,34 @@ namespace Opm
*/ */
#endif #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<std::string, int>::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. // Build the well_collection_ well group hierarchy.
if (deck.hasField("GRUPTREE")) { if (deck.hasField("GRUPTREE")) {