Canoe
Comprehensive Atmosphere N' Ocean Engine
nitrogen_cia.cpp
Go to the documentation of this file.
1 // C/C++
2 #include <algorithm>
3 #include <fstream>
4 #include <iostream>
5 #include <string>
6 
7 // canoe
8 #include <air_parcel.hpp>
9 #include <configure.hpp>
10 #include <constants.hpp>
11 
12 // climath
13 #include <climath/interpolation.h>
14 
15 // utils
16 #include <utils/vectorize.hpp>
17 
18 // opacity
19 #include "nitrogen_cia.hpp"
20 
21 // netcdf
22 #ifdef NETCDFOUTPUT
23 extern "C" {
24 #include <netcdf.h>
25 }
26 #endif
27 
28 static int const n_rt_sets = 10;
29 static int const n_fd1_sets = 5;
30 static int const n_fd2_sets = 5;
31 
32 void N2N2CIA::LoadCoefficient(std::string fname, size_t bid) {
33  std::string line;
34  std::ifstream file(fname);
35  double value;
36 
37  // Roto-translational band
38  std::getline(file, line);
39  auto sline = Vectorize<std::string>(line.c_str());
40  int nwave = std::stoi(sline[3]), ntemp = n_rt_sets;
41 
42  rt_axis_.resize(ntemp + nwave);
43  rt_.resize(ntemp * nwave);
44 
45  for (int i = 0; i < ntemp; ++i) {
46  rt_axis_[i] = std::stod(sline[4]);
47  for (int j = 0; j < nwave; ++j) {
48  file >> value;
49  rt_axis_[ntemp + j] = value;
50  file >> value;
51  rt_[i * nwave + j] = std::max(value, 0.);
52  }
53  std::getline(file, line);
54  std::getline(file, line);
55  sline = Vectorize<std::string>(line.c_str());
56  }
57  rt_len_[0] = ntemp;
58  rt_len_[1] = nwave;
59 
60  // Fundamental band
61  nwave = std::stoi(sline[3]), ntemp = n_fd1_sets;
62 
63  fd1_axis_.resize(ntemp + nwave);
64  fd1_.resize(ntemp * nwave);
65 
66  for (int i = 0; i < ntemp; ++i) {
67  fd1_axis_[i] = std::stod(sline[4]);
68  for (int j = 0; j < nwave; ++j) {
69  file >> value;
70  fd1_axis_[ntemp + j] = value;
71  file >> value;
72  fd1_[i * nwave + j] = std::max(value, 0.);
73  }
74  std::getline(file, line);
75  std::getline(file, line);
76  sline = Vectorize<std::string>(line.c_str());
77  }
78  fd1_len_[0] = ntemp;
79  fd1_len_[1] = nwave;
80 
81  // Fundamental band
82  nwave = std::stoi(sline[3]), ntemp = n_fd2_sets;
83 
84  fd2_axis_.resize(ntemp + nwave);
85  fd2_.resize(ntemp * nwave);
86 
87  for (int i = 0; i < ntemp; ++i) {
88  fd2_axis_[i] = std::stod(sline[4]);
89  for (int j = 0; j < nwave; ++j) {
90  if (i == 2) {
91  file >> value;
92  fd2_axis_[ntemp + j] = value;
93  file >> value;
94  fd2_[i * nwave + j] = std::max(value, 0.);
95  } else {
96  file >> value;
97  fd2_axis_[ntemp + j] = value;
98  file >> value;
99  fd2_[i * nwave + j] = std::max(value, 0.);
100  file >> value;
101  }
102  }
103  std::getline(file, line);
104  std::getline(file, line);
105  sline = Vectorize<std::string>(line.c_str());
106  }
107  fd2_len_[0] = ntemp;
108  fd2_len_[1] = nwave;
109 }
110 
111 Real N2N2CIA::getAttenuation1(Real wave, AirParcel const& qfrac) const {
112  Real kk, temp = qfrac.w[IDN];
113 
114  Real coor[2] = {temp, wave};
115 
116  int iN2 = GetSpeciesIndex(0);
117 
118  if (wave >= 0.02 && wave <= 554.) {
119  interpnf(&kk, coor, rt_.data(), rt_axis_.data(), rt_len_, 2);
120  } else if (wave >= 2000. && wave <= 2698.) {
121  interpnf(&kk, coor, fd2_.data(), fd2_axis_.data(), fd2_len_, 2);
122  } else if (wave >= 1850. && wave <= 3000.)
123  interpnf(&kk, coor, fd1_.data(), fd1_axis_.data(), fd1_len_, 2);
124  else
125  kk = 0.;
126 
127  Real num_n2 = qfrac.w[IPR] / (Constants::kBoltz * temp) * qfrac.w[iN2];
128 
129  // cm^5 molecule^{-2} * (molecule m^{-3})^2
130  return 1.E-10 * num_n2 * num_n2 * kk;
131 }
Real *const w
Definition: air_parcel.hpp:36
size_t fd2_len_[2]
std::vector< Real > fd2_axis_
size_t rt_len_[2]
std::vector< Real > rt_axis_
std::vector< Real > fd1_
Real getAttenuation1(Real wave, AirParcel const &var) const
std::vector< Real > rt_
std::vector< Real > fd2_
size_t fd1_len_[2]
void LoadCoefficient(std::string fname, size_t bid) override
Load absorption coefficient from file.
std::vector< Real > fd1_axis_
int GetSpeciesIndex(int n) const
double max(double x1, double x2, double x3)
Definition: core.h:19
void interpnf(double *val, double const *coor, double const *data, double const *axis, size_t const *len, int ndim)
Definition: interpnf.c:13
double const kBoltz
Definition: constants.hpp:7
float temp
Definition: fit_ammonia.py:6
static int const n_fd2_sets
static int const n_rt_sets
static int const n_fd1_sets