ARTS 2.5.11 (git: 725533f0)
physics_funcs.cc
Go to the documentation of this file.
1
11/*===========================================================================
12 === External declarations
13 ===========================================================================*/
14
15#include "physics_funcs.h"
16#include "arts_constants.h"
17#include "arts_conversions.h"
18#include "messages.h"
19#include "mystring.h"
20#include "physics_funcs.h"
21#include <cmath>
22#include <stdexcept>
23
26inline constexpr Numeric PLANCK_CONST=Constant::planck_constant;
28
29/*===========================================================================
30 === The functions (in alphabetical order)
31 ===========================================================================*/
32
45Numeric barometric_heightformula( //output is p1
46 //input
47 const Numeric& p,
48 const Numeric& dh)
49
50{
51 /* taken from: Seite „Barometrische Höhenformel“. In: Wikipedia,
52 * Die freie Enzyklopädie. Bearbeitungsstand: 3. April 2011, 20:28 UTC.
53 * URL: http://de.wikipedia.org/w/index.php?title=Barometrische_H%C3%B6henformel&oldid=87257486
54 * (Abgerufen: 15. April 2011, 15:41 UTC)
55 */
56
57 //barometric height formula
58 Numeric M = 0.02896; //mean molar mass of air [kg mol^-1]
59 Numeric g = 9.807; //earth acceleration [kg m s^-1]
60 Numeric R = 8.314; //universal gas constant [J K^−1 mol^−1]
61 Numeric T = 253; //median tropospheric reference temperature [K]
62
63 // calculation
64 Numeric p1 = p * exp(-(-dh) / (R * T / (M * g)));
65
66 return p1;
67}
68
81Numeric dinvplanckdI(const Numeric& i, const Numeric& f) {
82 ARTS_USER_ERROR_IF (i <= 0, "Non-positive radiance")
83 ARTS_USER_ERROR_IF (f <= 0, "Non-positive frequency")
84
85 static const Numeric a = PLANCK_CONST / BOLTZMAN_CONST;
86 static const Numeric b = 2 * PLANCK_CONST / (SPEED_OF_LIGHT * SPEED_OF_LIGHT);
87 const Numeric d = b * f * f * f / i;
88 const Numeric binv = a * f / log1p(d);
89
90 return binv * binv / (a * f * i * (1 / d + 1));
91}
92
113void fresnel(Complex& Rv,
114 Complex& Rh,
115 const Complex& n1,
116 const Complex& n2,
117 const Numeric& theta) {
118 const Numeric theta1 = DEG2RAD * theta;
119 const Numeric costheta1 = cos(theta1);
120 const Numeric costheta2 = cos(asin(n1.real() * sin(theta1) / n2.real()));
121
122 Complex a, b;
123 a = n2 * costheta1;
124 b = n1 * costheta2;
125 Rv = (a - b) / (a + b);
126 a = n1 * costheta1;
127 b = n2 * costheta2;
128 Rh = (a - b) / (a + b);
129}
130
143Numeric invplanck(const Numeric& i, const Numeric& f) {
144 ARTS_USER_ERROR_IF (i <= 0, "Non-positive radiance")
145 ARTS_USER_ERROR_IF (f < 0, "Non-positive frequency")
146
147 static const Numeric a = PLANCK_CONST / BOLTZMAN_CONST;
148 static const Numeric b = 2 * PLANCK_CONST / (SPEED_OF_LIGHT * SPEED_OF_LIGHT);
149
150 return (a * f) / log1p((b * f * f * f) / i);
151}
152
165Numeric invrayjean(const Numeric& i, const Numeric& f) {
166 // ARTS_USER_ERROR_IF (i < 0, "Negative radiance")
167 ARTS_USER_ERROR_IF (f <= 0, "Non-positive frequency")
168
169 static const Numeric a =
171
172 return (a * i) / (f * f);
173}
174
189Numeric planck(const Numeric& f, const Numeric& t) {
190 ARTS_USER_ERROR_IF (t <= 0, "Non-positive temperature")
191 ARTS_USER_ERROR_IF (f <= 0, "Non-positive frequency")
192
193 constexpr Numeric a = 2 * Constant::h / Math::pow2(Constant::c);;
194 constexpr Numeric b = Constant::h / Constant::k;
195
196 return a * Math::pow3(f) / std::expm1((b * f) / t);
197}
198
214void planck(VectorView b, const ConstVectorView& f, const Numeric& t) {
215 ARTS_USER_ERROR_IF (b.nelem() not_eq f.nelem(),
216 "Vector size mismatch: frequency dim is bad")
217 for (Index i = 0; i < f.nelem(); i++) b[i] = planck(f[i], t);
218}
219
235Vector planck(const ConstVectorView& f, const Numeric& t) {
236 Vector b(f.nelem());
237 for (Index i = 0; i < f.nelem(); i++) b[i] = planck(f[i], t);
238 return b;
239}
240
254Numeric dplanck_dt(const Numeric& f, const Numeric& t) {
255 ARTS_USER_ERROR_IF (t <= 0, "Non-positive temperature")
256 ARTS_USER_ERROR_IF (f <= 0, "Non-positive frequency")
257
258 constexpr Numeric a = 2 * Constant::h / Math::pow2(Constant::c);;
259 constexpr Numeric b = Constant::h / Constant::k;
260
261 // nb. expm1(x) should be more accurate than exp(x) - 1, so use it
262 const Numeric inv_exp_t_m1 = 1.0 / std::expm1(b * f / t);
263
264 return a * b * Math::pow4(f) * inv_exp_t_m1 * (1 + inv_exp_t_m1) / Math::pow2(t);
265}
266
280void dplanck_dt(VectorView dbdt, const ConstVectorView& f, const Numeric& t) {
281 ARTS_USER_ERROR_IF (dbdt.nelem() not_eq f.nelem(),
282 "Vector size mismatch: frequency dim is bad")
283 for (Index i = 0; i < f.nelem(); i++) dbdt[i] = dplanck_dt(f[i], t);
284}
285
299Vector dplanck_dt(const ConstVectorView& f, const Numeric& t) {
300 Vector dbdt(f.nelem());
301 for (Index i = 0; i < f.nelem(); i++) dbdt[i] = dplanck_dt(f[i], t);
302 return dbdt;
303}
304
318Numeric dplanck_df(const Numeric& f, const Numeric& t) {
319 ARTS_USER_ERROR_IF (t <= 0, "Non-positive temperature")
320 ARTS_USER_ERROR_IF (f <= 0, "Non-positive frequency")
321
322 constexpr Numeric a = 2 * Constant::h / Math::pow2(Constant::c);;
323 constexpr Numeric b = Constant::h / Constant::k;
324
325 const Numeric inv_exp_t_m1 = 1.0 / std::expm1(b * f / t);
326
327 return a * Math::pow2(f) * (3.0 - (b * f / t) * (1 + inv_exp_t_m1)) * inv_exp_t_m1;
328}
329
343Vector dplanck_df(const ConstVectorView& f, const Numeric& t) {
344 Vector dbdf(f.nelem());
345 for (Index i = 0; i < f.nelem(); i++) dbdf[i] = dplanck_df(f[i], t);
346 return dbdf;
347}
348
361Numeric rayjean(const Numeric& f, const Numeric& tb) {
362 ARTS_USER_ERROR_IF (tb <= 0, "Non-positive temperature")
363 ARTS_USER_ERROR_IF (f < 0, "Negative frequency")
364
365 static const Numeric a =
367
368 return (f * f) / (a * tb);
369}
Constants of physical expressions as constexpr.
Common ARTS conversions.
#define ARTS_USER_ERROR_IF(condition,...)
Definition debug.h:137
Declarations having to do with the four output streams.
This file contains the definition of String, the ARTS string class.
constexpr Numeric boltzmann_constant
Boltzmann constant [J/K] From: https://en.wikipedia.org/wiki/2019_redefinition_of_SI_base_units Date:...
constexpr Numeric k
Boltzmann constant convenience name [J/K].
constexpr Numeric speed_of_light
Speed of light [m/s] From: https://en.wikipedia.org/wiki/2019_redefinition_of_SI_base_units Date: 201...
constexpr Numeric planck_constant
Planck constant [J s] From: https://en.wikipedia.org/wiki/2019_redefinition_of_SI_base_units Date: 20...
constexpr Numeric c
Speed of light convenience name [m/s].
constexpr Numeric h
Planck constant convenience name [J s].
constexpr auto pow3(auto x) noexcept
power of three
constexpr auto pow4(auto x) noexcept
power of four
constexpr auto pow2(auto x) noexcept
power of two
constexpr Numeric PLANCK_CONST
constexpr Numeric BOLTZMAN_CONST
Numeric dplanck_df(const Numeric &f, const Numeric &t)
dplanck_df
constexpr Numeric SPEED_OF_LIGHT
Numeric dinvplanckdI(const Numeric &i, const Numeric &f)
dinvplanckdI
Numeric planck(const Numeric &f, const Numeric &t)
planck
Numeric barometric_heightformula(const Numeric &p, const Numeric &dh)
barometric_heightformula
Numeric invrayjean(const Numeric &i, const Numeric &f)
invrayjean
Numeric invplanck(const Numeric &i, const Numeric &f)
invplanck
Numeric dplanck_dt(const Numeric &f, const Numeric &t)
dplanck_dt
void fresnel(Complex &Rv, Complex &Rh, const Complex &n1, const Complex &n2, const Numeric &theta)
fresnel
Numeric rayjean(const Numeric &f, const Numeric &tb)
rayjean
This file contains declerations of functions of physical character.
#define d
#define a
#define b