RadLib
Loading...
Searching...
No Matches
parallel_planes.cc
Go to the documentation of this file.
1
3
4#include <cmath> // M_PI, sin, cos
5#include <iostream> //doldb
6#include "../../src/c++/rad.h"
7
8
9
10using namespace std;
11
13
26void I_IT(const vector<double> &x,
27 const double theta,
28 const vector<double> &T,
29 const vector<vector<double>> &kabs,
30 const vector<vector<double>> &awts,
31 const vector<double> &Ilo,
32 const vector<double> &Ihi,
33 vector<vector<double>> &I){
34
35 int n = x.size();
36 int nGGa = I[0].size();
37 double dx;
38
39 double Ib1, Ib2;
40 double mu = abs(cos(theta));
41
42 if(theta <= M_PI/2){
43 I[0] = Ilo;
44 for(int i=0; i<n-1; ++i){
45 Ib1 = rad::sigma/M_PI*pow(T[i+1],4.0);
46 Ib2 = rad::sigma/M_PI*pow(T[i],4.0);
47 dx = x[i+1] - x[i];
48 //I[i+1][0] = I[0][0]; // do the clear gas intensity
49 //for(int j=1; j<nGGa; ++j) // j=1 skips the clear gas, done in previous line
50 for(int j=0; j<nGGa; ++j) // OR, just do all (needed for Planck mean)
51 I[i+1][j] = (I[i][j] + dx/mu*0.5*(kabs[i+1][j]*awts[i+1][j]*Ib1 + kabs[i][j]*(awts[i][j]*Ib2 - I[i][j]))) /
52 (1.0+dx/mu*0.5*kabs[i+1][j]);
53 }
54 }
55 else{
56 I[n-1] = Ihi;
57 for(int i=n-1; i>0; --i){
58 Ib1 = rad::sigma/M_PI*pow(T[i-1],4.0);
59 Ib2 = rad::sigma/M_PI*pow(T[i],4.0);
60 dx = x[i] - x[i-1];
61 //I[i-1][0] = I[n-1][0]; // do the clear gas intensity
62 //for(int j=1; j<nGGa; ++j) // j=1 skips the clear gas, done in previous line
63 for(int j=0; j<nGGa; ++j) // OR, just do all (needed for Planck mean)
64 I[i-1][j] = (I[i][j] + dx/mu*0.5*(kabs[i-1][j]*awts[i-1][j]*Ib1 + kabs[i][j]*(awts[i][j]*Ib2 - I[i][j]))) /
65 (1.0+dx/mu*0.5*kabs[i-1][j]);
66 }
67 }
68}
69
71
93 const double L,
94 const int ntheta,
95 const vector<double> &T,
96 const double P,
97 const vector<double> &fvsoot,
98 const vector<double> &xH2O,
99 const vector<double> &xCO2,
100 const vector<double> &xCO,
101 const vector<double> &xCH4,
102 vector<double> &q,
103 vector<double> &Q,
104 vector<double> &x,
105 vector<double> &xQ,
106 const bool LzeroIbc=false
107 ) {
108
109 //--------------------- set the grid of x and array of theta
110
111 double dtheta = M_PI/ntheta;
112
113 vector<double> theta(ntheta, dtheta/2);
114 for(int i=1; i<ntheta; ++i)
115 theta[i] = theta[i-1] + dtheta;
116
117 int nx = T.size();
118 double dx = L/(nx-1);
119 x = vector<double> (nx, 0.0); // x grid are face values: | | | | |
120 xQ = vector<double> (nx-1,0.0); // xQ grid are cell centers: * * * *
121 for(int i=1; i<x.size(); ++i){
122 x[i] = x[i-1] + dx;
123 xQ[i-1] = 0.5*(x[i-1] + x[i]);
124 }
125
126 //--------------------- initialize radiative properties
127
128 vector<vector<double>> kabs(nx, vector<double>(RAD->get_nGGa()));
129 vector<vector<double>> awts(nx, vector<double>(RAD->get_nGGa()));
130
131 for(int i=0; i<nx; ++i)
132 RAD->get_k_a(kabs[i], awts[i], T[i], P, fvsoot[i], xH2O[i], xCO2[i], xCO[i], xCH4[i]);
133
134 vector<double> Ilo(RAD->get_nGGa(), 0.0);
135 vector<double> Ihi(RAD->get_nGGa(), 0.0);
136
137 for(int j=0; j<Ilo.size(); ++j){
138 if(LzeroIbc){
139 Ilo[j] = 0.0;
140 Ihi[j] = 0.0;
141 }
142 else{
143 Ilo[j] = rad::sigma/M_PI*pow(T[0], 4.0)*awts[0][j];
144 Ihi[j] = rad::sigma/M_PI*pow(T.back(), 4.0)*awts[nx-1][j];
145 }
146 }
147
148 vector<vector<double>> I(nx, vector<double>(RAD->get_nGGa(), 0.0));
149
150 //--------------------- solve for q, Q
151
152 q = vector<double>(nx, 0.0);
153 Q = vector<double>(nx-1, 0.0);
154
155 double sumI;
156
157 for(int j=0; j<ntheta; ++j) {
158 I_IT(x, theta[j], T, kabs, awts, Ilo, Ihi, I);
159 for(int i=0; i<nx; ++i) {
160 sumI = 0.0;
161 for(int k=0; k<RAD->get_nGGa(); ++k)
162 sumI += I[i][k];
163 q[i] += 2.0*M_PI*dtheta*cos(theta[j])*sin(theta[j])*sumI;
164 }
165 }
166
167 for(int i=0; i<nx-1; i++)
168 Q[i] = -(q[i+1]-q[i])/dx;
169
170}
Definition rad.h:20
static constexpr double sigma
Stephan-Boltzmann constant.
Definition rad.h:27
int get_nGGa()
Definition rad.h:63
virtual void get_k_a(std::vector< double > &kabs, std::vector< double > &awts, const double T, const double P, const double fvsoot, const double xH2O, const double xCO2, const double xCO=0, const double xCH4=0)=0
ABSTRACT BASE CLASS.
void parallel_planes(rad *RAD, const double L, const int ntheta, const vector< double > &T, const double P, const vector< double > &fvsoot, const vector< double > &xH2O, const vector< double > &xCO2, const vector< double > &xCO, const vector< double > &xCH4, vector< double > &q, vector< double > &Q, vector< double > &x, vector< double > &xQ, const bool LzeroIbc=false)
void I_IT(const vector< double > &x, const double theta, const vector< double > &T, const vector< vector< double > > &kabs, const vector< vector< double > > &awts, const vector< double > &Ilo, const vector< double > &Ihi, vector< vector< double > > &I)