ARTS  2.3.1285(git:92a29ea9-dirty)
m_linemixing.cc
Go to the documentation of this file.
1 /* Copyright (C) 2020
2  * Richard Larsson <larsson@mps.mpg.de>
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 
31 #include "global_data.h"
32 #include "linemixing_hitran.h"
33 #include "propagationmatrix.h"
34 
35 
37  ArrayOfArrayOfAbsorptionLines& abs_lines_per_species,
38  const ArrayOfArrayOfSpeciesTag& abs_species,
39  const String& basedir,
40  const Numeric& linemixinglimit,
41  const Numeric& fmin,
42  const Numeric& fmax,
43  const Numeric& stot,
44  const String& mode,
45  const Verbosity&)
46 {
48 
50  if (mode == "VP") intmode = lm_hitran_2017::ModeOfLineMixing::VP;
51  else if (mode == "VP_Y") intmode = lm_hitran_2017::ModeOfLineMixing::VP_Y;
52  else if (mode == "SDVP") intmode = lm_hitran_2017::ModeOfLineMixing::SDVP;
53  else if (mode == "SDVP_Y") intmode = lm_hitran_2017::ModeOfLineMixing::SDVP_Y;
54  else if (mode == "FullW") intmode = lm_hitran_2017::ModeOfLineMixing::FullW;
55  else if (mode == "VP_W") intmode = lm_hitran_2017::ModeOfLineMixing::VP_W;
56  else throw std::runtime_error("Bad mode, see method instruction for valid arguments");
57 
58  if (abs_species.nelem() not_eq abs_lines_per_species.nelem())
59  throw std::runtime_error("Bad size of input species+lines");
60 
62  lm_hitran_2017::read(abs_hitran_relmat_data, lines, basedir, linemixinglimit, fmin, fmax, stot, intmode);
63  std::for_each(lines.begin(), lines.end(), [](auto& band){band.sort_by_frequency();}); // Sort so largest frequency is last
64  ArrayOfIndex used(lines.nelem(), false);
65 
66  bool emptied=false;
67  for (Index i=0; i<abs_species.nelem(); i++) {
68 
69  for (Index j=0; j<abs_species[i].nelem(); j++) {
70  if (abs_species[i][j].Species() not_eq SpeciesTag("CO2").Species())
71  continue;
72 
73  if (not emptied) {
74  abs_lines_per_species[i].resize(0);
75  emptied = true;
76  }
77 
78  for (Index k=0; k<lines.nelem(); k++) {
79  if (used[k]) continue;
80 
81  const Numeric lf{abs_species[i][j].Lf() > 0 ? abs_species[i][j].Lf() : -std::numeric_limits<Numeric>::max()};
82  const Numeric uf{abs_species[i][j].Uf() > 0 ? abs_species[i][j].Uf() : std::numeric_limits<Numeric>::max()};
83 
84  // Select lines with correct Isotopologue and one line center within the range
85  if ((abs_species[i][j].Isotopologue() == lines[k].Isotopologue() or
86  abs_species[i][j].Isotopologue() == species_data[SpeciesTag("CO2").Species()].Isotopologue().nelem()) and
87  (lines[k].AllLines().front().F0() <= uf and lines[k].AllLines().back().F0() >= lf)) {
88  used[k] = true; // The lines should not be copied into other places
89  abs_lines_per_species[i].push_back(lines[k]);
90  }
91  }
92  }
93  }
94 }
95 
97  const HitranRelaxationMatrixData& abs_hitran_relmat_data,
98  const ArrayOfArrayOfAbsorptionLines& abs_lines_per_species,
99  const Vector& f_grid,
100  const ArrayOfArrayOfSpeciesTag& abs_species,
101  const ArrayOfRetrievalQuantity& jacobian_quantities,
102  const SpeciesAuxData& partition_functions,
103  const Numeric& rtp_pressure,
104  const Numeric& rtp_temperature,
105  const Vector& rtp_vmr,
106  const Verbosity&)
107 {
108  if (jacobian_quantities.nelem())
109  throw std::runtime_error("Cannot support any Jacobian at this time");
110  if (abs_species.nelem() not_eq abs_lines_per_species.nelem())
111  throw std::runtime_error("Bad size of input species+lines");
112  if (abs_species.nelem() not_eq rtp_vmr.nelem())
113  throw std::runtime_error("Bad size of input species+vmrs");
114 
115  // vmrs should be [air, water, co2]
116  Vector vmrs(3, 0);
117  for (Index i=0; i<abs_species.nelem(); i++) {
118  auto& specs = abs_species[i];
119  for (auto& spec: specs) {
120  if (SpeciesTag("H2O").Species() == spec.Species()) {
121  vmrs[1] = rtp_vmr[i];
122  }
123  else if (SpeciesTag("CO2").Species() == spec.Species()) {
124  vmrs[2] = rtp_vmr[i];
125  }
126  }
127  }
128  vmrs[0] = 1 - vmrs[1] - vmrs[2];
129 
130  for (Index i=0; i<abs_species.nelem(); i++) {
131  if (abs_lines_per_species[i].nelem() and
132  (abs_lines_per_species[i].front().Population() == Absorption::PopulationType::ByHITRANFullRelmat or
133  abs_lines_per_species[i].front().Population() == Absorption::PopulationType::ByHITRANRosenkranzRelmat))
134  propmat_clearsky[i].Kjj() += lm_hitran_2017::compute(abs_hitran_relmat_data, abs_lines_per_species[i], rtp_pressure, rtp_temperature, vmrs, f_grid, partition_functions);
135  }
136 }
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
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.
ModeOfLineMixing
Class that controls ReadFromLineMixingStream output.
Index nelem() const
Number of elements.
Definition: array.h:195
QuantumIdentifier::QType Index LowerQuantumNumbers Species
void read(HitranRelaxationMatrixData &hitran, ArrayOfAbsorptionLines &bands, const String &basedir, const Numeric linemixinglimit, const Numeric fmin, const Numeric fmax, const Numeric stot, const ModeOfLineMixing mode)
Read from HITRAN online line mixing file.
The Vector class.
Definition: matpackI.h:860
Index Species() const
Molecular species index.
Namespace and functions to deal with HITRAN linemixing.
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:51
const Array< SpeciesRecord > species_data
Species Data.
void abs_hitran_relmat_dataReadHitranRelmatDataAndLines(HitranRelaxationMatrixData &abs_hitran_relmat_data, ArrayOfArrayOfAbsorptionLines &abs_lines_per_species, const ArrayOfArrayOfSpeciesTag &abs_species, const String &basedir, const Numeric &linemixinglimit, const Numeric &fmin, const Numeric &fmax, const Numeric &stot, const String &mode, const Verbosity &)
WORKSPACE METHOD: abs_hitran_relmat_dataReadHitranRelmatDataAndLines.
Definition: m_linemixing.cc:36
Stuff related to the propagation matrix.
QuantumIdentifier::QType Isotopologue
A tag group can consist of the sum of several of these.
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
void propmat_clearskyAddHitranLineMixingLines(ArrayOfPropagationMatrix &propmat_clearsky, const HitranRelaxationMatrixData &abs_hitran_relmat_data, const ArrayOfArrayOfAbsorptionLines &abs_lines_per_species, const Vector &f_grid, const ArrayOfArrayOfSpeciesTag &abs_species, const ArrayOfRetrievalQuantity &jacobian_quantities, const SpeciesAuxData &partition_functions, const Numeric &rtp_pressure, const Numeric &rtp_temperature, const Vector &rtp_vmr, const Verbosity &)
WORKSPACE METHOD: propmat_clearskyAddHitranLineMixingLines.
Definition: m_linemixing.cc:96
Vector compute(const Numeric p, const Numeric t, const Numeric xco2, const Numeric xh2o, const ConstVectorView invcm_grid, const Numeric stotmax, const calctype type)
This can be used to make arrays out of anything.
Definition: array.h:40
G0 G2 FVC Y DV F0
#define max(a, b)
Index nelem(const Lines &l)
Number of lines.
Auxiliary data for isotopologues.
Definition: absorption.h:217