From 21f94c0606a2f2d2236f4bef01b59818db7905ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20Gr=C3=B8n=C3=A5s=20Drange?= Date: Fri, 1 Apr 2016 15:27:40 +0200 Subject: [PATCH] TableManager and Deck are now used as references, hid GridProperties * Added keyword "OPERNUM" to supported keywords in Eclipse3DProperties * Updated tests to use Eclipse3DProperties API instead of GridProperties * Moved init sequence of title into constructor * ThresholdPressure and SimulationConfig now tasks Deck ref instead of shared_ptr * Removed obsolete test and unused tests that tested gridProperties * Refactor use of TableManager. Is now a reference. * Added non-const GridProperties.getKeyword(size_t i) --- .../EclipseState/Eclipse3DProperties.cpp | 26 +- .../EclipseState/Eclipse3DProperties.hpp | 9 +- .../eclipse/EclipseState/EclipseState.cpp | 48 ++- .../eclipse/EclipseState/EclipseState.hpp | 26 +- .../EclipseState/Grid/GridProperties.hpp | 13 +- .../EclipseState/Grid/GridProperty.hpp | 6 +- .../Grid/GridPropertyInitializers.hpp | 9 +- .../EclipseState/Grid/MULTREGTScanner.cpp | 7 +- .../EclipseState/Grid/MULTREGTScanner.hpp | 5 +- .../Grid/tests/GridPropertyTests.cpp | 100 +---- .../Grid/tests/MULTREGTScannerTests.cpp | 66 ++-- .../SimulationConfig/SimulationConfig.cpp | 17 +- .../SimulationConfig/SimulationConfig.hpp | 11 +- .../SimulationConfig/ThresholdPressure.cpp | 29 +- .../SimulationConfig/ThresholdPressure.hpp | 9 +- .../tests/SimulationConfigTest.cpp | 64 ++-- .../tests/ThresholdPressureTest.cpp | 124 +++++-- .../EclipseState/tests/EclipseStateTests.cpp | 347 +++++++++--------- 18 files changed, 425 insertions(+), 491 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Eclipse3DProperties.cpp b/opm/parser/eclipse/EclipseState/Eclipse3DProperties.cpp index 94325e747..8f841f4fc 100644 --- a/opm/parser/eclipse/EclipseState/Eclipse3DProperties.cpp +++ b/opm/parser/eclipse/EclipseState/Eclipse3DProperties.cpp @@ -109,7 +109,8 @@ namespace Opm { GridProperties< int >::SupportedKeywordInfo( "FLUXNUM", 1, "1" ), GridProperties< int >::SupportedKeywordInfo( "MULTNUM", 1, "1" ), GridProperties< int >::SupportedKeywordInfo( "FIPNUM" , 1, "1" ), - GridProperties< int >::SupportedKeywordInfo( "MISCNUM", 1, "1" ) + GridProperties< int >::SupportedKeywordInfo( "MISCNUM", 1, "1" ), + GridProperties< int >::SupportedKeywordInfo( "OPERNUM" , 1, "1" ), }; } @@ -309,14 +310,9 @@ namespace Opm { return supportedDoubleKeywords; } - - - - - Eclipse3DProperties::Eclipse3DProperties( const Deck& deck, - std::shared_ptr tableManager, - const EclipseGrid& eclipseGrid) + const TableManager& tableManager, + const EclipseGrid& eclipseGrid) : m_defaultRegion("FLUXNUM"), @@ -326,9 +322,8 @@ namespace Opm { // register the grid properties m_intGridProperties(eclipseGrid, makeSupportedIntKeywords()), m_doubleGridProperties(eclipseGrid, - makeSupportedDoubleKeywords(tableManager.get(), &eclipseGrid, &m_intGridProperties)) + makeSupportedDoubleKeywords(&tableManager, &eclipseGrid, &m_intGridProperties)) { - /* * The EQUALREG, MULTREG, COPYREG, ... keywords are used to manipulate * vectors based on region values; for instance the statement @@ -369,7 +364,7 @@ namespace Opm { GridPropertyPostFunction< double > initPORV(&GridPropertyPostProcessor::initPORV, - tableManager.get(), + &tableManager, &eclipseGrid, &m_intGridProperties, &m_doubleGridProperties); @@ -417,15 +412,6 @@ namespace Opm { return m_doubleGridProperties.hasKeyword( keyword ); } - GridProperties& Eclipse3DProperties::getIntGridProperties() { - return m_intGridProperties; - } - - /// gets properties doubleGridProperties. This does not run any post processors - GridProperties& Eclipse3DProperties::getDoubleGridProperties() { - return m_doubleGridProperties; - } - /* 1. The public methods getIntGridProperty & getDoubleGridProperty will invoke and run the property post processor (if any is registered); the diff --git a/opm/parser/eclipse/EclipseState/Eclipse3DProperties.hpp b/opm/parser/eclipse/EclipseState/Eclipse3DProperties.hpp index a870a26fd..875d4ec27 100644 --- a/opm/parser/eclipse/EclipseState/Eclipse3DProperties.hpp +++ b/opm/parser/eclipse/EclipseState/Eclipse3DProperties.hpp @@ -56,16 +56,15 @@ namespace Opm { }; Eclipse3DProperties(const Deck& deck, - std::shared_ptr tableManager, + const TableManager& tableManager, const EclipseGrid& eclipseGrid); + const GridProperty& getRegion(const DeckItem& regionItem) const; std::string getDefaultRegionKeyword() const; const GridProperty& getIntGridProperty ( const std::string& keyword ) const; const GridProperty& getDoubleGridProperty ( const std::string& keyword ) const; - GridProperties& getIntGridProperties (); - GridProperties& getDoubleGridProperties(); bool hasDeckIntGridProperty(const std::string& keyword) const; bool hasDeckDoubleGridProperty(const std::string& keyword) const; @@ -100,10 +99,6 @@ namespace Opm { static void setKeywordBox(const DeckKeyword& deckKeyword, const DeckRecord&, BoxManager& boxManager); - void initProperties( const Deck& deck, - std::shared_ptr tableManager, - const EclipseGrid& eclipseGrid ); - std::string m_defaultRegion; const UnitSystem& m_deckUnitSystem; GridProperties m_intGridProperties; diff --git a/opm/parser/eclipse/EclipseState/EclipseState.cpp b/opm/parser/eclipse/EclipseState/EclipseState.cpp index 2252326e4..ee155c947 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.cpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -51,20 +50,26 @@ namespace Opm { EclipseState::EclipseState(std::shared_ptr deck, const ParseContext& parseContext) : m_deckUnitSystem( deck->getActiveUnitSystem() ), - m_parseContext( parseContext), - m_tables( std::make_shared( *deck )), - m_eclipseGrid( new EclipseGrid(deck)), + m_parseContext( parseContext ), + m_tables( *deck ), + m_eclipseGrid( std::make_shared(deck)), m_eclipseProperties( *deck, m_tables, *m_eclipseGrid) { initIOConfig(deck); m_schedule = ScheduleConstPtr( new Schedule(m_parseContext , getEclipseGrid() , deck, m_ioConfig) ); initIOConfigPostSchedule(deck); - initTitle(deck); + + if (deck->hasKeyword( "TITLE" )) { + const auto& titleKeyword = deck->getKeyword( "TITLE" ); + const auto& item = titleKeyword.getRecord( 0 ).getItem( 0 ); + std::vector itemValue = item.getData(); + m_title = boost::algorithm::join( itemValue, " " ); + } m_initConfig = std::make_shared(deck); - m_simulationConfig = std::make_shared(m_parseContext, deck, - m_eclipseProperties.getIntGridProperties() ); + m_simulationConfig = std::make_shared(m_parseContext, *deck, + m_eclipseProperties); initTransMult(); initFaults(deck); @@ -98,7 +103,7 @@ namespace Opm { } - std::shared_ptr EclipseState::getTableManager() const { + const TableManager& EclipseState::getTableManager() const { return m_tables; } @@ -171,22 +176,22 @@ namespace Opm { void EclipseState::initTransMult() { EclipseGridConstPtr grid = getEclipseGrid(); m_transMult = std::make_shared( grid->getNX() , grid->getNY() , grid->getNZ()); - // by obtaining doubleGridProperties we're circumventing the runpostprocessor which is called on state.getkeyword - auto& doubleGp = m_eclipseProperties.getDoubleGridProperties(); + + const auto& p = m_eclipseProperties; if (m_eclipseProperties.hasDeckDoubleGridProperty("MULTX")) - m_transMult->applyMULT(doubleGp.getKeyword("MULTX"), FaceDir::XPlus); + m_transMult->applyMULT(p.getDoubleGridProperty("MULTX"), FaceDir::XPlus); if (m_eclipseProperties.hasDeckDoubleGridProperty("MULTX-")) - m_transMult->applyMULT(doubleGp.getKeyword("MULTX-"), FaceDir::XMinus); + m_transMult->applyMULT(p.getDoubleGridProperty("MULTX-"), FaceDir::XMinus); if (m_eclipseProperties.hasDeckDoubleGridProperty("MULTY")) - m_transMult->applyMULT(doubleGp.getKeyword("MULTY"), FaceDir::YPlus); + m_transMult->applyMULT(p.getDoubleGridProperty("MULTY"), FaceDir::YPlus); if (m_eclipseProperties.hasDeckDoubleGridProperty("MULTY-")) - m_transMult->applyMULT(doubleGp.getKeyword("MULTY-"), FaceDir::YMinus); + m_transMult->applyMULT(p.getDoubleGridProperty("MULTY-"), FaceDir::YMinus); if (m_eclipseProperties.hasDeckDoubleGridProperty("MULTZ")) - m_transMult->applyMULT(doubleGp.getKeyword("MULTZ"), FaceDir::ZPlus); + m_transMult->applyMULT(p.getDoubleGridProperty("MULTZ"), FaceDir::ZPlus); if (m_eclipseProperties.hasDeckDoubleGridProperty("MULTZ-")) - m_transMult->applyMULT(doubleGp.getKeyword("MULTZ-"), FaceDir::ZMinus); + m_transMult->applyMULT(p.getDoubleGridProperty("MULTZ-"), FaceDir::ZMinus); } void EclipseState::initFaults(DeckConstPtr deck) { @@ -231,22 +236,13 @@ namespace Opm { std::shared_ptr scanner = std::make_shared( - m_eclipseProperties.getIntGridProperties(), + m_eclipseProperties, multregtKeywords , m_eclipseProperties.getDefaultRegionKeyword()); m_transMult->setMultregtScanner( scanner ); } - void EclipseState::initTitle(DeckConstPtr deck) { - if (deck->hasKeyword("TITLE")) { - const auto& titleKeyword = deck->getKeyword("TITLE"); - const auto& item = titleKeyword.getRecord( 0 ).getItem( 0 ); - std::vector itemValue = item.getData< std::string >(); - m_title = boost::algorithm::join(itemValue, " "); - } - } - void EclipseState::complainAboutAmbiguousKeyword(DeckConstPtr deck, const std::string& keywordName) const { OpmLog::addMessage(Log::MessageType::Error, "The " + keywordName + " keyword must be unique in the deck. Ignoring all!"); auto keywords = deck->getKeywordList(keywordName); diff --git a/opm/parser/eclipse/EclipseState/EclipseState.hpp b/opm/parser/eclipse/EclipseState/EclipseState.hpp index 6f5b506bb..6a2470514 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.hpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.hpp @@ -24,8 +24,9 @@ #include #include -#include #include +#include +#include #include namespace Opm { @@ -40,6 +41,7 @@ namespace Opm { class DeckKeyword; class DeckRecord; class EclipseGrid; + class Eclipse3DProperties; class Fault; class FaultCollection; class InitConfig; @@ -52,6 +54,7 @@ namespace Opm { class TableManager; class TransMult; class UnitSystem; + class MessageContainer; class EclipseState { public: @@ -82,11 +85,12 @@ namespace Opm { bool hasNNC() const; const Eclipse3DProperties& getEclipseProperties() const; - std::shared_ptr getTableManager() const; - // the unit system used by the deck. note that it is rarely needed to convert - // units because internally to opm-parser everything is represented by SI - // units... + const TableManager& getTableManager() const; + + // the unit system used by the deck. note that it is rarely needed to + // convert units because internally to opm-parser everything is + // represented by SI units... const UnitSystem& getDeckUnitSystem() const; void applyModifierDeck( std::shared_ptr deck); @@ -94,28 +98,30 @@ namespace Opm { void initTabdims(std::shared_ptr< const Deck > deck); void initIOConfig(std::shared_ptr< const Deck > deck); void initIOConfigPostSchedule(std::shared_ptr< const Deck > deck); - void initTitle(std::shared_ptr< const Deck > deck); void initTransMult(); void initFaults(std::shared_ptr< const Deck > deck); + void setMULTFLT(std::shared_ptr section) const; void initMULTREGT(std::shared_ptr< const Deck > deck); - void complainAboutAmbiguousKeyword(std::shared_ptr< const Deck > deck, const std::string& keywordName) const; + void complainAboutAmbiguousKeyword(std::shared_ptr< const Deck > deck, + const std::string& keywordName) const; std::shared_ptr< IOConfig > m_ioConfig; std::shared_ptr< const InitConfig > m_initConfig; std::shared_ptr< const Schedule > m_schedule; std::shared_ptr< const SimulationConfig > m_simulationConfig; - std::set phases; std::string m_title; - const UnitSystem& m_deckUnitSystem; std::shared_ptr m_transMult; std::shared_ptr m_faults; std::shared_ptr m_nnc; + + + const UnitSystem& m_deckUnitSystem; const ParseContext& m_parseContext; - std::shared_ptr m_tables; + const TableManager m_tables; std::shared_ptr m_eclipseGrid; Eclipse3DProperties m_eclipseProperties; MessageContainer m_messageContainer; diff --git a/opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp b/opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp index 159e5fdba..b27613845 100644 --- a/opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp @@ -28,9 +28,8 @@ #include #include -#include -/** +/* This class implements a container (std::unordered_map>) of Gridproperties. Usage is as follows: @@ -100,14 +99,16 @@ namespace Opm { throw std::invalid_argument("Invalid index"); } - GridProperty& getKeyword(size_t index) { + GridProperty& getKeyword(size_t index) { if (index < size()) return *m_property_list[index]; else - throw std::invalid_argument("Invalid index"); + throw std::invalid_argument( "Invalid index" ); } + + const GridProperty& getInitializedKeyword(const std::string& keyword) const { if (hasKeyword(keyword)) return *m_properties.at( keyword ); @@ -154,8 +155,8 @@ namespace Opm { void copyKeyword(const std::string& srcField , const std::string& targetField , const Box& inputBox) { - auto& src = getKeyword( srcField ); - auto& target = getOrCreateProperty( targetField ); + const auto& src = this->getKeyword( srcField ); + auto& target = this->getOrCreateProperty( targetField ); target.copyFrom( src , inputBox ); } diff --git a/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp b/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp index 756ef24de..793b1a470 100644 --- a/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp @@ -131,8 +131,6 @@ public: const std::string& getKeywordName() const; const SupportedKeywordInfo& getKeywordInfo() const; - void runPostProcessor(); - ERT::EclKW getEclKW() const; ERT::EclKW getEclKW( const EclipseGrid & ) const; @@ -147,6 +145,10 @@ private: const DeckItem& getDeckItem( const DeckKeyword& ); void setDataPoint(size_t sourceIdx, size_t targetIdx, const DeckItem& deckItem); + void runPostProcessor(); + + friend class Eclipse3DProperties; // currently needed for runPostProcessor, see Eclipse3DProperties::getDoubleGridProperty + size_t m_nx, m_ny, m_nz; SupportedKeywordInfo m_kwInfo; std::vector m_data; diff --git a/opm/parser/eclipse/EclipseState/Grid/GridPropertyInitializers.hpp b/opm/parser/eclipse/EclipseState/Grid/GridPropertyInitializers.hpp index 32f1a122a..39bff849a 100644 --- a/opm/parser/eclipse/EclipseState/Grid/GridPropertyInitializers.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/GridPropertyInitializers.hpp @@ -40,9 +40,8 @@ template< typename T > size_t, const TableManager*, const EclipseGrid*, - GridProperties* ig_props, - GridProperties* dg_props - ); + GridProperties*, + GridProperties*); GridPropertyInitFunction( signature, @@ -87,8 +86,8 @@ template< typename T > private: signature f = nullptr; - const TableManager* tm = nullptr; - const EclipseGrid* eg = nullptr; + const TableManager* tm = nullptr; + const EclipseGrid* eg = nullptr; GridProperties* igp = nullptr; GridProperties* dgp = nullptr; diff --git a/opm/parser/eclipse/EclipseState/Grid/MULTREGTScanner.cpp b/opm/parser/eclipse/EclipseState/Grid/MULTREGTScanner.cpp index 0f53c3879..c27f62e1c 100644 --- a/opm/parser/eclipse/EclipseState/Grid/MULTREGTScanner.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/MULTREGTScanner.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -126,7 +127,7 @@ namespace Opm { Then it will go through the different regions and looking for interface with the wanted region values. */ - MULTREGTScanner::MULTREGTScanner(const GridProperties& cellRegionNumbers, + MULTREGTScanner::MULTREGTScanner(const Eclipse3DProperties& cellRegionNumbers, const std::vector< const DeckKeyword* >& keywords, const std::string& defaultRegion ) : m_cellRegionNumbers(cellRegionNumbers) { @@ -136,7 +137,7 @@ namespace Opm { MULTREGTSearchMap searchPairs; for (std::vector::const_iterator record = m_records.begin(); record != m_records.end(); ++record) { - if (cellRegionNumbers.hasKeyword( record->m_region.getValue())) { + if (cellRegionNumbers.hasDeckIntGridProperty( record->m_region.getValue())) { if (record->m_srcRegion.hasValue() && record->m_targetRegion.hasValue()) { int srcRegion = record->m_srcRegion.getValue(); int targetRegion = record->m_targetRegion.getValue(); @@ -234,7 +235,7 @@ namespace Opm { double MULTREGTScanner::getRegionMultiplier(size_t globalIndex1 , size_t globalIndex2, FaceDir::DirEnum faceDir) const { for (auto iter = m_searchMap.begin(); iter != m_searchMap.end(); iter++) { - const Opm::GridProperty& region = m_cellRegionNumbers.getKeyword( (*iter).first ); + const Opm::GridProperty& region = m_cellRegionNumbers.getIntGridProperty( (*iter).first ); MULTREGTSearchMap map = (*iter).second; int regionId1 = region.iget(globalIndex1); diff --git a/opm/parser/eclipse/EclipseState/Grid/MULTREGTScanner.hpp b/opm/parser/eclipse/EclipseState/Grid/MULTREGTScanner.hpp index 097454879..87ec9364a 100644 --- a/opm/parser/eclipse/EclipseState/Grid/MULTREGTScanner.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/MULTREGTScanner.hpp @@ -21,6 +21,7 @@ #ifndef MULTREGTSCANNER_HPP #define MULTREGTSCANNER_HPP +#include #include #include @@ -69,7 +70,7 @@ namespace Opm { class MULTREGTScanner { public: - MULTREGTScanner(const GridProperties& cellRegionNumbers, + MULTREGTScanner(const Eclipse3DProperties& cellRegionNumbers, const std::vector< const DeckKeyword* >& keywords, const std::string& defaultRegion); double getRegionMultiplier(size_t globalCellIdx1, size_t globalCellIdx2, FaceDir::DirEnum faceDir) const; @@ -79,7 +80,7 @@ namespace Opm { void assertKeywordSupported(const DeckKeyword& deckKeyword, const std::string& defaultRegion); std::vector< MULTREGTRecord > m_records; std::map m_searchMap; - const GridProperties& m_cellRegionNumbers; + const Eclipse3DProperties& m_cellRegionNumbers; }; } diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp index f7843b2d5..755323b15 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp @@ -157,24 +157,23 @@ BOOST_AUTO_TEST_CASE(SetFromDeckKeyword) { } } - BOOST_AUTO_TEST_CASE(copy) { typedef Opm::GridProperty::SupportedKeywordInfo SupportedKeywordInfo; - SupportedKeywordInfo keywordInfo1("P1" , 0, "1"); - SupportedKeywordInfo keywordInfo2("P2" , 9, "1"); - Opm::GridProperty prop1( 4 , 4 , 2 , keywordInfo1); - Opm::GridProperty prop2( 4 , 4 , 2 , keywordInfo2); + SupportedKeywordInfo keywordInfo1("P1", 0, "1"); + SupportedKeywordInfo keywordInfo2("P2", 9, "1"); + Opm::GridProperty prop1(4, 4, 2, keywordInfo1); + Opm::GridProperty prop2(4, 4, 2, keywordInfo2); - Opm::Box global(4,4,2); - Opm::Box layer0(global , 0,3,0,3,0,0); + Opm::Box global(4, 4, 2); + Opm::Box layer0(global, 0, 3, 0, 3, 0, 0); - prop2.copyFrom(prop1 , layer0); + prop2.copyFrom(prop1, layer0); - for (size_t j=0; j < 4; j++) { - for (size_t i=0; i < 4; i++) { + for (size_t j = 0; j < 4; j++) { + for (size_t i = 0; i < 4; i++) { - BOOST_CHECK_EQUAL( prop2.iget(i,j,0), 0 ); - BOOST_CHECK_EQUAL( prop2.iget(i,j,1), 9 ); + BOOST_CHECK_EQUAL(prop2.iget(i, j, 0), 0); + BOOST_CHECK_EQUAL(prop2.iget(i, j, 1), 9); } } } @@ -363,6 +362,9 @@ BOOST_AUTO_TEST_CASE(GridPropertyInitialization) { // make sure that EclipseState does not throw if it is asked for a supported // grid property that is not contained in the deck + BOOST_CHECK_NO_THROW(props.hasDeckDoubleGridProperty("ISWU")); + BOOST_CHECK_NO_THROW(props.hasDeckIntGridProperty("FLUXNUM")); + BOOST_CHECK(!props.hasDeckDoubleGridProperty("ISWU")); BOOST_CHECK(!props.hasDeckIntGridProperty("FLUXNUM")); @@ -397,80 +399,6 @@ void TestPostProcessorMul(std::vector< double >& values, } - -static Opm::DeckPtr createDeck() { - const char *deckData = - "RUNSPEC\n" - "\n" - "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" - "100*0.25 /\n" - "MULTPV \n" - "1000*0.10 / \n" - "PORO \n" - "1000*0.10 / \n" - "EDIT\n" - "\n"; - - Opm::ParserPtr parser(new Opm::Parser()); - return parser->parseString(deckData, Opm::ParseContext()) ; -} - -BOOST_AUTO_TEST_CASE(GridPropertyPostProcessors) { - typedef Opm::GridPropertySupportedKeywordInfo SupportedKeywordInfo; - - Opm::DeckPtr deck = createDeck(); - Opm::EclipseGrid grid(deck); - std::shared_ptr tm = std::make_shared(*deck); - Opm::Eclipse3DProperties props(*deck, tm, grid); - - SupportedKeywordInfo kwInfo1("MULTPV" , 1.0 , "1"); - Opm::GridPropertyPostFunction< double > gfunc( &TestPostProcessorMul, - tm.get(), - &grid, - &props.getIntGridProperties(), - &props.getDoubleGridProperties() ); - - SupportedKeywordInfo kwInfo2("PORO", 1.0, gfunc, "1"); - std::vector supportedKeywords = { kwInfo1, kwInfo2 }; - - Opm::GridProperties properties(grid, std::move( supportedKeywords ) ); - - { - auto& poro = properties.getKeyword("PORO"); - auto& multpv = properties.getKeyword("MULTPV"); - - poro.loadFromDeckKeyword( deck->getKeyword("PORO" , 0)); - multpv.loadFromDeckKeyword( deck->getKeyword("MULTPV" , 0)); - - poro.runPostProcessor(); - multpv.runPostProcessor(); - - for (size_t g = 0; g < 1000; g++) { - BOOST_CHECK_EQUAL( multpv.iget(g) , 0.10 ); - BOOST_CHECK_EQUAL( poro.iget(g) , 0.20 ); - } - - poro.runPostProcessor(); - multpv.runPostProcessor(); - - for (size_t g = 0; g < 1000; g++) { - BOOST_CHECK_EQUAL( multpv.iget(g) , 0.10 ); - BOOST_CHECK_EQUAL( poro.iget(g) , 0.20 ); - } - } -} - - - BOOST_AUTO_TEST_CASE(multiply) { typedef Opm::GridProperty::SupportedKeywordInfo SupportedKeywordInfo; SupportedKeywordInfo keywordInfo("P" , 10 , "1"); diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/MULTREGTScannerTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/MULTREGTScannerTests.cpp index 56078822b..a9cde70a4 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/MULTREGTScannerTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/MULTREGTScannerTests.cpp @@ -98,38 +98,28 @@ static Opm::DeckPtr createInvalidMULTREGTDeck() { } - - BOOST_AUTO_TEST_CASE(InvalidInput) { - typedef Opm::GridProperties::SupportedKeywordInfo SupportedKeywordInfo; - std::vector supportedKeywords = { - SupportedKeywordInfo("FLUXNUM" , 1 , "1") , - SupportedKeywordInfo("OPERNUM" , 1 , "1") , - SupportedKeywordInfo("MULTNUM" , 1 , "1") - }; - - Opm::DeckPtr deck = createInvalidMULTREGTDeck(); Opm::EclipseGrid grid( deck ); - Opm::GridProperties gridProperties( grid, std::move( supportedKeywords ) ); + Opm::Eclipse3DProperties ep( *deck, Opm::TableManager( *deck ), grid ); // Invalid direction - std::vector< const Opm::DeckKeyword* > keywords0; - const auto& multregtKeyword0 = deck->getKeyword("MULTREGT",0); + std::vector keywords0; + const auto& multregtKeyword0 = deck->getKeyword( "MULTREGT", 0 ); keywords0.push_back( &multregtKeyword0 ); - BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner(gridProperties, keywords0, "MULTNUM"); , std::invalid_argument); + BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner( ep, keywords0, "MULTNUM" ); , std::invalid_argument ); // Not supported region std::vector keywords1; const auto& multregtKeyword1 = deck->getKeyword( "MULTREGT", 1 ); keywords1.push_back( &multregtKeyword1 ); - BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner( gridProperties, keywords1, "MULTNUM" ); , std::invalid_argument ); + BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner( ep, keywords1, "MULTNUM" ); , std::invalid_argument ); // The keyword is ok; but it refers to a region which is not in the deck. - std::vector< const Opm::DeckKeyword* > keywords2; - const auto& multregtKeyword2 = deck->getKeyword( "MULTREGT",2); + std::vector keywords2; + const auto& multregtKeyword2 = deck->getKeyword( "MULTREGT", 2 ); keywords2.push_back( &multregtKeyword2 ); - BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner(gridProperties,keywords2,"MULTNUM"); , std::logic_error); + BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner( ep, keywords2, "MULTNUM" ); , std::logic_error ); } @@ -168,41 +158,37 @@ static Opm::DeckPtr createNotSupportedMULTREGTDeck() { } -BOOST_AUTO_TEST_CASE(NotSupported) { - typedef Opm::GridProperties::SupportedKeywordInfo SupportedKeywordInfo; - std::vector supportedKeywords = { - SupportedKeywordInfo("FLUXNUM" , 1 , "1") , - SupportedKeywordInfo("OPERNUM" , 1 , "1") , - SupportedKeywordInfo("MULTNUM" , 1 , "1") - }; - Opm::DeckPtr deck = createNotSupportedMULTREGTDeck(); + +BOOST_AUTO_TEST_CASE(NotSupported) { + Opm::DeckPtr deck = createNotSupportedMULTREGTDeck(); Opm::EclipseGrid grid( deck ); - Opm::GridProperties gridProperties( grid, std::move( supportedKeywords ) ); + Opm::Eclipse3DProperties ep( *deck, Opm::TableManager( *deck ), grid ); // Not support NOAQUNNC behaviour - std::vector< const Opm::DeckKeyword* > keywords0; - const auto& multregtKeyword0 = deck->getKeyword("MULTREGT",0); + std::vector keywords0; + const auto& multregtKeyword0 = deck->getKeyword( "MULTREGT", 0 ); keywords0.push_back( &multregtKeyword0 ); - BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner(gridProperties,keywords0,"MULTNUM"); , std::invalid_argument); + BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner( ep, keywords0, "MULTNUM" ); , std::invalid_argument ); // Defaulted from value - not supported - std::vector< const Opm::DeckKeyword* > keywords1; - const auto& multregtKeyword1 = deck->getKeyword("MULTREGT",1); + std::vector keywords1; + const auto& multregtKeyword1 = deck->getKeyword( "MULTREGT", 1 ); keywords1.push_back( &multregtKeyword1 ); - BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner(gridProperties,keywords1,"MULTNUM"); , std::invalid_argument); + BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner( ep, keywords1, "MULTNUM" ); , std::invalid_argument ); + // Defaulted to value - not supported - std::vector< const Opm::DeckKeyword* > keywords2; - const auto& multregtKeyword2 = deck->getKeyword("MULTREGT",2); + std::vector keywords2; + const auto& multregtKeyword2 = deck->getKeyword( "MULTREGT", 2 ); keywords2.push_back( &multregtKeyword2 ); - BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner(gridProperties,keywords2,"MULTNUM"); , std::invalid_argument); + BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner( ep, keywords2, "MULTNUM" ); , std::invalid_argument ); // srcValue == targetValue - not supported - std::vector< const Opm::DeckKeyword* > keywords3; - const Opm::DeckKeyword& multregtKeyword3 = deck->getKeyword("MULTREGT",3); + std::vector keywords3; + const Opm::DeckKeyword& multregtKeyword3 = deck->getKeyword( "MULTREGT", 3 ); keywords3.push_back( &multregtKeyword3 ); - BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner(gridProperties,keywords3 , "MULTNUM"); , std::invalid_argument); + BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner( ep, keywords3, "MULTNUM" ); , std::invalid_argument ); } static Opm::DeckPtr createCopyMULTNUMDeck() { @@ -231,8 +217,6 @@ static Opm::DeckPtr createCopyMULTNUMDeck() { return parser->parseString(deckData, Opm::ParseContext()) ; } - - BOOST_AUTO_TEST_CASE(MULTREGT_COPY_MULTNUM) { Opm::DeckPtr deck = createCopyMULTNUMDeck(); Opm::EclipseState state(deck , Opm::ParseContext()); diff --git a/opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.cpp b/opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.cpp index 87a40e5d0..c9796dfa3 100644 --- a/opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.cpp +++ b/opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -46,14 +47,14 @@ namespace Opm { SimulationConfig::SimulationConfig(const ParseContext& parseContext, - DeckConstPtr deck, - GridProperties& gridProperties) : + const Deck& deck, + const Eclipse3DProperties& eclipseProperties) : m_useCPR(false), m_DISGAS(false), m_VAPOIL(false) { - if (Section::hasRUNSPEC(*deck)) { - const RUNSPECSection runspec(*deck); + if (Section::hasRUNSPEC(deck)) { + const RUNSPECSection runspec(deck); if (runspec.hasKeyword()) { const auto& cpr = runspec.getKeyword(); if (cpr.size() > 0) @@ -69,14 +70,14 @@ namespace Opm { } } - initThresholdPressure(parseContext , deck, gridProperties); + initThresholdPressure(parseContext , deck, eclipseProperties); } void SimulationConfig::initThresholdPressure(const ParseContext& parseContext, - DeckConstPtr deck, - GridProperties& gridProperties) { - m_ThresholdPressure = std::make_shared(parseContext , deck, gridProperties); + const Deck& deck, + const Eclipse3DProperties& eclipseProperties) { + m_ThresholdPressure = std::make_shared(parseContext , deck, eclipseProperties); } diff --git a/opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.hpp b/opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.hpp index 7329cf4ae..0593ab804 100644 --- a/opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.hpp +++ b/opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.hpp @@ -21,11 +21,10 @@ #define OPM_SIMULATION_CONFIG_HPP #include +#include namespace Opm { - template< typename > class GridProperties; - class ThresholdPressure; class ParseContext; @@ -34,8 +33,8 @@ namespace Opm { public: SimulationConfig(const ParseContext& parseContext, - DeckConstPtr deck, - GridProperties& gridProperties); + const Deck& deck, + const Eclipse3DProperties& gridProperties); std::shared_ptr getThresholdPressure() const; bool hasThresholdPressure() const; @@ -46,8 +45,8 @@ namespace Opm { private: void initThresholdPressure(const ParseContext& parseContext, - DeckConstPtr deck, - GridProperties& gridProperties); + const Deck& deck, + const Eclipse3DProperties& gridProperties); std::shared_ptr< const ThresholdPressure > m_ThresholdPressure; bool m_useCPR; diff --git a/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.cpp b/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.cpp index dd0158d0e..879c5eea7 100644 --- a/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.cpp +++ b/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.cpp @@ -16,9 +16,10 @@ You should have received a copy of the GNU General Public License along with OPM. If not, see . */ + #include #include -#include +#include #include #include #include @@ -29,15 +30,16 @@ namespace Opm { - ThresholdPressure::ThresholdPressure(const ParseContext& parseContext, DeckConstPtr deck, - GridProperties& gridProperties) - : m_parseContext( parseContext ) + ThresholdPressure::ThresholdPressure(const ParseContext& parseContext, + const Deck& deck, + const Eclipse3DProperties& eclipseProperties) : + m_parseContext( parseContext ) { - if (Section::hasRUNSPEC(*deck) && Section::hasSOLUTION(*deck)) { - std::shared_ptr runspecSection = std::make_shared(*deck); - std::shared_ptr solutionSection = std::make_shared(*deck); - initThresholdPressure(parseContext, runspecSection, solutionSection, gridProperties); + if (Section::hasRUNSPEC( deck ) && Section::hasSOLUTION( deck )) { + std::shared_ptr runspecSection = std::make_shared( deck ); + std::shared_ptr solutionSection = std::make_shared( deck ); + initThresholdPressure( parseContext, runspecSection, solutionSection, eclipseProperties ); } } @@ -68,11 +70,11 @@ namespace Opm { void ThresholdPressure::initThresholdPressure(const ParseContext& /* parseContext */, std::shared_ptr runspecSection, std::shared_ptr solutionSection, - GridProperties& gridProperties) { + const Eclipse3DProperties& eclipseProperties) { bool thpresOption = false; const bool thpresKeyword = solutionSection->hasKeyword( ); - const bool hasEqlnumKeyword = gridProperties.hasKeyword( ); + const bool hasEqlnumKeyword = eclipseProperties.hasDeckIntGridProperty( "EQLNUM" ); int maxEqlnum = 0; //Is THPRES option set? @@ -96,7 +98,7 @@ namespace Opm { { //Find max of eqlnum if (hasEqlnumKeyword) { - const auto& eqlnumKeyword = gridProperties.getKeyword( ); + const auto& eqlnumKeyword = eclipseProperties.getIntGridProperty( "EQLNUM" ); const auto& eqlnum = eqlnumKeyword.getData(); maxEqlnum = *std::max_element(eqlnum.begin(), eqlnum.end()); @@ -190,8 +192,3 @@ namespace Opm { } //namespace Opm - - - - - diff --git a/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.hpp b/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.hpp index 229faf1a8..838fbb775 100644 --- a/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.hpp +++ b/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.hpp @@ -23,9 +23,10 @@ #include #include +#include + namespace Opm { - template< typename > class GridProperties; class Deck; class ParseContext; @@ -37,8 +38,8 @@ namespace Opm { public: ThresholdPressure(const ParseContext& parseContext, - std::shared_ptr< const Deck > deck, - GridProperties& gridProperties); + const Deck& deck, + const Eclipse3DProperties& eclipseProperties); /* @@ -71,7 +72,7 @@ namespace Opm { void initThresholdPressure(const ParseContext& parseContext, std::shared_ptr runspecSection, std::shared_ptr solutionSection, - GridProperties& gridProperties); + const Eclipse3DProperties& eclipseProperties); static std::pair makeIndex(int r1 , int r2); void addPair(int r1 , int r2 , const std::pair& valuePair); diff --git a/opm/parser/eclipse/EclipseState/SimulationConfig/tests/SimulationConfigTest.cpp b/opm/parser/eclipse/EclipseState/SimulationConfig/tests/SimulationConfigTest.cpp index 6265f8f86..68c5f96ba 100644 --- a/opm/parser/eclipse/EclipseState/SimulationConfig/tests/SimulationConfigTest.cpp +++ b/opm/parser/eclipse/EclipseState/SimulationConfig/tests/SimulationConfigTest.cpp @@ -110,70 +110,60 @@ static DeckPtr createDeck(const ParseContext& parseContext , const std::string& return parser.parseString(input, parseContext); } -static GridProperties getGridProperties() { - GridPropertySupportedKeywordInfo kwInfo = GridPropertySupportedKeywordInfo("EQLNUM", 3, ""); - std::vector> supportedKeywordsVec; - supportedKeywordsVec.push_back(kwInfo); - const EclipseGrid eclipseGrid(3, 3, 3); - GridProperties gridProperties(eclipseGrid, std::move(supportedKeywordsVec)); - gridProperties.addKeyword("EQLNUM"); - return gridProperties; +static Eclipse3DProperties getGridProperties(DeckPtr deck) { + return Eclipse3DProperties( *deck, TableManager( *deck ), EclipseGrid( 10, 3, 4 ) ); } BOOST_AUTO_TEST_CASE(SimulationConfigGetThresholdPressureTableTest) { ParseContext parseContext; - auto gp = getGridProperties(); - DeckPtr deck = createDeck(parseContext, inputStr); + DeckPtr deck = createDeck(parseContext , inputStr); SimulationConfigConstPtr simulationConfigPtr; - BOOST_CHECK_NO_THROW( simulationConfigPtr = std::make_shared( parseContext, deck, gp ) ); + BOOST_CHECK_NO_THROW(simulationConfigPtr = std::make_shared + (parseContext , *deck, getGridProperties(deck))); } + BOOST_AUTO_TEST_CASE(SimulationConfigNOTHPRES) { ParseContext parseContext; - auto gp = getGridProperties(); DeckPtr deck = createDeck(parseContext , inputStr_noTHPRES); - SimulationConfig simulationConfig(parseContext , deck, gp); - BOOST_CHECK_EQUAL( false , simulationConfig.hasThresholdPressure()); + SimulationConfig simulationConfig(parseContext , *deck, getGridProperties(deck)); + BOOST_CHECK( !simulationConfig.hasThresholdPressure() ); } BOOST_AUTO_TEST_CASE(SimulationConfigCPRNotUsed) { - ParseContext parseContext; - auto gp = getGridProperties(); - DeckPtr deck = createDeck(parseContext , inputStr_noTHPRES); - SimulationConfig simulationConfig(parseContext , deck, gp); - BOOST_CHECK_EQUAL( false , simulationConfig.useCPR()); + ParseContext parseContext; + DeckPtr deck = createDeck(parseContext , inputStr_noTHPRES); + SimulationConfig simulationConfig(parseContext , *deck, getGridProperties(deck)); + BOOST_CHECK( ! simulationConfig.useCPR()); } BOOST_AUTO_TEST_CASE(SimulationConfigCPRUsed) { - ParseContext parseContext; - auto gp = getGridProperties(); - DeckPtr deck = createDeck(parseContext , inputStr_cpr); - SUMMARYSection summary(*deck); - SimulationConfig simulationConfig(parseContext , deck, gp); - BOOST_CHECK_EQUAL( true , simulationConfig.useCPR()); - BOOST_CHECK_EQUAL( false , summary.hasKeyword("CPR")); + ParseContext parseContext; + DeckPtr deck = createDeck(parseContext , inputStr_cpr); + SUMMARYSection summary(*deck); + SimulationConfig simulationConfig(parseContext , *deck, getGridProperties(deck)); + BOOST_CHECK( simulationConfig.useCPR() ); + BOOST_CHECK( ! summary.hasKeyword("CPR") ); } BOOST_AUTO_TEST_CASE(SimulationConfigCPRInSUMMARYSection) { ParseContext parseContext; - auto gp = getGridProperties(); DeckPtr deck = createDeck(parseContext , inputStr_cpr_in_SUMMARY); SUMMARYSection summary(*deck); - SimulationConfig simulationConfig(parseContext , deck, gp); - BOOST_CHECK_EQUAL( false , simulationConfig.useCPR()); - BOOST_CHECK_EQUAL( true , summary.hasKeyword("CPR")); + SimulationConfig simulationConfig(parseContext , *deck, getGridProperties(deck)); + BOOST_CHECK( ! simulationConfig.useCPR()); + BOOST_CHECK( summary.hasKeyword("CPR")); } BOOST_AUTO_TEST_CASE(SimulationConfigCPRBoth) { ParseContext parseContext; - auto gp = getGridProperties(); DeckPtr deck = createDeck(parseContext , inputStr_cpr_BOTH); SUMMARYSection summary(*deck); - SimulationConfig simulationConfig(parseContext , deck, gp); - BOOST_CHECK_EQUAL( true , simulationConfig.useCPR()); - BOOST_CHECK_EQUAL( true , summary.hasKeyword("CPR")); + SimulationConfig simulationConfig(parseContext , *deck, getGridProperties(deck)); + BOOST_CHECK( simulationConfig.useCPR()); + BOOST_CHECK( summary.hasKeyword("CPR")); const auto& cpr = summary.getKeyword(); const auto& record = cpr.getRecord(0); @@ -193,15 +183,13 @@ BOOST_AUTO_TEST_CASE(SimulationConfigCPRRUnspecWithData) { BOOST_AUTO_TEST_CASE(SimulationConfig_VAPOIL_DISGAS) { ParseContext parseContext; - auto gp1 = getGridProperties(); DeckPtr deck = createDeck(parseContext , inputStr); - SimulationConfig simulationConfig(parseContext , deck, gp1); + SimulationConfig simulationConfig(parseContext , *deck, getGridProperties(deck)); BOOST_CHECK_EQUAL( false , simulationConfig.hasDISGAS()); BOOST_CHECK_EQUAL( false , simulationConfig.hasVAPOIL()); - auto gp2 = getGridProperties(); DeckPtr deck_vd = createDeck(parseContext, inputStr_vap_dis); - SimulationConfig simulationConfig_vd(parseContext , deck_vd, gp2); + SimulationConfig simulationConfig_vd(parseContext , *deck_vd, getGridProperties(deck_vd)); BOOST_CHECK_EQUAL( true , simulationConfig_vd.hasDISGAS()); BOOST_CHECK_EQUAL( true , simulationConfig_vd.hasVAPOIL()); } diff --git a/opm/parser/eclipse/EclipseState/SimulationConfig/tests/ThresholdPressureTest.cpp b/opm/parser/eclipse/EclipseState/SimulationConfig/tests/ThresholdPressureTest.cpp index 15213ab0f..056533d85 100644 --- a/opm/parser/eclipse/EclipseState/SimulationConfig/tests/ThresholdPressureTest.cpp +++ b/opm/parser/eclipse/EclipseState/SimulationConfig/tests/ThresholdPressureTest.cpp @@ -29,7 +29,10 @@ #include #include +#include +#include #include +#include #include #include @@ -53,6 +56,42 @@ const std::string& inputStr = "RUNSPEC\n" "/\n" "\n"; +const std::string& inputStrWithEqlNum = + "RUNSPEC\n" + "EQLOPTS\n" + "THPRES /\n " + "\n" + "REGIONS\n" + "EQLNUM\n" + " 27*3 /\n" + "SOLUTION\n" + "THPRES\n" + "1 2 12.0/\n" + "1 3 5.0/\n" + "2 3 33.0 /\n" + "2 3 7.0/\n" + "/\n" + "\n"; + + +const std::string& inputStrWithEqlNumall0 = + "RUNSPEC\n" + "EQLOPTS\n" + "THPRES /\n " + "\n" + "REGIONS\n" + "EQLNUM\n" + " 27*0 /\n" + "SOLUTION\n" + "THPRES\n" + "1 2 12.0/\n" + "1 3 5.0/\n" + "2 3 33.0 /\n" + "2 3 7.0/\n" + "/\n" + "\n"; + + const std::string& inputStrNoSolutionSection = "RUNSPEC\n" "EQLOPTS\n" "THPRES /\n " @@ -123,7 +162,9 @@ const std::string& inputStrMissingPressure = "RUNSPEC\n" "EQLOPTS\n" "THPRES /\n " "\n" - + "REGIONS\n" + "EQLNUM\n" + " 27*3 /\n" "SOLUTION\n" "THPRES\n" "1 2 12.0/\n" @@ -140,23 +181,28 @@ static DeckPtr createDeck(const ParseContext& parseContext , const std::string& return parser.parseString(input , parseContext); } -static GridProperties getGridProperties(int defaultEqlnum = 3, bool addKeyword = true) { - GridPropertySupportedKeywordInfo kwInfo = GridPropertySupportedKeywordInfo( "EQLNUM", defaultEqlnum, "" ); - std::vector> supportedKeywordsVec( 1, kwInfo ); - const EclipseGrid eclipseGrid( 3, 3, 3 ); - GridProperties gridProperties( eclipseGrid, std::move( supportedKeywordsVec ) ); - if (addKeyword) { - gridProperties.addKeyword("EQLNUM"); - } - return gridProperties; +static Eclipse3DProperties getEclipseProperties(const Deck& deck, + ParseContext& parseContext) +{ + static const EclipseGrid eclipseGrid( 3, 3, 3 ); + return Eclipse3DProperties( deck, TableManager( deck ), eclipseGrid ); } + +BOOST_AUTO_TEST_CASE(ThresholdPressureDeckHasEqlnum) { + ParseContext parseContext; + DeckPtr deck = createDeck(parseContext , inputStrWithEqlNum); + auto ep = getEclipseProperties( *deck, parseContext ); + + BOOST_CHECK (ep.hasDeckIntGridProperty("EQLNUM")); +} + + BOOST_AUTO_TEST_CASE(ThresholdPressureTest) { ParseContext parseContext; - DeckPtr deck = createDeck(parseContext , inputStr); - auto gridProperties = getGridProperties(); - ThresholdPressureConstPtr thp = std::make_shared(parseContext , deck, gridProperties); - + DeckPtr deck = createDeck(parseContext , inputStrWithEqlNum); + auto ep = getEclipseProperties( *deck, parseContext ); + ThresholdPressureConstPtr thp = std::make_shared(parseContext , *deck, ep); BOOST_CHECK_EQUAL( thp->getThresholdPressure(1,2) , 1200000.0 ); BOOST_CHECK_EQUAL( thp->getThresholdPressure(2,1) , 1200000.0 ); @@ -171,8 +217,8 @@ BOOST_AUTO_TEST_CASE(ThresholdPressureTest) { BOOST_AUTO_TEST_CASE(ThresholdPressureEmptyTest) { ParseContext parseContext; DeckPtr deck = createDeck(parseContext , inputStrNoSolutionSection); - auto gridProperties = getGridProperties(); - ThresholdPressureConstPtr thresholdPressurePtr = std::make_shared(parseContext , deck, gridProperties); + auto ep = getEclipseProperties(*deck, parseContext); + ThresholdPressureConstPtr thresholdPressurePtr = std::make_shared(parseContext , *deck, ep); BOOST_CHECK_EQUAL(0, thresholdPressurePtr->size()); } @@ -181,12 +227,13 @@ BOOST_AUTO_TEST_CASE(ThresholdPressureNoTHPREStest) { ParseContext parseContext; DeckPtr deck_no_thpres = createDeck(parseContext , inputStrNoTHPRESinSolutionNorRUNSPEC); DeckPtr deck_no_thpres2 = createDeck(parseContext , inputStrTHPRESinRUNSPECnotSoultion); - auto gridProperties = getGridProperties(); + auto ep = getEclipseProperties(*deck_no_thpres, parseContext); + auto ep2 = getEclipseProperties(*deck_no_thpres2, parseContext); ThresholdPressureConstPtr thresholdPressurePtr; - BOOST_CHECK_NO_THROW(thresholdPressurePtr = std::make_shared(parseContext , deck_no_thpres, gridProperties)); + BOOST_CHECK_NO_THROW(thresholdPressurePtr = std::make_shared(parseContext , *deck_no_thpres, ep)); ThresholdPressureConstPtr thresholdPressurePtr2; - BOOST_CHECK_NO_THROW(thresholdPressurePtr2 = std::make_shared(parseContext , deck_no_thpres2, gridProperties)); + BOOST_CHECK_NO_THROW(thresholdPressurePtr2 = std::make_shared(parseContext , *deck_no_thpres2, ep2)); BOOST_CHECK_EQUAL(0, thresholdPressurePtr->size()); BOOST_CHECK_EQUAL(0, thresholdPressurePtr2->size()); @@ -196,33 +243,42 @@ BOOST_AUTO_TEST_CASE(ThresholdPressureNoTHPREStest) { BOOST_AUTO_TEST_CASE(ThresholdPressureThrowTest) { ParseContext parseContext; DeckPtr deck = createDeck(parseContext , inputStr); + DeckPtr deck_all0 = createDeck(parseContext , inputStrWithEqlNumall0); DeckPtr deck_irrevers = createDeck(parseContext , inputStrIrrevers); DeckPtr deck_inconsistency = createDeck(parseContext , inputStrInconsistency); DeckPtr deck_highRegNum = createDeck(parseContext , inputStrTooHighRegionNumbers); DeckPtr deck_missingData = createDeck(parseContext , inputStrMissingData); DeckPtr deck_missingPressure = createDeck(parseContext , inputStrMissingPressure); - auto gridProperties = getGridProperties(); - BOOST_CHECK_THROW(std::make_shared(parseContext,deck_irrevers, gridProperties), std::runtime_error); - BOOST_CHECK_THROW(std::make_shared(parseContext,deck_inconsistency, gridProperties), std::runtime_error); - BOOST_CHECK_THROW(std::make_shared(parseContext,deck_highRegNum, gridProperties), std::runtime_error); - BOOST_CHECK_THROW(std::make_shared(parseContext,deck_missingData, gridProperties), std::runtime_error); + auto ep = getEclipseProperties(*deck , parseContext); + auto ep_irrevers = getEclipseProperties(*deck_irrevers , parseContext); + auto ep_inconsistency = getEclipseProperties(*deck_inconsistency , parseContext); + auto ep_highRegNum = getEclipseProperties(*deck_highRegNum , parseContext); + auto ep_missingData = getEclipseProperties(*deck_missingData , parseContext); + auto ep_missingPressure = getEclipseProperties(*deck_missingPressure , parseContext); + + BOOST_CHECK_THROW(std::make_shared(parseContext,*deck_irrevers, ep_irrevers), std::runtime_error); + BOOST_CHECK_THROW(std::make_shared(parseContext,*deck_inconsistency, ep_inconsistency), std::runtime_error); + BOOST_CHECK_THROW(std::make_shared(parseContext,*deck_highRegNum, ep_highRegNum), std::runtime_error); + BOOST_CHECK_THROW(std::make_shared(parseContext,*deck_missingData, ep_missingData), std::runtime_error); { - auto gridPropertiesEQLNUMkeywordNotAdded = getGridProperties(3, false); - BOOST_CHECK_THROW(std::make_shared(parseContext , deck, gridPropertiesEQLNUMkeywordNotAdded), std::runtime_error); + auto gridPropertiesEQLNUMkeywordNotAdded = getEclipseProperties( *deck, parseContext); + BOOST_CHECK_THROW( + std::make_shared( parseContext, *deck, gridPropertiesEQLNUMkeywordNotAdded ), + std::runtime_error ); } { - auto gridPropertiesEQLNUMall0 = getGridProperties(0); - BOOST_CHECK_THROW(std::make_shared(parseContext , deck, gridPropertiesEQLNUMall0), std::runtime_error); + auto gridPropertiesEQLNUMall0 = getEclipseProperties(*deck_all0, parseContext); + BOOST_CHECK_THROW(std::make_shared(parseContext , *deck, gridPropertiesEQLNUMall0), std::runtime_error); } parseContext.update( ParseContext::UNSUPPORTED_INITIAL_THPRES , InputError::IGNORE ); - BOOST_CHECK_NO_THROW(ThresholdPressure(parseContext,deck_missingPressure, gridProperties)); + BOOST_CHECK_NO_THROW(ThresholdPressure(parseContext,*deck_missingPressure, ep_missingPressure)); { - ThresholdPressure thp(parseContext , deck_missingPressure , gridProperties ); + ThresholdPressure thp(parseContext , *deck_missingPressure , ep_missingPressure ); BOOST_CHECK_EQUAL( true , thp.hasRegionBarrier(2,3)); BOOST_CHECK_EQUAL( false , thp.hasThresholdPressure(2,3)); @@ -237,10 +293,10 @@ BOOST_AUTO_TEST_CASE(ThresholdPressureThrowTest) { BOOST_AUTO_TEST_CASE(HasPair) { - ParseContext parseContext; - DeckPtr deck = createDeck(parseContext , inputStr); - auto gridProperties = getGridProperties(); - ThresholdPressure thp(parseContext , deck , gridProperties); + ParseContext parseContext; + DeckPtr deck = createDeck(parseContext , inputStrWithEqlNum); + auto ep = getEclipseProperties(*deck, parseContext); + ThresholdPressure thp(parseContext , *deck , ep); BOOST_CHECK_EQUAL( true , thp.hasRegionBarrier( 1 , 2 )); BOOST_CHECK_EQUAL( false , thp.hasRegionBarrier( 1 , 7 )); diff --git a/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp b/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp index 4612c5edd..9c86e60ea 100644 --- a/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp +++ b/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp @@ -1,21 +1,21 @@ /* - Copyright 2013 Statoil ASA. +Copyright 2013 Statoil ASA. - This file is part of the Open Porous Media project (OPM). +This file is part of the Open Porous Media project (OPM). - OPM is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. +OPM is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. - OPM is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. +OPM is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with OPM. If not, see . - */ +You should have received a copy of the GNU General Public License +along with OPM. If not, see . +*/ #include #include @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -56,53 +57,51 @@ using namespace Opm; static DeckPtr createDeckTOP() { - const char *deckData = - "RUNSPEC\n" - "\n" - "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" - "PORO \n" - "100*0.10 /\n" - "PERMX \n" - "100*0.25 /\n" - "EDIT\n" - "OIL\n" - "\n" - "GAS\n" - "\n" - "TITLE\n" - "The title\n" - "\n" - "START\n" - "8 MAR 1998 /\n" - "\n" - "PROPS\n" - "REGIONS\n" - "SWAT\n" - "1000*1 /\n" - "SATNUM\n" - "1000*2 /\n" - "\n"; +const char *deckData = +"RUNSPEC\n" +"\n" +"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" +"PORO \n" +"100*0.10 /\n" +"PERMX \n" +"100*0.25 /\n" +"EDIT\n" +"OIL\n" +"\n" +"GAS\n" +"\n" +"TITLE\n" +"The title\n" +"\n" +"START\n" +"8 MAR 1998 /\n" +"\n" +"PROPS\n" +"REGIONS\n" +"SWAT\n" +"1000*1 /\n" +"SATNUM\n" +"1000*2 /\n" +"\n"; - ParserPtr parser(new Parser()); - return parser->parseString(deckData, ParseContext()) ; +ParserPtr parser(new Parser()); +return parser->parseString(deckData, ParseContext()) ; } - - BOOST_AUTO_TEST_CASE(GetPOROTOPBased) { DeckPtr deck = createDeckTOP(); EclipseState state(deck , ParseContext()); - auto& props = state.getEclipseProperties(); + const Eclipse3DProperties& props = state.getEclipseProperties(); const GridProperty& poro = props.getDoubleGridProperty( "PORO" ); const GridProperty& permx = props.getDoubleGridProperty( "PERMX" ); @@ -113,155 +112,153 @@ BOOST_AUTO_TEST_CASE(GetPOROTOPBased) { BOOST_CHECK_EQUAL( 0.10 , poro.iget(i) ); BOOST_CHECK_EQUAL( 0.25 * Metric::Permeability , permx.iget(i) ); } - } - static DeckPtr createDeck() { - const char *deckData = - "RUNSPEC\n" - "\n" - "DIMENS\n" - " 10 10 10 /\n" - "GRID\n" - "FAULTS \n" - " 'F1' 1 1 1 4 1 4 'X' / \n" - " 'F2' 5 5 1 4 1 4 'X-' / \n" - "/\n" - "MULTFLT \n" - " 'F1' 0.50 / \n" - " 'F2' 0.50 / \n" - "/\n" - "EDIT\n" - "MULTFLT /\n" - " 'F2' 0.25 / \n" - "/\n" - "OIL\n" - "\n" - "GAS\n" - "\n" - "TITLE\n" - "The title\n" - "\n" - "START\n" - "8 MAR 1998 /\n" - "\n" - "PROPS\n" - "REGIONS\n" - "SWAT\n" - "1000*1 /\n" - "SATNUM\n" - "1000*2 /\n" - "\n"; +const char *deckData = +"RUNSPEC\n" +"\n" +"DIMENS\n" +" 10 10 10 /\n" +"GRID\n" +"FAULTS \n" +" 'F1' 1 1 1 4 1 4 'X' / \n" +" 'F2' 5 5 1 4 1 4 'X-' / \n" +"/\n" +"MULTFLT \n" +" 'F1' 0.50 / \n" +" 'F2' 0.50 / \n" +"/\n" +"EDIT\n" +"MULTFLT /\n" +" 'F2' 0.25 / \n" +"/\n" +"OIL\n" +"\n" +"GAS\n" +"\n" +"TITLE\n" +"The title\n" +"\n" +"START\n" +"8 MAR 1998 /\n" +"\n" +"PROPS\n" +"REGIONS\n" +"SWAT\n" +"1000*1 /\n" +"SATNUM\n" +"1000*2 /\n" +"\n"; - ParserPtr parser(new Parser()); - return parser->parseString(deckData, ParseContext()) ; +ParserPtr parser(new Parser()); +return parser->parseString(deckData, ParseContext()) ; } static DeckPtr createDeckNoFaults() { - const char *deckData = - "RUNSPEC\n" - "\n" - "DIMENS\n" - " 10 10 10 /\n" - "GRID\n" - "PROPS\n" - "-- multiply one layer for each face\n" - "MULTX\n" - " 100*1 100*10 800*1 /\n" - "MULTX-\n" - " 200*1 100*11 700*1 /\n" - "MULTY\n" - " 300*1 100*12 600*1 /\n" - "MULTY-\n" - " 400*1 100*13 500*1 /\n" - "MULTZ\n" - " 500*1 100*14 400*1 /\n" - "MULTZ-\n" - " 600*1 100*15 300*1 /\n" - "\n"; +const char *deckData = +"RUNSPEC\n" +"\n" +"DIMENS\n" +" 10 10 10 /\n" +"GRID\n" +"PROPS\n" +"-- multiply one layer for each face\n" +"MULTX\n" +" 100*1 100*10 800*1 /\n" +"MULTX-\n" +" 200*1 100*11 700*1 /\n" +"MULTY\n" +" 300*1 100*12 600*1 /\n" +"MULTY-\n" +" 400*1 100*13 500*1 /\n" +"MULTZ\n" +" 500*1 100*14 400*1 /\n" +"MULTZ-\n" +" 600*1 100*15 300*1 /\n" +"\n"; - ParserPtr parser(new Parser()); - return parser->parseString(deckData, ParseContext()) ; +ParserPtr parser(new Parser()); +return parser->parseString(deckData, ParseContext()) ; } BOOST_AUTO_TEST_CASE(CreateSchedule) { - DeckPtr deck = createDeck(); - EclipseState state(deck , ParseContext()); - ScheduleConstPtr schedule = state.getSchedule(); - EclipseGridConstPtr eclipseGrid = state.getEclipseGrid(); +DeckPtr deck = createDeck(); +EclipseState state(deck , ParseContext()); +ScheduleConstPtr schedule = state.getSchedule(); +EclipseGridConstPtr eclipseGrid = state.getEclipseGrid(); - BOOST_CHECK_EQUAL( schedule->getStartTime() , boost::posix_time::ptime(boost::gregorian::date(1998 , 3 , 8 ))); +BOOST_CHECK_EQUAL( schedule->getStartTime() , boost::posix_time::ptime(boost::gregorian::date(1998 , 3 , 8 ))); } static DeckPtr createDeckSimConfig() { - const std::string& inputStr = "RUNSPEC\n" - "EQLOPTS\n" - "THPRES /\n " - "DIMENS\n" - "10 3 4 /\n" - "\n" - "GRID\n" - "REGIONS\n" - "EQLNUM\n" - "10*1 10*2 100*3 /\n " - "\n" +const std::string& inputStr = "RUNSPEC\n" + "EQLOPTS\n" + "THPRES /\n " + "DIMENS\n" + "10 3 4 /\n" + "\n" + "GRID\n" + "REGIONS\n" + "EQLNUM\n" + "10*1 10*2 100*3 /\n " + "\n" - "SOLUTION\n" - "THPRES\n" - "1 2 12.0/\n" - "1 3 5.0/\n" - "2 3 7.0/\n" - "/\n" - "\n"; + "SOLUTION\n" + "THPRES\n" + "1 2 12.0/\n" + "1 3 5.0/\n" + "2 3 7.0/\n" + "/\n" + "\n"; - ParserPtr parser(new Parser()); - return parser->parseString(inputStr, ParseContext()) ; +ParserPtr parser(new Parser()); +return parser->parseString(inputStr, ParseContext()) ; } BOOST_AUTO_TEST_CASE(CreateSimulationConfig) { - DeckPtr deck = createDeckSimConfig(); - EclipseState state(deck, ParseContext()); - SimulationConfigConstPtr simulationConfig = state.getSimulationConfig(); - BOOST_CHECK(simulationConfig->hasThresholdPressure()); - std::shared_ptr thresholdPressure = simulationConfig->getThresholdPressure(); - BOOST_CHECK_EQUAL(thresholdPressure->size(), 3); +DeckPtr deck = createDeckSimConfig(); +EclipseState state(deck, ParseContext()); +SimulationConfigConstPtr simConf = state.getSimulationConfig(); + +BOOST_CHECK( simConf->hasThresholdPressure() ); + +std::shared_ptr thresholdPressure = simConf->getThresholdPressure(); +BOOST_CHECK_EQUAL(thresholdPressure->size(), 3); } BOOST_AUTO_TEST_CASE(PhasesCorrect) { DeckPtr deck = createDeck(); - EclipseState state(deck, ParseContext()); - const auto& tm = *state.getTableManager(); - BOOST_CHECK( tm.hasPhase( Phase::PhaseEnum::OIL )); - BOOST_CHECK( tm.hasPhase( Phase::PhaseEnum::GAS )); - BOOST_CHECK( !tm.hasPhase( Phase::PhaseEnum::WATER )); + EclipseState state( deck, ParseContext() ); + const auto& tm = state.getTableManager(); + BOOST_CHECK( tm.hasPhase( Phase::PhaseEnum::OIL )); + BOOST_CHECK( tm.hasPhase( Phase::PhaseEnum::GAS )); + BOOST_CHECK( ! tm.hasPhase( Phase::PhaseEnum::WATER )); } - BOOST_AUTO_TEST_CASE(TitleCorrect) { DeckPtr deck = createDeck(); - EclipseState state(deck, ParseContext()); + EclipseState state( deck, ParseContext() ); - BOOST_CHECK_EQUAL( state.getTitle(), "The title"); + BOOST_CHECK_EQUAL( state.getTitle(), "The title" ); } - BOOST_AUTO_TEST_CASE(IntProperties) { DeckPtr deck = createDeck(); - EclipseState state(deck, ParseContext()); + EclipseState state( deck, ParseContext() ); - BOOST_CHECK( ! state.getEclipseProperties().supportsGridProperty("NONO")); - BOOST_CHECK( state.getEclipseProperties().supportsGridProperty("SATNUM")); - BOOST_CHECK( state.getEclipseProperties().hasDeckIntGridProperty("SATNUM")); + BOOST_CHECK_EQUAL( false, state.getEclipseProperties().supportsGridProperty( "NONO" ) ); + BOOST_CHECK_EQUAL( true, state.getEclipseProperties().supportsGridProperty( "SATNUM" ) ); + BOOST_CHECK_EQUAL( true, state.getEclipseProperties().hasDeckIntGridProperty( "SATNUM" ) ); } BOOST_AUTO_TEST_CASE(PropertiesNotSupportsFalse) { @@ -284,37 +281,33 @@ BOOST_AUTO_TEST_CASE(GetProperty) { BOOST_CHECK_THROW( satNUM.iget(100000) , std::invalid_argument); } - BOOST_AUTO_TEST_CASE(GetTransMult) { DeckPtr deck = createDeck(); - EclipseState state(deck, ParseContext()); + EclipseState state( deck, ParseContext() ); std::shared_ptr transMult = state.getTransMult(); - - BOOST_CHECK_EQUAL( 1.0 , transMult->getMultiplier(1,0,0,FaceDir::XPlus)); - BOOST_CHECK_THROW(transMult->getMultiplier(1000 , FaceDir::XPlus) , std::invalid_argument); + BOOST_CHECK_EQUAL( 1.0, transMult->getMultiplier( 1, 0, 0, FaceDir::XPlus ) ); + BOOST_CHECK_THROW( transMult->getMultiplier( 1000, FaceDir::XPlus ), std::invalid_argument ); } - - BOOST_AUTO_TEST_CASE(GetFaults) { DeckPtr deck = createDeck(); - EclipseState state(deck , ParseContext()); + EclipseState state( deck, ParseContext() ); std::shared_ptr faults = state.getFaults(); - BOOST_CHECK( faults->hasFault("F1") ); - BOOST_CHECK( faults->hasFault("F2") ); + BOOST_CHECK( faults->hasFault( "F1" ) ); + BOOST_CHECK( faults->hasFault( "F2" ) ); - std::shared_ptr F1 = faults->getFault("F1"); - std::shared_ptr F2 = faults->getFault("F2"); + std::shared_ptr F1 = faults->getFault( "F1" ); + std::shared_ptr F2 = faults->getFault( "F2" ); - BOOST_CHECK_EQUAL( 0.50 , F1->getTransMult()); - BOOST_CHECK_EQUAL( 0.25 , F2->getTransMult()); + BOOST_CHECK_EQUAL( 0.50, F1->getTransMult() ); + BOOST_CHECK_EQUAL( 0.25, F2->getTransMult() ); std::shared_ptr transMult = state.getTransMult(); - BOOST_CHECK_EQUAL( transMult->getMultiplier(0 , 0 , 0 , FaceDir::XPlus) , 0.50 ); - BOOST_CHECK_EQUAL( transMult->getMultiplier(4 , 3 , 0 , FaceDir::XMinus) , 0.25 ); - BOOST_CHECK_EQUAL( transMult->getMultiplier(4 , 3 , 0 , FaceDir::ZPlus) , 1.00 ); + BOOST_CHECK_EQUAL( transMult->getMultiplier( 0, 0, 0, FaceDir::XPlus ), 0.50 ); + BOOST_CHECK_EQUAL( transMult->getMultiplier( 4, 3, 0, FaceDir::XMinus ), 0.25 ); + BOOST_CHECK_EQUAL( transMult->getMultiplier( 4, 3, 0, FaceDir::ZPlus ), 1.00 ); }