//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Base/Const/Units.h
//! @brief     Defines some unit conversion factors and other constants in namespace Units.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#ifndef BORNAGAIN_BASE_CONST_UNITS_H
#define BORNAGAIN_BASE_CONST_UNITS_H

#include <numbers>

//! Constants and functions for physical unit conversions.
//!
//! In user code, quantities that have a physical dimension should always
//! be given in the form _value * unit_, e.g. 0.529 * angstrom for a length,
//! or 45 * deg for an angle.
//!
//! Internally, BornAgain has length, angle, magnetic field units of nanometer,
//! radians, Tesla. Therefore, in principle, the multipliers nm, rad, tesla could
//! be ommited from code. However, to make code more readable, and to prevent
//! misunderstandings, we recommend that physical dimension be always made clear
//! by multiplying values with an appropriate constant, even if this expands to 1.

namespace Units {

// Length
constexpr double nm = 1.; //!< Nanometer, internal unit for lengths
constexpr double angstrom = 1.e-1 * nm;
constexpr double micrometer = 1e3 * nm;
constexpr double millimeter = 1e6 * nm;

// Area (cross-section)
constexpr double nm2 = nm * nm;

// Volume
constexpr double nm3 = nm * nm * nm;

// Angle
constexpr double rad = 1.; //!< Radian, internal unit for angles
constexpr double deg = (std::numbers::pi / 180) * rad;

// Magnetic field
constexpr double tesla = 1.; //!< Internal unit for magnetic fields
constexpr double gauss = 1e-4;

// Converters

inline double rad2deg(double angle)
{
    return angle / deg;
}
inline double deg2rad(double angle)
{
    return angle * deg;
}

} // namespace Units

#endif // BORNAGAIN_BASE_CONST_UNITS_H
