Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:52:28

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file celeritas/Units.hh
0006 //! \brief Unit definitions
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Config.hh"
0011 
0012 #include "corecel/Types.hh"
0013 #include "corecel/math/Constant.hh"
0014 
0015 namespace celeritas
0016 {
0017 //---------------------------------------------------------------------------//
0018 /*!
0019  * Units in Celeritas for macro-scale quantities.
0020  *
0021  * Celeritas can be configured at build time to use different unit systems for
0022  * better compatibility with external libraries and applications. The
0023  * \c CELERITAS_UNITS CMake variable can be set to one of the following:
0024  * - `CELERITAS_UNITS_CGS` (default): use Gaussian CGS units
0025  * - `CELERITAS_UNITS_SI`: use SI units
0026  * - `CELERITAS_UNITS_CLHEP`: use the Geant4 high energy physics system (a mix
0027  *   of macro-scale and atomic-scale units)
0028  *
0029  * The following units have numerical values of 1 in the default Celeritas
0030  * system (Gaussian CGS) and are often seen in unit tests:
0031  * - cm for standard unit of length
0032  * - s for standard unit of time
0033  * - g for standard unit of mass
0034  * - G for standard unit of field strength
0035  *
0036  * Unless otherwise specified, the user-selected unit system is used for input
0037  * and
0038  * output numerical values. They are meant for macro-scale quantities coupling
0039  * the different code components of Celeritas.
0040  *
0041  * \note This system of units should be fully consistent so that constants can
0042  * be precisely defined. (E.g., you cannot define both MeV as 1 and Joule
0043  * as 1.) To express quantities in another system of units, such as MeV and
0044  * "natural" units, use the Quantity class.
0045  *
0046  * See also:
0047  *  - \c Constants.hh for constants defined in this unit system
0048  *  - \c physics/base/Units.hh for unit systems used by the physics
0049  *
0050  * Additionally:
0051  * - radians are used for measures of angle (unitless)
0052  * - steradians are used for measures of solid angle (unitless)
0053  */
0054 namespace units
0055 {
0056 //---------------------------------------------------------------------------//
0057 
0058 #define CELER_ICRT inline constexpr Constant
0059 
0060 #if CELERITAS_UNITS == CELERITAS_UNITS_CGS
0061 //!@{
0062 //! \name Units with numerical value defined to be 1 for CGS
0063 CELER_ICRT centimeter{1};  //!< Length
0064 CELER_ICRT gram{1};  //!< Mass
0065 CELER_ICRT second{1};  //!< Time
0066 CELER_ICRT gauss{1};  //!< Field strength
0067 CELER_ICRT kelvin{1};  //!< Temperature
0068 //!@}
0069 
0070 //!@{
0071 //! \name Exact unit transformations to SI units
0072 CELER_ICRT meter = 100 * centimeter;
0073 CELER_ICRT kilogram = 1000 * gram;
0074 CELER_ICRT tesla = 10000 * gauss;
0075 //!@}
0076 
0077 //!@{
0078 //! \name Exact unit transformations using SI unit definitions
0079 CELER_ICRT newton = kilogram * meter / (second * second);
0080 CELER_ICRT joule = newton * meter;
0081 CELER_ICRT coulomb = kilogram / (tesla * second);
0082 CELER_ICRT ampere = coulomb / second;
0083 CELER_ICRT volt = joule / coulomb;
0084 CELER_ICRT farad = coulomb / volt;
0085 //!@}
0086 
0087 //!@{
0088 //! \name CLHEP units
0089 CELER_ICRT millimeter = Constant{0.1} * centimeter;
0090 CELER_ICRT nanosecond = Constant{1e-9} * second;
0091 //!@}
0092 
0093 #elif CELERITAS_UNITS == CELERITAS_UNITS_SI
0094 //!@{
0095 //! \name Units with numerical value defined to be 1 for SI
0096 CELER_ICRT second{1};  //!< Time
0097 CELER_ICRT meter{1};  //!< Length
0098 CELER_ICRT kilogram{1};  //!< Mass
0099 CELER_ICRT kelvin{1};  //!< Temperature
0100 CELER_ICRT coulomb{1};  //!< Charge
0101 //!@}
0102 
0103 //!@{
0104 //! \name Exact unit transformations using SI unit definitions
0105 CELER_ICRT newton = kilogram * meter / (second * second);
0106 CELER_ICRT joule = newton * meter;
0107 CELER_ICRT volt = joule / coulomb;
0108 CELER_ICRT tesla = volt * second / (meter * meter);
0109 CELER_ICRT ampere = coulomb / second;
0110 CELER_ICRT farad = coulomb / volt;
0111 //!@}
0112 
0113 //!@{
0114 //! \name CGS units
0115 CELER_ICRT gauss = Constant{1e-4} * tesla;
0116 CELER_ICRT centimeter = Constant{1e-2} * meter;
0117 CELER_ICRT gram = Constant{1e-3} * kilogram;
0118 //!@}
0119 
0120 //!@{
0121 //! \name CLHEP units
0122 CELER_ICRT millimeter = Constant{1e-3} * meter;
0123 CELER_ICRT nanosecond = Constant{1e-9} * second;
0124 //!@}
0125 
0126 #elif CELERITAS_UNITS == CELERITAS_UNITS_CLHEP
0127 
0128 //!@{
0129 //! \name Units with numerical value defined to be 1 for CLHEP
0130 CELER_ICRT millimeter{1};  //!< Length
0131 CELER_ICRT megaelectronvolt{1};  //!< Energy
0132 CELER_ICRT nanosecond{1};  //!< Time
0133 CELER_ICRT e_electron{1};  //!< Charge
0134 CELER_ICRT kelvin{1};  //!< Temperature
0135 //!@}
0136 
0137 // Note: conversion constant is the value from SI 2019
0138 CELER_ICRT coulomb = e_electron / Constant{1.602176634e-19};
0139 CELER_ICRT volt = Constant{1e-6} * (megaelectronvolt / e_electron);
0140 CELER_ICRT joule = coulomb * volt;
0141 
0142 CELER_ICRT second = Constant{1e9} * nanosecond;
0143 CELER_ICRT meter = 1000 * millimeter;
0144 
0145 CELER_ICRT ampere = coulomb / second;
0146 CELER_ICRT farad = coulomb / volt;
0147 CELER_ICRT kilogram = joule * (second / meter) * (second / meter);
0148 CELER_ICRT tesla = volt * second / (meter * meter);
0149 CELER_ICRT newton = joule / meter;
0150 
0151 //!@{
0152 //! \name CGS-specific units
0153 CELER_ICRT centimeter = 10 * millimeter;
0154 CELER_ICRT gram = Constant{1e-3} * kilogram;
0155 CELER_ICRT gauss = Constant{1e-4} * tesla;
0156 //!@}
0157 
0158 #endif
0159 
0160 //!@{
0161 //! \name Other common units
0162 CELER_ICRT micrometer = Constant{1e-4} * centimeter;
0163 CELER_ICRT nanometer = Constant{1e-7} * centimeter;
0164 CELER_ICRT femtometer = Constant{1e-13} * centimeter;
0165 CELER_ICRT barn = Constant{1e-24} * centimeter * centimeter;
0166 //!@}
0167 
0168 #undef CELER_ICRT
0169 
0170 //---------------------------------------------------------------------------//
0171 }  // namespace units
0172 }  // namespace celeritas