From bd1c756e30d65a9d8bf73a8dc4a6b3dfc8f4e790 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Fri, 30 May 2014 13:19:43 +0200 Subject: [PATCH] Added copyFrom() property to GridProperty --- .../EclipseState/Grid/GridProperty.hpp | 15 +++++++++++++++ .../Grid/tests/GridPropertyTests.cpp | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp b/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp index 40504a077..4c940453a 100644 --- a/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp @@ -81,6 +81,21 @@ public: void loadFromDeckKeyword(std::shared_ptr inputBox , DeckKeywordConstPtr deckKeyword); void loadFromDeckKeyword(DeckKeywordConstPtr deckKeyword); + + + 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()); + } else { + const std::vector& indexList = inputBox->getIndexList(); + for (size_t i = 0; i < indexList.size(); i++) { + size_t targetIndex = indexList[i]; + m_data[targetIndex] = src.m_data[targetIndex]; + } + } + } + + private: void setFromVector(const std::vector& data) { diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp index 33f744e71..c1b528270 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp @@ -120,3 +120,22 @@ BOOST_AUTO_TEST_CASE(SetFromDeckKeyword) { } } } + + +BOOST_AUTO_TEST_CASE(copy) { + Opm::GridProperty prop1( 4 , 4 , 2 , "P1" , 0); + Opm::GridProperty prop2( 4 , 4 , 2 , "P2" , 9); + + Opm::Box global(4,4,2); + std::shared_ptr layer0 = std::make_shared(global , 0,3,0,3,0,0); + + prop2.copyFrom(prop1 , 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) , 0 ); + BOOST_CHECK_EQUAL( prop2.iget(i,j,1) , 9 ); + } + } +}