Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
shamunits Namespace Reference

namespace containing the units library More...

Classes

struct  Constants
 Physical constants in a unit system. More...
struct  NamedUnit
 One registry entry: a unit and the two names it can be looked up by. More...
struct  Dimension
 Exponents of the seven SI base dimensions. More...
struct  Unit
 A unit: its dimension and its magnitude expressed in SI base units, in precision Tscal. More...
class  UnitSystem
 A unit system, defined by the SI value of its base units. More...

Functions

template<class Tscal>
void to_json (nlohmann::json &j, const ::shamunits::UnitSystem< Tscal > &p)
 Converts a UnitSystem object to a JSON object.
template<class Tscal>
void from_json (const nlohmann::json &j, ::shamunits::UnitSystem< Tscal > &p)
 Deserializes a UnitSystem object from a JSON object.
constexpr Dimension operator* (Dimension a, Dimension b) noexcept
 Dimension of a product: exponents add.
constexpr Dimension operator/ (Dimension a, Dimension b) noexcept
 Dimension of a quotient: exponents subtract.
constexpr Dimension dim_pow (Dimension d, int n) noexcept
 Dimension raised to an integer power: exponents scale.
template<class Tdst, class Tsrc>
constexpr Unit< Tdst > unit_cast (Unit< Tsrc > u) noexcept
 Explicit precision conversion, e.g. unit_cast<float>(units::metre).
template<class T>
constexpr Unit< T > operator* (Unit< T > a, Unit< T > b) noexcept
 Product of two units: exponents add, factors multiply.
template<class T>
constexpr Unit< T > operator/ (Unit< T > a, Unit< T > b) noexcept
 Quotient of two units: exponents subtract, factors divide.
template<class T>
constexpr Unit< T > operator* (T s, Unit< T > u) noexcept
 Scale a unit, e.g. 149597870700. * metre.
template<class T>
constexpr Unit< T > operator* (Unit< T > u, T s) noexcept
 Scale a unit, e.g. metre * 1e3.
template<class T>
constexpr Unit< T > operator/ (Unit< T > u, T s) noexcept
 Divide a unit by a scalar, e.g. joule / 1e7.
template<class T>
constexpr Unit< T > operator/ (T s, Unit< T > u) noexcept
 Scalar over a unit, e.g. 1. / second: the dimension is inverted.
template<class T>
constexpr Unit< T > upow (Unit< T > u, int n) noexcept
 Integer power of a unit.
template<class T = double>
constexpr Unit< T > base_unit (Dimension d) noexcept
 A base unit of the given dimension with factor 1, e.g. base_unit({.metre = 1}).
template<class T>
constexpr Unit< T > scale (T s) noexcept
 A dimensionless scale factor, e.g. a prefix: scale(1e6) (precision of the argument).

Variables

template<class T>
constexpr T pi = 3.141592653589793116
 Value of pi Usage : auto pi = shamunits::pi<T>;.
template<class T>
constexpr T fine_structure = 0.0072973525693
 Fine structure constant.
template<class T>
constexpr T proton_electron_ratio = 1836.1526734311
 Mass ration between the proton and electron.
template<class T>
constexpr T electron_proton_ratio = 1 / proton_electron_ratio<T>
 Mass ration between the electron and proton.

Detailed Description

namespace containing the units library

Function Documentation

◆ base_unit()

template<class T = double>
Unit< T > shamunits::base_unit ( Dimension d)
constexprnoexcept

A base unit of the given dimension with factor 1, e.g. base_unit({.metre = 1}).

Definition at line 165 of file Unit.hpp.

◆ dim_pow()

Dimension shamunits::dim_pow ( Dimension d,
int n )
constexprnoexcept

Dimension raised to an integer power: exponents scale.

Definition at line 75 of file Unit.hpp.

◆ from_json()

template<class Tscal>
void shamunits::from_json ( const nlohmann::json & j,
::shamunits::UnitSystem< Tscal > & p )
inline

Deserializes a UnitSystem object from a JSON object.

Parameters
jThe JSON object to deserialize from.
pThe UnitSystem object to populate.

Definition at line 51 of file units_json.hpp.

◆ operator*() [1/4]

Dimension shamunits::operator* ( Dimension a,
Dimension b )
constexprnoexcept

Dimension of a product: exponents add.

Definition at line 49 of file Unit.hpp.

◆ operator*() [2/4]

template<class T>
Unit< T > shamunits::operator* ( T s,
Unit< T > u )
constexprnoexcept

Scale a unit, e.g. 149597870700. * metre.

Definition at line 117 of file Unit.hpp.

◆ operator*() [3/4]

template<class T>
Unit< T > shamunits::operator* ( Unit< T > a,
Unit< T > b )
constexprnoexcept

Product of two units: exponents add, factors multiply.

Definition at line 105 of file Unit.hpp.

◆ operator*() [4/4]

template<class T>
Unit< T > shamunits::operator* ( Unit< T > u,
T s )
constexprnoexcept

Scale a unit, e.g. metre * 1e3.

Definition at line 123 of file Unit.hpp.

◆ operator/() [1/4]

Dimension shamunits::operator/ ( Dimension a,
Dimension b )
constexprnoexcept

Dimension of a quotient: exponents subtract.

Definition at line 62 of file Unit.hpp.

◆ operator/() [2/4]

template<class T>
Unit< T > shamunits::operator/ ( T s,
Unit< T > u )
constexprnoexcept

Scalar over a unit, e.g. 1. / second: the dimension is inverted.

Definition at line 135 of file Unit.hpp.

◆ operator/() [3/4]

template<class T>
Unit< T > shamunits::operator/ ( Unit< T > a,
Unit< T > b )
constexprnoexcept

Quotient of two units: exponents subtract, factors divide.

Definition at line 111 of file Unit.hpp.

◆ operator/() [4/4]

template<class T>
Unit< T > shamunits::operator/ ( Unit< T > u,
T s )
constexprnoexcept

Divide a unit by a scalar, e.g. joule / 1e7.

Definition at line 129 of file Unit.hpp.

◆ scale()

template<class T>
Unit< T > shamunits::scale ( T s)
constexprnoexcept

A dimensionless scale factor, e.g. a prefix: scale(1e6) (precision of the argument).

Definition at line 171 of file Unit.hpp.

◆ to_json()

template<class Tscal>
void shamunits::to_json ( nlohmann::json & j,
const ::shamunits::UnitSystem< Tscal > & p )
inline

Converts a UnitSystem object to a JSON object.

Parameters
jThe JSON object to be populated.
pThe UnitSystem object to be converted.

Definition at line 33 of file units_json.hpp.

◆ unit_cast()

template<class Tdst, class Tsrc>
Unit< Tdst > shamunits::unit_cast ( Unit< Tsrc > u)
constexprnoexcept

Explicit precision conversion, e.g. unit_cast<float>(units::metre).

Definition at line 99 of file Unit.hpp.

◆ upow()

template<class T>
Unit< T > shamunits::upow ( Unit< T > u,
int n )
constexprnoexcept

Integer power of a unit.

Named upow rather than pow so argument-dependent lookup never competes with std::pow or sycl::pow. This is the only place in the unit algebra that can divide (for n < 0), and it folds at compile time whenever its argument is a constant expression.

Definition at line 147 of file Unit.hpp.

Here is the call graph for this function:

Variable Documentation

◆ electron_proton_ratio

template<class T>
T shamunits::electron_proton_ratio = 1 / proton_electron_ratio<T>
constexpr

Mass ration between the electron and proton.

Definition at line 46 of file Constants.hpp.

◆ fine_structure

template<class T>
T shamunits::fine_structure = 0.0072973525693
constexpr

Fine structure constant.

Definition at line 38 of file Constants.hpp.

◆ pi

template<class T>
T shamunits::pi = 3.141592653589793116
constexpr

Value of pi Usage : auto pi = shamunits::pi<T>;.

Definition at line 34 of file Constants.hpp.

◆ proton_electron_ratio

template<class T>
T shamunits::proton_electron_ratio = 1836.1526734311
constexpr

Mass ration between the proton and electron.

Definition at line 42 of file Constants.hpp.