AFLOW
 
Loading...
Searching...
No Matches
aurostd_defs.h
Go to the documentation of this file.
1
2
3#ifndef AUROSTD_DEFS_H
4#define AUROSTD_DEFS_H
5
6#include <cstdio>
7#include <limits>
8#include <string>
9
10#ifndef SWAP
11#define SWAP(a, b) \
12 { \
13 temp = (a); \
14 (a) = (b); \
15 (b) = temp; \
16 }
17#endif
18
19#ifndef NNN
20#define NNN -123456
21#endif
22
23#ifndef AUROSTD_NAN
24#define AUROSTD_NAN 1E9
25#endif
26
27#ifndef AUROSTD_DEFAULT_PRECISION
28#define AUROSTD_DEFAULT_PRECISION 20
29#endif
30
31// CO20171215 - more global control
32// this is for PRINTING, not for algorithmic zeroing
33#ifndef AUROSTD_ROUNDOFF_TOL
34#define AUROSTD_ROUNDOFF_TOL 1e-6
35#endif
36
37// CO20171215 - more global control
38// this is SMALLER than _ZERO_TOL_ in aflow.h
39//(aurostd default is less conservative to match read/write roundoff error)
40#ifndef AUROSTD_IDENTITY_TOL
41#define AUROSTD_IDENTITY_TOL 1e-6
42#endif
43
44// CO20171002 - USEFUL!
45#ifndef AUROSTD_MAX_INT
46#define AUROSTD_MAX_INT std::numeric_limits<int>::max()
47#endif
48
49// CO20171002 - USEFUL!
50#ifndef AUROSTD_MAX_UINT
51#define AUROSTD_MAX_UINT std::numeric_limits<uint>::max()
52#endif
53
54// CO20171002 - USEFUL!
55#ifndef AUROSTD_MAX_ULLINT
56#define AUROSTD_MAX_ULLINT std::numeric_limits<unsigned long long int>::max()
57#endif
58
59// CO20171002 - USEFUL!
60#ifndef AUROSTD_MAX_DOUBLE
61#define AUROSTD_MAX_DOUBLE std::numeric_limits<double>::max()
62#endif
63
64// SD20220914
65#ifndef AUROSTD_MAX_SIZET
66#define AUROSTD_MAX_SIZET std::numeric_limits<size_t>::max()
67#endif
68
69// CO20180101 - stream2stream modes
70#ifndef DEFAULT_STREAM
71#define DEFAULT_STREAM 'D'
72#endif
73#ifndef FIXED_STREAM
74#define FIXED_STREAM 'F'
75#endif
76#ifndef SCIENTIFIC_STREAM
77#define SCIENTIFIC_STREAM 'S'
78#endif
79
80#ifndef __STRICT_ANSI__
81#define __STRICT_ANSI__
82#endif
83
84#define _AUROSTD_XLIBS_ERROR_ std::string("ERROR - AUROSTD_XLIBS++ [***]:")
85#define _AUROSTD_XLIBS_WARNING_ std::string("WARNING - AUROSTD_XLIBS++ [***]:")
86
87#define EMPTY_WORDING std::string("blablabla")
88
89// CO20200624 START - adding from Jahnatek
90// http://ascii-table.com/ansi-escape-sequences.php
91// http://ascii-table.com/ansi-escape-sequences-vt-100.php
92#define cursor_moveyx(y, x, fstr) std::fprintf(fstr, "\033[%d;%dH", y, x) // Move cursor to position y,x (rows, columns) with (1,1) as origin
93#define cursor_moveup(y, fstr) std::fprintf(fstr, "\033[%dA", y) // Move cursor up y
94#define cursor_movedown(y, fstr) std::fprintf(fstr, "\033[%dB", y) // Move cursor down y
95#define cursor_moveright(x, fstr) std::fprintf(fstr, "\033[%dC", x) // Move cursor right x
96#define cursor_moveleft(x, fstr) std::fprintf(fstr, "\033[%dD", x) // Move cursor left x
97#define cursor_store(fstr) std::fprintf(fstr, "\033[s") // Store current cursor position and color
98#define cursor_restore(fstr) std::fprintf(fstr, "\033[u") // Restore cursor position and color from cursor_store()
99#define cursor_clear(fstr) std::fprintf(fstr, "\033[2J") // Clear screen and leave cursor where is
100#define cursor_clearline(fstr) std::fprintf(fstr, "\033[K") // Clear to end of line and leave cursor where is
101#define cursor_fore_black(fstr) std::fprintf(fstr, "\033[30m") // Change foreground color to black
102#define cursor_fore_red(fstr) std::fprintf(fstr, "\033[31m") // Change foreground color to red
103#define cursor_fore_green(fstr) std::fprintf(fstr, "\033[32m") // Change foreground color to green
104#define cursor_fore_orange(fstr) std::fprintf(fstr, "\033[33m") // Change foreground color to orange
105#define cursor_fore_blue(fstr) std::fprintf(fstr, "\033[34m") // Change foreground color to blue
106#define cursor_fore_magenta(fstr) std::fprintf(fstr, "\033[35m") // Change foreground color to magenta
107#define cursor_fore_cyan(fstr) std::fprintf(fstr, "\033[36m") // Change foreground color to cyan
108#define cursor_fore_yellow(fstr) std::fprintf(fstr, "\033[33m\033[1m") // Change foreground color to yellow (add bold to help visibility)
109#define cursor_fore_white(fstr) std::fprintf(fstr, "\033[37m") // Change foreground color to white
110#define cursor_back_black(fstr) std::fprintf(fstr, "\033[40m") // Change background color to black
111#define cursor_back_red(fstr) std::fprintf(fstr, "\033[41m") // Change background color to red
112#define cursor_back_green(fstr) std::fprintf(fstr, "\033[42m") // Change background color to green
113#define cursor_back_orange(fstr) std::fprintf(fstr, "\033[43m") // Change background color to orange
114#define cursor_back_blue(fstr) std::fprintf(fstr, "\033[44m") // Change background color to blue
115#define cursor_back_magenta(fstr) std::fprintf(fstr, "\033[45m") // Change background color to magenta
116#define cursor_back_cyan(fstr) std::fprintf(fstr, "\033[46m") // Change background color to cyan
117#define cursor_back_white(fstr) std::fprintf(fstr, "\033[47m") // Change background color to white
118#define cursor_attr_none(fstr) std::fprintf(fstr, "\033[0m") // Turn off all cursor attributes
119#define cursor_attr_bold(fstr) std::fprintf(fstr, "\033[1m") // Make test bold
120#define cursor_attr_underline(fstr) std::fprintf(fstr, "\033[4m") // Underline text
121#define cursor_attr_blink(fstr) std::fprintf(fstr, "\033[5m") // Supposed to make text blink, usually bolds it instead
122#define cursor_attr_reverse(fstr) std::fprintf(fstr, "\033[7m") // Swap background and foreground colors
123// CO20200624 END - adding from Jahnatek
124
125#define AUROSTD_ZIP_BIN "xz"
126#define AUROSTD_ZIP_EXT ".xz"
127
128#define __GNU_CPP
129#ifndef __xprototype
130#ifdef GNU
131#define __xprototype __attribute__((const))
132#else
133#define __xprototype
134#endif
135#endif
136
137#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) // CO20200502 - moved from aflow.h
138
139// CO20200502 START - including gettid()
140#ifdef __GLIBC__
141#define GLIBC_VERSION (__GLIBC__ * 100 + __GLIBC_MINOR__)
142#if (GLIBC_VERSION < 230) // CO20200502 - apparently they patched at 230 - https://stackoverflow.com/questions/30680550/c-gettid-was-not-declared-in-this-scope
143//[CO20200502 - too many warnings]#warning "defining getid() with syscall(SYS_gettid)"
144#include <sys/syscall.h> //CO20200502 - need for gettid()
145#define gettid() syscall(SYS_gettid)
146#endif // GLIBC_VERSION
147#endif //__GLIBC__
148// CO20200502 END - including gettid()
149
150#ifndef __xprototype
151#define __xprototype __attribute__((const))
152#endif
153
154// ----------------------------------------------------------------------------
155// ---------------------------------------------------------- physics constants
156
157#define rad2deg (180.0 / 3.14159265358979323846)
158#define deg2rad (3.14159265358979323846 / 180.0)
159#define angstrom2bohr (1 / 0.529177249)
160#define bohr2angstrom (0.529177249)
161
162// ME20181020 - check out https://physics.nist.gov/cuu/Constants/index.html
163// #define PI 3.14159265359
164#define PI 3.14159265358979323846
165#define pi PI
166#define TWOPI 6.28318530717958647692
167#define EULERSNUMBER 2.71828182845904523536
168#define RTPI (sqrt(PI))
169#define C_VACUUM 2.99792458E+8 // m/s
170#define EPS_VACUUM 8.854187817E-12 // C/(N-m2)
171#define MU_VACUUM (4.0 * PI * 1.0E-7) // N/A^2 (T^2m^3/J)
172#define AMU2KILOGRAM 1.66054E-27
173#define KILOGRAM2AMU 6.022137E+26
174#define E_ELECTRON 1.60217662E-19 // C
175#define eV2J E_ELECTRON // 1eV=E_ELECTRON J //CO20201111
176#define J2eV (1.0 / E_ELECTRON) // CO20201111
177#define PLANCKSCONSTANT_h 6.62607E-34 // J*s
178#define PLANCKSCONSTANT_hbar 1.0545718E-34 // J*s
179#define PLANCKSCONSTANTEV_h (PLANCKSCONSTANT_h / E_ELECTRON) // eV*s
180#define PLANCKSCONSTANTEV_hbar (PLANCKSCONSTANTEV_h / TWOPI) // eV*s
181#define KBOLTZ 1.3806504E-23 // J/K
182#define KBOLTZEV (KBOLTZ / E_ELECTRON) // eV/K //8.617343E-5
183#define eV2K (11604.505) // 1eV=11604.505 K
184#define meV2K (11.604505) // 1meV=11.604505 K
185#define mol2atom 6.0221408E23 // 1mol=6.022e23 atoms //CO20180329
186#define atom2mol (1.0 / 6.0221408E23) // CO20201111
187#define eVatom2kJmol (E_ELECTRON * mol2atom / 1.0e3) // 1eV/atom=96.5kJ/mol //CO20180329
188#define meVatom2kJmol (eVatom2kJmol / 1.0e3) // 1meV/atom=0.0965kJ/mol //CO20180329
189#define hartree2eV 27.2113862459 // 1hartree=27.211eV //ME20200206
190#define eV2hartree (1.0 / hartree2eV) // 1eV=0.0367hartree //SD20230919
191#define kcal2eV 4.336443203200000E-002 // 1(kcal/mol) = 4.33644E-2 eV
192#define eV2kcal (1.0 / kcal2eV)
193
194// ME20200107 - (A)APL conversion factors
195#define THz2Hz 1E12
196#define Hz2THz (1.0 / THz2Hz)
197#define au2Hz aurostd::sqrt(E_ELECTRON * 1E20 / AMU2KILOGRAM) // eV/(A^2 amu) -> Hz
198#define au2rcm (au2Hz / (100 * C_VACUUM)) // eV/(A^2 amu) -> cm^-1
199#define au2eV (au2Hz * PLANCKSCONSTANTEV_h) // eV/(A^2 amu) -> eV
200#define eV2Hz (1.0 / PLANCKSCONSTANTEV_h)
201#define eV2rcm (1.0 / (PLANCKSCONSTANTEV_h * 100 * C_VACUUM))
202#define au2nmTHz ((E_ELECTRON * Hz2THz * Hz2THz * 1E18) / (0.1 * AMU2KILOGRAM)) // eV/(A amu) -> nm * THz^2
203#define PLANCKSCONSTANT_h_THz (PLANCKSCONSTANT_h * THz2Hz) // J/THz
204#define PLANCKSCONSTANT_hbar_THz (PLANCKSCONSTANT_hbar * THz2Hz) // J/THz
205#define PLANCKSCONSTANTAMU_hbar_THz (PLANCKSCONSTANTEV_hbar * THz2Hz * (10 * au2nmTHz)) // amu A^2 THz
206#define BEfactor_hbar_THz (PLANCKSCONSTANTEV_hbar / (KBOLTZEV * Hz2THz)) // hbar/kB in K/THz
207#define BEfactor_h_THz (PLANCKSCONSTANTEV_h / (KBOLTZEV * Hz2THz)) // h/kB in K/THz
208
209// AS20200427 - QHA-related conversion factors
210#define eV2GPa (E_ELECTRON * 1e21) // [eV/A^3] --> [GPa]
211#define GPa2eV (1.0 / eV2GPa) // [GPa] --> [eV/A^3]
212#define eV2kBar (eV2GPa * 10) // [eV/A^3] --> [kBar]
213#define kBar2eV (1.0 / eV2kBar) // [kBar] --> [eV/A^3]
214#define kBar2GPa 0.1 // [kBar] --> [GPa]
215#define atm2Pa 101325
216
217// DX20210111 - GFA factors
218#define TEMPERATURE_ROOM 300.0 // K
219#define kBT_ROOM (KBOLTZEV * TEMPERATURE_ROOM) // 0.025
220
221#define LIBRARY_NOTHING 256
222
223#define LIBRARY_ALL 100
224
225#define _LOCK_LINK_SUFFIX_ std::string(".init")
226
227// ZERO PRECISION DEFINITIONS - TIGHT (DEFAULT) AND LOOSE
228#define _AUROSTD_ZERO_PRECISION_ 10
229#define _AUROSTD_ZERO_TOL_ std::pow(10, -_AUROSTD_ZERO_PRECISION_) // DX
230#define _AUROSTD_ZERO_PRECISION_LOOSE_ 3
231#define _AUROSTD_ZERO_TOL_LOOSE_ std::pow(10, -_AUROSTD_ZERO_PRECISION_LOOSE_) // DX
232#define _AUROSTD_DOUBLE_PRECISION_ 8
233#define _AUROSTD_DOUBLE_TOL_ std::pow(10, -_AUROSTD_DOUBLE_PRECISION_)
234#define _AUROSTD_FLOAT_PRECISION_ 6
235#define _AUROSTD_FLOAT_TOL_ std::pow(10, -_AUROSTD_FLOAT_PRECISION_) // ME20200519 - tolerance for float precision
236
237#endif // AUROSTD_DEFS_H