diff --git a/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp b/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp index b3e75346c..913f95f22 100644 --- a/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp @@ -144,6 +144,16 @@ public: iset(g,value); } + + void multiplyWith(const GridProperty& other) { + if ((m_nx == other.m_nx) && (m_ny == other.m_ny) && (m_nz == other.m_nz)) { + for (size_t g=0; g < m_data.size(); g++) + m_data[g] *= other.m_data[g]; + } else + throw std::invalid_argument("Size mismatch between properties in mulitplyWith."); + } + + void multiplyValueAtIndex(size_t index, T factor) { m_data[index] *= factor; } diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp index 39f2d1a9a..7a83dec07 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp @@ -353,3 +353,21 @@ BOOST_AUTO_TEST_CASE(GridPropertyInitializers) { BOOST_CHECK_EQUAL(sguPropData[2 * 3*3], 0.80); } + + + +BOOST_AUTO_TEST_CASE(multiply) { + typedef Opm::GridProperty::SupportedKeywordInfo SupportedKeywordInfo; + SupportedKeywordInfo keywordInfo("P" , 10 , "1"); + Opm::GridProperty p1( 5 , 5 , 4 , keywordInfo); + Opm::GridProperty p2( 5 , 5 , 5 , keywordInfo); + Opm::GridProperty p3( 5 , 5 , 4 , keywordInfo); + + BOOST_CHECK_THROW( p1.multiplyWith(p2) , std::invalid_argument ); + p1.multiplyWith(p3); + + for (size_t g = 0; g < p1.getCartesianSize(); g++) + BOOST_CHECK_EQUAL( 100 , p1.iget(g)); + +} +