ARTS 2.5.4 (git: 4c0d3b4d)
constants.h
Go to the documentation of this file.
1/* Copyright (C) 2019
2 * Richard Larsson <ric.larsson@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2, or (at your option) any
7 * later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 * USA. */
18
54#ifndef CONSTANTS_IN_ARTS_H
55#define CONSTANTS_IN_ARTS_H
56
57#include <cmath>
58
59#include "enums.h"
60#include "matpack.h"
61
63namespace Constant {
65template <class T>
66constexpr auto pow2(T x) noexcept -> decltype(x * x) {
67 return x * x;
68}
69
71template <class T>
72constexpr auto pow3(T x) noexcept -> decltype(pow2(x) * x) {
73 return pow2(x) * x;
74}
75
77template <class T>
78constexpr auto pow4(T x) noexcept -> decltype(pow2(pow2(x))) {
79 return pow2(pow2(x));
80}
81
113static constexpr Numeric pi =
114 3.141592653589793238462643383279502884197169399375105820974944592307816406286;
115
117static constexpr Numeric inv_pi =
118 0.3183098861837906715377675267450287240689192914809128974953346881177935952685;
119
121static constexpr Numeric two_pi =
122 6.283185307179586476925286766559005768394338798750211641949889184615632812572;
123
125static constexpr Numeric inv_two_pi =
126 0.1591549430918953357688837633725143620344596457404564487476673440588967976342;
127
129static constexpr Numeric sqrt_pi =
130 1.772453850905516027298167483341145182797549456122387128213807789852911284591;
131
133static constexpr Numeric inv_sqrt_pi =
134 0.5641895835477562869480794515607725858440506293289988568440857217106424684415;
135
137static constexpr Numeric euler =
138 2.718281828459045235360287471352662497757247093699959574966967627724076630354;
139
141static constexpr Numeric inv_euler =
142 0.3678794411714423215955237701614608674458111310317678345078368016974614957448;
143
145static constexpr Numeric log10_euler =
146 0.4342944819032518276511289189166050822943970058036665661144537831658646492089;
147
149static constexpr Numeric ln_10 =
150 2.302585092994045684017991454684364207601101488628772976033327900967572609677;
151
153static constexpr Numeric sqrt_2 =
154 1.414213562373095048801688724209698078569671875376948073176679737990732478462;
155
157static constexpr Numeric inv_sqrt_2 =
158 0.7071067811865475244008443621048490392848359376884740365883398689953662392311;
159
161static constexpr Numeric ln_2 =
162 0.6931471805599453094172321214581765680755001343602552541206800094933936219697;
163
165static constexpr Numeric inv_ln_2 =
166 1.442695040888963407359924681001892137426645954152985934135449406931109219181;
167
169static constexpr Numeric sqrt_ln_2 =
170 0.8325546111576977563531646448952010476305888522644407291668291172340794351973;
171
173static constexpr Numeric inv_sqrt_ln_2 =
174 1.201122408786449794857803286095221722566764028068699423868879896733837175546;
175
180static constexpr Numeric Delta_nu_Cs = 9192631770;
181
186static constexpr Numeric speed_of_light = 299792458;
187
189static constexpr Numeric c = speed_of_light;
190
195static constexpr Numeric planck_constant = 6.62607015e-34;
196
198static constexpr Numeric h = planck_constant;
199
201static constexpr Numeric reduced_planck_constant = h * inv_two_pi;
202
204static constexpr Numeric h_bar = reduced_planck_constant;
205
210static constexpr Numeric elementary_charge = 1.602176634e-19;
211
213static constexpr Numeric e = elementary_charge;
214
219static constexpr Numeric boltzmann_constant = 1.380649e-23;
220
222static constexpr Numeric k = boltzmann_constant;
223
228static constexpr Numeric avogadro_constant = 6.02214076e23;
229
231static constexpr Numeric NA = avogadro_constant;
232
237static constexpr Numeric K_cd = 683;
238
244static constexpr Numeric fine_structure_constant = 7.2973525693e-3;
245
247static constexpr Numeric alpha = fine_structure_constant;
248
254static constexpr Numeric rydberg_constant = 10973731.568160;
255
257static constexpr Numeric R_inf = rydberg_constant;
258
260static constexpr Numeric magnetic_constant = 2 * h * alpha / (c * pow2(e));
261
263static constexpr Numeric mu_0 = magnetic_constant;
264
266static constexpr Numeric vacuum_permittivity = pow2(e) / (2 * h * c * alpha);
267
269static constexpr Numeric epsilon_0 = vacuum_permittivity;
270
272static constexpr Numeric electron_mass = 2 * h * R_inf / (c * pow2(alpha));
273
275static constexpr Numeric m_e = electron_mass;
276
282static constexpr Numeric unified_atomic_mass_unit = 1.66053906660e-27;
283
285static constexpr Numeric m_u = unified_atomic_mass_unit;
286
292static constexpr Numeric mass_ratio_electrons_per_proton = 1'836.152'673'43;
293
295static constexpr Numeric proton_mass =
296 electron_mass * mass_ratio_electrons_per_proton;
297
303static constexpr Numeric mass_ratio_electrons_per_neutron = 1'838.683'661'73;
304
306static constexpr Numeric neutron_mass =
307 electron_mass * mass_ratio_electrons_per_neutron;
308
310static constexpr Numeric bohr_magneton = e * h_bar / (2 * m_e);
311
313static constexpr Numeric ideal_gas_constant = k * NA;
314
316static constexpr Numeric R = ideal_gas_constant;
317
319static constexpr Numeric doppler_broadening_const_squared = 2'000 * R / pow2(c);
320
322static constexpr Numeric one_degree_in_radians = pi / 180;
323}; // namespace Constant
324
326namespace Conversion {
327using namespace Constant;
328
330template <class T>
331constexpr auto deg2rad(T x) noexcept -> decltype(x * one_degree_in_radians) {
332 return x * one_degree_in_radians;
333}
334
336template <class T>
337constexpr auto rad2deg(T x) noexcept -> decltype(x / one_degree_in_radians) {
338 return x / one_degree_in_radians;
339}
340
342template <class T>
343auto cosd(T x) noexcept -> decltype(std::cos(deg2rad(x))) {
344 return std::cos(deg2rad(x));
345}
346
348template <class T>
349auto sind(T x) noexcept -> decltype(std::sin(deg2rad(x))) {
350 return std::sin(deg2rad(x));
351}
352
354template <class T>
355auto tand(T x) noexcept -> decltype(std::tan(deg2rad(x))) {
356 return std::tan(deg2rad(x));
357}
358
360template <class T>
361auto acosd(T x) noexcept -> decltype(rad2deg(std::acos(x))) {
362 return rad2deg(std::acos(x));
363}
364
366template <class T>
367auto asind(T x) noexcept -> decltype(rad2deg(std::asin(x))) {
368 return rad2deg(std::asin(x));
369}
370
372template <class T>
373auto atand(T x) noexcept -> decltype(rad2deg(std::atan(x))) {
374 return rad2deg(std::atan(x));
375}
376
378template <class T1, class T2>
379auto atan2d(T1 y, T2 x) noexcept -> decltype(rad2deg(std::atan2(y, x))) {
380 return rad2deg(std::atan2(y, x));
381}
382
384template <class T>
385constexpr auto kaycm2freq(T x) noexcept -> decltype(x * (100 * c)) {
386 return x * (100 * c);
387}
388
390template <class T>
391constexpr auto freq2kaycm(T x) noexcept -> decltype(x / (100 * c)) {
392 return x / (100 * c);
393}
394
396template <class T>
397constexpr auto angcm2freq(T x) noexcept -> decltype(kaycm2freq(inv_two_pi)) {
398 return x * kaycm2freq(inv_two_pi);
399}
400
402template <class T>
403constexpr auto freq2angcm(T x) noexcept
404 -> decltype(x / kaycm2freq(inv_two_pi)) {
405 return x / kaycm2freq(inv_two_pi);
406}
407
409template <class T>
410constexpr auto angfreq2freq(T x) noexcept -> decltype(x * inv_two_pi) {
411 return x * inv_two_pi;
412}
413
415template <class T>
416constexpr auto freq2angfreq(T x) noexcept -> decltype(x * two_pi) {
417 return x * two_pi;
418}
419
421template <class T>
422constexpr auto wavelen2freq(T x) noexcept -> decltype(c / x) {
423 return c / x;
424}
425
427template <class T>
428constexpr auto freq2wavelen(T x) noexcept -> decltype(c / x) {
429 return c / x;
430}
431
433template <class T>
434constexpr auto hz2ghz(T x) noexcept -> decltype(x * 1e-9) {
435 return x * 1e-9;
436}
437
439template <class T>
440constexpr auto ghz2hz(T x) noexcept -> decltype(x * 1e9) {
441 return x * 1e9;
442}
443
445template <class T>
446constexpr auto atm2pa(T x) noexcept -> decltype(x * 101'325.0) {
447 return x * 101'325.0;
448}
449
451template <class T>
452constexpr auto pa2atm(T x) noexcept -> decltype(x / 101'325.0) {
453 return x / 101'325.0;
454}
455
457template <class T>
458constexpr auto bar2pa(T x) noexcept -> decltype(x * 1e5) {
459 return x * 1e5;
460}
461
463template <class T>
464constexpr auto pa2bar(T x) noexcept -> decltype(x * 1e-5) {
465 return x * 1e-5;
466}
467
469template <class T>
470constexpr auto torr2pa(T x) noexcept -> decltype(x * atm2pa(1.0 / 760.0)) {
471 return x * atm2pa(1.0 / 760.0);
472}
473
475template <class T>
476constexpr auto pa2torr(T x) noexcept -> decltype(x / atm2pa(1.0 / 760.0)) {
477 return x / atm2pa(1.0 / 760.0);
478}
479
481template <class T>
482constexpr auto mhz_per_torr2hz_per_pa(T x) noexcept
483 -> decltype(x * pa2torr(1e6)) {
484 return x * pa2torr(1e6);
485}
486
488template <class T>
489constexpr auto celsius2kelvin(T x) noexcept -> decltype(x + 273.15) {
490 return x + 273.15;
491}
492
494template <class T>
495constexpr auto kelvin2celsius(T x) noexcept -> decltype(x - 273.15) {
496 return x - 273.15;
497}
498
500template <class T>
501constexpr auto kaycm_per_cmsquared2hz_per_msquared(T x) noexcept
502 -> decltype(x * kaycm2freq(1e-4)) {
503 return x * kaycm2freq(1e-4);
504}
505
507template <class T>
508constexpr auto hz_per_msquared2kaycm_per_cmsquared(T x) noexcept
509 -> decltype(x * freq2kaycm(1e4)) {
510 return x * freq2kaycm(1e4);
511}
512
514template <class T>
515constexpr auto kaycm_per_atm2hz_per_pa(T x) noexcept
516 -> decltype(x * kaycm2freq(pa2atm(1))) {
517 return x * kaycm2freq(pa2atm(1));
518}
519
521template <class T>
522constexpr auto hz_per_pa2kaycm_per_atm(T x) noexcept
523 -> decltype(x * freq2kaycm(atm2pa(1))) {
524 return x * freq2kaycm(atm2pa(1));
525}
526
528template <class T>
529constexpr auto kaycm2joule(T x) noexcept -> decltype(x * kaycm2freq(h)) {
530 return x * kaycm2freq(h);
531}
532
534template <class T>
535constexpr auto hz2joule(T x) noexcept -> decltype(x * h) {
536 return x * h;
537}
538
540template <class T>
541constexpr auto mhz2joule(T x) noexcept -> decltype(hz2joule(x) * 1e6) {
542 return hz2joule(x) * 1e6;
543}
544
546template <class T>
547constexpr auto kelvin2joule(T x) noexcept -> decltype(x * k) {
548 return x * k;
549}
550
552template <class T>
553constexpr auto joule2hz(T x) noexcept -> decltype(x / h) {
554 return x / h;
555}
556
558template <class T>
559constexpr auto joule2kaycm(T x) noexcept -> decltype(x / kaycm2freq(h)) {
560 return x / kaycm2freq(h);
561}
562
564template <class T>
565constexpr auto angstrom2meter(T x) noexcept -> decltype(x * 1e-10) {
566 return x * 1e-10;
567}
568
570template <class T>
571constexpr auto meter2angstrom(T x) noexcept -> decltype(x * 1e10) {
572 return x * 1e10;
573}
574}; // namespace Conversion
575
576namespace Options {
579 TimeStep, char, hour, hours, h, minute, minutes, min, second, seconds, s)
580
581
582ENUMCLASS(LineShapeCoeff, char, X0, X1, X2, X3)
583
584
585ENUMCLASS(WindMagJacobian, char, u, v, w, strength)
586
587
588ENUMCLASS(BasicCatParamJacobian, char, LineStrength, LineCenter)
589
590
592 HitranType,
593 char,
594 Pre2004, // 2004 version changed the .par-length
595 Post2004, // New par length
596 Online // Onine expects a modern .par line followed by Upper then Lower quantum numbers
597)
598
599
600ENUMCLASS(LblSpeedup, char, None, QuadraticIndependent, LinearIndependent)
601
602ENUMCLASS(SortingOption, char, ByFrequency, ByEinstein)
603} // namespace Options
604
605#endif
std::chrono::duration< Numeric > TimeStep
A duration of time, 1 full tick should be 1 second.
Definition: artstime.h:39
#define min(a, b)
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
Namespace containing several constants, physical and mathematical.
Definition: constants.h:63
constexpr auto pow2(T x) noexcept -> decltype(x *x)
power of two
Definition: constants.h:66
constexpr auto pow3(T x) noexcept -> decltype(pow2(x) *x)
power of three
Definition: constants.h:72
constexpr auto pow4(T x) noexcept -> decltype(pow2(pow2(x)))
power of four
Definition: constants.h:78
Namespace containing several practical unit conversions, physical and mathematical.
Definition: constants.h:326
constexpr auto hz2joule(T x) noexcept -> decltype(x *h)
Conversion from MHz to Joule.
Definition: constants.h:535
auto acosd(T x) noexcept -> decltype(rad2deg(std::acos(x)))
Returns rad2deg of the arc-cosine of the input.
Definition: constants.h:361
constexpr auto torr2pa(T x) noexcept -> decltype(x *atm2pa(1.0/760.0))
Conversion from Torr to Pa.
Definition: constants.h:470
constexpr auto freq2angcm(T x) noexcept -> decltype(x/kaycm2freq(inv_two_pi))
Conversion from Hz to Angular wavenumber.
Definition: constants.h:403
auto atand(T x) noexcept -> decltype(rad2deg(std::atan(x)))
Returns rad2deg of the arc-tangent of the input.
Definition: constants.h:373
constexpr auto atm2pa(T x) noexcept -> decltype(x *101 '325.0)
Conversion from Atm to Pa.
Definition: constants.h:446
constexpr auto kaycm_per_atm2hz_per_pa(T x) noexcept -> decltype(x *kaycm2freq(pa2atm(1)))
Conversion from cm-1 per atmosphere to Hz per Pascal.
Definition: constants.h:515
constexpr auto mhz_per_torr2hz_per_pa(T x) noexcept -> decltype(x *pa2torr(1e6))
Conversion from MHz/Torr to Hz/Pa.
Definition: constants.h:482
constexpr auto freq2wavelen(T x) noexcept -> decltype(c/x)
Conversion from Hz to wavelength.
Definition: constants.h:428
constexpr auto kelvin2celsius(T x) noexcept -> decltype(x - 273.15)
Conversion from K to C.
Definition: constants.h:495
constexpr auto ghz2hz(T x) noexcept -> decltype(x *1e9)
Conversion from Hz to wavelength.
Definition: constants.h:440
constexpr auto kaycm_per_cmsquared2hz_per_msquared(T x) noexcept -> decltype(x *kaycm2freq(1e-4))
Conversion from cm-1 per molecule per cm^2 to Hz per molecule per m^2.
Definition: constants.h:501
constexpr auto kaycm2freq(T x) noexcept -> decltype(x *(100 *c))
Conversion from Kayser wavenumber to Hz.
Definition: constants.h:385
constexpr auto pa2bar(T x) noexcept -> decltype(x *1e-5)
Conversion from Pa to bar.
Definition: constants.h:464
constexpr auto kaycm2joule(T x) noexcept -> decltype(x *kaycm2freq(h))
Conversion from cm-1 to Joule.
Definition: constants.h:529
auto sind(T x) noexcept -> decltype(std::sin(deg2rad(x)))
Returns the sine of the deg2rad of the input.
Definition: constants.h:349
constexpr auto meter2angstrom(T x) noexcept -> decltype(x *1e10)
Conversion from meter to Å
Definition: constants.h:571
constexpr auto pa2atm(T x) noexcept -> decltype(x/101 '325.0)
Conversion from Pa to Atm.
Definition: constants.h:452
constexpr auto angstrom2meter(T x) noexcept -> decltype(x *1e-10)
Conversion from Å to meter.
Definition: constants.h:565
auto tand(T x) noexcept -> decltype(std::tan(deg2rad(x)))
Returns the tangent of the deg2rad of the input.
Definition: constants.h:355
constexpr auto bar2pa(T x) noexcept -> decltype(x *1e5)
Conversion from bar to Pa.
Definition: constants.h:458
auto cosd(T x) noexcept -> decltype(std::cos(deg2rad(x)))
Returns the cosine of the deg2rad of the input.
Definition: constants.h:343
constexpr auto angfreq2freq(T x) noexcept -> decltype(x *inv_two_pi)
Conversion from Angular Hz to Hz.
Definition: constants.h:410
constexpr auto joule2hz(T x) noexcept -> decltype(x/h)
Conversion from Hz to Joule.
Definition: constants.h:553
constexpr auto hz_per_msquared2kaycm_per_cmsquared(T x) noexcept -> decltype(x *freq2kaycm(1e4))
Conversion from Hz per molecule per m^2 to cm-1 per molecule per cm^2.
Definition: constants.h:508
constexpr auto deg2rad(T x) noexcept -> decltype(x *one_degree_in_radians)
Converts degrees to radians.
Definition: constants.h:331
constexpr auto freq2kaycm(T x) noexcept -> decltype(x/(100 *c))
Conversion from Hz to Kayser wavenumber.
Definition: constants.h:391
constexpr auto mhz2joule(T x) noexcept -> decltype(hz2joule(x) *1e6)
Conversion from MHz to Joule.
Definition: constants.h:541
constexpr auto joule2kaycm(T x) noexcept -> decltype(x/kaycm2freq(h))
Conversion from Joule to cm-1.
Definition: constants.h:559
constexpr auto rad2deg(T x) noexcept -> decltype(x/one_degree_in_radians)
Converts radians to degrees.
Definition: constants.h:337
constexpr auto kelvin2joule(T x) noexcept -> decltype(x *k)
Conversion from Kelvin to Joule.
Definition: constants.h:547
constexpr auto celsius2kelvin(T x) noexcept -> decltype(x+273.15)
Conversion from C to K.
Definition: constants.h:489
constexpr auto wavelen2freq(T x) noexcept -> decltype(c/x)
Conversion from wavelength to Hz.
Definition: constants.h:422
constexpr auto hz_per_pa2kaycm_per_atm(T x) noexcept -> decltype(x *freq2kaycm(atm2pa(1)))
Conversion from Hz per Pascal to cm-1 per atmosphere.
Definition: constants.h:522
constexpr auto hz2ghz(T x) noexcept -> decltype(x *1e-9)
Conversion from wavelength to Hz.
Definition: constants.h:434
auto atan2d(T1 y, T2 x) noexcept -> decltype(rad2deg(std::atan2(y, x)))
Returns rad2deg of the arc-tangent of inputs #T1/#T2
Definition: constants.h:379
constexpr auto freq2angfreq(T x) noexcept -> decltype(x *two_pi)
Conversion from Hz to Angular Hz.
Definition: constants.h:416
constexpr auto angcm2freq(T x) noexcept -> decltype(kaycm2freq(inv_two_pi))
Conversion from Angular wavenumber to Hz.
Definition: constants.h:397
constexpr auto pa2torr(T x) noexcept -> decltype(x/atm2pa(1.0/760.0))
Conversion from Pa to Torr.
Definition: constants.h:476
auto asind(T x) noexcept -> decltype(rad2deg(std::asin(x)))
Returns rad2deg of the arc-sine of the input.
Definition: constants.h:367
ENUMCLASS(TimeStep, char, hour, hours, h, minute, minutes, min, second, seconds, s) ENUMCLASS(HitranType
Keep time options available to switch over them.
#define u
#define v
#define w
#define c