Make Schedule.groups auto, not a shared_ptr

This commit is contained in:
Jørgen Kvalsvik
2016-10-05 14:39:01 +02:00
parent 1638341a90
commit d5251d97e6
4 changed files with 46 additions and 47 deletions

View File

@@ -352,7 +352,7 @@ namespace Opm {
const auto* currentWell = getWell(wellName);
checkWELSPECSConsistency( *currentWell, keyword, recordNr);
addWellToGroup( *this->m_groups.at( groupName ), *this->m_wells.get( wellName ), currentStep);
addWellToGroup( this->m_groups.at( groupName ), *this->m_wells.get( wellName ), currentStep);
if (handleGroupFromWELSPECS(groupName, newTree))
needNewTree = true;
@@ -970,7 +970,7 @@ namespace Opm {
void Schedule::handleGCONINJE( const SCHEDULESection& section, const DeckKeyword& keyword, size_t currentStep) {
for( const auto& record : keyword ) {
const std::string& groupName = record.getItem("GROUP").getTrimmedString(0);
auto& group = *this->m_groups.at( groupName );
auto& group = this->m_groups.at( groupName );
{
Phase::PhaseEnum phase = Phase::PhaseEnumFromString( record.getItem("PHASE").getTrimmedString(0) );
@@ -1000,7 +1000,7 @@ namespace Opm {
void Schedule::handleGCONPROD( const DeckKeyword& keyword, size_t currentStep) {
for( const auto& record : keyword ) {
const std::string& groupName = record.getItem("GROUP").getTrimmedString(0);
auto& group = *this->m_groups.at( groupName );
auto& group = this->m_groups.at( groupName );
{
GroupProduction::ControlEnum controlMode = GroupProduction::ControlEnumFromString( record.getItem("CONTROL_MODE").getTrimmedString(0) );
group.setProductionControlMode( currentStep , controlMode );
@@ -1023,7 +1023,7 @@ namespace Opm {
void Schedule::handleGEFAC( const DeckKeyword& keyword, size_t currentStep) {
for( const auto& record : keyword ) {
const std::string& groupName = record.getItem("GROUP").getTrimmedString(0);
auto& group = *this->m_groups.at( groupName );
auto& group = this->m_groups.at( groupName );
group.setGroupEfficiencyFactor(currentStep, record.getItem("EFFICIENCY_FACTOR").get< double >(0));
@@ -1442,8 +1442,7 @@ namespace Opm {
if (!m_timeMap) {
throw std::invalid_argument("TimeMap is null, can't add group named: " + groupName);
}
GroupPtr group(new Group(groupName, m_timeMap , timeStep));
m_groups[ groupName ] = group;
m_groups.emplace( groupName, Group { groupName, m_timeMap, timeStep } );
m_events.addEvent( ScheduleEvents::NEW_GROUP , timeStep );
}
@@ -1456,9 +1455,9 @@ namespace Opm {
}
const Group* Schedule::getGroup(const std::string& groupName) const {
const Group& Schedule::getGroup(const std::string& groupName) const {
if (hasGroup(groupName)) {
return m_groups.at(groupName).get();
return m_groups.at(groupName);
} else
throw std::invalid_argument("Group: " + groupName + " does not exist");
}
@@ -1467,7 +1466,7 @@ namespace Opm {
std::vector< const Group* > groups;
for( const auto& itr : m_groups )
groups.push_back( itr.second.get() );
groups.push_back( &itr.second );
return groups;
}
@@ -1475,7 +1474,7 @@ namespace Opm {
void Schedule::addWellToGroup( Group& newGroup, Well& well , size_t timeStep) {
const std::string currentGroupName = well.getGroupName(timeStep);
if (currentGroupName != "") {
m_groups.at( currentGroupName )->delWell( timeStep, well.name() );
m_groups.at( currentGroupName ).delWell( timeStep, well.name() );
}
well.setGroupName(timeStep , newGroup.name());
newGroup.addWell(timeStep , &well);

View File

@@ -27,6 +27,7 @@
#include <opm/parser/eclipse/EclipseState/Schedule/DynamicState.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/DynamicVector.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Events.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Group.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/GroupTree.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/OilVaporizationProperties.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp>
@@ -41,7 +42,6 @@ namespace Opm
class DeckKeyword;
class DeckRecord;
class EclipseGrid;
class Group;
class ParseContext;
class SCHEDULESection;
class TimeMap;
@@ -82,7 +82,7 @@ namespace Opm
const GroupTree& getGroupTree(size_t t) const;
size_t numGroups() const;
bool hasGroup(const std::string& groupName) const;
const Group* getGroup(const std::string& groupName) const;
const Group& getGroup(const std::string& groupName) const;
std::vector< const Group* > getGroups() const;
const Tuning& getTuning() const;
@@ -96,7 +96,7 @@ namespace Opm
private:
std::shared_ptr< TimeMap > m_timeMap;
OrderedMap<std::shared_ptr< Well >> m_wells;
std::map<std::string , std::shared_ptr< Group >> m_groups;
std::map<std::string, Group > m_groups;
DynamicState< GroupTree > m_rootGroupTree;
DynamicState< OilVaporizationProperties > m_oilvaporizationproperties;
Events m_events;

View File

@@ -289,9 +289,9 @@ BOOST_AUTO_TEST_CASE(createDeckWithGEFAC) {
EclipseGrid grid(10,10,10);
Opm::Schedule schedule(parseContext , grid, deck );
const auto* group1 = schedule.getGroup("PRODUC");
BOOST_CHECK_EQUAL(group1->getGroupEfficiencyFactor(0), 0.85);
BOOST_CHECK_EQUAL(group1->getTransferGroupEfficiencyFactor(0), true);
const auto& group1 = schedule.getGroup("PRODUC");
BOOST_CHECK_EQUAL(group1.getGroupEfficiencyFactor(0), 0.85);
BOOST_CHECK(group1.getTransferGroupEfficiencyFactor(0));
}

View File

@@ -486,30 +486,30 @@ BOOST_AUTO_TEST_CASE( WellTestGroups ) {
BOOST_CHECK( sched->hasGroup( "OP" ));
{
auto* group = sched->getGroup("INJ");
BOOST_CHECK_EQUAL( Phase::WATER , group->getInjectionPhase( 3 ));
BOOST_CHECK_EQUAL( GroupInjection::VREP , group->getInjectionControlMode( 3 ));
BOOST_CHECK_CLOSE( 10/Metric::Time , group->getSurfaceMaxRate( 3 ) , 0.001);
BOOST_CHECK_CLOSE( 20/Metric::Time , group->getReservoirMaxRate( 3 ) , 0.001);
BOOST_CHECK_EQUAL( 0.75 , group->getTargetReinjectFraction( 3 ));
BOOST_CHECK_EQUAL( 0.95 , group->getTargetVoidReplacementFraction( 3 ));
auto& group = sched->getGroup("INJ");
BOOST_CHECK_EQUAL( Phase::WATER , group.getInjectionPhase( 3 ));
BOOST_CHECK_EQUAL( GroupInjection::VREP , group.getInjectionControlMode( 3 ));
BOOST_CHECK_CLOSE( 10/Metric::Time , group.getSurfaceMaxRate( 3 ) , 0.001);
BOOST_CHECK_CLOSE( 20/Metric::Time , group.getReservoirMaxRate( 3 ) , 0.001);
BOOST_CHECK_EQUAL( 0.75 , group.getTargetReinjectFraction( 3 ));
BOOST_CHECK_EQUAL( 0.95 , group.getTargetVoidReplacementFraction( 3 ));
BOOST_CHECK_EQUAL( Phase::OIL , group->getInjectionPhase( 6 ));
BOOST_CHECK_EQUAL( GroupInjection::RATE , group->getInjectionControlMode( 6 ));
BOOST_CHECK_CLOSE( 1000/Metric::Time , group->getSurfaceMaxRate( 6 ) , 0.0001);
BOOST_CHECK_EQUAL( Phase::OIL , group.getInjectionPhase( 6 ));
BOOST_CHECK_EQUAL( GroupInjection::RATE , group.getInjectionControlMode( 6 ));
BOOST_CHECK_CLOSE( 1000/Metric::Time , group.getSurfaceMaxRate( 6 ) , 0.0001);
BOOST_CHECK(group->isInjectionGroup(3));
BOOST_CHECK(group.isInjectionGroup(3));
}
{
auto* group = sched->getGroup("OP");
BOOST_CHECK_EQUAL( GroupProduction::ORAT , group->getProductionControlMode(3));
BOOST_CHECK_CLOSE( 10/Metric::Time , group->getOilTargetRate(3) , 0.001);
BOOST_CHECK_CLOSE( 20/Metric::Time , group->getWaterTargetRate(3) , 0.001);
BOOST_CHECK_CLOSE( 30/Metric::Time , group->getGasTargetRate(3) , 0.001);
BOOST_CHECK_CLOSE( 40/Metric::Time , group->getLiquidTargetRate(3) , 0.001);
auto& group = sched->getGroup("OP");
BOOST_CHECK_EQUAL( GroupProduction::ORAT , group.getProductionControlMode(3));
BOOST_CHECK_CLOSE( 10/Metric::Time , group.getOilTargetRate(3) , 0.001);
BOOST_CHECK_CLOSE( 20/Metric::Time , group.getWaterTargetRate(3) , 0.001);
BOOST_CHECK_CLOSE( 30/Metric::Time , group.getGasTargetRate(3) , 0.001);
BOOST_CHECK_CLOSE( 40/Metric::Time , group.getLiquidTargetRate(3) , 0.001);
BOOST_CHECK(group->isProductionGroup(3));
BOOST_CHECK(group.isProductionGroup(3));
}
}
@@ -523,24 +523,24 @@ BOOST_AUTO_TEST_CASE( WellTestGroupAndWellRelation ) {
EclipseGrid grid(10,10,3);
SchedulePtr sched( new Schedule(parseContext , grid , deck));
auto* group1 = sched->getGroup("GROUP1");
auto* group2 = sched->getGroup("GROUP2");
auto& group1 = sched->getGroup("GROUP1");
auto& group2 = sched->getGroup("GROUP2");
BOOST_CHECK( group1->hasBeenDefined(0) );
BOOST_CHECK_EQUAL(false , group2->hasBeenDefined(0));
BOOST_CHECK( group2->hasBeenDefined(1));
BOOST_CHECK( group1.hasBeenDefined(0) );
BOOST_CHECK_EQUAL(false , group2.hasBeenDefined(0));
BOOST_CHECK( group2.hasBeenDefined(1));
BOOST_CHECK_EQUAL( true , group1->hasWell("W_1" , 0));
BOOST_CHECK_EQUAL( true , group1->hasWell("W_2" , 0));
BOOST_CHECK_EQUAL( false, group2->hasWell("W_1" , 0));
BOOST_CHECK_EQUAL( false, group2->hasWell("W_2" , 0));
BOOST_CHECK_EQUAL( true , group1.hasWell("W_1" , 0));
BOOST_CHECK_EQUAL( true , group1.hasWell("W_2" , 0));
BOOST_CHECK_EQUAL( false, group2.hasWell("W_1" , 0));
BOOST_CHECK_EQUAL( false, group2.hasWell("W_2" , 0));
BOOST_CHECK_EQUAL( true , group1->hasWell("W_1" , 1));
BOOST_CHECK_EQUAL( false , group1->hasWell("W_2" , 1));
BOOST_CHECK_EQUAL( false , group2->hasWell("W_1" , 1));
BOOST_CHECK_EQUAL( true , group2->hasWell("W_2" , 1));
BOOST_CHECK_EQUAL( true , group1.hasWell("W_1" , 1));
BOOST_CHECK_EQUAL( false , group1.hasWell("W_2" , 1));
BOOST_CHECK_EQUAL( false , group2.hasWell("W_1" , 1));
BOOST_CHECK_EQUAL( true , group2.hasWell("W_2" , 1));
}