Reactions  0.0.0
Handling reaction trees and decays
units.hpp
Go to the documentation of this file.
1 /* \file
2 \brief Definition of units
3  */
4 #pragma once
6 #include "reactions/pow_enum.hpp"
7 
8 namespace reactions {
9 
11  REACTIONS_POW_ENUM_WITH_UNKNOWN(energy_units, eV, keV, MeV, GeV, TeV, PeV);
12 
14  namespace units {
15 
17  struct none {};
18 
20  auto scale_factor_for(energy_units u) {
21  switch (u) {
22  case (energy_units::eV):
23  return 1.;
24  case (energy_units::keV):
25  return 1e3;
26  case (energy_units::MeV):
27  return 1e6;
28  case (energy_units::GeV):
29  return 1e9;
30  case (energy_units::TeV):
31  return 1e12;
32  case (energy_units::PeV):
33  return 1e12;
34  case (energy_units::unknown):
35  break;
36  }
37 
38  throw internal_error(
39  (std::string{
40  "Attempt to compute a scale factor of an unknown unit: \""} +
41  energy_units_properties::to_string(u) + '"')
42  .c_str());
43  }
44 
46  template <energy_units U> struct reference {
48  static constexpr auto scale_factor(energy_units u) {
49  if (u == U)
50  return 1.;
51  else
52  return scale_factor_for(U) / scale_factor_for(u);
53  }
54  };
55  } // namespace units
56 } // namespace reactions
Exceptions that can be thrown when running the functions of the package.
auto scale_factor_for(energy_units u)
Compute the scale factor for the given unit.
Definition: units.hpp:20
Raised when unexpected problems appear, which should be reported as bugs.
Definition: exceptions.hpp:38
static constexpr auto scale_factor(energy_units u)
Determine the scale factor from a reference.
Definition: units.hpp:48
STL class.
Use the template argument as a reference to determine scale factors.
Definition: units.hpp:46
Contains macros to define smart enumeration types.
Main namespace of the Reactions package.
Definition: all.hpp:21
REACTIONS_POW_ENUM_WITH_UNKNOWN(energy_units, eV, keV, MeV, GeV, TeV, PeV)
Energy units.
Represent the abscence of units.
Definition: units.hpp:17