ARTS  2.3.1285(git:92a29ea9-dirty)
m_predefined_absorption_models.cc
Go to the documentation of this file.
1 /* Copyright (C) 2020
2  * Richard Larsson <ric.larsson@gmail.com>
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 
29 
30 
31 /* Workspace method: Doxygen documentation will be auto-generated */
33  ArrayOfArrayOfMatrix& dabs_xsec_per_species_dx,
34  const ArrayOfArrayOfSpeciesTag& abs_species,
35  const ArrayOfRetrievalQuantity& jacobian_quantities,
36  const Vector& f_grid,
37  const Vector& abs_p,
38  const Vector& abs_t,
39  const Matrix& abs_vmrs,
40  const Verbosity&)
41 {
42  // Forward simulations and their error handling
43  if (abs_vmrs.ncols() not_eq abs_p.nelem()) {
44  throw std::runtime_error("Mismatch dimensions on pressure and VMR inputs");
45  } else if (abs_t.nelem() not_eq abs_p.nelem()) {
46  throw std::runtime_error("Mismatch dimensions on pressure and temperature inputs");
47  } else if (abs_vmrs.nrows() not_eq abs_species.nelem()) {
48  throw std::runtime_error("Mismatch dimensions on species and VMR inputs");
49  } else if (abs_xsec_per_species.nelem() not_eq abs_species.nelem()) {
50  throw std::runtime_error("Mismatch dimensions on xsec and VMR inputs");
51  } else if (std::any_of(abs_xsec_per_species.cbegin(), abs_xsec_per_species.cend(),
52  [&abs_p](auto x){return x.ncols() not_eq abs_p.nelem();})) {
53  throw std::runtime_error("Mismatch dimensions on internal matrices of xsec and pressure");
54  } else if (std::any_of(abs_xsec_per_species.cbegin(), abs_xsec_per_species.cend(),
55  [&f_grid](auto x){return x.nrows() not_eq f_grid.nelem();})) {
56  throw std::runtime_error("Mismatch dimensions on internal matrices of xsec and frequency");
57  }
58 
59  // Derivatives and their error handling
60  const auto jac_pos = equivalent_propmattype_indexes(jacobian_quantities);
61  if (dabs_xsec_per_species_dx.nelem()) {
62  if(dabs_xsec_per_species_dx.nelem() not_eq abs_species.nelem()) {
63  throw std::runtime_error("Mismatch dimensions on species inputs and xsec derivatives");
64  } else if (std::any_of(dabs_xsec_per_species_dx.cbegin(), dabs_xsec_per_species_dx.cend(),
65  [&jac_pos](auto x){return x.nelem() not_eq jac_pos.nelem();})) {
66  throw std::runtime_error("Mismatch dimensions on xsec derivatives and Jacobian grids");
67  } else if (std::any_of(dabs_xsec_per_species_dx.cbegin(), dabs_xsec_per_species_dx.cend(),
68  [&abs_p](auto x1){return std::any_of(x1.cbegin(), x1.cend(),
69  [&abs_p](auto x2){return x2.ncols() not_eq abs_p.nelem();});})) {
70  throw std::runtime_error("Mismatch dimensions on internal matrices of xsec derivatives and pressure");
71  } else if (std::any_of(dabs_xsec_per_species_dx.cbegin(), dabs_xsec_per_species_dx.cend(),
72  [&f_grid](auto x1){return std::any_of(x1.cbegin(), x1.cend(),
73  [&f_grid](auto x2){return x2.nrows() not_eq f_grid.nelem();});})) {
74  throw std::runtime_error("Mismatch dimensions on internal matrices of xsec derivatives and frequency");
75  }
76  }
77 
78  // Positions of important species and VMR of water
79  auto o2_mpm2020 = find_first_species_tg(abs_species, SpeciesTag("O2-MPM2020"));
80  auto h2o = find_first_species_tg(abs_species, SpeciesTag("H2O").Species());
81  auto h2o_vmr = h2o == -1 ? Vector(abs_p.nelem(), 0) : abs_vmrs(h2o, joker);
82  ArrayOfMatrix empty(0);
83 
84  // Perform calculations if there is any oxygen
85  if (o2_mpm2020 >= 0 and o2_mpm2020 < abs_xsec_per_species.nelem()) {
86  Absorption::PredefinedModel::makarov2020_o2_lines_mpm(abs_xsec_per_species[o2_mpm2020],
87  dabs_xsec_per_species_dx.nelem() ? dabs_xsec_per_species_dx[o2_mpm2020] : empty,
88  f_grid, abs_p, abs_t, h2o_vmr, jacobian_quantities, jac_pos);
89  }
90 }
ArrayOfIndex equivalent_propmattype_indexes(const ArrayOfRetrievalQuantity &js)
Returns a list of positions for the derivatives in Propagation Matrix calculations.
Definition: jacobian.cc:1099
#define x2
Index nelem() const
Number of elements.
Definition: array.h:195
QuantumIdentifier::QType Index LowerQuantumNumbers Species
The Vector class.
Definition: matpackI.h:860
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
#define x1
Index ncols() const
Returns the number of columns.
Definition: matpackI.cc:432
void makarov2020_o2_lines_mpm(Matrix &xsec, ArrayOfMatrix &dxsec, const Vector &f, const Vector &p, const Vector &t, const Vector &water_vmr, const ArrayOfRetrievalQuantity &jacs, const ArrayOfIndex &jacs_pos)
Adds Makarov MPM2020 O2 absorption lines to the absorption matrix.
A tag group can consist of the sum of several of these.
Index find_first_species_tg(const ArrayOfArrayOfSpeciesTag &tgs, const Index &spec)
Find first occurrence of species in tag groups.
const Joker joker
The Matrix class.
Definition: matpackI.h:1193
This can be used to make arrays out of anything.
Definition: array.h:40
void abs_xsec_per_speciesAddPredefinedO2MPM2020(ArrayOfMatrix &abs_xsec_per_species, ArrayOfArrayOfMatrix &dabs_xsec_per_species_dx, const ArrayOfArrayOfSpeciesTag &abs_species, const ArrayOfRetrievalQuantity &jacobian_quantities, const Vector &f_grid, const Vector &abs_p, const Vector &abs_t, const Matrix &abs_vmrs, const Verbosity &)
WORKSPACE METHOD: abs_xsec_per_speciesAddPredefinedO2MPM2020.
Index nrows() const
Returns the number of rows.
Definition: matpackI.cc:429