diff --git a/opm/parser/eclipse/EclipseState/EclipseState.cpp b/opm/parser/eclipse/EclipseState/EclipseState.cpp index c0d53ecd7..9e1a6d291 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.cpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.cpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include @@ -106,28 +108,57 @@ namespace Opm { } - void EclipseState::loadGridPropertyFromDeckKeyword(DeckKeywordConstPtr deckKeyword) { + void EclipseState::loadGridPropertyFromDeckKeyword(std::shared_ptr inputBox , DeckKeywordConstPtr deckKeyword) { const std::string& keyword = deckKeyword->name(); auto gridProperty = m_intGridProperties->getKeyword( keyword ); - gridProperty->loadFromDeckKeyword( deckKeyword ); + gridProperty->loadFromDeckKeyword( inputBox , deckKeyword ); } - void EclipseState::initProperties(DeckConstPtr deck) { - size_t volume = m_eclipseGrid->getCartesianSize(); - std::vector > supportedKeywords = {{ "SATNUM" , 0 }}; - m_intGridProperties = std::make_shared >(m_eclipseGrid->getNX() , m_eclipseGrid->getNY() , m_eclipseGrid->getNZ() , supportedIntKeywords); - if (Section::hasREGIONS(deck)) { - std::shared_ptr regionsSection(new Opm::REGIONSSection(deck) ); - - for (auto iter = regionsSection->begin(); iter != regionsSection->end(); ++iter) { - DeckKeywordConstPtr deckKeyword = *iter; - - if (supportsGridProperty( deckKeyword->name())) - loadGridPropertyFromDeckKeyword( deckKeyword ); - - } - } + void EclipseState::initProperties(DeckConstPtr deck) { + BoxManager boxManager(m_eclipseGrid->getNX( ) , m_eclipseGrid->getNY() , m_eclipseGrid->getNZ()); + std::vector > supportedIntKeywords = {{ "SATNUM" , 0 }}; // Should come in config .... + m_intGridProperties = std::make_shared >(m_eclipseGrid->getNX() , m_eclipseGrid->getNY() , m_eclipseGrid->getNZ() , supportedIntKeywords); + + + + if (Section::hasREGIONS(deck)) { + std::shared_ptr regionsSection(new Opm::REGIONSSection(deck) ); + + for (auto iter = regionsSection->begin(); iter != regionsSection->end(); ++iter) { + DeckKeywordConstPtr deckKeyword = *iter; + + if (supportsGridProperty( deckKeyword->name()) ) + loadGridPropertyFromDeckKeyword( boxManager.getActiveBox() , deckKeyword ); + + if (deckKeyword->name() == "BOX") + handleBOXKeyword(deckKeyword , boxManager); + + if (deckKeyword->name() == "ENDBOX") + handleENDBOXKeyword(deckKeyword , boxManager); + + std::cout << "Looking at kw: " << deckKeyword->name() << std::endl; + } + } } + + + void EclipseState::handleBOXKeyword(DeckKeywordConstPtr deckKeyword , BoxManager& boxManager) { + DeckRecordConstPtr record = deckKeyword->getRecord(0); + int I1 = record->getItem("I1")->getInt(0) - 1; + int I2 = record->getItem("I2")->getInt(0) - 1; + int J1 = record->getItem("J1")->getInt(0) - 1; + int J2 = record->getItem("J2")->getInt(0) - 1; + int K1 = record->getItem("K1")->getInt(0) - 1; + int K2 = record->getItem("K2")->getInt(0) - 1; + + boxManager.setInputBox( I1 , I2 , J1 , J2 , K1 , K2 ); + } + + + void EclipseState::handleENDBOXKeyword(DeckKeywordConstPtr deckKeyword , BoxManager& boxManager) { + boxManager.endInputBox(); + } + } diff --git a/opm/parser/eclipse/EclipseState/EclipseState.hpp b/opm/parser/eclipse/EclipseState/EclipseState.hpp index 593f39726..c31d8a0f5 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.hpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.hpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include @@ -41,7 +43,7 @@ namespace Opm { bool supportsGridProperty(const std::string& keyword) const; std::shared_ptr > getIntProperty( const std::string& keyword ); bool hasIntGridProperty(const std::string& keyword) const; - void loadGridPropertyFromDeckKeyword(DeckKeywordConstPtr deckKeyword); + void loadGridPropertyFromDeckKeyword(std::shared_ptr inputBox , DeckKeywordConstPtr deckKeyword); private: void initSchedule(DeckConstPtr deck); @@ -49,7 +51,10 @@ namespace Opm { void initPhases(DeckConstPtr deck); void initTitle(DeckConstPtr deck); void initProperties(DeckConstPtr deck); - + + void handleBOXKeyword(DeckKeywordConstPtr deckKeyword , BoxManager& boxManager); + void handleENDBOXKeyword(DeckKeywordConstPtr deckKeyword , BoxManager& boxManager); + EclipseGridConstPtr m_eclipseGrid; ScheduleConstPtr schedule; diff --git a/opm/parser/eclipse/EclipseState/Grid/Box.cpp b/opm/parser/eclipse/EclipseState/Grid/Box.cpp index 8442a04df..3957d3961 100644 --- a/opm/parser/eclipse/EclipseState/Grid/Box.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/Box.cpp @@ -42,8 +42,9 @@ namespace Opm { m_stride[0] = 1; m_stride[1] = m_dims[0]; m_stride[2] = m_dims[0] * m_dims[1]; - + m_isGlobal = true; + initIndexList(); } @@ -68,6 +69,8 @@ namespace Opm { m_isGlobal = true; else m_isGlobal = false; + + initIndexList(); } @@ -98,33 +101,27 @@ namespace Opm { } - const std::vector& Box::getIndexList() { - assertIndexList(); + const std::vector& Box::getIndexList() const { return m_indexList; } - void Box::assertIndexList() { - if (m_indexList.size() > 0) - return; - - { - m_indexList.resize( size() ); - - size_t ii,ij,ik; - size_t l = 0; - - for (ik=0; ik < m_dims[2]; ik++) { - size_t k = ik + m_offset[2]; - for (ij=0; ij < m_dims[1]; ij++) { - size_t j = ij + m_offset[1]; - for (ii=0; ii < m_dims[0]; ii++) { - size_t i = ii + m_offset[0]; - size_t g = i * m_stride[0] + j*m_stride[1] + k*m_stride[2]; - - m_indexList[l] = g; - l++; - } + void Box::initIndexList() { + m_indexList.resize( size() ); + + size_t ii,ij,ik; + size_t l = 0; + + for (ik=0; ik < m_dims[2]; ik++) { + size_t k = ik + m_offset[2]; + for (ij=0; ij < m_dims[1]; ij++) { + size_t j = ij + m_offset[1]; + for (ii=0; ii < m_dims[0]; ii++) { + size_t i = ii + m_offset[0]; + size_t g = i * m_stride[0] + j*m_stride[1] + k*m_stride[2]; + + m_indexList[l] = g; + l++; } } } diff --git a/opm/parser/eclipse/EclipseState/Grid/Box.hpp b/opm/parser/eclipse/EclipseState/Grid/Box.hpp index 1bb2be7c0..629aad6bd 100644 --- a/opm/parser/eclipse/EclipseState/Grid/Box.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/Box.hpp @@ -33,12 +33,12 @@ namespace Opm { size_t size() const; bool isGlobal() const; size_t getDim(size_t idim) const; - const std::vector& getIndexList(); + const std::vector& getIndexList() const; bool equal(const Box& other) const; private: - void assertIndexList(); + void initIndexList(); static void assertDims(const Box& globalBox, size_t idim , int l1 , int l2); size_t m_dims[3]; size_t m_offset[3]; diff --git a/opm/parser/eclipse/EclipseState/Grid/GridProperty.cpp b/opm/parser/eclipse/EclipseState/Grid/GridProperty.cpp index 046a29145..314c29fdd 100644 --- a/opm/parser/eclipse/EclipseState/Grid/GridProperty.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/GridProperty.cpp @@ -17,7 +17,8 @@ along with OPM. If not, see . */ -#include "GridProperty.hpp" +#include +#include namespace Opm { @@ -30,4 +31,13 @@ void GridProperty::loadFromDeckKeyword(Opm::DeckKeywordConstPtr deckKeyword throw std::invalid_argument("Can only load from DATA keywords"); } +template<> +void GridProperty::loadFromDeckKeyword(std::shared_ptr inputBox , Opm::DeckKeywordConstPtr deckKeyword) { + if (deckKeyword->isDataKeyword()) { + const std::vector& data = deckKeyword->getIntData(); + setFromVector(inputBox , data); + } else + throw std::invalid_argument("Can only load from DATA keywords"); +} + } diff --git a/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp b/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp index 3924d108d..40504a077 100644 --- a/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp @@ -23,7 +23,9 @@ #include #include #include + #include +#include /* This class implemenents a class representing properties which are diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/BoxTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/BoxTests.cpp index 74c8f546c..d1572cb0f 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/BoxTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/BoxTests.cpp @@ -112,3 +112,5 @@ BOOST_AUTO_TEST_CASE(BoxEqual) { BOOST_CHECK( !globalBox4.equal( subBox4 )); BOOST_CHECK( !subBox4.equal( subBox5 )); } + + diff --git a/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp b/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp index fbad4bfa8..fd212c2d9 100644 --- a/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp +++ b/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp @@ -120,7 +120,8 @@ BOOST_AUTO_TEST_CASE(PropertiesNotSupportedThrows) { DeckPtr deck = createDeck(); EclipseState state(deck); DeckKeywordConstPtr fluxNUM = deck->getKeyword("FLUXNUM"); - BOOST_CHECK_THROW( state.loadGridPropertyFromDeckKeyword( fluxNUM ) , std::invalid_argument) + BOOST_CHECK_EQUAL( false , state.supportsGridProperty("FLUXNUM")); + BOOST_CHECK_THROW( state.loadGridPropertyFromDeckKeyword( std::make_shared(10,10,10) , fluxNUM ) , std::invalid_argument) } diff --git a/opm/parser/eclipse/IntegrationTests/BoxTest.cpp b/opm/parser/eclipse/IntegrationTests/BoxTest.cpp new file mode 100644 index 000000000..430f30289 --- /dev/null +++ b/opm/parser/eclipse/IntegrationTests/BoxTest.cpp @@ -0,0 +1,56 @@ +/* + Copyright 2013 Statoil ASA. + + 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 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 . + */ + +#define BOOST_TEST_MODULE BoxTest +#include +#include + +#include +#include +#include + + +using namespace Opm; + + +BOOST_AUTO_TEST_CASE( PARSE_BOX_OK ) { + ParserPtr parser(new Parser( )); + boost::filesystem::path boxFile("testdata/integration_tests/BOX/BOXTEST1"); + DeckPtr deck = parser->parseFile(boxFile.string() , false); + EclipseState state(deck); + + std::shared_ptr > satnum = state.getIntProperty("SATNUM"); + { + size_t i,j,k; + std::shared_ptr grid = state.getEclipseGrid(); + for (k = 0; k < grid->getNZ(); k++) { + for (j = 0; j < grid->getNY(); j++) { + for (i = 0; i < grid->getNX(); i++) { + + size_t g = i + j*grid->getNX() + k * grid->getNX() * grid->getNY(); + if (i <= 1 && j <= 1 && k <= 1) + BOOST_CHECK_EQUAL(satnum->iget(g) , 10); + else + BOOST_CHECK_EQUAL(satnum->iget(g) , 2); + + } + } + } + } +} diff --git a/opm/parser/eclipse/IntegrationTests/CMakeLists.txt b/opm/parser/eclipse/IntegrationTests/CMakeLists.txt index 2b7e0739d..6f2f2cdef 100644 --- a/opm/parser/eclipse/IntegrationTests/CMakeLists.txt +++ b/opm/parser/eclipse/IntegrationTests/CMakeLists.txt @@ -91,6 +91,13 @@ add_test(NAME runParseSWOF WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND ${TEST_MEMCHECK_TOOL} ${EXECUTABLE_OUTPUT_PATH}/runParseSWOF) +add_executable(runBoxTest BoxTest.cpp) +target_link_libraries(runBoxTest Parser ${Boost_LIBRARIES}) +add_test(NAME runBoxTest + WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} + COMMAND ${TEST_MEMCHECK_TOOL} ${EXECUTABLE_OUTPUT_PATH}/runBoxTest) + + add_executable(runParseSGOF ParseSGOF.cpp) target_link_libraries(runParseSGOF Parser ${Boost_LIBRARIES}) add_test(NAME runParseSGOF diff --git a/testdata/integration_tests/BOX/BOXTEST1 b/testdata/integration_tests/BOX/BOXTEST1 new file mode 100644 index 000000000..d8361fda8 --- /dev/null +++ b/testdata/integration_tests/BOX/BOXTEST1 @@ -0,0 +1,48 @@ +RUNSPEC + +DIMENS + 10 10 10 / + +GRID + +DX +1000*0.25 / + +DYV +10*0.25 / + +DZ +1000*0.25 / + +TOPS +1000*0.25 / + +EDIT + +OIL +GAS + +TITLE +The title + +START +8 MAR 1998 / + +REGIONS + +FLUXNUM + 1000*1 / + +SATNUM + 1000*2 / + +BOX + 1 2 1 2 1 2 / + +SATNUM + 8*10 / + +ENDBOX + +SCHEDULE +