diff --git a/opm/parser/eclipse/Units/UnitSystem.cpp b/opm/parser/eclipse/Units/UnitSystem.cpp index da3d61d26..8fd429a62 100644 --- a/opm/parser/eclipse/Units/UnitSystem.cpp +++ b/opm/parser/eclipse/Units/UnitSystem.cpp @@ -447,6 +447,21 @@ namespace { return this->measure_table_to_si[ static_cast< int >( m ) ] * val; } + void UnitSystem::from_si( measure m, std::vector& data ) const { + double factor = this->measure_table_from_si[ static_cast< int >( m ) ]; + auto scale = [=](double x) { return x * factor; }; + std::transform( data.begin() , data.end() , data.begin() , scale); + } + + + void UnitSystem::to_si( measure m, std::vector& data) const { + double factor = this->measure_table_to_si[ static_cast< int >( m ) ]; + auto scale = [=](double x) { return x * factor; }; + std::transform( data.begin() , data.end() , data.begin() , scale); + } + + + const char* UnitSystem::name( measure m ) const { return this->unit_name_table[ static_cast< int >( m ) ]; } diff --git a/opm/parser/eclipse/Units/UnitSystem.hpp b/opm/parser/eclipse/Units/UnitSystem.hpp index 1521a1953..d22e6f3be 100644 --- a/opm/parser/eclipse/Units/UnitSystem.hpp +++ b/opm/parser/eclipse/Units/UnitSystem.hpp @@ -22,6 +22,7 @@ #include #include +#include #include namespace Opm { @@ -81,6 +82,8 @@ namespace Opm { double from_si( measure, double ) const; double to_si( measure, double ) const; + void from_si( measure, std::vector& ) const; + void to_si( measure, std::vector& ) const; const char* name( measure ) const; static UnitSystem * newMETRIC(); diff --git a/opm/parser/eclipse/Units/tests/UnitTests.cpp b/opm/parser/eclipse/Units/tests/UnitTests.cpp index d3184f3ec..4cf311dd2 100644 --- a/opm/parser/eclipse/Units/tests/UnitTests.cpp +++ b/opm/parser/eclipse/Units/tests/UnitTests.cpp @@ -213,3 +213,16 @@ BOOST_AUTO_TEST_CASE(LabUnitConversions) { BOOST_CHECK_CLOSE( 1.0 , lab->from_si( q.m , q.f ) , 1.0e-10 ); } } + + +BOOST_AUTO_TEST_CASE( VectorConvert ) { + std::vector d0 = {1,2,3}; + std::vector d1 = {1,2,3}; + UnitSystem * units = UnitSystem::newLAB(); + + units->from_si( UnitSystem::measure::pressure , d0 ); + for (size_t i = 0; i < d1.size(); i++) + BOOST_CHECK_EQUAL( units->from_si( UnitSystem::measure::pressure , d1[i] ) , d0[i]); + + delete units; +}