units.h File Reference

#include "config.h"
#include "isinfnan.h"
#include "measurement.h"
#include <iostream>
#include <sstream>
#include <cmath>
#include <stdexcept>

Include dependency graph for units.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Units< M, L, T, K, I >
 Unit Checking/tracking Class. More...

Defines

#define UNITS_ALLOW_CAST_TO_DOUBLE
#define UNITS_ALLOW_GET_RAW_VALUE
#define CHECK_UNITS
#define MAX(a, b)   ( (a) < (b) ? (b) : (a) )
#define MIN(a, b)   ( (a) < (b) ? (a) : (b) )
#define ABS(x)   ( ((x) > 0) ? (x) : -(x) )
#define DEFINE_OUTPUT_METHOD(MM, LL, TT, KK, II, UNITS)
#define UNITS_CAST_ERROR(M, L, T, K, I, dim)

Typedefs

typedef Units< 1 > Mass
typedef Units< 0, 1 > Length
typedef Units< 0, 0, 1 > Time
typedef Units< 0, 0, 0, 1 > Temperature
typedef Units< 0, 0, 0, 0, 1 > Current
typedef Units< 0, 2 > Area
typedef Units< 0, 3 > Volume
typedef Units< 1,-3 > Density
typedef Units<-1, 3 > SpecificVolume
typedef Units< 1,-3,-1 > DensityPerTime
typedef Units< 0, 0,-1 > Frequency
typedef Units< 1, 1,-2 > Force
typedef Units< 1,-1,-2 > Pressure
typedef Units< 0, 1,-1 > Velocity
typedef Units< 0, 1,-2 > Acceleration
typedef Units< 1, 2,-2 > Torque
typedef Units< 1, 2,-2 > Energy
typedef Units< 1, 2,-3 > Power
typedef Units< 0, 2,-2 > SpecificEnergy
typedef Units< 1,-1,-1 > DynamicViscosity
typedef Units< 0, 2,-1 > KinematicViscosity
typedef Units< 1, 1,-3 > PowerPerLength
typedef Units< 1,-2,-2 > PressurePerLength
typedef Units< 1, 0,-2 > ForcePerLength
typedef Units< 0, 2,-3 > PowerPerMass
typedef Units< 1,-1,-3 > DensitySpecificEnergyPerTime
typedef Units< 0, 3,-1 > VolFlowRate
typedef Units< 1, 0,-1 > MassFlowRate
typedef Units< 1,-1,-1 > MassFlowRatePerLength
typedef Units< 1, 0,-2 > MassFlowRatePerTime
typedef Units< 1, 0,-3 > HeatFlux
typedef Units< 1,-2,-1 > MassFlux
typedef Units< 1, 2,-2,-1 > Entropy
typedef Units< 0, 2,-2,-1 > SpecificEntropy
typedef Units< 1, 1,-3,-1 > ThermalConductivity
typedef Units< 1, 0,-3,-1 > HeatTransferCoefficient
typedef Units<-1, 0, 3, 1 > ThermalResistance
typedef Units< 1, 1,-2,-1 > HeatCapacityPerLength
typedef Units< 1, 2,-3,-1 > PowerPerTemperature
typedef Units< 0, 0, 0,-1 > ThermalExpansionCoefficient
typedef Units< 0, 0, 1, 0, 1 > Charge
typedef Units< 1, 2,-3, 0,-1 > ElecPotential
typedef Units< 1, 2,-4, 0,-2 > Capacitance
typedef Units< 1, 2,-3, 0,-2 > Resistance
typedef Units<-1,-2, 3, 0, 2 > Conductance
typedef Velocity Speed
typedef Length Distance
typedef Energy Heat
typedef Heat Work
typedef Power HeatRate
typedef PowerPerLength HeatRatePerLength
typedef PowerPerTemperature HeatRatePerTemperature
typedef Pressure Stress
typedef HeatTransferCoefficient HTCoeff
typedef SpecificEntropy SpecificHeatCapacity
typedef SpecificHeatCapacity SpecHeatCap
typedef SpecificHeatCapacity SpecificGasConstant
typedef SpecificGasConstant SpecGasConst
typedef ForcePerLength SurfaceTension

Functions

template<int m, int l, int t, int k, int i>
Units< m, l, t, k, i > operator* (const double d, const Units< m, l, t, k, i > &u)
 Scalar multiplication.
template<int m, int l, int t, int k, int i>
Units<-m,-l,-t,-k,-i > operator/ (const double d, const Units< m, l, t, k, i > &u)
 Division.
template<int M, int L, int T, int K, int I, int m, int l, int t, int k, int i>
Units< M+m, L+l, T+t, K+k, I+i > operator* (const Units< M, L, T, K, I > &u1, const Units< m, l, t, k, i > &u2)
 Multiplication.
template<int M, int L, int T, int K, int I>
bool eq (const Units< M, L, T, K, I > &u, const Units< M, L, T, K, I > &v, const Units< M, L, T, K, I > &tol)
 Equality with some tolerance.
template<int M, int L, int T, int K, int I>
Units< M, L, T, K, I > fabs (const Units< M, L, T, K, I > u)
template<int M, int L, int T, int K, int I>
Units< 2 *M, 2 *L, 2 *T, 2 *K,
2 *I > 
sq (const Units< M, L, T, K, I > u)
 Square of a value.
template<int M, int L, int T, int K, int I>
Units< 3 *M, 3 *L, 3 *T, 3 *K,
3 *I > 
cube (const Units< M, L, T, K, I > u)
 Cube of a value.
template<int M, int L, int T, int K, int I>
bool isnan (const Units< M, L, T, K, I > &u)
template<int M, int L, int T, int K, int I>
bool isinf (const Units< M, L, T, K, I > &u)
template<int m, int l, int t, int k, int i>
std::ostream & operator<< (std::ostream &os, const Units< m, l, t, k, i > &u)
std::ostream & operator<< (std::ostream &os, const Units< 0, 0, 0, 0, 0 > &u)
 DEFINE_OUTPUT_METHOD (1, 0, 0, 0, 0,"kg")
 DEFINE_OUTPUT_METHOD (0, 1, 0, 0, 0,"m")
 DEFINE_OUTPUT_METHOD (0, 2, 0, 0, 0,"m")
 DEFINE_OUTPUT_METHOD (0, 3, 0, 0, 0,"m")
 DEFINE_OUTPUT_METHOD (1,-1, 0, 0, 0,"kg/m")
 DEFINE_OUTPUT_METHOD (1,-2, 0, 0, 0,"kg/m")
 DEFINE_OUTPUT_METHOD (1,-3, 0, 0, 0,"kg/m")
 DEFINE_OUTPUT_METHOD (-1, 3, 0, 0, 0,"m/kg")
 DEFINE_OUTPUT_METHOD (0, 0, 1, 0, 0,"s")
 DEFINE_OUTPUT_METHOD (0, 0,-1, 0, 0,"Hz")
 DEFINE_OUTPUT_METHOD (1, 0,-1, 0, 0,"kg/s")
 DEFINE_OUTPUT_METHOD (1, 0,-3, 0, 0,"W/m")
 DEFINE_OUTPUT_METHOD (0, 1,-1, 0, 0,"m/s")
 DEFINE_OUTPUT_METHOD (0, 2,-2, 0, 0,"J/kg")
 DEFINE_OUTPUT_METHOD (1,-1,-2, 0, 0,"Pa")
 DEFINE_OUTPUT_METHOD (1,-1,-1, 0, 0,"Pas")
 DEFINE_OUTPUT_METHOD (1, 1,-3, 0, 0,"W/m")
 DEFINE_OUTPUT_METHOD (1, 2,-3, 0, 0,"W")
 DEFINE_OUTPUT_METHOD (1,-2,-1, 0, 0,"kg/s/m")
 DEFINE_OUTPUT_METHOD (0, 0, 0, 1, 0,"K")
 DEFINE_OUTPUT_METHOD (0, 2,-2,-1, 0,"J/kgK")
 DEFINE_OUTPUT_METHOD (1, 1,-3,-1, 0,"W/m/K")
double tocelsius (const Temperature &T)
Temperature fromcelsius (const double &T_C)
double tofahrenheit (const Temperature &T)
Temperature fromfahrenheit (const double &T_F)
 Convert Temperature object to Fahrenheit.

Variables

const Mass kilogram
const Length metre
const Time second
const Temperature Kelvin
const Current ampere
const double Tera = 1e12
const double Giga = 1e9
const double Mega = 1e6
const double kilo = 1e3
const double hecta = 1e2
const double Deca = 10
const double deci = 0.1
const double centi = 1e-2
const double milli = 1e-3
const double micro = 1e-6
const Mass gram = milli * kilogram
const Mass kg = kilogram
const Length centimetre = metre / 100.0
const Length kilometre = 1000.0 * metre
const Area metre2 = metre * metre
const Area hectare = (100.0 * metre) * (100.0 * metre)
const Volume metre3 = metre2 * metre
const Volume litre = milli * metre3
const Volume centimetre3
const Time minute = 60.0 * second
const Time hour = 60.0 * minute
const Time day = 24.0 * hour
const Frequency Hertz = 1.0 / second
const Force Newton = kilogram * metre / (second * second)
const Pressure Pascal = Newton / (metre * metre)
const Pressure bar = 100.0 * kilo * Pascal
const Pressure MPa = Mega * Pascal
const Pressure kPa = kilo * Pascal
const Energy Joule = Newton * metre
const Energy kJ = kilo * Joule
const Energy Btu = 1055.05585262 * Joule
const Power Watt = Joule / second
const HeatFlux W_m2 = Watt / metre2
const double Percent = 1.0 / 100
const SpecificEnergy kJ_kg = kilo * Joule / kilogram
const SpecificEnergy J_kg = Joule / kilogram
const SpecificEntropy kJ_kgK = kilo * Joule / kilogram / Kelvin
const SpecificEntropy J_kgK = Joule / kilogram / Kelvin
const HeatTransferCoefficient W_m2K = Watt / metre2 / Kelvin
const ThermalConductivity W_mK = Watt / metre / Kelvin
const ThermalConductivity mW_mK = milli * W_mK
const Density kg_m3 = kilogram / metre3
const SpecificVolume m3_kg = metre3 / kilogram
const MassFlowRate kg_s = kilogram / second
const VolFlowRate m3_s = metre3 / second
const HeatCapacityPerLength J_mK = Joule / metre / Kelvin
const ElecPotential volt = Watt / ampere
const Charge Coulomb = ampere * second
const Capacitance Farad = volt / Coulomb
const Resistance Ohm = volt / ampere
const Temperature Rankin = 0.556 * Kelvin
const Frequency RPM = 1. / minute
const Length yard = 0.9144 * metre
const Length foot = yard / 3.
const Length inch = foot / 12.
const Length mile = 1760. * yard
const Mass lbm = 0.45359237 * kilogram
const Acceleration grav_accel = 9.80665 * metre / second / second
const Force lbf = grav_accel * lbm
const Pressure lbf_in2 = lbf / inch / inch
const Temperature ZeroCelsius = 273.15 * Kelvin
const Temperature ZeroFahrenheit = ZeroCelsius - 32.0 * Rankin
const Units< 1, 0,-3,-4 > SIGMA_C = (5.670e-8) * W_m2 /sq(sq(Kelvin))
 Stefan-Boltzmann Constant (radiation).


Define Documentation

#define ABS (  )     ( ((x) > 0) ? (x) : -(x) )

#define CHECK_UNITS

#define DEFINE_OUTPUT_METHOD ( MM,
LL,
TT,
KK,
II,
UNITS   ) 

Value:

inline \
                std::ostream& operator <<(std::ostream &os,const Units<MM,LL,TT,KK,II> &u){ \
                        double d = *reinterpret_cast<const double*>(&u); \
                        os << d; \
                        os.flags() & std::ios_base::showbase && os << " " << UNITS; \
                        return os; \
                }

#define MAX ( a,
 )     ( (a) < (b) ? (b) : (a) )

#define MIN ( a,
 )     ( (a) < (b) ? (a) : (b) )

#define UNITS_ALLOW_CAST_TO_DOUBLE

#define UNITS_ALLOW_GET_RAW_VALUE

#define UNITS_CAST_ERROR ( M,
L,
T,
K,
I,
dim   ) 

Value:

"Invalid cast from Measurement <" << dim.m << "," << dim.l << "," << dim.t << "," \
        << dim.k << "," << dim.i << "> to Units <" << M << "," << L << "," << T << "," \
        << K << "," << I << ">"

Referenced by Units< M, L, T, K, I >::Units().


Typedef Documentation

typedef Units< 0, 1, -2 > Acceleration

typedef Units< 0, 2 > Area

typedef Units< 1, 2, -4, 0, -2 > Capacitance

typedef Units< 0, 0, 1, 0, 1 > Charge

typedef Units<-1, -2, 3, 0, 2 > Conductance

typedef Units< 0, 0, 0, 0, 1 > Current

typedef Units< 1, -3 > Density

typedef Units< 1, -3, -1> DensityPerTime

typedef Units< 1, -1, -3 > DensitySpecificEnergyPerTime

typedef Length Distance

typedef Units< 1, -1, -1 > DynamicViscosity

typedef Units< 1, 2, -3, 0, -1 > ElecPotential

typedef Units< 1, 2, -2 > Energy

typedef Units< 1, 2, -2, -1 > Entropy

typedef Units< 1, 1, -2 > Force

typedef Units< 1, 0, -2 > ForcePerLength

typedef Units< 0, 0, -1> Frequency

typedef Energy Heat

typedef Units< 1, 1, -2, -1 > HeatCapacityPerLength

typedef Units< 1, 0, -3 > HeatFlux

typedef Power HeatRate

typedef Units< 1, 0, -3, -1 > HeatTransferCoefficient

typedef Units< 0, 2, -1 > KinematicViscosity

typedef Units< 0, 1 > Length

typedef Units< 1 > Mass

typedef Units< 1, 0, -1 > MassFlowRate

typedef Units< 1, -1, -1 > MassFlowRatePerLength

typedef Units< 1, 0, -2 > MassFlowRatePerTime

typedef Units< 1, -2, -1 > MassFlux

typedef Units< 1, 2, -3 > Power

typedef Units< 1, 1, -3 > PowerPerLength

typedef Units< 0, 2, -3 > PowerPerMass

typedef Units< 1, 2, -3, -1 > PowerPerTemperature

typedef Units< 1, -1, -2 > Pressure

typedef Units< 1, -2, -2 > PressurePerLength

typedef Units< 1, 2, -3, 0, -2 > Resistance

typedef Units< 0, 2, -2 > SpecificEnergy

typedef Units< 0, 2, -2, -1 > SpecificEntropy

typedef Units<-1, 3 > SpecificVolume

typedef Velocity Speed

typedef Pressure Stress

typedef Units< 0, 0, 0, 1 > Temperature

typedef Units< 1, 1, -3, -1 > ThermalConductivity

typedef Units< 0, 0, 0, -1 > ThermalExpansionCoefficient

typedef Units<-1, 0, 3, 1 > ThermalResistance

typedef Units< 0, 0, 1 > Time

typedef Units< 1, 2, -2 > Torque

typedef Units< 0, 1, -1 > Velocity

typedef Units< 0, 3, -1 > VolFlowRate

typedef Units< 0, 3 > Volume

typedef Heat Work


Function Documentation

template<int M, int L, int T, int K, int I>
Units<3*M, 3*L, 3*T, 3*K, 3*I> cube ( const Units< M, L, T, K, I >  u  )  [inline]

Cube of a value.

DEFINE_OUTPUT_METHOD ( ,
,
3,
1,
,
"W/m/K"   
)

DEFINE_OUTPUT_METHOD ( ,
,
2,
1,
,
"J/kgK"   
)

DEFINE_OUTPUT_METHOD ( ,
,
,
,
,
"K"   
)

DEFINE_OUTPUT_METHOD ( ,
2,
1,
,
,
"kg/s/m"   
)

DEFINE_OUTPUT_METHOD ( ,
,
3,
,
,
"W"   
)

DEFINE_OUTPUT_METHOD ( ,
,
3,
,
,
"W/m"   
)

DEFINE_OUTPUT_METHOD ( ,
1,
1,
,
,
"Pas"   
)

DEFINE_OUTPUT_METHOD ( ,
1,
2,
,
,
"Pa"   
)

DEFINE_OUTPUT_METHOD ( ,
,
2,
,
,
"J/kg  
)

DEFINE_OUTPUT_METHOD ( ,
,
1,
,
,
"m/s"   
)

DEFINE_OUTPUT_METHOD ( ,
,
3,
,
,
"W/m"   
)

DEFINE_OUTPUT_METHOD ( ,
,
1,
,
,
"kg/s"   
)

DEFINE_OUTPUT_METHOD ( ,
,
1,
,
,
"Hz"   
)

DEFINE_OUTPUT_METHOD ( ,
,
,
,
,
"s"   
)

DEFINE_OUTPUT_METHOD ( 1,
,
,
,
,
"m/kg  
)

DEFINE_OUTPUT_METHOD ( ,
3,
,
,
,
"kg/m"   
)

DEFINE_OUTPUT_METHOD ( ,
2,
,
,
,
"kg/m"   
)

DEFINE_OUTPUT_METHOD ( ,
1,
,
,
,
"kg/m"   
)

DEFINE_OUTPUT_METHOD ( ,
,
,
,
,
"m"   
)

DEFINE_OUTPUT_METHOD ( ,
,
,
,
,
"m"   
)

DEFINE_OUTPUT_METHOD ( ,
,
,
,
,
"m"   
)

DEFINE_OUTPUT_METHOD ( ,
,
,
,
,
"kg"   
)

template<int M, int L, int T, int K, int I>
bool eq ( const Units< M, L, T, K, I > &  u,
const Units< M, L, T, K, I > &  v,
const Units< M, L, T, K, I > &  tol 
) [inline]

Equality with some tolerance.

References fabs().

template<int M, int L, int T, int K, int I>
Units<M,L,T,K,I> fabs ( const Units< M, L, T, K, I >  u  )  [inline]

Temperature fromcelsius ( const double &  T_C  )  [inline]

Convert a Celsius temperature to Kelvin

Parameters:
T_C double value for the temperature in degrees
Returns:
Temperature object (Kelvin)
Examples:
/home/john/freesteam/steamcalculator.h.

Temperature fromfahrenheit ( const double &  T_F  )  [inline]

Convert Temperature object to Fahrenheit.

Returns:
temperature in Fahrenheit (as type 'double')

template<int M, int L, int T, int K, int I>
bool isinf ( const Units< M, L, T, K, I > &  u  )  [inline]

template<int M, int L, int T, int K, int I>
bool isnan ( const Units< M, L, T, K, I > &  u  )  [inline]

template<int M, int L, int T, int K, int I, int m, int l, int t, int k, int i>
Units<M+m,L+l,T+t,K+k,I+i > operator* ( const Units< M, L, T, K, I > &  u1,
const Units< m, l, t, k, i > &  u2 
) [inline]

Multiplication.

template<int m, int l, int t, int k, int i>
Units<m,l,t,k,i> operator* ( const double  d,
const Units< m, l, t, k, i > &  u 
) [inline]

Scalar multiplication.

template<int m, int l, int t, int k, int i>
Units<-m,-l,-t,-k,-i> operator/ ( const double  d,
const Units< m, l, t, k, i > &  u 
) [inline]

Division.

References IAPWS95::t.

std::ostream& operator<< ( std::ostream &  os,
const Units< 0, 0, 0, 0, 0 > &  u 
) [inline]

References IAPWS95::d.

template<int m, int l, int t, int k, int i>
std::ostream& operator<< ( std::ostream &  os,
const Units< m, l, t, k, i > &  u 
) [inline]

References IAPWS95::d.

template<int M, int L, int T, int K, int I>
Units<2*M, 2*L, 2*T, 2*K, 2*I> sq ( const Units< M, L, T, K, I >  u  )  [inline]

Square of a value.

double tocelsius ( const Temperature T  )  [inline]

Convert a temperature (in Kelvin) to Celsius.

Returns:
the temperature, as a plain 'double' type

References IAPWS95::d.

double tofahrenheit ( const Temperature T  )  [inline]

Convert from Fahrenheit temperature to Temperature object (Kelvin)


Variable Documentation

const Current ampere

const Pressure bar = 100.0 * kilo * Pascal

const Energy Btu = 1055.05585262 * Joule

const double centi = 1e-2

const Length centimetre = metre / 100.0

Initial value:

    (centi * metre) * (centi * metre) * (centi * metre)

const Time day = 24.0 * hour

const double Deca = 10

const double deci = 0.1

const Length foot = yard / 3.

const double Giga = 1e9

const Mass gram = milli * kilogram

const Acceleration grav_accel = 9.80665 * metre / second / second

const double hecta = 1e2

const Area hectare = (100.0 * metre) * (100.0 * metre)

const Frequency Hertz = 1.0 / second

const Time hour = 60.0 * minute

const Length inch = foot / 12.

const Energy Joule = Newton * metre

const Mass kg = kilogram

const double kilo = 1e3

const Mass kilogram

const Length kilometre = 1000.0 * metre

const Energy kJ = kilo * Joule

const Pressure kPa = kilo * Pascal

const Force lbf = grav_accel * lbm

const Pressure lbf_in2 = lbf / inch / inch

const Mass lbm = 0.45359237 * kilogram

const Volume litre = milli * metre3

const double Mega = 1e6

const Length metre

Referenced by surfaceTension().

const Area metre2 = metre * metre

const double micro = 1e-6

const Length mile = 1760. * yard

const double milli = 1e-3

Referenced by surfaceTension().

const Time minute = 60.0 * second

const Pressure MPa = Mega * Pascal

Referenced by surfaceTension().

const Pressure Pascal = Newton / (metre * metre)

const double Percent = 1.0 / 100

const Temperature Rankin = 0.556 * Kelvin

const Frequency RPM = 1. / minute

const Time second

const Units<1,0,-3,-4> SIGMA_C = (5.670e-8) * W_m2 /sq(sq(Kelvin))

Stefan-Boltzmann Constant (radiation).

const double Tera = 1e12

const HeatFlux W_m2 = Watt / metre2

const Power Watt = Joule / second

const Length yard = 0.9144 * metre

const Temperature ZeroCelsius = 273.15 * Kelvin


Generated on Tue Feb 10 18:37:37 2009 for freesteam by  doxygen 1.5.6