Use Schedule::groupNames() intead of getGroups()

This commit is contained in:
Joakim Hove
2019-07-07 10:29:24 +02:00
parent 6426644ce4
commit 7559c31e43
4 changed files with 51 additions and 30 deletions

View File

@@ -147,6 +147,7 @@ namespace Opm
size_t numGroups(size_t timeStep) const;
bool hasGroup(const std::string& groupName) const;
const Group& getGroup(const std::string& groupName) const;
Group& getGroup(const std::string& groupName);
std::vector< const Group* > getGroups() const;
std::vector< const Group* > getGroups(size_t timeStep) const;
const Tuning& getTuning() const;

View File

@@ -82,6 +82,11 @@ namespace {
return sch.hasWell( wellName );
}
const Group& get_group(const Schedule& sch, const std::string group_name) {
return sch.getGroup(group_name);
}
}
void sunbeam::export_Schedule(py::module& module) {
@@ -94,7 +99,7 @@ void sunbeam::export_Schedule(py::module& module) {
.def( "_get_wells", &Schedule::getWells2)
.def("_getwell", &get_well)
.def( "__contains__", &has_well )
.def( "_group", &Schedule::getGroup, ref_internal)
.def( "_group", &get_group, ref_internal)
.def( "_group_tree", &get_grouptree, ref_internal);
}

View File

@@ -1412,19 +1412,20 @@ namespace {
void Schedule::handleGCONINJE( const SCHEDULESection& section, const DeckKeyword& keyword, size_t currentStep, const ParseContext& parseContext, ErrorGuard& errors) {
for( const auto& record : keyword ) {
const std::string& groupNamePattern = record.getItem("GROUP").getTrimmedString(0);
auto groups = getGroups ( groupNamePattern );
const auto group_names = this->groupNames(groupNamePattern);
if (groups.empty())
if (group_names.empty())
invalidNamePattern(groupNamePattern, parseContext, errors, keyword);
for (auto* group : groups){
for (const auto& group_name : group_names){
auto& group = this->getGroup(group_name);
{
Phase phase = get_phase( record.getItem("PHASE").getTrimmedString(0) );
group->setInjectionPhase( currentStep , phase );
group.setInjectionPhase( currentStep , phase );
}
{
GroupInjection::ControlEnum controlMode = GroupInjection::ControlEnumFromString( record.getItem("CONTROL_MODE").getTrimmedString(0) );
group->setInjectionControlMode( currentStep , controlMode );
group.setInjectionControlMode( currentStep , controlMode );
}
Phase wellPhase = get_phase( record.getItem("PHASE").getTrimmedString(0));
@@ -1433,12 +1434,12 @@ namespace {
surfaceInjectionRate = injection::rateToSI(surfaceInjectionRate, wellPhase, section.unitSystem());
double reservoirInjectionRate = record.getItem("RESV_TARGET").get<UDAValue>(0).get<double>();
group->setSurfaceMaxRate( currentStep , surfaceInjectionRate);
group->setReservoirMaxRate( currentStep , reservoirInjectionRate);
group->setTargetReinjectFraction( currentStep , record.getItem("REINJ_TARGET").get<UDAValue>(0).get<double>());
group->setTargetVoidReplacementFraction( currentStep , record.getItem("VOIDAGE_TARGET").get<UDAValue>(0).get<double>());
group.setSurfaceMaxRate( currentStep , surfaceInjectionRate);
group.setReservoirMaxRate( currentStep , reservoirInjectionRate);
group.setTargetReinjectFraction( currentStep , record.getItem("REINJ_TARGET").get<UDAValue>(0).get<double>());
group.setTargetVoidReplacementFraction( currentStep , record.getItem("VOIDAGE_TARGET").get<UDAValue>(0).get<double>());
group->setInjectionGroup(currentStep, true);
group.setInjectionGroup(currentStep, true);
}
}
}
@@ -1446,27 +1447,28 @@ namespace {
void Schedule::handleGCONPROD( const DeckKeyword& keyword, size_t currentStep, const ParseContext& parseContext, ErrorGuard& errors) {
for( const auto& record : keyword ) {
const std::string& groupNamePattern = record.getItem("GROUP").getTrimmedString(0);
auto groups = getGroups ( groupNamePattern );
const auto group_names = this->groupNames(groupNamePattern);
if (groups.empty())
if (group_names.empty())
invalidNamePattern(groupNamePattern, parseContext, errors, keyword);
for (auto* group : groups){
for (const auto& group_name : group_names){
auto& group = this->getGroup(group_name);
{
GroupProduction::ControlEnum controlMode = GroupProduction::ControlEnumFromString( record.getItem("CONTROL_MODE").getTrimmedString(0) );
group->setProductionControlMode( currentStep , controlMode );
group.setProductionControlMode( currentStep , controlMode );
}
group->setOilTargetRate( currentStep , record.getItem("OIL_TARGET").get<UDAValue>(0).get<double>());
group->setGasTargetRate( currentStep , record.getItem("GAS_TARGET").get<UDAValue>(0).get<double>());
group->setWaterTargetRate( currentStep , record.getItem("WATER_TARGET").get<UDAValue>(0).get<double>());
group->setLiquidTargetRate( currentStep , record.getItem("LIQUID_TARGET").get<UDAValue>(0).get<double>());
group->setReservoirVolumeTargetRate( currentStep , record.getItem("RESERVOIR_FLUID_TARGET").getSIDouble(0));
group.setOilTargetRate( currentStep , record.getItem("OIL_TARGET").get<UDAValue>(0).get<double>());
group.setGasTargetRate( currentStep , record.getItem("GAS_TARGET").get<UDAValue>(0).get<double>());
group.setWaterTargetRate( currentStep , record.getItem("WATER_TARGET").get<UDAValue>(0).get<double>());
group.setLiquidTargetRate( currentStep , record.getItem("LIQUID_TARGET").get<UDAValue>(0).get<double>());
group.setReservoirVolumeTargetRate( currentStep , record.getItem("RESERVOIR_FLUID_TARGET").getSIDouble(0));
{
GroupProductionExceedLimit::ActionEnum exceedAction = GroupProductionExceedLimit::ActionEnumFromString(record.getItem("EXCEED_PROC").getTrimmedString(0) );
group->setProductionExceedLimitAction( currentStep , exceedAction );
group.setProductionExceedLimitAction( currentStep , exceedAction );
}
group->setProductionGroup(currentStep, true);
group.setProductionGroup(currentStep, true);
}
}
}
@@ -1475,17 +1477,18 @@ namespace {
void Schedule::handleGEFAC( const DeckKeyword& keyword, size_t currentStep, const ParseContext& parseContext, ErrorGuard& errors) {
for( const auto& record : keyword ) {
const std::string& groupNamePattern = record.getItem("GROUP").getTrimmedString(0);
auto groups = getGroups ( groupNamePattern );
const auto group_names = this->groupNames(groupNamePattern);
if (groups.empty())
if (group_names.empty())
invalidNamePattern(groupNamePattern, parseContext, errors, keyword);
for (auto* group : groups){
group->setGroupEfficiencyFactor(currentStep, record.getItem("EFFICIENCY_FACTOR").get< double >(0));
for (const auto& group_name : group_names){
auto& group = this->getGroup(group_name);
const std::string& transfer_str = record.getItem("TRANSFER_EXT_NET").getTrimmedString(0);
bool transfer = (transfer_str == "YES") ? true : false;
group->setTransferGroupEfficiencyFactor(currentStep, transfer);
group.setGroupEfficiencyFactor(currentStep, record.getItem("EFFICIENCY_FACTOR").get< double >(0));
group.setTransferGroupEfficiencyFactor(currentStep, transfer);
}
}
}
@@ -2163,15 +2166,16 @@ namespace {
size_t Schedule::numGroups() const {
return m_groups.size();
}
size_t Schedule::numGroups(size_t timeStep) const {
return this->getGroups( timeStep ).size();
const auto group_names = this->groupNames(timeStep);
return group_names.size();
}
bool Schedule::hasGroup(const std::string& groupName) const {
return m_groups.count(groupName) > 0;
}
const Group& Schedule::getGroup(const std::string& groupName) const {
if (hasGroup(groupName)) {
return m_groups.at(groupName);
@@ -2179,6 +2183,13 @@ namespace {
throw std::invalid_argument("Group: " + groupName + " does not exist");
}
Group& Schedule::getGroup(const std::string& groupName) {
if (hasGroup(groupName)) {
return m_groups.at(groupName);
} else
throw std::invalid_argument("Group: " + groupName + " does not exist");
}
std::vector< const Group* > Schedule::getGroups() const {
std::vector< const Group* > groups;

View File

@@ -288,6 +288,10 @@ BOOST_AUTO_TEST_CASE(createDeckWithGEFAC) {
Runspec runspec (deck );
Opm::Schedule schedule(deck, grid, eclipseProperties, runspec);
auto group_names = schedule.groupNames("PRODUC");
BOOST_CHECK_EQUAL(group_names.size(), 1);
BOOST_CHECK_EQUAL(group_names[0], "PRODUC");
const auto& group1 = schedule.getGroup("PRODUC");
BOOST_CHECK_EQUAL(group1.getGroupEfficiencyFactor(0), 0.85);
BOOST_CHECK(group1.getTransferGroupEfficiencyFactor(0));