Schedule::getGroup returns reference, not pointer

This commit is contained in:
Jørgen Kvalsvik 2016-10-05 15:24:14 +02:00
parent 6a1ad6f3fe
commit 3c2ebf9cfd
7 changed files with 53 additions and 53 deletions

View File

@ -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.");
}

View File

@ -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

View File

@ -1064,29 +1064,29 @@ namespace Opm
}
} // anonymous namespace
std::shared_ptr<WellsGroupInterface> createGroupWellsGroup(const Group* group, size_t timeStep, const PhaseUsage& phase_usage )
std::shared_ptr<WellsGroupInterface> 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<WellsGroupInterface> wells_group(new WellsGroup(group->name(), production_specification, injection_specification, phase_usage));
std::shared_ptr<WellsGroupInterface> wells_group(new WellsGroup(group.name(), production_specification, injection_specification, phase_usage));
return wells_group;
}

View File

@ -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<WellsGroupInterface> createGroupWellsGroup(const Group* group, size_t timeStep,
std::shared_ptr<WellsGroupInterface> createGroupWellsGroup(const Group& group, size_t timeStep,
const PhaseUsage& phase_usage );
}
#endif /* OPM_WELLSGROUP_HPP */

View File

@ -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);

View File

@ -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());

View File

@ -88,24 +88,24 @@ BOOST_AUTO_TEST_CASE(ConstructGroupFromGroup) {
EclipseStateConstPtr eclipseState(new EclipseState(*deck , parseContext));
PhaseUsage pu = phaseUsageFromDeck(eclipseState);
std::vector<GroupTreeNodeConstPtr> nodes = eclipseState->getSchedule()->getGroupTree(2)->getNodes();
auto nodes = eclipseState->getSchedule()->getGroupTree(2).getNodes();
for (size_t i=0; i<nodes.size(); i++) {
const auto* group = eclipseState->getSchedule()->getGroup(nodes[i]->name());
const auto& group = eclipseState->getSchedule()->getGroup(nodes[i]->name());
std::shared_ptr<WellsGroupInterface> 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_);
}
}
}