ARTS  2.3.1285(git:92a29ea9-dirty)
microphysics.cc
Go to the documentation of this file.
1 /* Copyright (C) 2011-2017 Jana Mendrok <jana.mendrok@gmail.com>
2 
3  This program is free software; you can redistribute it and/or modify it
4  under the terms of the GNU General Public License as published by the
5  Free Software Foundation; either version 2, or (at your option) any
6  later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16  USA.
17 */
18 
27 #include "microphysics.h"
28 
29 extern const Numeric PI;
30 extern const Numeric DENSITY_OF_ICE;
31 extern const Numeric DENSITY_OF_WATER;
32 
33 /*===========================================================================
34  === External declarations
35  ===========================================================================*/
36 #include <algorithm>
37 #include <cmath>
38 #include <ctime>
39 #include <limits>
40 #include <stdexcept>
41 
42 #include "arts.h"
43 #include "check_input.h"
44 #include "cloudbox.h"
45 #include "lin_alg.h"
46 #include "logic.h"
47 #include "math_funcs.h"
48 #include "mc_antenna.h"
49 #include "messages.h"
50 #include "physics_funcs.h"
51 #include "ppath.h"
52 #include "psd.h"
53 #include "rng.h"
54 #include "sorting.h"
55 
78  Numeric& b,
79  const Vector& x,
80  const Vector& mass,
81  const Numeric& x_fit_start,
82  const Numeric& x_fit_end) {
83  const Index nse = x.nelem();
84  assert(nse > 1);
85 
86  ArrayOfIndex intarr_sort, intarr_unsort(0);
87  Vector x_unsorted(nse), m_unsorted(nse);
88  Vector q;
89  Index nsev = 0;
90 
91  for (Index i = 0; i < nse; i++) {
92  if (std::isnan(x[i]))
93  throw runtime_error("NaN found in selected size grid data.");
94  if (std::isnan(mass[i]))
95  throw runtime_error("NaN found among particle mass data.");
96 
97  if (x[i] >= x_fit_start && x[i] <= x_fit_end) {
98  x_unsorted[nsev] = x[i];
99  m_unsorted[nsev] = mass[i];
100  nsev += 1;
101  }
102  }
103 
104  if (nsev < 2)
105  throw runtime_error(
106  "Less than two size points found in the range "
107  "[x_fit_start,x_fit_end]. It is then not possible "
108  "to determine the a and b parameters.");
109 
110  get_sorted_indexes(intarr_sort, x_unsorted[Range(0, nsev)]);
111  Vector log_x(nsev), log_m(nsev);
112 
113  for (Index i = 0; i < nsev; i++) {
114  log_x[i] = log(x_unsorted[intarr_sort[i]]);
115  log_m[i] = log(m_unsorted[intarr_sort[i]]);
116  }
117 
118  linreg(q, log_x, log_m);
119  a = exp(q[0]);
120  b = q[1];
121 }
122 
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Declarations having to do with the four output streams.
The Vector class.
Definition: matpackI.h:860
void derive_scat_species_a_and_b(Numeric &a, Numeric &b, const Vector &x, const Vector &mass, const Numeric &x_fit_start, const Numeric &x_fit_end)
Definition: microphysics.cc:77
The range class.
Definition: matpackI.h:160
Linear algebra functions.
Internal functions for microphysics calculations (size distributions etc.)
Workspace functions for the solution of cloud-box radiative transfer by Monte Carlo methods...
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:51
Contains sorting routines.
The global header file for ARTS.
member functions of the Rng class and gsl_rng code
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
Propagation path structure and functions.
void get_sorted_indexes(ArrayOfIndex &sorted, const T &data)
get_sorted_indexes
Definition: sorting.h:73
Header file for logic.cc.
This can be used to make arrays out of anything.
Definition: array.h:40
const Numeric PI
#define q
const Numeric DENSITY_OF_ICE
Internal functions associated with size distributions.
void linreg(Vector &p, ConstVectorView x, ConstVectorView y)
Definition: lin_alg.cc:2302
Internal cloudbox functions.
const Numeric DENSITY_OF_WATER
This file contains declerations of functions of physical character.