Canoe
Comprehensive Atmosphere N' Ocean Engine
set_spectral_properties.cpp
Go to the documentation of this file.
1 // cnaoe
2 #include <configure.hpp>
3 
4 // athena
5 #include <athena/coordinates/coordinates.hpp>
6 #include <athena/hydro/hydro.hpp>
7 #include <athena/mesh/mesh.hpp>
8 #include <athena/reconstruct/interpolation.hpp>
9 #include <athena/scalars/scalars.hpp>
10 #include <athena/stride_iterator.hpp>
11 
12 // canoe
13 #include <air_parcel.hpp>
14 #include <constants.hpp>
15 #include <impl.hpp>
16 
17 // snap
19 
20 // opacity
21 #include <opacity/absorber.hpp>
22 
23 // harp
24 #include "radiation.hpp"
25 #include "radiation_band.hpp"
26 
27 // setting optical properties
29  Coordinates const* pcoord, Real grav,
30  int k, int j) {
31  int nspec = GetNumSpecGrids();
32  int npmom = GetNumPhaseMoments();
33 
34  // set tau, ssalb, pmom, etc...
35  tau_.ZeroClear();
36  ssa_.ZeroClear();
37  pmom_.ZeroClear();
38 
39  std::vector<Real> mypmom(1 + npmom);
40 
41  for (int i = 0; i < ac.size(); ++i) {
42  auto& air = ac[i];
43  air.ToMoleFraction();
44  tem_[i] = air.w[IDN];
45 
46  for (auto& a : absorbers_) {
47  for (int m = 0; m < nspec; ++m) {
48  auto& spec = pgrid_->spec[m];
49  Real kcoeff = a->GetAttenuation(spec.wav1, spec.wav2, air); // 1/m
50  Real dssalb =
51  a->GetSingleScatteringAlbedo(spec.wav1, spec.wav2, air) * kcoeff;
52  // tau
53  tau_(m, i) += kcoeff;
54  // ssalb
55  ssa_(m, i) += dssalb;
56  // pmom
57  a->GetPhaseMomentum(mypmom.data(), spec.wav1, spec.wav2, air, npmom);
58  for (int p = 0; p <= npmom; ++p) pmom_(m, i, p) += mypmom[p] * dssalb;
59  }
60  }
61  }
62 
63  // set temperature at cell interface
64  int il = 0, iu = ac.size() - 1;
65  temf_[il] = 3. * tem_[il] - 2. * tem_[il + 1];
66  temf_[il + 1] = (tem_[il] + tem_[il + 1]) / 2.;
67  for (int i = il + 2; i <= iu - 1; ++i)
68  temf_[i] = interp_cp4(tem_[i - 2], tem_[i - 1], tem_[i], tem_[i + 1]);
69  temf_[iu] = (tem_[iu] + tem_[iu - 1]) / 2.;
70  temf_[iu + 1] = 3. * tem_[iu] - 2. * tem_[iu - 1];
71 
72  // absorption coefficiunts -> optical thickness
73  for (int m = 0; m < nspec; ++m) {
74  for (int i = 0; i < ac.size(); ++i) {
75  if (tau_(m, i) > 1e-6 && ssa_(m, i) > 1e-6) { // has scattering
76  for (int p = 0; p <= npmom; ++p) pmom_(m, i, p) /= ssa_(m, i);
77  ssa_(m, i) /= tau_(m, i);
78  } else {
79  ssa_(m, i) = 0.;
80  pmom_(m, i, 0) = 1.;
81  for (int p = 1; p <= npmom; ++p) pmom_(m, i, p) = 0.;
82  }
83 #ifdef HYDROSTATIC
84  auto pthermo = Thermodynamics::GetInstance();
85  Real H0 = pcoord->GetPressureScaleHeight();
86  Real Rgas = pthermo->RovRd(ac[i]) * pthermo->GetRd();
87  // TODO(cli) check this
88  // \delta z = \delt Z * (R T)/(g H0)
89  tau_(m, i) *= pcoord->dx1f(i) * (Rgas * tem_[i]) / (grav * H0);
90 #else
91  tau_(m, i) *= pcoord->dx1f(i);
92 #endif
93  }
94  }
95 
96  // aggregated band properties
97  for (int i = 0; i < ac.size(); ++i) {
98  btau(k, j, i) = 0;
99  bssa(k, j, i) = 0;
100  for (int p = 0; p <= npmom; ++p) bpmom(p, k, j, i) = 0.;
101 
102  for (int m = 0; m < nspec; ++m) {
103  btau(k, j, i) += tau_(m, i);
104  bssa(k, j, i) += ssa_(m, i) * tau_(m, i);
105  for (int p = 0; p <= npmom; ++p)
106  bpmom(p, k, j, i) += pmom_(m, i, p) * ssa_(m, i);
107  }
108 
109  for (int p = 0; p <= npmom; ++p) bpmom(p, k, j, i) /= bssa(k, j, i);
110  bssa(k, j, i) /= btau(k, j, i);
111  btau(k, j, i) /= nspec;
112  }
113 }
std::vector< AirParcel > AirColumn
Definition: air_parcel.hpp:121
std::vector< Real > temf_
temperature at cell boundary (face)
AthenaArray< Real > bpmom
band phase function moments
AthenaArray< Real > pmom_
spectral bin phase function moments
std::shared_ptr< SpectralGridBase > pgrid_
spectral grid
AthenaArray< Real > btau
band optical depth
AthenaArray< Real > ssa_
spectral bin single scattering albedo
std::vector< Real > tem_
temperature at cell center
std::vector< std::shared_ptr< Absorber > > absorbers_
all absorbers
void SetSpectralProperties(AirColumn &air, Coordinates const *pcoord, Real grav, int k, int j)
Set spectral properties for an air column.
AthenaArray< Real > tau_
spectral bin optical depth
size_t GetNumPhaseMoments() const
Get number of phase function moments.
size_t GetNumSpecGrids() const
Get number of spectral grids.
AthenaArray< Real > bssa
band single scattering albedo
static Thermodynamics const * GetInstance()
Return a pointer to the one and only instance of Thermodynamics.
double const Rgas
Definition: constants.hpp:5