ARTS  2.4.0(git:4fb77825)
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 
91  mtype(EnergyLevelMapType::Tensor3_t),
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++)
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) {
149  std::ostringstream os;
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")
162  return EnergyLevelMapType::Tensor3_t;
163  else if (s == "Vector")
165  else if (s == "Numeric")
167  else if (s == "None")
169  else {
170  std::ostringstream os;
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) {
180  case EnergyLevelMapType::Tensor3_t:
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 }
Matrix
The Matrix class.
Definition: matpackI.h:1193
ARTS::Var::atmosphere_dim
Index atmosphere_dim(Workspace &ws) noexcept
Definition: autoarts.h:2510
energylevelmap.h
Class to map energy levels.
EnergyLevelMap::get_ratio_params
Output2 get_ratio_params(const AbsorptionLines &band, const Index &line_index) const
Get the output required for Population::NLTE.
Definition: energylevelmap.cc:31
ARTS::Var::lat
Numeric lat(Workspace &ws) noexcept
Definition: autoarts.h:3933
EnergyLevelMap::get_vibtemp_params
Output4 get_vibtemp_params(const AbsorptionLines &band, const Index &line_index, const Numeric T) const
Get the output required for Population::NLTE-VibrationalTemperatures.
Definition: energylevelmap.cc:58
EnergyLevelMap::Energies
const Vector & Energies() const noexcept
Energy level type.
Definition: energylevelmap.h:128
joker
const Joker joker
EnergyLevelMap::Data
const Tensor4 & Data() const noexcept
Energy level type.
Definition: energylevelmap.h:131
interp_atmfield_by_itw
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.
Definition: special_interp.cc:101
EnergyLevelMap::mtype
EnergyLevelMapType mtype
Definition: energylevelmap.h:62
data
G0 G2 FVC Y DV Numeric Numeric Numeric Zeeman LowerQuantumNumbers void * data
Definition: arts_api_classes.cc:232
Vector_t
@ Vector_t
Definition: token.h:33
Absorption::id_in_line_lower
bool id_in_line_lower(const Lines &band, const QuantumIdentifier &id, size_t line_index)
Checks if the external quantum identifier match a line's ID.
Definition: absorptionlines.cc:2904
EnergyLevelMap::mvalue
Tensor4 mvalue
Definition: energylevelmap.h:65
Output2
Definition: energylevelmap.h:36
Absorption::id_in_line_upper
bool id_in_line_upper(const Lines &band, const QuantumIdentifier &id, size_t line_index)
Checks if the external quantum identifier match a line's ID.
Definition: absorptionlines.cc:2877
Tensor4
The Tensor4 class.
Definition: matpackIV.h:421
EnergyLevelMapType::Tensor3_t
@ Tensor3_t
energylevelmaptype2string
String energylevelmaptype2string(EnergyLevelMapType type)
Definition: energylevelmap.cc:177
ARTS::Var::lon
Numeric lon(Workspace &ws) noexcept
Definition: autoarts.h:4064
Array< QuantumIdentifier >
Absorption::nelem
Index nelem(const Lines &l)
Number of lines.
Definition: absorptionlines.h:1820
EnergyLevelMap::Levels
const ArrayOfQuantumIdentifier & Levels() const noexcept
Energy level type.
Definition: energylevelmap.h:125
EnergyLevelMap::ThrowIfNotOK
void ThrowIfNotOK() const
Definition: energylevelmap.h:93
EnergyLevelMap::Type
EnergyLevelMapType Type() const noexcept
Energy level type.
Definition: energylevelmap.h:122
my_basic_string< char >
ConstTensor4View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackIV.cc:66
EnergyLevelMap::mvib_energy
Vector mvib_energy
Definition: energylevelmap.h:64
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
EnergyLevelMap::mlevels
ArrayOfQuantumIdentifier mlevels
Definition: energylevelmap.h:63
EnergyLevelMap::operator[]
EnergyLevelMap operator[](Index ip) const
Definition: energylevelmap.cc:139
EnergyLevelMap::EnergyLevelMap
EnergyLevelMap()
Definition: energylevelmap.h:95
string2energylevelmaptype
EnergyLevelMapType string2energylevelmaptype(const String &s)
Definition: energylevelmap.cc:160
Output4
Definition: energylevelmap.h:42
Absorption::Lines
Definition: absorptionlines.h:547
EnergyLevelMap
Definition: energylevelmap.h:60
Numeric_t
@ Numeric_t
Definition: token.h:30
ARTS::Var::nrows
Index nrows(Workspace &ws) noexcept
Definition: autoarts.h:4682
EnergyLevelMap::InterpToGridPos
EnergyLevelMap InterpToGridPos(Index atmosphere_dim, const ArrayOfGridPos &p, const ArrayOfGridPos &lat, const ArrayOfGridPos &lon) const
Definition: energylevelmap.cc:119
interp_atmfield_gp2itw
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.
Definition: special_interp.cc:75
operator<<
std::ostream & operator<<(std::ostream &os, const EnergyLevelMap &elm)
Definition: energylevelmap.cc:192
special_interp.h
Header file for special_interp.cc.
EnergyLevelMap::operator()
EnergyLevelMap operator()(Index ip, Index ilat, Index ilon) const
Definition: energylevelmap.cc:199
ARTS::Var::x
Vector x(Workspace &ws) noexcept
Definition: autoarts.h:7346
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
ARTS::Var::ncols
Index ncols(Workspace &ws) noexcept
Definition: autoarts.h:4546
EnergyLevelMapType
EnergyLevelMapType
Definition: energylevelmap.h:49
Vector
The Vector class.
Definition: matpackI.h:860
Array::nelem
Index nelem() const
Number of elements.
Definition: array.h:195