Merge pull request #931 from joakim-hove/unit-system-vector-overlaod
Added vector overload of unit onversion methods.
This commit is contained in:
@@ -447,6 +447,21 @@ namespace {
|
||||
return this->measure_table_to_si[ static_cast< int >( m ) ] * val;
|
||||
}
|
||||
|
||||
void UnitSystem::from_si( measure m, std::vector<double>& 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<double>& 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 ) ];
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
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<double>& ) const;
|
||||
void to_si( measure, std::vector<double>& ) const;
|
||||
const char* name( measure ) const;
|
||||
|
||||
static UnitSystem * newMETRIC();
|
||||
|
||||
@@ -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<double> d0 = {1,2,3};
|
||||
std::vector<double> 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user