Canoe
Comprehensive Atmosphere N' Ocean Engine
xu_waterice_cloud.cpp
Go to the documentation of this file.
1 // C/C++ headers
2 #include <algorithm>
3 #include <cassert> // assert
4 #include <cstring>
5 #include <fstream>
6 #include <iostream>
7 #include <stdexcept>
8 
9 // canoe
10 #include <air_parcel.hpp>
11 
12 // climath
13 #include <climath/interpolation.h>
14 
15 // utils
16 #include <utils/vectorize.hpp>
17 
18 // snap
20 
21 // harp
22 #include <harp/radiation.hpp> // GetPhaseMomentum
23 
24 // opacity
25 #include "water_cloud.hpp"
26 
27 void XuWaterIceCloud::LoadCoefficient(std::string fname, size_t bid) {
28  std::string line;
29  std::ifstream file(fname.c_str(), std::ios::in);
30 
31  int nwave = 396, nsize = 189;
32 
33  axis_.resize(nwave + nsize);
34  ssalb_.resize(nwave * nsize);
35  gg_.resize(nwave * nsize);
36 
37  Real value;
38  for (int i = 0; i < nwave; ++i) {
39  for (int j = 0; j < nsize; ++j) {
40  std::getline(file, line);
41 
42  auto sline = Vectorize<std::string>(line.c_str());
43  if (i == 0) axis_[nwave + j] = atof(sline[1].c_str());
44  if (j == 0) axis_[i] = atof(sline[0].c_str());
45  ssalb_[i * nsize + j] = atof(sline[5].c_str());
46  gg_[i * nsize + j] = atof(sline[6].c_str());
47  /*
48  if (i ==0) axis_[nwave+j] = std::stod(sline[1]);
49  if (j ==0) axis_[i] = std::stod(sline[0]);
50  ssalb_[i*nsize+j] = std::stod(sline[5]);
51  gg_[i*nsize+j] = std::stod(sline[6]);
52  */
53  }
54  }
55  len_[0] = nwave; // number of wavelength
56  len_[1] = nsize; // number of size
57 }
58 
59 Real XuWaterIceCloud::getAttenuation1(Real wave, AirParcel const& air) const {
60  Real T1, re, result;
61  // calculate ice cloud size
62  T1 = air.w[IDN] - 273.15; // K to C
63  T1 = std::min(-25., std::max(-50., T1));
64  re = 326.3 + 12.42 * T1 + 0.197 * T1 * T1 + 0.0012 * T1 * T1 * T1;
65  Real dens = air.w[IPR] * 29e-3 / (Constants::Rgas * air.w[IDN]);
66 
67  result = (0.003448 + 2.431 / re) * dens * air.c[GetCloudIndex(0)] * 1e9;
68 
69  return result;
70 }
71 
73  AirParcel const& air) const {
74  Real T1, re, kk;
75  // calculate ice cloud size
76  T1 = air.w[IDN] - 273.15; // K to C
77  T1 = std::min(-25., std::max(-50., T1));
78  re = 326.3 + 12.42 * T1 + 0.197 * T1 * T1 + 0.0012 * T1 * T1 * T1;
79 
80  Real ww = 10000. / wave; // wavelength(um) to wavenumber (cm-1)
81  Real coor[2] = {ww, re};
82 
83  interpnf(&kk, coor, ssalb_.data(), axis_.data(), len_, 2);
84 
85  // if (air.w[imols_[0]]<2e-19){
86  // return 0.0;
87  // }else{
88  return kk;
89  //}
90 }
91 
92 void XuWaterIceCloud::getPhaseMomentum1(Real* pp, Real wave,
93  AirParcel const& air, int np) const {
94  Real T1, re, gg;
95  // calculate ice cloud size
96  T1 = air.w[IDN] - 273.15; // K to C
97  T1 = std::min(-25., std::max(-50., T1));
98  re = 326.3 + 12.42 * T1 + 0.197 * T1 * T1 + 0.0012 * T1 * T1 * T1;
99 
100  Real ww = 10000. / wave; // wavelength(um) to wavenumber (cm-1)
101  Real coor[2] = {ww, re};
102 
103  interpnf(&gg, coor, gg_.data(), axis_.data(), len_, 2);
104 
105  // if (air.w[imols_[0]]<2e-19){
106  // get_phase_momentum(pp, 0.0, np); // 0 for HENYEY_GREENSTEIN
107  // }else{
109  //}
110 }
Real *const w
Definition: air_parcel.hpp:36
Real *const c
cloud data
Definition: air_parcel.hpp:39
int GetCloudIndex(int n) const
std::vector< Real > axis_
void LoadCoefficient(std::string fname, size_t bid) override
Load absorption coefficient from file.
Real getAttenuation1(Real wave, AirParcel const &var) const
std::vector< Real > ssalb_
Real getSingleScatteringAlbedo1(Real wave, AirParcel const &var) const
std::vector< Real > gg_
void getPhaseMomentum1(Real *pp, Real wave, AirParcel const &var, int np) const
double min(double x1, double x2, double x3)
Definition: core.h:16
double max(double x1, double x2, double x3)
Definition: core.h:19
Real re[8]
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 Rgas
Definition: constants.hpp:5
void get_phase_momentum(Real *pmom, int iphas, Real gg, int npmom)
Definition: radiation.cpp:256