ARTS 2.5.0 (git: 9ee3ac6c)
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
29extern const Numeric PI;
30extern const Numeric DENSITY_OF_ICE;
31extern 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 ARTS_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
The global header file for ARTS.
Index nelem() const ARTS_NOEXCEPT
Returns the number of elements.
Definition: matpackI.cc:48
The range class.
Definition: matpackI.h:165
The Vector class.
Definition: matpackI.h:876
Internal cloudbox functions.
#define ARTS_ASSERT(condition,...)
Definition: debug.h:83
#define q
void linreg(Vector &p, ConstVectorView x, ConstVectorView y)
Definition: lin_alg.cc:2297
Linear algebra functions.
Header file for logic.cc.
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
Workspace functions for the solution of cloud-box radiative transfer by Monte Carlo methods....
Declarations having to do with the four output streams.
const Numeric DENSITY_OF_WATER
const Numeric PI
const Numeric DENSITY_OF_ICE
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
Internal functions for microphysics calculations (size distributions etc.)
Vector mass(const ConstVectorView &atmospheric_vmrs, const ArrayOfArrayOfSpeciesTag &atmospheric_species, const ArrayOfSpecies &lineshape_species, const SpeciesIsotopologueRatios &ir) ARTS_NOEXCEPT
Returns a mass vector for this model's main calculations.
constexpr bool isnan(double d) noexcept
Definition: nonstd.h:39
This file contains declerations of functions of physical character.
Propagation path structure and functions.
#define a
#define b
Internal functions associated with size distributions.
member functions of the Rng class and gsl_rng code
Contains sorting routines.
void get_sorted_indexes(ArrayOfIndex &sorted, const T &data)
get_sorted_indexes
Definition: sorting.h:73