ARTS 2.5.9 (git: 825fa5f2)
arts_conversions.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
29#ifndef CONVERSIONS_IN_ARTS_H
30#define CONVERSIONS_IN_ARTS_H
31
32#include <cmath>
33
34#include "arts_constants.h"
35
37namespace Conversion {
38using namespace Constant;
39
41constexpr auto deg2rad(auto x) noexcept { return x * one_degree_in_radians; }
42
44constexpr auto rad2deg(auto x) noexcept { return x / one_degree_in_radians; }
45
47auto cosd(auto x) noexcept { return std::cos(deg2rad(x)); }
48
50auto sind(auto x) noexcept { return std::sin(deg2rad(x)); }
51
53auto tand(auto x) noexcept { return std::tan(deg2rad(x)); }
54
56auto acosd(auto x) noexcept { return rad2deg(std::acos(x)); }
57
59auto asind(auto x) noexcept { return rad2deg(std::asin(x)); }
60
62auto atand(auto x) noexcept { return rad2deg(std::atan(x)); }
63
65auto atan2d(auto y, auto x) noexcept { return rad2deg(std::atan2(y, x)); }
66
68constexpr auto kaycm2freq(auto x) noexcept { return x * (100 * c); }
69
71constexpr auto freq2kaycm(auto x) noexcept { return x / (100 * c); }
72
74constexpr auto angcm2freq(auto x) noexcept {
75 return x * kaycm2freq(inv_two_pi);
76}
77
79constexpr auto freq2angcm(auto x) noexcept {
80 return x / kaycm2freq(inv_two_pi);
81}
82
84constexpr auto angfreq2freq(auto x) noexcept { return x * inv_two_pi; }
85
87constexpr auto freq2angfreq(auto x) noexcept { return x * two_pi; }
88
90constexpr auto wavelen2freq(auto x) noexcept { return c / x; }
91
93constexpr auto freq2wavelen(auto x) noexcept { return c / x; }
94
96constexpr auto hz2ghz(auto x) noexcept { return x * 1e-9; }
97
99constexpr auto ghz2hz(auto x) noexcept { return x * 1e9; }
100
102constexpr auto atm2pa(auto x) noexcept { return x * 101'325.0; }
103
105constexpr auto pa2atm(auto x) noexcept { return x / 101'325.0; }
106
108constexpr auto bar2pa(auto x) noexcept { return x * 1e5; }
109
111constexpr auto pa2bar(auto x) noexcept { return x * 1e-5; }
112
114constexpr auto torr2pa(auto x) noexcept { return x * atm2pa(1.0 / 760.0); }
115
117constexpr auto pa2torr(auto x) noexcept { return x / atm2pa(1.0 / 760.0); }
118
120constexpr auto mhz_per_torr2hz_per_pa(auto x) noexcept {
121 return x * pa2torr(1e6);
122}
123
125constexpr auto celsius2kelvin(auto x) noexcept { return x + 273.15; }
126
128constexpr auto kelvin2celsius(auto x) noexcept { return x - 273.15; }
129
131constexpr auto kaycm_per_cmsquared2hz_per_msquared(auto x) noexcept {
132 return x * kaycm2freq(1e-4);
133}
134
136constexpr auto hz_per_msquared2kaycm_per_cmsquared(auto x) noexcept {
137 return x * freq2kaycm(1e4);
138}
139
141constexpr auto kaycm_per_atm2hz_per_pa(auto x) noexcept {
142 return x * kaycm2freq(pa2atm(1));
143}
144
146constexpr auto hz_per_pa2kaycm_per_atm(auto x) noexcept {
147 return x * freq2kaycm(atm2pa(1));
148}
149
151constexpr auto kaycm2joule(auto x) noexcept { return x * kaycm2freq(h); }
152
154constexpr auto hz2joule(auto x) noexcept { return x * h; }
155
157constexpr auto mhz2joule(auto x) noexcept { return hz2joule(x) * 1e6; }
158
160constexpr auto kelvin2joule(auto x) noexcept { return x * k; }
161
163constexpr auto joule2hz(auto x) noexcept { return x / h; }
164
166constexpr auto joule2kaycm(auto x) noexcept { return x / kaycm2freq(h); }
167
169constexpr auto angstrom2meter(auto x) noexcept { return x * 1e-10; }
170
172constexpr auto meter2angstrom(auto x) noexcept { return x * 1e10; }
173}; // namespace Conversion
174
175#endif
Constants of physical expressions as constexpr.
Namespace containing several constants, physical and mathematical.
constexpr Numeric one_degree_in_radians
One degree in radians.
constexpr Numeric inv_two_pi
Inverse of two pi.
constexpr Numeric two_pi
Two times pi.
constexpr Numeric k
Boltzmann constant convenience name [J/K].
constexpr Numeric c
Speed of light convenience name [m/s].
constexpr Numeric e
Elementary charge convenience name [C].
constexpr Numeric h
Planck constant convenience name [J s].
Namespace containing several practical unit conversions, physical and mathematical.
constexpr auto ghz2hz(auto x) noexcept
Conversion from Hz to wavelength.
auto tand(auto x) noexcept
Returns the tangent of the deg2rad of the input.
constexpr auto deg2rad(auto x) noexcept
Converts degrees to radians.
constexpr auto kelvin2joule(auto x) noexcept
Conversion from Kelvin to Joule.
constexpr auto pa2atm(auto x) noexcept
Conversion from Pa to Atm.
constexpr auto celsius2kelvin(auto x) noexcept
Conversion from C to K.
auto atand(auto x) noexcept
Returns rad2deg of the arc-tangent of the input.
constexpr auto kaycm2joule(auto x) noexcept
Conversion from cm-1 to Joule.
constexpr auto joule2kaycm(auto x) noexcept
Conversion from Joule to cm-1.
auto asind(auto x) noexcept
Returns rad2deg of the arc-sine of the input.
constexpr auto freq2wavelen(auto x) noexcept
Conversion from Hz to wavelength.
constexpr auto torr2pa(auto x) noexcept
Conversion from Torr to Pa.
constexpr auto kaycm_per_cmsquared2hz_per_msquared(auto x) noexcept
Conversion from cm-1 per molecule per cm^2 to Hz per molecule per m^2.
constexpr auto kaycm_per_atm2hz_per_pa(auto x) noexcept
Conversion from cm-1 per atmosphere to Hz per Pascal.
constexpr auto mhz2joule(auto x) noexcept
Conversion from MHz to Joule.
constexpr auto hz2joule(auto x) noexcept
Conversion from MHz to Joule.
constexpr auto hz_per_pa2kaycm_per_atm(auto x) noexcept
Conversion from Hz per Pascal to cm-1 per atmosphere.
constexpr auto mhz_per_torr2hz_per_pa(auto x) noexcept
Conversion from MHz/Torr to Hz/Pa.
auto acosd(auto x) noexcept
Returns rad2deg of the arc-cosine of the input.
constexpr auto meter2angstrom(auto x) noexcept
Conversion from meter to Å
auto sind(auto x) noexcept
Returns the sine of the deg2rad of the input.
constexpr auto rad2deg(auto x) noexcept
Converts radians to degrees.
constexpr auto freq2angfreq(auto x) noexcept
Conversion from Hz to Angular Hz.
constexpr auto wavelen2freq(auto x) noexcept
Conversion from wavelength to Hz.
constexpr auto freq2angcm(auto x) noexcept
Conversion from Hz to Angular wavenumber.
constexpr auto joule2hz(auto x) noexcept
Conversion from Hz to Joule.
constexpr auto bar2pa(auto x) noexcept
Conversion from bar to Pa.
auto cosd(auto x) noexcept
Returns the cosine of the deg2rad of the input.
constexpr auto freq2kaycm(auto x) noexcept
Conversion from Hz to Kayser wavenumber.
constexpr auto angcm2freq(auto x) noexcept
Conversion from Angular wavenumber to Hz.
constexpr auto kelvin2celsius(auto x) noexcept
Conversion from K to C.
constexpr auto kaycm2freq(auto x) noexcept
Conversion from Kayser wavenumber to Hz.
constexpr auto hz2ghz(auto x) noexcept
Conversion from wavelength to Hz.
constexpr auto pa2bar(auto x) noexcept
Conversion from Pa to bar.
constexpr auto pa2torr(auto x) noexcept
Conversion from Pa to Torr.
auto atan2d(auto y, auto x) noexcept
Returns rad2deg of the arc-tangent of inputs #T1/#T2
constexpr auto hz_per_msquared2kaycm_per_cmsquared(auto x) noexcept
Conversion from Hz per molecule per m^2 to cm-1 per molecule per cm^2.
constexpr auto angstrom2meter(auto x) noexcept
Conversion from Å to meter.
constexpr auto atm2pa(auto x) noexcept
Conversion from Atm to Pa.
constexpr auto angfreq2freq(auto x) noexcept
Conversion from Angular Hz to Hz.