Merge pull request #482 from joakim-hove/wellsmanager-rates
Wellsmanager: use new parser for WCONINJE and WCONPROD
This commit is contained in:
@@ -34,10 +34,10 @@ enum WellControlType {
|
||||
SURFACE_RATE /**< Well constrained by surface volume flow rate */
|
||||
};
|
||||
|
||||
struct WellControls;
|
||||
struct WellControls;
|
||||
|
||||
bool
|
||||
well_controls_equal(const struct WellControls *ctrls1, const struct WellControls *ctrls2);
|
||||
well_controls_equal(const struct WellControls *ctrls1, const struct WellControls *ctrls2 , bool verbose);
|
||||
|
||||
struct WellControls *
|
||||
well_controls_create(void);
|
||||
|
||||
@@ -263,7 +263,7 @@ struct Wells *
|
||||
clone_wells(const struct Wells *W);
|
||||
|
||||
bool
|
||||
wells_equal(const struct Wells *W1, const struct Wells *W2);
|
||||
wells_equal(const struct Wells *W1, const struct Wells *W2 , bool verbose);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
#include <opm/core/wells/WellCollection.hpp>
|
||||
#include <opm/core/props/phaseUsageFromDeck.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
@@ -103,6 +105,33 @@ namespace
|
||||
<< control << " in input file");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Mode mode(Opm::WellProducer::ControlModeEnum controlMode)
|
||||
{
|
||||
switch( controlMode ) {
|
||||
case Opm::WellProducer::ORAT:
|
||||
return ORAT;
|
||||
case Opm::WellProducer::WRAT:
|
||||
return WRAT;
|
||||
case Opm::WellProducer::GRAT:
|
||||
return GRAT;
|
||||
case Opm::WellProducer::LRAT:
|
||||
return LRAT;
|
||||
case Opm::WellProducer::CRAT:
|
||||
return CRAT;
|
||||
case Opm::WellProducer::RESV:
|
||||
return RESV;
|
||||
case Opm::WellProducer::BHP:
|
||||
return BHP;
|
||||
case Opm::WellProducer::THP:
|
||||
return THP;
|
||||
case Opm::WellProducer::GRUP:
|
||||
return GRUP;
|
||||
default:
|
||||
throw std::invalid_argument("unhandled enum value");
|
||||
}
|
||||
}
|
||||
} // namespace ProductionControl
|
||||
|
||||
|
||||
@@ -142,6 +171,25 @@ namespace
|
||||
<< control << " in input file");
|
||||
}
|
||||
}
|
||||
|
||||
Mode mode(Opm::WellInjector::ControlModeEnum controlMode)
|
||||
{
|
||||
switch ( controlMode ) {
|
||||
case Opm::WellInjector::GRUP:
|
||||
return GRUP;
|
||||
case Opm::WellInjector::RESV:
|
||||
return RESV;
|
||||
case Opm::WellInjector::RATE:
|
||||
return RATE;
|
||||
case Opm::WellInjector::THP:
|
||||
return THP;
|
||||
case Opm::WellInjector::BHP:
|
||||
return BHP;
|
||||
default:
|
||||
throw std::invalid_argument("unhandled enum value");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace InjectionControl
|
||||
|
||||
|
||||
@@ -307,6 +355,10 @@ namespace Opm
|
||||
// perforation.
|
||||
wd.reference_bhp_depth = (well->getRefDepth() < 0.0) ? -1e100 : well->getRefDepth();
|
||||
wd.welspecsline = -1;
|
||||
if (well->isInjector( timeStep ))
|
||||
wd.type = INJECTOR;
|
||||
else
|
||||
wd.type = PRODUCER;
|
||||
well_data.push_back(wd);
|
||||
}
|
||||
}
|
||||
@@ -371,32 +423,6 @@ namespace Opm
|
||||
OPM_THROW(std::runtime_error, "Failed creating Wells struct.");
|
||||
}
|
||||
|
||||
// Classify wells
|
||||
if (deck.hasField("WCONINJE")) {
|
||||
const std::vector<WconinjeLine>& lines = deck.getWCONINJE().wconinje;
|
||||
for (size_t i = 0 ; i < lines.size(); ++i) {
|
||||
const std::map<std::string, int>::const_iterator it = well_names_to_index.find(lines[i].well_);
|
||||
if (it != well_names_to_index.end()) {
|
||||
const int well_index = it->second;
|
||||
well_data[well_index].type = INJECTOR;
|
||||
} else {
|
||||
OPM_THROW(std::runtime_error, "Unseen well name: " << lines[i].well_ << " first seen in WCONINJE");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (deck.hasField("WCONPROD")) {
|
||||
const std::vector<WconprodLine>& lines = deck.getWCONPROD().wconprod;
|
||||
for (size_t i = 0; i < lines.size(); ++i) {
|
||||
const std::map<std::string, int>::const_iterator it = well_names_to_index.find(lines[i].well_);
|
||||
if (it != well_names_to_index.end()) {
|
||||
const int well_index = it->second;
|
||||
well_data[well_index].type = PRODUCER;
|
||||
} else {
|
||||
OPM_THROW(std::runtime_error, "Unseen well name: " << lines[i].well_ << " first seen in WCONPROD");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Add wells.
|
||||
for (int w = 0; w < num_wells; ++w) {
|
||||
@@ -416,227 +442,222 @@ namespace Opm
|
||||
OPM_THROW(std::runtime_error, "Failed adding well " << well_names[w] << " to Wells data structure.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
well_index = 0;
|
||||
for (auto wellIter= wells.begin(); wellIter != wells.end(); ++wellIter) {
|
||||
WellConstPtr well = (*wellIter);
|
||||
|
||||
if (well->isInjector(timeStep)) {
|
||||
clear_well_controls(well_index, w_);
|
||||
int ok = 1;
|
||||
int control_pos[5] = { -1, -1, -1, -1, -1 };
|
||||
|
||||
// Get WCONINJE data, add injection controls to wells.
|
||||
// It is allowed to have multiple lines corresponding to
|
||||
// the same well, in which case the last one encountered
|
||||
// is the one used.
|
||||
if (deck.hasField("WCONINJE")) {
|
||||
const WCONINJE& wconinjes = deck.getWCONINJE();
|
||||
const int num_wconinjes = wconinjes.wconinje.size();
|
||||
for (int kw = 0; kw < num_wconinjes; ++kw) {
|
||||
const WconinjeLine& wci_line = wconinjes.wconinje[kw];
|
||||
// Extract well name, or the part of the well name that
|
||||
// comes before the '*'.
|
||||
std::string name = wci_line.well_;
|
||||
std::string::size_type len = name.find('*');
|
||||
if (len != std::string::npos) {
|
||||
name = name.substr(0, len);
|
||||
if (well->hasInjectionControl(timeStep , WellInjector::RATE)) {
|
||||
control_pos[InjectionControl::RATE] = well_controls_get_num(w_->ctrls[well_index]);
|
||||
double distr[3] = { 0.0, 0.0, 0.0 };
|
||||
WellInjector::TypeEnum injectorType = well->getInjectorType(timeStep);
|
||||
|
||||
if (injectorType == WellInjector::TypeEnum::WATER) {
|
||||
distr[pu.phase_pos[BlackoilPhases::Aqua]] = 1.0;
|
||||
} else if (injectorType == WellInjector::TypeEnum::OIL) {
|
||||
distr[pu.phase_pos[BlackoilPhases::Liquid]] = 1.0;
|
||||
} else if (injectorType == WellInjector::TypeEnum::GAS) {
|
||||
distr[pu.phase_pos[BlackoilPhases::Vapour]] = 1.0;
|
||||
}
|
||||
|
||||
ok = append_well_controls(SURFACE_RATE,
|
||||
well->getSurfaceInjectionRate( timeStep ) ,
|
||||
distr,
|
||||
well_index,
|
||||
w_);
|
||||
}
|
||||
bool well_found = false;
|
||||
for (int wix = 0; wix < num_wells; ++wix) {
|
||||
if (well_names[wix].compare(0,len, name) == 0) { //equal
|
||||
well_found = true;
|
||||
assert(well_data[wix].type == w_->type[wix]);
|
||||
if (well_data[wix].type != INJECTOR) {
|
||||
OPM_THROW(std::runtime_error, "Found WCONINJE entry for a non-injector well: " << well_names[wix]);
|
||||
}
|
||||
|
||||
// Add all controls that are present in well.
|
||||
// First we must clear existing controls, in case the
|
||||
// current WCONINJE line is modifying earlier controls.
|
||||
clear_well_controls(wix, w_);
|
||||
int ok = 1;
|
||||
int control_pos[5] = { -1, -1, -1, -1, -1 };
|
||||
if (ok && wci_line.surface_flow_max_rate_ >= 0.0) {
|
||||
control_pos[InjectionControl::RATE] = well_controls_get_num(w_->ctrls[wix]);
|
||||
double distr[3] = { 0.0, 0.0, 0.0 };
|
||||
if (wci_line.injector_type_ == "WATER") {
|
||||
distr[pu.phase_pos[BlackoilPhases::Aqua]] = 1.0;
|
||||
} else if (wci_line.injector_type_ == "OIL") {
|
||||
distr[pu.phase_pos[BlackoilPhases::Liquid]] = 1.0;
|
||||
} else if (wci_line.injector_type_ == "GAS") {
|
||||
distr[pu.phase_pos[BlackoilPhases::Vapour]] = 1.0;
|
||||
} else {
|
||||
OPM_THROW(std::runtime_error, "Injector type " << wci_line.injector_type_ << " not supported."
|
||||
"WellsManager only supports WATER, OIL and GAS injector types.");
|
||||
}
|
||||
ok = append_well_controls(SURFACE_RATE, wci_line.surface_flow_max_rate_,
|
||||
distr, wix, w_);
|
||||
}
|
||||
if (ok && wci_line.reservoir_flow_max_rate_ >= 0.0) {
|
||||
control_pos[InjectionControl::RESV] = well_controls_get_num(w_->ctrls[wix]);
|
||||
double distr[3] = { 0.0, 0.0, 0.0 };
|
||||
if (wci_line.injector_type_ == "WATER") {
|
||||
distr[pu.phase_pos[BlackoilPhases::Aqua]] = 1.0;
|
||||
} else if (wci_line.injector_type_ == "OIL") {
|
||||
distr[pu.phase_pos[BlackoilPhases::Liquid]] = 1.0;
|
||||
} else if (wci_line.injector_type_ == "GAS") {
|
||||
distr[pu.phase_pos[BlackoilPhases::Vapour]] = 1.0;
|
||||
} else {
|
||||
OPM_THROW(std::runtime_error, "Injector type " << wci_line.injector_type_ << " not supported."
|
||||
"WellsManager only supports WATER, OIL and GAS injector types.");
|
||||
}
|
||||
ok = append_well_controls(RESERVOIR_RATE, wci_line.reservoir_flow_max_rate_,
|
||||
distr, wix, w_);
|
||||
}
|
||||
if (ok && wci_line.BHP_limit_ > 0.0) {
|
||||
control_pos[InjectionControl::BHP] = well_controls_get_num(w_->ctrls[wix]);
|
||||
ok = append_well_controls(BHP, wci_line.BHP_limit_,
|
||||
NULL, wix, w_);
|
||||
}
|
||||
if (ok && wci_line.THP_limit_ > 0.0) {
|
||||
OPM_THROW(std::runtime_error, "We cannot handle THP limit for well " << well_names[wix]);
|
||||
}
|
||||
if (!ok) {
|
||||
OPM_THROW(std::runtime_error, "Failure occured appending controls for well " << well_names[wix]);
|
||||
}
|
||||
InjectionControl::Mode mode = InjectionControl::mode(wci_line.control_mode_);
|
||||
int cpos = control_pos[mode];
|
||||
if (cpos == -1 && mode != InjectionControl::GRUP) {
|
||||
OPM_THROW(std::runtime_error, "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_);
|
||||
if (ok && well->hasInjectionControl(timeStep , WellInjector::RESV)) {
|
||||
control_pos[InjectionControl::RESV] = well_controls_get_num(w_->ctrls[well_index]);
|
||||
double distr[3] = { 0.0, 0.0, 0.0 };
|
||||
WellInjector::TypeEnum injectorType = well->getInjectorType(timeStep);
|
||||
|
||||
if (injectorType == WellInjector::TypeEnum::WATER) {
|
||||
distr[pu.phase_pos[BlackoilPhases::Aqua]] = 1.0;
|
||||
} else if (injectorType == WellInjector::TypeEnum::OIL) {
|
||||
distr[pu.phase_pos[BlackoilPhases::Liquid]] = 1.0;
|
||||
} else if (injectorType == WellInjector::TypeEnum::GAS) {
|
||||
distr[pu.phase_pos[BlackoilPhases::Vapour]] = 1.0;
|
||||
}
|
||||
|
||||
ok = append_well_controls(RESERVOIR_RATE,
|
||||
well->getReservoirInjectionRate( timeStep ),
|
||||
distr,
|
||||
well_index,
|
||||
w_);
|
||||
}
|
||||
|
||||
// Set well component fraction.
|
||||
double cf[3] = { 0.0, 0.0, 0.0 };
|
||||
if (wci_line.injector_type_[0] == 'W') {
|
||||
if (!pu.phase_used[BlackoilPhases::Aqua]) {
|
||||
OPM_THROW(std::runtime_error, "Water phase not used, yet found water-injecting well.");
|
||||
}
|
||||
cf[pu.phase_pos[BlackoilPhases::Aqua]] = 1.0;
|
||||
} else if (wci_line.injector_type_[0] == 'O') {
|
||||
if (!pu.phase_used[BlackoilPhases::Liquid]) {
|
||||
OPM_THROW(std::runtime_error, "Oil phase not used, yet found oil-injecting well.");
|
||||
}
|
||||
cf[pu.phase_pos[BlackoilPhases::Liquid]] = 1.0;
|
||||
} else if (wci_line.injector_type_[0] == 'G') {
|
||||
if (!pu.phase_used[BlackoilPhases::Vapour]) {
|
||||
OPM_THROW(std::runtime_error, "Gas phase not used, yet found gas-injecting well.");
|
||||
}
|
||||
cf[pu.phase_pos[BlackoilPhases::Vapour]] = 1.0;
|
||||
}
|
||||
std::copy(cf, cf + pu.num_phases, w_->comp_frac + wix*pu.num_phases);
|
||||
if (ok && well->hasInjectionControl(timeStep , WellInjector::BHP)) {
|
||||
control_pos[InjectionControl::BHP] = well_controls_get_num(w_->ctrls[well_index]);
|
||||
ok = append_well_controls(BHP,
|
||||
well->getBHPLimit(timeStep),
|
||||
NULL,
|
||||
well_index,
|
||||
w_);
|
||||
}
|
||||
|
||||
if (ok && well->hasInjectionControl(timeStep , WellInjector::THP)) {
|
||||
OPM_THROW(std::runtime_error, "We cannot handle THP limit for well " << well_names[well_index]);
|
||||
}
|
||||
|
||||
|
||||
if (!ok) {
|
||||
OPM_THROW(std::runtime_error, "Failure occured appending controls for well " << well_names[well_index]);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
InjectionControl::Mode mode = InjectionControl::mode( well->getInjectorControlMode(timeStep) );
|
||||
int cpos = control_pos[mode];
|
||||
if (cpos == -1 && mode != InjectionControl::GRUP) {
|
||||
OPM_THROW(std::runtime_error, "Control not specified in well " << well_names[well_index]);
|
||||
}
|
||||
}
|
||||
if (!well_found) {
|
||||
OPM_THROW(std::runtime_error, "Undefined well name: " << wci_line.well_
|
||||
<< " in WCONINJE");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get WCONPROD data
|
||||
// It is allowed to have multiple lines corresponding to
|
||||
// the same well, in which case the last one encountered
|
||||
// is the one used.
|
||||
if (deck.hasField("WCONPROD")) {
|
||||
const WCONPROD& wconprods = deck.getWCONPROD();
|
||||
const int num_wconprods = wconprods.wconprod.size();
|
||||
for (int kw = 0; kw < num_wconprods; ++kw) {
|
||||
const WconprodLine& wcp_line = wconprods.wconprod[kw];
|
||||
std::string name = wcp_line.well_;
|
||||
std::string::size_type len = name.find('*');
|
||||
if (len != std::string::npos) {
|
||||
name = name.substr(0, len);
|
||||
}
|
||||
bool well_found = false;
|
||||
for (int wix = 0; wix < num_wells; ++wix) {
|
||||
if (well_names[wix].compare(0,len, name) == 0) { //equal
|
||||
well_found = true;
|
||||
assert(well_data[wix].type == w_->type[wix]);
|
||||
if (well_data[wix].type != PRODUCER) {
|
||||
OPM_THROW(std::runtime_error, "Found WCONPROD entry for a non-producer well: " << well_names[wix]);
|
||||
}
|
||||
// Add all controls that are present in well.
|
||||
// First we must clear existing controls, in case the
|
||||
// current WCONPROD line is modifying earlier controls.
|
||||
clear_well_controls(wix, w_);
|
||||
int control_pos[9] = { -1, -1, -1, -1, -1, -1, -1, -1, -1 };
|
||||
int ok = 1;
|
||||
if (ok && wcp_line.oil_max_rate_ >= 0.0) {
|
||||
if (!pu.phase_used[BlackoilPhases::Liquid]) {
|
||||
OPM_THROW(std::runtime_error, "Oil phase not active and ORAT control specified.");
|
||||
}
|
||||
control_pos[ProductionControl::ORAT] = well_controls_get_num(w_->ctrls[wix]);
|
||||
double distr[3] = { 0.0, 0.0, 0.0 };
|
||||
distr[pu.phase_pos[BlackoilPhases::Liquid]] = 1.0;
|
||||
ok = append_well_controls(SURFACE_RATE, -wcp_line.oil_max_rate_,
|
||||
distr, wix, w_);
|
||||
}
|
||||
if (ok && wcp_line.water_max_rate_ >= 0.0) {
|
||||
if (!pu.phase_used[BlackoilPhases::Aqua]) {
|
||||
OPM_THROW(std::runtime_error, "Water phase not active and WRAT control specified.");
|
||||
}
|
||||
control_pos[ProductionControl::WRAT] = well_controls_get_num(w_->ctrls[wix]);
|
||||
double distr[3] = { 0.0, 0.0, 0.0 };
|
||||
distr[pu.phase_pos[BlackoilPhases::Aqua]] = 1.0;
|
||||
ok = append_well_controls(SURFACE_RATE, -wcp_line.water_max_rate_,
|
||||
distr, wix, w_);
|
||||
}
|
||||
if (ok && wcp_line.gas_max_rate_ >= 0.0) {
|
||||
if (!pu.phase_used[BlackoilPhases::Vapour]) {
|
||||
OPM_THROW(std::runtime_error, "Gas phase not active and GRAT control specified.");
|
||||
}
|
||||
control_pos[ProductionControl::GRAT] = well_controls_get_num(w_->ctrls[wix]);
|
||||
double distr[3] = { 0.0, 0.0, 0.0 };
|
||||
distr[pu.phase_pos[BlackoilPhases::Vapour]] = 1.0;
|
||||
ok = append_well_controls(SURFACE_RATE, -wcp_line.gas_max_rate_,
|
||||
distr, wix, w_);
|
||||
}
|
||||
if (ok && wcp_line.liquid_max_rate_ >= 0.0) {
|
||||
if (!pu.phase_used[BlackoilPhases::Aqua]) {
|
||||
OPM_THROW(std::runtime_error, "Water phase not active and LRAT control specified.");
|
||||
}
|
||||
if (!pu.phase_used[BlackoilPhases::Liquid]) {
|
||||
OPM_THROW(std::runtime_error, "Oil phase not active and LRAT control specified.");
|
||||
}
|
||||
control_pos[ProductionControl::LRAT] = well_controls_get_num(w_->ctrls[wix]);
|
||||
double distr[3] = { 0.0, 0.0, 0.0 };
|
||||
distr[pu.phase_pos[BlackoilPhases::Aqua]] = 1.0;
|
||||
distr[pu.phase_pos[BlackoilPhases::Liquid]] = 1.0;
|
||||
ok = append_well_controls(SURFACE_RATE, -wcp_line.liquid_max_rate_,
|
||||
distr, wix, w_);
|
||||
}
|
||||
if (ok && wcp_line.reservoir_flow_max_rate_ >= 0.0) {
|
||||
control_pos[ProductionControl::RESV] = well_controls_get_num(w_->ctrls[wix]);
|
||||
double distr[3] = { 1.0, 1.0, 1.0 };
|
||||
ok = append_well_controls(RESERVOIR_RATE, -wcp_line.reservoir_flow_max_rate_,
|
||||
distr, wix, w_);
|
||||
}
|
||||
if (ok && wcp_line.BHP_limit_ > 0.0) {
|
||||
control_pos[ProductionControl::BHP] = well_controls_get_num(w_->ctrls[wix]);
|
||||
ok = append_well_controls(BHP, wcp_line.BHP_limit_,
|
||||
NULL, wix, w_);
|
||||
}
|
||||
if (ok && wcp_line.THP_limit_ > 0.0) {
|
||||
OPM_THROW(std::runtime_error, "We cannot handle THP limit for well " << well_names[wix]);
|
||||
}
|
||||
if (!ok) {
|
||||
OPM_THROW(std::runtime_error, "Failure occured appending controls for well " << well_names[wix]);
|
||||
}
|
||||
ProductionControl::Mode mode = ProductionControl::mode(wcp_line.control_mode_);
|
||||
int cpos = control_pos[mode];
|
||||
if (cpos == -1 && mode != ProductionControl::GRUP) {
|
||||
OPM_THROW(std::runtime_error, "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_);
|
||||
|
||||
// We need to check if the well is shut or not
|
||||
if (well->getStatus( timeStep ) == WellCommon::SHUT) {
|
||||
cpos = ~cpos;
|
||||
}
|
||||
set_current_control(well_index, cpos, w_);
|
||||
}
|
||||
if (!well_found) {
|
||||
OPM_THROW(std::runtime_error, "Undefined well name: " << wcp_line.well_
|
||||
<< " in WCONPROD");
|
||||
|
||||
|
||||
// Set well component fraction.
|
||||
double cf[3] = { 0.0, 0.0, 0.0 };
|
||||
if (well->getInjectorType(timeStep) == WellInjector::WATER) {
|
||||
if (!pu.phase_used[BlackoilPhases::Aqua]) {
|
||||
OPM_THROW(std::runtime_error, "Water phase not used, yet found water-injecting well.");
|
||||
}
|
||||
cf[pu.phase_pos[BlackoilPhases::Aqua]] = 1.0;
|
||||
} else if (well->getInjectorType(timeStep) == WellInjector::OIL) {
|
||||
if (!pu.phase_used[BlackoilPhases::Liquid]) {
|
||||
OPM_THROW(std::runtime_error, "Oil phase not used, yet found oil-injecting well.");
|
||||
}
|
||||
cf[pu.phase_pos[BlackoilPhases::Liquid]] = 1.0;
|
||||
} else if (well->getInjectorType(timeStep) == WellInjector::GAS) {
|
||||
if (!pu.phase_used[BlackoilPhases::Vapour]) {
|
||||
OPM_THROW(std::runtime_error, "Gas phase not used, yet found gas-injecting well.");
|
||||
}
|
||||
cf[pu.phase_pos[BlackoilPhases::Vapour]] = 1.0;
|
||||
}
|
||||
std::copy(cf, cf + pu.num_phases, w_->comp_frac + well_index*pu.num_phases);
|
||||
|
||||
}
|
||||
|
||||
if (well->isProducer(timeStep)) {
|
||||
// Add all controls that are present in well.
|
||||
// First we must clear existing controls, in case the
|
||||
// current WCONPROD line is modifying earlier controls.
|
||||
clear_well_controls(well_index, w_);
|
||||
int control_pos[9] = { -1, -1, -1, -1, -1, -1, -1, -1, -1 };
|
||||
int ok = 1;
|
||||
if (ok && well->hasProductionControl(timeStep , WellProducer::ORAT)) {
|
||||
if (!pu.phase_used[BlackoilPhases::Liquid]) {
|
||||
OPM_THROW(std::runtime_error, "Oil phase not active and ORAT control specified.");
|
||||
}
|
||||
|
||||
control_pos[ProductionControl::ORAT] = well_controls_get_num(w_->ctrls[well_index]);
|
||||
double distr[3] = { 0.0, 0.0, 0.0 };
|
||||
distr[pu.phase_pos[BlackoilPhases::Liquid]] = 1.0;
|
||||
ok = append_well_controls(SURFACE_RATE,
|
||||
-well->getOilRate( timeStep ),
|
||||
distr,
|
||||
well_index,
|
||||
w_);
|
||||
}
|
||||
|
||||
if (ok && well->hasProductionControl(timeStep , WellProducer::WRAT)) {
|
||||
if (!pu.phase_used[BlackoilPhases::Aqua]) {
|
||||
OPM_THROW(std::runtime_error, "Water phase not active and WRAT control specified.");
|
||||
}
|
||||
control_pos[ProductionControl::WRAT] = well_controls_get_num(w_->ctrls[well_index]);
|
||||
double distr[3] = { 0.0, 0.0, 0.0 };
|
||||
distr[pu.phase_pos[BlackoilPhases::Aqua]] = 1.0;
|
||||
ok = append_well_controls(SURFACE_RATE,
|
||||
-well->getWaterRate(timeStep),
|
||||
distr,
|
||||
well_index,
|
||||
w_);
|
||||
}
|
||||
|
||||
if (ok && well->hasProductionControl(timeStep , WellProducer::GRAT)) {
|
||||
if (!pu.phase_used[BlackoilPhases::Vapour]) {
|
||||
OPM_THROW(std::runtime_error, "Gas phase not active and GRAT control specified.");
|
||||
}
|
||||
control_pos[ProductionControl::GRAT] = well_controls_get_num(w_->ctrls[well_index]);
|
||||
double distr[3] = { 0.0, 0.0, 0.0 };
|
||||
distr[pu.phase_pos[BlackoilPhases::Vapour]] = 1.0;
|
||||
ok = append_well_controls(SURFACE_RATE,
|
||||
-well->getGasRate( timeStep ),
|
||||
distr,
|
||||
well_index,
|
||||
w_);
|
||||
}
|
||||
|
||||
if (ok && well->hasProductionControl(timeStep , WellProducer::LRAT)) {
|
||||
if (!pu.phase_used[BlackoilPhases::Aqua]) {
|
||||
OPM_THROW(std::runtime_error, "Water phase not active and LRAT control specified.");
|
||||
}
|
||||
if (!pu.phase_used[BlackoilPhases::Liquid]) {
|
||||
OPM_THROW(std::runtime_error, "Oil phase not active and LRAT control specified.");
|
||||
}
|
||||
control_pos[ProductionControl::LRAT] = well_controls_get_num(w_->ctrls[well_index]);
|
||||
double distr[3] = { 0.0, 0.0, 0.0 };
|
||||
distr[pu.phase_pos[BlackoilPhases::Aqua]] = 1.0;
|
||||
distr[pu.phase_pos[BlackoilPhases::Liquid]] = 1.0;
|
||||
ok = append_well_controls(SURFACE_RATE,
|
||||
-well->getLiquidRate(timeStep),
|
||||
distr,
|
||||
well_index,
|
||||
w_);
|
||||
}
|
||||
|
||||
if (ok && well->hasProductionControl(timeStep , WellProducer::RESV)) {
|
||||
control_pos[ProductionControl::RESV] = well_controls_get_num(w_->ctrls[well_index]);
|
||||
double distr[3] = { 1.0, 1.0, 1.0 };
|
||||
ok = append_well_controls(RESERVOIR_RATE,
|
||||
-well->getResVRate(timeStep),
|
||||
distr,
|
||||
well_index,
|
||||
w_);
|
||||
}
|
||||
|
||||
if (ok && well->hasProductionControl(timeStep , WellProducer::BHP)) {
|
||||
control_pos[ProductionControl::BHP] = well_controls_get_num(w_->ctrls[well_index]);
|
||||
ok = append_well_controls(BHP,
|
||||
well->getBHPLimit( timeStep ) ,
|
||||
NULL,
|
||||
well_index,
|
||||
w_);
|
||||
}
|
||||
|
||||
if (ok && well->hasProductionControl(timeStep , WellProducer::THP)) {
|
||||
OPM_THROW(std::runtime_error, "We cannot handle THP limit for well " << well_names[well_index]);
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
OPM_THROW(std::runtime_error, "Failure occured appending controls for well " << well_names[well_index]);
|
||||
}
|
||||
|
||||
ProductionControl::Mode mode = ProductionControl::mode(well->getProducerControlMode(timeStep));
|
||||
int cpos = control_pos[mode];
|
||||
if (cpos == -1 && mode != ProductionControl::GRUP) {
|
||||
OPM_THROW(std::runtime_error, "Control mode type " << mode << " not present in well " << well_names[well_index]);
|
||||
}
|
||||
// If it's shut, we complement the cpos
|
||||
if (well->getStatus(timeStep) == WellCommon::SHUT) {
|
||||
cpos = ~cpos; // So we can easily retrieve the cpos later
|
||||
}
|
||||
set_current_control(well_index, cpos, w_);
|
||||
}
|
||||
well_index++;
|
||||
}
|
||||
|
||||
|
||||
// Get WELTARG data
|
||||
if (deck.hasField("WELTARG")) {
|
||||
|
||||
@@ -293,19 +293,38 @@ well_controls_add_new(enum WellControlType type , double target , const double *
|
||||
|
||||
|
||||
bool
|
||||
well_controls_equal(const struct WellControls *ctrls1, const struct WellControls *ctrls2)
|
||||
well_controls_equal(const struct WellControls *ctrls1, const struct WellControls *ctrls2 , bool verbose)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
bool are_equal = true;
|
||||
are_equal = (ctrls1->num == ctrls2->num);
|
||||
are_equal = are_equal && (ctrls1->number_of_phases == ctrls2->number_of_phases);
|
||||
|
||||
if (ctrls1->num != ctrls2->num) {
|
||||
are_equal = false;
|
||||
if (verbose)
|
||||
printf("ctrls1->num:%d ctrls2->num:%d \n",ctrls1->num , ctrls2->num);
|
||||
}
|
||||
|
||||
if (ctrls1->number_of_phases != ctrls2->number_of_phases) {
|
||||
are_equal = false;
|
||||
if (verbose)
|
||||
printf("ctrls1->number_of_phases:%d ctrls2->number_of_phases:%d \n",ctrls1->number_of_phases , ctrls2->number_of_phases);
|
||||
}
|
||||
|
||||
if (!are_equal) {
|
||||
return are_equal;
|
||||
}
|
||||
|
||||
are_equal = are_equal && (memcmp(ctrls1->type, ctrls2->type, ctrls1->num * sizeof *ctrls1->type ) == 0);
|
||||
are_equal = are_equal && (memcmp(ctrls1->target, ctrls2->target, ctrls1->num * sizeof *ctrls1->target ) == 0);
|
||||
are_equal = are_equal && (memcmp(ctrls1->distr, ctrls2->distr, ctrls1->num * ctrls1->number_of_phases * sizeof *ctrls1->distr ) == 0);
|
||||
if (memcmp(ctrls1->type, ctrls2->type, ctrls1->num * sizeof *ctrls1->type ) != 0) {
|
||||
are_equal = false;
|
||||
if (verbose)
|
||||
printf("The ->type vectors are different \n");
|
||||
}
|
||||
|
||||
if (memcmp(ctrls1->target, ctrls2->target, ctrls1->num * sizeof *ctrls1->target ) != 0) {
|
||||
are_equal = false;
|
||||
if (verbose)
|
||||
printf("The ->target vectors are different \n");
|
||||
}
|
||||
are_equal = are_equal && (ctrls1->cpty == ctrls2->cpty);
|
||||
|
||||
return are_equal;
|
||||
|
||||
@@ -541,7 +541,7 @@ clone_wells(const struct Wells *W)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
bool
|
||||
wells_equal(const struct Wells *W1, const struct Wells *W2)
|
||||
wells_equal(const struct Wells *W1, const struct Wells *W2 , bool verbose)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
bool are_equal = true;
|
||||
@@ -567,10 +567,25 @@ wells_equal(const struct Wells *W1, const struct Wells *W2)
|
||||
are_equal = are_equal && (strcmp(W1->name[i], W2->name[i]) == 0);
|
||||
else
|
||||
are_equal = are_equal && (W1->name[i] == W2->name[i]);
|
||||
|
||||
if (verbose && !are_equal)
|
||||
printf("Well name[%d] %s and %s are different \n", i , W1->name[i] , W2->name[i]);
|
||||
}
|
||||
if (W1->type[i] != W2->type[i]) {
|
||||
are_equal = false;
|
||||
if (verbose)
|
||||
printf("Well->type[%d] different %d %d \n",i , W1->type[i] , W2->type[i] );
|
||||
}
|
||||
if (W1->depth_ref[i] != W2->depth_ref[i]) {
|
||||
are_equal = false;
|
||||
if (verbose)
|
||||
printf("Well->depth_ref[%d] different %g %g \n",i , W1->depth_ref[i] , W2->depth_ref[i] );
|
||||
}
|
||||
if (!well_controls_equal(W1->ctrls[i], W2->ctrls[i],verbose)) {
|
||||
are_equal = false;
|
||||
if (verbose)
|
||||
printf("Well controls are different for well[%d]:%s \n",i,W1->name[i]);
|
||||
}
|
||||
are_equal = are_equal && (W1->type[i] == W2->type[i]);
|
||||
are_equal = are_equal && (W1->depth_ref[i] == W2->depth_ref[i]);
|
||||
are_equal = are_equal && (well_controls_equal(W1->ctrls[i], W2->ctrls[i]));
|
||||
}
|
||||
|
||||
|
||||
@@ -581,10 +596,16 @@ wells_equal(const struct Wells *W1, const struct Wells *W2)
|
||||
are_equal = are_equal && (mgmt1->well_cpty == mgmt2->well_cpty);
|
||||
}
|
||||
|
||||
are_equal = are_equal && (memcmp(W1->comp_frac, W2->comp_frac, W1->number_of_wells * W1->number_of_phases * sizeof *W1->comp_frac ) == 0);
|
||||
are_equal = are_equal && (memcmp(W1->well_connpos, W2->well_connpos, (1 + W1->number_of_wells) * sizeof *W1->well_connpos ) == 0);
|
||||
if (!are_equal) {
|
||||
return are_equal;
|
||||
if (memcmp(W1->comp_frac, W2->comp_frac, W1->number_of_wells * W1->number_of_phases * sizeof *W1->comp_frac ) != 0) {
|
||||
are_equal = false;
|
||||
if (verbose)
|
||||
printf("Component fractions different \n");
|
||||
}
|
||||
|
||||
if (memcmp(W1->well_connpos, W2->well_connpos, (1 + W1->number_of_wells) * sizeof *W1->well_connpos ) != 0) {
|
||||
are_equal = false;
|
||||
if (verbose)
|
||||
printf("perforation position map difference \n");
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -204,7 +204,7 @@ BOOST_AUTO_TEST_CASE(Copy)
|
||||
BOOST_CHECK_EQUAL( dist1[p] , dist2[p]);
|
||||
}
|
||||
}
|
||||
BOOST_CHECK( well_controls_equal( c1 , c2 ));
|
||||
BOOST_CHECK( well_controls_equal( c1 , c2 , false) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -219,7 +219,7 @@ BOOST_AUTO_TEST_CASE(Equals_WellsEqual_ReturnsTrue) {
|
||||
std::shared_ptr<Wells> W2(create_wells(nphases, nwells, nperfs),
|
||||
destroy_wells);
|
||||
|
||||
BOOST_CHECK(wells_equal(W1.get(), W2.get()));
|
||||
BOOST_CHECK(wells_equal(W1.get(), W2.get() , false));
|
||||
}
|
||||
|
||||
|
||||
@@ -232,5 +232,5 @@ BOOST_AUTO_TEST_CASE(Equals_WellsDiffer_ReturnsFalse) {
|
||||
std::shared_ptr<Wells> W2(create_wells(nphases, 3, nperfs),
|
||||
destroy_wells);
|
||||
|
||||
BOOST_CHECK(!wells_equal(W1.get(), W2.get()));
|
||||
BOOST_CHECK(!wells_equal(W1.get(), W2.get() , false ));
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ BOOST_AUTO_TEST_CASE(New_Constructor_Works) {
|
||||
|
||||
check_controls_epoch0( wellsManager.c_wells()->ctrls );
|
||||
|
||||
BOOST_CHECK(wells_equal(wellsManager.c_wells(), oldWellsManager.c_wells()));
|
||||
BOOST_CHECK(wells_equal(wellsManager.c_wells(), oldWellsManager.c_wells() , false));
|
||||
}
|
||||
|
||||
Deck.setCurrentEpoch(1);
|
||||
@@ -234,7 +234,7 @@ BOOST_AUTO_TEST_CASE(New_Constructor_Works) {
|
||||
|
||||
check_controls_epoch1( wellsManager.c_wells()->ctrls );
|
||||
|
||||
BOOST_CHECK(wells_equal( wellsManager.c_wells(), oldWellsManager.c_wells()));
|
||||
BOOST_CHECK(wells_equal( wellsManager.c_wells(), oldWellsManager.c_wells(),false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,7 +252,7 @@ BOOST_AUTO_TEST_CASE(New_Constructor_Works_ExpandedData) {
|
||||
Opm::WellsManager wellsManager(eclipseState, 0, Deck, *gridManager.c_grid(), NULL);
|
||||
Opm::WellsManager oldWellsManager(Deck, *gridManager.c_grid(), NULL);
|
||||
|
||||
BOOST_CHECK(wells_equal(wellsManager.c_wells(), oldWellsManager.c_wells()));
|
||||
BOOST_CHECK(wells_equal(wellsManager.c_wells(), oldWellsManager.c_wells(),false));
|
||||
}
|
||||
|
||||
Deck.setCurrentEpoch(1);
|
||||
@@ -260,7 +260,7 @@ BOOST_AUTO_TEST_CASE(New_Constructor_Works_ExpandedData) {
|
||||
Opm::WellsManager wellsManager(eclipseState, 1,Deck, *gridManager.c_grid(), NULL);
|
||||
Opm::WellsManager oldWellsManager(Deck, *gridManager.c_grid(), NULL);
|
||||
|
||||
BOOST_CHECK(wells_equal( wellsManager.c_wells(), oldWellsManager.c_wells()));
|
||||
BOOST_CHECK(wells_equal( wellsManager.c_wells(), oldWellsManager.c_wells(), true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,8 +276,8 @@ BOOST_AUTO_TEST_CASE(WellsEqual) {
|
||||
Deck.setCurrentEpoch(1);
|
||||
Opm::WellsManager wellsManager1(Deck, *gridManager.c_grid(), NULL);
|
||||
|
||||
BOOST_CHECK( wells_equal( wellsManager0.c_wells() , wellsManager0.c_wells()) );
|
||||
BOOST_CHECK( !wells_equal( wellsManager0.c_wells() , wellsManager1.c_wells()) );
|
||||
BOOST_CHECK( wells_equal( wellsManager0.c_wells() , wellsManager0.c_wells(),false) );
|
||||
BOOST_CHECK( !wells_equal( wellsManager0.c_wells() , wellsManager1.c_wells(),false) );
|
||||
}
|
||||
|
||||
|
||||
@@ -291,15 +291,15 @@ BOOST_AUTO_TEST_CASE(ControlsEqual) {
|
||||
Deck.setCurrentEpoch(1);
|
||||
Opm::WellsManager wellsManager1(Deck, *gridManager.c_grid(), NULL);
|
||||
|
||||
BOOST_CHECK( well_controls_equal( wellsManager0.c_wells()->ctrls[0] , wellsManager0.c_wells()->ctrls[0]));
|
||||
BOOST_CHECK( well_controls_equal( wellsManager0.c_wells()->ctrls[1] , wellsManager0.c_wells()->ctrls[1]));
|
||||
BOOST_CHECK( well_controls_equal( wellsManager1.c_wells()->ctrls[0] , wellsManager1.c_wells()->ctrls[0]));
|
||||
BOOST_CHECK( well_controls_equal( wellsManager1.c_wells()->ctrls[1] , wellsManager1.c_wells()->ctrls[1]));
|
||||
BOOST_CHECK( well_controls_equal( wellsManager0.c_wells()->ctrls[0] , wellsManager0.c_wells()->ctrls[0] , false));
|
||||
BOOST_CHECK( well_controls_equal( wellsManager0.c_wells()->ctrls[1] , wellsManager0.c_wells()->ctrls[1] , false));
|
||||
BOOST_CHECK( well_controls_equal( wellsManager1.c_wells()->ctrls[0] , wellsManager1.c_wells()->ctrls[0] , false));
|
||||
BOOST_CHECK( well_controls_equal( wellsManager1.c_wells()->ctrls[1] , wellsManager1.c_wells()->ctrls[1] , false));
|
||||
|
||||
BOOST_CHECK( !well_controls_equal( wellsManager0.c_wells()->ctrls[0] , wellsManager0.c_wells()->ctrls[1]));
|
||||
BOOST_CHECK( !well_controls_equal( wellsManager0.c_wells()->ctrls[1] , wellsManager0.c_wells()->ctrls[0]));
|
||||
BOOST_CHECK( !well_controls_equal( wellsManager1.c_wells()->ctrls[0] , wellsManager0.c_wells()->ctrls[0]));
|
||||
BOOST_CHECK( !well_controls_equal( wellsManager1.c_wells()->ctrls[1] , wellsManager0.c_wells()->ctrls[1]));
|
||||
BOOST_CHECK( !well_controls_equal( wellsManager0.c_wells()->ctrls[0] , wellsManager0.c_wells()->ctrls[1] , false));
|
||||
BOOST_CHECK( !well_controls_equal( wellsManager0.c_wells()->ctrls[1] , wellsManager0.c_wells()->ctrls[0] , false));
|
||||
BOOST_CHECK( !well_controls_equal( wellsManager1.c_wells()->ctrls[0] , wellsManager0.c_wells()->ctrls[0] , false));
|
||||
BOOST_CHECK( !well_controls_equal( wellsManager1.c_wells()->ctrls[1] , wellsManager0.c_wells()->ctrls[1] , false));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user