ARTS 2.5.0 (git: 9ee3ac6c)
quantum.h
Go to the documentation of this file.
1/* Copyright (C) 2013
2 Oliver Lemke <olemke@core-dump.info>
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 quantum_h
28#define quantum_h
29
30#include "array.h"
31#include "enums.h"
32#include "interpolation.h"
33#include "isotopologues.h"
34#include "matpack.h"
35#include "mystring.h"
36#include "rational.h"
37#include <array>
38#include <iostream>
39#include <map>
40#include <numeric>
41#include <stdexcept>
42
44ENUMCLASS(QuantumNumberType, char,
45 J, // Total angular momentum
46 dJ, // Delta total angular momentum
47 M, // Projection of J along magnetic field
48 N, // J minus spin
49 dN, // Delta J minus spin
50 S, // Spin angular momentum (from electrons) NOTE: S_global for HITRAN S
51 tau,
52 n,
53 F, // J + nuclear spin
54 Ka, //(This is a projection of J along one axis)
55 Kc, //(This is a projection of J along another axis)
56 Omega, // This is an absolute projection of J and S
57 i, //(Is related to Omega)
58 Lambda, // This is Sigma or Pi or Lambda states (as seen in literature)
59 alpha, // Alpha from HITRAN
60 Sym, // Symmetry expression
61 parity, // parity value (+/-)
62 kronigParity, // ???
63 v1, // Vibrational mode 1
64 v2, // Vibrational mode 2
65 v3, // Vibrational mode 3
66 v4, // Vibrational mode 4
67 v5, // Vibrational mode 5
68 v6, // Vibrational mode 6
69 v7,
70 v8,
71 v9,
72 v10,
73 v11,
74 v12,
75 l1, // The absolute sum of l_j for v_j
76 l2, // Vibrational angular momentum associated with v2
77 l3,
78 l4,
79 l5,
80 l6,
81 l7,
82 l8,
83 l9,
84 l10,
85 l11,
86 l12,
87 pm, // Symmetry type for l=0
88 r, // Rank of the level within a set of the same vibrational symmetry
89 S_global, // Symmetry of the level
90 ElectronState, // Electronic state
91 n_global, // Torosional quanta
92 C, // Another symmetry expression
93 Hund // Flag for Hund case type. This flag lets Zeeman know what to expect
94) // QuantumNumberType
95
96constexpr QuantumNumberType string2quantumnumbertype(const std::string_view s) {
97 QuantumNumberType out = toQuantumNumberType(s);
98 if (out == QuantumNumberType::FINAL) {
99 if (s.find("F#") < s.length()) out = QuantumNumberType::F; // HITRAN has many names for F
100 else if (s == "K") out = QuantumNumberType::Ka; // HITRAN name
101 else if (s == "v") out = QuantumNumberType::v1; // HITRAN name
102 else if (s == "l") out = QuantumNumberType::l1; // HITRAN name
103 else if (s == "ElecStateLabel") out = QuantumNumberType::ElectronState; // HITRAN name
104 }
105 return out;
106}
107
109enum class Hund : Index { CaseA = int('a'), CaseB = int('b') };
110
113 public:
114 using QuantumContainer = std::array<Rational, Index(QuantumNumberType::FINAL)>;
115
117 constexpr QuantumNumbers() noexcept
135
136 // Temporary initialization until there is a more reliable way to setup
137 // a full initialization for all quantum numbers but only choose a few
138 // select ones based on the problem at hand
139 constexpr QuantumNumbers(Rational J, Rational N, Rational v) noexcept
157
163 constexpr const Rational& operator[](const Index qn) const noexcept {
164 return mqnumbers[qn];
165 }
166
172 constexpr const Rational& operator[](const QuantumNumberType qn) const noexcept {
173 return mqnumbers[Index(qn)];
174 }
175
181 constexpr Rational& operator[](const Index qn) noexcept {
182 return mqnumbers[qn];
183 }
184
190 constexpr Rational& operator[](const QuantumNumberType qn) noexcept {
191 return mqnumbers[Index(qn)];
192 }
193
199 constexpr void Set(Index qn, Rational r) {
200 mqnumbers[qn] = r;
201 }
202
208 constexpr void Set(QuantumNumberType qn, Rational r) {
209 mqnumbers[Index(qn)] = r;
210 }
211
217 constexpr void Set(const std::string_view qn, Rational r) {
218 mqnumbers[Index(string2quantumnumbertype(qn))] = r;
219 }
220
225 [[nodiscard]] constexpr const QuantumContainer& GetNumbers() const { return mqnumbers; }
226
231 [[nodiscard]] constexpr Index nNumbers() const {
232 Index out=0;
233 for (auto& qn: mqnumbers) if (qn.isDefined()) out++;
234 return out;
235 }
236
238 [[nodiscard]] constexpr bool Any() const {
239 for (auto& qn: mqnumbers) if (qn.isDefined()) return true;
240 return false;
241 }
242
244 [[nodiscard]] String toString() const;
245
246 private:
248};
249
257constexpr bool operator==(const QuantumNumbers& a, const QuantumNumbers& b) {
258 for (Index i=0; i<Index(QuantumNumberType::FINAL); i++) {
259 Rational ra = a.GetNumbers()[i];
260 Rational rb = b.GetNumbers()[i];
261 if (ra.isDefined() or rb.isDefined()) {
262 if (ra not_eq rb) {
263 return false;
264 }
265 }
266 }
267 return true;
268}
269
277constexpr bool operator!=(const QuantumNumbers& a, const QuantumNumbers& b) {
278 return not (a == b);
279}
280
282std::istream& operator>>(std::istream& is, QuantumNumbers& qn);
283
285std::ostream& operator<<(std::ostream& os, const QuantumNumbers& qn);
286
288
289namespace Quantum {
290ENUMCLASS (IdentifierType, unsigned char,
291 None,
292 All,
293 Transition,
294 EnergyLevel
295 )
296
297
320struct Identifier {
321 IdentifierType type{IdentifierType::None}; // Type of ID
322 Index spec_ind{-1}; // Index to valid IsotopeRecord in Isotopologues, or -1
323 QuantumNumbers upp{}; // Upper quantum numbers, or energy level quantum numbers
324 QuantumNumbers low{}; // Lower quantum numbers
325
326 [[nodiscard]] constexpr Index SpecInd(const Species::IsotopeRecord& ir) const ARTS_NOEXCEPT {
328 ARTS_ASSERT(ind >= 0 and not Species::is_predefined_model(ir),
329 "Must be valid, non-joker, isotopologue. Is: ", ir)
330 return ind;
331 }
332
334 constexpr Identifier() noexcept = default;
335
336 constexpr Identifier(const Species::IsotopeRecord& ir, IdentifierType t=IdentifierType::All) ARTS_NOEXCEPT :
337 type(t), spec_ind(SpecInd(ir)), upp(), low() {}
338
339 constexpr Identifier(const Species::IsotopeRecord& ir,
341 type(IdentifierType::EnergyLevel), spec_ind(SpecInd(ir)),
342 upp(std::move(el)), low() {}
343
344 constexpr Identifier(const Species::IsotopeRecord& ir,
346 type(IdentifierType::Transition), spec_ind(SpecInd(ir)),
347 upp(std::move(upper)), low(std::move(lower)) {}
348
349 Identifier(const Species::IsotopeRecord& ir,
350 const std::vector<QuantumNumberType>& keys,
351 const std::vector<Rational>& upper,
352 const std::vector<Rational>& lower) ARTS_NOEXCEPT :
353 type(IdentifierType::Transition), spec_ind(SpecInd(ir)), upp(), low() {
354 const std::size_t n = keys.size();
355 ARTS_ASSERT(n == upper.size() and n == lower.size())
356 for (std::size_t i=0; i<n; i++) {
357 upp[keys[i]] = upper[i];
358 low[keys[i]] = lower[i];
359 }
360 }
361
362 void SetFromString(String str);
363
364 [[nodiscard]] String GetString() const;
365
366 explicit Identifier(String x) { SetFromString(std::move(x)); }
367
368 [[nodiscard]] constexpr const Species::IsotopeRecord& Isotopologue() const noexcept {
369 return Species::Isotopologues[spec_ind];
370 }
371
372 constexpr void Isotopologue(const Species::IsotopeRecord& ir) ARTS_NOEXCEPT {
373 spec_ind = SpecInd(ir);
374 }
375
376 [[nodiscard]] constexpr Species::Species Species() const noexcept {
377 return Isotopologue().spec;
378 }
379
380 [[nodiscard]] constexpr const QuantumNumbers& Upper() const ARTS_NOEXCEPT {
381 ARTS_ASSERT(IdentifierType::Transition == type)
382 return upp;
383 }
384
385 constexpr QuantumNumbers& Upper() ARTS_NOEXCEPT {
386 ARTS_ASSERT(IdentifierType::Transition == type)
387 return upp;
388 }
389
390 [[nodiscard]] constexpr const QuantumNumbers& Lower() const ARTS_NOEXCEPT {
391 ARTS_ASSERT(IdentifierType::Transition == type)
392 return low;
393 }
394
395 constexpr QuantumNumbers& Lower() ARTS_NOEXCEPT {
396 ARTS_ASSERT(IdentifierType::Transition == type)
397 return low;
398 }
399
400 [[nodiscard]] constexpr const QuantumNumbers& Level() const ARTS_NOEXCEPT {
401 ARTS_ASSERT(IdentifierType::EnergyLevel == type)
402 return upp;
403 }
404
405 constexpr QuantumNumbers& Level() ARTS_NOEXCEPT {
406 ARTS_ASSERT(IdentifierType::EnergyLevel == type)
407 return upp;
408 }
409
410 constexpr bool operator==(const Identifier& other) const noexcept {
411 if (other.spec_ind not_eq spec_ind) return false;
412
413 // The types must be the same
414 if (other.type not_eq type) {
415 // Except, the joker is a joker for truth
416 if (other.type == IdentifierType::All or type == IdentifierType::All) {
417 return true;
418 }
419
420 return false;
421 }
422
423 switch (type) {
424 case IdentifierType::None: return false;
425 case IdentifierType::All: return true;
426 case IdentifierType::EnergyLevel: return upp == other.upp;
427 case IdentifierType::Transition: return upp == other.upp and low == other.low;
428 case IdentifierType::FINAL: {/* Leave last */
429 }
430 }
431 return false;
432 }
433
434 constexpr bool operator!=(const Identifier& other) const noexcept {
435 return not operator==(other);
436 }
437
438 friend std::ostream& operator<<(std::ostream& os, const Identifier& id) {
439 switch (id.type) {
440 case IdentifierType::None: return os << "NONE"; break;
441 case IdentifierType::All:
442 return os << Species::Isotopologues[id.spec_ind].FullName() << " ALL";
443 case IdentifierType::EnergyLevel:
444 return os << Species::Isotopologues[id.spec_ind].FullName() << " EN " << id.upp;
445 case IdentifierType::Transition:
446 return os << Species::Isotopologues[id.spec_ind].FullName() << " TR"
447 " UP " << id.upp <<
448 " LO " << id.low;
449 case IdentifierType::FINAL: { /* Leave last */
450 }
451 }
452
453 return os;
454 }
455
457 [[nodiscard]] constexpr Identifier LowerId() const ARTS_NOEXCEPT {
458 return Identifier(Species::Isotopologues[spec_ind], low);
459 };
460
462 [[nodiscard]] constexpr Identifier UpperId() const ARTS_NOEXCEPT {
463 return Identifier(Species::Isotopologues[spec_ind], upp);
464 };
465};
466} // namespace Quantum
467
468using QuantumIdentifierType = Quantum::IdentifierType;
469
471using QuantumIdentifier = Quantum::Identifier;
472
475
482constexpr bool IsValidQuantumNumberName(const std::string_view name) {
483 return good_enum(string2quantumnumbertype(name));
484}
485
491
500void update_id(QuantumIdentifier& qid, const std::vector<std::array<String, 2> >& upper_list, const std::vector<std::array<String, 2> >& lower_list);
501
502#endif
This file contains the definition of Array.
type upp char * str
This can be used to make arrays out of anything.
Definition: array.h:107
Container class for Quantum Numbers.
Definition: quantum.h:112
constexpr void Set(Index qn, Rational r)
Set quantum number at position.
Definition: quantum.h:199
constexpr void Set(QuantumNumberType qn, Rational r)
Set quantum number at position.
Definition: quantum.h:208
constexpr QuantumNumbers() noexcept
Initializer with undefined values.
Definition: quantum.h:117
constexpr Rational & operator[](const QuantumNumberType qn) noexcept
Access operator.
Definition: quantum.h:190
constexpr const Rational & operator[](const Index qn) const noexcept
Access operator.
Definition: quantum.h:163
constexpr Index nNumbers() const
The number of defined quantum numbers.
Definition: quantum.h:231
std::array< Rational, Index(QuantumNumberType::FINAL)> QuantumContainer
Definition: quantum.h:114
QuantumContainer mqnumbers
Definition: quantum.h:247
constexpr const Rational & operator[](const QuantumNumberType qn) const noexcept
Access operator.
Definition: quantum.h:172
constexpr void Set(const std::string_view qn, Rational r)
Set quantum number at position.
Definition: quantum.h:217
String toString() const
Returns this as a string.
Definition: quantum.cc:180
constexpr const QuantumContainer & GetNumbers() const
Get the numbers.
Definition: quantum.h:225
constexpr QuantumNumbers(Rational J, Rational N, Rational v) noexcept
Definition: quantum.h:139
constexpr bool Any() const
Check if there's any quantum numbers defined.
Definition: quantum.h:238
constexpr Rational & operator[](const Index qn) noexcept
Access operator.
Definition: quantum.h:181
Implements rational numbers to work with other ARTS types.
Definition: rational.h:52
constexpr bool isDefined() const noexcept
Is the object defined.
Definition: rational.h:115
#define ARTS_NOEXCEPT
Definition: debug.h:80
#define ARTS_ASSERT(condition,...)
Definition: debug.h:83
constexpr bool good_enum(EnumType x) noexcept
Checks if the enum number is good.
Definition: enums.h:21
Header file for interpolation.cc.
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
This file contains the definition of String, the ARTS string class.
char Type type
X3 LineCenter None
Definition: constants.h:576
ENUMCLASS(IdentifierType, unsigned char, None, All, Transition, EnergyLevel) struct Identifier
Class to identify and match lines by their quantum numbers.
Definition: quantum.h:290
constexpr bool is_predefined_model(const IsotopeRecord &ir) noexcept
constexpr std::array Isotopologues
Definition: isotopologues.h:50
constexpr Index find_species_index(const Species spec, const std::string_view isot) noexcept
#define v
#define a
#define b
Hund
Enum for Hund cases.
Definition: quantum.h:109
void ThrowIfQuantumNumberNameInvalid(String name)
Check for valid quantum number name and throws if it is invalid.
Definition: quantum.cc:33
constexpr bool operator==(const QuantumNumbers &a, const QuantumNumbers &b)
Check if all quantum numbers are the same between a and b.
Definition: quantum.h:257
ENUMCLASS(QuantumNumberType, char, J, dJ, M, N, dN, S, tau, n, F, Ka, Kc, Omega, i, Lambda, alpha, Sym, parity, kronigParity, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, pm, r, S_global, ElectronState, n_global, C, Hund) const expr QuantumNumberType string2quantumnumbertype(const std
Enum for Quantum Numbers used for indexing.
Definition: quantum.h:44
constexpr bool operator!=(const QuantumNumbers &a, const QuantumNumbers &b)
Opposite of operator==()
Definition: quantum.h:277
std::ostream & operator<<(std::ostream &os, const QuantumNumbers &qn)
Output operator.
Definition: quantum.cc:49
Quantum::Identifier QuantumIdentifier
Definition: quantum.h:471
void update_id(QuantumIdentifier &qid, const std::vector< std::array< String, 2 > > &upper_list, const std::vector< std::array< String, 2 > > &lower_list)
Updates the quantum identifier based on a lists of strings.
Definition: quantum.cc:153
std::istream & operator>>(std::istream &is, QuantumNumbers &qn)
Input operator.
Definition: quantum.cc:38
Quantum::IdentifierType QuantumIdentifierType
Definition: quantum.h:468
constexpr bool IsValidQuantumNumberName(const std::string_view name)
Check for valid quantum number name.
Definition: quantum.h:482
Contains the rational class definition.
#define RATIONAL_UNDEFINED
Definition: rational.h:391
#define N
Definition: rng.cc:164
#define M
Definition: rng.cc:165
Struct containing all information needed about one isotope.
Definition: isotopologues.h:14