DynamicState::update() will return bool.
This commit is contained in:
@@ -29,6 +29,29 @@
|
||||
|
||||
namespace Opm {
|
||||
|
||||
/**
|
||||
The DynamicState<T> class is designed to hold information about
|
||||
properties with the following semantics:
|
||||
|
||||
1. The property can be updated repeatedly at different
|
||||
timesteps; observe that the class does not support
|
||||
operator[] - only updates with weakly increasing timesteps
|
||||
are supported.
|
||||
|
||||
2. At any point in the time the previous last set value
|
||||
applies.
|
||||
|
||||
The class is very much tailored to support the Schedule file of
|
||||
Eclipse where a control applied at time T will apply
|
||||
indefinitely, or until explicitly set to a different value.
|
||||
|
||||
The update() method returns true if the updated value is
|
||||
different from the current value, this implies that the
|
||||
class<T> must support operator!=
|
||||
*/
|
||||
|
||||
|
||||
|
||||
template <class T>
|
||||
class DynamicState {
|
||||
public:
|
||||
@@ -88,27 +111,34 @@ namespace Opm {
|
||||
}
|
||||
|
||||
|
||||
void update(size_t index , T value) {
|
||||
/**
|
||||
If the current value has been changed the method will
|
||||
return true, otherwise it will return false.
|
||||
*/
|
||||
bool update(size_t index , T value) {
|
||||
bool change = (value != m_currentValue);
|
||||
if (index >= (m_timeMap->size()))
|
||||
throw std::range_error("Index value is out range.");
|
||||
|
||||
if (m_data.size() > 0) {
|
||||
if (m_data.size() > 0) {
|
||||
if (index < (m_data.size() - 1))
|
||||
throw std::invalid_argument("Elements must be added in weakly increasing order");
|
||||
}
|
||||
|
||||
{
|
||||
size_t currentSize = m_data.size();
|
||||
if (currentSize <= index) {
|
||||
for (size_t i = currentSize; i <= index; i++)
|
||||
m_data.push_back( m_currentValue );
|
||||
}
|
||||
}
|
||||
{
|
||||
size_t currentSize = m_data.size();
|
||||
if (currentSize <= index) {
|
||||
for (size_t i = currentSize; i <= index; i++)
|
||||
m_data.push_back( m_currentValue );
|
||||
}
|
||||
}
|
||||
|
||||
m_data[index] = value;
|
||||
m_currentValue = value;
|
||||
if (m_initialRange == 0)
|
||||
m_initialRange = index;
|
||||
m_data[index] = value;
|
||||
m_currentValue = value;
|
||||
if (m_initialRange == 0)
|
||||
m_initialRange = index;
|
||||
|
||||
return change;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ namespace Opm {
|
||||
}
|
||||
|
||||
void Group::setInjectionRate( size_t time_step , double rate) {
|
||||
return m_injection->rate->update( time_step , rate);
|
||||
m_injection->rate->update( time_step , rate);
|
||||
}
|
||||
|
||||
double Group::getInjectionRate( size_t time_step ) const {
|
||||
@@ -170,7 +170,7 @@ namespace Opm {
|
||||
}
|
||||
|
||||
void Group::setSurfaceMaxRate( size_t time_step , double rate) {
|
||||
return m_injection->surfaceFlowMaxRate->update( time_step , rate);
|
||||
m_injection->surfaceFlowMaxRate->update( time_step , rate);
|
||||
}
|
||||
|
||||
double Group::getSurfaceMaxRate( size_t time_step ) const {
|
||||
@@ -178,7 +178,7 @@ namespace Opm {
|
||||
}
|
||||
|
||||
void Group::setReservoirMaxRate( size_t time_step , double rate) {
|
||||
return m_injection->reservoirFlowMaxRate->update( time_step , rate);
|
||||
m_injection->reservoirFlowMaxRate->update( time_step , rate);
|
||||
}
|
||||
|
||||
double Group::getReservoirMaxRate( size_t time_step ) const {
|
||||
@@ -186,7 +186,7 @@ namespace Opm {
|
||||
}
|
||||
|
||||
void Group::setTargetReinjectFraction( size_t time_step , double rate) {
|
||||
return m_injection->targetReinjectFraction->update( time_step , rate);
|
||||
m_injection->targetReinjectFraction->update( time_step , rate);
|
||||
}
|
||||
|
||||
double Group::getTargetReinjectFraction( size_t time_step ) const {
|
||||
@@ -194,7 +194,7 @@ namespace Opm {
|
||||
}
|
||||
|
||||
void Group::setTargetVoidReplacementFraction( size_t time_step , double rate) {
|
||||
return m_injection->targetVoidReplacementFraction->update( time_step , rate);
|
||||
m_injection->targetVoidReplacementFraction->update( time_step , rate);
|
||||
}
|
||||
|
||||
double Group::getTargetVoidReplacementFraction( size_t time_step ) const {
|
||||
|
||||
@@ -16,4 +16,22 @@ namespace Opm {
|
||||
controlMode = WellInjector::CMODE_UNDEFINED;
|
||||
}
|
||||
|
||||
|
||||
bool WellInjectionProperties::operator==(const WellInjectionProperties& other) const {
|
||||
if ((surfaceInjectionRate == other.surfaceInjectionRate) &&
|
||||
(reservoirInjectionRate == other.reservoirInjectionRate) &&
|
||||
(BHPLimit == other.BHPLimit) &&
|
||||
(THPLimit == other.THPLimit) &&
|
||||
(predictionMode == other.predictionMode) &&
|
||||
(injectionControls == other.injectionControls) &&
|
||||
(injectorType == other.injectorType) &&
|
||||
(controlMode == other.controlMode))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WellInjectionProperties::operator!=(const WellInjectionProperties& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,10 @@ namespace Opm {
|
||||
WellInjector::TypeEnum injectorType;
|
||||
WellInjector::ControlModeEnum controlMode;
|
||||
|
||||
WellInjectionProperties();
|
||||
bool operator==(const WellInjectionProperties& other) const;
|
||||
bool operator!=(const WellInjectionProperties& other) const;
|
||||
|
||||
WellInjectionProperties();
|
||||
bool hasInjectionControl(WellInjector::ControlModeEnum controlModeArg) const {
|
||||
if (injectionControls & controlModeArg)
|
||||
return true;
|
||||
|
||||
@@ -9,4 +9,17 @@ namespace Opm {
|
||||
m_polymerConcentration = 0.0;
|
||||
m_saltConcentration = 0.0;
|
||||
}
|
||||
|
||||
bool WellPolymerProperties::operator==(const WellPolymerProperties& other) const {
|
||||
if ((m_polymerConcentration == other.m_polymerConcentration) &&
|
||||
(m_saltConcentration == other.m_saltConcentration))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
bool WellPolymerProperties::operator!=(const WellPolymerProperties& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ namespace Opm {
|
||||
double m_polymerConcentration;
|
||||
double m_saltConcentration;
|
||||
|
||||
bool operator==(const WellPolymerProperties& other) const;
|
||||
bool operator!=(const WellPolymerProperties& other) const;
|
||||
WellPolymerProperties();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -129,4 +129,27 @@ namespace Opm {
|
||||
|
||||
m_productionControls = 0;
|
||||
}
|
||||
|
||||
bool WellProductionProperties::operator==(const WellProductionProperties& other) const {
|
||||
if ((OilRate == other.OilRate) &&
|
||||
(WaterRate == other.WaterRate) &&
|
||||
(GasRate == other.GasRate) &&
|
||||
(LiquidRate == other.LiquidRate) &&
|
||||
(ResVRate == other.ResVRate) &&
|
||||
(BHPLimit == other.BHPLimit) &&
|
||||
(THPLimit == other.THPLimit) &&
|
||||
(VFPTableNumber == other.VFPTableNumber) &&
|
||||
(controlMode == other.controlMode) &&
|
||||
(m_productionControls == other.m_productionControls))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WellProductionProperties::operator!=(const WellProductionProperties& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Opm
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
#include <opm/parser/eclipse/Deck/DeckRecord.hpp>
|
||||
|
||||
namespace Opm {
|
||||
struct WellProductionProperties {
|
||||
class WellProductionProperties {
|
||||
public:
|
||||
double OilRate;
|
||||
double WaterRate;
|
||||
double GasRate;
|
||||
@@ -38,6 +39,8 @@ namespace Opm {
|
||||
|
||||
WellProducer::ControlModeEnum controlMode;
|
||||
|
||||
bool operator==(const WellProductionProperties& other) const;
|
||||
bool operator!=(const WellProductionProperties& other) const;
|
||||
WellProductionProperties();
|
||||
|
||||
static WellProductionProperties history(DeckRecordConstPtr record);
|
||||
|
||||
@@ -222,3 +222,16 @@ BOOST_AUTO_TEST_CASE( ResetGlobal ) {
|
||||
BOOST_CHECK_EQUAL( state[5] , 88 );
|
||||
BOOST_CHECK_EQUAL( state[9] , 88 );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( CheckReturn ) {
|
||||
boost::gregorian::date startDate( 2010 , boost::gregorian::Jan , 1);
|
||||
Opm::TimeMapPtr timeMap(new Opm::TimeMap(boost::posix_time::ptime(startDate)));
|
||||
Opm::DynamicState<int> state(timeMap , 137);
|
||||
for (size_t i = 0; i < 10; i++)
|
||||
timeMap->addTStep( boost::posix_time::hours( (i+1) * 24 ));
|
||||
|
||||
BOOST_CHECK_EQUAL( false , state.update( 0 , 137 ));
|
||||
BOOST_CHECK_EQUAL( false , state.update( 3 , 137 ));
|
||||
BOOST_CHECK_EQUAL( true , state.update( 5 , 200 ));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user