ARTS 2.5.9 (git: 825fa5f2)
physics_funcs.cc
Go to the documentation of this file.
1/* Copyright (C) 2002-2012
2 Patrick Eriksson <Patrick.Eriksson@chalmers.se>
3 Stefan Buehler <sbuehler@ltu.se>
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any
8 later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18 USA. */
19
30/*===========================================================================
31 === External declarations
32 ===========================================================================*/
33
34#include "physics_funcs.h"
35#include "arts_constants.h"
36#include "arts_conversions.h"
37#include "messages.h"
38#include "mystring.h"
39#include "physics_funcs.h"
40#include <cmath>
41#include <stdexcept>
42
47
48/*===========================================================================
49 === The functions (in alphabetical order)
50 ===========================================================================*/
51
65 //input
66 const Numeric& p,
67 const Numeric& dh)
68
69{
70 /* taken from: Seite „Barometrische Höhenformel“. In: Wikipedia,
71 * Die freie Enzyklopädie. Bearbeitungsstand: 3. April 2011, 20:28 UTC.
72 * URL: http://de.wikipedia.org/w/index.php?title=Barometrische_H%C3%B6henformel&oldid=87257486
73 * (Abgerufen: 15. April 2011, 15:41 UTC)
74 */
75
76 //barometric height formula
77 Numeric M = 0.02896; //mean molar mass of air [kg mol^-1]
78 Numeric g = 9.807; //earth acceleration [kg m s^-1]
79 Numeric R = 8.314; //universal gas constant [J K^−1 mol^−1]
80 Numeric T = 253; //median tropospheric reference temperature [K]
81
82 // calculation
83 Numeric p1 = p * exp(-(-dh) / (R * T / (M * g)));
84
85 return p1;
86}
87
100Numeric dinvplanckdI(const Numeric& i, const Numeric& f) {
101 ARTS_USER_ERROR_IF (i <= 0, "Non-positive radiance")
102 ARTS_USER_ERROR_IF (f <= 0, "Non-positive frequency")
103
104 static const Numeric a = PLANCK_CONST / BOLTZMAN_CONST;
105 static const Numeric b = 2 * PLANCK_CONST / (SPEED_OF_LIGHT * SPEED_OF_LIGHT);
106 const Numeric d = b * f * f * f / i;
107 const Numeric binv = a * f / log1p(d);
108
109 return binv * binv / (a * f * i * (1 / d + 1));
110}
111
133 Complex& Rh,
134 const Complex& n1,
135 const Complex& n2,
136 const Numeric& theta) {
137 const Numeric theta1 = DEG2RAD * theta;
138 const Numeric costheta1 = cos(theta1);
139 const Numeric costheta2 = cos(asin(n1.real() * sin(theta1) / n2.real()));
140
141 Complex a, b;
142 a = n2 * costheta1;
143 b = n1 * costheta2;
144 Rv = (a - b) / (a + b);
145 a = n1 * costheta1;
146 b = n2 * costheta2;
147 Rh = (a - b) / (a + b);
148}
149
162Numeric invplanck(const Numeric& i, const Numeric& f) {
163 ARTS_USER_ERROR_IF (i <= 0, "Non-positive radiance")
164 ARTS_USER_ERROR_IF (f < 0, "Non-positive frequency")
165
166 static const Numeric a = PLANCK_CONST / BOLTZMAN_CONST;
167 static const Numeric b = 2 * PLANCK_CONST / (SPEED_OF_LIGHT * SPEED_OF_LIGHT);
168
169 return (a * f) / log1p((b * f * f * f) / i);
170}
171
184Numeric invrayjean(const Numeric& i, const Numeric& f) {
185 // ARTS_USER_ERROR_IF (i < 0, "Negative radiance")
186 ARTS_USER_ERROR_IF (f <= 0, "Non-positive frequency")
187
188 static const Numeric a =
190
191 return (a * i) / (f * f);
192}
193
208Numeric planck(const Numeric& f, const Numeric& t) {
209 ARTS_USER_ERROR_IF (t <= 0, "Non-positive temperature")
210 ARTS_USER_ERROR_IF (f <= 0, "Non-positive frequency")
211
212 constexpr Numeric a = 2 * Constant::h / Math::pow2(Constant::c);;
213 constexpr Numeric b = Constant::h / Constant::k;
214
215 return a * Math::pow3(f) / std::expm1((b * f) / t);
216}
217
233void planck(VectorView b, const ConstVectorView& f, const Numeric& t) {
234 ARTS_USER_ERROR_IF (b.nelem() not_eq f.nelem(),
235 "Vector size mismatch: frequency dim is bad")
236 for (Index i = 0; i < f.nelem(); i++) b[i] = planck(f[i], t);
237}
238
255 Vector b(f.nelem());
256 for (Index i = 0; i < f.nelem(); i++) b[i] = planck(f[i], t);
257 return b;
258}
259
273Numeric dplanck_dt(const Numeric& f, const Numeric& t) {
274 ARTS_USER_ERROR_IF (t <= 0, "Non-positive temperature")
275 ARTS_USER_ERROR_IF (f <= 0, "Non-positive frequency")
276
277 constexpr Numeric a = 2 * Constant::h / Math::pow2(Constant::c);;
278 constexpr Numeric b = Constant::h / Constant::k;
279
280 // nb. expm1(x) should be more accurate than exp(x) - 1, so use it
281 const Numeric inv_exp_t_m1 = 1.0 / std::expm1(b * f / t);
282
283 return a * b * Math::pow4(f) * inv_exp_t_m1 * (1 + inv_exp_t_m1) / Math::pow2(t);
284}
285
299void dplanck_dt(VectorView dbdt, const ConstVectorView& f, const Numeric& t) {
300 ARTS_USER_ERROR_IF (dbdt.nelem() not_eq f.nelem(),
301 "Vector size mismatch: frequency dim is bad")
302 for (Index i = 0; i < f.nelem(); i++) dbdt[i] = dplanck_dt(f[i], t);
303}
304
319 Vector dbdt(f.nelem());
320 for (Index i = 0; i < f.nelem(); i++) dbdt[i] = dplanck_dt(f[i], t);
321 return dbdt;
322}
323
337Numeric dplanck_df(const Numeric& f, const Numeric& t) {
338 ARTS_USER_ERROR_IF (t <= 0, "Non-positive temperature")
339 ARTS_USER_ERROR_IF (f <= 0, "Non-positive frequency")
340
341 constexpr Numeric a = 2 * Constant::h / Math::pow2(Constant::c);;
342 constexpr Numeric b = Constant::h / Constant::k;
343
344 const Numeric inv_exp_t_m1 = 1.0 / std::expm1(b * f / t);
345
346 return a * Math::pow2(f) * (3.0 - (b * f / t) * (1 + inv_exp_t_m1)) * inv_exp_t_m1;
347}
348
363 Vector dbdf(f.nelem());
364 for (Index i = 0; i < f.nelem(); i++) dbdf[i] = dplanck_df(f[i], t);
365 return dbdf;
366}
367
380Numeric rayjean(const Numeric& f, const Numeric& tb) {
381 ARTS_USER_ERROR_IF (tb <= 0, "Non-positive temperature")
382 ARTS_USER_ERROR_IF (f < 0, "Negative frequency")
383
384 static const Numeric a =
386
387 return (f * f) / (a * tb);
388}
Constants of physical expressions as constexpr.
Common ARTS conversions.
A constant view of a Vector.
Definition: matpackI.h:521
Index nelem() const noexcept
Returns the number of elements.
Definition: matpackI.h:547
The VectorView class.
Definition: matpackI.h:674
The Vector class.
Definition: matpackI.h:910
#define ARTS_USER_ERROR_IF(condition,...)
Definition: debug.h:134
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
std::complex< Numeric > Complex
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 deg2rad(auto x) noexcept
Converts degrees to radians.
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
constexpr Numeric DEG2RAD
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 M
Definition: rng.cc:165
#define d
#define a
#define b