Go to the documentation of this file.
65 fs = exp(-kI * s) * (I * cosh(kQ * s) + Q * sinh(kQ * s));
160 fa =
ext_I(I, Q, KI, KQ, sa);
162 fb =
ext_I(I, Q, KI, KQ, sb);
170 macheps = DBL_EPSILON;
182 tol = 2.0 * macheps *
abs(sb) + t;
185 if (
abs(m) <= tol || fb == 0.0) {
189 if (
abs(e) < tol ||
abs(fa) <=
abs(fb)) {
201 p = s * (2.0 * m *
q * (
q - r) - (sb - sa) * (r - 1.0));
202 q = (
q - 1.0) * (r - 1.0) * (s - 1.0);
214 if (2.0 * p < 3.0 * m *
q -
abs(tol *
q) && p <
abs(0.5 * s *
q)) {
226 }
else if (0.0 < m) {
232 fb =
ext_I(I, Q, KI, KQ, sb);
235 if ((0.0 < fb && 0.0 < fc) || (fb <= 0.0 && fc <= 0.0)) {
272 ao_gp_lat[0] = gp_lat;
273 ao_gp_lon[0] = gp_lon;
284 t_vec, 3,
t_field, ao_gp_p, ao_gp_lat, ao_gp_lon, itw_field);
286 for (
Index is = 0; is <
ns; is++) {
296 temperature = t_vec[0];
298 const Vector rtp_mag_dummy(3, 0);
299 const Vector ppath_los_dummy;
304 local_propmat_clearsky,
305 local_nlte_source_dummy,
307 local_dnlte_dx_source_dummy,
308 local_nlte_dsource_dx_dummy,
320 local_ext_mat, local_abs_vec, local_propmat_clearsky);
349 Matrix pnd_ppath(N_se, 1);
361 local_dnlte_dx_source_dummy;
363 local_nlte_dsource_dx_dummy;
370 ao_gp_lat[0] = gp_lat;
371 ao_gp_lon[0] = gp_lon;
385 pnd_vec = pnd_ppath(
joker, 0);
386 temperature = t_ppath[0];
388 const Vector rtp_mag_dummy(3, 0);
389 const Vector ppath_los_dummy;
393 local_propmat_clearsky,
394 local_nlte_source_dummy,
396 local_dnlte_dx_source_dummy,
397 local_nlte_dsource_dx_dummy,
409 local_ext_mat, local_abs_vec, local_propmat_clearsky);
427 Matrix dir_array(1, 2, 0.);
428 dir_array(0,
joker) = sca_dir;
455 ext_mat_mono += ext_mat_bulk(0, 0, 0,
joker,
joker);
456 abs_vec_mono += abs_vec_bulk(0, 0, 0,
joker);
472 assert(pressure.
nelem() == np);
480 for (
Index i = 0; i < np; i++) {
502 itw2p(pressure, p_grid_cloud, gp_p_cloud, itw_p);
509 itw_field,
atmosphere_dim, gp_p_cloud, gp_lat_cloud, gp_lon_cloud);
519 for (
Index is = 0; is <
ns; is++) {
531 for (
Index i_se = 0; i_se < N_se; i_se++) {
585 ppath.gp_lat[np - 1],
586 ppath.gp_lon[np - 1],
601 ppath.gp_lat[np - 1],
602 ppath.gp_lon[np - 1],
604 t_field(p_range, lat_range, lon_range),
618 ppath.gp_lat[np - 1],
619 ppath.gp_lon[np - 1],
626 trans_matArray[1] = trans_mat;
627 ext_matArray[1] = ext_mat_mono;
630 for (
Index ip = np - 2; ip >= 0; ip--) {
631 dl =
ppath.lstep[ip];
633 ext_matArray[0] = ext_matArray[1];
634 trans_matArray[0] = trans_matArray[1];
656 t_field(p_range, lat_range, lon_range),
678 ext_matArray[1] = ext_mat_mono;
683 Index extmat_case = 0;
687 mult(trans_mat, incT, trans_matArray[1]);
688 trans_matArray[1] = trans_mat;
722 Index& termination_flag,
761 evol_opArray[1] = evol_op;
820 t_field(p_range, lat_range, lon_range),
843 ext_matArray[1] = ext_mat_mono;
844 abs_vecArray[1] = abs_vec_mono;
845 tArray[1] = temperature;
846 pnd_vecArray[1] = pnd_vec;
851 termination_flag = 0;
853 while ((evol_op(0, 0) > r) && (!termination_flag)) {
856 if (istep > 100000) {
858 "100000 path points have been reached. "
859 "Is this an infinite loop?");
862 evol_opArray[0] = evol_opArray[1];
863 ext_matArray[0] = ext_matArray[1];
864 abs_vecArray[0] = abs_vecArray[1];
865 tArray[0] = tArray[1];
866 pnd_vecArray[0] = pnd_vecArray[1];
879 bool oktaustep =
false;
881 const Index lmax_limit = 10;
886 Numeric lmax = taustep_limit / ext_mat_mono(0, 0);
890 if (lmax < lmax_limit) {
928 t_field(p_range, lat_range, lon_range),
956 if (ppath_try > 1 || ext_mat_mono(0, 0) <= ext_matArray[0](0, 0) ||
957 (ext_mat_mono(0, 0) + ext_matArray[0](0, 0)) * dl / 2 <=
971 ext_matArray[1] = ext_mat_mono;
972 abs_vecArray[1] = abs_vec_mono;
973 tArray[1] = temperature;
974 pnd_vecArray[1] = pnd_vec;
979 Index extmat_case = 0;
983 mult(evol_op, evol_opArray[0], incT);
984 evol_opArray[1] = evol_op;
986 if (evol_op(0, 0) > r) {
993 termination_flag = 2;
997 termination_flag = 1;
1003 if (termination_flag) {
1016 ds = log(evol_opArray[0](0, 0) / r) / k;
1025 assert(gp[0].idx == 0);
1027 interp(ext_mat_mono, itw, ext_matArray, gp[0]);
1029 ext_mat += ext_matArray[gp[0].idx];
1032 Index extmat_case = 0;
1036 mult(evol_op, evol_opArray[gp[0].idx], incT);
1037 interp(abs_vec_mono, itw, abs_vecArray, gp[0]);
1038 temperature =
interp(itw, tArray, gp[0]);
1039 interp(pnd_vec, itw, pnd_vecArray, gp[0]);
1040 for (
Index i = 0; i < 2; i++) {
1047 assert(isfinite(g));
1050 const Index np = ip + 1;
1066 Index& termination_flag,
1072 const bool& anyptype_nonTotRan,
1098 Numeric ds, dt = -999, dl = -999;
1111 evol_opArray[1] = evol_op;
1138 termination_flag = 1;
1155 local_rte_los[0] = 180 -
ppath_step.los(0, 0);
1156 local_rte_los[1] =
ppath_step.los(0, 1) - 180;
1170 t_field(p_range, lat_range, lon_range),
1193 ext_matArray[1] = ext_mat_mono;
1194 abs_vecArray[1] = abs_vec_mono;
1195 tArray[1] = temperature;
1196 pnd_vecArray[1] = pnd_vec;
1201 termination_flag = 0;
1207 while ((evop0 > r) && (!termination_flag)) {
1210 if (istep > 25000) {
1211 throw runtime_error(
1212 "25000 path points have been reached. "
1213 "Is this an infinite loop?");
1216 evol_opArray[0] = evol_opArray[1];
1217 ext_matArray[0] = ext_matArray[1];
1218 abs_vecArray[0] = abs_vecArray[1];
1219 tArray[0] = tArray[1];
1220 pnd_vecArray[0] = pnd_vecArray[1];
1233 termination_flag = 1;
1252 local_rte_los[0] = 180 -
ppath_step.los(ip, 0);
1253 local_rte_los[1] =
ppath_step.los(ip, 1) - 180;
1267 t_field(p_range, lat_range, lon_range),
1289 ext_matArray[1] = ext_mat_mono;
1290 abs_vecArray[1] = abs_vec_mono;
1291 tArray[1] = temperature;
1292 pnd_vecArray[1] = pnd_vec;
1297 Index extmat_case = 0;
1302 mult(evol_op, incT, evol_opArray[0]);
1303 evol_opArray[1] = evol_op;
1304 evop0 = evol_op(0, 0);
1308 const Numeric Q1 = evol_op(0, 1) * Iprop[1] / Iprop[0];
1318 termination_flag = 2;
1322 termination_flag = 1;
1328 if (termination_flag != 0) {
1344 if (anyptype_nonTotRan) {
1345 const Numeric I1 = evol_opArray[0](0, 0);
1346 const Numeric Q1 = evol_opArray[0](0, 1) * Iprop[1] / Iprop[0];
1353 ds = log(evol_opArray[0](0, 0) / r) / kI;
1356 ttot += ds * dt / dl;
1364 assert(gp[0].idx == 0);
1366 interp(ext_mat_mono, itw, ext_matArray, gp[0]);
1368 ext_mat += ext_matArray[gp[0].idx];
1371 Index extmat_case = 0;
1375 mult(evol_op, incT, evol_opArray[gp[0].idx]);
1376 interp(abs_vec_mono, itw, abs_vecArray, gp[0]);
1377 temperature =
interp(itw, tArray, gp[0]);
1378 interp(pnd_vec, itw, pnd_vecArray, gp[0]);
1379 for (
Index i = 0; i < 2; i++) {
1387 const Index np = ip + 1;
1403 const Index t_interp_order) {
1405 bool tryagain =
true;
1413 for (
Index i = 0; i < np; i++) {
1414 Z11max += Z11maxvector[i] * pnd_vec[i];
1429 Matrix pdir(1, 2), idir(1, 2);
1432 pnds(
joker, 0) = pnd_vec;
1435 new_rte_los[0] = acos(1 - 2 * rng.
draw()) *
RAD2DEG;
1436 new_rte_los[1] = rng.
draw() * 360 - 180;
1446 pdir(0,
joker) = sca_dir;
1447 idir(0,
joker) = inc_dir;
1459 pha_mat_ssbulk, ptype_ssbulk, pha_mat_Nse, ptypes_Nse, pnds, t_ok);
1460 pha_mat_Bulk(pha_mat_bulk, ptype_bulk, pha_mat_ssbulk, ptype_ssbulk);
1463 if (rng.
draw() <= Z(0, 0) / Z11max)
1468 g_los_csc_theta = Z(0, 0) / Csca;
1472 new_rte_los[1] = rng.
draw() * 360 - 180;
1473 new_rte_los[0] = acos(1 - 2 * rng.
draw()) *
RAD2DEG;
void MatrixAtPosition(MatrixView ret, const Index iv=0, const Index iz=0, const Index ia=0) const
Sets the dense matrix.
Index atmosphere_dim(Workspace &ws) noexcept
std::size_t pos() const noexcept
Ppath ppath_step(Workspace &ws) noexcept
Tensor3 z_field(Workspace &ws) noexcept
Stokes vector is as Propagation matrix but only has 4 possible values.
Agenda ppath_step_agenda(Workspace &ws) noexcept
void gridpos(ArrayOfGridPos &gp, ConstVectorView old_grid, ConstVectorView new_grid, const Numeric &extpolfac)
Set up a grid position Array.
void mcPathTraceGeneral(Workspace &ws, MatrixView evol_op, Vector &abs_vec_mono, Numeric &temperature, MatrixView ext_mat_mono, Rng &rng, Vector &rte_pos, Vector &rte_los, Vector &pnd_vec, Numeric &g, Ppath &ppath_step, Index &termination_flag, bool &inside_cloud, const Agenda &ppath_step_agenda, const Numeric &ppath_lmax, const Numeric &ppath_lraytrace, const Numeric &taustep_limit, const Agenda &propmat_clearsky_agenda, const Index stokes_dim, const Index f_index, const Vector &f_grid, const Vector &p_grid, const Vector &lat_grid, const Vector &lon_grid, const Tensor3 &z_field, const Vector &refellipsoid, const Matrix &z_surface, const Tensor3 &t_field, const Tensor4 &vmr_field, const ArrayOfIndex &cloudbox_limits, const Tensor4 &pnd_field, const ArrayOfArrayOfSingleScatteringData &scat_data, const Verbosity &verbosity)
mcPathTraceGeneral.
void id_mat(MatrixView I)
Identity Matrix.
Interpolation classes and functions created for use within Monte Carlo scattering simulations.
void itw2p(VectorView p_values, ConstVectorView p_grid, const ArrayOfGridPos &gp, ConstMatrixView itw)
Converts interpolation weights to pressures.
const Numeric RAD2DEG
Global constant, conversion from radians to degrees.
Vector lat_grid(Workspace &ws) noexcept
Tensor4 pnd_field(Workspace &ws) noexcept
Numeric interp(ConstVectorView itw, ConstVectorView a, const GridPos &tc)
Red 1D Interpolate.
Verbosity verbosity(Workspace &ws) noexcept
void mult(ComplexVectorView y, const ConstComplexMatrixView &M, const ConstComplexVectorView &x)
Matrix-Vector Multiplication.
void interp_atmfield_by_itw(VectorView x, const Index &atmosphere_dim, ConstTensor3View x_field, const ArrayOfGridPos &gp_p, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon, ConstMatrixView itw)
Interpolates an atmospheric field with pre-calculated weights by interp_atmfield_gp2itw.
Index f_index(Workspace &ws) noexcept
ArrayOfIndex cloudbox_limits(Workspace &ws) noexcept
void brent_zero(Numeric &sb, const Numeric &a, const Numeric &b, const Numeric &t, const Numeric &rn, const Numeric &I, const Numeric &Q, const Numeric &KI, const Numeric &KQ)
brent_zero.
bool is_gp_inside_cloudbox(const GridPos &gp_p, const GridPos &gp_lat, const GridPos &gp_lon, const ArrayOfIndex &cloudbox_limits, const bool &include_boundaries, const Index &atmosphere_dim)
void opt_prop_ScatSpecBulk(ArrayOfTensor5 &ext_mat, ArrayOfTensor4 &abs_vec, ArrayOfIndex &ptype, const ArrayOfArrayOfTensor5 &ext_mat_se, const ArrayOfArrayOfTensor4 &abs_vec_se, const ArrayOfArrayOfIndex &ptypes_se, ConstMatrixView pnds, ConstMatrixView t_ok)
Scattering species bulk extinction and absorption.
Numeric fractional_gp(const GridPos &gp)
fractional_gp
Index stokes_dim(Workspace &ws) noexcept
Array< RetrievalQuantity > ArrayOfRetrievalQuantity
void mcPathTraceRadar(Workspace &ws, MatrixView evol_op, Vector &abs_vec_mono, Numeric &temperature, MatrixView ext_mat_mono, Rng &rng, Vector &rte_pos, Vector &rte_los, Vector &pnd_vec, Numeric &stot, Numeric &ttot, Ppath &ppath_step, Index &termination_flag, bool &inside_cloud, const Agenda &ppath_step_agenda, const Numeric &ppath_lmax, const Numeric &ppath_lraytrace, const Agenda &propmat_clearsky_agenda, const bool &anyptype_nonTotRan, const Index stokes_dim, const Index f_index, const Vector &f_grid, const Vector &Iprop, const Vector &p_grid, const Vector &lat_grid, const Vector &lon_grid, const Tensor3 &z_field, const Vector &refellipsoid, const Matrix &z_surface, const Tensor3 &t_field, const Tensor4 &vmr_field, const ArrayOfIndex &cloudbox_limits, const Tensor4 &pnd_field, const ArrayOfArrayOfSingleScatteringData &scat_data, const Verbosity &verbosity)
mcPathTraceRadar.
Index TotalNumberOfElements(const Array< Array< base > > &aa)
Determine total number of elements in an ArrayOfArray.
void Sample_los_uniform(VectorView new_rte_los, Rng &rng)
Sample_los_uniform.
The structure to describe a propagation path and releated quantities.
A constant view of a Tensor4.
void opt_prop_NScatElems(ArrayOfArrayOfTensor5 &ext_mat, ArrayOfArrayOfTensor4 &abs_vec, ArrayOfArrayOfIndex &ptypes, Matrix &t_ok, const ArrayOfArrayOfSingleScatteringData &scat_data, const Index &stokes_dim, const Vector &T_array, const Matrix &dir_array, const Index &f_index, const Index &t_interp_order)
Extinction and absorption from all scattering elements.
This can be used to make arrays out of anything.
double draw()
Draws a double from the uniform distribution [0,1)
bool is_anyptype_nonTotRan(const ArrayOfArrayOfSingleScatteringData &scat_data)
is_anyptype_nonTotRan.
void Sample_los(VectorView new_rte_los, Numeric &g_los_csc_theta, MatrixView Z, Rng &rng, ConstVectorView rte_los, const ArrayOfArrayOfSingleScatteringData &scat_data, const Index f_index, const Index stokes_dim, ConstVectorView pnd_vec, ConstVectorView Z11maxvector, const Numeric Csca, const Numeric rtp_temperature, const Index t_interp_order)
Sample_los.
void pha_mat_Bulk(Tensor6 &pha_mat, Index &ptype, const ArrayOfTensor6 &pha_mat_ss, const ArrayOfIndex &ptypes_ss)
Scattering species bulk phase matrix.
Vector rte_pos(Workspace &ws) noexcept
void gridpos_upperend_check(GridPos &gp, const Index &ie)
gridpos_upperend_check
Index nelem() const
Returns the number of elements.
Tensor4 vmr_field(Workspace &ws) noexcept
Vector rte_los(Workspace &ws) noexcept
Vector p_grid(Workspace &ws) noexcept
Ppath ppath(Workspace &ws) noexcept
NUMERIC Numeric
The type to use for all floating point numbers.
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)
void pha_mat_NScatElems(ArrayOfArrayOfTensor6 &pha_mat, ArrayOfArrayOfIndex &ptypes, Matrix &t_ok, const ArrayOfArrayOfSingleScatteringData &scat_data, const Index &stokes_dim, const Vector &T_array, const Matrix &pdir_array, const Matrix &idir_array, const Index &f_index, const Index &t_interp_order)
Phase matrices from all scattering elements.
Index nbooks() const
Returns the number of books.
Vector refellipsoid(Workspace &ws) noexcept
Vector f_grid(Workspace &ws) noexcept
PropagationMatrix ext_mat(Workspace &ws) noexcept
ArrayOfArrayOfSingleScatteringData scat_data(Workspace &ws) noexcept
void clear_rt_vars_at_gp(Workspace &ws, MatrixView ext_mat_mono, VectorView abs_vec_mono, Numeric &temperature, const Agenda &propmat_clearsky_agenda, const Numeric &f_mono, const GridPos &gp_p, const GridPos &gp_lat, const GridPos &gp_lon, ConstVectorView p_grid, ConstTensor3View t_field, ConstTensor4View vmr_field)
clear_rt_vars_at_gp.
Vector lon_grid(Workspace &ws) noexcept
Numeric ppath_lmax(Workspace &ws) noexcept
Numeric ppath_lraytrace(Workspace &ws) noexcept
invlib::Vector< ArtsVector > Vector
invlib wrapper type for ARTS vectors.
Structure to store a grid position.
void ppath_start_stepping(Ppath &ppath, const Index &atmosphere_dim, ConstVectorView p_grid, ConstVectorView lat_grid, ConstVectorView lon_grid, ConstTensor3View z_field, ConstVectorView refellipsoid, ConstMatrixView z_surface, const Index &cloudbox_on, const ArrayOfIndex &cloudbox_limits, const bool &ppath_inside_cloudbox_do, ConstVectorView rte_pos, ConstVectorView rte_los, const Verbosity &verbosity)
Initiates a Ppath structure for calculation of a path with ppath_step.
void interp_atmfield_gp2itw(Matrix &itw, const Index &atmosphere_dim, const ArrayOfGridPos &gp_p, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon)
Converts atmospheric grid positions to weights for interpolation of an atmospheric field.
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)
void opt_prop_sum_propmat_clearsky(PropagationMatrix &ext_mat, StokesVector &abs_vec, const ArrayOfPropagationMatrix &propmat_clearsky)
Get optical properties from propmat_clearsky.
void get_ppath_transmat(Workspace &ws, MatrixView &trans_mat, const Ppath &ppath, const Agenda &propmat_clearsky_agenda, const Index stokes_dim, const Index f_index, const Vector &f_grid, const Vector &p_grid, const Tensor3 &t_field, const Tensor4 &vmr_field, const ArrayOfIndex &cloudbox_limits, const Tensor4 &pnd_field, const ArrayOfArrayOfSingleScatteringData &scat_data, const Verbosity &verbosity)
get_ppath_transmat.
Numeric rtp_temperature(Workspace &ws) noexcept
void cloud_atm_vars_by_gp(VectorView pressure, VectorView temperature, MatrixView vmr, MatrixView pnd, const ArrayOfGridPos &gp_p, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon, const ArrayOfIndex &cloudbox_limits, ConstVectorView p_grid_cloud, ConstTensor3View t_field_cloud, ConstTensor4View vmr_field_cloud, ConstTensor4View pnd_field)
cloud_atm_vars_by_gp.
void opt_prop_Bulk(Tensor5 &ext_mat, Tensor4 &abs_vec, Index &ptype, const ArrayOfTensor5 &ext_mat_ss, const ArrayOfTensor4 &abs_vec_ss, const ArrayOfIndex &ptypes_ss)
one-line descript
void mirror_los(Vector &los_mirrored, ConstVectorView los, const Index &atmosphere_dim)
Determines the backward direction for a given line-of-sight.
void ext2trans(MatrixView trans_mat, Index &icase, ConstMatrixView ext_mat, const Numeric &lstep)
Converts an extinction matrix to a transmission matrix.
Tensor3 t_field(Workspace &ws) noexcept
A constant view of a Tensor3.
Numeric ext_I(const Numeric &I, const Numeric &Q, const Numeric &kI, const Numeric &kQ, const Numeric &s)
ext_I.
Agenda propmat_clearsky_agenda(Workspace &ws) noexcept
void ppath_set_background(Ppath &ppath, const Index &case_nr)
Sets the background field of a Ppath structure.
Vector x(Workspace &ws) noexcept
INDEX Index
The type to use for all integer numbers and indices.
Index ppath_what_background(const Ppath &ppath)
Returns the case number for the radiative background.
A constant view of a Vector.
Index nelem() const
Number of elements.
void interpweights(VectorView itw, const GridPos &tc)
Red 1D interpolation weights.
Matrix z_surface(Workspace &ws) noexcept
const Numeric SPEED_OF_LIGHT
VectorView VectorAtPosition(const Index iv=0, const Index iz=0, const Index ia=0)
Get a vectorview to the position.
void pha_mat_ScatSpecBulk(ArrayOfTensor6 &pha_mat, ArrayOfIndex &ptype, const ArrayOfArrayOfTensor6 &pha_mat_se, const ArrayOfArrayOfIndex &ptypes_se, ConstMatrixView pnds, ConstMatrixView t_ok)
Scattering species bulk phase matrices.
void cloudy_rt_vars_at_gp(Workspace &ws, MatrixView ext_mat_mono, VectorView abs_vec_mono, VectorView pnd_vec, Numeric &temperature, const Agenda &propmat_clearsky_agenda, const Index stokes_dim, const Index f_index, const Vector &f_grid, const GridPos &gp_p, const GridPos &gp_lat, const GridPos &gp_lon, ConstVectorView p_grid_cloud, ConstTensor3View t_field_cloud, ConstTensor4View vmr_field_cloud, const Tensor4 &pnd_field, const ArrayOfArrayOfSingleScatteringData &scat_data, const ArrayOfIndex &cloudbox_limits, const Vector &rte_los)
cloudy_rt_vars_at_gp.