DLG4::VolumeBuilders
A fluent interface for Geant4 geometry definition.
Loading...
Searching...
No Matches
Classes | Typedefs | Functions | Variables
DLG4::Units Namespace Reference

Classes

class  Density
 
class  Length
 
class  Mass
 
class  Unit
 
class  Unit3Vec
 
struct  UnitOrValue
 
struct  UnitTag
 
class  Volume
 

Typedefs

using Length3Vec = Unit3Vec
 
template<typename T , typename U >
using ResultType = std::conditional_t< std::is_base_of_v< UnitTag, T >, T, U >
 
using UnitlessG4Transform3D = G4Transform3D
 

Functions

Density operator/ (Mass m, Volume v)
 
template<typename T , typename U , typename = std::enable_if_t<std::is_base_of_v<UnitTag, T> != std::is_base_of_v<UnitTag, U>>>
auto operator* (const T &a, const U &b)
 
template<typename T , typename U , typename = std::enable_if_t<std::is_base_of_v<UnitTag, T> && !std::is_base_of_v<UnitTag, U>>>
auto operator/ (const T &a, const U &b)
 
template<typename T , typename = std::enable_if_t<std::is_base_of_v<UnitTag, T>>>
operator+ (const T &a, const T &b)
 
template<typename T , typename = std::enable_if_t<std::is_base_of_v<UnitTag, T>>>
operator- (const T &a, const T &b)
 
Unit3Vec operator* (const G4ThreeVector &v, const Length &u)
 
Unit3Vec operator* (const Unit3Vec &v, G4double scalar)
 
Unit3Vec operator* (G4double scalar, const Unit3Vec &v)
 
Unit3Vec operator/ (const Unit3Vec &v, G4double scalar)
 
template<typename T >
void SetGlobalDefaultUnit (T unit)
 

Variables

template<typename T >
G4double global_default_unit = 1.0
 

Detailed Description

Typesafe units!! No accidental mixing values and units.

Typedef Documentation

◆ Length3Vec

A 3 vector that is scalable with/to Units.

Definition at line 132 of file DLG4Units.hh.

◆ ResultType

template<typename T , typename U >
using ResultType = std::conditional_t<std::is_base_of_v<UnitTag, T>, T, U>

Definition at line 418 of file DLG4Units.hh.

◆ UnitlessG4Transform3D

using UnitlessG4Transform3D = G4Transform3D

Definition at line 545 of file DLG4Units.hh.

Function Documentation

◆ operator*() [1/4]

Unit3Vec operator* ( const G4ThreeVector &  v,
const Length u 
)
inline

Definition at line 528 of file DLG4Units.hh.

528 {
529 return Unit3Vec(v, u);
530 }
A 3 vector that is scalable with/to Units.
Definition DLG4Units.hh:452

◆ operator*() [2/4]

template<typename T , typename U , typename = std::enable_if_t<std::is_base_of_v<UnitTag, T> != std::is_base_of_v<UnitTag, U>>>
auto operator* ( const T &  a,
const U &  b 
)
inline

Definition at line 423 of file DLG4Units.hh.

423 {
424 using R = ResultType<T, U>;
425 return R(UnitOrValue<T>(a).val * UnitOrValue<U>(b).val, R::native);
426 }
std::conditional_t< std::is_base_of_v< UnitTag, T >, T, U > ResultType
Definition DLG4Units.hh:418
Type-erases unit or value to just a value.
Definition DLG4Units.hh:406

◆ operator*() [3/4]

Unit3Vec operator* ( const Unit3Vec v,
G4double  scalar 
)
inline

Definition at line 532 of file DLG4Units.hh.

532 {
533 // We use the FromNative-style construction to wrap the scaled vector
534 return Unit3Vec(v.Native() * scalar, Length::native);
535 }
G4ThreeVector Native() const
Definition DLG4Units.hh:507

◆ operator*() [4/4]

Unit3Vec operator* ( G4double  scalar,
const Unit3Vec v 
)
inline

Definition at line 537 of file DLG4Units.hh.

537 {
538 return v * scalar; // Just reuse the one above
539 }

◆ operator+()

template<typename T , typename = std::enable_if_t<std::is_base_of_v<UnitTag, T>>>
T operator+ ( const T &  a,
const T &  b 
)
inline

Definition at line 438 of file DLG4Units.hh.

438 {
439 // Uses the protected constructor/FromNative to return a new dimensioned object
440 return T::FromNative(a.Native() + b.Native());
441 }

◆ operator-()

template<typename T , typename = std::enable_if_t<std::is_base_of_v<UnitTag, T>>>
T operator- ( const T &  a,
const T &  b 
)
inline

Definition at line 445 of file DLG4Units.hh.

445 {
446 return T::FromNative(a.Native() - b.Native());
447 }

◆ operator/() [1/3]

template<typename T , typename U , typename = std::enable_if_t<std::is_base_of_v<UnitTag, T> && !std::is_base_of_v<UnitTag, U>>>
auto operator/ ( const T &  a,
const U &  b 
)
inline

Definition at line 431 of file DLG4Units.hh.

431 {
432 // T is the Unit, U is the Scalar
433 return T(UnitOrValue<T>(a).val / static_cast<double>(b), T::native);
434 }

◆ operator/() [2/3]

Unit3Vec operator/ ( const Unit3Vec v,
G4double  scalar 
)
inline

Definition at line 541 of file DLG4Units.hh.

541 {
542 return Unit3Vec(v.Native() / scalar, Length::native);
543 }

◆ operator/() [3/3]

Density operator/ ( Mass  m,
Volume  v 
)
inline

Definition at line 366 of file DLG4Units.hh.

366 {
367 Density x = Density::FromNative(m.Native / v.Native);
368 return x;
369 }
PropertySetter Native
Definition DLG4Units.hh:182

Variable Documentation

◆ global_default_unit

template<typename T >
G4double global_default_unit = 1.0
inline

Definition at line 137 of file DLG4Units.hh.