From eb9e11849e5d8a93016d3b5c1a11c7277598a71f Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Fri, 30 May 2014 14:13:57 +0200 Subject: [PATCH] Added support for MULTIPLY keyword. --- .../eclipse/EclipseState/EclipseState.cpp | 29 +++++++++++++++++-- .../eclipse/EclipseState/EclipseState.hpp | 6 ++-- .../EclipseState/Grid/GridProperty.hpp | 21 +++++++++++++- .../Grid/tests/GridPropertyTests.cpp | 21 ++++++++++++++ .../eclipse/IntegrationTests/BoxTest.cpp | 21 ++++++++++++-- testdata/integration_tests/BOX/BOXTEST1 | 16 ++++++++++ 6 files changed, 106 insertions(+), 8 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/EclipseState.cpp b/opm/parser/eclipse/EclipseState/EclipseState.cpp index d019bd671..39562dd76 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.cpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.cpp @@ -134,14 +134,18 @@ namespace Opm { if (deckKeyword->name() == "BOX") handleBOXKeyword(deckKeyword , boxManager); + + if (deckKeyword->name() == "COPY") + handleCOPYKeyword(deckKeyword , boxManager); if (deckKeyword->name() == "ENDBOX") handleENDBOXKeyword(deckKeyword , boxManager); - if (deckKeyword->name() == "COPY") - handleCOPYKeyword(deckKeyword , boxManager); + if (deckKeyword->name() == "MULTIPLY") + handleMULTIPLYKeyword(deckKeyword , boxManager); std::cout << "Looking at kw: " << deckKeyword->name() << std::endl; + boxManager.endKeyword(); } } } @@ -165,6 +169,26 @@ namespace Opm { } + void EclipseState::handleMULTIPLYKeyword(DeckKeywordConstPtr deckKeyword , BoxManager& boxManager) { + for (auto iter = deckKeyword->begin(); iter != deckKeyword->end(); ++iter) { + DeckRecordConstPtr record = *iter; + const std::string& field = record->getItem("field")->getString(0); + double scaleFactor = record->getItem("factor")->getRawDouble(0); + + setKeywordBox( record , boxManager ); + + if (m_intGridProperties->hasKeyword( field )) { + int intFactor = static_cast(scaleFactor); + std::shared_ptr > property = m_intGridProperties->getKeyword( field ); + + property->scale( intFactor , boxManager.getActiveBox() ); + } else + throw std::invalid_argument("Fatal error processing MULTIPLY keyword. Tried to multiply not defined keyword" + field); + + } + } + + void EclipseState::handleCOPYKeyword(DeckKeywordConstPtr deckKeyword , BoxManager& boxManager) { for (auto iter = deckKeyword->begin(); iter != deckKeyword->end(); ++iter) { DeckRecordConstPtr record = *iter; @@ -173,7 +197,6 @@ namespace Opm { setKeywordBox( record , boxManager ); - if (m_intGridProperties->hasKeyword( srcField )) copyIntKeyword( srcField , targetField , boxManager.getActiveBox()); else diff --git a/opm/parser/eclipse/EclipseState/EclipseState.hpp b/opm/parser/eclipse/EclipseState/EclipseState.hpp index 5980f8f01..46f6903e7 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.hpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.hpp @@ -52,10 +52,12 @@ namespace Opm { void initTitle(DeckConstPtr deck); void initProperties(DeckConstPtr deck); - void setKeywordBox(DeckRecordConstPtr deckRecord , BoxManager& boxManager); void handleBOXKeyword(DeckKeywordConstPtr deckKeyword , BoxManager& boxManager); - void handleENDBOXKeyword(DeckKeywordConstPtr deckKeyword , BoxManager& boxManager); void handleCOPYKeyword(DeckKeywordConstPtr deckKeyword , BoxManager& boxManager); + void handleENDBOXKeyword(DeckKeywordConstPtr deckKeyword , BoxManager& boxManager); + void handleMULTIPLYKeyword(DeckKeywordConstPtr deckKeyword , BoxManager& boxManager); + + void setKeywordBox(DeckRecordConstPtr deckRecord , BoxManager& boxManager); void copyIntKeyword(const std::string& srcField , const std::string& targetField , std::shared_ptr inputBox); EclipseGridConstPtr m_eclipseGrid; diff --git a/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp b/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp index 4c940453a..cb0500cb3 100644 --- a/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -85,7 +86,9 @@ public: void copyFrom(const GridProperty& src, std::shared_ptr inputBox) { if (inputBox->isGlobal()) { - std::copy( src.m_data.begin() , src.m_data.end() , m_data.begin()); + for (size_t i = 0; i < m_data.size(); i++) + m_data[i] = src.m_data[i]; + //std::copy( src.m_data.begin() , src.m_data.end() , m_data.begin() ); } else { const std::vector& indexList = inputBox->getIndexList(); for (size_t i = 0; i < indexList.size(); i++) { @@ -95,6 +98,22 @@ public: } } + void scale(T scaleFactor , std::shared_ptr inputBox) { + if (inputBox->isGlobal()) { + std::transform(m_data.begin(), m_data.end(), m_data.begin(), + std::bind1st(std::multiplies() , scaleFactor)); + + } else { + const std::vector& indexList = inputBox->getIndexList(); + for (size_t i = 0; i < indexList.size(); i++) { + size_t targetIndex = indexList[i]; + m_data[targetIndex] *= scaleFactor; + } + } + } + + + private: diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp index c1b528270..e531f5259 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp @@ -139,3 +139,24 @@ BOOST_AUTO_TEST_CASE(copy) { } } } + + +BOOST_AUTO_TEST_CASE(SCALE) { + Opm::GridProperty prop1( 4 , 4 , 2 , "P1" , 1); + Opm::GridProperty prop2( 4 , 4 , 2 , "P2" , 9); + + std::shared_ptr global = std::make_shared(4,4,2); + std::shared_ptr layer0 = std::make_shared(*global , 0,3,0,3,0,0); + + prop2.copyFrom(prop1 , layer0); + prop2.scale( 2 , global ); + prop2.scale( 2 , layer0 ); + + for (size_t j=0; j < 4; j++) { + for (size_t i=0; i < 4; i++) { + + BOOST_CHECK_EQUAL( prop2.iget(i,j,0) , 4 ); + BOOST_CHECK_EQUAL( prop2.iget(i,j,1) , 18 ); + } + } +} diff --git a/opm/parser/eclipse/IntegrationTests/BoxTest.cpp b/opm/parser/eclipse/IntegrationTests/BoxTest.cpp index a63631ce8..8e8401a02 100644 --- a/opm/parser/eclipse/IntegrationTests/BoxTest.cpp +++ b/opm/parser/eclipse/IntegrationTests/BoxTest.cpp @@ -63,9 +63,26 @@ BOOST_AUTO_TEST_CASE( PARSE_BOX_OK ) { -BOOST_AUTO_TEST_CASE( PARSE_COPY ) { +BOOST_AUTO_TEST_CASE( PARSE_MULTIPLY_COPY ) { EclipseState state = makeState("testdata/integration_tests/BOX/BOXTEST1"); - BOOST_CHECK(state.hasIntGridProperty( "FIPNUM" )); + std::shared_ptr > satnum = state.getIntProperty("SATNUM"); + std::shared_ptr > fipnum = state.getIntProperty("FIPNUM"); + 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(4*satnum->iget(g) , fipnum->iget(g)); + else + BOOST_CHECK_EQUAL(2*satnum->iget(i,j,k) , fipnum->iget(i,j,k)); + + } + } + } } diff --git a/testdata/integration_tests/BOX/BOXTEST1 b/testdata/integration_tests/BOX/BOXTEST1 index 1f4212c37..94c0388ab 100644 --- a/testdata/integration_tests/BOX/BOXTEST1 +++ b/testdata/integration_tests/BOX/BOXTEST1 @@ -36,6 +36,10 @@ FLUXNUM SATNUM 1000*2 / +COPY + SATNUM FIPNUM / +/ + BOX 1 2 1 2 1 2 / @@ -46,6 +50,18 @@ COPY SATNUM FIPNUM / / +ENDBOX + +MULTIPLY + FIPNUM 2 / +/ + +BOX + 1 2 1 2 1 2 / + +MULTIPLY + FIPNUM 2 / +/ ENDBOX