GRINS-0.8.0
List of all members | Public Member Functions | Protected Member Functions | Protected Attributes
GRINS::HITRAN Class Reference

HITRAN interface object. More...

#include <hitran.h>

Public Member Functions

 HITRAN (const std::string &data_file, const std::string &partition_function_file, libMesh::Real T_min, libMesh::Real T_max, libMesh::Real T_step)
 Constructor. More...
 
unsigned int isotopologue (unsigned int index)
 Isotopologue ID. More...
 
libMesh::Real nu0 (unsigned int index)
 Linecenter wavenumber [ $ cm^{-1} $]. More...
 
libMesh::Real sw (unsigned int index)
 Linestrength [ $ \frac{cm^{-1}}{molecule \cdot cm^{-2}} $]. More...
 
libMesh::Real gamma_air (unsigned int index)
 Air-broadening half-width [ $ cm^{-1} atm^{-1} $]. More...
 
libMesh::Real gamma_self (unsigned int index)
 Self-broadening half-wdith [ $ cm^{-1} atm^{-1} $]. More...
 
libMesh::Real elower (unsigned int index)
 Lower state energy of transition [ $ cm^{-1} $]. More...
 
libMesh::Real n_air (unsigned int index)
 Temperature coefficient []. More...
 
libMesh::Real delta_air (unsigned int index)
 Air pressure-induced line shift [ $ cm^{-1} atm^{-1} $]. More...
 
libMesh::Real partition_function (libMesh::Real T, unsigned int iso)
 
unsigned int get_data_size ()
 Return the data size. More...
 
libMesh::Real partition_function_derivative (libMesh::Real T, unsigned int iso)
 Finite difference derivative for partition function. More...
 

Protected Member Functions

int T_index (libMesh::Real T)
 Find the index into _T corresponding to the given temperature. More...
 
libMesh::Real get_partition_function_value (libMesh::Real T, unsigned int iso)
 Search through the partition function data to get value for given temperature. More...
 
libMesh::Real interpolate_values (int index_r, libMesh::Real T_star, const std::vector< libMesh::Real > &y) const
 Linear interpolation helper function. More...
 
 HITRAN ()
 User should not call empty constructor. More...
 

Protected Attributes

libMesh::Real _Tmin
 
libMesh::Real _Tmax
 
libMesh::Real _Tstep
 
int _data_size
 Size of spectroscopic data. More...
 
int _q_size
 Size of partition function data. More...
 
libMesh::Real _T0
 Reference temperature (296K) More...
 
std::vector< libMesh::Real > _qT0
 
std::vector< unsigned int > _isotop
 
std::vector< libMesh::Real > _nu
 
std::vector< libMesh::Real > _sw
 
std::vector< libMesh::Real > _gamma_air
 
std::vector< libMesh::Real > _gamma_self
 
std::vector< libMesh::Real > _elower
 
std::vector< libMesh::Real > _n
 
std::vector< libMesh::Real > _delta_air
 
std::vector< std::vector< libMesh::Real > > _qT
 Vector for partition function values for all isotopologues. More...
 

Detailed Description

HITRAN interface object.

This class provides an interface to utilize data from the HITRAN Spectroscopic Database. Data can be pulled directly from the HITRAN website, or through the HITRAN python API, HAPI.

Two files must be provided to this class, one with various data members, and one with values of the partition function at various temperatures.

The data file must contain comma-separated values for individual spectrscopic lines in the following format:
Isotopologue,Linecenter,Linestrength,Air-broadened Half Width,Self-Broadened Half Width,Lower State Energy,Temperature Coefficient,Air-Pressure Shift

The partition function file must contain comma-separated values for each isotopologue at the same temperature values. The temperature limits themselves are specified as inputs to the constructor.

Note the partition function data must explicitly include a value at the given reference temperature, which is currently 296K for HITRAN.

The basic units for values are those given by HITRAN, which currently are [cm] and [atm]

Definition at line 58 of file hitran.h.

Constructor & Destructor Documentation

GRINS::HITRAN::HITRAN ( const std::string &  data_file,
const std::string &  partition_function_file,
libMesh::Real  T_min,
libMesh::Real  T_max,
libMesh::Real  T_step 
)

Constructor.

Parameters
data_fileA file containing values for the required quantities, formatted as described above
partition_function_fileA file containing partition function values, formatted as described above
T_minThe minimum temperature for the partition function values, inclusive
T_maxThe maximum temperature for the partition function values, inclusive
T_stepThe step between successive temperature values

Definition at line 40 of file hitran.C.

References _data_size, _delta_air, _elower, _gamma_air, _gamma_self, _isotop, _n, _nu, _q_size, _qT, _qT0, _sw, _T0, and GRINS::StringUtilities::split_string_real().

42  : _Tmin(T_min),
43  _Tmax(T_max),
44  _Tstep(T_step),
45  _T0(296.0)
46  {
47  // sanity checks on temperature range specification
48  if ( (T_min<0.0) || (T_min>=T_max) || (T_step<=0.0) || (T_min>_T0) || (T_max<_T0) )
49  {
50  std::stringstream ss;
51  ss <<"Invalid specification of temperature range:" <<std::endl;
52  ss <<"T_min: " <<T_min <<std::endl;
53  ss <<"T_max: " <<T_max <<std::endl;
54  ss <<"T_step: " <<T_step <<std::endl;
55  libmesh_error_msg(ss.str());
56  }
57 
58  // open data file
59  std::ifstream hitran_file;
60  hitran_file.open(data_file);
61  if (!hitran_file.is_open())
62  {
63  std::stringstream ss;
64  ss <<"Unable to open provided hitran_file: " <<data_file <<std::endl;
65  libmesh_error_msg(ss.str());
66  }
67 
68  while(!hitran_file.eof())
69  {
70  std::string line;
71  getline(hitran_file,line);
72 
73  if (line == "")
74  continue;
75 
76  std::vector<libMesh::Real> vals;
77 
79 
80  libmesh_assert_equal_to(vals.size(),8);
81 
82  // HITRAN gives isotopologue numbers starting at 1
83  // shift to zero-based to make indexing easier
84  _isotop.push_back(static_cast<unsigned int>(vals[0]-1));
85 
86  _nu.push_back(vals[1]);
87  _sw.push_back(vals[2]);
88  _gamma_air.push_back(vals[3]);
89  _gamma_self.push_back(vals[4]);
90  _elower.push_back(vals[5]);
91  _n.push_back(vals[6]);
92  _delta_air.push_back(vals[7]);
93  }
94 
95  // sanity checks
96  libmesh_assert_equal_to( _isotop.size(), _nu.size() );
97  libmesh_assert_equal_to( _nu.size(), _sw.size() );
98  libmesh_assert_equal_to( _sw.size(), _gamma_air.size() );
99  libmesh_assert_equal_to( _gamma_air.size(), _gamma_self.size() );
100  libmesh_assert_equal_to( _gamma_self.size(), _elower.size() );
101  libmesh_assert_equal_to( _elower.size(), _n.size() );
102  libmesh_assert_equal_to( _n.size(), _delta_air.size() );
103 
104  // save data length and close HITRAN data file
105  _data_size = _isotop.size(); // all data vectors are the same length
106  hitran_file.close();
107 
108  // file with partition function values
109  std::ifstream qT_file;
110  qT_file.open(partition_function_file);
111  if (!qT_file.is_open())
112  {
113  std::stringstream ss;
114  ss <<"Unable to open provided partition_function_file: " <<partition_function_file <<std::endl;
115  libmesh_error_msg(ss.str());
116  }
117 
118  // number of temperature values
119  unsigned int num_T = (T_max-T_min)/T_step + 1;
120 
121  // read the partition function values
122  unsigned int counter = 0;
123 
124  while(!qT_file.eof())
125  {
126  std::string line;
127  getline(qT_file,line);
128 
129  if (line == "")
130  continue;
131 
132  _qT.push_back(std::vector<libMesh::Real>());
133 
135 
136  // we should have a partition function value for each temperature
137  libmesh_assert_equal_to(num_T,_qT[counter].size());
138 
139  counter++;
140  }
141 
142  // save length and close partition sum file
143  _q_size = num_T;
144  qT_file.close();
145 
146  // cache the partition function values at the referece temperature
147  for(unsigned int i=0; i<_qT.size(); i++)
148  _qT0.push_back(this->get_partition_function_value(_T0,i));
149 
150  return;
151  }
std::vector< libMesh::Real > _nu
Definition: hitran.h:124
int _data_size
Size of spectroscopic data.
Definition: hitran.h:110
libMesh::Real _Tstep
Definition: hitran.h:107
std::vector< libMesh::Real > _sw
Definition: hitran.h:125
libMesh::Real _Tmax
Definition: hitran.h:107
std::vector< libMesh::Real > _gamma_air
Definition: hitran.h:126
std::vector< libMesh::Real > _gamma_self
Definition: hitran.h:127
void split_string_real(const std::string &input, const std::string &delimiter, std::vector< libMesh::Real > &results)
Definition: string_utils.C:53
std::vector< libMesh::Real > _n
Definition: hitran.h:129
libMesh::Real _T0
Reference temperature (296K)
Definition: hitran.h:116
std::vector< libMesh::Real > _delta_air
Definition: hitran.h:130
std::vector< unsigned int > _isotop
Definition: hitran.h:123
int _q_size
Size of partition function data.
Definition: hitran.h:113
std::vector< std::vector< libMesh::Real > > _qT
Vector for partition function values for all isotopologues.
Definition: hitran.h:133
libMesh::Real _Tmin
Definition: hitran.h:107
std::vector< libMesh::Real > _elower
Definition: hitran.h:128
std::vector< libMesh::Real > _qT0
Definition: hitran.h:120
GRINS::HITRAN::HITRAN ( )
protected

User should not call empty constructor.

Member Function Documentation

libMesh::Real GRINS::HITRAN::delta_air ( unsigned int  index)

Air pressure-induced line shift [ $ cm^{-1} atm^{-1} $].

Definition at line 228 of file hitran.C.

References _delta_air.

Referenced by GRINSTesting::HITRANtest::parse_from_file().

229  {
230  libmesh_assert_less(index,_delta_air.size());
231  return _delta_air[index];
232  }
std::vector< libMesh::Real > _delta_air
Definition: hitran.h:130
libMesh::Real GRINS::HITRAN::elower ( unsigned int  index)

Lower state energy of transition [ $ cm^{-1} $].

Definition at line 216 of file hitran.C.

References _elower.

Referenced by GRINSTesting::HITRANtest::parse_from_file().

217  {
218  libmesh_assert_less(index,_elower.size());
219  return _elower[index];
220  }
std::vector< libMesh::Real > _elower
Definition: hitran.h:128
libMesh::Real GRINS::HITRAN::gamma_air ( unsigned int  index)

Air-broadening half-width [ $ cm^{-1} atm^{-1} $].

Definition at line 204 of file hitran.C.

References _gamma_air.

Referenced by GRINSTesting::HITRANtest::parse_from_file().

205  {
206  libmesh_assert_less(index,_gamma_air.size());
207  return _gamma_air[index];
208  }
std::vector< libMesh::Real > _gamma_air
Definition: hitran.h:126
libMesh::Real GRINS::HITRAN::gamma_self ( unsigned int  index)

Self-broadening half-wdith [ $ cm^{-1} atm^{-1} $].

Definition at line 210 of file hitran.C.

References _gamma_self.

Referenced by GRINSTesting::HITRANtest::parse_from_file().

211  {
212  libmesh_assert_less(index,_gamma_self.size());
213  return _gamma_self[index];
214  }
std::vector< libMesh::Real > _gamma_self
Definition: hitran.h:127
unsigned int GRINS::HITRAN::get_data_size ( )

Return the data size.

Definition at line 153 of file hitran.C.

References _data_size.

154  {
155  return _data_size;
156  }
int _data_size
Size of spectroscopic data.
Definition: hitran.h:110
libMesh::Real GRINS::HITRAN::get_partition_function_value ( libMesh::Real  T,
unsigned int  iso 
)
protected

Search through the partition function data to get value for given temperature.

Definition at line 246 of file hitran.C.

References _qT, interpolate_values(), and T_index().

Referenced by partition_function().

247  {
248  libMesh::Real retval = -1.0;
249 
250  int i = T_index(T);
251 
252  if (i >= 0)
253  retval = this->interpolate_values(i,T,_qT[iso]);
254  else
255  {
256  std::stringstream ss;
257  ss <<"Error: Temperature " <<T <<"K does not exist in the given partition sum data" <<std::endl;
258  libmesh_error_msg(ss.str());
259  }
260 
261  return retval;
262  }
libMesh::Real interpolate_values(int index_r, libMesh::Real T_star, const std::vector< libMesh::Real > &y) const
Linear interpolation helper function.
Definition: hitran.C:271
std::vector< std::vector< libMesh::Real > > _qT
Vector for partition function values for all isotopologues.
Definition: hitran.h:133
int T_index(libMesh::Real T)
Find the index into _T corresponding to the given temperature.
Definition: hitran.C:264
libMesh::Real GRINS::HITRAN::interpolate_values ( int  index_r,
libMesh::Real  T_star,
const std::vector< libMesh::Real > &  y 
) const
protected

Linear interpolation helper function.

Definition at line 271 of file hitran.C.

References _Tmax, _Tmin, and _Tstep.

Referenced by get_partition_function_value().

272  {
273  if ( (T_star>_Tmax) || (T_star<_Tmin) )
274  {
275  std::stringstream ss;
276  ss <<"Error, temperature T=" <<T_star <<" is outside the specified range of provided partition function values" <<std::endl;
277  libmesh_error_msg(ss.str());
278  }
279 
280  libMesh::Real T = _Tmin + (_Tstep*index_r);
281  return y[index_r-1] + ( (T_star-(T-_Tstep))*(y[index_r]-y[index_r-1]) )/(T-(T-_Tstep));
282  }
libMesh::Real _Tstep
Definition: hitran.h:107
libMesh::Real _Tmax
Definition: hitran.h:107
libMesh::Real _Tmin
Definition: hitran.h:107
unsigned int GRINS::HITRAN::isotopologue ( unsigned int  index)

Isotopologue ID.

Definition at line 186 of file hitran.C.

References _isotop.

Referenced by GRINSTesting::HITRANtest::parse_from_file().

187  {
188  libmesh_assert_less(index,_isotop.size());
189  return _isotop[index];
190  }
std::vector< unsigned int > _isotop
Definition: hitran.h:123
libMesh::Real GRINS::HITRAN::n_air ( unsigned int  index)

Temperature coefficient [].

Definition at line 222 of file hitran.C.

References _n.

Referenced by GRINSTesting::HITRANtest::parse_from_file().

223  {
224  libmesh_assert_less(index,_n.size());
225  return _n[index];
226  }
std::vector< libMesh::Real > _n
Definition: hitran.h:129
libMesh::Real GRINS::HITRAN::nu0 ( unsigned int  index)

Linecenter wavenumber [ $ cm^{-1} $].

Definition at line 192 of file hitran.C.

References _nu.

Referenced by GRINSTesting::HITRANtest::parse_from_file().

193  {
194  libmesh_assert_less(index,_nu.size());
195  return _nu[index];
196  }
std::vector< libMesh::Real > _nu
Definition: hitran.h:124
libMesh::Real GRINS::HITRAN::partition_function ( libMesh::Real  T,
unsigned int  iso 
)

Returns the value of the partition function of the given isotopologue at the given temperature

Definition at line 234 of file hitran.C.

References _qT0, _T0, and get_partition_function_value().

Referenced by GRINSTesting::HITRANtest::parse_from_file(), and partition_function_derivative().

235  {
236  libMesh::Real qt;
237 
238  if (T==_T0)
239  qt = _qT0[iso];
240  else
241  qt = this->get_partition_function_value(T,iso);
242 
243  return qt;
244  }
libMesh::Real get_partition_function_value(libMesh::Real T, unsigned int iso)
Search through the partition function data to get value for given temperature.
Definition: hitran.C:246
libMesh::Real _T0
Reference temperature (296K)
Definition: hitran.h:116
std::vector< libMesh::Real > _qT0
Definition: hitran.h:120
libMesh::Real GRINS::HITRAN::partition_function_derivative ( libMesh::Real  T,
unsigned int  iso 
)

Finite difference derivative for partition function.

Definition at line 158 of file hitran.C.

References _Tmax, _Tmin, _Tstep, and partition_function().

159  {
160  libMesh::Real deriv = -1.0;
161  if (std::abs(T-_Tmin)<libMesh::TOLERANCE) // 1st order forward difference
162  {
163  libMesh::Real QT0 = this->partition_function(_Tmin,iso);
164  libMesh::Real QT1 = this->partition_function(_Tmin+_Tstep,iso);
165 
166  deriv = (QT1-QT0)/_Tstep;
167  }
168  else if (std::abs(T-_Tmax)<libMesh::TOLERANCE) // 1st order backward difference
169  {
170  libMesh::Real QT0 = this->partition_function(_Tmax-_Tstep,iso);
171  libMesh::Real QT1 = this->partition_function(_Tmax,iso);
172 
173  deriv = (QT1-QT0)/_Tstep;
174  }
175  else // 2nd order central difference
176  {
177  libMesh::Real QT1 = this->partition_function(T+_Tstep,iso);
178  libMesh::Real QT0 = this->partition_function(T-_Tstep,iso);
179 
180  deriv = (QT1-QT0)/(2.0*_Tstep);
181  }
182 
183  return deriv;
184  }
libMesh::Real partition_function(libMesh::Real T, unsigned int iso)
Definition: hitran.C:234
libMesh::Real _Tstep
Definition: hitran.h:107
libMesh::Real _Tmax
Definition: hitran.h:107
libMesh::Real _Tmin
Definition: hitran.h:107
libMesh::Real GRINS::HITRAN::sw ( unsigned int  index)

Linestrength [ $ \frac{cm^{-1}}{molecule \cdot cm^{-2}} $].

Definition at line 198 of file hitran.C.

References _sw.

Referenced by GRINSTesting::HITRANtest::parse_from_file().

199  {
200  libmesh_assert_less(index,_sw.size());
201  return _sw[index];
202  }
std::vector< libMesh::Real > _sw
Definition: hitran.h:125
int GRINS::HITRAN::T_index ( libMesh::Real  T)
protected

Find the index into _T corresponding to the given temperature.

Definition at line 264 of file hitran.C.

References _Tmin, and _Tstep.

Referenced by get_partition_function_value().

265  {
266  unsigned int index = std::ceil((T-_Tmin)/_Tstep);
267  index = std::max(index,(unsigned int)1);
268  return index;
269  }
libMesh::Real _Tstep
Definition: hitran.h:107
libMesh::Real _Tmin
Definition: hitran.h:107

Member Data Documentation

int GRINS::HITRAN::_data_size
protected

Size of spectroscopic data.

Definition at line 110 of file hitran.h.

Referenced by get_data_size(), and HITRAN().

std::vector<libMesh::Real> GRINS::HITRAN::_delta_air
protected

Definition at line 130 of file hitran.h.

Referenced by delta_air(), and HITRAN().

std::vector<libMesh::Real> GRINS::HITRAN::_elower
protected

Definition at line 128 of file hitran.h.

Referenced by elower(), and HITRAN().

std::vector<libMesh::Real> GRINS::HITRAN::_gamma_air
protected

Definition at line 126 of file hitran.h.

Referenced by gamma_air(), and HITRAN().

std::vector<libMesh::Real> GRINS::HITRAN::_gamma_self
protected

Definition at line 127 of file hitran.h.

Referenced by gamma_self(), and HITRAN().

std::vector<unsigned int> GRINS::HITRAN::_isotop
protected

Definition at line 123 of file hitran.h.

Referenced by HITRAN(), and isotopologue().

std::vector<libMesh::Real> GRINS::HITRAN::_n
protected

Definition at line 129 of file hitran.h.

Referenced by HITRAN(), and n_air().

std::vector<libMesh::Real> GRINS::HITRAN::_nu
protected

Definition at line 124 of file hitran.h.

Referenced by HITRAN(), and nu0().

int GRINS::HITRAN::_q_size
protected

Size of partition function data.

Definition at line 113 of file hitran.h.

Referenced by HITRAN().

std::vector<std::vector<libMesh::Real> > GRINS::HITRAN::_qT
protected

Vector for partition function values for all isotopologues.

Definition at line 133 of file hitran.h.

Referenced by get_partition_function_value(), and HITRAN().

std::vector<libMesh::Real> GRINS::HITRAN::_qT0
protected

Value of partition function at reference temperature for all isotopologues. Cached since it is used frequently

Definition at line 120 of file hitran.h.

Referenced by HITRAN(), and partition_function().

std::vector<libMesh::Real> GRINS::HITRAN::_sw
protected

Definition at line 125 of file hitran.h.

Referenced by HITRAN(), and sw().

libMesh::Real GRINS::HITRAN::_T0
protected

Reference temperature (296K)

Definition at line 116 of file hitran.h.

Referenced by HITRAN(), and partition_function().

libMesh::Real GRINS::HITRAN::_Tmax
protected

Definition at line 107 of file hitran.h.

Referenced by interpolate_values(), and partition_function_derivative().

libMesh::Real GRINS::HITRAN::_Tmin
protected

Definition at line 107 of file hitran.h.

Referenced by interpolate_values(), partition_function_derivative(), and T_index().

libMesh::Real GRINS::HITRAN::_Tstep
protected

Definition at line 107 of file hitran.h.

Referenced by interpolate_values(), partition_function_derivative(), and T_index().


The documentation for this class was generated from the following files:

Generated on Tue Dec 19 2017 12:47:30 for GRINS-0.8.0 by  doxygen 1.8.9.1