From af8cab1a6450a12e23ce138c436102ae2109334c Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Fri, 7 Nov 2014 11:59:14 +0100 Subject: [PATCH 01/13] ParserKeyword: fix typos and improve exception messages --- opm/parser/eclipse/Parser/ParserKeyword.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/opm/parser/eclipse/Parser/ParserKeyword.cpp b/opm/parser/eclipse/Parser/ParserKeyword.cpp index 70be832ef..b38ad1f9b 100644 --- a/opm/parser/eclipse/Parser/ParserKeyword.cpp +++ b/opm/parser/eclipse/Parser/ParserKeyword.cpp @@ -528,13 +528,12 @@ namespace Opm { keyword->setDataKeyword( isDataKeyword() ); return keyword; } else - throw std::invalid_argument("Tried to create a deck keyword from an imcomplete rawkeyword: " + rawKeyword->getKeywordName()); + throw std::invalid_argument("Tried to create a deck keyword from an incomplete raw keyword " + rawKeyword->getKeywordName()); } size_t ParserKeyword::getFixedSize() const { - if (!hasFixedSize()) { - throw std::logic_error("This parser keyword does not have a fixed size!"); - } + if (!hasFixedSize()) + throw std::logic_error("The parser keyword "+getName()+" does not have a fixed size!"); return m_fixedSize; } From e424017a319801b00743fde9d9cdc61b6ff94f75 Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Fri, 7 Nov 2014 12:00:02 +0100 Subject: [PATCH 02/13] grid property modifier keywords: make the box specifiers optional for all of them this means adding defaults to EQUALS and COPY. While at it use -1 as the default value for boxes in all of these keywords... --- opm/parser/share/keywords/A/ADD | 12 ++++++------ opm/parser/share/keywords/C/COPY | 12 ++++++------ opm/parser/share/keywords/E/EQUALS | 12 ++++++------ opm/parser/share/keywords/M/MULTIPLY | 12 ++++++------ 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/opm/parser/share/keywords/A/ADD b/opm/parser/share/keywords/A/ADD index a39da0ec0..e86dfa002 100644 --- a/opm/parser/share/keywords/A/ADD +++ b/opm/parser/share/keywords/A/ADD @@ -1,10 +1,10 @@ {"name" : "ADD", "sections" : ["GRID", "EDIT", "PROPS", "REGIONS", "SOLUTION"], "items" : [ {"name" : "field" , "value_type" : "STRING"}, {"name" : "shift" , "value_type" : "DOUBLE"}, - {"name" : "I1" , "value_type" : "INT", "default" : 0}, - {"name" : "I2" , "value_type" : "INT", "default" : 0}, - {"name" : "J1" , "value_type" : "INT", "default" : 0}, - {"name" : "J2" , "value_type" : "INT", "default" : 0}, - {"name" : "K1" , "value_type" : "INT", "default" : 0}, - {"name" : "K2" , "value_type" : "INT", "default" : 0}]} + {"name" : "I1" , "value_type" : "INT", "default" : -1}, + {"name" : "I2" , "value_type" : "INT", "default" : -1}, + {"name" : "J1" , "value_type" : "INT", "default" : -1}, + {"name" : "J2" , "value_type" : "INT", "default" : -1}, + {"name" : "K1" , "value_type" : "INT", "default" : -1}, + {"name" : "K2" , "value_type" : "INT", "default" : -1}]} diff --git a/opm/parser/share/keywords/C/COPY b/opm/parser/share/keywords/C/COPY index b34486193..1490b56d9 100644 --- a/opm/parser/share/keywords/C/COPY +++ b/opm/parser/share/keywords/C/COPY @@ -1,10 +1,10 @@ {"name" : "COPY" , "sections" : ["GRID", "EDIT", "PROPS", "REGIONS", "SOLUTION"], "items" : [ {"name" : "src", "value_type" : "STRING"}, {"name" : "target", "value_type" : "STRING"}, - {"name" : "I1" , "value_type" : "INT"}, - {"name" : "I2" , "value_type" : "INT"}, - {"name" : "J1" , "value_type" : "INT"}, - {"name" : "J2" , "value_type" : "INT"}, - {"name" : "K1" , "value_type" : "INT"}, - {"name" : "K2" , "value_type" : "INT"}]} + {"name" : "I1" , "value_type" : "INT", "default": -1}, + {"name" : "I2" , "value_type" : "INT", "default": -1}, + {"name" : "J1" , "value_type" : "INT", "default": -1}, + {"name" : "J2" , "value_type" : "INT", "default": -1}, + {"name" : "K1" , "value_type" : "INT", "default": -1}, + {"name" : "K2" , "value_type" : "INT", "default": -1}]} diff --git a/opm/parser/share/keywords/E/EQUALS b/opm/parser/share/keywords/E/EQUALS index 1840a0482..9a6b30bd4 100644 --- a/opm/parser/share/keywords/E/EQUALS +++ b/opm/parser/share/keywords/E/EQUALS @@ -1,9 +1,9 @@ {"name" : "EQUALS", "sections" : ["GRID", "EDIT", "PROPS", "REGIONS", "SOLUTION"], "items" : [ {"name" : "field" , "value_type" : "STRING"}, {"name" : "value" , "value_type" : "DOUBLE"}, - {"name" : "I1" , "value_type" : "INT"}, - {"name" : "I2" , "value_type" : "INT"}, - {"name" : "J1" , "value_type" : "INT"}, - {"name" : "J2" , "value_type" : "INT"}, - {"name" : "K1" , "value_type" : "INT"}, - {"name" : "K2" , "value_type" : "INT"}]} \ No newline at end of file + {"name" : "I1" , "value_type" : "INT", "default": -1}, + {"name" : "I2" , "value_type" : "INT", "default": -1}, + {"name" : "J1" , "value_type" : "INT", "default": -1}, + {"name" : "J2" , "value_type" : "INT", "default": -1}, + {"name" : "K1" , "value_type" : "INT", "default": -1}, + {"name" : "K2" , "value_type" : "INT", "default": -1}]} diff --git a/opm/parser/share/keywords/M/MULTIPLY b/opm/parser/share/keywords/M/MULTIPLY index f584e7ebe..fa1a71a83 100644 --- a/opm/parser/share/keywords/M/MULTIPLY +++ b/opm/parser/share/keywords/M/MULTIPLY @@ -1,9 +1,9 @@ {"name" : "MULTIPLY", "sections" : ["GRID", "EDIT", "PROPS", "REGIONS", "SOLUTION"], "items" : [ {"name" : "field" , "value_type" : "STRING"}, {"name" : "factor" , "value_type" : "DOUBLE"}, - {"name" : "I1" , "value_type" : "INT" , "default" : 0}, - {"name" : "I2" , "value_type" : "INT" , "default" : 0}, - {"name" : "J1" , "value_type" : "INT" , "default" : 0}, - {"name" : "J2" , "value_type" : "INT" , "default" : 0}, - {"name" : "K1" , "value_type" : "INT" , "default" : 0}, - {"name" : "K2" , "value_type" : "INT" , "default" : 0}]} + {"name" : "I1" , "value_type" : "INT" , "default" : -1}, + {"name" : "I2" , "value_type" : "INT" , "default" : -1}, + {"name" : "J1" , "value_type" : "INT" , "default" : -1}, + {"name" : "J2" , "value_type" : "INT" , "default" : -1}, + {"name" : "K1" , "value_type" : "INT" , "default" : -1}, + {"name" : "K2" , "value_type" : "INT" , "default" : -1}]} From 4e293ee3e68646d1addc8c4c42651f944131bc06 Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Wed, 22 Oct 2014 13:01:40 +0200 Subject: [PATCH 03/13] EclipseState: make it instantiable without a grid instead of throwing, we now add a warning to the parser log... --- .../eclipse/EclipseState/EclipseState.cpp | 33 +++++++++--- .../eclipse/EclipseState/EclipseState.hpp | 1 + .../EclipseState/tests/EclipseStateTests.cpp | 50 +++++++++++++++---- opm/parser/eclipse/Parser/ParserKeyword.cpp | 2 +- 4 files changed, 69 insertions(+), 17 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/EclipseState.cpp b/opm/parser/eclipse/EclipseState/EclipseState.cpp index 388795146..bdce6e0fa 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.cpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.cpp @@ -116,20 +116,36 @@ namespace Opm { initPhases(deck, parserLog); initTables(deck, parserLog); - initEclipseGrid(deck, parserLog); initSchedule(deck, parserLog); initTitle(deck, parserLog); - initProperties(deck, parserLog); - initTransMult(parserLog); - initFaults(deck, parserLog); - initMULTREGT(deck, parserLog); + + initEclipseGrid(deck, parserLog); + + if (hasEclipseGrid()) { + initProperties(deck, parserLog); + initTransMult(parserLog); + initFaults(deck, parserLog); + initMULTREGT(deck, parserLog); + } + else { + std::string msg("Grid could not be initialized. Skipping grid properties, " + "faults, as well as transmissibility and region multipliers."); + parserLog->addWarning("", -1, msg); + } } std::shared_ptr EclipseState::getDeckUnitSystem() const { return m_deckUnitSystem; } + bool EclipseState::hasEclipseGrid() const { + return static_cast(m_eclipseGrid); + } + EclipseGridConstPtr EclipseState::getEclipseGrid() const { + if (!hasEclipseGrid()) + throw std::logic_error("The eclipse grid object cannot be retrieved if no grid is featured by the deck."); + return m_eclipseGrid; } @@ -357,7 +373,12 @@ namespace Opm { void EclipseState::initEclipseGrid(DeckConstPtr deck, ParserLogPtr parserLog) { - m_eclipseGrid = EclipseGridConstPtr( new EclipseGrid(deck, parserLog)); + try { + m_eclipseGrid = EclipseGridConstPtr( new EclipseGrid(deck, parserLog)); + } catch (const std::exception& e) { + std::string msg("Could not create a grid: "+std::string(e.what())); + parserLog->addWarning("", -1, msg); + } } diff --git a/opm/parser/eclipse/EclipseState/EclipseState.hpp b/opm/parser/eclipse/EclipseState/EclipseState.hpp index a6586ae4c..ca8f8c320 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.hpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.hpp @@ -67,6 +67,7 @@ namespace Opm { EclipseState(DeckConstPtr deck, ParserLogPtr parserLog = std::make_shared(&std::cout)); ScheduleConstPtr getSchedule() const; + bool hasEclipseGrid() const; EclipseGridConstPtr getEclipseGrid() const; EclipseGridPtr getEclipseGridCopy() const; bool hasPhase(enum Phase::PhaseEnum phase) const; diff --git a/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp b/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp index 208193474..d5e4f29eb 100644 --- a/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp +++ b/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp @@ -112,6 +112,24 @@ BOOST_AUTO_TEST_CASE(GetPOROTOPBased) { } +static DeckPtr createEmptyDeck() { + const char *deckData = + ""; + + ParserPtr parser(new Parser()); + return parser->parseString(deckData) ; +} + +static DeckPtr createDeckWithoutGrid() { + const char *deckData = + "PROPS\n" + "EQUALS\n" + "'PERMX' 1.23 /\n" + "/\n"; + + ParserPtr parser(new Parser()); + return parser->parseString(deckData) ; +} static DeckPtr createDeck() { const char *deckData = @@ -197,16 +215,7 @@ static DeckPtr createDeckNoFaults() { return parser->parseString(deckData) ; } -BOOST_AUTO_TEST_CASE(StrictSemantics) { - DeckPtr deck = createDeck(); - EclipseState state(deck); - - // the deck misses a few sections... - ParserLogPtr parserLog(new ParserLog()); - BOOST_CHECK(!checkDeck(deck, parserLog)); -} - -BOOST_AUTO_TEST_CASE(CreatSchedule) { +BOOST_AUTO_TEST_CASE(CreateSchedule) { DeckPtr deck = createDeck(); EclipseState state(deck); ScheduleConstPtr schedule = state.getSchedule(); @@ -234,6 +243,27 @@ BOOST_AUTO_TEST_CASE(TitleCorrect) { BOOST_CHECK_EQUAL( state.getTitle(), "The title"); } +BOOST_AUTO_TEST_CASE(SupportsEmptyDeck) { + DeckPtr deck = createEmptyDeck(); + ParserLogPtr parserLog(new ParserLog); + BOOST_CHECK_NO_THROW(EclipseState(deck, parserLog)); + + // we need to get two warnings: The first that no grid could be + // instantiated, the second that grid properties (et al.) are + // skipped... + BOOST_CHECK_EQUAL(parserLog->numWarnings(), 2); +} + +BOOST_AUTO_TEST_CASE(SupportsDeckWithoutGrid) { + DeckPtr deck = createDeckWithoutGrid(); + ParserLogPtr parserLog(new ParserLog); + BOOST_CHECK_NO_THROW(EclipseState(deck, parserLog)); + + // we need to get two warnings: The first that no grid could be + // instantiated, the second that grid properties (et al.) are + // skipped... + BOOST_CHECK_EQUAL(parserLog->numWarnings(), 2); +} BOOST_AUTO_TEST_CASE(IntProperties) { DeckPtr deck = createDeck(); diff --git a/opm/parser/eclipse/Parser/ParserKeyword.cpp b/opm/parser/eclipse/Parser/ParserKeyword.cpp index b38ad1f9b..28d9c6b00 100644 --- a/opm/parser/eclipse/Parser/ParserKeyword.cpp +++ b/opm/parser/eclipse/Parser/ParserKeyword.cpp @@ -520,7 +520,7 @@ namespace Opm { DeckKeywordPtr ParserKeyword::parse(RawKeywordConstPtr rawKeyword) const { if (rawKeyword->isFinished()) { DeckKeywordPtr keyword(new DeckKeyword(rawKeyword->getKeywordName())); - keyword->setLocation(rawKeyword->getFilename(), rawKeyword->getLineNR()); + keyword->setLocation(rawKeyword->getFilename(), rawKeyword->getLineNR()); for (size_t i = 0; i < rawKeyword->size(); i++) { DeckRecordConstPtr deckRecord = m_record->parse(rawKeyword->getRecord(i)); keyword->addRecord(deckRecord); From a7ba8af558c959fd2c620f2d2f397a7e6d0f2dac Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Sun, 9 Nov 2014 17:37:32 +0100 Subject: [PATCH 04/13] EclipseState: make specifying anything which requires a grid an error if no grid could be instantiated --- .../eclipse/EclipseState/EclipseState.cpp | 83 ++++++++++++++----- .../EclipseState/Grid/GridProperties.hpp | 18 ++-- .../Grid/tests/GridPropertiesTests.cpp | 6 +- .../Grid/tests/GridPropertyTests.cpp | 2 +- .../Grid/tests/MULTREGTScannerTests.cpp | 4 +- .../EclipseState/tests/EclipseStateTests.cpp | 13 +-- 6 files changed, 79 insertions(+), 47 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/EclipseState.cpp b/opm/parser/eclipse/EclipseState/EclipseState.cpp index bdce6e0fa..98482cfa3 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.cpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.cpp @@ -121,17 +121,10 @@ namespace Opm { initEclipseGrid(deck, parserLog); - if (hasEclipseGrid()) { - initProperties(deck, parserLog); - initTransMult(parserLog); - initFaults(deck, parserLog); - initMULTREGT(deck, parserLog); - } - else { - std::string msg("Grid could not be initialized. Skipping grid properties, " - "faults, as well as transmissibility and region multipliers."); - parserLog->addWarning("", -1, msg); - } + initProperties(deck, parserLog); + initTransMult(parserLog); + initFaults(deck, parserLog); + initMULTREGT(deck, parserLog); } std::shared_ptr EclipseState::getDeckUnitSystem() const { @@ -266,6 +259,12 @@ namespace Opm { } void EclipseState::initTransMult(ParserLogPtr /*parserLog*/) { + if (!hasEclipseGrid()) + // no checking required here as the class will already + // refrain from processing the MULT* grid properties if no + // grid is available... + return; + EclipseGridConstPtr grid = getEclipseGrid(); m_transMult = std::make_shared( grid->getNX() , grid->getNY() , grid->getNZ()); @@ -286,6 +285,16 @@ namespace Opm { } void EclipseState::initFaults(DeckConstPtr deck, ParserLogPtr parserLog) { + if (!hasEclipseGrid()) { + if (deck->hasKeyword("FAULTS") || + deck->hasKeyword("MULTFAULT")) + { + throw std::logic_error("Grid could not be initialized, but fault transmissibility multipliers have been detected."); + } + else + return; + } + EclipseGridConstPtr grid = getEclipseGrid(); m_faults = std::make_shared(); std::shared_ptr gridSection(new Opm::GRIDSection(deck) ); @@ -347,6 +356,14 @@ namespace Opm { void EclipseState::initMULTREGT(DeckConstPtr deck, ParserLogPtr /*parserLog*/) { + if (!hasEclipseGrid()) { + if (deck->hasKeyword("MULTREGT")) { + throw std::logic_error("Grid could not be initialized, but region transmissibility multipliers have been detected."); + } + else + return; + } + EclipseGridConstPtr grid = getEclipseGrid(); std::shared_ptr scanner = std::make_shared(); @@ -525,7 +542,6 @@ namespace Opm { } - void EclipseState::initProperties(DeckConstPtr deck, ParserLogPtr parserLog) { typedef GridProperties::SupportedKeywordInfo SupportedIntKeywordInfo; std::shared_ptr > supportedIntKeywords(new std::vector{ @@ -716,18 +732,39 @@ namespace Opm { SupportedDoubleKeywordInfo( "SWATINIT" , 0.0, "1") }); - // create the grid properties - m_intGridProperties = std::make_shared >(m_eclipseGrid->getNX(), - m_eclipseGrid->getNY(), - m_eclipseGrid->getNZ(), - supportedIntKeywords); - m_doubleGridProperties = std::make_shared >(m_eclipseGrid->getNX(), - m_eclipseGrid->getNY(), - m_eclipseGrid->getNZ(), - supportedDoubleKeywords); + // register the grid properties + m_intGridProperties = std::make_shared >(m_eclipseGrid.get(), supportedIntKeywords); + m_doubleGridProperties = std::make_shared >(m_eclipseGrid.get(), supportedDoubleKeywords); - // first process all integer grid properties as these may be needed in order to - // initialize the double properties + if (!hasEclipseGrid()) { + // make sure that no grid properties are specified by the deck + for (size_t kwIdx = 0; kwIdx < deck->size(); ++ kwIdx) { + const std::string& kwName = deck->getKeyword(kwIdx)->name(); + if (supportsGridProperty(kwName)) + throw std::logic_error("Grid could not be initialized, but grid property " + kwName + " has been detected."); + } + + // make sure that no grid property modifier keywords + // (which can make grid properties appear out of thin air) + // are present in the deck. + if (deck->hasKeyword("ADD") || + deck->hasKeyword("BOX") || + deck->hasKeyword("COPY") || + deck->hasKeyword("EQUALS") || + deck->hasKeyword("MULTIPLY")) + { + throw std::logic_error("Grid could not be initialized, but grid properties have been detected."); + } + + // if we don't have a grid and also no grid properties, we + // just skip this method. + return; + } + + // actually create the grid property objects. we need to first + // process all integer grid properties before the double ones + // as these may be needed in order to initialize the double + // properties processGridProperties(deck, parserLog, /*enabledTypes=*/IntProperties); processGridProperties(deck, parserLog, /*enabledTypes=*/DoubleProperties); } diff --git a/opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp b/opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp index d6e2213ac..0b95671b6 100644 --- a/opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp @@ -25,6 +25,7 @@ #include #include +#include #include /* @@ -51,12 +52,9 @@ class GridProperties { public: typedef typename GridProperty::SupportedKeywordInfo SupportedKeywordInfo; - GridProperties(size_t nx , size_t ny , size_t nz , - std::shared_ptr > supportedKeywords) { - m_nx = nx; - m_ny = ny; - m_nz = nz; - + GridProperties(const EclipseGrid* eclipseGrid, std::shared_ptr > supportedKeywords) { + m_eclipseGrid = eclipseGrid; + for (auto iter = supportedKeywords->begin(); iter != supportedKeywords->end(); ++iter) m_supportedKeywords[iter->getKeywordName()] = *iter; } @@ -78,7 +76,6 @@ public: return m_properties.at( keyword ); } - bool addKeyword(const std::string& keywordName) { if (!supportsKeyword( keywordName )) throw std::invalid_argument("The keyword: " + keywordName + " is not supported in this container"); @@ -87,7 +84,10 @@ public: return false; else { auto supportedKeyword = m_supportedKeywords.at( keywordName ); - std::shared_ptr > newProperty(new GridProperty(m_nx , m_ny , m_nz , supportedKeyword)); + int nx = m_eclipseGrid->getNX(); + int ny = m_eclipseGrid->getNY(); + int nz = m_eclipseGrid->getNZ(); + std::shared_ptr > newProperty(new GridProperty(nx , ny , nz , supportedKeyword)); m_properties.insert( std::pair > > ( keywordName , newProperty )); return true; @@ -96,7 +96,7 @@ public: private: - size_t m_nx, m_ny, m_nz; + const EclipseGrid* m_eclipseGrid; std::unordered_map m_supportedKeywords; std::map > > m_properties; }; diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertiesTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertiesTests.cpp index 954e16fed..81884d4eb 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertiesTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertiesTests.cpp @@ -41,7 +41,7 @@ BOOST_AUTO_TEST_CASE(Empty) { SupportedKeywordInfo("SATNUM" , 0, "1"), SupportedKeywordInfo("FIPNUM" , 2, "1") }); - Opm::GridProperties gridProperties( 10, 10, 100 , supportedKeywords); + Opm::GridProperties gridProperties( NULL , supportedKeywords); BOOST_CHECK( gridProperties.supportsKeyword("SATNUM") ); BOOST_CHECK( gridProperties.supportsKeyword("FIPNUM") ); @@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(addKeyword) { std::shared_ptr > supportedKeywords(new std::vector{ SupportedKeywordInfo("SATNUM" , 0, "1") }); - Opm::GridProperties gridProperties( 100, 10 , 10 , supportedKeywords); + Opm::GridProperties gridProperties( NULL , supportedKeywords); BOOST_CHECK_THROW( gridProperties.addKeyword("NOT-SUPPORTED") , std::invalid_argument); @@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE(getKeyword) { std::shared_ptr > supportedKeywords(new std::vector{ SupportedKeywordInfo("SATNUM" , 0, "1") }); - Opm::GridProperties gridProperties( 100,25,4 , supportedKeywords); + Opm::GridProperties gridProperties( NULL , supportedKeywords); std::shared_ptr > satnum1 = gridProperties.getKeyword("SATNUM"); std::shared_ptr > satnum2 = gridProperties.getKeyword("SATNUM"); diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp index 8f207d7ca..c87a616d4 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp @@ -427,9 +427,9 @@ BOOST_AUTO_TEST_CASE(GridPropertyPostProcessors) { SupportedKeywordInfo kwInfo2("PORO" , 1.0 , testPostP , "1"); std::shared_ptr > supportedKeywords(new std::vector{ kwInfo1 , kwInfo2 }); - Opm::GridProperties properties(10,10,10,supportedKeywords); Opm::DeckPtr deck = createDeck(); Opm::EclipseGrid grid(deck); + Opm::GridProperties properties(&grid, supportedKeywords); { auto poro = properties.getKeyword("PORO"); diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/MULTREGTScannerTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/MULTREGTScannerTests.cpp index 788889158..b788d4dc9 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/MULTREGTScannerTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/MULTREGTScannerTests.cpp @@ -115,7 +115,7 @@ BOOST_AUTO_TEST_CASE(InvalidInput) { Opm::MULTREGTScanner scanner; Opm::DeckPtr deck = createInvalidMULTREGTDeck(); Opm::EclipseGrid grid(deck); - std::shared_ptr > gridProperties = std::make_shared >( grid.getNX() , grid.getNY() , grid.getNZ() , supportedKeywords); + std::shared_ptr > gridProperties = std::make_shared >(&grid, supportedKeywords); Opm::DeckKeywordConstPtr multregtKeyword0 = deck->getKeyword("MULTREGT",0); Opm::DeckKeywordConstPtr multregtKeyword1 = deck->getKeyword("MULTREGT",1); Opm::DeckKeywordConstPtr multregtKeyword2 = deck->getKeyword("MULTREGT",2); @@ -254,7 +254,7 @@ BOOST_AUTO_TEST_CASE(SimpleMULTREGT) { Opm::EclipseGrid grid(deck); std::shared_ptr inputBox = std::make_shared( grid.getNX() , grid.getNY() , grid.getNZ() ); - std::shared_ptr > gridProperties = std::make_shared >( grid.getNX() , grid.getNY() , grid.getNZ() , supportedKeywords); + std::shared_ptr > gridProperties = std::make_shared >(&grid, supportedKeywords); std::shared_ptr > fluxNum = gridProperties->getKeyword("FLUXNUM"); std::shared_ptr > multNum = gridProperties->getKeyword("MULTNUM"); Opm::DeckKeywordConstPtr fluxnumKeyword = deck->getKeyword("FLUXNUM",0); diff --git a/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp b/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp index d5e4f29eb..ef12c2455 100644 --- a/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp +++ b/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp @@ -248,21 +248,16 @@ BOOST_AUTO_TEST_CASE(SupportsEmptyDeck) { ParserLogPtr parserLog(new ParserLog); BOOST_CHECK_NO_THROW(EclipseState(deck, parserLog)); - // we need to get two warnings: The first that no grid could be - // instantiated, the second that grid properties (et al.) are - // skipped... - BOOST_CHECK_EQUAL(parserLog->numWarnings(), 2); + // we need to get a warning because no grid could be instantiated + BOOST_CHECK_EQUAL(parserLog->numWarnings(), 1); } BOOST_AUTO_TEST_CASE(SupportsDeckWithoutGrid) { DeckPtr deck = createDeckWithoutGrid(); ParserLogPtr parserLog(new ParserLog); - BOOST_CHECK_NO_THROW(EclipseState(deck, parserLog)); - // we need to get two warnings: The first that no grid could be - // instantiated, the second that grid properties (et al.) are - // skipped... - BOOST_CHECK_EQUAL(parserLog->numWarnings(), 2); + // specifying grid properties without a grid is not supported! + BOOST_CHECK_THROW(EclipseState(deck, parserLog), std::logic_error); } BOOST_AUTO_TEST_CASE(IntProperties) { From 39bca17ce0f873dacb8e4e3b5028ac284ca69929 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Sun, 9 Nov 2014 23:31:53 +0100 Subject: [PATCH 05/13] Split EclipseGrid in dimensions and cell info. In many cases the only required information in an EclipseGrid instance is the cartesian dimensions. To facilitate simpler testing - and not have to create a full dummy grid the dimensions have been internalized as a separate nx,ny,nz triplet. With this commit it is possible to instantiate a grid with only dimensions, and no underlying ecl_grid_type pointer. --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 53 +++++++++++++++---- .../eclipse/EclipseState/Grid/EclipseGrid.hpp | 35 ++++++++++++ .../Grid/tests/EclipseGridTests.cpp | 46 +++++++++++++++- 3 files changed, 122 insertions(+), 12 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp index 34b3f9959..49af62bba 100644 --- a/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -43,6 +43,10 @@ namespace Opm { m_grid.reset( new_ptr , ecl_grid_free ); else throw std::invalid_argument("Could not load grid from binary file: " + filename); + + m_nx = static_cast( ecl_grid_get_nx( m_grid.get() )); + m_ny = static_cast( ecl_grid_get_ny( m_grid.get() )); + m_nz = static_cast( ecl_grid_get_nz( m_grid.get() )); } EclipseGrid::EclipseGrid(const ecl_grid_type * src_ptr) @@ -50,6 +54,26 @@ namespace Opm { m_pinch("PINCH") { m_grid.reset( ecl_grid_alloc_copy( src_ptr ) , ecl_grid_free ); + + m_nx = static_cast( ecl_grid_get_nx( m_grid.get() )); + m_ny = static_cast( ecl_grid_get_ny( m_grid.get() )); + m_nz = static_cast( ecl_grid_get_nz( m_grid.get() )); + } + + /* + This creates a grid which only has dimension, and no pointer to + a true grid structure. This grid will answer false to + hasCellInfo() - but can be used in all situations where the grid + dependency is really only on the dimensions. + */ + + EclipseGrid::EclipseGrid(size_t nx, size_t ny , size_t nz) + : m_minpv("MINPV"), + m_pinch("PINCH") + { + m_nx = nx; + m_ny = ny; + m_nz = nz; } @@ -116,16 +140,16 @@ namespace Opm { void EclipseGrid::initGrid( const std::vector& dims, DeckConstPtr deck, ParserLogPtr parserLog) { + m_nx = static_cast(dims[0]); + m_ny = static_cast(dims[1]); + m_nz = static_cast(dims[2]); + if (hasCornerPointKeywords(deck)) { initCornerPointGrid(dims , deck, parserLog); } else if (hasCartesianKeywords(deck)) { initCartesianGrid(dims , deck); - } else { - const std::string msg = "The deck must have COORD / ZCORN or D?? + TOPS keywords"; - parserLog->addError("", -1, msg); - throw std::invalid_argument(msg); - } - + } + if (deck->hasKeyword("PINCH")) { m_pinch.setValue( deck->getKeyword("PINCH")->getRecord(0)->getItem("THRESHOLD_THICKNESS")->getSIDouble(0) ); } @@ -149,21 +173,30 @@ namespace Opm { } size_t EclipseGrid::getNX( ) const { - return static_cast(ecl_grid_get_nx( m_grid.get() )); + return m_nx; } size_t EclipseGrid::getNY( ) const { - return static_cast(ecl_grid_get_ny( m_grid.get() )); + return m_ny; } size_t EclipseGrid::getNZ( ) const { - return static_cast(ecl_grid_get_nz( m_grid.get() )); + return m_nz; } size_t EclipseGrid::getCartesianSize( ) const { - return static_cast( ecl_grid_get_global_size( m_grid.get() )); + return m_nx * m_ny * m_nz; } + /* + This function checks if the grid has a pointer to an underlying + ecl_grid_type; which must be used to read cell info as + size/depth/active of individual cells. + */ + bool EclipseGrid::hasCellInfo() const { + return static_cast( m_grid ); + } + bool EclipseGrid::isPinchActive( ) const { return m_pinch.hasValue(); } diff --git a/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp index 5b0d10936..9eda6e242 100644 --- a/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -33,10 +33,41 @@ namespace Opm { + /** + About cell information and dimension: The actual grid + information is held in a pointer to an ERT ecl_grid_type + instance. This pointer must be used for access to all cell + related properties, including: + + - Size of cells + - Real world position of cells + - Active/inactive status of cells + + However in may cases the only required information is the + dimension of the grid. To facilitate simpler use, in particular + in testing, the grid dimensions are internalized separate from + the ecl_grid_type pointer. This means that in many cases a grid + without the underlying ecl_grid_type pointer is sufficient. To + create such a 'naked' grid you can parse a deck with only + DIMENS / SPECGRID and no further grid related keywords, or + alternatively use the: + + EclipseGrid::EclipseGrid(nx,ny,nz) + + constructor. + + To query a grid instance if it has proper underlying grid + support use the method: + + bool EclipseGrid::hasCellInfo(); + + */ + class EclipseGrid { public: explicit EclipseGrid(const std::string& filename); explicit EclipseGrid(const ecl_grid_type * src_ptr); + explicit EclipseGrid(size_t nx, size_t ny , size_t nz); explicit EclipseGrid(std::shared_ptr deck, ParserLogPtr parserLog = std::make_shared()); static bool hasCornerPointKeywords(std::shared_ptr deck); @@ -50,6 +81,7 @@ namespace Opm { double getPinchThresholdThickness( ) const; bool isMinpvActive( ) const; double getMinpvValue( ) const; + bool hasCellInfo() const; void assertGlobalIndex(size_t globalIndex) const; void assertIJK(size_t i , size_t j , size_t k) const; @@ -70,6 +102,9 @@ namespace Opm { std::shared_ptr m_grid; Value m_minpv; Value m_pinch; + size_t m_nx; + size_t m_ny; + size_t m_nz; void initCartesianGrid(const std::vector& dims , DeckConstPtr deck); void initCornerPointGrid(const std::vector& dims , DeckConstPtr deck, ParserLogPtr parserLog); diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/EclipseGridTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/EclipseGridTests.cpp index 5717145bd..1adedb297 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/EclipseGridTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/EclipseGridTests.cpp @@ -65,6 +65,23 @@ static Opm::DeckPtr createDeckHeaders() { } +static Opm::DeckPtr createDeckMissingDIMS() { + const char *deckData = + "RUNSPEC\n" + "\n" + "GRID\n" + "EDIT\n" + "\n"; + + Opm::ParserPtr parser(new Opm::Parser()); + return parser->parseString(deckData) ; +} + +BOOST_AUTO_TEST_CASE(MissingDimsThrows) { + Opm::DeckPtr deck = createDeckMissingDIMS(); + BOOST_CHECK_THROW( new Opm::EclipseGrid( deck ) , std::invalid_argument); +} + BOOST_AUTO_TEST_CASE(HasGridKeywords) { Opm::DeckPtr deck = createDeckHeaders(); @@ -72,6 +89,18 @@ BOOST_AUTO_TEST_CASE(HasGridKeywords) { BOOST_CHECK( !Opm::EclipseGrid::hasCartesianKeywords( deck )); } + +BOOST_AUTO_TEST_CASE(CreateGridNoCells) { + Opm::DeckPtr deck = createDeckHeaders(); + Opm::EclipseGrid grid( deck ); + BOOST_CHECK_EQUAL( 10 , grid.getNX()); + BOOST_CHECK_EQUAL( 10 , grid.getNY()); + BOOST_CHECK_EQUAL( 10 , grid.getNZ()); + BOOST_CHECK_EQUAL( 1000 , grid.getCartesianSize()); +} + + + static Opm::DeckPtr createCPDeck() { const char *deckData = "RUNSPEC\n" @@ -228,6 +257,17 @@ static Opm::DeckPtr createCARTInvalidDeck() { return parser->parseString(deckData) ; } +BOOST_AUTO_TEST_CASE(CREATE_SIMPLE) { + Opm::EclipseGrid grid(10,20,30); + + BOOST_CHECK_EQUAL( grid.getNX() , 10 ); + BOOST_CHECK_EQUAL( grid.getNY() , 20 ); + BOOST_CHECK_EQUAL( grid.getNZ() , 30 ); + BOOST_CHECK_EQUAL( grid.getCartesianSize() , 6000 ); + BOOST_CHECK_EQUAL( false , grid.hasCellInfo() ); + +} + BOOST_AUTO_TEST_CASE(DEPTHZ_EQUAL_TOPS) { Opm::DeckPtr deck1 = createCARTDeck(); Opm::DeckPtr deck2 = createCARTDeckDEPTHZ(); @@ -306,7 +346,8 @@ BOOST_AUTO_TEST_CASE(HasINVALIDCartKeywords) { BOOST_AUTO_TEST_CASE(CreateMissingGRID_throws) { Opm::DeckPtr deck = createDeckHeaders(); - BOOST_CHECK_THROW(new Opm::EclipseGrid( deck ) , std::invalid_argument); + Opm::EclipseGrid grid( deck ); + BOOST_CHECK_EQUAL( false , grid.hasCellInfo() ); } @@ -366,7 +407,8 @@ static Opm::DeckPtr createInvalidDXYZCARTDeckDEPTHZ() { BOOST_AUTO_TEST_CASE(CreateCartesianGRIDDEPTHZ) { Opm::DeckPtr deck = createInvalidDXYZCARTDeckDEPTHZ(); - BOOST_CHECK_THROW(new Opm::EclipseGrid( deck ) , std::invalid_argument); + Opm::EclipseGrid grid( deck ); + BOOST_CHECK_EQUAL( false , grid.hasCellInfo() ); } From 6f4b353fe5aed291d3f185f9a3824ba3ee7a138e Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Sun, 9 Nov 2014 23:46:56 +0100 Subject: [PATCH 06/13] Using shared_ptr instead of bare EclipseGrid * --- opm/parser/eclipse/EclipseState/EclipseState.cpp | 4 ++-- .../eclipse/EclipseState/Grid/GridProperties.hpp | 4 ++-- .../EclipseState/Grid/tests/GridPropertiesTests.cpp | 11 +++++++---- .../EclipseState/Grid/tests/GridPropertyTests.cpp | 4 ++-- .../EclipseState/Grid/tests/MULTREGTScannerTests.cpp | 10 +++++----- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/EclipseState.cpp b/opm/parser/eclipse/EclipseState/EclipseState.cpp index 98482cfa3..3362b6009 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.cpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.cpp @@ -733,8 +733,8 @@ namespace Opm { }); // register the grid properties - m_intGridProperties = std::make_shared >(m_eclipseGrid.get(), supportedIntKeywords); - m_doubleGridProperties = std::make_shared >(m_eclipseGrid.get(), supportedDoubleKeywords); + m_intGridProperties = std::make_shared >(m_eclipseGrid , supportedIntKeywords); + m_doubleGridProperties = std::make_shared >(m_eclipseGrid , supportedDoubleKeywords); if (!hasEclipseGrid()) { // make sure that no grid properties are specified by the deck diff --git a/opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp b/opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp index 0b95671b6..77e5f21b8 100644 --- a/opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp @@ -52,7 +52,7 @@ class GridProperties { public: typedef typename GridProperty::SupportedKeywordInfo SupportedKeywordInfo; - GridProperties(const EclipseGrid* eclipseGrid, std::shared_ptr > supportedKeywords) { + GridProperties(std::shared_ptr eclipseGrid , std::shared_ptr > supportedKeywords) { m_eclipseGrid = eclipseGrid; for (auto iter = supportedKeywords->begin(); iter != supportedKeywords->end(); ++iter) @@ -96,7 +96,7 @@ public: private: - const EclipseGrid* m_eclipseGrid; + std::shared_ptr m_eclipseGrid; std::unordered_map m_supportedKeywords; std::map > > m_properties; }; diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertiesTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertiesTests.cpp index 81884d4eb..d677367d1 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertiesTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertiesTests.cpp @@ -41,7 +41,9 @@ BOOST_AUTO_TEST_CASE(Empty) { SupportedKeywordInfo("SATNUM" , 0, "1"), SupportedKeywordInfo("FIPNUM" , 2, "1") }); - Opm::GridProperties gridProperties( NULL , supportedKeywords); + + std::shared_ptr grid = std::make_shared(10,7,9); + Opm::GridProperties gridProperties( grid , supportedKeywords); BOOST_CHECK( gridProperties.supportsKeyword("SATNUM") ); BOOST_CHECK( gridProperties.supportsKeyword("FIPNUM") ); @@ -57,13 +59,13 @@ BOOST_AUTO_TEST_CASE(addKeyword) { std::shared_ptr > supportedKeywords(new std::vector{ SupportedKeywordInfo("SATNUM" , 0, "1") }); - Opm::GridProperties gridProperties( NULL , supportedKeywords); + std::shared_ptr grid = std::make_shared(10,7,9); + Opm::GridProperties gridProperties( grid , supportedKeywords); BOOST_CHECK_THROW( gridProperties.addKeyword("NOT-SUPPORTED") , std::invalid_argument); BOOST_CHECK( gridProperties.addKeyword("SATNUM")); BOOST_CHECK( !gridProperties.addKeyword("SATNUM")); - BOOST_CHECK( gridProperties.hasKeyword("SATNUM")); } @@ -74,7 +76,8 @@ BOOST_AUTO_TEST_CASE(getKeyword) { std::shared_ptr > supportedKeywords(new std::vector{ SupportedKeywordInfo("SATNUM" , 0, "1") }); - Opm::GridProperties gridProperties( NULL , supportedKeywords); + std::shared_ptr grid = std::make_shared(10,7,9); + Opm::GridProperties gridProperties( grid , supportedKeywords); std::shared_ptr > satnum1 = gridProperties.getKeyword("SATNUM"); std::shared_ptr > satnum2 = gridProperties.getKeyword("SATNUM"); diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp index c87a616d4..35723cb37 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp @@ -428,8 +428,8 @@ BOOST_AUTO_TEST_CASE(GridPropertyPostProcessors) { std::shared_ptr > supportedKeywords(new std::vector{ kwInfo1 , kwInfo2 }); Opm::DeckPtr deck = createDeck(); - Opm::EclipseGrid grid(deck); - Opm::GridProperties properties(&grid, supportedKeywords); + std::shared_ptr grid = std::make_shared(deck); + Opm::GridProperties properties(grid, supportedKeywords); { auto poro = properties.getKeyword("PORO"); diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/MULTREGTScannerTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/MULTREGTScannerTests.cpp index b788d4dc9..f0d52864d 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/MULTREGTScannerTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/MULTREGTScannerTests.cpp @@ -114,8 +114,8 @@ BOOST_AUTO_TEST_CASE(InvalidInput) { Opm::MULTREGTScanner scanner; Opm::DeckPtr deck = createInvalidMULTREGTDeck(); - Opm::EclipseGrid grid(deck); - std::shared_ptr > gridProperties = std::make_shared >(&grid, supportedKeywords); + std::shared_ptr grid = std::make_shared( deck ); + std::shared_ptr > gridProperties = std::make_shared >(grid, supportedKeywords); Opm::DeckKeywordConstPtr multregtKeyword0 = deck->getKeyword("MULTREGT",0); Opm::DeckKeywordConstPtr multregtKeyword1 = deck->getKeyword("MULTREGT",1); Opm::DeckKeywordConstPtr multregtKeyword2 = deck->getKeyword("MULTREGT",2); @@ -251,10 +251,10 @@ BOOST_AUTO_TEST_CASE(SimpleMULTREGT) { SupportedKeywordInfo("MULTNUM" , 1 , "1") }); Opm::DeckPtr deck = createSimpleMULTREGTDeck(); - Opm::EclipseGrid grid(deck); - std::shared_ptr inputBox = std::make_shared( grid.getNX() , grid.getNY() , grid.getNZ() ); + std::shared_ptr grid = std::make_shared( deck ); + std::shared_ptr inputBox = std::make_shared( grid->getNX() , grid->getNY() , grid->getNZ() ); - std::shared_ptr > gridProperties = std::make_shared >(&grid, supportedKeywords); + std::shared_ptr > gridProperties = std::make_shared >(grid, supportedKeywords); std::shared_ptr > fluxNum = gridProperties->getKeyword("FLUXNUM"); std::shared_ptr > multNum = gridProperties->getKeyword("MULTNUM"); Opm::DeckKeywordConstPtr fluxnumKeyword = deck->getKeyword("FLUXNUM",0); From 24cb9944c6a2a51945d5496388f8e20f11ae5cd8 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 10 Nov 2014 00:14:55 +0100 Subject: [PATCH 07/13] EclipseGrid - check content of c_ptr before use This commit contains quite large changes to the EclipseGrid. The main functional change is that the access to the ecl_grid_type pointer is protected. In addition there are 'white space' changes due to methods moving around and some methods have been marked static. --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 315 ++++++++++-------- .../eclipse/EclipseState/Grid/EclipseGrid.hpp | 11 +- 2 files changed, 175 insertions(+), 151 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp index 49af62bba..2037ed9d0 100644 --- a/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -44,9 +44,9 @@ namespace Opm { else throw std::invalid_argument("Could not load grid from binary file: " + filename); - m_nx = static_cast( ecl_grid_get_nx( m_grid.get() )); - m_ny = static_cast( ecl_grid_get_ny( m_grid.get() )); - m_nz = static_cast( ecl_grid_get_nz( m_grid.get() )); + m_nx = static_cast( ecl_grid_get_nx( c_ptr() )); + m_ny = static_cast( ecl_grid_get_ny( c_ptr() )); + m_nz = static_cast( ecl_grid_get_nz( c_ptr() )); } EclipseGrid::EclipseGrid(const ecl_grid_type * src_ptr) @@ -55,9 +55,9 @@ namespace Opm { { m_grid.reset( ecl_grid_alloc_copy( src_ptr ) , ecl_grid_free ); - m_nx = static_cast( ecl_grid_get_nx( m_grid.get() )); - m_ny = static_cast( ecl_grid_get_ny( m_grid.get() )); - m_nz = static_cast( ecl_grid_get_nz( m_grid.get() )); + m_nx = static_cast( ecl_grid_get_nx( c_ptr() )); + m_ny = static_cast( ecl_grid_get_ny( c_ptr() )); + m_nz = static_cast( ecl_grid_get_nz( c_ptr() )); } /* @@ -161,17 +161,6 @@ namespace Opm { - bool EclipseGrid::equal(const EclipseGrid& other) const { - return (m_pinch.equal( other.m_pinch ) && - m_minpv.equal( other.m_minpv ) && - ecl_grid_compare( m_grid.get() , other.m_grid.get() , true , false , false )); - } - - - size_t EclipseGrid::getNumActive( ) const { - return static_cast(ecl_grid_get_nactive( m_grid.get() )); - } - size_t EclipseGrid::getNX( ) const { return m_nx; } @@ -187,15 +176,6 @@ namespace Opm { size_t EclipseGrid::getCartesianSize( ) const { return m_nx * m_ny * m_nz; } - - /* - This function checks if the grid has a pointer to an underlying - ecl_grid_type; which must be used to read cell info as - size/depth/active of individual cells. - */ - bool EclipseGrid::hasCellInfo() const { - return static_cast( m_grid ); - } bool EclipseGrid::isPinchActive( ) const { return m_pinch.hasValue(); @@ -224,91 +204,43 @@ namespace Opm { } - double EclipseGrid::getCellVolume(size_t globalIndex) const { - assertGlobalIndex( globalIndex ); - return ecl_grid_get_cell_volume1( m_grid.get() , static_cast(globalIndex)); + + void EclipseGrid::initCartesianGrid(const std::vector& dims , DeckConstPtr deck) { + if (hasDVDEPTHZKeywords( deck )) + initDVDEPTHZGrid( dims , deck ); + else if (hasDTOPSKeywords(deck)) + initDTOPSGrid( dims ,deck ); + else + throw std::invalid_argument("Tried to initialize cartesian grid without all required keywords"); } + + void EclipseGrid::initDVDEPTHZGrid(const std::vector& dims , DeckConstPtr deck) { + const std::vector& DXV = deck->getKeyword("DXV")->getSIDoubleData(); + const std::vector& DYV = deck->getKeyword("DYV")->getSIDoubleData(); + const std::vector& DZV = deck->getKeyword("DZV")->getSIDoubleData(); + const std::vector& DEPTHZ = deck->getKeyword("DEPTHZ")->getSIDoubleData(); - double EclipseGrid::getCellVolume(size_t i , size_t j , size_t k) const { - assertIJK(i,j,k); - return ecl_grid_get_cell_volume3( m_grid.get() , static_cast(i),static_cast(j),static_cast(k)); - } - - std::tuple EclipseGrid::getCellCenter(size_t globalIndex) const { - assertGlobalIndex( globalIndex ); - { - double x,y,z; - ecl_grid_get_xyz1( m_grid.get() , static_cast(globalIndex) , &x , &y , &z); - return std::tuple {x,y,z}; - } - } - - - std::tuple EclipseGrid::getCellCenter(size_t i,size_t j, size_t k) const { - assertIJK(i,j,k); - { - double x,y,z; - ecl_grid_get_xyz3( m_grid.get() , static_cast(i),static_cast(j),static_cast(k), &x , &y , &z); - return std::tuple {x,y,z}; - } - } - - bool EclipseGrid::hasCornerPointKeywords(DeckConstPtr deck) { - if (deck->hasKeyword("ZCORN") && deck->hasKeyword("COORD")) - return true; - else - return false; - } - - - void EclipseGrid::assertCornerPointKeywords( const std::vector& dims , DeckConstPtr deck, ParserLogPtr parserLog) const - { - const int nx = dims[0]; - const int ny = dims[1]; - const int nz = dims[2]; - { - DeckKeywordConstPtr ZCORNKeyWord = deck->getKeyword("ZCORN"); - - if (ZCORNKeyWord->getDataSize() != static_cast(8*nx*ny*nz)) { - const std::string msg = - "Wrong size of the ZCORN keyword: Expected 8*x*ny*nz = " - + std::to_string(static_cast(8*nx*ny*nz)) + " is " - + std::to_string(static_cast(ZCORNKeyWord->getDataSize())); - - parserLog->addError("", -1, msg); - throw std::invalid_argument(msg); - } - } - - { - DeckKeywordConstPtr COORDKeyWord = deck->getKeyword("COORD"); - if (COORDKeyWord->getDataSize() != static_cast(6*(nx + 1)*(ny + 1))) { - const std::string msg = - "Wrong size of the COORD keyword: Expected 8*(nx + 1)*(ny + 1) = " - + std::to_string(static_cast(8*(nx + 1)*(ny + 1))) + " is " - + std::to_string(static_cast(COORDKeyWord->getDataSize())); - parserLog->addError("", -1, msg); - throw std::invalid_argument(msg); - } - } - - if (deck->hasKeyword("ACTNUM")) { - DeckKeywordConstPtr ACTNUMKeyWord = deck->getKeyword("ACTNUM"); - if (ACTNUMKeyWord->getDataSize() != static_cast(nx*ny*nz)) { - const std::string msg = - "Wrong size of the ACTNUM keyword: Expected nx*ny*nz = " - + std::to_string(static_cast(nx*ny*nz)) + " is " - + std::to_string(static_cast(ACTNUMKeyWord->getDataSize())); - parserLog->addError("", -1, msg); - throw std::invalid_argument(msg); - } - } - } + assertVectorSize( DEPTHZ , static_cast( (dims[0] + 1)*(dims[1] +1 )) , "DEPTHZ"); + assertVectorSize( DXV , static_cast( dims[0] ) , "DXV"); + assertVectorSize( DYV , static_cast( dims[1] ) , "DYV"); + assertVectorSize( DZV , static_cast( dims[2] ) , "DZV"); + m_grid.reset( ecl_grid_alloc_dxv_dyv_dzv_depthz( dims[0] , dims[1] , dims[2] , DXV.data() , DYV.data() , DZV.data() , DEPTHZ.data() , NULL ) , ecl_grid_free); + } + void EclipseGrid::initDTOPSGrid(const std::vector& dims , DeckConstPtr deck) { + std::vector DX = createDVector( dims , 0 , "DX" , "DXV" , deck); + std::vector DY = createDVector( dims , 1 , "DY" , "DYV" , deck); + std::vector DZ = createDVector( dims , 2 , "DZ" , "DZV" , deck); + std::vector TOPS = createTOPSVector( dims , DZ , deck ); + + m_grid.reset( ecl_grid_alloc_dx_dy_dz_tops( dims[0] , dims[1] , dims[2] , DX.data() , DY.data() , DZ.data() , TOPS.data() , NULL ) , ecl_grid_free); + } + + void EclipseGrid::initCornerPointGrid(const std::vector& dims , DeckConstPtr deck, ParserLogPtr parserLog) { assertCornerPointKeywords( dims , deck, parserLog); { @@ -359,6 +291,61 @@ namespace Opm { } + + bool EclipseGrid::hasCornerPointKeywords(DeckConstPtr deck) { + if (deck->hasKeyword("ZCORN") && deck->hasKeyword("COORD")) + return true; + else + return false; + } + + + void EclipseGrid::assertCornerPointKeywords( const std::vector& dims , DeckConstPtr deck, ParserLogPtr parserLog) + { + const int nx = dims[0]; + const int ny = dims[1]; + const int nz = dims[2]; + { + DeckKeywordConstPtr ZCORNKeyWord = deck->getKeyword("ZCORN"); + + if (ZCORNKeyWord->getDataSize() != static_cast(8*nx*ny*nz)) { + const std::string msg = + "Wrong size of the ZCORN keyword: Expected 8*x*ny*nz = " + + std::to_string(static_cast(8*nx*ny*nz)) + " is " + + std::to_string(static_cast(ZCORNKeyWord->getDataSize())); + + parserLog->addError("", -1, msg); + throw std::invalid_argument(msg); + } + } + + { + DeckKeywordConstPtr COORDKeyWord = deck->getKeyword("COORD"); + if (COORDKeyWord->getDataSize() != static_cast(6*(nx + 1)*(ny + 1))) { + const std::string msg = + "Wrong size of the COORD keyword: Expected 8*(nx + 1)*(ny + 1) = " + + std::to_string(static_cast(8*(nx + 1)*(ny + 1))) + " is " + + std::to_string(static_cast(COORDKeyWord->getDataSize())); + parserLog->addError("", -1, msg); + throw std::invalid_argument(msg); + } + } + + if (deck->hasKeyword("ACTNUM")) { + DeckKeywordConstPtr ACTNUMKeyWord = deck->getKeyword("ACTNUM"); + if (ACTNUMKeyWord->getDataSize() != static_cast(nx*ny*nz)) { + const std::string msg = + "Wrong size of the ACTNUM keyword: Expected nx*ny*nz = " + + std::to_string(static_cast(nx*ny*nz)) + " is " + + std::to_string(static_cast(ACTNUMKeyWord->getDataSize())); + parserLog->addError("", -1, msg); + throw std::invalid_argument(msg); + } + } + } + + + bool EclipseGrid::hasCartesianKeywords(DeckConstPtr deck) { if (hasDVDEPTHZKeywords( deck )) return true; @@ -388,44 +375,13 @@ namespace Opm { } - void EclipseGrid::initCartesianGrid(const std::vector& dims , DeckConstPtr deck) { - if (hasDVDEPTHZKeywords( deck )) - initDVDEPTHZGrid( dims , deck ); - else if (hasDTOPSKeywords(deck)) - initDTOPSGrid( dims ,deck ); - else - throw std::invalid_argument("Tried to initialize cartesian grid without all required keywords"); - } void EclipseGrid::assertVectorSize(const std::vector& vector , size_t expectedSize , const std::string& vectorName) { if (vector.size() != expectedSize) throw std::invalid_argument("Wrong size for keyword: " + vectorName + ". Expected: " + boost::lexical_cast(expectedSize) + " got: " + boost::lexical_cast(vector.size())); } - - void EclipseGrid::initDVDEPTHZGrid(const std::vector& dims , DeckConstPtr deck) { - const std::vector& DXV = deck->getKeyword("DXV")->getSIDoubleData(); - const std::vector& DYV = deck->getKeyword("DYV")->getSIDoubleData(); - const std::vector& DZV = deck->getKeyword("DZV")->getSIDoubleData(); - const std::vector& DEPTHZ = deck->getKeyword("DEPTHZ")->getSIDoubleData(); - assertVectorSize( DEPTHZ , static_cast( (dims[0] + 1)*(dims[1] +1 )) , "DEPTHZ"); - assertVectorSize( DXV , static_cast( dims[0] ) , "DXV"); - assertVectorSize( DYV , static_cast( dims[1] ) , "DYV"); - assertVectorSize( DZV , static_cast( dims[2] ) , "DZV"); - - m_grid.reset( ecl_grid_alloc_dxv_dyv_dzv_depthz( dims[0] , dims[1] , dims[2] , DXV.data() , DYV.data() , DZV.data() , DEPTHZ.data() , NULL ) , ecl_grid_free); - } - - - void EclipseGrid::initDTOPSGrid(const std::vector& dims , DeckConstPtr deck) { - std::vector DX = createDVector( dims , 0 , "DX" , "DXV" , deck); - std::vector DY = createDVector( dims , 1 , "DY" , "DYV" , deck); - std::vector DZ = createDVector( dims , 2 , "DZ" , "DZV" , deck); - std::vector TOPS = createTOPSVector( dims , DZ , deck ); - - m_grid.reset( ecl_grid_alloc_dx_dy_dz_tops( dims[0] , dims[1] , dims[2] , DX.data() , DY.data() , DZ.data() , TOPS.data() , NULL ) , ecl_grid_free); - } std::vector EclipseGrid::createTOPSVector(const std::vector& dims , const std::vector& DZ , DeckConstPtr deck) { @@ -499,52 +455,117 @@ namespace Opm { } } + + /* + This function checks if the grid has a pointer to an underlying + ecl_grid_type; which must be used to read cell info as + size/depth/active of individual cells. + */ + + bool EclipseGrid::hasCellInfo() const { + return static_cast( m_grid ); + } + + + void EclipseGrid::assertCellInfo() const { + if (!hasCellInfo()) + throw std::invalid_argument("Tried to access cell information in a grid with only dimensions"); + } + + + const ecl_grid_type * EclipseGrid::c_ptr() const { + assertCellInfo(); + return m_grid.get(); + } + + + bool EclipseGrid::equal(const EclipseGrid& other) const { + return (m_pinch.equal( other.m_pinch ) && + m_minpv.equal( other.m_minpv ) && + ecl_grid_compare( c_ptr() , other.c_ptr() , true , false , false )); + } + + + size_t EclipseGrid::getNumActive( ) const { + return static_cast(ecl_grid_get_nactive( c_ptr() )); + } + + + double EclipseGrid::getCellVolume(size_t globalIndex) const { + assertGlobalIndex( globalIndex ); + return ecl_grid_get_cell_volume1( c_ptr() , static_cast(globalIndex)); + } + + + double EclipseGrid::getCellVolume(size_t i , size_t j , size_t k) const { + assertIJK(i,j,k); + return ecl_grid_get_cell_volume3( c_ptr() , static_cast(i),static_cast(j),static_cast(k)); + } + + std::tuple EclipseGrid::getCellCenter(size_t globalIndex) const { + assertGlobalIndex( globalIndex ); + { + double x,y,z; + ecl_grid_get_xyz1( c_ptr() , static_cast(globalIndex) , &x , &y , &z); + return std::tuple {x,y,z}; + } + } + + + std::tuple EclipseGrid::getCellCenter(size_t i,size_t j, size_t k) const { + assertIJK(i,j,k); + { + double x,y,z; + ecl_grid_get_xyz3( c_ptr() , static_cast(i),static_cast(j),static_cast(k), &x , &y , &z); + return std::tuple {x,y,z}; + } + } + + + void EclipseGrid::exportACTNUM( std::vector& actnum) const { size_t volume = getNX() * getNY() * getNZ(); if (getNumActive() == volume) actnum.resize(0); else { actnum.resize( volume ); - ecl_grid_init_actnum_data( m_grid.get() , actnum.data() ); + ecl_grid_init_actnum_data( c_ptr() , actnum.data() ); } } void EclipseGrid::exportMAPAXES( std::vector& mapaxes) const { - if (ecl_grid_use_mapaxes( m_grid.get())) { + if (ecl_grid_use_mapaxes( c_ptr())) { mapaxes.resize(6); - ecl_grid_init_mapaxes_data_double( m_grid.get() , mapaxes.data() ); + ecl_grid_init_mapaxes_data_double( c_ptr() , mapaxes.data() ); } else { mapaxes.resize(0); } } void EclipseGrid::exportCOORD( std::vector& coord) const { - coord.resize( ecl_grid_get_coord_size( m_grid.get() )); - ecl_grid_init_coord_data_double( m_grid.get() , coord.data() ); + coord.resize( ecl_grid_get_coord_size( c_ptr() )); + ecl_grid_init_coord_data_double( c_ptr() , coord.data() ); } void EclipseGrid::exportZCORN( std::vector& zcorn) const { - zcorn.resize( ecl_grid_get_zcorn_size( m_grid.get() )); - ecl_grid_init_zcorn_data_double( m_grid.get() , zcorn.data() ); + zcorn.resize( ecl_grid_get_zcorn_size( c_ptr() )); + ecl_grid_init_zcorn_data_double( c_ptr() , zcorn.data() ); } void EclipseGrid::resetACTNUM( const int * actnum) { + assertCellInfo(); ecl_grid_reset_actnum( m_grid.get() , actnum ); } void EclipseGrid::fwriteEGRID( const std::string& filename ) const { + assertCellInfo(); ecl_grid_fwrite_EGRID( m_grid.get() , filename.c_str() ); } - const ecl_grid_type * EclipseGrid::c_ptr() const { - return m_grid.get(); - } - - } diff --git a/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp index 9eda6e242..284f968aa 100644 --- a/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -105,19 +105,22 @@ namespace Opm { size_t m_nx; size_t m_ny; size_t m_nz; + + void assertCellInfo() const; void initCartesianGrid(const std::vector& dims , DeckConstPtr deck); void initCornerPointGrid(const std::vector& dims , DeckConstPtr deck, ParserLogPtr parserLog); - void assertCornerPointKeywords(const std::vector& dims, DeckConstPtr deck, ParserLogPtr parserLog) const ; void initDTOPSGrid(const std::vector& dims , DeckConstPtr deck); void initDVDEPTHZGrid(const std::vector& dims , DeckConstPtr deck); void initGrid(const std::vector& dims, DeckConstPtr deck, ParserLogPtr parserLog); + + static void assertCornerPointKeywords(const std::vector& dims, DeckConstPtr deck, ParserLogPtr parserLog) ; static bool hasDVDEPTHZKeywords(DeckConstPtr deck); static bool hasDTOPSKeywords(DeckConstPtr deck); static void assertVectorSize(const std::vector& vector , size_t expectedSize , const std::string& msg); - std::vector createTOPSVector(const std::vector& dims , const std::vector& DZ , DeckConstPtr deck); - std::vector createDVector(const std::vector& dims , size_t dim , const std::string& DKey , const std::string& DVKey, DeckConstPtr deck); - void scatterDim(const std::vector& dims , size_t dim , const std::vector& DV , std::vector& D); + static std::vector createTOPSVector(const std::vector& dims , const std::vector& DZ , DeckConstPtr deck); + static std::vector createDVector(const std::vector& dims , size_t dim , const std::string& DKey , const std::string& DVKey, DeckConstPtr deck); + static void scatterDim(const std::vector& dims , size_t dim , const std::vector& DV , std::vector& D); }; typedef std::shared_ptr EclipseGridPtr; From 52883c9e697524c18c8729079ebb2638645e1b07 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 10 Nov 2014 00:17:10 +0100 Subject: [PATCH 08/13] Check that exception is raised if PORV is initialized without grid. --- .../EclipseState/Grid/tests/PORVTests.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/PORVTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/PORVTests.cpp index 02b64deba..10a924640 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/PORVTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/PORVTests.cpp @@ -319,3 +319,29 @@ BOOST_AUTO_TEST_CASE(PORV_multpvAndNtg) { BOOST_CHECK_CLOSE( PORV * multpv , porv->iget(0,0,0) , 0.001); BOOST_CHECK_CLOSE( cell_volume * poro*multpv*NTG , porv->iget(9,9,9) , 0.001); } + + + +static Opm::DeckPtr createDeckNakedGRID() { + const char *deckData = + "RUNSPEC\n" + "\n" + "DIMENS\n" + " 10 10 10 /\n" + "GRID\n" + "PORO\n" + "100*0.10 100*0.20 100*0.30 100*0.40 100*0.50 100*0.60 100*0.70 100*0.80 100*0.90 100*1.0 /\n" + "EDIT\n" + "\n"; + + Opm::ParserPtr parser(new Opm::Parser()); + return parser->parseString(deckData) ; +} + + +BOOST_AUTO_TEST_CASE(NAKED_GRID_THROWS) { + /* Check that MULTIPLE Boxed PORV and MULTPV statements work and NTG */ + Opm::DeckPtr deck = createDeckNakedGRID(); + auto state = std::make_shared(deck); + BOOST_CHECK_THROW( state->getDoubleGridProperty("PORV") , std::invalid_argument ); +} From ffce0408c465501c373c55a0002b7bfd9c2e996d Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 10 Nov 2014 00:20:48 +0100 Subject: [PATCH 09/13] Removed unused dummy grids in test deck. --- .../Grid/tests/MULTREGTScannerTests.cpp | 32 ------------------- .../EclipseState/tests/EclipseStateTests.cpp | 16 ---------- testdata/integration_tests/BOX/BOXTEST1 | 12 ------- testdata/integration_tests/BOX/BOXTEST2 | 11 ------- testdata/integration_tests/BOX/BOXTEST3 | 12 ------- 5 files changed, 83 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/MULTREGTScannerTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/MULTREGTScannerTests.cpp index f0d52864d..e0103739b 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/MULTREGTScannerTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/MULTREGTScannerTests.cpp @@ -70,14 +70,6 @@ static Opm::DeckPtr createInvalidMULTREGTDeck() { "DIMENS\n" " 3 3 2 /\n" "GRID\n" - "DX\n" - "18*0.25 /\n" - "DYV\n" - "3*0.25 /\n" - "DZ\n" - "18*0.25 /\n" - "TOPS\n" - "9*0.25 /\n" "FLUXNUM\n" "1 1 2\n" "1 1 2\n" @@ -140,14 +132,6 @@ static Opm::DeckPtr createNotSupportedMULTREGTDeck() { "DIMENS\n" " 3 3 2 /\n" "GRID\n" - "DX\n" - "18*0.25 /\n" - "DYV\n" - "3*0.25 /\n" - "DZ\n" - "18*0.25 /\n" - "TOPS\n" - "9*0.25 /\n" "FLUXNUM\n" "1 1 2\n" "1 1 2\n" @@ -209,14 +193,6 @@ static Opm::DeckPtr createSimpleMULTREGTDeck() { "DIMENS\n" "2 2 2 /\n" "GRID\n" - "DX\n" - "8*0.25 /\n" - "DYV\n" - "2*0.25 /\n" - "DZ\n" - "8*0.25 /\n" - "TOPS\n" - "4*0.25 /\n" "FLUXNUM\n" "1 2\n" "1 2\n" @@ -316,14 +292,6 @@ static Opm::DeckPtr createCopyMULTNUMDeck() { "DIMENS\n" "2 2 2 /\n" "GRID\n" - "DX\n" - "8*0.25 /\n" - "DYV\n" - "2*0.25 /\n" - "DZ\n" - "8*0.25 /\n" - "TOPS\n" - "4*0.25 /\n" "FLUXNUM\n" "1 2\n" "1 2\n" diff --git a/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp b/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp index ef12c2455..509cd179f 100644 --- a/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp +++ b/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp @@ -138,14 +138,6 @@ static DeckPtr createDeck() { "DIMENS\n" " 10 10 10 /\n" "GRID\n" - "DX\n" - "1000*0.25 /\n" - "DYV\n" - "10*0.25 /\n" - "DZ\n" - "1000*0.25 /\n" - "TOPS\n" - "1000*0.25 /\n" "FAULTS \n" " 'F1' 1 1 1 4 1 4 'X' / \n" " 'F2' 5 5 1 4 1 4 'X-' / \n" @@ -187,14 +179,6 @@ static DeckPtr createDeckNoFaults() { "DIMENS\n" " 10 10 10 /\n" "GRID\n" - "DX\n" - "1000*0.25 /\n" - "DYV\n" - "10*0.25 /\n" - "DZ\n" - "1000*0.25 /\n" - "TOPS\n" - "1000*0.25 /\n" "PROPS\n" "-- multiply one layer for each face\n" "MULTX\n" diff --git a/testdata/integration_tests/BOX/BOXTEST1 b/testdata/integration_tests/BOX/BOXTEST1 index cba78a3cb..06cad6229 100644 --- a/testdata/integration_tests/BOX/BOXTEST1 +++ b/testdata/integration_tests/BOX/BOXTEST1 @@ -5,18 +5,6 @@ DIMENS GRID -DX -1000*0.25 / - -DYV -10*0.25 / - -DZ -1000*0.25 / - -TOPS -1000*0.25 / - PERMX 1000*1 / diff --git a/testdata/integration_tests/BOX/BOXTEST2 b/testdata/integration_tests/BOX/BOXTEST2 index ca4b2efe0..0e4b5a1fd 100644 --- a/testdata/integration_tests/BOX/BOXTEST2 +++ b/testdata/integration_tests/BOX/BOXTEST2 @@ -5,17 +5,6 @@ DIMENS GRID -DX -1000*0.25 / - -DYV -10*0.25 / - -DZ -1000*0.25 / - -TOPS -1000*0.25 / EDIT diff --git a/testdata/integration_tests/BOX/BOXTEST3 b/testdata/integration_tests/BOX/BOXTEST3 index 370cde115..b33e4bbbb 100644 --- a/testdata/integration_tests/BOX/BOXTEST3 +++ b/testdata/integration_tests/BOX/BOXTEST3 @@ -5,18 +5,6 @@ DIMENS GRID -DX -1000*0.25 / - -DYV -10*0.25 / - -DZ -1000*0.25 / - -TOPS -1000*0.25 / - EDIT OIL From cf5a839d97f9cb4b67a6a9c04cc0a773afd296f3 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 10 Nov 2014 00:24:17 +0100 Subject: [PATCH 10/13] Removed unnecessary default values. --- opm/parser/share/keywords/A/ADD | 12 ++++++------ opm/parser/share/keywords/C/COPY | 12 ++++++------ opm/parser/share/keywords/E/EQUALS | 12 ++++++------ opm/parser/share/keywords/M/MULTIPLY | 12 ++++++------ 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/opm/parser/share/keywords/A/ADD b/opm/parser/share/keywords/A/ADD index e86dfa002..c5946d339 100644 --- a/opm/parser/share/keywords/A/ADD +++ b/opm/parser/share/keywords/A/ADD @@ -1,10 +1,10 @@ {"name" : "ADD", "sections" : ["GRID", "EDIT", "PROPS", "REGIONS", "SOLUTION"], "items" : [ {"name" : "field" , "value_type" : "STRING"}, {"name" : "shift" , "value_type" : "DOUBLE"}, - {"name" : "I1" , "value_type" : "INT", "default" : -1}, - {"name" : "I2" , "value_type" : "INT", "default" : -1}, - {"name" : "J1" , "value_type" : "INT", "default" : -1}, - {"name" : "J2" , "value_type" : "INT", "default" : -1}, - {"name" : "K1" , "value_type" : "INT", "default" : -1}, - {"name" : "K2" , "value_type" : "INT", "default" : -1}]} + {"name" : "I1" , "value_type" : "INT"}, + {"name" : "I2" , "value_type" : "INT"}, + {"name" : "J1" , "value_type" : "INT"}, + {"name" : "J2" , "value_type" : "INT"}, + {"name" : "K1" , "value_type" : "INT"}, + {"name" : "K2" , "value_type" : "INT"}]} diff --git a/opm/parser/share/keywords/C/COPY b/opm/parser/share/keywords/C/COPY index 1490b56d9..b34486193 100644 --- a/opm/parser/share/keywords/C/COPY +++ b/opm/parser/share/keywords/C/COPY @@ -1,10 +1,10 @@ {"name" : "COPY" , "sections" : ["GRID", "EDIT", "PROPS", "REGIONS", "SOLUTION"], "items" : [ {"name" : "src", "value_type" : "STRING"}, {"name" : "target", "value_type" : "STRING"}, - {"name" : "I1" , "value_type" : "INT", "default": -1}, - {"name" : "I2" , "value_type" : "INT", "default": -1}, - {"name" : "J1" , "value_type" : "INT", "default": -1}, - {"name" : "J2" , "value_type" : "INT", "default": -1}, - {"name" : "K1" , "value_type" : "INT", "default": -1}, - {"name" : "K2" , "value_type" : "INT", "default": -1}]} + {"name" : "I1" , "value_type" : "INT"}, + {"name" : "I2" , "value_type" : "INT"}, + {"name" : "J1" , "value_type" : "INT"}, + {"name" : "J2" , "value_type" : "INT"}, + {"name" : "K1" , "value_type" : "INT"}, + {"name" : "K2" , "value_type" : "INT"}]} diff --git a/opm/parser/share/keywords/E/EQUALS b/opm/parser/share/keywords/E/EQUALS index 9a6b30bd4..1dbdc9622 100644 --- a/opm/parser/share/keywords/E/EQUALS +++ b/opm/parser/share/keywords/E/EQUALS @@ -1,9 +1,9 @@ {"name" : "EQUALS", "sections" : ["GRID", "EDIT", "PROPS", "REGIONS", "SOLUTION"], "items" : [ {"name" : "field" , "value_type" : "STRING"}, {"name" : "value" , "value_type" : "DOUBLE"}, - {"name" : "I1" , "value_type" : "INT", "default": -1}, - {"name" : "I2" , "value_type" : "INT", "default": -1}, - {"name" : "J1" , "value_type" : "INT", "default": -1}, - {"name" : "J2" , "value_type" : "INT", "default": -1}, - {"name" : "K1" , "value_type" : "INT", "default": -1}, - {"name" : "K2" , "value_type" : "INT", "default": -1}]} + {"name" : "I1" , "value_type" : "INT"}, + {"name" : "I2" , "value_type" : "INT"}, + {"name" : "J1" , "value_type" : "INT"}, + {"name" : "J2" , "value_type" : "INT"}, + {"name" : "K1" , "value_type" : "INT"}, + {"name" : "K2" , "value_type" : "INT"}]} diff --git a/opm/parser/share/keywords/M/MULTIPLY b/opm/parser/share/keywords/M/MULTIPLY index fa1a71a83..0ace771a9 100644 --- a/opm/parser/share/keywords/M/MULTIPLY +++ b/opm/parser/share/keywords/M/MULTIPLY @@ -1,9 +1,9 @@ {"name" : "MULTIPLY", "sections" : ["GRID", "EDIT", "PROPS", "REGIONS", "SOLUTION"], "items" : [ {"name" : "field" , "value_type" : "STRING"}, {"name" : "factor" , "value_type" : "DOUBLE"}, - {"name" : "I1" , "value_type" : "INT" , "default" : -1}, - {"name" : "I2" , "value_type" : "INT" , "default" : -1}, - {"name" : "J1" , "value_type" : "INT" , "default" : -1}, - {"name" : "J2" , "value_type" : "INT" , "default" : -1}, - {"name" : "K1" , "value_type" : "INT" , "default" : -1}, - {"name" : "K2" , "value_type" : "INT" , "default" : -1}]} + {"name" : "I1" , "value_type" : "INT" }, + {"name" : "I2" , "value_type" : "INT" }, + {"name" : "J1" , "value_type" : "INT" }, + {"name" : "J2" , "value_type" : "INT" }, + {"name" : "K1" , "value_type" : "INT" }, + {"name" : "K2" , "value_type" : "INT" }]} From 5f7a7d808378bd02f3aa8d59373cd93b520d85a5 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 10 Nov 2014 00:34:22 +0100 Subject: [PATCH 11/13] Removed EclipseState::hasGrid() method --- .../eclipse/EclipseState/EclipseState.cpp | 62 +------------------ .../eclipse/EclipseState/EclipseState.hpp | 1 - .../EclipseState/tests/EclipseStateTests.cpp | 33 ---------- 3 files changed, 1 insertion(+), 95 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/EclipseState.cpp b/opm/parser/eclipse/EclipseState/EclipseState.cpp index 3362b6009..2fc856b2b 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.cpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.cpp @@ -131,14 +131,8 @@ namespace Opm { return m_deckUnitSystem; } - bool EclipseState::hasEclipseGrid() const { - return static_cast(m_eclipseGrid); - } EclipseGridConstPtr EclipseState::getEclipseGrid() const { - if (!hasEclipseGrid()) - throw std::logic_error("The eclipse grid object cannot be retrieved if no grid is featured by the deck."); - return m_eclipseGrid; } @@ -259,12 +253,6 @@ namespace Opm { } void EclipseState::initTransMult(ParserLogPtr /*parserLog*/) { - if (!hasEclipseGrid()) - // no checking required here as the class will already - // refrain from processing the MULT* grid properties if no - // grid is available... - return; - EclipseGridConstPtr grid = getEclipseGrid(); m_transMult = std::make_shared( grid->getNX() , grid->getNY() , grid->getNZ()); @@ -285,16 +273,6 @@ namespace Opm { } void EclipseState::initFaults(DeckConstPtr deck, ParserLogPtr parserLog) { - if (!hasEclipseGrid()) { - if (deck->hasKeyword("FAULTS") || - deck->hasKeyword("MULTFAULT")) - { - throw std::logic_error("Grid could not be initialized, but fault transmissibility multipliers have been detected."); - } - else - return; - } - EclipseGridConstPtr grid = getEclipseGrid(); m_faults = std::make_shared(); std::shared_ptr gridSection(new Opm::GRIDSection(deck) ); @@ -356,14 +334,6 @@ namespace Opm { void EclipseState::initMULTREGT(DeckConstPtr deck, ParserLogPtr /*parserLog*/) { - if (!hasEclipseGrid()) { - if (deck->hasKeyword("MULTREGT")) { - throw std::logic_error("Grid could not be initialized, but region transmissibility multipliers have been detected."); - } - else - return; - } - EclipseGridConstPtr grid = getEclipseGrid(); std::shared_ptr scanner = std::make_shared(); @@ -390,12 +360,7 @@ namespace Opm { void EclipseState::initEclipseGrid(DeckConstPtr deck, ParserLogPtr parserLog) { - try { - m_eclipseGrid = EclipseGridConstPtr( new EclipseGrid(deck, parserLog)); - } catch (const std::exception& e) { - std::string msg("Could not create a grid: "+std::string(e.what())); - parserLog->addWarning("", -1, msg); - } + m_eclipseGrid = EclipseGridConstPtr( new EclipseGrid(deck, parserLog)); } @@ -736,31 +701,6 @@ namespace Opm { m_intGridProperties = std::make_shared >(m_eclipseGrid , supportedIntKeywords); m_doubleGridProperties = std::make_shared >(m_eclipseGrid , supportedDoubleKeywords); - if (!hasEclipseGrid()) { - // make sure that no grid properties are specified by the deck - for (size_t kwIdx = 0; kwIdx < deck->size(); ++ kwIdx) { - const std::string& kwName = deck->getKeyword(kwIdx)->name(); - if (supportsGridProperty(kwName)) - throw std::logic_error("Grid could not be initialized, but grid property " + kwName + " has been detected."); - } - - // make sure that no grid property modifier keywords - // (which can make grid properties appear out of thin air) - // are present in the deck. - if (deck->hasKeyword("ADD") || - deck->hasKeyword("BOX") || - deck->hasKeyword("COPY") || - deck->hasKeyword("EQUALS") || - deck->hasKeyword("MULTIPLY")) - { - throw std::logic_error("Grid could not be initialized, but grid properties have been detected."); - } - - // if we don't have a grid and also no grid properties, we - // just skip this method. - return; - } - // actually create the grid property objects. we need to first // process all integer grid properties before the double ones // as these may be needed in order to initialize the double diff --git a/opm/parser/eclipse/EclipseState/EclipseState.hpp b/opm/parser/eclipse/EclipseState/EclipseState.hpp index ca8f8c320..a6586ae4c 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.hpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.hpp @@ -67,7 +67,6 @@ namespace Opm { EclipseState(DeckConstPtr deck, ParserLogPtr parserLog = std::make_shared(&std::cout)); ScheduleConstPtr getSchedule() const; - bool hasEclipseGrid() const; EclipseGridConstPtr getEclipseGrid() const; EclipseGridPtr getEclipseGridCopy() const; bool hasPhase(enum Phase::PhaseEnum phase) const; diff --git a/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp b/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp index 509cd179f..5b578621c 100644 --- a/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp +++ b/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp @@ -112,24 +112,7 @@ BOOST_AUTO_TEST_CASE(GetPOROTOPBased) { } -static DeckPtr createEmptyDeck() { - const char *deckData = - ""; - ParserPtr parser(new Parser()); - return parser->parseString(deckData) ; -} - -static DeckPtr createDeckWithoutGrid() { - const char *deckData = - "PROPS\n" - "EQUALS\n" - "'PERMX' 1.23 /\n" - "/\n"; - - ParserPtr parser(new Parser()); - return parser->parseString(deckData) ; -} static DeckPtr createDeck() { const char *deckData = @@ -227,22 +210,6 @@ BOOST_AUTO_TEST_CASE(TitleCorrect) { BOOST_CHECK_EQUAL( state.getTitle(), "The title"); } -BOOST_AUTO_TEST_CASE(SupportsEmptyDeck) { - DeckPtr deck = createEmptyDeck(); - ParserLogPtr parserLog(new ParserLog); - BOOST_CHECK_NO_THROW(EclipseState(deck, parserLog)); - - // we need to get a warning because no grid could be instantiated - BOOST_CHECK_EQUAL(parserLog->numWarnings(), 1); -} - -BOOST_AUTO_TEST_CASE(SupportsDeckWithoutGrid) { - DeckPtr deck = createDeckWithoutGrid(); - ParserLogPtr parserLog(new ParserLog); - - // specifying grid properties without a grid is not supported! - BOOST_CHECK_THROW(EclipseState(deck, parserLog), std::logic_error); -} BOOST_AUTO_TEST_CASE(IntProperties) { DeckPtr deck = createDeck(); From ad75b870a52de9aba8f8d31cc9158a8b708f245f Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 10 Nov 2014 00:36:30 +0100 Subject: [PATCH 12/13] Changes to emacs file . --- .dir-locals.el | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.dir-locals.el b/.dir-locals.el index 67270a807..2af6c6568 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -1,4 +1,9 @@ ;; -((c-mode . ((c-basic-offset . 4) - (tab-width . 8) - (indent-tabs-mode . nil)))) +(( nil . ((eval . (progn + (require 'projectile) + (puthash (projectile-project-root) "cd build; make -j 4" projectile-compilation-cmd-map) + (puthash (projectile-project-root) "cd build; ctest -j 4" projectile-test-cmd-map))))) + ( c-mode . ((c-basic-offset . 4) + (tab-width . 8) + (indent-tabs-mode . nil)))) + From 456d36ccba1e2ecebdd4efb18dd32bc7b765e0cf Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 10 Nov 2014 17:05:54 +0100 Subject: [PATCH 13/13] Added test of EQUALS keyword auto creation. --- opm/parser/eclipse/IntegrationTests/BoxTest.cpp | 2 ++ testdata/integration_tests/BOX/BOXTEST1 | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/opm/parser/eclipse/IntegrationTests/BoxTest.cpp b/opm/parser/eclipse/IntegrationTests/BoxTest.cpp index 074436545..273b6c52d 100644 --- a/opm/parser/eclipse/IntegrationTests/BoxTest.cpp +++ b/opm/parser/eclipse/IntegrationTests/BoxTest.cpp @@ -142,6 +142,7 @@ BOOST_AUTO_TEST_CASE( EQUAL ) { EclipseState state = makeState("testdata/integration_tests/BOX/BOXTEST1", parserLog); std::shared_ptr > pvtnum = state.getIntGridProperty("PVTNUM"); std::shared_ptr > eqlnum = state.getIntGridProperty("EQLNUM"); + std::shared_ptr > poro = state.getDoubleGridProperty("PORO"); size_t i,j,k; std::shared_ptr grid = state.getEclipseGrid(); @@ -151,6 +152,7 @@ BOOST_AUTO_TEST_CASE( EQUAL ) { BOOST_CHECK_EQUAL( pvtnum->iget(i,j,k) , k ); BOOST_CHECK_EQUAL( eqlnum->iget(i,j,k) , 77 + 2 * k ); + BOOST_CHECK_EQUAL( poro->iget(i,j,k) , 0.25 ); } } diff --git a/testdata/integration_tests/BOX/BOXTEST1 b/testdata/integration_tests/BOX/BOXTEST1 index 06cad6229..0716ab73c 100644 --- a/testdata/integration_tests/BOX/BOXTEST1 +++ b/testdata/integration_tests/BOX/BOXTEST1 @@ -21,6 +21,10 @@ MULTIPLY PERMZ 0.25 / / +EQUALS + PORO 0.25 / +/ + EDIT OIL