SYCL: Avoid using no_init read accessor in rocFFT
[alexxy/gromacs.git] / api / legacy / include / gromacs / math / units.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team.
6  * Copyright (c) 2012,2014,2015,2018,2019, The GROMACS development team.
7  * Copyright (c) 2020,2021, by the GROMACS development team, led by
8  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9  * and including many others, as listed in the AUTHORS file in the
10  * top-level source directory and at http://www.gromacs.org.
11  *
12  * GROMACS is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public License
14  * as published by the Free Software Foundation; either version 2.1
15  * of the License, or (at your option) any later version.
16  *
17  * GROMACS is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with GROMACS; if not, see
24  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
26  *
27  * If you want to redistribute modifications to GROMACS, please
28  * consider that scientific software is very special. Version
29  * control is crucial - bugs must be traceable. We will be happy to
30  * consider code for inclusion in the official distribution, but
31  * derived work must not be called official GROMACS. Details are found
32  * in the README & COPYING files - if they are missing, get the
33  * official version at http://www.gromacs.org.
34  *
35  * To help us fund GROMACS development, we humbly ask that you cite
36  * the research papers on the package. Check out http://www.gromacs.org.
37  */
38 #ifndef GMX_MATH_UNITS_H
39 #define GMX_MATH_UNITS_H
40
41 #include <cmath>
42
43 /*
44  * Physical constants to be used in Gromacs.
45  * No constants (apart from 0, 1 or 2) should
46  * be anywhere else in the code.
47  */
48
49 #ifndef M_PI
50 #    define M_PI 3.14159265358979323846
51 #endif
52
53 #ifndef M_PI_2
54 #    define M_PI_2 1.57079632679489661923
55 #endif
56
57 #ifndef M_2PI
58 #    define M_2PI 6.28318530717958647692
59 #endif
60
61 #ifndef M_SQRT2
62 #    define M_SQRT2 sqrt(2.0)
63 #endif
64
65 #ifndef M_1_PI
66 #    define M_1_PI 0.31830988618379067154
67 #endif
68
69 #ifndef M_FLOAT_1_SQRTPI /* used in GPU kernels */
70 /* 1.0 / sqrt(M_PI) */
71 #    define M_FLOAT_1_SQRTPI 0.564189583547756f
72 #endif
73
74 #ifndef M_1_SQRTPI
75 /* 1.0 / sqrt(M_PI) */
76 #    define M_1_SQRTPI 0.564189583547756
77 #endif
78
79 #ifndef M_2_SQRTPI
80 /* 2.0 / sqrt(M_PI) */
81 #    define M_2_SQRTPI 1.128379167095513
82 #endif
83
84 namespace gmx
85 {
86
87 constexpr double c_angstrom       = 1e-10;
88 constexpr double c_kilo           = 1e3;
89 constexpr double c_nano           = 1e-9;
90 constexpr double c_pico           = 1e-12;
91 constexpr double c_nm2A           = c_nano / c_angstrom;
92 constexpr double c_cal2Joule      = 4.184;           /* Exact definition of the calorie */
93 constexpr double c_electronCharge = 1.602176634e-19; /* Exact definition, Coulomb NIST 2018 CODATA */
94
95 constexpr double c_amu       = 1.66053906660e-27; /* kg, NIST 2018 CODATA  */
96 constexpr double c_boltzmann = 1.380649e-23;      /* (J/K, Exact definition, NIST 2018 CODATA */
97 constexpr double c_avogadro  = 6.02214076e23;     /* 1/mol, Exact definition, NIST 2018 CODATA */
98 constexpr double c_universalGasConstant = c_boltzmann * c_avogadro;        /* (J/(mol K))  */
99 constexpr double c_boltz                = c_universalGasConstant / c_kilo; /* (kJ/(mol K)) */
100 constexpr double c_faraday              = c_electronCharge * c_avogadro;   /* (C/mol)      */
101 constexpr double c_planck1 = 6.62607015e-34; /* J/Hz, Exact definition, NIST 2018 CODATA */
102 constexpr double c_planck  = (c_planck1 * c_avogadro / (c_pico * c_kilo)); /* (kJ/mol) ps */
103
104 constexpr double c_epsilon0Si = 8.8541878128e-12; /* F/m,  NIST 2018 CODATA */
105 /* Epsilon in our MD units: (e^2 / Na (kJ nm)) == (e^2 mol/(kJ nm)) */
106 constexpr double c_epsilon0 =
107         ((c_epsilon0Si * c_nano * c_kilo) / (c_electronCharge * c_electronCharge * c_avogadro));
108
109 constexpr double c_speedOfLight =
110         2.99792458e05; /* units of nm/ps, Exact definition, NIST 2018 CODATA */
111
112 constexpr double c_rydberg = 1.0973731568160e-02; /* nm^-1, NIST 2018 CODATA */
113
114 constexpr double c_one4PiEps0 = (1.0 / (4.0 * M_PI * c_epsilon0));
115
116 /* Pressure in MD units is:
117  * 1 bar = 1e5 Pa = 1e5 kg m^-1 s^-2 = 1e-28 kg nm^-1 ps^-2 = 1e-28 / amu amu nm^1 ps ^2
118  */
119 constexpr double c_barMdunits = (1e5 * c_nano * c_pico * c_pico / c_amu);
120 constexpr double c_presfac    = 1.0 / c_barMdunits;
121
122 /* c_debye2Enm should be (1e-21*c_pico)/(c_speedOfLight*c_electronCharge*c_nano*c_nano),
123  * but we need to factor out some of the exponents to avoid single-precision overflows.
124  */
125 constexpr double c_debye2Enm = (1e-15 / (c_speedOfLight * c_electronCharge));
126 constexpr double c_enm2Debye = 1.0 / c_debye2Enm;
127
128 /* to convert from a acceleration in (e V)/(amu nm) */
129 /* c_fieldfac is also Faraday's constant and c_electronCharge/(1e6 amu) */
130 constexpr double c_fieldfac = c_faraday / c_kilo;
131
132 /* to convert AU to MD units: */
133 constexpr double c_hartree2Kj     = ((2.0 * c_rydberg * c_planck * c_speedOfLight) / c_avogadro);
134 constexpr double c_bohr2Nm        = 0.0529177210903; /* nm^-1, NIST 2018 CODATA */
135 constexpr double c_hartreeBohr2Md = (c_hartree2Kj * c_avogadro / c_bohr2Nm);
136
137 constexpr double c_rad2Deg = 180.0 / M_PI;
138 constexpr double c_deg2Rad = M_PI / 180.0;
139 } // namespace gmx
140
141 /* The four basic units */
142 #define unit_length "nm"
143 #define unit_time "ps"
144 #define unit_mass "u"
145 #define unit_energy "kJ/mol"
146
147 /* Temperature unit, T in this unit times c_boltz give energy in unit_energy */
148 #define unit_temp_K "K"
149
150 /* Charge unit, electron charge, involves c_one4PiEps0 */
151 #define unit_charge_e "e"
152
153 /* Pressure unit, pressure in basic units times c_presfac gives this unit */
154 #define unit_pres_bar "bar"
155
156 /* Dipole unit, debye, conversion from the unit_charge_e involves c_enm2Debye */
157 #define unit_dipole_D "D"
158
159 /* Derived units from basic units only */
160 #define unit_vel unit_length "/" unit_time
161 #define unit_volume unit_length "^3"
162 #define unit_invtime "1/" unit_time
163
164 /* Other derived units */
165 #define unit_surft_bar unit_pres_bar " " unit_length
166
167 /* SI units, conversion from basic units involves c_nano, c_pico and amu */
168 #define unit_length_SI "m"
169 #define unit_time_SI "s"
170 #define unit_mass_SI "kg"
171
172 #define unit_density_SI unit_mass_SI "/" unit_length_SI "^3"
173 #define unit_invvisc_SI unit_length_SI " " unit_time_SI "/" unit_mass_SI
174
175 #endif