4 #include <boost/rational.hpp> 5 #include <boost/array.hpp> 6 #include <boost/operators.hpp> 26 boost::equality_comparable<Unit>,
27 boost::multipliable<Unit>,
28 boost::multipliable<Unit, double>,
29 boost::dividable<Unit>,
30 boost::dividable<Unit, double> {
33 Unit(
const std::string& Name,
double Conversion_to_si,
34 const boost::rational<int>& Length_power,
35 const boost::rational<int>& Mass_power,
36 const boost::rational<int>& Time_power,
37 const boost::rational<int>& Current_power,
38 const boost::rational<int>& Temperature_power,
39 const boost::rational<int>& Amount_power,
40 const boost::rational<int>& Luminous_intensity_power,
41 const boost::rational<int>& Solid_angle_power,
42 const boost::rational<int>& Angle_power,
43 const boost::rational<int>& Photon_count_power,
44 const boost::rational<int>& Sample_index);
45 Unit(
const std::string& Name,
const Unit& Dunit);
46 Unit(
const std::string& Name_to_parse);
54 {
return base_unit_powers_;}
77 const std::string&
name()
const {
return name_;}
83 void name(
const std::string& V) {name_ = V;}
93 void print(std::ostream& Os)
const;
96 double conversion_to_si_;
100 Unit pow(
const Unit& Dunit,
const boost::rational<int>& Exponent);
104 return Scale_factor *
pow(Unit, -1);
114 const Unit m(
"m", 1.0, 1,0,0,0,0,0,0,0,0,0,0);
115 const Unit kg(
"kg", 1.0, 0,1,0,0,0,0,0,0,0,0,0);
116 const Unit s(
"s", 1.0, 0,0,1,0,0,0,0,0,0,0,0);
117 const Unit K(
"K", 1.0, 0,0,0,1,0,0,0,0,0,0,0);
118 const Unit A(
"A", 1.0, 0,0,0,0,1,0,0,0,0,0,0);
119 const Unit mol(
"mol", 1.0, 0,0,0,0,0,1,0,0,0,0,0);
120 const Unit cd(
"cd", 1.0, 0,0,0,0,0,0,1,0,0,0,0);
121 const Unit sr(
"sr", 1.0, 0,0,0,0,0,0,0,1,0,0,0);
122 const Unit rad(
"rad", 1.0, 0,0,0,0,0,0,0,0,1,0,0);
123 const Unit ph(
"ph", 1.0, 0,0,0,0,0,0,0,0,0,1,0);
125 1.0, 0,0,0,0,0,0,0,0,0,0,1);
127 1.0, 0,0,0,0,0,0,0,0,0,0,0);
133 const double pi = 3.14159265358979323846;
135 const Unit deg(
"deg", pi / 180.0 * rad);
139 const Unit day(
"day", 24 * 60 * 60 * s);
140 const Unit year(
"year", 365.25 * 24 * 60 * 60 * s);
141 const Unit cm(
"cm", 1e-2 * m);
142 const Unit km(
"km", 1e3 * m);
143 const Unit nm(
"nm", 1e-9 * m);
145 const Unit g(
"g", 1e-3 * kg);
149 const Unit N(
"N", kg * m / (s*s));
150 const Unit Pa(
"Pa",
N / (m * m));
const boost::array< boost::rational< int >, number_base_unit > & base_unit_powers() const
Array of the powers of the base units (so m^2 would return (1,0,0,0,0,0,0,0))
const Unit arcsec("arcsec", deg/(60.0 *60))
Unit & operator/=(double Scale_factor)
const Unit s("s", 1.0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0)
static Unit parse(const std::string &S)
Parse a string, and return a Unit that matches the given units.
void name(const std::string &V)
Set name of unit.
Unit operator/(double Scale_factor, const Unit &Unit)
const Unit cm("cm", 1e-2 *m)
const Unit mW("mW", 1e-3 *W)
bool operator==(const Unit &U) const
Test for equality.
const Unit dimensionless("dimensionless", 1.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
const Unit nm("nm", 1e-9 *m)
Unit()
Default constructor. This creates a dimensionless unit.
const Unit kW("kW", 1e3 *W)
const Unit Pa("Pa", N/(m *m))
double conversion(const Unit &Dunit_from, const Unit &Dunit_to)
Return conversion factor to go from one unit to another.
const Unit sr("sr", 1.0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0)
This is a Mixin for classes that can be printed.
const Unit micron("micron", 1e-6 *m)
const Unit sample_index("sample_index", 1.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
const Unit A("A", 1.0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0)
void print(std::ostream &Os) const
Print to a stream.
const Unit inv_cm("cm^-1", pow(cm, -1))
const Unit K("K", 1.0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0)
const Unit kg("kg", 1.0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0)
const Unit m("m", 1.0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
Unit pow(const Unit &Dunit, const boost::rational< int > &Exponent)
const Unit inv_sr("sr^-1", pow(sr, -1))
double conversion_to_si() const
Conversion factor to go to SI units.
const Unit day("day", 24 *60 *60 *s)
const Unit year("year", 365.25 *24 *60 *60 *s)
const Unit cd("cd", 1.0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0)
const Unit g("g", 1e-3 *kg)
Libraries such as boost::units allow unit handling where we know the units at compile time...
bool is_commensurate(const Unit &Units) const
Test if this set of units is commensurate with another set.
const Unit N("N", kg *m/(s *s))
Contains classes to abstract away details in various Spurr Radiative Transfer software.
const Unit mol("mol", 1.0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0)
const Unit uW("uW", 1e-6 *W)
const Unit ph("ph", 1.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0)
const std::string & name() const
Name of unit. May be an empty string if a name wasn't assigned.
const Unit km("km", 1e3 *m)
Unit & operator*=(const Unit &Dunit)
Basic math operators for units.
const Unit rad("rad", 1.0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0)
const Unit deg("deg", pi/180.0 *rad)