diff --git a/opm/core/wells/WellCollection.cpp b/opm/core/wells/WellCollection.cpp index d1238e7c..c901c8ab 100644 --- a/opm/core/wells/WellCollection.cpp +++ b/opm/core/wells/WellCollection.cpp @@ -29,8 +29,8 @@ namespace Opm { - void WellCollection::addField(const Group* fieldGroup, size_t timeStep, const PhaseUsage& phaseUsage) { - WellsGroupInterface* fieldNode = findNode(fieldGroup->name()); + void WellCollection::addField(const Group& fieldGroup, size_t timeStep, const PhaseUsage& phaseUsage) { + WellsGroupInterface* fieldNode = findNode(fieldGroup.name()); if (fieldNode) { OPM_THROW(std::runtime_error, "Trying to add FIELD node, but this already exists. Can only have one FIELD node."); } @@ -38,15 +38,15 @@ namespace Opm roots_.push_back(createGroupWellsGroup(fieldGroup, timeStep, phaseUsage)); } - void WellCollection::addGroup(const Group* groupChild, std::string parent_name, + void WellCollection::addGroup(const Group& groupChild, std::string parent_name, size_t timeStep, const PhaseUsage& phaseUsage) { WellsGroupInterface* parent = findNode(parent_name); if (!parent) { OPM_THROW(std::runtime_error, "Trying to add child group to group named " << parent_name << ", but this does not exist in the WellCollection."); } - if (findNode(groupChild->name())) { - OPM_THROW(std::runtime_error, "Trying to add child group named " << groupChild->name() << ", but this group is already in the WellCollection."); + if (findNode(groupChild.name())) { + OPM_THROW(std::runtime_error, "Trying to add child group named " << groupChild.name() << ", but this group is already in the WellCollection."); } diff --git a/opm/core/wells/WellCollection.hpp b/opm/core/wells/WellCollection.hpp index b0082743..a05142ae 100644 --- a/opm/core/wells/WellCollection.hpp +++ b/opm/core/wells/WellCollection.hpp @@ -36,11 +36,11 @@ namespace Opm { public: - void addField(const Group* fieldGroup, size_t timeStep, const PhaseUsage& phaseUsage); + void addField(const Group& fieldGroup, size_t timeStep, const PhaseUsage& phaseUsage); void addWell(const Well* wellChild, size_t timeStep, const PhaseUsage& phaseUsage); - void addGroup(const Group* groupChild, std::string parent_name, + void addGroup(const Group& groupChild, std::string parent_name, size_t timeStep, const PhaseUsage& phaseUsage); /// Adds the child to the collection diff --git a/opm/core/wells/WellsGroup.cpp b/opm/core/wells/WellsGroup.cpp index 558f39fc..6ec0cf10 100644 --- a/opm/core/wells/WellsGroup.cpp +++ b/opm/core/wells/WellsGroup.cpp @@ -1064,29 +1064,29 @@ namespace Opm } } // anonymous namespace - std::shared_ptr createGroupWellsGroup(const Group* group, size_t timeStep, const PhaseUsage& phase_usage ) + std::shared_ptr createGroupWellsGroup(const Group& group, size_t timeStep, const PhaseUsage& phase_usage ) { InjectionSpecification injection_specification; ProductionSpecification production_specification; - if (group->isInjectionGroup(timeStep)) { - injection_specification.injector_type_ = toInjectorType(Phase::PhaseEnum2String(group->getInjectionPhase(timeStep))); - injection_specification.control_mode_ = toInjectionControlMode(GroupInjection::ControlEnum2String(group->getInjectionControlMode(timeStep))); - injection_specification.surface_flow_max_rate_ = group->getSurfaceMaxRate(timeStep); - injection_specification.reservoir_flow_max_rate_ = group->getReservoirMaxRate(timeStep); - injection_specification.reinjection_fraction_target_ = group->getTargetReinjectFraction(timeStep); - injection_specification.voidage_replacment_fraction_ = group->getTargetVoidReplacementFraction(timeStep); + if (group.isInjectionGroup(timeStep)) { + injection_specification.injector_type_ = toInjectorType(Phase::PhaseEnum2String(group.getInjectionPhase(timeStep))); + injection_specification.control_mode_ = toInjectionControlMode(GroupInjection::ControlEnum2String(group.getInjectionControlMode(timeStep))); + injection_specification.surface_flow_max_rate_ = group.getSurfaceMaxRate(timeStep); + injection_specification.reservoir_flow_max_rate_ = group.getReservoirMaxRate(timeStep); + injection_specification.reinjection_fraction_target_ = group.getTargetReinjectFraction(timeStep); + injection_specification.voidage_replacment_fraction_ = group.getTargetVoidReplacementFraction(timeStep); } - else if (group->isProductionGroup(timeStep)) { - production_specification.oil_max_rate_ = group->getOilTargetRate(timeStep); - production_specification.control_mode_ = toProductionControlMode(GroupProduction::ControlEnum2String(group->getProductionControlMode(timeStep))); - production_specification.water_max_rate_ = group->getWaterTargetRate(timeStep); - production_specification.gas_max_rate_ = group->getGasTargetRate(timeStep); - production_specification.liquid_max_rate_ = group->getLiquidTargetRate(timeStep); - production_specification.procedure_ = toProductionProcedure(GroupProductionExceedLimit::ActionEnum2String(group->getProductionExceedLimitAction(timeStep))); - production_specification.reservoir_flow_max_rate_ = group->getReservoirVolumeTargetRate(timeStep); + else if (group.isProductionGroup(timeStep)) { + production_specification.oil_max_rate_ = group.getOilTargetRate(timeStep); + production_specification.control_mode_ = toProductionControlMode(GroupProduction::ControlEnum2String(group.getProductionControlMode(timeStep))); + production_specification.water_max_rate_ = group.getWaterTargetRate(timeStep); + production_specification.gas_max_rate_ = group.getGasTargetRate(timeStep); + production_specification.liquid_max_rate_ = group.getLiquidTargetRate(timeStep); + production_specification.procedure_ = toProductionProcedure(GroupProductionExceedLimit::ActionEnum2String(group.getProductionExceedLimitAction(timeStep))); + production_specification.reservoir_flow_max_rate_ = group.getReservoirVolumeTargetRate(timeStep); } - std::shared_ptr wells_group(new WellsGroup(group->name(), production_specification, injection_specification, phase_usage)); + std::shared_ptr wells_group(new WellsGroup(group.name(), production_specification, injection_specification, phase_usage)); return wells_group; } diff --git a/opm/core/wells/WellsGroup.hpp b/opm/core/wells/WellsGroup.hpp index c93fcdac..81e7e63e 100644 --- a/opm/core/wells/WellsGroup.hpp +++ b/opm/core/wells/WellsGroup.hpp @@ -413,7 +413,7 @@ namespace Opm /// \param[in] group the Group to construct object for /// \param[in] timeStep the time step in question /// \param[in] the phase usage - std::shared_ptr createGroupWellsGroup(const Group* group, size_t timeStep, + std::shared_ptr createGroupWellsGroup(const Group& group, size_t timeStep, const PhaseUsage& phase_usage ); } #endif /* OPM_WELLSGROUP_HPP */ diff --git a/opm/core/wells/WellsManager_impl.hpp b/opm/core/wells/WellsManager_impl.hpp index 48196744..e7fe979d 100644 --- a/opm/core/wells/WellsManager_impl.hpp +++ b/opm/core/wells/WellsManager_impl.hpp @@ -407,9 +407,9 @@ WellsManager::init(const Opm::EclipseStateConstPtr eclipseState, { GroupTreeNodeConstPtr fieldNode = - schedule->getGroupTree(timeStep)->getNode("FIELD"); + schedule->getGroupTree(timeStep).getNode("FIELD"); - const auto* fieldGroup = schedule->getGroup(fieldNode->name()); + const auto& fieldGroup = schedule->getGroup(fieldNode->name()); well_collection_.addField(fieldGroup, timeStep, pu); addChildGroups(fieldNode, schedule, timeStep, pu); diff --git a/tests/test_wellcollection.cpp b/tests/test_wellcollection.cpp index 35860e9a..4c318531 100644 --- a/tests/test_wellcollection.cpp +++ b/tests/test_wellcollection.cpp @@ -47,32 +47,32 @@ BOOST_AUTO_TEST_CASE(AddWellsAndGroupToCollection) { EclipseStateConstPtr eclipseState(new EclipseState(*deck, parseContext)); PhaseUsage pu = phaseUsageFromDeck(eclipseState); - GroupTreeNodePtr field=eclipseState->getSchedule()->getGroupTree(2)->getNode("FIELD"); - GroupTreeNodePtr g1=eclipseState->getSchedule()->getGroupTree(2)->getNode("G1"); - GroupTreeNodePtr g2=eclipseState->getSchedule()->getGroupTree(2)->getNode("G2"); + GroupTreeNodePtr field=eclipseState->getSchedule()->getGroupTree(2).getNode("FIELD"); + GroupTreeNodePtr g1=eclipseState->getSchedule()->getGroupTree(2).getNode("G1"); + GroupTreeNodePtr g2=eclipseState->getSchedule()->getGroupTree(2).getNode("G2"); WellCollection collection; // Add groups to WellCollection - const auto* fieldGroup = eclipseState->getSchedule()->getGroup(field->name()); + const auto& fieldGroup = eclipseState->getSchedule()->getGroup(field->name()); collection.addField(fieldGroup, 2, pu); for (auto iter = field->begin(); iter != field->end(); ++iter) { - const auto* childGroupNode = eclipseState->getSchedule()->getGroup((*iter).second->name()); - collection.addGroup(childGroupNode, fieldGroup->name(), 2, pu); + const auto& childGroupNode = eclipseState->getSchedule()->getGroup((*iter).second->name()); + collection.addGroup(childGroupNode, fieldGroup.name(), 2, pu); } - const auto* g1Group = eclipseState->getSchedule()->getGroup(g1->name()); + const auto& g1Group = eclipseState->getSchedule()->getGroup(g1->name()); for (auto iter = g1->begin(); iter != g1->end(); ++iter) { - const auto* childGroupNode = eclipseState->getSchedule()->getGroup((*iter).second->name()); - collection.addGroup(childGroupNode, g1Group->name(), 2, pu); + const auto& childGroupNode = eclipseState->getSchedule()->getGroup((*iter).second->name()); + collection.addGroup(childGroupNode, g1Group.name(), 2, pu); } - const auto* g2Group = eclipseState->getSchedule()->getGroup(g2->name()); + const auto& g2Group = eclipseState->getSchedule()->getGroup(g2->name()); for (auto iter = g2->begin(); iter != g2->end(); ++iter) { - const auto* childGroupNode = eclipseState->getSchedule()->getGroup((*iter).second->name()); - collection.addGroup(childGroupNode, g2Group->name(), 2, pu); + auto childGroupNode = eclipseState->getSchedule()->getGroup((*iter).second->name()); + collection.addGroup(childGroupNode, g2Group.name(), 2, pu); } BOOST_CHECK_EQUAL("FIELD", collection.findNode("FIELD")->name()); diff --git a/tests/test_wellsgroup.cpp b/tests/test_wellsgroup.cpp index f6e24cd4..be6d619d 100644 --- a/tests/test_wellsgroup.cpp +++ b/tests/test_wellsgroup.cpp @@ -88,24 +88,24 @@ BOOST_AUTO_TEST_CASE(ConstructGroupFromGroup) { EclipseStateConstPtr eclipseState(new EclipseState(*deck , parseContext)); PhaseUsage pu = phaseUsageFromDeck(eclipseState); - std::vector nodes = eclipseState->getSchedule()->getGroupTree(2)->getNodes(); + auto nodes = eclipseState->getSchedule()->getGroupTree(2).getNodes(); for (size_t i=0; igetSchedule()->getGroup(nodes[i]->name()); + const auto& group = eclipseState->getSchedule()->getGroup(nodes[i]->name()); std::shared_ptr wellsGroup = createGroupWellsGroup(group, 2, pu); - BOOST_CHECK_EQUAL(group->name(), wellsGroup->name()); - if (group->isInjectionGroup(2)) { - BOOST_CHECK_EQUAL(group->getSurfaceMaxRate(2), wellsGroup->injSpec().surface_flow_max_rate_); - BOOST_CHECK_EQUAL(group->getReservoirMaxRate(2), wellsGroup->injSpec().reservoir_flow_max_rate_); - BOOST_CHECK_EQUAL(group->getTargetReinjectFraction(2), wellsGroup->injSpec().reinjection_fraction_target_); - BOOST_CHECK_EQUAL(group->getTargetVoidReplacementFraction(2), wellsGroup->injSpec().voidage_replacment_fraction_); + BOOST_CHECK_EQUAL(group.name(), wellsGroup->name()); + if (group.isInjectionGroup(2)) { + BOOST_CHECK_EQUAL(group.getSurfaceMaxRate(2), wellsGroup->injSpec().surface_flow_max_rate_); + BOOST_CHECK_EQUAL(group.getReservoirMaxRate(2), wellsGroup->injSpec().reservoir_flow_max_rate_); + BOOST_CHECK_EQUAL(group.getTargetReinjectFraction(2), wellsGroup->injSpec().reinjection_fraction_target_); + BOOST_CHECK_EQUAL(group.getTargetVoidReplacementFraction(2), wellsGroup->injSpec().voidage_replacment_fraction_); } - if (group->isProductionGroup(2)) { - BOOST_CHECK_EQUAL(group->getReservoirVolumeTargetRate(2), wellsGroup->prodSpec().reservoir_flow_max_rate_); - BOOST_CHECK_EQUAL(group->getGasTargetRate(2), wellsGroup->prodSpec().gas_max_rate_); - BOOST_CHECK_EQUAL(group->getOilTargetRate(2), wellsGroup->prodSpec().oil_max_rate_); - BOOST_CHECK_EQUAL(group->getWaterTargetRate(2), wellsGroup->prodSpec().water_max_rate_); - BOOST_CHECK_EQUAL(group->getLiquidTargetRate(2), wellsGroup->prodSpec().liquid_max_rate_); + if (group.isProductionGroup(2)) { + BOOST_CHECK_EQUAL(group.getReservoirVolumeTargetRate(2), wellsGroup->prodSpec().reservoir_flow_max_rate_); + BOOST_CHECK_EQUAL(group.getGasTargetRate(2), wellsGroup->prodSpec().gas_max_rate_); + BOOST_CHECK_EQUAL(group.getOilTargetRate(2), wellsGroup->prodSpec().oil_max_rate_); + BOOST_CHECK_EQUAL(group.getWaterTargetRate(2), wellsGroup->prodSpec().water_max_rate_); + BOOST_CHECK_EQUAL(group.getLiquidTargetRate(2), wellsGroup->prodSpec().liquid_max_rate_); } } }