constants.hh 2.62 KB
Newer Older
1
2
3
4
5
6
7
8
/*
 * File:   constants.hh
 * Author: Jordan P. Lefebvre
 *
 * Created on August 13, 2012, 8:26 PM
 */

#ifndef RADIX_RADIXMATH_CONSTANTS_H
9
#define RADIX_RADIXMATH_CONSTANTS_H
10
11
#include <cmath>
#include <limits>
12
13

#include "radixdl/visibility.hh"
14
15
namespace radix
{
16
17
18
19
20
21
/**
 * Type def double precision
 */
typedef unsigned short index_t;
typedef double Real;
const Real EARTH_RADIUS_MEAN = 6371200.0;
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const Real wgs84_minor       = 6356752.314245;
const Real kEpsilon          = 1.0E-12;
const Real lookAheadEpsilon  = 1.0E-9;
const Real halfKEpsilon      = 0.5 * kEpsilon;
const Real kHugeValue        = 1.0E10;
const Real maxReal           = std::numeric_limits<Real>::max();
const Real minReal           = std::numeric_limits<Real>::min();
const Real PI               = 2 * std::acos(Real(0));  // 3.1415926535897932384;
const Real TWO_PI           = PI * 2;                  // 6.2831853071795864769;
const Real PI_BELOW_180     = 180 / PI;
const Real PI_ON_180        = PI / 180;    // 0.0174532925199432957;
const Real invPI            = 1 / PI;      // 0.3183098861837906715;
const Real invTWO_PI        = 1 / TWO_PI;  // 0.1591549430918953358;
const Real infinity         = std::numeric_limits<Real>::infinity();
const Real sqrtHALF         = std::sqrt(Real(0.5));
const Real sqrtTWO          = std::sqrt(Real(2.0));
const Real sqrtTHREE        = std::sqrt(Real(3.0));
const Real DAYS_PER_YEAR    = 365.25;
40
const Real SECONDS_PER_HOUR = 3600.0;
41
const Real METERS_PER_MILE  = 1609.344;
42
43
const Real ABS_ZERO_CELSIUS = -273.15;
const Real MASS_RATIO_WATER_VAPOR_DRY_AIR = 0.62198;
44
45
46
47
48
49
50
51
52

/**
 * @brief SPECIFIC_GAS_CONSTANT J K^-1 mol^-1
 */
const Real SPECIFIC_GAS_CONSTANT = 8.3144598;
/**
 * @brief GRAVITATIONAL_ACCELERATION m/s^2
 */
const Real GRAVITATIONAL_ACCELERATION = 9.80616;
53
54
55
56
57
58
59
60
61

/**
 * @brief MOLAR_MASS_DRY_AIR kg/mol
 */
const Real MOLAR_MASS_DRY_AIR = 0.028964;
/**
 * @brief MOLAR_MASS_WATER_VAPER kg/mol
 */
const Real MOLAR_MASS_WATER_VAPER = 0.018016;
62
63
64
65
/**
 * Type def unsigned long to Identifier
 */
typedef unsigned long Identifier;
66

67
68
69
70
71
72
73
/**
 * @function clamp
 * @param x 1d point in space
 * @param min
 * @param max
 * @return
 */
74
75
inline Real RADIX_PUBLIC clamp(const Real x, const Real min, const Real max)
{
76
  return (x < min ? min : (x > max ? max : x));
77
}
78
79
inline bool RADIX_PUBLIC isWithin(Real x, Real y, Real within = kEpsilon)
{
80
  return std::abs(x - y) <= within;
81
82
83
84
85
86
87
}
/**
 * Determine if the two values are within kepsilon of one-another
 * @param x
 * @param y
 * @return true, iff abs(x-y) <= kEpsilon
 */
88
89
inline bool RADIX_PUBLIC isWithinKEpsilon(Real x, Real y)
{
90
  return isWithin(x, y, kEpsilon);
91
}
92

93
94
}  // namespace radix
#endif /* RADIX_RADIXMATH_CONSTANTS_H */