ARTS  2.3.1285(git:92a29ea9-dirty)
m_radiation_field.cc
Go to the documentation of this file.
1 /* Copyright (C) 2015
2  Richard Larsson
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License as published by the
6  Free Software Foundation; either version 2, or (at your option) any
7  later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17  USA. */
18 
27 #include "absorption.h"
28 #include "arts.h"
29 #include "arts_omp.h"
30 #include "auto_md.h"
31 #include "linefunctions.h"
32 #include "physics_funcs.h"
33 #include "ppath.h"
34 #include "propmat_field.h"
35 #include "radiation_field.h"
36 
38  Workspace& ws,
39  Matrix& line_irradiance,
40  Tensor3& line_transmission,
41  const ArrayOfArrayOfSpeciesTag& abs_species,
42  const ArrayOfArrayOfAbsorptionLines& abs_lines_per_species,
43  const EnergyLevelMap& nlte_field,
44  const Tensor4& vmr_field,
45  const Tensor3& t_field,
46  const Tensor3& z_field,
47  const Vector& p_grid,
48  const Vector& refellipsoid,
49  const Tensor3& surface_props_data,
50  const Agenda& ppath_agenda,
51  const Agenda& iy_main_agenda,
52  const Agenda& iy_space_agenda,
53  const Agenda& iy_surface_agenda,
54  const Agenda& iy_cloudbox_agenda,
55  const Agenda& propmat_clearsky_agenda,
56  const Numeric& df,
57  const Index& nz,
58  const Index& nf,
59  const Numeric& r,
60  const Verbosity& verbosity)
61 {
62  if (abs_lines_per_species.nelem() not_eq 1)
63  throw std::runtime_error("Only for one species...");
64  if (nf % 2 not_eq 1)
65  throw std::runtime_error("Must hit line center, nf % 2 must be 1.");
66  const Index nl = nelem(abs_lines_per_species);
67  const Index np = p_grid.nelem();
68 
69  // Compute variables
70  ArrayOfTensor3 diy_dx;
71  FieldOfPropagationMatrix propmat_field;
72  FieldOfStokesVector absorption_field, additional_source_field;
73  ArrayOfPpath ppath_field;
74 
75  // Check that the lines and nf is correct
76  Vector f_grid(nf * nl);
77  Index il=0;
78  for (auto& lines: abs_lines_per_species) {
79  for (auto& band: lines) {
80  for (Index k=0; k<band.NumLines(); k++) {
81  nlinspace(f_grid[Range(il * nf, nf)], band.F0(k) * (1 - df), band.F0(k) * (1 + df), nf);
82  il++;
83  }
84  }
85  }
86 
88  ppath_field,
89  ppath_agenda,
90  -1,
91  1e99,
92  1,
93  z_field,
94  f_grid,
95  0,
96  1,
97  0,
98  Vector(1, 0),
99  Vector(1, 0),
100  Vector(0),
101  refellipsoid,
102  1,
103  nz,
104  verbosity);
105 
106  ArrayOfArrayOfIndex sorted_index;
107  ArrayOfVector cos_zenith_angles;
108  sorted_index_of_ppath_field(sorted_index, cos_zenith_angles, ppath_field);
109 
110  for (Index ip = 0; ip < np; ip++)
112  "Your lineshape integration does normalize. Increase nf and decrease df until it does.",
113  test_integrate_zenith(cos_zenith_angles[ip], sorted_index[ip]));
114 
116  propmat_field,
117  absorption_field,
118  additional_source_field,
119  1,
120  f_grid,
121  p_grid,
122  z_field,
123  t_field,
124  nlte_field,
125  vmr_field,
127  propmat_clearsky_agenda);
128 
129  Array<Array<Eigen::VectorXcd>> lineshapes(
130  nl, Array<Eigen::VectorXcd>(np, Eigen::VectorXcd(nf * nl)));
131  for (Index ip=0; ip<np; ip++) {
132  il=0;
133  for (auto& lines: abs_lines_per_species) {
134  for (auto& band: lines) {
135  const Numeric doppler_constant = Linefunctions::DopplerConstant(t_field(ip, 0, 0), band.SpeciesMass());
136  const Vector vmrs = band.BroadeningSpeciesVMR(vmr_field(joker, ip, 0, 0), abs_species);
137  for (Index k=0; k<band.NumLines(); k++) {
138  const auto X = band.ShapeParameters(k, t_field(ip, 0, 0), p_grid[ip], vmrs);
139  Linefunctions::set_lineshape(lineshapes[il][ip], MapToEigen(f_grid),
140  band.Line(k), t_field(ip, 0, 0), 0, 0, doppler_constant, X,
141  band.LineShapeType(), band.Mirroring(), band.Normalization());
142  il++;
143  }
144  }
145  }
146  }
147  for (auto& aols : lineshapes)
148  for (auto& ls : aols)
150  "Your lineshape integration does not normalize. Increase nf and decrease df until it does.",
151  test_integrate_convolved(ls, f_grid));
152 
153  // Counting the path index so we can make the big loop parallel
154  ArrayOfArrayOfIndex counted_path_index(ppath_field.nelem());
155  ArrayOfIndex counter(np, 0);
156  for (Index i = 0; i < ppath_field.nelem(); i++) {
157  const Ppath& path = ppath_field[i];
158  counted_path_index[i].resize(path.np);
159  for (Index ip_path = 0; ip_path < path.np; ip_path++) {
160  const Index ip_grid = grid_index_from_gp(path.gp_p[ip_path]);
161  counted_path_index[i][ip_path] = counter[ip_grid];
162  counter[ip_grid]++;
163  }
164  }
165 
166  line_irradiance = Matrix(nl, np, 0.0);
167  line_transmission = Tensor3(1, nl, np, 0.0);
168 
169  ArrayOfMatrix line_radiance(np);
170  for (Index i = 0; i < np; i++)
171  line_radiance[i].resize(sorted_index[i].nelem(), nl);
172 
173  Workspace l_ws(ws);
174  Agenda l_iy_main_agenda(iy_main_agenda);
175  Agenda l_iy_space_agenda(iy_space_agenda);
176  Agenda l_iy_surface_agenda(iy_surface_agenda);
177  Agenda l_iy_cloudbox_agenda(iy_cloudbox_agenda);
178 
179 #pragma omp parallel for if (not arts_omp_in_parallel()) \
180  schedule(guided) default(shared) firstprivate(l_ws, \
181  l_iy_main_agenda, \
182  l_iy_space_agenda, \
183  l_iy_surface_agenda, \
184  l_iy_cloudbox_agenda,\
185  il)
186  for (Index i = 0; i < ppath_field.nelem(); i++) {
187  const Ppath& path = ppath_field[i];
188 
189  thread_local ArrayOfRadiationVector lvl_rad;
190  thread_local ArrayOfRadiationVector src_rad;
191  thread_local ArrayOfTransmissionMatrix lyr_tra;
192  thread_local ArrayOfTransmissionMatrix tot_tra;
193 
195  lvl_rad,
196  src_rad,
197  lyr_tra,
198  tot_tra,
199  propmat_field,
200  absorption_field,
201  additional_source_field,
202  f_grid,
203  t_field,
204  nlte_field,
205  path,
206  l_iy_main_agenda,
207  l_iy_space_agenda,
208  l_iy_surface_agenda,
209  l_iy_cloudbox_agenda,
210  surface_props_data,
211  verbosity);
212 
213  for (Index ip_path = 0; ip_path < path.np; ip_path++) {
214  const Index ip_grid = grid_index_from_gp(path.gp_p[ip_path]);
215  for (il = 0; il < nl; il++)
216  line_radiance[ip_grid](counted_path_index[i][ip_path], il) =
218  lvl_rad[ip_path], lineshapes[il][ip_grid], f_grid);
219  }
220  }
221 
222  for (Index ip = 0; ip < np; ip++) {
223  for (il = 0; il < nl; il++) {
224  line_irradiance(il, ip) = integrate_zenith(line_radiance[ip](joker, il),
225  cos_zenith_angles[ip],
226  sorted_index[ip]);
227  }
228  }
229 
230  if (r > 0) {
231  const FieldOfTransmissionMatrix transmat_field =
232  transmat_field_calc_from_propmat_field(propmat_field, r);
233  for (Index ip = 0; ip < np; ip++)
234  for (il = 0; il < nl; il++)
235  line_transmission(0, il, ip) = integrate_convolved(
236  transmat_field(ip, 0, 0), lineshapes[il][ip], f_grid);
237  }
238 }
239 
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Numeric test_integrate_zenith(const Vector &cosza, const Array< Index > &sorted_index)
Integrate cos(za) over the angles.
Vector vmrs(const ConstVectorView &atmospheric_vmrs, const ArrayOfArrayOfSpeciesTag &atmospheric_species, const QuantumIdentifier &self, const ArrayOfSpeciesTag &lineshape_species, bool self_in_list, bool bath_in_list, Type type)
Returns a VMR vector for this model&#39;s main calculations.
The Agenda class.
Definition: agenda_class.h:44
Index nelem() const
Number of elements.
Definition: array.h:195
Numeric test_integrate_convolved(const Eigen::Ref< Eigen::VectorXcd > F, const Vector &f)
Integrate the line shape.
The Vector class.
Definition: matpackI.h:860
The Tensor4 class.
Definition: matpackIV.h:421
The range class.
Definition: matpackI.h:160
Implements a propagation matrix field.
Array< RetrievalQuantity > ArrayOfRetrievalQuantity
Definition: jacobian.h:402
Creates a 3D field of a base unit.
Definition: field.h:33
void emission_from_propmat_field(Workspace &ws, ArrayOfRadiationVector &lvl_rad, ArrayOfRadiationVector &src_rad, ArrayOfTransmissionMatrix &lyr_tra, ArrayOfTransmissionMatrix &tot_tra, const FieldOfPropagationMatrix &propmat_field, const FieldOfStokesVector &absorption_field, const FieldOfStokesVector &additional_source_field, const Vector &f_grid, const Tensor3 &t_field, const EnergyLevelMap &nlte_field, const Ppath &ppath, const Agenda &iy_main_agenda, const Agenda &iy_space_agenda, const Agenda &iy_surface_agenda, const Agenda &iy_cloudbox_agenda, const Tensor3 &surface_props_data, const Verbosity &verbosity)
Computes the radiation and transmission from fields of atmospheric propagation.
invlib::Vector< ArtsVector > Vector
invlib wrapper type for ARTS vectors.
Definition: oem.h:32
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:51
void ppath_fieldFromDownUpLimbGeoms(Workspace &ws, ArrayOfPpath &ppath_field, const Agenda &ppath_agenda, const Numeric &ppath_lmax, const Numeric &ppath_lraytrace, const Index &atmgeom_checked, const Tensor3 &z_field, const Vector &f_grid, const Index &cloudbox_on, const Index &cloudbox_checked, const Index &ppath_inside_cloudbox_do, const Vector &rte_pos, const Vector &rte_los, const Vector &rte_pos2, const Vector &refellipsoid, const Index &atmosphere_dim, const Index &zenith_angles_per_position, const Verbosity &verbosity)
WORKSPACE METHOD: ppath_fieldFromDownUpLimbGeoms.
Definition: m_ppath.cc:1120
Numeric integrate_convolved(const RadiationVector &I, const Eigen::VectorXcd &F, const Vector &f)
Convolve intensity and line shape and integrate.
Stuff related to lineshape functions.
The Tensor3 class.
Definition: matpackIII.h:339
The global header file for ARTS.
Numeric integrate_zenith(const VectorView j, const Vector &cosza, const Array< Index > &sorted_index)
Convolve source function with 1D sphere and integrate.
void nlinspace(Vector &x, const Numeric start, const Numeric stop, const Index n)
nlinspace
Definition: math_funcs.cc:231
const Joker joker
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
The Matrix class.
Definition: matpackI.h:1193
Declarations required for the calculation of absorption coefficients.
Radiation field calculations.
Propagation path structure and functions.
void field_of_propagation(Workspace &ws, FieldOfPropagationMatrix &propmat_field, FieldOfStokesVector &absorption_field, FieldOfStokesVector &additional_source_field, const Index &stokes_dim, const Vector &f_grid, const Vector &p_grid, const Tensor3 &z_field, const Tensor3 &t_field, const EnergyLevelMap &nlte_field, const Tensor4 &vmr_field, const ArrayOfRetrievalQuantity &jacobian_quantities, const Agenda &propmat_clearsky_agenda)
Creates a field of propagation matrices, absorption vectors, and source vectors.
void set_lineshape(Eigen::Ref< Eigen::VectorXcd > F, const Eigen::Ref< const Eigen::VectorXd > f_grid, const Absorption::SingleLine &line, const Numeric &temperature, const Numeric &zeeman_df, const Numeric &magnetic_magnitude, const Numeric &doppler_constant, const LineShape::Output &lso, const LineShape::Type lineshape_type, const Absorption::MirroringType mirroring_type, const Absorption::NormalizationType norm_type)
Sets the lineshape normalized to unity.
FieldOfTransmissionMatrix transmat_field_calc_from_propmat_field(const FieldOfPropagationMatrix &propmat_field, const Numeric &r)
Get a field of transmission matrices from the propagation matrix field.
Index np
Number of points describing the ppath.
Definition: ppath.h:52
void sorted_index_of_ppath_field(ArrayOfArrayOfIndex &sorted_index, ArrayOfVector &cosza, const ArrayOfPpath &ppath_field)
Get sorting of zenith angles in field of ppath.
Numeric DopplerConstant(Numeric T, Numeric mass)
Returns the frequency-independent part of the Doppler broadening.
Index nelem(const Lines &l)
Number of lines.
Workspace class.
Definition: workspace_ng.h:40
The structure to describe a propagation path and releated quantities.
Definition: ppath.h:48
Header file for helper functions for OpenMP.
Index grid_index_from_gp(const GridPos &gp)
Get a discrete position from grid pos.
ComplexConstMatrixViewMap MapToEigen(const ConstComplexMatrixView &A)
Definition: complex.cc:1655
invlib::Matrix< ArtsMatrix > Matrix
invlib wrapper type for ARTS matrices.
Definition: oem.h:34
This file contains declerations of functions of physical character.
void line_irradianceCalcForSingleSpeciesNonOverlappingLinesPseudo2D(Workspace &ws, Matrix &line_irradiance, Tensor3 &line_transmission, const ArrayOfArrayOfSpeciesTag &abs_species, const ArrayOfArrayOfAbsorptionLines &abs_lines_per_species, const EnergyLevelMap &nlte_field, const Tensor4 &vmr_field, const Tensor3 &t_field, const Tensor3 &z_field, const Vector &p_grid, const Vector &refellipsoid, const Tensor3 &surface_props_data, const Agenda &ppath_agenda, const Agenda &iy_main_agenda, const Agenda &iy_space_agenda, const Agenda &iy_surface_agenda, const Agenda &iy_cloudbox_agenda, const Agenda &propmat_clearsky_agenda, const Numeric &df, const Index &nz, const Index &nf, const Numeric &r, const Verbosity &verbosity)
WORKSPACE METHOD: line_irradianceCalcForSingleSpeciesNonOverlappingLinesPseudo2D. ...
ArrayOfGridPos gp_p
Index position with respect to the pressure grid.
Definition: ppath.h:82
void error_in_integrate(const String &error_msg, const Numeric &value_that_should_be_unity)
Throws an error if integration values are bad.