Flow123d  release_3.0.0-1211-g84d0b74
Classes | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
UnitSI Class Reference

Class for representation SI units of Fields. More...

#include <unit_si.hh>

Collaboration diagram for UnitSI:
Collaboration graph
[legend]

Classes

struct  OutputFormat
 Variable parts of output format. Used in the format method. More...
 

Public Member Functions

 UnitSI ()
 Constructor. More...
 
UnitSIm (int exp=1)
 Methods set values of exponents for SI units with similar name. More...
 
UnitSIkg (int exp=1)
 
UnitSIs (int exp=1)
 
UnitSIA (int exp=1)
 
UnitSIK (int exp=1)
 
UnitSImol (int exp=1)
 
UnitSIcd (int exp=1)
 
UnitSImd (int exp=-1)
 The dimension dependent meter: md^y = m^(yd), where 'd' is dimension. More...
 
std::string format_latex () const
 
std::string format_text () const
 
std::string json () const
 
void undef (bool val=true)
 
bool is_def () const
 Return true if the unit is defined. More...
 
void multiply (const UnitSI &other, int exp=1)
 Multiply with power of given unit. More...
 
void reset ()
 Reset UnitSI object (set vector of exponents to zeros and set undef flag) More...
 
double convert_unit_from (std::string actual_unit) const
 Convert and check user-defined unit. More...
 
bool operator== (const UnitSI &other) const
 Comparison operator. More...
 

Static Public Member Functions

static UnitSIN ()
 
static UnitSIJ ()
 Returns Joule. More...
 
static UnitSIW ()
 Returns Watt. More...
 
static UnitSIPa ()
 Returns Pascal. More...
 
static UnitSIdimensionless ()
 Returns dimensionless unit. More...
 
static UnitSIone ()
 Returns dimensionless unit. More...
 

Private Types

enum  UnitOrder {
  order_m =0, order_md =1, order_kg =2, order_s =3,
  order_A =4, order_K =5, order_mol =6, order_cd =7,
  n_base_units =8
}
 Values determine positions of exponents in exponents_ vector. More...
 

Private Member Functions

std::string format (OutputFormat form) const
 Generic output formating method. More...
 

Static Private Member Functions

static const std::string & unit_symbol (unsigned int idx)
 

Private Attributes

std::vector< int > exponents_
 
bool undef_
 

Friends

UnitSI operator* (const UnitSI &a, const UnitSI &b)
 Product of two units. More...
 
UnitSI operator/ (const UnitSI &a, const UnitSI &b)
 Proportion of two units. More...
 

Detailed Description

Class for representation SI units of Fields.

Units are set through exponents of basic SI units. These exponents are set in methods with same name as unit symbols (e.g. kg(), K() etc).

Class contains method that provides formated string representing full unit symbol (usable in LaTeX output).

UnitSI object contains flag that says if it is defined

Class contains static methods that return frequently used derived units (Watt, Pascal etc).

Definition at line 40 of file unit_si.hh.

Member Enumeration Documentation

enum UnitSI::UnitOrder
private

Values determine positions of exponents in exponents_ vector.

Enumerator
order_m 
order_md 
order_kg 
order_s 
order_A 
order_K 
order_mol 
order_cd 
n_base_units 

Definition at line 117 of file unit_si.hh.

Constructor & Destructor Documentation

UnitSI::UnitSI ( )

Constructor.

Definition at line 28 of file unit_si.cc.

Member Function Documentation

UnitSI & UnitSI::A ( int  exp = 1)

Definition at line 82 of file unit_si.cc.

Here is the caller graph for this function:

UnitSI & UnitSI::cd ( int  exp = 1)

Definition at line 100 of file unit_si.cc.

Here is the caller graph for this function:

double UnitSI::convert_unit_from ( std::string  actual_unit) const

Convert and check user-defined unit.

  • converts unit SI define by user as string
  • checks if converted unit is equal with self
  • return multiplicated coeficient

Definition at line 217 of file unit_si.cc.

Here is the caller graph for this function:

UnitSI & UnitSI::dimensionless ( )
static

Returns dimensionless unit.

Definition at line 55 of file unit_si.cc.

Here is the caller graph for this function:

std::string UnitSI::format ( OutputFormat  form) const
private

Generic output formating method.

Definition at line 144 of file unit_si.cc.

std::string UnitSI::format_latex ( ) const

Makes unit description string in Latex format, e.g. "$[m.kg^{2}.s^{-2}]$"

Have assert for undefined units.

Definition at line 117 of file unit_si.cc.

std::string UnitSI::format_text ( ) const

Definition at line 127 of file unit_si.cc.

Here is the caller graph for this function:

bool UnitSI::is_def ( ) const

Return true if the unit is defined.

Definition at line 201 of file unit_si.cc.

Here is the caller graph for this function:

UnitSI & UnitSI::J ( )
static

Returns Joule.

Definition at line 40 of file unit_si.cc.

Here is the caller graph for this function:

std::string UnitSI::json ( ) const

Machine readable JSON format. Units are stored as a record with keys given by SI units strings (corresponding to setters). Values of the keys are integer.

Definition at line 183 of file unit_si.cc.

UnitSI & UnitSI::K ( int  exp = 1)

Definition at line 88 of file unit_si.cc.

Here is the caller graph for this function:

UnitSI & UnitSI::kg ( int  exp = 1)

Definition at line 70 of file unit_si.cc.

Here is the caller graph for this function:

UnitSI & UnitSI::m ( int  exp = 1)

Methods set values of exponents for SI units with similar name.

Definition at line 64 of file unit_si.cc.

Here is the caller graph for this function:

UnitSI & UnitSI::md ( int  exp = -1)

The dimension dependent meter: md^y = m^(yd), where 'd' is dimension.

Definition at line 106 of file unit_si.cc.

UnitSI & UnitSI::mol ( int  exp = 1)

Definition at line 94 of file unit_si.cc.

Here is the caller graph for this function:

void UnitSI::multiply ( const UnitSI other,
int  exp = 1 
)

Multiply with power of given unit.

Definition at line 205 of file unit_si.cc.

Here is the caller graph for this function:

UnitSI & UnitSI::N ( )
static

Methods return frequently used derived units Returns Newton

Definition at line 35 of file unit_si.cc.

UnitSI & UnitSI::one ( )
static

Returns dimensionless unit.

Definition at line 60 of file unit_si.cc.

bool UnitSI::operator== ( const UnitSI other) const

Comparison operator.

Definition at line 230 of file unit_si.cc.

UnitSI & UnitSI::Pa ( )
static

Returns Pascal.

Definition at line 50 of file unit_si.cc.

void UnitSI::reset ( )

Reset UnitSI object (set vector of exponents to zeros and set undef flag)

Definition at line 212 of file unit_si.cc.

Here is the caller graph for this function:

UnitSI & UnitSI::s ( int  exp = 1)

Definition at line 76 of file unit_si.cc.

Here is the caller graph for this function:

void UnitSI::undef ( bool  val = true)

Set flag that unit is undefined.

Default value is true (set in constructor). If any exponent is set, undef_ flag is unset. In all fields unit must be defined by user.

Definition at line 197 of file unit_si.cc.

Here is the caller graph for this function:

const std::string & UnitSI::unit_symbol ( unsigned int  idx)
staticprivate

Symbols for individual units. Can not use static variable due to usage in static initialization.

Definition at line 137 of file unit_si.cc.

UnitSI & UnitSI::W ( )
static

Returns Watt.

Definition at line 45 of file unit_si.cc.

Here is the caller graph for this function:

Friends And Related Function Documentation

UnitSI operator* ( const UnitSI a,
const UnitSI b 
)
friend

Product of two units.

Definition at line 235 of file unit_si.cc.

UnitSI operator/ ( const UnitSI a,
const UnitSI b 
)
friend

Proportion of two units.

Definition at line 248 of file unit_si.cc.

Member Data Documentation

std::vector<int> UnitSI::exponents_
private

Stores exponents of base SI units in the order given by the UnitOrder enum

where md represents value of exponent depended on dimension (m^{-d})

Definition at line 149 of file unit_si.hh.

bool UnitSI::undef_
private

Flag if object is undefined.

Value is set on true in constructor, when any exponent is changed, false value is set.

Definition at line 157 of file unit_si.hh.


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