Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 09:57:02

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2020-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file celeritas/Units.hh
0007 //! \brief Unit definitions
0008 //---------------------------------------------------------------------------//
0009 #pragma once
0010 
0011 #include "corecel/Config.hh"
0012 
0013 #include "corecel/Types.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, this unit system is used for input and
0037  * output numerical values. They are meant for macro-scale quantities coupling
0038  * the different code components of Celeritas.
0039  *
0040  * \note This system of units should be fully consistent so that constants can
0041  * be precisely defined. (E.g., you cannot define both MeV as 1 and Joule
0042  * as 1.) To express quantities in another system of units, such as MeV and
0043  * "natural" units, use the Quantity class.
0044  *
0045  * See also:
0046  *  - \c Constants.hh for constants defined in this unit system
0047  *  - \c physics/base/Units.hh for unit systems used by the physics
0048  *
0049  * Additionally:
0050  * - radians are used for measures of angle (unitless)
0051  * - steradians are used for measures of solid angle (unitless)
0052  *
0053  * \todo If we're serious about supporting single-precision arithmetic, we
0054  * should define a helper class that stores the constant as full precision but
0055  * when multiplied by a single/double is truncated to that precision.
0056  * Otherwise, if \c real_type is single-precision, then we lose accuracy in
0057  * places like the GeantImporter where everything is double precision.
0058  */
0059 namespace units
0060 {
0061 //---------------------------------------------------------------------------//
0062 
0063 #define CELER_ICRT inline constexpr real_type
0064 
0065 #if CELERITAS_UNITS == CELERITAS_UNITS_CGS
0066 //!@{
0067 //! \name Units with numerical value defined to be 1 for CGS
0068 CELER_ICRT centimeter = 1;  //!< Length
0069 CELER_ICRT gram = 1;  //!< Mass
0070 CELER_ICRT second = 1;  //!< Time
0071 CELER_ICRT gauss = 1;  //!< Field strength
0072 CELER_ICRT kelvin = 1;  //!< Temperature
0073 //!@}
0074 
0075 //!@{
0076 //! \name Exact unit transformations to SI units
0077 CELER_ICRT meter = 100 * centimeter;
0078 CELER_ICRT kilogram = 1000 * gram;
0079 CELER_ICRT tesla = 10000 * gauss;
0080 //!@}
0081 
0082 //!@{
0083 //! \name Exact unit transformations using SI unit definitions
0084 CELER_ICRT newton = kilogram * meter / (second * second);
0085 CELER_ICRT joule = newton * meter;
0086 CELER_ICRT coulomb = kilogram / (tesla * second);
0087 CELER_ICRT ampere = coulomb / second;
0088 CELER_ICRT volt = joule / coulomb;
0089 CELER_ICRT farad = coulomb / volt;
0090 //!@}
0091 
0092 //!@{
0093 //! \name CLHEP units
0094 CELER_ICRT millimeter = real_type(0.1) * centimeter;
0095 CELER_ICRT nanosecond = real_type(1e-9) * second;
0096 //!@}
0097 
0098 #elif CELERITAS_UNITS == CELERITAS_UNITS_SI
0099 //!@{
0100 //! \name Units with numerical value defined to be 1 for SI
0101 CELER_ICRT second = 1;  //!< Time
0102 CELER_ICRT meter = 1;  //!< Length
0103 CELER_ICRT kilogram = 1;  //!< Mass
0104 CELER_ICRT kelvin = 1;  //!< Temperature
0105 CELER_ICRT coulomb = 1;  //!< Charge
0106 //!@}
0107 
0108 //!@{
0109 //! \name Exact unit transformations using SI unit definitions
0110 CELER_ICRT newton = kilogram * meter / (second * second);
0111 CELER_ICRT joule = newton * meter;
0112 CELER_ICRT volt = joule / coulomb;
0113 CELER_ICRT tesla = volt * second / (meter * meter);
0114 CELER_ICRT ampere = coulomb / second;
0115 CELER_ICRT farad = coulomb / volt;
0116 //!@}
0117 
0118 //!@{
0119 //! \name CGS units
0120 CELER_ICRT gauss = real_type(1e-4) * tesla;
0121 CELER_ICRT centimeter = real_type(1e-2) * meter;
0122 CELER_ICRT gram = real_type(1e-3) * kilogram;
0123 //!@}
0124 
0125 //!@{
0126 //! \name CLHEP units
0127 CELER_ICRT millimeter = real_type(1e-3) * meter;
0128 CELER_ICRT nanosecond = real_type(1e-9) * second;
0129 //!@}
0130 
0131 #elif CELERITAS_UNITS == CELERITAS_UNITS_CLHEP
0132 
0133 //!@{
0134 //! \name Units with numerical value defined to be 1 for CLHEP
0135 CELER_ICRT millimeter = 1;  //!< Length
0136 CELER_ICRT megaelectronvolt = 1;  //!< Energy
0137 CELER_ICRT nanosecond = 1;  //!< Time
0138 CELER_ICRT e_electron = 1;  //!< Charge
0139 CELER_ICRT kelvin = 1;  //!< Temperature
0140 //!@}
0141 
0142 CELER_ICRT coulomb = e_electron / 1.602176634e-19;  //! Value from SI 2019
0143 CELER_ICRT volt = real_type(1e-6) * (megaelectronvolt / e_electron);
0144 CELER_ICRT joule = coulomb * volt;
0145 
0146 CELER_ICRT second = real_type(1e9) * nanosecond;
0147 CELER_ICRT meter = 1000 * millimeter;
0148 
0149 CELER_ICRT ampere = coulomb / second;
0150 CELER_ICRT farad = coulomb / volt;
0151 CELER_ICRT kilogram = joule * (second / meter) * (second / meter);
0152 CELER_ICRT tesla = volt * second / (meter * meter);
0153 CELER_ICRT newton = joule / meter;
0154 
0155 //!@{
0156 //! \name CGS-specific units
0157 CELER_ICRT centimeter = real_type(10) * millimeter;
0158 CELER_ICRT gram = real_type(1e-3) * kilogram;
0159 CELER_ICRT gauss = real_type(1e-4) * tesla;
0160 //!@}
0161 
0162 #endif
0163 
0164 //!@{
0165 //! \name Other common units
0166 CELER_ICRT micrometer = real_type(1e-4) * centimeter;
0167 CELER_ICRT nanometer = real_type(1e-7) * centimeter;
0168 CELER_ICRT femtometer = real_type(1e-13) * centimeter;
0169 CELER_ICRT barn = real_type(1e-24) * centimeter * centimeter;
0170 //!@}
0171 
0172 #undef CELER_ICRT
0173 
0174 //---------------------------------------------------------------------------//
0175 }  // namespace units
0176 }  // namespace celeritas