ARTS  2.3.1285(git:92a29ea9-dirty)
energylevelmap.cc
Go to the documentation of this file.
1 /* Copyright (C) 2019
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 
27 #include "energylevelmap.h"
28 #include "special_interp.h"
29 
30 
32  const AbsorptionLines& band, const Index& line_index) const
33 {
35  throw std::runtime_error("Must have Numeric_t, input type is bad");
36 
37  Output2 x{/*.r_low=*/0, /*.r_upp=*/0};
38 
39  bool found1=false;
40  bool found2=false;
41  for (size_t i=0; i<mlevels.size(); i++) {
42  if (Absorption::id_in_line_lower(band, mlevels[i], line_index)) {
43  found1 = true;
44  x.r_low = mvalue(i, 0, 0, 0);
45  }
46 
47  if (Absorption::id_in_line_upper(band, mlevels[i], line_index)) {
48  found2 = true;
49  x.r_upp = mvalue(i, 0, 0, 0);
50  }
51 
52  if (found1 and found2)
53  break;
54  }
55  return x;
56 }
57 
59  const AbsorptionLines& band,
60  const Index& line_index,
61  const Numeric T) const
62 {
64  throw std::runtime_error("Must have Numeric_t, input type is bad");
65 
66  Output4 x{/*.E_low=*/0, /*.E_upp=*/0, /*.T_low=*/T, /*.T_upp=*/T};
67 
68  bool found1=false;
69  bool found2=false;
70  for (Index i=0; i<mlevels.nelem(); i++) {
71  if (Absorption::id_in_line_lower(band, mlevels[i], line_index)) {
72  found1 = true;
73  x.T_low = mvalue(i, 0, 0, 0);
74  x.E_low = mvib_energy[i];
75  }
76 
77  if (Absorption::id_in_line_upper(band, mlevels[i], line_index)) {
78  found2 = true;
79  x.T_upp = mvalue(i, 0, 0, 0);
80  x.E_upp = mvib_energy[i];
81  }
82 
83  if (found1 and found2) {
84  break;
85  }
86  }
87  return x;
88 }
89 
92  mlevels(levels),
93  mvib_energy(energies),
94  mvalue(data)
95 {
96  ThrowIfNotOK();
97 }
98 
101  mlevels(levels),
102  mvib_energy(energies),
103  mvalue(data.nrows(), 1, 1, data.ncols())
104 {
105  mvalue(joker, 0, 0, joker) = data;
106  ThrowIfNotOK();
107 }
108 
111  mlevels(levels),
112  mvib_energy(energies),
113  mvalue(data.nelem(), 1, 1, 1)
114 {
115  mvalue(joker, 0, 0, 0) = data;
116  ThrowIfNotOK();
117 }
118 
120 {
122  return EnergyLevelMap();
123  else if (mtype not_eq EnergyLevelMapType::Tensor3_t)
124  throw std::runtime_error("Must have Tensor3_t, input type is bad");
125 
126  EnergyLevelMap elm(EnergyLevelMapType::Vector_t, 1, 1, p.nelem(), *this);
127 
128  Matrix itw_field;
129  interp_atmfield_gp2itw(itw_field, atmosphere_dim, p, lat, lon);
130 
131  const Index nnlte = mlevels.nelem();
132  for (Index itnlte = 0; itnlte < nnlte; itnlte++)
133  interp_atmfield_by_itw(elm.mvalue(itnlte, 0, 0, joker), atmosphere_dim,
134  mvalue(itnlte, joker, joker, joker),
135  p, lat, lon, itw_field);
136  return elm;
137 }
138 
140 {
142  return EnergyLevelMap();
144  return *this;
145  else if (mtype not_eq EnergyLevelMapType::Vector_t)
146  throw std::runtime_error("Must have Vector_t, input type is bad");
147 
148  if (ip >= mvalue.ncols() or ip < 0) {
150  os << "Bad dims for data:\n\tThe pressure dim of data contains: "
151  << mvalue.ncols() << " values and you are requesting element index " << ip << "\n";
152  throw std::runtime_error(os.str());
153  }
154 
155  EnergyLevelMap elm(EnergyLevelMapType::Numeric_t, 1, 1, 1, *this);
156  elm.mvalue(joker, 0, 0, 0) = mvalue(joker, 0, 0, ip);
157  return elm;
158 }
159 
161  if (s == "Tensor3")
163  else if (s == "Vector")
165  else if (s == "Numeric")
167  else if (s == "None")
169  else {
171  os << "Only \"None\", \"Numeric\", \"Vector\", and \"Tensor3\" types accepted\n"
172  << "You request to have an EnergyLevelMap of type: " << s << '\n';
173  throw std::runtime_error(os.str());
174  }
175 }
176 
178 {
179  switch(type) {
181  return "Tensor3";
183  return "Vector";
185  return "Numeric";
187  return "None";
188  }
189  return "";
190 }
191 
192 std::ostream& operator<<(std::ostream& os, const EnergyLevelMap& elm) {
193  return os << energylevelmaptype2string(elm.Type()) << '\n'
194  << elm.Levels() << '\n'
195  << elm.Data() << '\n'
196  << elm.Energies() << '\n';
197 }
198 
200 {
202  return *this;
203  else if (mtype not_eq EnergyLevelMapType::Tensor3_t)
204  throw std::runtime_error("Must have Tensor3_t, input type is bad");
205 
206  auto elm = EnergyLevelMap(EnergyLevelMapType::Numeric_t, 1, 1, 1, *this);
207  elm.mvalue(joker, 0, 0, 0) = mvalue(joker, ip, ilat, ilon);
208  return elm;
209 }
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
String energylevelmaptype2string(EnergyLevelMapType type)
Output4 get_vibtemp_params(const AbsorptionLines &band, const Index &line_index, const Numeric T) const
Get the output required for Population::NLTE-VibrationalTemperatures.
Index nelem() const
Number of elements.
Definition: array.h:195
Output2 get_ratio_params(const AbsorptionLines &band, const Index &line_index) const
Get the output required for Population::NLTE.
The Vector class.
Definition: matpackI.h:860
const Tensor4 & Data() const noexcept
Energy level type.
EnergyLevelMapType mtype
The Tensor4 class.
Definition: matpackIV.h:421
const Vector & Energies() const noexcept
Energy level type.
G0 G2 FVC Y DV Numeric Numeric Numeric Zeeman LowerQuantumNumbers void * data
EnergyLevelMapType Type() const noexcept
Energy level type.
ArrayOfQuantumIdentifier mlevels
void ThrowIfNotOK() const
std::ostream & operator<<(std::ostream &os, const EnergyLevelMap &elm)
const ArrayOfQuantumIdentifier & Levels() const noexcept
Energy level type.
bool id_in_line_upper(const Lines &band, const QuantumIdentifier &id, size_t line_index)
Checks if the external quantum identifier match a line&#39;s ID.
EnergyLevelMapType
EnergyLevelMap InterpToGridPos(Index atmosphere_dim, const ArrayOfGridPos &p, const ArrayOfGridPos &lat, const ArrayOfGridPos &lon) const
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
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...
Header file for special_interp.cc.
Class to map energy levels.
EnergyLevelMap operator[](Index ip) const
basic_ostringstream< char, string_char_traits< char >, alloc > ostringstream
Definition: sstream.h:204
Index nelem(const Lines &l)
Number of lines.
Numeric T_low
EnergyLevelMap operator()(Index ip, Index ilat, Index ilon) const
Numeric r_low
EnergyLevelMapType string2energylevelmaptype(const String &s)
Index ncols() const
Returns the number of columns.
Definition: matpackIV.cc:66
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.
bool id_in_line_lower(const Lines &band, const QuantumIdentifier &id, size_t line_index)
Checks if the external quantum identifier match a line&#39;s ID.