ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_NumericalConstants.H
Go to the documentation of this file.
1 /*! @file ERF_NumericalConstants.H
2  * \brief Dimensionless numeric literals and pure mathematical constants.
3  *
4  * Nothing in this file is physics. These are spelling aids that let the code
5  * write `myhalf` instead of `amrex::Real(0.5)` and so stay precision-agnostic
6  * between double and single (AMREX_USE_FLOAT) builds, plus the mathematical
7  * constant pi and the two combinations of it that recur often enough to be
8  * worth naming.
9  *
10  * GPU note: these are host constexpr variables, so device code may use their
11  * *value* freely but must never odr-use them (bind a reference to one or take
12  * its address). In particular, do not pass a bare constant to std::min/std::max
13  * or amrex::min/amrex::max -- those take const T&, and nvcc then reports
14  * 'identifier "zero" is undefined in device code'. Write amrex::Real(zero)
15  * instead, which passes a temporary and costs nothing.
16  *
17  * Kept separate from ERF_Constants.H so that a file needing only numeric
18  * literals does not have to pull in the thermodynamic constants, and so that
19  * ERF_Constants.H reads as a list of physical constants. ERF_Constants.H
20  * includes this header, so every existing consumer keeps compiling unchanged.
21  */
22 
23 #ifndef ERF_NUMERICAL_CONSTANTS_H_
24 #define ERF_NUMERICAL_CONSTANTS_H_
25 
26 #include <limits>
27 
28 #include <AMReX_REAL.H>
29 
30 //! Roundoff floor of the working precision: 2.22e-16 in a double build, 1.19e-07
31 //! under AMREX_USE_FLOAT. Write a tolerance as a multiple of this rather than as
32 //! a hard-wired literal such as amrex::Real(1.e-16), which in a single-precision
33 //! build sits far below the noise floor and so never fires.
35 
36 constexpr amrex::Real zero = amrex::Real(0.0);
37 constexpr amrex::Real one = amrex::Real(1.0);
38 constexpr amrex::Real two = amrex::Real(2.0);
39 constexpr amrex::Real three = amrex::Real(3.0);
40 constexpr amrex::Real four = amrex::Real(4.0);
41 constexpr amrex::Real myhalf = amrex::Real(0.5);
42 constexpr amrex::Real fourth = amrex::Real(0.25);
43 constexpr amrex::Real third = amrex::Real(1.0/3.0);
44 constexpr amrex::Real eightthirds = amrex::Real(8.0/3.0);
45 
46 constexpr amrex::Real PI = amrex::Real(3.14159265358979323846264338327950288);
47 constexpr amrex::Real PIoTwo = PI/two;
49 
50 #endif
constexpr amrex::Real three
Definition: ERF_NumericalConstants.H:39
constexpr amrex::Real four
Definition: ERF_NumericalConstants.H:40
constexpr amrex::Real real_eps
Definition: ERF_NumericalConstants.H:34
constexpr amrex::Real two
Definition: ERF_NumericalConstants.H:38
constexpr amrex::Real eightthirds
Definition: ERF_NumericalConstants.H:44
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real fourth
Definition: ERF_NumericalConstants.H:42
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
constexpr amrex::Real PI
Definition: ERF_NumericalConstants.H:46
constexpr amrex::Real PIoTwo
Definition: ERF_NumericalConstants.H:47
constexpr amrex::Real third
Definition: ERF_NumericalConstants.H:43
constexpr amrex::Real four_thirds_pi
Definition: ERF_NumericalConstants.H:48
amrex::Real Real
Definition: ERF_ShocInterface.H:19
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12