-
Notifications
You must be signed in to change notification settings - Fork 0
/
RadMom1DState_First_Order.cc
378 lines (320 loc) · 14.9 KB
/
RadMom1DState_First_Order.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/*!\file RadMom1DState_First_Order.cc
\brief Header file defining 1D RadMom Solution State Classes. */
#ifndef _RADMOM1D_STATE_FIRST_ORDER_INCLUDED
#include "RadMom1DState_First_Order.h"
#endif // _RADMOM1D_STATE_FIRST_ORDER_INCLUDED
// /*************************************************************
// * RadMom1D_pState_First_Order -- Create storage and assign gas constants.*
// *************************************************************/
template <>
int RadMom1D_pState<RadMom1D_cState_First_Order,
RadMom1D_pState_First_Order>::closure_type = MOMENT_CLOSURE_M1;
template <>
int RadMom1D_pState<RadMom1D_cState_First_Order,
RadMom1D_pState_First_Order>::Absorption_Model = MEDIUM1D_ABSORB_GRAY;
template <>
int RadMom1D_pState<RadMom1D_cState_First_Order,
RadMom1D_pState_First_Order>::Scattering_Func = RADIATION_SCATTER_ISO;
template <>
double RadMom1D_pState<RadMom1D_cState_First_Order,
RadMom1D_pState_First_Order>::c = SPEED_OF_LIGHT;
template <>
double RadMom1D_pState<RadMom1D_cState_First_Order,
RadMom1D_pState_First_Order>::a = RADIATION_CONSTANT;
template <>
double RadMom1D_pState<RadMom1D_cState_First_Order,
RadMom1D_pState_First_Order>::C1 = PLANCK_CONSTANT;
int RadMom1D_pState_First_Order :: NUM_VAR_RADMOM1D_FIRST_ORDER = 0;
// /*************************************************************
// * RadMom1D_cState -- Create storage and assign gas constants.*
// *************************************************************/
template <>
int RadMom1D_cState<RadMom1D_cState_First_Order,
RadMom1D_pState_First_Order>::closure_type = MOMENT_CLOSURE_M1;
template <>
int RadMom1D_cState<RadMom1D_cState_First_Order,
RadMom1D_pState_First_Order>::Absorption_Model = MEDIUM1D_ABSORB_GRAY;
template <>
int RadMom1D_cState<RadMom1D_cState_First_Order,
RadMom1D_pState_First_Order>::Scattering_Func = RADIATION_SCATTER_ISO;
template <>
double RadMom1D_cState<RadMom1D_cState_First_Order,
RadMom1D_pState_First_Order>::c = SPEED_OF_LIGHT;
template <>
double RadMom1D_cState<RadMom1D_cState_First_Order,
RadMom1D_pState_First_Order>::a = RADIATION_CONSTANT;
template <>
double RadMom1D_cState<RadMom1D_cState_First_Order,
RadMom1D_pState_First_Order>::C1 = PLANCK_CONSTANT;
int RadMom1D_cState_First_Order :: NUM_VAR_RADMOM1D_FIRST_ORDER = 0;
/*********************************************************
* Routine: Rotate *
* *
* This function returns the solution in the local *
* rotated frame (clockwise). *
* *
*********************************************************/
void RadMom1D_pState_First_Order :: Rotate(const double &norm_dir) {
RadMom1D_pState_First_Order W_rotated;
Copy_to_W(W_rotated);
W_rotated[1] = I0();
W_rotated[2] = norm_dir*N1x();
Copy(W_rotated);
}
void RadMom1D_cState_First_Order :: Rotate(const double &norm_dir) {
RadMom1D_cState_First_Order U_rotated;
Copy_to_U(U_rotated);
U_rotated[1] = I0();
U_rotated[2] = norm_dir*I1x();
Copy(U_rotated);
}
/********************************************************
* Routine: RoeAverage (Roe Averages) *
* *
* This function returns the Roe-averaged (linearized) *
* primitive solution state given left and right *
* primitive solution variables. *
* *
********************************************************/
void RadMom1D_pState_First_Order :: RoeAverage(const RadMom1D_pState_First_Order &Wl,
const RadMom1D_pState_First_Order &Wr) {
RadMom1D_pState_First_Order Wstar;
Wstar = RadMom1D_pState<RadMom1D_cState_First_Order,
RadMom1D_pState_First_Order>::RoeAverage(Wl, Wr);
/* Return the Roe-averged state. */
Copy(Wstar);
}
void RadMom1D_pState_First_Order :: AverageStates(const RadMom1D_pState_First_Order &Wl,
const RadMom1D_pState_First_Order &Wr) {
RadMom1D_pState_First_Order Wstar;
RadMom1D_pState<RadMom1D_cState_First_Order,
RadMom1D_pState_First_Order>::AverageStates(Wstar, Wl, Wr);
/* Return the Roe-averged state. */
Copy(Wstar);
}
/********************************************************
* Routine: Set_ICs *
* *
* This function returns the initial condition state *
* at the left, right, upper or lower boundary or the *
* interior domain given an incoming radiative intensity*
* *
********************************************************/
void RadMom1D_cState_First_Order :: Set_ICs(const double &Medium_Temperature) {
static Medium1D_State Mwall; // a container
// set wall blackbody intensity
Mwall.setBlackBody(Medium_Temperature);
const double Ib_wall(Mwall.Ib());
m_values[0] = Ib_wall*FOUR*PI;
m_values[1] = ZERO;
// m_values[0] = Ib_wall*TWO*PI;
// m_values[1] = Ib_wall*PI;
}
void RadMom1D_cState_First_Order :: Set_ICs_Intensity(const double &Ib_wall) {
m_values[0] = Ib_wall*TWO*PI;
m_values[1] = Ib_wall*PI;
}
/********************************************************
* Routine: Set_BCs *
* *
* This function returns the initial boundary conditions*
* at the left, right, upper or lower boundary or the *
* interior domain given an incoming radiative intensity*
* *
********************************************************/
void RadMom1D_cState_First_Order :: Set_BCs(const double *Intensity,
const double norm_dir) {
m_values[0] = Intensity[0]*TWO*PI;
m_values[1] = -Intensity[0]*PI;
// m_values[0] = Intensity[0]*FOUR*PI;
// m_values[1] = ZERO;
Rotate(norm_dir);
}
void RadMom1D_pState_First_Order :: Gray_Wall(RadMom1D_pState_First_Order W_inner,
const double &wall_temperature,
const double &wall_emissivity,
const double &norm_dir) {
RadMom1D_cState_First_Order U_wall;
static Medium1D_State Mwall; // a container
// set wall blackbody intensity
Mwall.setBlackBody(wall_temperature);
const double Ib_wall(Mwall.Ib());
double Iw;
double Fx_plus, E_plus;
//------------------------------------------------
// for a black wall
//------------------------------------------------
if (wall_emissivity>MICRO) {
Iw = wall_emissivity * Ib_wall;
} else {
Iw = ZERO;
}
//------------------------------------------------
// For grey wall.
//------------------------------------------------
if ( fabs(ONE - wall_emissivity)>MICRO ) {
cout << "Double-check this implementation for M1 and P1 Gray_Wall !!!!" << endl;
switch (RadMom1D_pState_First_Order::closure_type){
case MOMENT_CLOSURE_P1 :
Fx_plus = (ONE/FOUR)*W_inner.I0() + (ONE/TWO)*W_inner.I0()*W_inner.N1x();
break;
case MOMENT_CLOSURE_M1 :
W_inner.Partial_Normalized_Moments_1D(E_plus, Fx_plus);
break;
};
Iw = wall_emissivity * Ib_wall;
Iw += (ONE - wall_emissivity) * Fx_plus/PI;
}
U_wall.Set_BCs(&Iw, norm_dir);
Copy(U_wall.W());
}
/********************************************************
* Routine: PartialMoments_n *
* *
* This function returns the boundary values in the *
* x-direction using partial fluxes given the primitive *
* solution variables in the cell just inside the *
* boundary. *
* *
********************************************************/
void RadMom1D_pState_First_Order :: PartialMoments_n(RadMom1D_pState_First_Order W_inner,
const double &wall_temperature,
const double &wall_emissivity,
const double &norm_dir) {
double E_plus, E_minus, Fx_minus, Fx_plus;
RadMom1D_cState_First_Order U_partial;
W_inner.Rotate(norm_dir);
Gray_Wall(W_inner, wall_temperature, wall_emissivity, norm_dir);
Rotate(norm_dir);
switch (RadMom1D_pState_First_Order::closure_type){
case MOMENT_CLOSURE_P1 :
E_plus = (ONE/TWO)*W_inner.I0() + (THREE/FOUR)*W_inner.I0()*W_inner.N1x();
Fx_plus = (ONE/FOUR)*W_inner.I0() + (ONE/TWO)*W_inner.I0()*W_inner.N1x();
E_minus = I0();
Fx_minus = I0()*N1x();
m_values[0] = E_plus + E_minus;
m_values[1] = (Fx_plus + Fx_minus)/I0();
break;
case MOMENT_CLOSURE_M1 :
E_minus = I0();
Fx_minus = I0()*N1x();
W_inner.Partial_Normalized_Moments_1D(E_plus, Fx_plus);
m_values[0] = E_plus + E_minus;
m_values[1] = (Fx_plus+Fx_minus)/I0();
break;
};
Rotate(norm_dir);
}
void RadMom1D_pState_First_Order :: Partial_Normalized_Moments_1D(double &E_plus, double &Fx_plus) {
double zeta;
if (fabs(N1x()) < 1.0e-3) {
E_plus = (ONE/TWO) + (THREE/FOUR)*N1x();
Fx_plus = (ONE/FOUR) + (ONE/TWO)*N1x();
} else {
zeta = xi();
E_plus = zeta*(NINE*sqr(N1x()) - SIXTEEN) - THIRTY*sqr(N1x()) + cube(N1x()) + SIX*sqr(sqr(N1x())) + THIRTY_TWO;
E_plus /= TWO*cube(N1x());
Fx_plus = THREE*sqr(sqr(N1x())) + zeta*cube(N1x()) - TWO*cube(N1x()) - TWO*cube(zeta) + SIX*sqr(zeta) - EIGHT;
Fx_plus /= TWO*sqr(N1x())*(zeta - TWO);
}
E_plus *= I0();
Fx_plus *= I0();
}
/********************************************************
* Routine: Characteristic *
* *
* This function returns the boundary values using *
* characteristic wavespeeds in the x-direction given *
* the primitive solution variables at the boundary *
* and just inside the boundary. *
* *
********************************************************/
void RadMom1D_pState_First_Order :: Characteristic(RadMom1D_pState_First_Order W_inner,
const double &wall_temperature,
const double &wall_emissivity,
const double &norm_dir) {
double lambda_val;
RadMom1D_pState_First_Order W_charac, W_ghost;
RadMom1D_pState_First_Order Wstar;
RadMom1D_cState_First_Order U_bound;
Eigenstructure_M1 Eig_M1;
double rc_val, lc_val;
W_inner.Rotate(norm_dir);
Gray_Wall(W_inner, wall_temperature, wall_emissivity, norm_dir);
Rotate(norm_dir);
Copy_to_W(W_ghost);
Wstar.RoeAverage(W_inner, W_ghost);
switch(closure_type) {
case MOMENT_CLOSURE_P1 :
Setup_Eigenstructure_P1(Eig_M1);
break;
case MOMENT_CLOSURE_M1 :
// Precompute eigenstructure of the non-gray M1 closure
// if (Wstar.I0() > TOLER_RADIATIVE_DENSITY_M1 &&
// fabs(W_inner.I0() - W_ghost.I0()) > TOLER_RADIATIVE_DENSITY_M1) {
// Setup_Eigenstructure_M1(Eig_M1, W_inner, W_ghost);
// } else {
Wstar.Setup_Eigenstructure_M1(Eig_M1);
// }
break;
default:
cout << "Closure type not specified" << endl;
exit(0);
break;
}
// Compute characteristic variables at the boundaries
for (int i = 0; i < STATIC_NUM_VAR_RADMOM1D_FIRST_ORDER; i++) {
lambda_val = Eig_M1.lambdas[i];
// cout << "Eig_M1.lambdas[0] = " << Eig_M1.lambdas[0] << " " << "Eig_M1.lambdas[1] = " << Eig_M1.lambdas[1] << endl;
W_charac[i+1] = ZERO;
if (lambda_val > -TOLER) {
// Characteristic variable at the boundary is based on the incoming solution
// which in this case corresponds to the inner solution
for (int j = 0; j < STATIC_NUM_VAR_RADMOM1D_FIRST_ORDER; j++) {
lc_val = Eig_M1.lc_vec[i][j];
W_charac[i+1] += lc_val * W_inner.U(j+1);
}
} else {
// Then characteristic variable at the boundary is based on the outgoing solution
// which in this case corresponds to the ghost cell solution
for (int j = 0; j < STATIC_NUM_VAR_RADMOM1D_FIRST_ORDER; j++) {
lc_val = Eig_M1.lc_vec[i][j];
W_charac[i+1] += lc_val * W_ghost.U(j+1);
}
}
}
// /////////////////////////////////////////////////////////
// double temp_val;
// for (int i = 0; i < 2; i++) {
// for (int j = 0; j < 2; j++) {
// temp_val = 0.0;
// for (int k = 0; k < 2; k++) {
// // Compute flux Jacobian based on eigen-decomposition
// temp_val += Eig_M1.rc_vec[i][k] * Eig_M1.lambdas[k] * Eig_M1.lc_vec[k][j];
// // cout << "rc = " << rc_vec[k][l] << " " << "lc = " << lc_vec[k][l] << " " << "lambdas = " << lambdas[k][l] << " " << "k = " << k << " " << "l = " << l << endl;
// }
//
// // if (j == 0 )
// // cout << endl;
// // cout << temp_val << " ";
//
// if (fabs(Eig_M1.dFdU[i][j] - temp_val) > 1.0e-6) {
// cout << "Eigenstructure decomposition not correct: temp_val = " << temp_val << " " << "dFdU[i][j] = " << Eig_M1.dFdU[i][j] << " " << "i = " << i << " " << "j = " << j << endl;
// }
// }
// }
// // exit(0);
// Now compute the solution on the boundary based the vector of characteristic variables
// at that boundary
for (int i = 0; i < STATIC_NUM_VAR_RADMOM1D_FIRST_ORDER; i++) {
// Initialize the conserved variable of interest
U_bound[i+1] = ZERO;
for (int j = 0; j < STATIC_NUM_VAR_RADMOM1D_FIRST_ORDER; j++) {
rc_val = Eig_M1.rc_vec[i][j];
U_bound[i+1] += rc_val * W_charac[j+1];
}
}
m_values[0] = U_bound.W().I0();
m_values[1] = U_bound.W().N1x();
Rotate(norm_dir);
}