ReFRACtor
FullPhysics::Unit Class Reference

Libraries such as boost::units allow unit handling where we know the units at compile time. More...

#include <unit.h>

+ Inheritance diagram for FullPhysics::Unit:
+ Collaboration diagram for FullPhysics::Unit:

Public Types

enum  { number_base_unit = 11 }
 

Public Member Functions

 Unit (const std::string &Name, double Conversion_to_si, const boost::rational< int > &Length_power, const boost::rational< int > &Mass_power, const boost::rational< int > &Time_power, const boost::rational< int > &Current_power, const boost::rational< int > &Temperature_power, const boost::rational< int > &Amount_power, const boost::rational< int > &Luminous_intensity_power, const boost::rational< int > &Solid_angle_power, const boost::rational< int > &Angle_power, const boost::rational< int > &Photon_count_power, const boost::rational< int > &Sample_index)
 Create a unit. More...
 
 Unit (const std::string &Name, const Unit &Dunit)
 Create a unit. More...
 
 Unit (const std::string &Name_to_parse)
 Variation of constructor that uses parse on the given string to determine the units. More...
 
 Unit ()
 Default constructor. This creates a dimensionless unit. More...
 
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)) More...
 
double conversion_to_si () const
 Conversion factor to go to SI units. More...
 
bool is_commensurate (const Unit &Units) const
 Test if this set of units is commensurate with another set. More...
 
const std::string & name () const
 Name of unit. May be an empty string if a name wasn't assigned. More...
 
void name (const std::string &V)
 Set name of unit. More...
 
Unitoperator*= (const Unit &Dunit)
 Basic math operators for units. More...
 
Unitoperator*= (double Scale_factor)
 Scale a unit. More...
 
Unitoperator/= (double Scale_factor)
 
Unitoperator/= (const Unit &Dunit)
 Divide two units. More...
 
bool operator== (const Unit &U) const
 Test for equality. More...
 
void print (std::ostream &Os) const
 Print to a stream. More...
 
std::string print_to_string () const
 Print to string. More...
 

Static Public Member Functions

static Unit parse (const std::string &S)
 Parse a string, and return a Unit that matches the given units. More...
 

Detailed Description

Libraries such as boost::units allow unit handling where we know the units at compile time.

This class provide the same sort of handling, but for instances where we know the units at runtime rather than compile time (e.g., based on input read).

We do dimensional analysis based on the SI base units. In order, these are meter, kilogram, second, Kelvin, Ampere, mole, candela, steradian, radian, photon, sample_index

Note that steradian, radian and sample_index are actually dimensionless, but it is useful to track them. Also photon is a photon count, which doesn't really have units either. But it is useful to track because we can determine the photon count at a particular wavelength to convert to cm^-1.

Definition at line 25 of file unit.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
number_base_unit 

Definition at line 32 of file unit.h.

Constructor & Destructor Documentation

◆ Unit() [1/4]

Unit::Unit ( const std::string &  Name,
double  Conversion_to_si,
const boost::rational< int > &  Length_power,
const boost::rational< int > &  Mass_power,
const boost::rational< int > &  Time_power,
const boost::rational< int > &  Current_power,
const boost::rational< int > &  Temperature_power,
const boost::rational< int > &  Amount_power,
const boost::rational< int > &  Luminous_intensity_power,
const boost::rational< int > &  Solid_angle_power,
const boost::rational< int > &  Angle_power,
const boost::rational< int > &  Photon_count_power,
const boost::rational< int > &  Sample_index 
)

Create a unit.

This takes string giving the name (e.g., "m", "m^2"), a factor to convert to SI units, and the power of each of the base units.

Definition at line 22 of file unit.cc.

◆ Unit() [2/4]

Unit::Unit ( const std::string &  Name,
const Unit Dunit 
)

Create a unit.

This variation takes name and applies it to a passed in unit. This allows you to do things like: Unit meter_sq("m ^ 2", meter * meter);

Definition at line 56 of file unit.cc.

◆ Unit() [3/4]

Unit::Unit ( const std::string &  Name_to_parse)

Variation of constructor that uses parse on the given string to determine the units.

Definition at line 78 of file unit.cc.

◆ Unit() [4/4]

Unit::Unit ( )

Default constructor. This creates a dimensionless unit.

Definition at line 66 of file unit.cc.

Member Function Documentation

◆ base_unit_powers()

const boost::array<boost::rational<int>, number_base_unit>& FullPhysics::Unit::base_unit_powers ( ) const
inline

Array of the powers of the base units (so m^2 would return (1,0,0,0,0,0,0,0))

Definition at line 53 of file unit.h.

◆ conversion_to_si()

double FullPhysics::Unit::conversion_to_si ( ) const
inline

Conversion factor to go to SI units.

Definition at line 60 of file unit.h.

◆ is_commensurate()

bool FullPhysics::Unit::is_commensurate ( const Unit Units) const
inline

Test if this set of units is commensurate with another set.

If this return true then conversion() would succeed, otherwise it would fail.

Definition at line 68 of file unit.h.

◆ name() [1/2]

const std::string& FullPhysics::Unit::name ( ) const
inline

Name of unit. May be an empty string if a name wasn't assigned.

Definition at line 77 of file unit.h.

◆ name() [2/2]

void FullPhysics::Unit::name ( const std::string &  V)
inline

Set name of unit.

Definition at line 83 of file unit.h.

◆ operator*=() [1/2]

Unit & Unit::operator*= ( const Unit Dunit)

Basic math operators for units.

Multiple two units together.

Definition at line 87 of file unit.cc.

◆ operator*=() [2/2]

Unit & Unit::operator*= ( double  Scale_factor)

Scale a unit.

Definition at line 99 of file unit.cc.

◆ operator/=() [1/2]

Unit & Unit::operator/= ( double  Scale_factor)

Definition at line 106 of file unit.cc.

◆ operator/=() [2/2]

Unit & Unit::operator/= ( const Unit Dunit)

Divide two units.

Definition at line 117 of file unit.cc.

◆ operator==()

bool Unit::operator== ( const Unit U) const

Test for equality.

This does not verify that the name is the same, instead we verify that the underlying units described are the same (i.e., they are commensurate and have same conversion_to_si factor)

Definition at line 133 of file unit.cc.

◆ parse()

Unit Unit::parse ( const std::string &  S)
static

Parse a string, and return a Unit that matches the given units.

Definition at line 350 of file unit.cc.

◆ print()

void Unit::print ( std::ostream &  Os) const

Print to a stream.

Definition at line 143 of file unit.cc.

◆ print_to_string()

std::string FullPhysics::Printable< Unit >::print_to_string ( ) const
inlineinherited

Print to string.

This is primarily useful for SWIG wrappers to this class, e.g. a to_s method in ruby.

Definition at line 31 of file printable.h.


The documentation for this class was generated from the following files:

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:14