Move to_si/from_si into UnitSystem
UnitSystem already offered similar functionality, but via string-map lookup and a very clunky interface. Offer simple to/from methods as an addition.
This commit is contained in:
@@ -32,18 +32,108 @@
|
||||
|
||||
namespace Opm {
|
||||
|
||||
namespace {
|
||||
/*
|
||||
* It is VERY important that the measure enum has the same order as the
|
||||
* metric and field arrays. C++ does not support designated initializers, so
|
||||
* this cannot be done in a declaration-order independent matter.
|
||||
*/
|
||||
|
||||
static const double to_metric[] = {
|
||||
1 / Metric::Length,
|
||||
1 / Metric::Time,
|
||||
1 / Metric::Density,
|
||||
1 / Metric::Pressure,
|
||||
1 / Metric::AbsoluteTemperature,
|
||||
1 / Metric::Temperature,
|
||||
1 / Metric::Viscosity,
|
||||
1 / Metric::Permeability,
|
||||
1 / Metric::LiquidSurfaceVolume,
|
||||
1 / Metric::GasSurfaceVolume,
|
||||
1 / Metric::ReservoirVolume,
|
||||
1 / ( Metric::LiquidSurfaceVolume / Metric::Time ),
|
||||
1 / ( Metric::GasSurfaceVolume / Metric::Time ),
|
||||
1 / ( Metric::ReservoirVolume / Metric::Time ),
|
||||
1 / Metric::Transmissibility,
|
||||
1 / Metric::Mass,
|
||||
};
|
||||
|
||||
static const double from_metric[] = {
|
||||
Metric::Length,
|
||||
Metric::Time,
|
||||
Metric::Density,
|
||||
Metric::Pressure,
|
||||
Metric::AbsoluteTemperature,
|
||||
Metric::Temperature,
|
||||
Metric::Viscosity,
|
||||
Metric::Permeability,
|
||||
Metric::LiquidSurfaceVolume,
|
||||
Metric::GasSurfaceVolume,
|
||||
Metric::ReservoirVolume,
|
||||
Metric::LiquidSurfaceVolume / Metric::Time,
|
||||
Metric::GasSurfaceVolume / Metric::Time,
|
||||
Metric::ReservoirVolume / Metric::Time,
|
||||
Metric::Transmissibility,
|
||||
Metric::Mass,
|
||||
};
|
||||
|
||||
static const double to_field[] = {
|
||||
1 / Field::Length,
|
||||
1 / Field::Time,
|
||||
1 / Field::Density,
|
||||
1 / Field::Pressure,
|
||||
1 / Field::AbsoluteTemperature,
|
||||
1 / Field::Temperature,
|
||||
1 / Field::Viscosity,
|
||||
1 / Field::Permeability,
|
||||
1 / Field::LiquidSurfaceVolume,
|
||||
1 / Field::GasSurfaceVolume,
|
||||
1 / Field::ReservoirVolume,
|
||||
1 / ( Field::LiquidSurfaceVolume / Field::Time ),
|
||||
1 / ( Field::GasSurfaceVolume / Field::Time ),
|
||||
1 / ( Field::ReservoirVolume / Field::Time ),
|
||||
1 / Field::Transmissibility,
|
||||
1 / Field::Mass,
|
||||
};
|
||||
|
||||
static const double from_field[] = {
|
||||
Field::Length,
|
||||
Field::Time,
|
||||
Field::Density,
|
||||
Field::Pressure,
|
||||
Field::AbsoluteTemperature,
|
||||
Field::Temperature,
|
||||
Field::Viscosity,
|
||||
Field::Permeability,
|
||||
Field::LiquidSurfaceVolume,
|
||||
Field::GasSurfaceVolume,
|
||||
Field::ReservoirVolume,
|
||||
Field::LiquidSurfaceVolume / Field::Time,
|
||||
Field::GasSurfaceVolume / Field::Time,
|
||||
Field::ReservoirVolume / Field::Time,
|
||||
Field::Transmissibility,
|
||||
Field::Mass,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
UnitSystem::UnitSystem(const UnitType unit) :
|
||||
m_unittype( unit )
|
||||
{
|
||||
switch(unit) {
|
||||
case(UNIT_TYPE_METRIC):
|
||||
m_name = "Metric";
|
||||
this->measure_table_from_si = to_metric;
|
||||
this->measure_table_to_si = from_metric;
|
||||
break;
|
||||
case(UNIT_TYPE_FIELD):
|
||||
m_name = "Field";
|
||||
this->measure_table_from_si = to_field;
|
||||
this->measure_table_to_si = from_field;
|
||||
break;
|
||||
case(UNIT_TYPE_LAB):
|
||||
m_name = "Lab";
|
||||
throw std::runtime_error( "Lab unit system is not supported" );
|
||||
break;
|
||||
default:
|
||||
//do nothing
|
||||
@@ -51,7 +141,6 @@ namespace Opm {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
bool UnitSystem::hasDimension(const std::string& dimension) const {
|
||||
return (m_dimensions.find( dimension ) != m_dimensions.end());
|
||||
}
|
||||
@@ -162,6 +251,13 @@ namespace Opm {
|
||||
return equal_;
|
||||
}
|
||||
|
||||
double UnitSystem::from_si( measure m, double val ) const {
|
||||
return this->measure_table_from_si[ static_cast< int >( m ) ] * val;
|
||||
}
|
||||
|
||||
double UnitSystem::to_si( measure m, double val ) const {
|
||||
return this->measure_table_to_si[ static_cast< int >( m ) ] * val;
|
||||
}
|
||||
|
||||
UnitSystem * UnitSystem::newMETRIC() {
|
||||
UnitSystem * system = new UnitSystem(UNIT_TYPE_METRIC);
|
||||
@@ -218,6 +314,3 @@ namespace Opm {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user