BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Units.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Base/Const/Units.h
6 //! @brief Defines some unit conversion factors and other constants in namespace Units.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_BASE_CONST_UNITS_H
16 #define BORNAGAIN_BASE_CONST_UNITS_H
17 
18 //! Constants and functions for physical unit conversions.
19 //!
20 //! In user code, quantities that have a physical dimension should always
21 //! be given in the form _value * unit_, e.g. 0.529 * angstrom for a length,
22 //! or 45 * deg for an angle.
23 //!
24 //! Internally, BornAgain has length, angle, magnetic field units of nanometer,
25 //! radians, Tesla. Therefore, in principle, the multipliers nm, rad, tesla could
26 //! be ommited from code. However, to make code more readable, and to prevent
27 //! misunderstandings, we recommend that physical dimension be always made clear
28 //! by multiplying values with an appropriate constant, even if this expands to 1.
29 
30 namespace Units {
31 
32 // Length
33 static constexpr double nanometer = 1.; //!< Internal unit for lengths
34 static constexpr double angstrom = 1.e-1 * nanometer;
35 static constexpr double micrometer = 1.e+3 * nanometer;
36 static constexpr double millimeter = 1.e+6 * nanometer;
37 
38 // Symbols for length
39 static constexpr double nm = nanometer;
40 
41 // Area (cross-section)
42 static constexpr double nm2 = nanometer * nanometer;
43 
44 // Angle
45 static constexpr double rad = 1.; //!< Radian, internal unit for angles
46 static constexpr double deg = (3.1415926535897932 / 180.0) * rad;
47 
48 // Magnetic field
49 static constexpr double tesla = 1.; //!< Internal unit for magnetic fields
50 static constexpr double gauss = 1e-4;
51 
52 // Converters
53 
54 #ifndef SWIG
55 inline double rad2deg(double angle)
56 {
57  return angle / deg;
58 }
59 inline double deg2rad(double angle)
60 {
61  return angle * deg;
62 }
63 #endif // USER_API
64 
65 } // namespace Units
66 
67 #endif // BORNAGAIN_BASE_CONST_UNITS_H
Constants and functions for physical unit conversions.
Definition: Units.h:30
static constexpr double rad
Radian, internal unit for angles.
Definition: Units.h:45
double deg2rad(double angle)
Definition: Units.h:59
static constexpr double deg
Definition: Units.h:46
static constexpr double micrometer
Definition: Units.h:35
static constexpr double nm
Definition: Units.h:39
static constexpr double gauss
Definition: Units.h:50
static constexpr double nm2
Definition: Units.h:42
static constexpr double millimeter
Definition: Units.h:36
double rad2deg(double angle)
Definition: Units.h:55
static constexpr double angstrom
Definition: Units.h:34
static constexpr double nanometer
Internal unit for lengths.
Definition: Units.h:33
static constexpr double tesla
Internal unit for magnetic fields.
Definition: Units.h:49