SyDEVS  v0.7
Simulation-based analysis of complex systems involving people, devices, physical elements, and dynamic environments.
sydevs::units< g, m, s, A, K, mol, cd > Struct Template Reference

A template which represents Standard International (SI) units inclusing the base units such as grams, meters, and seconds, and derived units such as meters-per-second-squared. More...

#include <units.h>

Public Types

enum  {
  g_ = g , m_ = m , s_ = s , A_ = A ,
  K_ = K , mol_ = mol , cd_ = cd
}
 

Public Member Functions

constexpr units ()=default
 Constructs a unit object. More...
 
template<int64 g_, int64 m_, int64 s_, int64 A_, int64 K_, int64 mol_, int64 cd_>
constexpr units< g+g_, m+m_, s+s_, A+A_, K+K_, mol+mol_, cd+cd_operator* (units< g_, m_, s_, A_, K_, mol_, cd_ > rhs) const
 Combines two units into one as if the unit on the left were multiplied by that on the right. More...
 
template<int64 g_, int64 m_, int64 s_, int64 A_, int64 K_, int64 mol_, int64 cd_>
constexpr units< g - g_, m - m_, s - s_, A - A_, K - K_, mol - mol_, cd - cd_operator/ (units< g_, m_, s_, A_, K_, mol_, cd_ > rhs) const
 Combines two units into one as if the unit on the left were divided by that on the right. More...
 

Detailed Description

template<int64 g, int64 m, int64 s, int64 A, int64 K, int64 mol, int64 cd>
struct sydevs::units< g, m, s, A, K, mol, cd >

A template which represents Standard International (SI) units inclusing the base units such as grams, meters, and seconds, and derived units such as meters-per-second-squared.

The units type can be used to specify an SI unit at compile time as a combination of the 7 base units: grams (g), meters (m), seconds (s), Amperes (A), Kelvin (L), mols (mol), and candelas (cd).

A type alias is defined for dimensionless quantities.

units< 0, 0, 0, 0, 0, 0, 0 > no_units
Definition: units.h:115

There is also a type alias for each of the base units:

grams // Unit of mass
meters // Unit of distance
seconds // Unit of duration
amperes // Unit of electric current
kelvins // Unit of thermodynamic temperature
moles // Unit of amount of substance
candelas // Unit of luminous intensity
units< 0, 0, 0, 0, 1, 0, 0 > kelvins
Definition: units.h:120
units< 0, 0, 1, 0, 0, 0, 0 > seconds
Definition: units.h:118
units< 0, 0, 0, 1, 0, 0, 0 > amperes
Definition: units.h:119
units< 0, 0, 0, 0, 0, 1, 0 > moles
Definition: units.h:121
units< 0, 0, 0, 0, 0, 0, 1 > candelas
Definition: units.h:122
units< 1, 0, 0, 0, 0, 0, 0 > grams
Definition: units.h:116
units< 0, 1, 0, 0, 0, 0, 0 > meters
Definition: units.h:117

For each base unit, the associated value is defined as a constant.

_g // grams()
_m // meters()
_s // seconds()
_A // amperes()
_K // kelvins()
_mol // moles()
_cd // candelas()
constexpr auto _m
Definition: units.h:127
constexpr auto _s
Definition: units.h:128
constexpr auto _g
Definition: units.h:126
constexpr auto _K
Definition: units.h:130
constexpr auto _A
Definition: units.h:129
constexpr auto _cd
Definition: units.h:132
constexpr auto _mol
Definition: units.h:131

There are two ways to expressed SI derived units. The first is using the template constructor, where each template parameter is the exponent of the corresponding base unit.

units<0, 1, -1, 0, 0, 0, 0> // meters/second (speed)
units<0, 1, -2, 0, 0, 0, 0> // meters/second^2 (acceleration)
units<0, 0, 1, 1, 0, 0, 0> // second*Ampere or coulomb (electric charge)
units<0, -2, 0, 0, 0, 0, 1> // candelas/meter^2 or lux (illuminance)
constexpr units()=default
Constructs a unit object.

The second approach employs the base unit values in conjunction with multiplication and division operators and decltype.

decltype(_m/_s) // meters/second (speed)
decltype(_m/_s/_s) // meters/second^2 (acceleration)
decltype(_s*_A) // second*Ampere or coulomb (electric charge)
decltype (_cd/_m/_m) // candelas/meter^2 or lux (illuminance)

It is important to note that the units class treats grams, not kilograms, as the base unit for mass. This affects derived quantities such as Newtons.

decltype(_g*_m/_s/_s) // grams*meters/second^2 or milliNewtons (force)

Member Enumeration Documentation

◆ anonymous enum

template<int64 g, int64 m, int64 s, int64 A, int64 K, int64 mol, int64 cd>
anonymous enum
Enumerator
g_ 

Grams exponent.

m_ 

Meters exponent.

s_ 

Seconds exponent.

A_ 

Amperes exponent.

K_ 

Kelvins exponent.

mol_ 

Moles exponent.

cd_ 

Candelas exponent.

Constructor & Destructor Documentation

◆ units()

template<int64 g, int64 m, int64 s, int64 A, int64 K, int64 mol, int64 cd>
constexpr sydevs::units< g, m, s, A, K, mol, cd >::units ( )
constexprdefault

Constructs a unit object.

Member Function Documentation

◆ operator*()

template<int64 g, int64 m, int64 s, int64 A, int64 K, int64 mol, int64 cd>
template<int64 g_, int64 m_, int64 s_, int64 A_, int64 K_, int64 mol_, int64 cd_>
constexpr units<g + g_, m + m_, s + s_, A + A_, K + K_, mol + mol_, cd + cd_> sydevs::units< g, m, s, A, K, mol, cd >::operator* ( units< g_, m_, s_, A_, K_, mol_, cd_ rhs) const
inlineconstexpr

Combines two units into one as if the unit on the left were multiplied by that on the right.

◆ operator/()

template<int64 g, int64 m, int64 s, int64 A, int64 K, int64 mol, int64 cd>
template<int64 g_, int64 m_, int64 s_, int64 A_, int64 K_, int64 mol_, int64 cd_>
constexpr units<g - g_, m - m_, s - s_, A - A_, K - K_, mol - mol_, cd - cd_> sydevs::units< g, m, s, A, K, mol, cd >::operator/ ( units< g_, m_, s_, A_, K_, mol_, cd_ rhs) const
inlineconstexpr

Combines two units into one as if the unit on the left were divided by that on the right.


The documentation for this struct was generated from the following file: