Added wells to groups.

This commit is contained in:
Joakim Hove
2013-11-22 19:10:23 +01:00
parent 0271e5fc03
commit 5d0870581b
3 changed files with 205 additions and 1 deletions

View File

@@ -22,6 +22,7 @@
#include <boost/date_time.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Group.hpp>
namespace Opm {
namespace GroupProduction {
struct ProductionData {
@@ -77,11 +78,74 @@ namespace Opm {
}
}
/*****************************************************************/
class WellSet {
public:
WellSet();
size_t size() const;
bool hasWell(const std::string& wellName) const;
WellConstPtr getWell(const std::string& wellName) const;
void addWell(WellPtr well);
void delWell(const std::string& wellName);
WellSet * shallowCopy() const;
private:
std::map<std::string , WellPtr> m_wells;
};
WellSet::WellSet() {
}
size_t WellSet::size() const {
return m_wells.size();
}
bool WellSet::hasWell(const std::string& wellName) const {
return (m_wells.find(wellName) != m_wells.end());
}
WellConstPtr WellSet::getWell(const std::string& wellName) const {
if (hasWell(wellName))
return m_wells.find(wellName)->second;
else
throw std::invalid_argument("Does not have this well?!\n");
}
void WellSet::addWell(WellPtr well) {
const std::string& wellName = well->name();
if (!hasWell(wellName))
m_wells[wellName] = well;
}
void WellSet::delWell(const std::string& wellName) {
if (hasWell(wellName))
m_wells.erase( wellName );
else
throw std::invalid_argument("Does not have this well?");
}
WellSet * WellSet::shallowCopy() const {
WellSet * copy = new WellSet();
for (std::map<std::string , WellPtr>::const_iterator iter=m_wells.begin(); iter != m_wells.end(); ++iter)
copy->addWell( (*iter).second );
return copy;
}
/*****************************************************************/
Group::Group(const std::string& name , TimeMapConstPtr timeMap) :
m_injection( new GroupInjection::InjectionData(timeMap) ),
m_production( new GroupProduction::ProductionData( timeMap ))
m_production( new GroupProduction::ProductionData( timeMap )),
m_wells( new DynamicState<WellSetConstPtr>(timeMap , WellSetConstPtr(new WellSet() )))
{
m_name = name;
}
@@ -232,7 +296,46 @@ namespace Opm {
}
/*****************************************************************/
WellSetConstPtr Group::wellMap(size_t time_step) const {
return m_wells->get(time_step);
}
bool Group::hasWell(const std::string& wellName , size_t time_step) {
WellSetConstPtr wellSet = wellMap(time_step);
return wellSet->hasWell(wellName);
}
WellConstPtr Group::getWell(const std::string& wellName , size_t time_step) const {
WellSetConstPtr wellSet = wellMap(time_step);
return wellSet->getWell(wellName);
}
size_t Group::numWells(size_t time_step) {
WellSetConstPtr wellSet = wellMap(time_step);
return wellSet->size();
}
void Group::addWell(size_t time_step , WellPtr well) {
WellSetConstPtr wellSet = wellMap(time_step);
WellSetPtr newWellSet = WellSetPtr( wellSet->shallowCopy() );
newWellSet->addWell(well);
m_wells->add(time_step , newWellSet);
}
void Group::delWell(size_t time_step , const std::string& wellName) {
WellSetConstPtr wellSet = wellMap(time_step);
WellSetPtr newWellSet = WellSetPtr( wellSet->shallowCopy() );
newWellSet->delWell(wellName);
m_wells->add(time_step , newWellSet);
}
}

View File

@@ -24,6 +24,7 @@
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/DynamicState.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Well.hpp>
#include <boost/shared_ptr.hpp>
#include <string>
@@ -39,6 +40,10 @@ namespace Opm {
struct ProductionData;
}
class WellSet;
typedef boost::shared_ptr<const WellSet> WellSetConstPtr;
typedef boost::shared_ptr<WellSet> WellSetPtr;
class Group {
public:
@@ -83,10 +88,20 @@ namespace Opm {
void setLiquidTargetRate(size_t time_step , double LiquidTargetRate);
double getLiquidTargetRate(size_t time_step);
/*****************************************************************/
bool hasWell(const std::string& wellName , size_t time_step);
WellConstPtr getWell(const std::string& wellName , size_t time_step) const;
size_t numWells(size_t time_step);
void addWell(size_t time_step , WellPtr well);
void delWell(size_t time_step , const std::string& wellName);
private:
WellSetConstPtr wellMap(size_t time_step) const;
std::string m_name;
boost::shared_ptr<GroupInjection::InjectionData> m_injection;
boost::shared_ptr<GroupProduction::ProductionData> m_production;
boost::shared_ptr<DynamicState<WellSetConstPtr> > m_wells;
};
typedef boost::shared_ptr<Group> GroupPtr;
typedef boost::shared_ptr<const Group> GroupConstPtr;

View File

@@ -100,3 +100,89 @@ BOOST_AUTO_TEST_CASE(GroupMiscInjection) {
group.setTargetVoidReplacementFraction( 3 , 400 );
BOOST_CHECK_EQUAL( 400 , group.getTargetVoidReplacementFraction( 5 ));
}
BOOST_AUTO_TEST_CASE(GroupDoesNotHaveWell) {
Opm::TimeMapPtr timeMap = createXDaysTimeMap(10);
Opm::Group group("G1" , timeMap);
BOOST_CHECK_EQUAL(false , group.hasWell("NO", 2));
BOOST_CHECK_EQUAL(0U , group.numWells(2));
BOOST_CHECK_THROW(group.getWell("NO" , 2) , std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(GroupAddWell) {
Opm::TimeMapPtr timeMap = createXDaysTimeMap(10);
Opm::Group group("G1" , timeMap);
Opm::WellPtr well1(new Opm::Well("WELL1" , timeMap));
Opm::WellPtr well2(new Opm::Well("WELL2" , timeMap));
BOOST_CHECK_EQUAL(0U , group.numWells(2));
group.addWell( 3 , well1 );
BOOST_CHECK_EQUAL( 1U , group.numWells(3));
BOOST_CHECK_EQUAL( 0U , group.numWells(1));
group.addWell( 4 , well1 );
BOOST_CHECK_EQUAL( 1U , group.numWells(4));
BOOST_CHECK_EQUAL( 0U , group.numWells(1));
BOOST_CHECK_EQUAL( 1U , group.numWells(5));
group.addWell( 6 , well2 );
BOOST_CHECK_EQUAL( 1U , group.numWells(4));
BOOST_CHECK_EQUAL( 0U , group.numWells(1));
BOOST_CHECK_EQUAL( 1U , group.numWells(5));
BOOST_CHECK_EQUAL( 2U , group.numWells(6));
BOOST_CHECK_EQUAL( 2U , group.numWells(8));
BOOST_CHECK(group.hasWell("WELL1" , 8 ));
BOOST_CHECK(group.hasWell("WELL2" , 8 ));
BOOST_CHECK_EQUAL(false , group.hasWell("WELL1" , 0 ));
BOOST_CHECK_EQUAL(false , group.hasWell("WELL2" , 0 ));
BOOST_CHECK_EQUAL(true , group.hasWell("WELL1" , 5 ));
BOOST_CHECK_EQUAL(false , group.hasWell("WELL2" , 5 ));
}
BOOST_AUTO_TEST_CASE(GroupAddAndDelWell) {
Opm::TimeMapPtr timeMap = createXDaysTimeMap(10);
Opm::Group group("G1" , timeMap);
Opm::WellPtr well1(new Opm::Well("WELL1" , timeMap));
Opm::WellPtr well2(new Opm::Well("WELL2" , timeMap));
BOOST_CHECK_EQUAL(0U , group.numWells(2));
group.addWell( 3 , well1 );
BOOST_CHECK_EQUAL( 1U , group.numWells(3));
BOOST_CHECK_EQUAL( 0U , group.numWells(1));
group.addWell( 6 , well2 );
BOOST_CHECK_EQUAL( 1U , group.numWells(4));
BOOST_CHECK_EQUAL( 0U , group.numWells(1));
BOOST_CHECK_EQUAL( 1U , group.numWells(5));
BOOST_CHECK_EQUAL( 2U , group.numWells(6));
BOOST_CHECK_EQUAL( 2U , group.numWells(8));
group.delWell( 7 , "WELL1");
BOOST_CHECK_EQUAL(false , group.hasWell("WELL1" , 7));
BOOST_CHECK_EQUAL(true , group.hasWell("WELL2" , 7));
BOOST_CHECK_EQUAL( 1U , group.numWells(7));
BOOST_CHECK_EQUAL( 2U , group.numWells(6));
group.delWell( 8 , "WELL2");
BOOST_CHECK_EQUAL(false , group.hasWell("WELL1" , 8));
BOOST_CHECK_EQUAL(false , group.hasWell("WELL2" , 8));
BOOST_CHECK_EQUAL( 0U , group.numWells(8));
BOOST_CHECK_EQUAL( 1U , group.numWells(7));
BOOST_CHECK_EQUAL( 2U , group.numWells(6));
BOOST_CHECK_THROW( group.delWell( 8 , "WeLLDOESNOT" ) , std::invalid_argument);
BOOST_CHECK_THROW( group.delWell( 8 , "WELL1" ) , std::invalid_argument);
}