ARTS 2.5.11 (git: 6827797f)
mc_interp.cc
Go to the documentation of this file.
1
9/*===========================================================================
10 === External declarations
11 ===========================================================================*/
12#include "mc_interp.h"
13#include "arts_constants.h"
14#include "arts_conversions.h"
15#include "logic.h"
16#include "montecarlo.h"
17
18
19inline constexpr Numeric DEG2RAD=Conversion::deg2rad(1);
20inline constexpr Numeric RAD2DEG=Conversion::rad2deg(1);
21inline constexpr Numeric PI=Constant::pi;
22
23Numeric SLIData2::interpolate(Numeric x1, Numeric x2) const {
24 GridPos gp1, gpl, gpr;
25 Vector itw1(2), itwl(2), itwr(2);
26 Numeric yl, yr;
27 //Get interpolation weights for x1 interpolation
28 gridpos(gp1, this->x1a, x1);
29 interpweights(itw1, gp1);
30 //Get y values on bounding x1 grid points for desired x2
31 gridpos(gpl, this->x2a[gp1.idx], x2);
32 interpweights(itwl, gpl);
33 gridpos(gpr, this->x2a[gp1.idx + 1], x2);
34 interpweights(itwr, gpr);
35 yl = interp(itwl, this->ya[gp1.idx], gpl);
36 yr = interp(itwr, this->ya[gp1.idx + 1], gpr);
37 //interpolate these two y values useing x1 interpolation weights
38 return itw1[0] * yl + itw1[1] * yr;
39}
40
41//void SLIData2::check() const
42//{
43// Index nx1=this->x1a.nelem();
44// ARTS_ASSERT(nx1>0);
45//}
46
47ostream& operator<<(ostream& os, const SLIData2& /* sli */) {
48 os << "SLIData2 : Output operator not implemented";
49 return os;
50}
51
52void interp(MatrixView tia,
53 ConstVectorView itw,
54 const ArrayOfMatrix& a,
55 const GridPos& tc) {
56 DEBUG_ONLY(const Numeric sum_check_epsilon = 1e-6);
57
58 ARTS_ASSERT(is_size(itw, 2)); // We need 2 interpolation
59 // weights.
60
61 // Check that interpolation weights are valid. The sum of all
62 // weights (last dimension) must always be approximately one.
63 ARTS_ASSERT(is_same_within_epsilon(sum(itw), 1, sum_check_epsilon));
64
65 Index anr = a[0].nrows();
66 Index anc = a[0].ncols();
67
68 ARTS_ASSERT(tia.nrows() == anr);
69 ARTS_ASSERT(tia.ncols() == anc);
70
71 for (Index inr = 0; inr < anr; inr++)
72 for (Index inc = 0; inc < anc; inc++) {
73 tia(inr, inc) =
74 a[tc.idx](inr, inc) * itw[0] + a[tc.idx + 1](inr, inc) * itw[1];
75 }
76}
77
78void interp(VectorView tia,
79 ConstVectorView itw,
80 const ArrayOfVector& a,
81 const GridPos& tc) {
82 DEBUG_ONLY(const Numeric sum_check_epsilon = 1e-6);
83 ARTS_ASSERT(is_size(itw, 2)); // We need 2 interpolation
84 // weights.
85
86 // Check that interpolation weights are valid. The sum of all
87 // weights (last dimension) must always be approximately one.
88 ARTS_ASSERT(is_same_within_epsilon(sum(itw), 1, sum_check_epsilon));
89
90 Index an = a[0].nelem();
91
92 ARTS_ASSERT(tia.nelem() == an);
93
94 for (Index i = 0; i < an; ++i) {
95 tia[i] = a[tc.idx][i] * itw[0] + a[tc.idx + 1][i] * itw[1];
96 }
97}
98
100 VectorView pha_mat_int,
101 Numeric& theta_rad,
102 //Input:
103 const SingleScatteringData& scat_data_single,
104 const Numeric& za_sca,
105 const Numeric& aa_sca,
106 const Numeric& za_inc,
107 const Numeric& aa_inc,
108 const Numeric& rtp_temperature) {
109 Numeric ANG_TOL = 1e-7;
110
111 //Calculate scattering angle from incident and scattered directions.
112 //The two special cases are implemented here to avoid NaNs that can
113 //sometimes occur in in the acos... formula in forward and backscatter
114 //cases. CPD 5/10/03.
115
116 if (abs(aa_sca - aa_inc) < ANG_TOL) {
117 theta_rad = DEG2RAD * abs(za_sca - za_inc);
118 } else if (abs(abs(aa_sca - aa_inc) - 180) < ANG_TOL) {
119 theta_rad = DEG2RAD * (za_sca + za_inc);
120 if (theta_rad > PI) {
121 theta_rad = 2 * PI - theta_rad;
122 }
123 } else {
124 const Numeric za_sca_rad = za_sca * DEG2RAD;
125 const Numeric za_inc_rad = za_inc * DEG2RAD;
126 const Numeric aa_sca_rad = aa_sca * DEG2RAD;
127 const Numeric aa_inc_rad = aa_inc * DEG2RAD;
128
129 // cout << "Interpolation on scattering angle" << endl;
130 ARTS_ASSERT(scat_data_single.pha_mat_data.ncols() == 6);
131 // Calculation of the scattering angle:
132 theta_rad =
133 acos(cos(za_sca_rad) * cos(za_inc_rad) +
134 sin(za_sca_rad) * sin(za_inc_rad) * cos(aa_sca_rad - aa_inc_rad));
135 }
136 const Numeric theta = RAD2DEG * theta_rad;
137
138 // Interpolation of the data on the scattering angle:
139
140 GridPos thet_gp;
141 gridpos(thet_gp, scat_data_single.za_grid, theta);
142 GridPos t_gp;
143
144 if (scat_data_single.T_grid.nelem() == 1) {
145 Vector itw(2);
146 interpweights(itw, thet_gp);
147
148 for (Index i = 0; i < 6; i++) {
149 pha_mat_int[i] = interp(
150 itw, scat_data_single.pha_mat_data(0, 0, joker, 0, 0, 0, i), thet_gp);
151 }
152 } else {
153 gridpos(t_gp, scat_data_single.T_grid, rtp_temperature);
154
155 Vector itw(4);
156 interpweights(itw, t_gp, thet_gp);
157
158 for (Index i = 0; i < 6; i++) {
159 pha_mat_int[i] =
160 interp(itw,
161 scat_data_single.pha_mat_data(0, joker, joker, 0, 0, 0, i),
162 t_gp,
163 thet_gp);
164 }
165 }
166}
Constants of physical expressions as constexpr.
Common ARTS conversions.
A 2D sequential linear interpolation (SLI) lookup table This class holds the gridded for 2D SLI as we...
Definition: mc_interp.h:35
ArrayOfVector x2a
Definition: mc_interp.h:40
Numeric interpolate(Numeric x1, Numeric x2) const
Definition: mc_interp.cc:23
ArrayOfVector ya
Definition: mc_interp.h:42
Vector x1a
Definition: mc_interp.h:38
#define DEBUG_ONLY(...)
Definition: debug.h:53
#define ARTS_ASSERT(condition,...)
Definition: debug.h:84
void gridpos(ArrayOfGridPos &gp, ConstVectorView old_grid, ConstVectorView new_grid, const Numeric &extpolfac)
Set up a grid position Array.
void interpweights(VectorView itw, const GridPos &tc)
Red 1D interpolation weights.
constexpr Numeric DEG2RAD
Definition: mc_interp.cc:19
void interp(MatrixView tia, ConstVectorView itw, const ArrayOfMatrix &a, const GridPos &tc)
interp.
Definition: mc_interp.cc:52
ostream & operator<<(ostream &os, const SLIData2 &)
Definition: mc_interp.cc:47
constexpr Numeric RAD2DEG
Definition: mc_interp.cc:20
void interp_scat_angle_temperature(VectorView pha_mat_int, Numeric &theta_rad, const SingleScatteringData &scat_data_single, const Numeric &za_sca, const Numeric &aa_sca, const Numeric &za_inc, const Numeric &aa_inc, const Numeric &rtp_temperature)
interp_scat_angle_temperature.
Definition: mc_interp.cc:99
constexpr Numeric PI
Definition: mc_interp.cc:21
Interpolation classes and functions created for use within Monte Carlo scattering simulations.
void interp(MatrixView tia, ConstVectorView itw, const ArrayOfMatrix &a, const GridPos &tc)
interp.
Definition: mc_interp.cc:52
constexpr Numeric pi
The following mathematical constants are generated in python Decimal package by the code:
constexpr auto deg2rad(auto x) noexcept
Converts degrees to radians.
constexpr auto rad2deg(auto x) noexcept
Converts radians to degrees.
Structure to store a grid position.
Definition: interpolation.h:56
Index idx
Definition: interpolation.h:57
#define a