ARTS  2.4.0(git:4fb77825)
energylevelmap.h
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 #ifndef energylevelmap_h
28 #define energylevelmap_h
29 
30 #include "absorptionlines.h"
31 #include "matpackIV.h"
32 #include "mystring.h"
33 #include "quantum.h"
34 
35 // Output from EnergyLevelMap
36 struct Output2{
39 };
40 
41 // Output from EnergyLevelMap
42 struct Output4{
47 };
48 
49 enum class EnergyLevelMapType {
50  Tensor3_t,
51  Vector_t,
52  Numeric_t,
53  None_t,
54 };
55 
57 
59 
61 private:
66 
67 public:
68  bool OK() const {
69  if (not (mvalue.nbooks() == mlevels.nelem() and
70  (mvib_energy.nelem() == mlevels.nelem() or mvib_energy.nelem() == 0)))
71  return false; // Bad dimensions, vibrational energies and IDs and data of strange size
72 
73  if (mtype == EnergyLevelMapType::Tensor3_t) {
74  } else if (mtype == EnergyLevelMapType::Vector_t) {
75  if (mvalue.npages() not_eq 1 or mvalue.nrows() not_eq 1)
76  return false; // Bad dimensions for vector type
77  } else if (mtype == EnergyLevelMapType::Numeric_t) {
78  if (mvalue.npages() not_eq 1 or mvalue.nrows() not_eq 1 or mvalue.ncols() not_eq 1)
79  return false; // Bad dimensions for numeric type
80  } else if (mtype == EnergyLevelMapType::None_t) {
81  if (mvalue.npages() not_eq 0 or mvalue.nrows() not_eq 0 or mvalue.ncols() not_eq 0)
82  return false; // Bad dimensions for none type
83  }
84 
85  // FIXME: matpack does not do pointers in a clear manner
86  // return not std::any_of(mvib_energy.begin(), mvib_energy.end(), [](auto& x){return x < 0;});
87 
88  for (auto& e: mvib_energy) if (e < 0) return false; // Bad energies
89 
90  return true;
91  }
92 
93  void ThrowIfNotOK() const {if (not OK()) throw std::runtime_error("Class in bad state");}
94 
96  mvib_energy(0), mvalue(0, 0, 0, 0) {ThrowIfNotOK();}
97 
99  Index cols, const EnergyLevelMap& old) :
100  mtype(new_type), mlevels(old.mlevels), mvib_energy(old.mvib_energy),
101  mvalue(old.mlevels.nelem(), pages, rows, cols) {ThrowIfNotOK();};
102 
103  // Create Tensor3_t from the raw inputs
104  EnergyLevelMap(const Tensor4& data, const ArrayOfQuantumIdentifier& levels, const Vector& energies=Vector(0));
105 
106  // Create Vector_t from the raw inputs
107  EnergyLevelMap(const Matrix& data, const ArrayOfQuantumIdentifier& levels, const Vector& energies=Vector(0));
108 
109  // Create Numeric_t from the raw inputs
110  EnergyLevelMap(const Vector& data, const ArrayOfQuantumIdentifier& levels, const Vector& energies=Vector(0));
111 
112  // Create Vector_t from Tensor3_t
114 
115  // Create Numeric_t from Vector_t
116  EnergyLevelMap operator[](Index ip) const;
117 
118  // Create Numeric_t from Tensor3_t
119  EnergyLevelMap operator()(Index ip, Index ilat, Index ilon) const;
120 
122  EnergyLevelMapType Type() const noexcept {return mtype;}
123 
125  const ArrayOfQuantumIdentifier& Levels() const noexcept {return mlevels;}
126 
128  const Vector& Energies() const noexcept {return mvib_energy;}
129 
131  const Tensor4& Data() const noexcept {return mvalue;}
132 
134  EnergyLevelMapType& Type() noexcept {return mtype;}
135 
138 
140  Vector& Energies() noexcept {return mvib_energy;}
141 
143  Tensor4& Data() noexcept {return mvalue;}
144 
146  // C API interface access //
148 
149  static bool validIndexForType(Index x) noexcept
150  {
151  constexpr auto keys = stdarrayify(Index(EnergyLevelMapType::Tensor3_t), EnergyLevelMapType::Vector_t, EnergyLevelMapType::Numeric_t, EnergyLevelMapType::None_t);
152  return std::any_of(keys.cbegin(), keys.cend(), [x](auto y){return x == y;});
153  }
154 
156  void Type(EnergyLevelMapType x) noexcept {mtype = x;}
157 
158  static EnergyLevelMapType string2Type(const String& s) noexcept
159  {
160  if (s == "Tensor3")
161  return EnergyLevelMapType::Tensor3_t;
162  else if (s == "Vector")
164  else if (s == "Numeric")
166  else if (s == "None")
168  else {
169  return EnergyLevelMapType(-1);
170  }
171  }
172 
174  // Numeric_t access //
176 
182  Output2 get_ratio_params(const AbsorptionLines& band, const Index& line_index) const;
183 
189  Output4 get_vibtemp_params(const AbsorptionLines& band, const Index& line_index, const Numeric T) const;
190 };
191 
192 std::ostream& operator<<(std::ostream& os, const EnergyLevelMap& elm);
193 
194 #endif // energylevelmap_h
Matrix
The Matrix class.
Definition: matpackI.h:1193
ARTS::Var::atmosphere_dim
Index atmosphere_dim(Workspace &ws) noexcept
Definition: autoarts.h:2510
operator<<
std::ostream & operator<<(std::ostream &os, const EnergyLevelMap &elm)
Definition: energylevelmap.cc:192
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
Output4::E_low
Numeric E_low
Definition: energylevelmap.h:43
EnergyLevelMap::Energies
const Vector & Energies() const noexcept
Energy level type.
Definition: energylevelmap.h:128
EnergyLevelMap::Data
const Tensor4 & Data() const noexcept
Energy level type.
Definition: energylevelmap.h:131
EnergyLevelMap::string2Type
static EnergyLevelMapType string2Type(const String &s) noexcept
Definition: energylevelmap.h:158
EnergyLevelMap::Levels
ArrayOfQuantumIdentifier & Levels() noexcept
Energy level type.
Definition: energylevelmap.h:137
absorptionlines.h
Contains the absorption namespace.
EnergyLevelMap::mtype
EnergyLevelMapType mtype
Definition: energylevelmap.h:62
ARTS::Var::y
Vector y(Workspace &ws) noexcept
Definition: autoarts.h:7401
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
EnergyLevelMap::mvalue
Tensor4 mvalue
Definition: energylevelmap.h:65
Output2
Definition: energylevelmap.h:36
quantum.h
Tensor4
The Tensor4 class.
Definition: matpackIV.h:421
stdarrayify
constexpr std::array< T, 1+sizeof...(Ts)> stdarrayify(const T &first, const Ts &... the_rest)
Make a std::array of a list of variables (must be 1-long at least)
Definition: array.h:374
EnergyLevelMapType::Tensor3_t
@ Tensor3_t
ARTS::Var::lon
Numeric lon(Workspace &ws) noexcept
Definition: autoarts.h:4064
EnergyLevelMap::EnergyLevelMap
EnergyLevelMap(EnergyLevelMapType new_type, Index pages, Index rows, Index cols, const EnergyLevelMap &old)
Definition: energylevelmap.h:98
matpackIV.h
Array< QuantumIdentifier >
Output4::T_upp
Numeric T_upp
Definition: energylevelmap.h:46
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
EnergyLevelMap::Data
Tensor4 & Data() noexcept
Energy level type.
Definition: energylevelmap.h:143
my_basic_string< char >
ConstVectorView::nelem
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:51
ConstTensor4View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackIV.cc:66
Output4::T_low
Numeric T_low
Definition: energylevelmap.h:45
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
ConstTensor4View::npages
Index npages() const
Returns the number of pages.
Definition: matpackIV.cc:60
EnergyLevelMap::EnergyLevelMap
EnergyLevelMap()
Definition: energylevelmap.h:95
ConstTensor4View::nbooks
Index nbooks() const
Returns the number of books.
Definition: matpackIV.cc:57
Output4
Definition: energylevelmap.h:42
Absorption::Lines
Definition: absorptionlines.h:547
EnergyLevelMap
Definition: energylevelmap.h:60
Numeric_t
@ Numeric_t
Definition: token.h:30
ConstTensor4View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackIV.cc:63
oem::Vector
invlib::Vector< ArtsVector > Vector
invlib wrapper type for ARTS vectors.
Definition: oem.h:32
EnergyLevelMap::InterpToGridPos
EnergyLevelMap InterpToGridPos(Index atmosphere_dim, const ArrayOfGridPos &p, const ArrayOfGridPos &lat, const ArrayOfGridPos &lon) const
Definition: energylevelmap.cc:119
Output4::E_upp
Numeric E_upp
Definition: energylevelmap.h:44
energylevelmaptype2string
String energylevelmaptype2string(EnergyLevelMapType type)
Definition: energylevelmap.cc:177
EnergyLevelMap::OK
bool OK() const
Definition: energylevelmap.h:68
string2energylevelmaptype
EnergyLevelMapType string2energylevelmaptype(const String &s)
Definition: energylevelmap.cc:160
Output2::r_upp
Numeric r_upp
Definition: energylevelmap.h:38
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
EnergyLevelMap::Energies
Vector & Energies() noexcept
Energy level type.
Definition: energylevelmap.h:140
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
Output2::r_low
Numeric r_low
Definition: energylevelmap.h:37
EnergyLevelMap::Type
EnergyLevelMapType & Type() noexcept
Energy level type.
Definition: energylevelmap.h:134
mystring.h
This file contains the definition of String, the ARTS string class.
EnergyLevelMap::validIndexForType
static bool validIndexForType(Index x) noexcept
Definition: energylevelmap.h:149
EnergyLevelMap::Type
void Type(EnergyLevelMapType x) noexcept
Energy level type.
Definition: energylevelmap.h:156