ARTS  2.3.1285(git:92a29ea9-dirty)
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 
95  EnergyLevelMap() : mtype(EnergyLevelMapType::None_t), mlevels(0),
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
113  EnergyLevelMap InterpToGridPos(Index atmosphere_dim, const ArrayOfGridPos& p, const ArrayOfGridPos& lat, const ArrayOfGridPos& lon) const;
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 
137  ArrayOfQuantumIdentifier& Levels() noexcept {return mlevels;}
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  {
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")
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
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Numeric T_upp
Numeric E_upp
Numeric E_low
Index nelem() const
Number of elements.
Definition: array.h:195
String energylevelmaptype2string(EnergyLevelMapType type)
static EnergyLevelMapType string2Type(const String &s) noexcept
The Vector class.
Definition: matpackI.h:860
const Tensor4 & Data() const noexcept
Energy level type.
EnergyLevelMapType mtype
The Tensor4 class.
Definition: matpackIV.h:421
Index npages() const
Returns the number of pages.
Definition: matpackIV.cc:60
const Vector & Energies() const noexcept
Energy level type.
invlib::Vector< ArtsVector > Vector
invlib wrapper type for ARTS vectors.
Definition: oem.h:32
std::ostream & operator<<(std::ostream &os, const EnergyLevelMap &elm)
Contains the absorption namespace.
EnergyLevelMapType string2energylevelmaptype(const String &s)
ArrayOfQuantumIdentifier & Levels() noexcept
Energy level type.
G0 G2 FVC Y DV Numeric Numeric Numeric Zeeman LowerQuantumNumbers void * data
EnergyLevelMap(EnergyLevelMapType new_type, Index pages, Index rows, Index cols, const EnergyLevelMap &old)
Index nrows() const
Returns the number of rows.
Definition: matpackIV.cc:63
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:51
EnergyLevelMapType Type() const noexcept
Energy level type.
ArrayOfQuantumIdentifier mlevels
Tensor4 & Data() noexcept
Energy level type.
void ThrowIfNotOK() const
const ArrayOfQuantumIdentifier & Levels() const noexcept
Energy level type.
EnergyLevelMapType
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
Numeric r_upp
The Matrix class.
Definition: matpackI.h:1193
bool OK() const
Index nelem(const Lines &l)
Number of lines.
Numeric T_low
Index nbooks() const
Returns the number of books.
Definition: matpackIV.cc:57
static bool validIndexForType(Index x) noexcept
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
Numeric r_low
Vector & Energies() noexcept
Energy level type.
Index ncols() const
Returns the number of columns.
Definition: matpackIV.cc:66
EnergyLevelMapType & Type() noexcept
Energy level type.
This file contains the definition of String, the ARTS string class.
void Type(EnergyLevelMapType x) noexcept
Energy level type.