ARTS 2.5.0 (git: 9ee3ac6c)
quantum.cc
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#include "quantum.h"
28#include "absorption.h"
29#include "global_data.h"
30#include "special_interp.h"
31#include <stdexcept>
32
35 "Invalid quantum number: ", name)
36}
37
38std::istream& operator>>(std::istream& is, QuantumNumbers& qn) {
39 String name;
40 Rational r;
41
42 is >> name >> r;
43
44 qn.Set(name, r);
45
46 return is;
47}
48
49std::ostream& operator<<(std::ostream& os, const QuantumNumbers& qn) {
50 bool first = true;
51 for (Index i=0; i<Index(QuantumNumberType::FINAL); i++) {
52 if (qn[i].isDefined()) {
53 if (first) {
54 os << QuantumNumberType(i) << ' ' << qn[i];
55 first = false;
56 } else {
57 os << ' ' << QuantumNumberType(i) << ' ' << qn[i];
58 }
59 }
60 }
61
62 return os;
63}
64
65void Quantum::Identifier::SetFromString(String str) {
66 std::istringstream is(str);
67 String token;
68
69 is >> token;
70
71 spec_ind = Species::Tag(token).spec_ind;
72
73 is >> token;
74 if (token == "TR") {
75 type = Quantum::IdentifierType::Transition;
76 is >> token;
77 ARTS_USER_ERROR_IF (token != "UP",
78 "Expected 'UP', but got: ", token)
79
80 is >> token;
81 Rational r;
82 while (is) {
83 if (token == "LO") break;
85 is >> r;
86 Upper().Set(token, r);
87 is >> token;
88 }
89
91 "Premature end of data, expected 'LO'.")
92 is >> token;
93 while (is) {
95 is >> r;
96 Lower().Set(token, r);
97 is >> token;
98 }
99 } else if (token == "EN") {
100 type = Quantum::IdentifierType::EnergyLevel;
101
102 is >> token;
103 Rational r;
104 while (is) {
106 is >> r;
107 Level().Set(token, r);
108 is >> token;
109 }
110 } else if (token == "ALL") {
111 type = Quantum::IdentifierType::All;
112 } else if (token == "NONE") {
114 } else {
116 "Error parsing QuantumIdentifier. Expected TR or EN, but got: ",
117 token, "\n"
118 "QI: ", str)
119 }
120}
121
122String Quantum::Identifier::GetString() const
123{
124 std::ostringstream os;
125 os << *this;
126 return os.str();
127}
128
129
130Rational interpret_stringdata(const QuantumNumberType key, const String& val) {
131 if (key == QuantumNumberType::parity) {
132 if (val == "+")
133 return 1;
134 if (val == "-")
135 return -1;
136 }
137
138 if (key == QuantumNumberType::ElectronState) {
139 if (val == "X")
140 return Rational(int('X'));
141 }
142
143 if (key == QuantumNumberType::kronigParity) {
144 if (val == "f")
145 return Rational(int('f'));
146 if (val == "e")
147 return Rational(int('e'));
148 }
149
150 return Rational(val);
151}
152
153void update_id(QuantumIdentifier& qid, const std::vector<std::array<String, 2> >& upper_list, const std::vector<std::array<String, 2> >& lower_list)
154{
155 for (auto& keyval: upper_list) {
156 auto key = string2quantumnumbertype(keyval[0]);
157 if (key == QuantumNumberType::FINAL) {
158 } else {
159 auto val = interpret_stringdata(key, keyval[1]);
160 if (val != RATIONAL_UNDEFINED) {
161 qid.Upper()[key] = val;
162 } else {
163 }
164 }
165 }
166
167 for (auto& keyval: lower_list) {
168 auto key = string2quantumnumbertype(keyval[0]);
169 if (key == QuantumNumberType::FINAL) {
170 } else {
171 auto val = interpret_stringdata(key, keyval[1]);
172 if (val != RATIONAL_UNDEFINED) {
173 qid.Lower()[key] = val;
174 } else {
175 }
176 }
177 }
178}
179
181{
182 std::ostringstream out;
183 out << (*this) << ' ';
184 String s=out.str();
185 if(s.back() == ' ')
186 s.pop_back();
187 return s;
188}
Declarations required for the calculation of absorption coefficients.
type upp char * str
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
String toString() const
Returns this as a string.
Definition: quantum.cc:180
Implements rational numbers to work with other ARTS types.
Definition: rational.h:52
#define ARTS_USER_ERROR(...)
Definition: debug.h:150
#define ARTS_USER_ERROR_IF(condition,...)
Definition: debug.h:134
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
char Type type
X3 LineCenter None
Definition: constants.h:576
void ThrowIfQuantumNumberNameInvalid(String name)
Check for valid quantum number name and throws if it is invalid.
Definition: quantum.cc:33
std::ostream & operator<<(std::ostream &os, const QuantumNumbers &qn)
Output operator.
Definition: quantum.cc:49
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
Rational interpret_stringdata(const QuantumNumberType key, const String &val)
Definition: quantum.cc:130
Quantum::Identifier QuantumIdentifier
Definition: quantum.h:471
constexpr bool IsValidQuantumNumberName(const std::string_view name)
Check for valid quantum number name.
Definition: quantum.h:482
#define RATIONAL_UNDEFINED
Definition: rational.h:391
Header file for special_interp.cc.