Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
shamunits::UnitSystem< T > Class Template Reference

Defines a unit system. More...

#include <shamunits/include/shamunits/UnitSystem.hpp>

Collaboration diagram for shamunits::UnitSystem< T >:

Public Member Functions

 UnitSystem (T unit_time=1, T unit_length=1, T unit_mass=1, T unit_current=1, T unit_temperature=1, T unit_qte=1, T unit_lumint=1)
 Construct a new UnitSystem from either supplied base units or SI by default.
template<UnitPrefix pref = None, units::UnitName u, int power = 1>
constexpr T get () const noexcept
 get the value of a units in the current system
template<UnitPrefix pref = None, units::UnitName u, int power = 1>
constexpr T to ()
 To the si units (convert a system unit to si ones). This function is the inverse of get.
template<units::UnitName u, int power = 1>
constexpr T get ()
 Simplified signature for get without prefix.
template<units::UnitName u, int power = 1>
constexpr T to ()
 Simplified signature for to without prefix.
runtime_get (UnitPrefix pref, units::UnitName name, int power)
 Non templated version of get.
runtime_to (UnitPrefix pref, units::UnitName name, int power)
 Non templated version of to.

Public Attributes

s
 value of a second in this system
m
 value of a meter in this system
kg
 value of a kilogram in this system
A
 value of a Ampere in this system
K
 value of a Kelvin in this system
mol
 value of a mol in this system
cd
 value of a candela in this system
s_inv
 inverse value of a second in this system
m_inv
 inverse value of a meter in this system
kg_inv
 inverse value of a kilogram in this system
A_inv
 inverse value of a Ampere in this system
K_inv
 inverse value of a Kelvin in this system
mol_inv
 inverse value of a mol in this system
cd_inv
 inverse value of a candela in this system

Detailed Description

template<class T>
class shamunits::UnitSystem< T >

Defines a unit system.

Example of usage :

using namespace shamunits;
//create si units
// get the value of au^2 in the unit system
// but it is quite big :)
std::cout << si.get<units::astronomical_unit,2>() << std::endl;
double sol_mass = Constants<double>(si).sol_mass();
/*
* create a unit system with time in Myr, length in au, mass in solar masses
*/
UnitSystem<double> astro_units {
si.get<mega, units::years>(),
si.get<units::astronomical_unit>(),
si.get<units::kilogram>()*sol_mass,
};
//this time it returns 1 because the base length is the astronomical unit
std::cout << astro_units.get<units::astronomical_unit,2>() << std::endl;
Constants<double> astro_cte {astro_units};
// in those units G is 3.94781e+25
std::cout << astro_cte.G() << std::endl;
Defines a unit system.
constexpr T get() const noexcept
get the value of a units in the current system
UnitSystem(T unit_time=1, T unit_length=1, T unit_mass=1, T unit_current=1, T unit_temperature=1, T unit_qte=1, T unit_lumint=1)
Construct a new UnitSystem from either supplied base units or SI by default.
namespace containing the units library
Physical constants.
constexpr T sol_mass()
get the value of a sol_mass in the mass unit of the current unit system units
constexpr T G()
get the value of G in the current unit system units

Definition at line 77 of file UnitSystem.hpp.

Constructor & Destructor Documentation

◆ UnitSystem()

template<class T>
shamunits::UnitSystem< T >::UnitSystem ( T unit_time = 1,
T unit_length = 1,
T unit_mass = 1,
T unit_current = 1,
T unit_temperature = 1,
T unit_qte = 1,
T unit_lumint = 1 )
inlineexplicit

Construct a new UnitSystem from either supplied base units or SI by default.

Parameters
unit_time
unit_length
unit_mass
unit_current
unit_temperature
unit_qte
unit_lumint

Definition at line 148 of file UnitSystem.hpp.

Member Function Documentation

◆ get() [1/2]

template<class T>
template<units::UnitName u, int power = 1>
T shamunits::UnitSystem< T >::get ( )
inlineconstexpr

Simplified signature for get without prefix.

Definition at line 240 of file UnitSystem.hpp.

◆ get() [2/2]

template<class T>
template<UnitPrefix pref = None, units::UnitName u, int power = 1>
T shamunits::UnitSystem< T >::get ( ) const
inlineconstexprnoexcept

get the value of a units in the current system

Todo
better doc with example
Template Parameters
prefunit prefix (default to none)
uthe units
powerthe power of the units (also applied to the prefix)
Returns
constexpr T the value in this system

◆ runtime_get()

template<class T>
T shamunits::UnitSystem< T >::runtime_get ( UnitPrefix pref,
units::UnitName name,
int power )
inline

Non templated version of get.

Definition at line 319 of file UnitSystem.hpp.

◆ runtime_to()

template<class T>
T shamunits::UnitSystem< T >::runtime_to ( UnitPrefix pref,
units::UnitName name,
int power )
inline

Non templated version of to.

Definition at line 324 of file UnitSystem.hpp.

◆ to() [1/2]

template<class T>
template<units::UnitName u, int power = 1>
T shamunits::UnitSystem< T >::to ( )
inlineconstexpr

Simplified signature for to without prefix.

Definition at line 246 of file UnitSystem.hpp.

◆ to() [2/2]

template<class T>
template<UnitPrefix pref = None, units::UnitName u, int power = 1>
T shamunits::UnitSystem< T >::to ( )
inlineconstexpr

To the si units (convert a system unit to si ones). This function is the inverse of get.

Todo
better doc with example
Template Parameters
prefunit prefix (default to none)
uthe units
powerthe power of the units (also applied to the prefix)
Returns
constexpr T the value in si units

Definition at line 234 of file UnitSystem.hpp.

Member Data Documentation

◆ A

template<class T>
T shamunits::UnitSystem< T >::A

value of a Ampere in this system

Definition at line 134 of file UnitSystem.hpp.

◆ A_inv

template<class T>
T shamunits::UnitSystem< T >::A_inv

inverse value of a Ampere in this system

Definition at line 135 of file UnitSystem.hpp.

◆ cd

template<class T>
T shamunits::UnitSystem< T >::cd

value of a candela in this system

Definition at line 134 of file UnitSystem.hpp.

◆ cd_inv

template<class T>
T shamunits::UnitSystem< T >::cd_inv

inverse value of a candela in this system

Definition at line 135 of file UnitSystem.hpp.

◆ K

template<class T>
T shamunits::UnitSystem< T >::K

value of a Kelvin in this system

Definition at line 134 of file UnitSystem.hpp.

◆ K_inv

template<class T>
T shamunits::UnitSystem< T >::K_inv

inverse value of a Kelvin in this system

Definition at line 135 of file UnitSystem.hpp.

◆ kg

template<class T>
T shamunits::UnitSystem< T >::kg

value of a kilogram in this system

Definition at line 134 of file UnitSystem.hpp.

◆ kg_inv

template<class T>
T shamunits::UnitSystem< T >::kg_inv

inverse value of a kilogram in this system

Definition at line 135 of file UnitSystem.hpp.

◆ m

template<class T>
T shamunits::UnitSystem< T >::m

value of a meter in this system

Definition at line 134 of file UnitSystem.hpp.

◆ m_inv

template<class T>
T shamunits::UnitSystem< T >::m_inv

inverse value of a meter in this system

Definition at line 135 of file UnitSystem.hpp.

◆ mol

template<class T>
T shamunits::UnitSystem< T >::mol

value of a mol in this system

Definition at line 134 of file UnitSystem.hpp.

◆ mol_inv

template<class T>
T shamunits::UnitSystem< T >::mol_inv

inverse value of a mol in this system

Definition at line 135 of file UnitSystem.hpp.

◆ s

template<class T>
T shamunits::UnitSystem< T >::s

value of a second in this system

Definition at line 134 of file UnitSystem.hpp.

◆ s_inv

template<class T>
T shamunits::UnitSystem< T >::s_inv

inverse value of a second in this system

Definition at line 135 of file UnitSystem.hpp.


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