Phyth v0.1.0
A dimensional safe C++ header-only mechanics and electromagnetics simulation library.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | List of all members
Phyth::Unit< DimT, Scale, TagT > Struct Template Reference

Physical unit with dimension and scale factor relative to SI base. More...

#include <Unit.hpp>

Public Types

using DimensionT = DimT
 
using ScaleT = Scale
 

Public Member Functions

 Unit ()=default
 Default constructor.
 

Static Public Attributes

static constexpr double scale = static_cast<double>(Scale::num) / Scale::den
 Scale factor relative to the SI base unit.
 

Detailed Description

template<typename DimT, typename Scale = std::ratio<1>, typename TagT = void>
struct Phyth::Unit< DimT, Scale, TagT >

Physical unit with dimension and scale factor relative to SI base.

Unit is the compile-time representation of a unit. It combines:

Template Parameters
DimTThe dimension type (e.g., Length, Mass, Velocity)
Scalestd::ratio scale relative to base unit (default: 1)
TagTAn optional tag type to distinguish units with same dimension and scale (e.g., radians vs. degrees)

Example: using Meter = Unit<Length, std::ratio<1>>; using Kilometer = Unit<Length, std::ratio<1000>>; using Second = Unit<Time, std::ratio<1>>; using MilliSecond = Unit<Time, std::ratio<1, 1000>>;

// Same dimension, different scale, no tag static_assert(std::is_same_v<Meter::DimensionT, Length>); static_assert(Meter::scale == 1.0); static_assert(Kilometer::scale == 1000.0);

// Differentiating units with the same dimension and scale via TagT: struct RadianTag {}; struct DegreeTag {}; using Radian = Unit<Dimensionless, std::ratio<1>, RadianTag>; using Degree = Unit<Dimensionless, std::ratio<1>, DegreeTag>; // Radian and Degree are distinct types despite having the same // DimensionT and scale, because their TagT differ. static_assert(!stdis_same_v<Radian, Degree>);

Definition at line 41 of file Unit.hpp.

Member Typedef Documentation

◆ DimensionT

template<typename DimT , typename Scale = std::ratio<1>, typename TagT = void>
using Phyth::Unit< DimT, Scale, TagT >::DimensionT = DimT

The dimension type of this unit

Definition at line 43 of file Unit.hpp.

◆ ScaleT

template<typename DimT , typename Scale = std::ratio<1>, typename TagT = void>
using Phyth::Unit< DimT, Scale, TagT >::ScaleT = Scale

Definition at line 44 of file Unit.hpp.

Constructor & Destructor Documentation

◆ Unit()

template<typename DimT , typename Scale = std::ratio<1>, typename TagT = void>
Phyth::Unit< DimT, Scale, TagT >::Unit ( )
default

Default constructor.

Member Data Documentation

◆ scale

template<typename DimT , typename Scale = std::ratio<1>, typename TagT = void>
constexpr double Phyth::Unit< DimT, Scale, TagT >::scale = static_cast<double>(Scale::num) / Scale::den
staticconstexpr

Scale factor relative to the SI base unit.

Value is computed at compile-time as Scale::num / Scale::den. Examples: Meter::scale = 1.0 Kilometer::scale = 1000.0 MilliSecond::scale = 0.001

Definition at line 55 of file Unit.hpp.


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