DeckItem: add indices to the methods which allow to query the defaulted status

also, this renames DeckItem::setInDeck() to DeckItem::wasSetInDeck()
because the former method can easily be confused with a setter method
(which it is not, it is a 'getter').

note that there is a small semantical difference now: the old
signatures specified the status of the whole *item* while the new
variants are specific for a single *data point* of an item. Though at
this point the index passed to the methods is still disregarded..
This commit is contained in:
Andreas Lauser
2014-09-09 14:35:54 +02:00
parent 09d9508c39
commit e6fa1e01a8
15 changed files with 76 additions and 85 deletions

View File

@@ -37,26 +37,17 @@ namespace Opm {
This function will return true if the item has been explicitly
set in the deck.
*/
bool DeckItem::setInDeck() const {
if ((m_valueStatus & DeckValue::SET_IN_DECK) == DeckValue::SET_IN_DECK)
return true;
else
return false;
bool DeckItem::wasSetInDeck(size_t /*index*/) const {
return (m_valueStatus & DeckValue::SET_IN_DECK) == DeckValue::SET_IN_DECK;
}
bool DeckItem::defaultApplied() const {
if ((m_valueStatus & DeckValue::DEFAULT) == DeckValue::DEFAULT)
return true;
else
return false;
bool DeckItem::defaultApplied(size_t /*index*/) const {
return (m_valueStatus & DeckValue::DEFAULT) == DeckValue::DEFAULT;
}
bool DeckItem::hasData() const {
if (m_valueStatus & (DeckValue::DEFAULT + DeckValue::SET_IN_DECK))
return true;
else
return false;
bool DeckItem::hasData(size_t index) const {
return defaultApplied(index) || wasSetInDeck(index);
}

View File

@@ -44,9 +44,9 @@ namespace Opm {
DeckItem(const std::string& name , bool m_scalar = true);
const std::string& name() const;
bool setInDeck() const;
bool defaultApplied() const;
bool hasData() const;
bool wasSetInDeck(size_t index) const;
bool defaultApplied(size_t index) const;
bool hasData(size_t index) const;
virtual size_t size() const = 0;

View File

@@ -85,13 +85,13 @@ BOOST_AUTO_TEST_CASE(sizeDouble_correct) {
BOOST_AUTO_TEST_CASE(SetInDeck) {
DeckDoubleItem deckDoubleItem("TEST");
BOOST_CHECK_EQUAL( false , deckDoubleItem.setInDeck() );
BOOST_CHECK_EQUAL( false , deckDoubleItem.wasSetInDeck(0) );
deckDoubleItem.push_backDefault( 1 );
BOOST_CHECK_EQUAL( false , deckDoubleItem.setInDeck() );
BOOST_CHECK_EQUAL( false , deckDoubleItem.wasSetInDeck(0) );
deckDoubleItem.push_back( 10 );
BOOST_CHECK_EQUAL( true , deckDoubleItem.setInDeck() );
BOOST_CHECK_EQUAL( true , deckDoubleItem.wasSetInDeck(0) );
deckDoubleItem.push_backDefault( 1 );
BOOST_CHECK_EQUAL( true , deckDoubleItem.setInDeck() );
BOOST_CHECK_EQUAL( true , deckDoubleItem.wasSetInDeck(0) );
}

View File

@@ -83,13 +83,13 @@ BOOST_AUTO_TEST_CASE(sizeFloat_correct) {
BOOST_AUTO_TEST_CASE(SetInDeck) {
DeckFloatItem deckFloatItem("TEST");
BOOST_CHECK_EQUAL( false , deckFloatItem.setInDeck() );
BOOST_CHECK_EQUAL( false , deckFloatItem.wasSetInDeck(0) );
deckFloatItem.push_backDefault( 1 );
BOOST_CHECK_EQUAL( false , deckFloatItem.setInDeck() );
BOOST_CHECK_EQUAL( false , deckFloatItem.wasSetInDeck(0) );
deckFloatItem.push_back( 10 );
BOOST_CHECK_EQUAL( true , deckFloatItem.setInDeck() );
BOOST_CHECK_EQUAL( true , deckFloatItem.wasSetInDeck(0) );
deckFloatItem.push_backDefault( 1 );
BOOST_CHECK_EQUAL( true , deckFloatItem.setInDeck() );
BOOST_CHECK_EQUAL( true , deckFloatItem.wasSetInDeck(0) );
}

View File

@@ -42,15 +42,15 @@ BOOST_AUTO_TEST_CASE(GetIntAtIndex_NoData_ExceptionThrown) {
BOOST_AUTO_TEST_CASE(InitializeDefaultApplied) {
DeckIntItem deckIntItem("TEST");
BOOST_REQUIRE_NO_THROW( deckIntItem.setInDeck() );
BOOST_CHECK( !deckIntItem.setInDeck());
BOOST_REQUIRE_NO_THROW( deckIntItem.wasSetInDeck(0) );
BOOST_CHECK( !deckIntItem.wasSetInDeck(0));
}
BOOST_AUTO_TEST_CASE(InitializeDefaultApplied_Throws_for_nonScalar) {
DeckIntItem deckIntItem("TEST" , false);
BOOST_REQUIRE_NO_THROW( deckIntItem.setInDeck() );
BOOST_CHECK( !deckIntItem.setInDeck());
BOOST_REQUIRE_NO_THROW( deckIntItem.wasSetInDeck(0) );
BOOST_CHECK( !deckIntItem.wasSetInDeck(0));
}
@@ -92,29 +92,29 @@ BOOST_AUTO_TEST_CASE(size_correct) {
BOOST_AUTO_TEST_CASE(SetInDeck) {
DeckIntItem deckIntItem("TEST");
BOOST_CHECK( !deckIntItem.setInDeck() );
BOOST_CHECK( !deckIntItem.wasSetInDeck(0) );
deckIntItem.push_back( 100 );
BOOST_CHECK( deckIntItem.setInDeck() );
BOOST_CHECK( deckIntItem.wasSetInDeck(0) );
}
BOOST_AUTO_TEST_CASE(SetInDeckData) {
DeckIntItem deckIntItem("TEST");
BOOST_CHECK_EQUAL( false , deckIntItem.setInDeck() );
BOOST_CHECK_EQUAL( false , deckIntItem.defaultApplied());
BOOST_CHECK_EQUAL( false , deckIntItem.hasData());
BOOST_CHECK_EQUAL( false , deckIntItem.wasSetInDeck(0) );
BOOST_CHECK_EQUAL( false , deckIntItem.defaultApplied(0));
BOOST_CHECK_EQUAL( false , deckIntItem.hasData(0));
deckIntItem.push_backDefault( 1 );
BOOST_CHECK_EQUAL( false , deckIntItem.setInDeck() );
BOOST_CHECK_EQUAL( true , deckIntItem.defaultApplied());
BOOST_CHECK_EQUAL( true , deckIntItem.hasData());
BOOST_CHECK_EQUAL( false , deckIntItem.wasSetInDeck(0) );
BOOST_CHECK_EQUAL( true , deckIntItem.defaultApplied(0));
BOOST_CHECK_EQUAL( true , deckIntItem.hasData(0));
deckIntItem.push_back( 10 );
BOOST_CHECK_EQUAL( true , deckIntItem.setInDeck() );
BOOST_CHECK_EQUAL( true , deckIntItem.defaultApplied());
BOOST_CHECK_EQUAL( true , deckIntItem.hasData());
BOOST_CHECK_EQUAL( true , deckIntItem.wasSetInDeck(0) );
BOOST_CHECK_EQUAL( true , deckIntItem.defaultApplied(0));
BOOST_CHECK_EQUAL( true , deckIntItem.hasData(0));
deckIntItem.push_backDefault( 1 );
BOOST_CHECK_EQUAL( true , deckIntItem.setInDeck() );
BOOST_CHECK_EQUAL( true , deckIntItem.hasData());
BOOST_CHECK_EQUAL( true , deckIntItem.wasSetInDeck(0) );
BOOST_CHECK_EQUAL( true , deckIntItem.hasData(0));
}

View File

@@ -75,13 +75,13 @@ BOOST_AUTO_TEST_CASE(size_variouspushes_sizecorrect) {
BOOST_AUTO_TEST_CASE(SetInDeckData) {
DeckStringItem deckStringItem("TEST");
BOOST_CHECK_EQUAL( false , deckStringItem.setInDeck() );
BOOST_CHECK_EQUAL( false , deckStringItem.wasSetInDeck(0) );
deckStringItem.push_backDefault( "Default" );
BOOST_CHECK_EQUAL( false , deckStringItem.setInDeck() );
BOOST_CHECK_EQUAL( false , deckStringItem.wasSetInDeck(0) );
deckStringItem.push_back( "Value" );
BOOST_CHECK_EQUAL( true , deckStringItem.setInDeck() );
BOOST_CHECK_EQUAL( true , deckStringItem.wasSetInDeck(0) );
deckStringItem.push_backDefault( "Deafult" );
BOOST_CHECK_EQUAL( true , deckStringItem.setInDeck() );
BOOST_CHECK_EQUAL( true , deckStringItem.wasSetInDeck(0) );
}

View File

@@ -671,22 +671,22 @@ namespace Opm {
size_t setCount = 0;
if (I1Item->setInDeck())
if (I1Item->wasSetInDeck(0))
setCount++;
if (I2Item->setInDeck())
if (I2Item->wasSetInDeck(0))
setCount++;
if (J1Item->setInDeck())
if (J1Item->wasSetInDeck(0))
setCount++;
if (J2Item->setInDeck())
if (J2Item->wasSetInDeck(0))
setCount++;
if (K1Item->setInDeck())
if (K1Item->wasSetInDeck(0))
setCount++;
if (K2Item->setInDeck())
if (K2Item->wasSetInDeck(0))
setCount++;
if (setCount == 6) {

View File

@@ -71,13 +71,13 @@ namespace Opm {
DeckItemConstPtr diameterItem = compdatRecord->getItem("DIAMETER");
DeckItemConstPtr skinFactorItem = compdatRecord->getItem("SKIN");
if (connectionTransmissibilityFactorItem->hasData())
if (connectionTransmissibilityFactorItem->hasData(0))
connectionTransmissibilityFactor.setValue( connectionTransmissibilityFactorItem->getSIDouble(0));
if (diameterItem->hasData())
if (diameterItem->hasData(0))
diameter.setValue( diameterItem->getSIDouble(0));
if (skinFactorItem->hasData())
if (skinFactorItem->hasData(0))
skinFactor.setValue( skinFactorItem->getRawDouble(0));
}

View File

@@ -158,7 +158,7 @@ namespace Opm {
if (well->getHeadJ() != record->getItem("HEAD_J")->getInt(0) - 1) {
throw std::invalid_argument("Unable process WELSPECS for well " + well->name() + ", HEAD_J deviates from existing value");
}
if (well->getRefDepthDefaulted() == record->getItem("REF_DEPTH")->setInDeck()) {
if (well->getRefDepthDefaulted() == record->getItem("REF_DEPTH")->wasSetInDeck(0)) {
throw std::invalid_argument("Unable process WELSPECS for well " + well->name() + ", REF_DEPTH defaulted state deviates from existing value");
}
if (!well->getRefDepthDefaulted()) {
@@ -243,21 +243,21 @@ namespace Opm {
properties.injectorType = injectorType;
properties.predictionMode = true;
if (record->getItem("RATE")->setInDeck()) {
if (record->getItem("RATE")->wasSetInDeck(0)) {
properties.surfaceInjectionRate = convertInjectionRateToSI(record->getItem("RATE")->getRawDouble(0) , injectorType, *deck->getActiveUnitSystem());
properties.addInjectionControl(WellInjector::RATE);
} else
properties.dropInjectionControl(WellInjector::RATE);
if (record->getItem("RESV")->setInDeck()) {
if (record->getItem("RESV")->wasSetInDeck(0)) {
properties.reservoirInjectionRate = convertInjectionRateToSI(record->getItem("RESV")->getRawDouble(0) , injectorType, *deck->getActiveUnitSystem());
properties.addInjectionControl(WellInjector::RESV);
} else
properties.dropInjectionControl(WellInjector::RESV);
if (record->getItem("THP")->setInDeck()) {
if (record->getItem("THP")->wasSetInDeck(0)) {
properties.THPLimit = record->getItem("THP")->getSIDouble(0);
properties.addInjectionControl(WellInjector::THP);
} else
@@ -271,7 +271,7 @@ namespace Opm {
do not do that.
*/
properties.BHPLimit = record->getItem("BHP")->getSIDouble(0);
if (record->getItem("BHP")->setInDeck()) {
if (record->getItem("BHP")->wasSetInDeck(0)) {
properties.addInjectionControl(WellInjector::BHP);
} else
properties.dropInjectionControl(WellInjector::BHP);
@@ -410,7 +410,7 @@ namespace Opm {
well->setGuideRate(currentStep, record->getItem("GUIDE_RATE")->getRawDouble(0));
if (record->getItem("PHASE")->setInDeck()) {
if (record->getItem("PHASE")->wasSetInDeck(0)) {
std::string guideRatePhase = record->getItem("PHASE")->getTrimmedString(0);
well->setGuideRatePhase(currentStep, GuideRate::GuideRatePhaseEnumFromString(guideRatePhase));
} else
@@ -454,7 +454,7 @@ namespace Opm {
Phase::PhaseEnum preferredPhase = Phase::PhaseEnumFromString(record->getItem("PHASE")->getTrimmedString(0));
WellPtr well;
if (record->getItem("REF_DEPTH")->setInDeck()) {
if (record->getItem("REF_DEPTH")->wasSetInDeck(0)) {
double refDepth = record->getItem("REF_DEPTH")->getSIDouble(0);
well = std::make_shared<Well>(wellName, headI, headJ, refDepth, preferredPhase, m_timeMap , timeStep);
} else {

View File

@@ -50,7 +50,7 @@ namespace Opm {
}
// BHP control must be explictly provided.
if (record->getItem("BHP")->setInDeck()) {
if (record->getItem("BHP")->wasSetInDeck(0)) {
p.addProductionControl(WellProducer::BHP);
}
@@ -78,7 +78,7 @@ namespace Opm {
mode = controlModes.begin(), end = controlModes.end();
mode != end; ++mode)
{
if (record->getItem(*mode)->setInDeck()) {
if (record->getItem(*mode)->wasSetInDeck(0)) {
const WellProducer::ControlModeEnum cmode =
WellProducer::ControlModeFromString(*mode);

View File

@@ -83,7 +83,7 @@ BOOST_AUTO_TEST_CASE( parse_DATAWithDefult_OK ) {
DeckItemConstPtr item2 = rec2->getItem(0);
BOOST_CHECK_EQUAL( 3U , keyword->size());
BOOST_CHECK( item0->setInDeck() );
BOOST_CHECK( item0->wasSetInDeck(0) );
BOOST_CHECK_EQUAL( 100 , item0->getRawDouble(0));
BOOST_CHECK_EQUAL( -1 , item0->getRawDouble(1));
@@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE( parse_DATAWithDefult_OK ) {
BOOST_CHECK_EQUAL( 100 , item1->getRawDouble(0));
BOOST_CHECK_EQUAL( -1 , item1->getRawDouble(1));
BOOST_CHECK( item2->setInDeck() );
BOOST_CHECK( item2->wasSetInDeck(0) );
}

View File

@@ -86,7 +86,7 @@ static void check_parser(ParserPtr parser) {
DeckItemConstPtr item2_0 = record2->getItem("GAS_PRESSURE");
DeckItemConstPtr item2_1 = record2->getItem("DATA");
BOOST_CHECK( !item2_0->setInDeck());
BOOST_CHECK( !item2_0->wasSetInDeck(0));
BOOST_CHECK_EQUAL(0U , item2_1->size());
BOOST_CHECK_EQUAL(2U , record2->size());

View File

@@ -86,7 +86,7 @@ static void check_parser(ParserPtr parser) {
DeckItemConstPtr item2_0 = record2->getItem("RS");
DeckItemConstPtr item2_1 = record2->getItem("DATA");
BOOST_CHECK(!item2_0->setInDeck());
BOOST_CHECK(!item2_0->wasSetInDeck(0));
BOOST_CHECK_EQUAL(0U , item2_1->size());
BOOST_CHECK_EQUAL(2U , record2->size());

View File

@@ -215,9 +215,9 @@ BOOST_AUTO_TEST_CASE(ParseWithDefault_defaultAppliedCorrectInDeck) {
DeckItemConstPtr deckIntItem = itemInt->scan(rawRecord);
DeckItemConstPtr deckDoubleItem = itemDouble->scan(rawRecord);
BOOST_CHECK(!deckStringItem->setInDeck());
BOOST_CHECK(!deckIntItem->setInDeck());
BOOST_CHECK(!deckDoubleItem->setInDeck());
BOOST_CHECK(!deckStringItem->wasSetInDeck(0));
BOOST_CHECK(!deckIntItem->wasSetInDeck(0));
BOOST_CHECK(!deckDoubleItem->wasSetInDeck(0));
}
@@ -227,9 +227,9 @@ BOOST_AUTO_TEST_CASE(ParseWithDefault_defaultAppliedCorrectInDeck) {
DeckItemConstPtr deckIntItem = itemInt->scan(rawRecord);
DeckItemConstPtr deckDoubleItem = itemDouble->scan(rawRecord);
BOOST_CHECK(!deckStringItem->setInDeck());
BOOST_CHECK(!deckIntItem->setInDeck());
BOOST_CHECK(!deckDoubleItem->setInDeck());
BOOST_CHECK(!deckStringItem->wasSetInDeck(0));
BOOST_CHECK(!deckIntItem->wasSetInDeck(0));
BOOST_CHECK(!deckDoubleItem->wasSetInDeck(0));
}
@@ -239,9 +239,9 @@ BOOST_AUTO_TEST_CASE(ParseWithDefault_defaultAppliedCorrectInDeck) {
DeckItemConstPtr deckIntItem = itemInt->scan(rawRecord);
DeckItemConstPtr deckDoubleItem = itemDouble->scan(rawRecord);
BOOST_CHECK(deckStringItem->setInDeck());
BOOST_CHECK(deckIntItem->setInDeck());
BOOST_CHECK(deckDoubleItem->setInDeck());
BOOST_CHECK(deckStringItem->wasSetInDeck(0));
BOOST_CHECK(deckIntItem->wasSetInDeck(0));
BOOST_CHECK(deckDoubleItem->wasSetInDeck(0));
}
@@ -251,9 +251,9 @@ BOOST_AUTO_TEST_CASE(ParseWithDefault_defaultAppliedCorrectInDeck) {
DeckItemConstPtr deckIntItem = itemInt->scan(rawRecord);
DeckItemConstPtr deckDoubleItem = itemDouble->scan(rawRecord);
BOOST_CHECK(!deckStringItem->setInDeck());
BOOST_CHECK(!deckIntItem->setInDeck());
BOOST_CHECK(!deckDoubleItem->setInDeck());
BOOST_CHECK(!deckStringItem->wasSetInDeck(0));
BOOST_CHECK(!deckIntItem->wasSetInDeck(0));
BOOST_CHECK(!deckDoubleItem->wasSetInDeck(0));
}
{
@@ -262,9 +262,9 @@ BOOST_AUTO_TEST_CASE(ParseWithDefault_defaultAppliedCorrectInDeck) {
DeckItemConstPtr deckIntItem = itemInt->scan(rawRecord);
DeckItemConstPtr deckDoubleItem = itemDouble->scan(rawRecord);
BOOST_CHECK(!deckStringItem->setInDeck());
BOOST_CHECK(!deckIntItem->setInDeck());
BOOST_CHECK(!deckDoubleItem->setInDeck());
BOOST_CHECK(!deckStringItem->wasSetInDeck(0));
BOOST_CHECK(!deckIntItem->wasSetInDeck(0));
BOOST_CHECK(!deckDoubleItem->wasSetInDeck(0));
}
}

View File

@@ -99,7 +99,7 @@ size_t MultiRecordTable::getNumFlatItems_(Opm::DeckRecordConstPtr deckRecord)
int result = 0;
for (unsigned i = 0; i < deckRecord->size(); ++ i) {
Opm::DeckItemConstPtr item(deckRecord->getItem(i));
if (i == 0 && !item->setInDeck())
if (i == 0 && !item->wasSetInDeck(0))
return result;
result += item->size();
}