70 const Numeric& rtp_planck_value,
71 const bool& trans_is_precalc) {
80 assert(
is_size(trans_mat, 1, stokes_dim, stokes_dim));
83 assert(
is_size(sca_vec_av, stokes_dim));
84 assert(rtp_planck_value >= 0);
98 if (!trans_is_precalc) {
100 trans_mat, lstep, ext_mat_av, 0);
104 if (stokes_dim == 1) {
105 stokes_vec[0] = stokes_vec[0] * trans_mat(0, 0) +
106 (abs_vec_av.
Kjj()[0] * rtp_planck_value + sca_vec_av[0]) /
107 ext_mat_av.
Kjj()[0] * (1 - trans_mat(0, 0));
133 Matrix invK(stokes_dim, stokes_dim);
137 source *= rtp_planck_value;
139 for (
Index i = 0;
i < stokes_dim;
i++)
140 source[
i] += sca_vec_av[
i];
144 mult(x, invK, source);
149 Matrix ImT(stokes_dim, stokes_dim);
156 mult(term1, trans_mat, stokes_vec);
158 for (
Index i = 0;
i < stokes_dim;
i++)
159 stokes_vec[
i] = term1[
i] + term2[
i];
168 const Agenda& spt_calc_agenda,
169 const Index& za_index,
170 const Index& aa_index,
180 out3 <<
"Calculate scattering properties in cloudbox \n";
182 const Index atmosphere_dim = cloudbox_limits.
nelem() / 2;
184 const Index stokes_dim = ext_mat_field.
ncols();
186 assert(atmosphere_dim == 1 || atmosphere_dim == 3);
187 assert(ext_mat_field.
ncols() == ext_mat_field.
nrows() &&
188 ext_mat_field.
ncols() == abs_vec_field.
ncols());
190 const Index Np_cloud = cloudbox_limits[1] - cloudbox_limits[0] + 1;
193 Index Nlat_cloud = 1;
194 Index Nlon_cloud = 1;
196 if (atmosphere_dim == 3) {
197 Nlat_cloud = cloudbox_limits[3] - cloudbox_limits[2] + 1;
198 Nlon_cloud = cloudbox_limits[5] - cloudbox_limits[4] + 1;
205 for (
auto& av : abs_vec_spt_local) {
210 for (
auto&
pm : ext_mat_spt_local) {
230 for (
Index scat_p_index_local = 0; scat_p_index_local < Np_cloud;
231 scat_p_index_local++) {
232 for (
Index scat_lat_index_local = 0; scat_lat_index_local < Nlat_cloud;
233 scat_lat_index_local++) {
234 for (
Index scat_lon_index_local = 0; scat_lon_index_local < Nlon_cloud;
235 scat_lon_index_local++) {
236 if (atmosphere_dim == 1)
237 rtp_temperature_local =
238 t_field(scat_p_index_local + cloudbox_limits[0], 0, 0);
240 rtp_temperature_local =
241 t_field(scat_p_index_local + cloudbox_limits[0],
242 scat_lat_index_local + cloudbox_limits[2],
243 scat_lon_index_local + cloudbox_limits[4]);
251 scat_lat_index_local,
252 scat_lon_index_local,
253 rtp_temperature_local,
281 scat_lat_index_local,
282 scat_lon_index_local,
286 abs_vec_field(scat_p_index_local,
287 scat_lat_index_local,
288 scat_lon_index_local,
292 scat_lat_index_local,
293 scat_lon_index_local,
305 const Index& p_index,
306 const Index& za_index,
311 const Agenda& propmat_clearsky_agenda,
314 const Agenda& ppath_step_agenda,
316 const Numeric& ppath_lraytrace,
323 const Index& f_index,
327 const Agenda& surface_rtprop_agenda,
329 const Index& scat_za_interp,
341 ppath_step.
pos(0, 0) = z_field(p_index, 0, 0);
342 ppath_step.
r[0] = refellipsoid[0] + z_field(p_index, 0, 0);
345 ppath_step.
los(0, 0) = za_grid[za_index];
348 ppath_step.
gp_p[0].idx = p_index;
349 ppath_step.
gp_p[0].fd[0] = 0;
350 ppath_step.
gp_p[0].fd[1] = 1;
357 Vector(1, f_grid[f_index]),
365 if ((cloudbox_limits[0] <= ppath_step.
gp_p[1].idx &&
366 cloudbox_limits[1] > ppath_step.
gp_p[1].idx) ||
367 (cloudbox_limits[1] == ppath_step.
gp_p[1].idx &&
368 abs(ppath_step.
gp_p[1].fd[0]) < 1e-6)) {
370 const Index stokes_dim = cloudbox_field_mono.
ncols();
381 Tensor3 ext_mat_int(stokes_dim, stokes_dim, ppath_step.
np, 0.);
382 Matrix abs_vec_int(stokes_dim, ppath_step.
np, 0.);
383 Matrix sca_vec_int(stokes_dim, ppath_step.
np, 0.);
384 Matrix cloudbox_field_mono_int(stokes_dim, ppath_step.
np, 0.);
386 Matrix vmr_list_int(N_species, ppath_step.
np, 0.);
392 cloudbox_field_mono_int,
420 propmat_clearsky_agenda,
427 cloudbox_field_mono_int,
444 surface_rtprop_agenda,
461 const Index& p_index,
462 const Index& za_index,
468 const Agenda& propmat_clearsky_agenda,
471 const Agenda& ppath_step_agenda,
473 const Numeric& ppath_lraytrace,
481 const Index& f_index,
485 const Agenda& surface_rtprop_agenda,
486 const Index& scat_za_interp,
498 ppath_step.
pos(0, 0) = z_field(p_index, 0, 0);
499 ppath_step.
r[0] = refellipsoid[0] + z_field(p_index, 0, 0);
502 ppath_step.
los(0, 0) = za_grid[za_index];
505 ppath_step.
gp_p[0].idx = p_index;
506 ppath_step.
gp_p[0].fd[0] = 0;
507 ppath_step.
gp_p[0].fd[1] = 1;
514 Vector(1, f_grid[f_index]),
522 if ((cloudbox_limits[0] <= ppath_step.
gp_p[1].idx &&
523 cloudbox_limits[1] > ppath_step.
gp_p[1].idx) ||
524 (cloudbox_limits[1] == ppath_step.
gp_p[1].idx &&
525 abs(ppath_step.
gp_p[1].fd[0]) < 1e-6)) {
527 const Index stokes_dim = cloudbox_field_mono.
ncols();
538 Tensor3 ext_mat_int(stokes_dim, stokes_dim, ppath_step.
np, 0.);
539 Matrix abs_vec_int(stokes_dim, ppath_step.
np, 0.);
540 Matrix sca_vec_int(stokes_dim, ppath_step.
np, 0.);
541 Matrix cloudbox_field_mono_int(stokes_dim, ppath_step.
np, 0.);
543 Matrix vmr_list_int(N_species, ppath_step.
np, 0.);
549 cloudbox_field_mono_int,
556 cloudbox_field_mono_old,
581 propmat_clearsky_agenda,
588 cloudbox_field_mono_int,
603 surface_rtprop_agenda,
617 const Index& p_index,
618 const Index& za_index,
623 const Agenda& propmat_clearsky_agenda,
631 const Index& f_index,
639 const Index stokes_dim = cloudbox_field_mono.
ncols();
640 const Index atmosphere_dim = 1;
644 Matrix matrix_tmp(stokes_dim, stokes_dim);
645 Vector vector_tmp(stokes_dim);
646 Vector rtp_vmr(N_species, 0.);
648 Vector sca_vec_av(stokes_dim, 0);
653 Vector stokes_vec(stokes_dim);
655 if ((p_index == 0) && (za_grid[za_index] > 90)) {
663 if (za_grid[za_index] <= 90.0) {
664 stokes_vec = cloudbox_field_mono(
665 p_index - cloudbox_limits[0] + 1, 0, 0, za_index, 0,
joker);
666 Numeric z_field_above = z_field(p_index + 1, 0, 0);
667 Numeric z_field_0 = z_field(p_index, 0, 0);
670 if (za_grid[za_index] == 90.0) {
676 cos_theta = cos(za_grid[za_index] *
PI / 180.0);
678 Numeric dz = (z_field_above - z_field_0);
680 lstep =
abs(dz / cos_theta);
684 0.5 * (t_field(p_index, 0, 0) + t_field(p_index + 1, 0, 0));
687 Numeric rtp_pressure = 0.5 * (p_grid[p_index] + p_grid[p_index + 1]);
690 for (
Index j = 0; j < N_species; j++)
691 rtp_vmr[j] = 0.5 * (vmr_field(j, p_index, 0, 0) +
692 vmr_field(j, p_index + 1, 0, 0));
698 const Vector rtp_mag_dummy(3, 0);
699 const Vector ppath_los_dummy;
710 partial_source_dummy,
713 f_grid[
Range(f_index, 1)],
720 propmat_clearsky_agenda);
724 for (
Index k = 0; k < stokes_dim; k++) {
731 p_index - cloudbox_limits[0], 0, 0, za_index, 0, k) +
733 p_index - cloudbox_limits[0] + 1, 0, 0, za_index, 0, k));
740 abs_vec_field(p_index - cloudbox_limits[0], 0, 0,
joker),
741 abs_vec_field(p_index - cloudbox_limits[0] + 1, 0, 0,
joker));
746 ext_mat_field(p_index - cloudbox_limits[0], 0, 0,
joker,
joker),
747 ext_mat_field(p_index - cloudbox_limits[0] + 1, 0, 0,
joker,
joker));
757 if (out3.sufficient_priority()) {
760 out3 <<
"-----------------------------------------\n";
761 out3 <<
"Input for radiative transfer step \n" 762 <<
"calculation inside" 765 out3 <<
"Stokes vector at intersection point: \n" << stokes_vec <<
"\n";
766 out3 <<
"lstep: ..." << lstep <<
"\n";
767 out3 <<
"------------------------------------------\n";
768 out3 <<
"Averaged coefficients: \n";
769 out3 <<
"Planck function: " << rte_planck_value <<
"\n";
770 out3 <<
"Scattering vector: " << sca_vec_av <<
"\n";
771 out3 <<
"Absorption vector: " << vector_tmp <<
"\n";
772 out3 <<
"Extinction matrix: " << matrix_tmp <<
"\n";
780 Matrix(stokes_dim, stokes_dim),
789 p_index - cloudbox_limits[0], 0, 0, za_index, 0,
joker) =
792 if (za_grid[za_index] > 90) {
793 stokes_vec = cloudbox_field_mono(
794 p_index - cloudbox_limits[0] - 1, 0, 0, za_index, 0,
joker);
795 Numeric z_field_below = z_field(p_index - 1, 0, 0);
796 Numeric z_field_0 = z_field(p_index, 0, 0);
799 if (za_grid[za_index] == 90.0) {
800 cos_theta = cos((za_grid[za_index] - 1) *
PI / 180.);
804 cos_theta = cos(za_grid[za_index] *
PI / 180.0);
806 Numeric dz = (z_field_0 - z_field_below);
807 lstep =
abs(dz / cos_theta);
811 0.5 * (t_field(p_index, 0, 0) + t_field(p_index - 1, 0, 0));
814 Numeric rtp_pressure = 0.5 * (p_grid[p_index] + p_grid[p_index - 1]);
818 for (
Index k = 0; k < N_species; k++)
819 rtp_vmr[k] = 0.5 * (vmr_field(k, p_index, 0, 0) +
820 vmr_field(k, p_index - 1, 0, 0));
826 const Vector rtp_mag_dummy(3, 0);
827 const Vector ppath_los_dummy;
837 partial_source_dummy,
840 f_grid[
Range(f_index, 1)],
847 propmat_clearsky_agenda);
857 for (
Index k = 0; k < stokes_dim; k++) {
864 p_index - cloudbox_limits[0], 0, 0, za_index, 0, k) +
866 p_index - cloudbox_limits[0] - 1, 0, 0, za_index, 0, k));
872 abs_vec_field(p_index - cloudbox_limits[0], 0, 0,
joker),
873 abs_vec_field(p_index - cloudbox_limits[0] - 1, 0, 0,
joker));
878 ext_mat_field(p_index - cloudbox_limits[0], 0, 0,
joker,
joker),
879 ext_mat_field(p_index - cloudbox_limits[0] + 1, 0, 0,
joker,
joker));
889 if (out3.sufficient_priority()) {
892 out3 <<
"-----------------------------------------\n";
893 out3 <<
"Input for radiative transfer step \n" 894 <<
"calculation inside" 897 out3 <<
"Stokes vector at intersection point: \n" << stokes_vec <<
"\n";
898 out3 <<
"lstep: ..." << lstep <<
"\n";
899 out3 <<
"------------------------------------------\n";
900 out3 <<
"Averaged coefficients: \n";
901 out3 <<
"Planck function: " << rte_planck_value <<
"\n";
902 out3 <<
"Scattering vector: " << sca_vec_av <<
"\n";
903 out3 <<
"Absorption vector: " << vector_tmp <<
"\n";
904 out3 <<
"Extinction matrix: " << matrix_tmp <<
"\n";
912 Matrix(stokes_dim, stokes_dim),
921 p_index - cloudbox_limits[0], 0, 0, za_index, 0,
joker) =
928 else if (bkgr == 2) {
932 Vector rte_pos(atmosphere_dim);
933 Numeric z_field_0 = z_field(0, 0, 0);
937 rte_los = za_grid[za_index];
949 "Surface reflections inside cloud box not yet handled.");
1111 const Index& p_index,
1112 const Index& lat_index,
1113 const Index& lon_index,
1114 const Index& za_index,
1115 const Index& aa_index,
1121 const Agenda& propmat_clearsky_agenda,
1124 const Agenda& ppath_step_agenda,
1126 const Numeric& ppath_lraytrace,
1135 const Index& f_index,
1144 const Index stokes_dim = cloudbox_field_mono.
ncols();
1146 Vector sca_vec_av(stokes_dim, 0);
1150 aa_g[
i] = aa_grid[
i] - 180.;
1162 ppath_step.
pos(0, 2) = lon_grid[lon_index];
1163 ppath_step.
pos(0, 1) = lat_grid[lat_index];
1164 ppath_step.
pos(0, 0) = z_field(p_index, lat_index, lon_index);
1167 refell2r(refellipsoid, ppath_step.
pos(0, 1)) + ppath_step.
pos(0, 0);
1170 ppath_step.
los(0, 0) = za_grid[za_index];
1171 ppath_step.
los(0, 1) = aa_g[aa_index];
1174 ppath_step.
gp_p[0].idx = p_index;
1175 ppath_step.
gp_p[0].fd[0] = 0.;
1176 ppath_step.
gp_p[0].fd[1] = 1.;
1178 ppath_step.
gp_lat[0].idx = lat_index;
1179 ppath_step.
gp_lat[0].fd[0] = 0.;
1180 ppath_step.
gp_lat[0].fd[1] = 1.;
1182 ppath_step.
gp_lon[0].idx = lon_index;
1183 ppath_step.
gp_lon[0].fd[0] = 0.;
1184 ppath_step.
gp_lon[0].fd[1] = 1.;
1191 Vector(1, f_grid[f_index]),
1209 cloud_gp_p[
i].idx -= cloudbox_limits[0];
1210 cloud_gp_lat[
i].idx -= cloudbox_limits[2];
1211 cloud_gp_lon[
i].idx -= cloudbox_limits[4];
1213 const Index n1 = cloudbox_limits[1] - cloudbox_limits[0];
1214 const Index n2 = cloudbox_limits[3] - cloudbox_limits[2];
1215 const Index n3 = cloudbox_limits[5] - cloudbox_limits[4];
1237 los_grid_aa[
i] = los_grid_aa[
i] + 180.;
1240 gridpos(gp_za, za_grid, los_grid_za);
1243 gridpos(gp_aa, aa_grid, los_grid_aa);
1245 Matrix itw_p_za(ppath_step.
np, 32);
1247 itw_p_za, cloud_gp_p, cloud_gp_lat, cloud_gp_lon, gp_za, gp_aa);
1255 Tensor3 ext_mat_int(stokes_dim, stokes_dim, ppath_step.
np);
1256 Matrix abs_vec_int(stokes_dim, ppath_step.
np);
1257 Matrix sca_vec_int(stokes_dim, ppath_step.
np, 0.);
1258 Matrix cloudbox_field_mono_int(stokes_dim, ppath_step.
np, 0.);
1262 Vector stokes_vec(stokes_dim);
1270 for (
Index i = 0;
i < stokes_dim;
i++) {
1273 out3 <<
"Interpolate ext_mat:\n";
1274 for (
Index j = 0; j < stokes_dim; j++) {
1300 out3 <<
"Interpolate doit_scat_field:\n";
1309 out3 <<
"Interpolate cloudbox_field_mono:\n";
1324 out3 <<
"Interpolate temperature field\n";
1341 Matrix vmr_list_int(N_species, ppath_step.
np);
1343 for (
Index i = 0;
i < N_species;
i++) {
1344 out3 <<
"Interpolate vmr field\n";
1352 vmr_list_int(
i,
joker) = vmr_int;
1356 itw2p(p_int, p_grid, ppath_step.
gp_p, itw_p);
1358 out3 <<
"Calculate radiative transfer inside cloudbox.\n";
1360 cloudbox_field_mono,
1361 propmat_clearsky_agenda,
1368 cloudbox_field_mono_int,
1386 const Agenda& propmat_clearsky_agenda,
1387 const Ppath& ppath_step,
1397 const Index& f_index,
1398 const Index& p_index,
1399 const Index& lat_index,
1400 const Index& lon_index,
1401 const Index& za_index,
1402 const Index& aa_index,
1406 const Index N_species = vmr_list_int.
nrows();
1407 const Index stokes_dim = cloudbox_field_mono.
ncols();
1408 const Index atmosphere_dim = cloudbox_limits.
nelem() / 2;
1410 Vector sca_vec_av(stokes_dim, 0);
1411 Vector stokes_vec(stokes_dim, 0.);
1413 Vector rtp_vmr_local(N_species, 0.);
1421 Matrix matrix_tmp(stokes_dim, stokes_dim);
1422 Vector vector_tmp(stokes_dim);
1425 stokes_vec = cloudbox_field_mono_int(
joker, ppath_step.
np - 1);
1427 for (
Index k = ppath_step.
np - 1; k >= 0; k--) {
1430 std::swap(cur_propmat_clearsky, prev_propmat_clearsky);
1435 const Vector rtp_mag_dummy(3, 0);
1436 const Vector ppath_los_dummy;
1444 cur_propmat_clearsky,
1447 partial_source_dummy,
1450 f_grid[
Range(f_index, 1)],
1456 vmr_list_int(
joker, k),
1457 propmat_clearsky_agenda);
1461 if (k == ppath_step.
np - 1)
continue;
1465 prev_propmat_clearsky[
i] += cur_propmat_clearsky[
i];
1466 prev_propmat_clearsky[
i] *= 0.5;
1470 ext_mat_local, abs_vec_local, prev_propmat_clearsky);
1472 for (
Index i = 0;
i < stokes_dim;
i++) {
1476 sca_vec_av[
i] = 0.5 * (sca_vec_int(
i, k) + sca_vec_int(
i, k + 1));
1483 abs_vec_int(
joker, k + 1));
1496 Numeric rte_planck_value =
planck(f, 0.5 * (t_int[k] + t_int[k + 1]));
1502 if (out3.sufficient_priority()) {
1505 out3 <<
"-----------------------------------------\n";
1506 out3 <<
"Input for radiative transfer step \n" 1507 <<
"calculation inside" 1510 out3 <<
"Stokes vector at intersection point: \n" << stokes_vec <<
"\n";
1511 out3 <<
"lstep: ..." << lstep <<
"\n";
1512 out3 <<
"------------------------------------------\n";
1513 out3 <<
"Averaged coefficients: \n";
1514 out3 <<
"Planck function: " << rte_planck_value <<
"\n";
1515 out3 <<
"Scattering vector: " << sca_vec_av <<
"\n";
1516 out3 <<
"Absorption vector: " << vector_tmp <<
"\n";
1517 out3 <<
"Extinction matrix: " << matrix_tmp <<
"\n";
1525 Matrix(stokes_dim, stokes_dim),
1534 if (atmosphere_dim == 1)
1535 cloudbox_field_mono(
1536 p_index - cloudbox_limits[0], 0, 0, za_index, 0,
joker) =
1538 else if (atmosphere_dim == 3)
1539 cloudbox_field_mono(p_index - cloudbox_limits[0],
1540 lat_index - cloudbox_limits[2],
1541 lon_index - cloudbox_limits[4],
1544 joker) = stokes_vec;
1551 const Agenda& surface_rtprop_agenda,
1553 const Index& f_index,
1554 const Index& stokes_dim,
1555 const Ppath& ppath_step,
1558 const Index& za_index) {
1559 chk_not_empty(
"surface_rtprop_agenda", surface_rtprop_agenda);
1575 rte_pos = ppath_step.
pos(np - 1,
Range(0, ppath_step.
dim));
1579 rte_los = ppath_step.
los(np - 1,
joker);
1588 Vector(1, f_grid[f_index]),
1591 surface_rtprop_agenda);
1593 iy = surface_emission;
1600 for (
Index ilos = 0; ilos < nlos; ilos++) {
1607 cloudbox_field_mono(cloudbox_limits[0],
1610 (za_grid.
nelem() - 1 - za_index),
1613 iy(0,
joker) += rtmp;
1616 cloudbox_field_mono(cloudbox_limits[0], 0, 0, za_index, 0,
joker) =
1622 const Index& accelerated,
1628 for (
Index i = 0;
i < accelerated; ++
i) {
1663 for (
Index p_index = 0; p_index < N_p; ++p_index) {
1664 for (
Index za_index = 0; za_index < N_za; ++za_index) {
1665 A1 += Q1(p_index, za_index) * Q1(p_index, za_index) *
1666 J(p_index, za_index);
1667 A2B1 += Q2(p_index, za_index) * Q1(p_index, za_index) *
1668 J(p_index, za_index);
1669 B2 += Q2(p_index, za_index) * Q2(p_index, za_index) *
1670 J(p_index, za_index);
1671 C1 += Q1(p_index, za_index) * Q3(p_index, za_index) *
1672 J(p_index, za_index);
1673 C2 += Q2(p_index, za_index) * Q3(p_index, za_index) *
1674 J(p_index, za_index);
1678 NGA = (C1 * B2 - C2 * A2B1) / (A1 * B2 - A2B1 * A2B1);
1679 NGB = (C2 * A1 - C1 * A2B1) / (A1 * B2 - A2B1 * A2B1);
1681 if (!std::isnan(NGB) && !std::isnan(NGA)) {
1683 for (
Index p_index = 0; p_index < N_p; ++p_index) {
1684 for (
Index za_index = 0; za_index < N_za; ++za_index) {
1685 Q1(p_index, za_index) = (1 - NGA - NGB) * S4(p_index, za_index) +
1686 NGA * S3(p_index, za_index) +
1687 NGB * S2(p_index, za_index);
1690 cloudbox_field_mono(joker, 0, 0, joker, 0,
i) = Q1;
1711 const Ppath& ppath_step,
1714 const Index& scat_za_interp,
1719 const Index stokes_dim = cloudbox_field_mono.
ncols();
1728 cloud_gp_p[
i].idx -= cloudbox_limits[0];
1731 const Index n1 = cloudbox_limits[1] - cloudbox_limits[0];
1744 gridpos(gp_za, za_grid, los_grid);
1753 for (
Index i = 0;
i < stokes_dim;
i++) {
1756 out3 <<
"Interpolate ext_mat:\n";
1757 for (
Index j = 0; j < stokes_dim; j++) {
1763 ext_mat_field(
joker, 0, 0,
i, j),
1770 out3 <<
"Interpolate abs_vec:\n";
1772 abs_vec_int(
i,
joker), itw, abs_vec_field(
joker, 0, 0,
i), cloud_gp_p);
1778 out3 <<
"Interpolate doit_scat_field and cloudbox_field_mono:\n";
1779 if (scat_za_interp == 0)
1791 }
else if (scat_za_interp == 1)
1797 stokes_dim, ppath_step.
np, za_grid.
nelem(), 0.);
1798 Tensor3 cloudbox_field_mono_int_za(
1799 stokes_dim, ppath_step.
np, za_grid.
nelem(), 0.);
1800 for (
Index za = 0; za < za_grid.
nelem(); za++) {
1803 doit_scat_field(
joker, 0, 0, za, 0,
i),
1805 out3 <<
"Interpolate cloudbox_field_mono:\n";
1808 cloudbox_field_mono(
joker, 0, 0, za, 0,
i),
1811 for (
Index ip = 0; ip < ppath_step.
np; ip++) {
1813 sca_vec_int_za(
i, ip,
joker),
1816 cloudbox_field_mono_int(
i, ip) =
1818 cloudbox_field_mono_int_za(
i, ip,
joker),
1829 out3 <<
"Interpolate temperature field\n";
1842 for (
Index i_sp = 0; i_sp < N_species; i_sp++) {
1843 out3 <<
"Interpolate vmr field\n";
1845 vmr_list_int(i_sp,
joker) = vmr_int;
1850 itw2p(p_int, p_grid, ppath_step.
gp_p, itw);
1855 Matrix& cloudbox_field_opt,
1860 const Index& scat_za_interp) {
1863 assert(cloudbox_field_mono.
npages() == N_za);
1867 Vector i_approx_interp(N_za);
1872 idx.push_back(N_za - 1);
1887 while (max_diff > acc) {
1895 for (
Index i_p = 0; i_p < N_p; i_p++) {
1896 for (
Index i_za_red = 0; i_za_red < idx.
nelem(); i_za_red++) {
1897 za_reduced[i_za_red] = za_grid_fine[idx[i_za_red]];
1898 cloudbox_field_opt(i_p, i_za_red) =
1899 cloudbox_field_mono(i_p, 0, 0, idx[i_za_red], 0, 0);
1902 gridpos(gp_za, za_reduced, za_grid_fine);
1904 if (scat_za_interp == 0 || idx.
nelem() < 3) {
1906 interp(i_approx_interp, itw, cloudbox_field_opt(i_p,
joker), gp_za);
1907 }
else if (scat_za_interp == 1) {
1908 for (
Index i_za = 0; i_za < N_za; i_za++) {
1910 cloudbox_field_opt(i_p,
joker),
1920 for (
Index i_za = 0; i_za < N_za; i_za++) {
1921 diff_vec[i_za] =
abs(cloudbox_field_mono(i_p, 0, 0, i_za, 0, 0) -
1922 i_approx_interp[i_za]);
1923 if (diff_vec[i_za] > max_diff_za[i_p]) {
1924 max_diff_za[i_p] = diff_vec[i_za];
1929 if (max_diff_za[i_p] > max_diff_p) {
1930 max_diff_p = max_diff_za[i_p];
1937 max_diff_p / cloudbox_field_mono(ind_p, 0, 0, ind_za[ind_p], 0, 0) * 100.;
1939 idx.push_back(ind_za[ind_p]);
1942 i_sort.resize(idx_unsorted.
nelem());
1946 idx[
i] = idx_unsorted[i_sort[
i]];
1954 za_grid_opt[
i] = za_grid_fine[idx[
i]];
1955 cloudbox_field_opt(
joker,
i) = cloudbox_field_mono(
joker, 0, 0, idx[
i], 0, 0);
1961 const Tensor6& cloudbox_field_mono,
1963 const Agenda& spt_calc_agenda,
1964 const Index& atmosphere_dim,
1969 const Numeric& norm_error_threshold,
1970 const Index& norm_debug,
1972 if (atmosphere_dim != 1)
1973 throw runtime_error(
"Only 1D is supported here for now");
1981 if (za_grid[0] != 0. || za_grid[Nza - 1] != 180.)
1982 throw runtime_error(
"The range of *za_grid* must [0 180].");
1987 if (Naa > 1 && (aa_grid[0] != 0. || aa_grid[Naa - 1] != 360.))
1988 throw runtime_error(
"The range of *aa_grid* must [0 360].");
1991 const Index stokes_dim = doit_scat_field.
ncols();
1992 assert(stokes_dim > 0 || stokes_dim < 5);
1996 Tensor5 ext_mat_field(cloudbox_limits[1] - cloudbox_limits[0] + 1,
2003 cloudbox_limits[1] - cloudbox_limits[0] + 1, 1, 1, stokes_dim, 0.);
2009 doit_scat_field.
nbooks(),
2010 doit_scat_field.
npages(),
2011 doit_scat_field.
nrows(),
2014 Index aa_index_local = 0;
2017 for (
Index za_index_local = 0; za_index_local < Nza;
2033 for (
Index p_index = 0;
2034 p_index <= (cloudbox_limits[1] - cloudbox_limits[0]);
2040 for (
Index i = 0;
i < stokes_dim;
i++) {
2041 doit_scat_ext_field(p_index, 0, 0, za_index_local, 0) +=
2042 cloudbox_field_mono(p_index, 0, 0, za_index_local, 0,
i) *
2043 (ext_mat_field(p_index, 0, 0, 0,
i) -
2044 abs_vec_field(p_index, 0, 0,
i));
2050 Index corr_max_p_index = -1;
2052 for (
Index p_index = 0; p_index < Np; p_index++) {
2055 doit_scat_field(p_index, 0, 0,
joker, 0, 0), za_grid);
2058 doit_scat_ext_field(p_index, 0, 0,
joker, 0), za_grid);
2062 const Numeric corr_factor = scat_ext_int / scat_int;
2066 if (!std::isnan(corr_factor) && !std::isinf(corr_factor)) {
2067 if (
abs(corr_factor) >
abs(corr_max)) {
2068 corr_max = corr_factor;
2069 corr_max_p_index = p_index;
2072 out0 <<
" DOIT corr_factor: " << 1. - corr_factor
2073 <<
" ( scat_ext_int: " << scat_ext_int
2074 <<
", scat_int: " << scat_int <<
")" 2075 <<
" at p_index " << p_index <<
"\n";
2077 if (
abs(1. - corr_factor) > norm_error_threshold) {
2079 os <<
"ERROR: DOIT correction factor exceeds threshold (=" 2080 << norm_error_threshold <<
"): " << setprecision(4)
2081 << 1. - corr_factor <<
" at p_index " << p_index <<
"\n";
2082 throw runtime_error(os.
str());
2083 }
else if (
abs(1. - corr_factor) > norm_error_threshold / 2.) {
2084 out0 <<
" WARNING: DOIT correction factor above threshold/2: " 2085 << 1. - corr_factor <<
" at p_index " << p_index <<
"\n";
2089 doit_scat_field(p_index, 0, 0,
joker, 0,
joker) *= corr_factor;
2090 }
else if (norm_debug) {
2091 out0 <<
" DOIT corr_factor ignored: " << 1. - corr_factor
2092 <<
" ( scat_ext_int: " << scat_ext_int <<
", scat_int: " << scat_int
2094 <<
" at p_index " << p_index <<
"\n";
2099 if (corr_max_p_index != -1) {
2100 os <<
" Max. DOIT correction factor in this iteration: " << 1. - corr_max
2101 <<
" at p_index " << corr_max_p_index <<
"\n";
2103 os <<
" No DOIT correction performed in this iteration.\n";
INDEX Index
The type to use for all integer numbers and indices.
ArrayOfGridPos gp_lat
Index position with respect to the latitude grid.
void surface_rtprop_agendaExecute(Workspace &ws, Numeric &surface_skin_t, Matrix &surface_emission, Matrix &surface_los, Tensor4 &surface_rmatrix, const Vector &f_grid, const Vector &rtp_pos, const Vector &rtp_los, const Agenda &input_agenda)
Numeric interp_poly(ConstVectorView x, ConstVectorView y, const Numeric &x_i, const GridPos &gp)
Polynomial interpolation.
VectorView VectorAtPosition(const Index iv=0, const Index iz=0, const Index ia=0)
Get a vectorview to the position.
Index nrows() const
Returns the number of rows.
void opt_prop_bulkCalc(PropagationMatrix &ext_mat, StokesVector &abs_vec, const ArrayOfPropagationMatrix &ext_mat_spt, const ArrayOfStokesVector &abs_vec_spt, const Tensor4 &pnd_field, const Index &scat_p_index, const Index &scat_lat_index, const Index &scat_lon_index, const Verbosity &)
WORKSPACE METHOD: opt_prop_bulkCalc.
Index nelem() const
Number of elements.
Declarations having to do with the four output streams.
void gridpos_upperend_check(GridPos &gp, const Index &ie)
gridpos_upperend_check
void MatrixAtPosition(MatrixView ret, const Index iv=0, const Index iz=0, const Index ia=0) const
Sets the dense matrix.
Matrix los
Line-of-sight at each ppath point.
Index nvitrines() const
Returns the number of vitrines.
Numeric interp(ConstVectorView itw, ConstVectorView a, const GridPos &tc)
Red 1D Interpolate.
Index dim
Atmospheric dimensionality.
A constant view of a Tensor6.
void ppath_step_agendaExecute(Workspace &ws, Ppath &ppath_step, const Numeric ppath_lmax, const Numeric ppath_lraytrace, const Vector &f_grid, const Agenda &input_agenda)
Array< RetrievalQuantity > ArrayOfRetrievalQuantity
Vector lstep
The length between ppath points.
Linear algebra functions.
void spt_calc_agendaExecute(Workspace &ws, ArrayOfPropagationMatrix &ext_mat_spt, ArrayOfStokesVector &abs_vec_spt, const Index scat_p_index, const Index scat_lat_index, const Index scat_lon_index, const Numeric rtp_temperature, const Index za_index, const Index aa_index, const Agenda &input_agenda)
void MatrixInverseAtPosition(MatrixView ret, const Index iv=0, const Index iz=0, const Index ia=0) const
Return the matrix inverse at the position.
void cloudbox_field_ngAcceleration(Tensor6 &cloudbox_field_mono, const ArrayOfTensor6 &acceleration_input, const Index &accelerated, const Verbosity &)
Convergence acceleration.
invlib::Vector< ArtsVector > Vector
invlib wrapper type for ARTS vectors.
Matrix pos
The distance between start pos and the last position in pos.
This file contains basic functions to handle XML data files.
void cloud_ppath_update3D(Workspace &ws, Tensor6View cloudbox_field_mono, const Index &p_index, const Index &lat_index, const Index &lon_index, const Index &za_index, const Index &aa_index, ConstVectorView za_grid, ConstVectorView aa_grid, const ArrayOfIndex &cloudbox_limits, ConstTensor6View doit_scat_field, const Agenda &propmat_clearsky_agenda, ConstTensor4View vmr_field, const Agenda &ppath_step_agenda, const Numeric &ppath_lmax, const Numeric &ppath_lraytrace, ConstVectorView p_grid, ConstVectorView lat_grid, ConstVectorView lon_grid, ConstTensor3View z_field, ConstVectorView refellipsoid, ConstTensor3View t_field, ConstVectorView f_grid, const Index &f_index, ConstTensor5View ext_mat_field, ConstTensor4View abs_vec_field, const Index &, const Verbosity &verbosity)
Radiative transfer calculation along a path inside the cloudbox (3D).
Vector r
Radius of each ppath point.
Stokes vector is as Propagation matrix but only has 4 possible values.
void opt_prop_sum_propmat_clearsky(PropagationMatrix &ext_mat, StokesVector &abs_vec, const ArrayOfPropagationMatrix &propmat_clearsky)
Get optical properties from propmat_clearsky.
void cloud_RT_no_background(Workspace &ws, Tensor6View cloudbox_field_mono, const Agenda &propmat_clearsky_agenda, const Ppath &ppath_step, ConstVectorView t_int, ConstMatrixView vmr_list_int, ConstTensor3View ext_mat_int, ConstMatrixView abs_vec_int, ConstMatrixView sca_vec_int, ConstMatrixView cloudbox_field_mono_int, ConstVectorView p_int, const ArrayOfIndex &cloudbox_limits, ConstVectorView f_grid, const Index &f_index, const Index &p_index, const Index &lat_index, const Index &lon_index, const Index &za_index, const Index &aa_index, const Verbosity &verbosity)
Calculates RT in the cloudbox (1D)
Index nelem() const
Returns the number of elements.
void rte_step_doit_replacement(VectorView stokes_vec, MatrixView trans_mat, const PropagationMatrix &ext_mat_av, const StokesVector &abs_vec_av, ConstVectorView sca_vec_av, const Numeric &lstep, const Numeric &rtp_planck_value, const bool &trans_is_precalc)
Solves monochromatic VRTE for an atmospheric slab with constant conditions.
Contains sorting routines.
A constant view of a Tensor4.
Index ppath_what_background(const Ppath &ppath)
Returns the case number for the radiative background.
This file contains the definition of Array.
Index ncols() const
Returns the number of columns.
void swap(ComplexVector &v1, ComplexVector &v2)
Swaps two objects.
void AddAverageAtPosition(ConstMatrixView mat1, ConstMatrixView mat2, const Index iv=0, const Index iz=0, const Index ia=0)
Add the average of the two input at position.
_CS_string_type str() const
Stuff related to the propagation matrix.
Declarations for agendas.
void ppath_init_structure(Ppath &ppath, const Index &atmosphere_dim, const Index &np)
Initiates a Ppath structure to hold the given number of points.
void cloud_fieldsCalc(Workspace &ws, Tensor5View ext_mat_field, Tensor4View abs_vec_field, const Agenda &spt_calc_agenda, const Index &za_index, const Index &aa_index, const ArrayOfIndex &cloudbox_limits, ConstTensor3View t_field, ConstTensor4View pnd_field, const Verbosity &verbosity)
Calculate ext_mat, abs_vec for all points inside the cloudbox for one.
Index nrows() const
Returns the number of rows.
void gridpos(ArrayOfGridPos &gp, ConstVectorView old_grid, ConstVectorView new_grid, const Numeric &extpolfac)
Set up a grid position Array.
bool is_inside_cloudbox(const Ppath &ppath_step, const ArrayOfIndex &cloudbox_limits, const bool include_boundaries)
A constant view of a Tensor5.
NUMERIC Numeric
The type to use for all floating point numbers.
Index StokesDimensions() const
The stokes dimension of the propagation matrix.
Numeric refell2r(ConstVectorView refellipsoid, const Numeric &lat)
refell2r
Header file for special_interp.cc.
Propagation path structure and functions.
void get_sorted_indexes(ArrayOfIndex &sorted, const T &data)
get_sorted_indexes
void mult(ComplexVectorView y, const ConstComplexMatrixView &M, const ConstComplexVectorView &x)
Matrix-Vector Multiplication.
Header file for logic.cc.
Radiative transfer in cloudbox.
Index NumberOfFrequencies() const
The number of frequencies of the propagation matrix.
This can be used to make arrays out of anything.
Index nshelves() const
Returns the number of shelves.
bool is_singular(ConstMatrixView A)
Checks if a square matrix is singular.
Index ncols() const
Returns the number of columns.
VectorView Kjj(const Index iz=0, const Index ia=0)
Vector view to diagonal elements.
void resize(Index n)
Resize function.
A constant view of a Tensor3.
void interp_cloud_coeff1D(Tensor3View ext_mat_int, MatrixView abs_vec_int, MatrixView sca_vec_int, MatrixView cloudbox_field_mono_int, VectorView t_int, MatrixView vmr_list_int, VectorView p_int, ConstTensor5View ext_mat_field, ConstTensor4View abs_vec_field, ConstTensor6View doit_scat_field, ConstTensor6View cloudbox_field_mono, ConstTensor3View t_field, ConstTensor4View vmr_field, ConstVectorView p_grid, const Ppath &ppath_step, const ArrayOfIndex &cloudbox_limits, ConstVectorView za_grid, const Index &scat_za_interp, const Verbosity &verbosity)
Interpolate all inputs of the VRTE on a propagation path step.
A constant view of a Vector.
Index np
Number of points describing the ppath.
void doit_scat_fieldNormalize(Workspace &ws, Tensor6 &doit_scat_field, const Tensor6 &cloudbox_field_mono, const ArrayOfIndex &cloudbox_limits, const Agenda &spt_calc_agenda, const Index &atmosphere_dim, const Vector &za_grid, const Vector &aa_grid, const Tensor4 &pnd_field, const Tensor3 &t_field, const Numeric &norm_error_threshold, const Index &norm_debug, const Verbosity &verbosity)
Normalization of scattered field.
ArrayOfGridPos gp_lon
Index position with respect to the longitude grid.
Index npages() const
Returns the number of pages.
A constant view of a Matrix.
void cloud_ppath_update1D_noseq(Workspace &ws, Tensor6View cloudbox_field_mono, const Index &p_index, const Index &za_index, ConstVectorView za_grid, const ArrayOfIndex &cloudbox_limits, ConstTensor6View cloudbox_field_mono_old, ConstTensor6View doit_scat_field, const Agenda &propmat_clearsky_agenda, ConstTensor4View vmr_field, const Agenda &ppath_step_agenda, const Numeric &ppath_lmax, const Numeric &ppath_lraytrace, ConstVectorView p_grid, ConstTensor3View z_field, ConstVectorView refellipsoid, ConstTensor3View t_field, ConstVectorView f_grid, const Index &f_index, ConstTensor5View ext_mat_field, ConstTensor4View abs_vec_field, const Agenda &surface_rtprop_agenda, const Index &scat_za_interp, const Verbosity &verbosity)
Calculation of radiation field along a propagation path step for specified zenith direction and press...
Numeric planck(const Numeric &f, const Numeric &t)
planck
Index nbooks() const
Returns the number of books.
Index ncols() const
Returns the number of columns.
bool is_size(ConstVectorView x, const Index &n)
Verifies that the size of x is l.
void id_mat(MatrixView I)
Identity Matrix.
void propmat_clearsky_agendaExecute(Workspace &ws, ArrayOfPropagationMatrix &propmat_clearsky, ArrayOfStokesVector &nlte_source, ArrayOfPropagationMatrix &dpropmat_clearsky_dx, ArrayOfStokesVector &dnlte_dx_source, ArrayOfStokesVector &nlte_dsource_dx, const ArrayOfRetrievalQuantity &jacobian_quantities, const Vector &f_grid, const Vector &rtp_mag, const Vector &rtp_los, const Numeric rtp_pressure, const Numeric rtp_temperature, const EnergyLevelMap &rtp_nlte, const Vector &rtp_vmr, const Agenda &input_agenda)
The structure to describe a propagation path and releated quantities.
Internal cloudbox functions.
Index ncols() const
Returns the number of columns.
void cloud_ppath_update1D_planeparallel(Workspace &ws, Tensor6View cloudbox_field_mono, const Index &p_index, const Index &za_index, ConstVectorView za_grid, const ArrayOfIndex &cloudbox_limits, ConstTensor6View doit_scat_field, const Agenda &propmat_clearsky_agenda, ConstTensor4View vmr_field, ConstVectorView p_grid, ConstTensor3View z_field, ConstTensor3View t_field, ConstVectorView f_grid, const Index &f_index, ConstTensor5View ext_mat_field, ConstTensor4View abs_vec_field, const Verbosity &verbosity)
Radiative transfer calculation inside cloudbox for planeparallel case.
void interpweights(VectorView itw, const GridPos &tc)
Red 1D interpolation weights.
void cloud_ppath_update1D(Workspace &ws, Tensor6View cloudbox_field_mono, const Index &p_index, const Index &za_index, ConstVectorView za_grid, const ArrayOfIndex &cloudbox_limits, ConstTensor6View doit_scat_field, const Agenda &propmat_clearsky_agenda, ConstTensor4View vmr_field, const Agenda &ppath_step_agenda, const Numeric &ppath_lmax, const Numeric &ppath_lraytrace, ConstVectorView p_grid, ConstTensor3View z_field, ConstVectorView refellipsoid, ConstTensor3View t_field, ConstVectorView f_grid, const Index &f_index, ConstTensor5View ext_mat_field, ConstTensor4View abs_vec_field, const Agenda &surface_rtprop_agenda, const Index &scat_za_interp, const Verbosity &verbosity)
Calculates radiation field along a propagation path step for specified zenith direction and pressure ...
void AddAverageAtPosition(ConstVectorView vec1, ConstVectorView vec2, const Index iv=0, const Index iz=0, const Index ia=0)
Add the average of both inputs at position.
invlib::Matrix< ArtsMatrix > Matrix
invlib wrapper type for ARTS matrices.
This file contains declerations of functions of physical character.
Index nrows() const
Returns the number of rows.
ArrayOfGridPos gp_p
Index position with respect to the pressure grid.
void cloud_RT_surface(Workspace &ws, Tensor6View cloudbox_field_mono, const Agenda &surface_rtprop_agenda, ConstVectorView f_grid, const Index &f_index, const Index &stokes_dim, const Ppath &ppath_step, const ArrayOfIndex &cloudbox_limits, ConstVectorView za_grid, const Index &za_index)
Calculates RT in the cloudbox.
Numeric AngIntegrate_trapezoid(ConstMatrixView Integrand, ConstVectorView za_grid, ConstVectorView aa_grid)
AngIntegrate_trapezoid.
void itw2p(VectorView p_values, ConstVectorView p_grid, const ArrayOfGridPos &gp, ConstMatrixView itw)
Converts interpolation weights to pressures.
Declaration of functions in rte.cc.
void compute_transmission_matrix_from_averaged_matrix_at_frequency(MatrixView T, const Numeric &r, const PropagationMatrix &averaged_propagation_matrix, const Index iv, const Index iz, const Index ia)
Compute the matrix exponent as the transmission matrix of this propagation matrix.
void resize(Index r, Index c)
Resize function.
void za_gridOpt(Vector &za_grid_opt, Matrix &cloudbox_field_opt, ConstVectorView za_grid_fine, ConstTensor6View cloudbox_field_mono, const Numeric &acc, const Index &scat_za_interp)
Optimize the zenith angle grid.
Index nbooks() const
Returns the number of books.