ARTS  2.3.1285(git:92a29ea9-dirty)
linerecord_partitionfunctiondata.cc
Go to the documentation of this file.
1 /* Copyright (C) 2015
2 Richard Larsson <ric.larsson@gmail.com>
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 <cmath>
28 #include "check_input.h"
29 
30 
32 // Partition function interactions to get cross section goes below here
34 
35 
37  const Numeric& line_t0,
38  const Numeric& atm_t) const
39 {
40  if(mtype == PF_NONE) // The standard case
41  return 1;
42  else if(mtype == PF_Coeff) // The Coefficient case
43  {
44  GetCoeff(part, line_t0, atm_t);
45  }
46  else
47  throw std::runtime_error("You are trying to store a partition function type that is unknown to ARTS.\n");
48  return 0;
49 }
50 
51 
52 //Similar to old partition functionality.
53 void PartitionFunctionData::GetCoeff(Numeric& part, const Numeric& line_t0, const Numeric& atm_t) const
54 {
55  assert(mtype == PF_Coeff );
56  assert(mdata.nelem() == 1);
57 
58  Numeric result_t0 = 0.;
59  Numeric result_t = 0.;
60  Numeric exponent_t0 = 1.;
61  Numeric exponent_t = 1.;
62 
63  for (Index ii=0; ii < mnelem; ii++)
64  {
65  result_t += mdata[0][ii] * exponent_t;
66  exponent_t *= atm_t;
67  result_t0 += mdata[0][ii] * exponent_t0;
68  exponent_t0 *= line_t0;
69  }
70  part = result_t0 / result_t;
71 }
72 
73 
74 //Similar to old partition functionality.
75 // void PartitionFunctionData::GetTv(Numeric& part, const Numeric& line_t0, const Numeric& atm_t, const Numeric& atm_p, const Numeric& E_low, const Numeric& E_up) const
76 // {
77 // extern const Numeric BOLTZMAN_CONST;
78 //
79 // const Numeric& Ev_low = mdata[0][0];
80 // const Numeric& Ev_up = mdata[0][1];
81 // const Vector& p_grid = mdata[1];
82 // const Vector& tv_low_grid = mdata[2];
83 // const Vector& tv_up_grid = mdata[3];
84 //
85 // const Vector P0(1,atm_p);
86 // Vector tmp1(1),tmp2(1);
87 //
88 // // Interpolation variables
89 // ArrayOfGridPosPoly gp(1);
90 //
91 // Matrix itw;
92 // itw.resize(gp.nelem(),2);
93 // chk_interpolation_grids("Partition function NLTE pressure interpolation",
94 // p_grid,
95 // P0,
96 // 1);
97 //
98 // // Interpolation variale determination
99 // gridpos_poly(gp, p_grid, P0, 1);
100 // interpweights(itw, gp);
101 //
102 // // Interpolated values
103 // interp(tmp1, itw, tv_low_grid, gp);
104 // interp(tmp2, itw, tv_up_grid, gp);
105 //
106 // // Set temperatures but if the temperature is negative this is a flag for setting temperature to atmospheric temperature
107 // const Numeric& Tv_low = tmp1[0]<0?atm_t:tmp1[0];
108 // const Numeric& Tv_up = tmp2[0]<0?atm_t:tmp2[0];
109 //
110 // const Numeric denom = exp(- E_low / ( BOLTZMAN_CONST * line_t0 ) ) -
111 // exp(- E_up / ( BOLTZMAN_CONST * line_t0 ) );
112 //
113 // const Numeric nom = exp(-Ev_low / ( BOLTZMAN_CONST * Tv_low ) ) * exp(- (E_low-Ev_low) / ( BOLTZMAN_CONST * atm_t ) ) -
114 // exp(-Ev_up / ( BOLTZMAN_CONST * Tv_up ) ) * exp(- (E_up-Ev_up) / ( BOLTZMAN_CONST * atm_t ) );
115 //
116 // part = nom/denom;
117 // }
118 
119 
121 // Partition function interactions to get cross section goes above here
122 // Below is partition function storage functions.
124 
125 
126 // This will parse any Vector by the own mtype to the right settings for mdata
128 {
129  if(mtype == PF_NONE) // The standard case
130  Vector2NoneData(input);
131  else if(mtype == PF_Coeff) // The Coefficient case
132  Vector2CoeffData(input);
133  else
134  throw std::runtime_error("You are trying to store a partition function type that is unknown to ARTS.\n");
135 }
136 
137 
138 // This will convert the read vector to the Coefficient data format
140 {
141  assert(mtype == PF_Coeff);
142 
143  if(input.nelem() != ExpectedVectorLengthFromType())
144  {
145  throw std::runtime_error("The partition function data vector is not of the right length for the coefficient case.\n");
146  }
147 
148  mdata.resize(1);
149 
150  mdata[0] = input;
151 }
152 
153 // // This will convert the read vector to the Coefficient data format
154 // void PartitionFunctionData::Vector2TvData(const Vector& input)
155 // {
156 // assert(mtype == PF_Tv);
157 //
158 // if(input.nelem() != ExpectedVectorLengthFromType())
159 // {
160 // throw std::runtime_error("The partition function data vector is not of the right length for vibrational temperature case.\n");
161 // }
162 //
163 // mdata.resize(4);
164 //
165 // // The vibrational energy levels
166 // mdata[0].resize(2);
167 // mdata[0][0] = input[0]; // Lower vibrational energy level
168 // mdata[0][1] = input[1]; // Upper vibrational energy level
169 //
170 //
171 // mdata[1].resize((mnelem-2)/3);//Pressure Grid
172 // mdata[2].resize((mnelem-2)/3);//Tv low Grid
173 // mdata[3].resize((mnelem-2)/3);//Tv up Grid
174 //
175 // // Loop and insert values in the right spot
176 // for(Index ii=0;ii<(mnelem-2)/3; ii++)
177 // {
178 // mdata[1][ii] = input[2+ii];
179 // mdata[2][ii] = input[2+ii+(mnelem-2)/3];
180 // mdata[3][ii] = input[2+ii+(mnelem-2)/3*2];
181 // }
182 //
183 // }
184 
185 
186 // This will convert the read vector to the none data format
188 { // Setting mdata.resize(0) is probably a better method for this...
190  if( input.nelem() != ExpectedVectorLengthFromType() )
191  throw std::runtime_error("You are trying to set partition function data to a none line mixed line.\n");
192 }
193 
194 
195 // This will convert the stored two char string to PF_Type
197  {
198  if(input == "NA") // The standard case
199  mtype = PF_NONE;
200  else if(input == "CN") // The Coefficient case
201  mtype = PF_Coeff;
202  else
203  throw std::runtime_error("You are trying to read a partition function type that is unknown to ARTS.\n");
204 }
205 
206 
207 // This will convert the Coeff data format to a vector for storage
209 {
210  assert(mtype==PF_Coeff);
211  assert(output.nelem()==mnelem);
212 
213  output = mdata[0];
214 }
215 
216 
217 // This will convert the Tv data format to a vector for storage
218 // void PartitionFunctionData::TvData2Vector(Vector& output) const
219 // {
220 // assert(mtype==PF_Tv);
221 // output.resize(ExpectedVectorLengthFromType());
222 // assert(output.nelem()==mnelem);
223 //
224 // // First two values are for vibrational energy levels
225 // output[0]=mdata[0][0];
226 // output[1]=mdata[0][1];
227 //
228 // // Loop and insert values in the right spot
229 // for(Index ii=0;ii<(mnelem-2)/3; ii++)
230 // {
231 // output[2+ii] = mdata[1][ii];
232 // output[2+ii+(mnelem-2)/3] = mdata[2][ii];
233 // output[2+ii+(mnelem-2)/3*2] = mdata[3][ii];
234 // }
235 // }
236 
238 {
239  if(mtype == PF_NONE) // The standard case
240  output.resize(0);
241  else if(mtype == PF_Coeff) // The Coefficient case
242  CoeffData2Vector(output);
243  else
244  throw std::runtime_error("You are trying to store a partition function type that is unknown to ARTS.\n");
245 }
246 
247 
248 // This will convert PF_Type to a two char string for storage
250 {
251  String output;
252 
253  if(mtype == PF_NONE) // The standard case
254  output = "NA";
255  else if(mtype == PF_Coeff) // The Coefficient case
256  output = "CN";
257  else
258  throw std::runtime_error("You are trying to store a partition function type that is unknown to ARTS.\n");
259  return output;
260 }
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Index nelem() const
Number of elements.
Definition: array.h:195
void CoeffData2Vector(Vector &output) const
The Vector class.
Definition: matpackI.h:860
void GetVectorFromData(Vector &output) const
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:51
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
Index GetPartitionFunctionDataParams(Numeric &part, const Numeric &line_t0, const Numeric &atm_t) const
void GetCoeff(Numeric &part, const Numeric &line_t0, const Numeric &atm_t) const
void Vector2CoeffData(const Vector &input)
void SetDataFromVectorWithKnownType(const Vector &input)
Contains the partition function data class definition.
void resize(Index n)
Resize function.
Definition: matpackI.cc:404
void StorageTag2SetType(const String &input)