Changed unit system to use more std::shared_ptr instead of instance variables.
This commit is contained in:
@@ -47,10 +47,11 @@ namespace Opm {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
Dimension Dimension::makeComposite(const std::string& dim , double SIfactor) {
|
||||
Dimension dimension;
|
||||
dimension.m_name = dim;
|
||||
dimension.m_SIfactor = SIfactor;
|
||||
|
||||
Dimension * Dimension::newComposite(const std::string& dim , double SIfactor) {
|
||||
Dimension * dimension = new Dimension();
|
||||
dimension->m_name = dim;
|
||||
dimension->m_SIfactor = SIfactor;
|
||||
|
||||
return dimension;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Opm {
|
||||
Dimension(const std::string& name, double SI_factor);
|
||||
double getSIScaling() const;
|
||||
const std::string& getName() const;
|
||||
static Dimension makeComposite(const std::string& dim , double SIfactor);
|
||||
static Dimension * newComposite(const std::string& dim , double SIfactor);
|
||||
|
||||
private:
|
||||
Dimension();
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace Opm {
|
||||
}
|
||||
|
||||
|
||||
Dimension UnitSystem::parseFactor(const std::string& dimension) const {
|
||||
std::shared_ptr<Dimension> UnitSystem::parseFactor(const std::string& dimension) const {
|
||||
std::vector<std::string> dimensionList;
|
||||
boost::split(dimensionList , dimension , boost::is_any_of("*"));
|
||||
double SIfactor = 1.0;
|
||||
@@ -69,12 +69,12 @@ namespace Opm {
|
||||
Dimension dim = getDimension( *iter );
|
||||
SIfactor *= dim.getSIScaling();
|
||||
}
|
||||
return Dimension::makeComposite( dimension , SIfactor );
|
||||
return std::shared_ptr<Dimension>(Dimension::newComposite( dimension , SIfactor ));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Dimension UnitSystem::parse(const std::string& dimension) const {
|
||||
std::shared_ptr<Dimension> UnitSystem::parse(const std::string& dimension) const {
|
||||
bool haveDivisor;
|
||||
{
|
||||
size_t divCount = std::count( dimension.begin() , dimension.end() , '/' );
|
||||
@@ -89,10 +89,10 @@ namespace Opm {
|
||||
if (haveDivisor) {
|
||||
std::vector<std::string> parts;
|
||||
boost::split(parts , dimension , boost::is_any_of("/"));
|
||||
Dimension dividend = parseFactor( parts[0] );
|
||||
Dimension divisor = parseFactor( parts[1] );
|
||||
std::shared_ptr<const Dimension> dividend = parseFactor( parts[0] );
|
||||
std::shared_ptr<const Dimension> divisor = parseFactor( parts[1] );
|
||||
|
||||
return Dimension::makeComposite( dimension , dividend.getSIScaling() / divisor.getSIScaling() );
|
||||
return std::shared_ptr<Dimension>( Dimension::newComposite( dimension , dividend->getSIScaling() / divisor->getSIScaling() ));
|
||||
} else {
|
||||
return parseFactor( dimension );
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include <opm/parser/eclipse/Units/Dimension.hpp>
|
||||
|
||||
@@ -36,13 +37,13 @@ namespace Opm {
|
||||
const Dimension& getDimension(const std::string& dimension) const;
|
||||
bool hasDimension(const std::string& dimension) const;
|
||||
|
||||
Dimension parse(const std::string& dimension) const;
|
||||
std::shared_ptr<Dimension> parse(const std::string& dimension) const;
|
||||
|
||||
static UnitSystem * newMETRIC();
|
||||
static UnitSystem * newFIELD();
|
||||
private:
|
||||
Dimension parseFactor(const std::string& dimension) const;
|
||||
|
||||
std::shared_ptr<Dimension> parseFactor(const std::string& dimension) const;
|
||||
|
||||
const std::string m_name;
|
||||
std::map<std::string , Dimension> m_dimensions;
|
||||
};
|
||||
|
||||
@@ -18,14 +18,15 @@
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_MODULE UnitTests
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Units/UnitSystemMap.hpp>
|
||||
#include <opm/parser/eclipse/Units/UnitSystem.hpp>
|
||||
#include <opm/parser/eclipse/Units/Dimension.hpp>
|
||||
#include <opm/parser/eclipse/Units/ConversionFactors.hpp>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
@@ -36,9 +37,9 @@ BOOST_AUTO_TEST_CASE(CreateDimension) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(makeComposite) {
|
||||
Dimension composite = Dimension::makeComposite("L*L*L/t" , 100);
|
||||
BOOST_CHECK_EQUAL("L*L*L/t" , composite.getName());
|
||||
BOOST_CHECK_EQUAL(100 , composite.getSIScaling());
|
||||
std::shared_ptr<Dimension> composite(Dimension::newComposite("L*L*L/t" , 100));
|
||||
BOOST_CHECK_EQUAL("L*L*L/t" , composite->getName());
|
||||
BOOST_CHECK_EQUAL(100 , composite->getSIScaling());
|
||||
}
|
||||
|
||||
|
||||
@@ -96,9 +97,9 @@ BOOST_AUTO_TEST_CASE(UnitSystemParseInvalidThrows) {
|
||||
system.addDimension("L" , 3.00 );
|
||||
system.addDimension("t" , 9.0 );
|
||||
|
||||
Dimension volumePerTime = system.parse("L*L*L/t");
|
||||
BOOST_CHECK_EQUAL("L*L*L/t" , volumePerTime.getName() );
|
||||
BOOST_CHECK_EQUAL(3.0 , volumePerTime.getSIScaling());
|
||||
std::shared_ptr<Dimension> volumePerTime = system.parse("L*L*L/t");
|
||||
BOOST_CHECK_EQUAL("L*L*L/t" , volumePerTime->getName() );
|
||||
BOOST_CHECK_EQUAL(3.0 , volumePerTime->getSIScaling());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user