ARTS  2.3.1285(git:92a29ea9-dirty)
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 <cmath>
36 #include <stdexcept>
37 #include "messages.h"
38 #include "mystring.h"
39 #include "physics_funcs.h"
40 
41 extern const Numeric BOLTZMAN_CONST;
42 extern const Numeric DEG2RAD;
43 extern const Numeric PLANCK_CONST;
44 extern const Numeric SPEED_OF_LIGHT;
45 
46 /*===========================================================================
47  === The functions (in alphabetical order)
48  ===========================================================================*/
49 
63  //input
64  const Numeric& p,
65  const Numeric& dh)
66 
67 {
68  /* taken from: Seite „Barometrische Höhenformel“. In: Wikipedia,
69  * Die freie Enzyklopädie. Bearbeitungsstand: 3. April 2011, 20:28 UTC.
70  * URL: http://de.wikipedia.org/w/index.php?title=Barometrische_H%C3%B6henformel&oldid=87257486
71  * (Abgerufen: 15. April 2011, 15:41 UTC)
72  */
73 
74  //barometric height formula
75  Numeric M = 0.02896; //mean molar mass of air [kg mol^-1]
76  Numeric g = 9.807; //earth acceleration [kg m s^-1]
77  Numeric R = 8.314; //universal gas constant [J K^−1 mol^−1]
78  Numeric T = 253; //median tropospheric reference temperature [K]
79 
80  // calculation
81  Numeric p1 = p * exp(-(-dh) / (R * T / (M * g)));
82 
83  return p1;
84 }
85 
98 Numeric dinvplanckdI(const Numeric& i, const Numeric& f) try {
99  if (i <= 0) throw "Non-positive radiance";
100  if (f <= 0) throw "Non-positive frequency";
101 
102  static const Numeric a = PLANCK_CONST / BOLTZMAN_CONST;
103  static const Numeric b = 2 * PLANCK_CONST / (SPEED_OF_LIGHT * SPEED_OF_LIGHT);
104  const Numeric d = b * f * f * f / i;
105  const Numeric binv = a * f / log(d + 1);
106 
107  return binv * binv / (a * f * i * (1 / d + 1));
108 } catch (const char* e) {
110  os << "Errors raised by *dinvplanckdI* internal function:\n";
111  os << "\tError: " << e << '\n';
112  throw std::runtime_error(os.str());
113 }
114 
135 void fresnel(Complex& Rv,
136  Complex& Rh,
137  const Complex& n1,
138  const Complex& n2,
139  const Numeric& theta) {
140  const Numeric theta1 = DEG2RAD * theta;
141  const Numeric costheta1 = cos(theta1);
142  const Numeric costheta2 = cos(asin(n1.real() * sin(theta1) / n2.real()));
143 
144  Complex a, b;
145  a = n2 * costheta1;
146  b = n1 * costheta2;
147  Rv = (a - b) / (a + b);
148  a = n1 * costheta1;
149  b = n2 * costheta2;
150  Rh = (a - b) / (a + b);
151 }
152 
165 Numeric invplanck(const Numeric& i, const Numeric& f) try {
166  if (i <= 0) throw "Non-positive radiance";
167  if (f < 0) throw "Non-positive frequency";
168 
169  static const Numeric a = PLANCK_CONST / BOLTZMAN_CONST;
170  static const Numeric b = 2 * PLANCK_CONST / (SPEED_OF_LIGHT * SPEED_OF_LIGHT);
171 
172  return (a * f) / log((b * f * f * f) / i + 1.0);
173 } catch (const char* e) {
175  os << "Errors raised by *invplanck* internal function:\n";
176  os << "\tError: " << e << '\n';
177  throw std::runtime_error(os.str());
178 }
179 
192 Numeric invrayjean(const Numeric& i, const Numeric& f) try {
193  // if(i < 0) throw "Negative radiance";
194  if (f <= 0) throw "Non-positive frequency";
195 
196  static const Numeric a =
198 
199  return (a * i) / (f * f);
200 } catch (const char* e) {
202  os << "Errors raised by *invrayjean* internal function:\n";
203  os << "\tError: " << e << '\n';
204  throw std::runtime_error(os.str());
205 }
206 
219 Numeric number_density(const Numeric& p, const Numeric& t) try {
220  if (p < 0) throw "Negative pressure";
221  if (t <= 0) throw "Non-positive temperature";
222 
223  return p / (t * BOLTZMAN_CONST);
224 } catch (const char* e) {
226  os << "Errors raised by *number_density* internal function:\n";
227  os << "\tError: " << e << '\n';
228  throw std::runtime_error(os.str());
229 }
230 
243 Numeric dnumber_density_dt(const Numeric& p, const Numeric& t) try {
244  if (p < 0) throw "Negative pressure";
245  if (t <= 0) throw "Non-positive temperature";
246 
247  return -p / (t * BOLTZMAN_CONST * t);
248 } catch (const char* e) {
250  os << "Errors raised by *dnumber_density_dt* internal function:\n";
251  os << "\tError: " << e << '\n';
252  throw std::runtime_error(os.str());
253 }
254 
269 Numeric planck(const Numeric& f, const Numeric& t) try {
270  if (t <= 0) throw "Non-positive temperature";
271  if (f <= 0) throw "Non-positive frequency";
272 
273  static const Numeric a = 2 * PLANCK_CONST / (SPEED_OF_LIGHT * SPEED_OF_LIGHT);
274  static const Numeric b = PLANCK_CONST / BOLTZMAN_CONST;
275 
276  return (a * f * f * f) / (exp((b * f) / t) - 1.0);
277 } catch (const char* e) {
279  os << "Errors raised by *planck* internal function:\n";
280  os << "\tError: " << e << '\n';
281  throw std::runtime_error(os.str());
282 }
283 
299 void planck(VectorView b, ConstVectorView f, const Numeric& t) try {
300  if (b.nelem() not_eq f.nelem())
301  throw "Vector size mismatch: frequency dim is bad";
302 
303  for (Index i = 0; i < f.nelem(); i++) b[i] = planck(f[i], t);
304 } catch (const char* e) {
306  os << "Errors raised by *planck* internal function:\n";
307  os << "\tError: " << e << '\n';
308  throw std::runtime_error(os.str());
309 } catch (const std::exception& e) {
311  os << "Errors in calls by *planck* internal function:\n";
312  os << e.what();
313 
314  Index n = 0;
315  for (auto& F : f)
316  if (F <= 0) n++;
317  if (n)
318  os << '\t' << "You have " << n
319  << " frequency grid points that reports a negative frequency!\n";
320 
321  throw std::runtime_error(os.str());
322 }
323 
337 Numeric dplanck_dt(const Numeric& f, const Numeric& t) try {
338  if (t <= 0) throw "Non-positive temperature";
339  if (f <= 0) throw "Non-positive frequency";
340 
341  static const Numeric a = 2 * PLANCK_CONST / (SPEED_OF_LIGHT * SPEED_OF_LIGHT);
342  static const Numeric b = PLANCK_CONST / BOLTZMAN_CONST;
343 
344  const Numeric exp_t = exp(b * f / t);
345  const Numeric exp_t_m1 = exp_t - 1.0;
346  const Numeric f2 = f * f;
347 
348  return a * b * f2 * f2 * exp_t / (t * t * exp_t_m1 * exp_t_m1);
349 } catch (const char* e) {
351  os << "Errors raised by *dplanck_dt* internal function:\n";
352  os << "\tError: " << e << '\n';
353  throw std::runtime_error(os.str());
354 }
355 
369 void dplanck_dt(VectorView dbdt, ConstVectorView f, const Numeric& t) try {
370  if (dbdt.nelem() not_eq f.nelem())
371  throw "Vector size mismatch: frequency dim is bad";
372 
373  for (Index i = 0; i < f.nelem(); i++) dbdt[i] = dplanck_dt(f[i], t);
374 } catch (const char* e) {
376  os << "Errors raised by *planck* internal function:\n";
377  os << "\tError: " << e << '\n';
378  throw std::runtime_error(os.str());
379 } catch (const std::exception& e) {
381  os << "Errors in calls by *planck* internal function:\n";
382  os << e.what();
383 
384  Index n = 0;
385  for (auto& F : f)
386  if (F <= 0) n++;
387  if (n)
388  os << '\t' << "You have " << n
389  << " frequency grid points that reports a negative frequency!\n";
390 
391  throw std::runtime_error(os.str());
392 }
393 
407 Numeric dplanck_df(const Numeric& f, const Numeric& t) try {
408  if (t <= 0) throw "Non-positive temperature";
409  if (f <= 0) throw "Non-positive frequency";
410 
411  static const Numeric a = 2 * PLANCK_CONST / (SPEED_OF_LIGHT * SPEED_OF_LIGHT);
412  static const Numeric b = PLANCK_CONST / BOLTZMAN_CONST;
413 
414  const Numeric exp_t = exp(b * f / t);
415  const Numeric exp_t_m1 = exp_t - 1.0;
416 
417  return -(a * f * f * (3.0 * t - 3.0 * t * exp_t + b * f * exp_t)) /
418  (t * exp_t_m1 * exp_t_m1);
419 } catch (const char* e) {
421  os << "Errors raised by *dplanck_df* internal function:\n";
422  os << "\tError: " << e << '\n';
423  throw std::runtime_error(os.str());
424 }
425 
438 Numeric rayjean(const Numeric& f, const Numeric& tb) try {
439  if (tb <= 0) throw "Non-positive temperature";
440  if (f < 0) throw "Negative frequency";
441 
442  static const Numeric a =
444 
445  return (f * f) / (a * tb);
446 } catch (const char* e) {
448  os << "Errors raised by *rayjean* internal function:\n";
449  os << "\tError: " << e << '\n';
450  throw std::runtime_error(os.str());
451 }
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
The VectorView class.
Definition: matpackI.h:610
#define M
Definition: rng.cc:165
Declarations having to do with the four output streams.
Numeric invrayjean(const Numeric &i, const Numeric &f)
invrayjean
Numeric dinvplanckdI(const Numeric &i, const Numeric &f)
dinvplanckdI
void fresnel(Complex &Rv, Complex &Rh, const Complex &n1, const Complex &n2, const Numeric &theta)
fresnel
Numeric number_density(const Numeric &p, const Numeric &t)
number_density
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:51
Numeric barometric_heightformula(const Numeric &p, const Numeric &dh)
barometric_heightformula
Numeric dplanck_dt(const Numeric &f, const Numeric &t)
dplanck_dt
std::complex< Numeric > Complex
Definition: complex.h:33
Numeric dplanck_df(const Numeric &f, const Numeric &t)
dplanck_df
Numeric dnumber_density_dt(const Numeric &p, const Numeric &t)
dnumber_density_dT
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
basic_ostringstream< char, string_char_traits< char >, alloc > ostringstream
Definition: sstream.h:204
const Numeric PLANCK_CONST
A constant view of a Vector.
Definition: matpackI.h:476
Numeric rayjean(const Numeric &f, const Numeric &tb)
rayjean
Numeric planck(const Numeric &f, const Numeric &t)
planck
Numeric invplanck(const Numeric &i, const Numeric &f)
invplanck
const Numeric BOLTZMAN_CONST
const Numeric SPEED_OF_LIGHT
const Numeric DEG2RAD
This file contains declerations of functions of physical character.
This file contains the definition of String, the ARTS string class.