-
Notifications
You must be signed in to change notification settings - Fork 0
/
RadMom1DState.h
836 lines (707 loc) · 25.7 KB
/
RadMom1DState.h
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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
/*!\file RadMom1DState.h
\brief Header file defining 1D RadMom Solution State Classes. */
#ifndef _RADMOM1D_STATE_INCLUDED
#define _RADMOM1D_STATE_INCLUDED
/* Include required C++ libraries. */
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstdlib>
#include <cstring>
/* Using std namespace functions */
using namespace std;
#ifndef _MATH_MACROS_INCLUDED
#include "./Math.h"
#endif // _MATH_MACROS_INCLUDED
#ifndef _CFD_INCLUDED
#include "./CFD/CFD.h"
#endif // _CFD_INCLUDED
#ifndef _MEDIUM_1D_STATE_INCLUDED
#include "./Medium1DState/Medium1DState.h"
#endif //_MEDIUM_1D_STATE_INCLUDED
// Enviroment flag for cfrte1D root directory path
#define PATHVAR "cfrte1D_Path"
/* Define the classes. */
template<class cState, class pState>
class RadMom1D_cState;
template<class cState, class pState>
class RadMom1D_pState;
/*!
* Class: RadMom1D_pState
*
* @brief Base class for primitive variable solution state class .
*
* \verbatim
* Member functions
* closure_type -- moment closure type for solving the radiative transfer equation.
* Absorption_Model -- absorption model for the absorption coefficient.
* Scattering_Func -- model for scattering phase function.
* C1 -- Return Planck constant
* a -- Return blackbody source constant 8*pi^5*k^4/(15*h^3*c^3).
* Sr -- Return source term.
*
* Member operators
* W -- a primitive solution state
* b -- a scalar (double)
*
* W = W;
* c = W[i];
* W = W + W;
* W = W - W;
* c = W * W; (inner product)
* W = c * W;
* W = W * c;
* W = W / c;
* W = W ^ W; (a useful product)
* W = +W;
* W = -W;
* W += W;
* W -= W;
* W == W;
* W != W;
* cout << W; (output function)
* cin >> W; (input function)
* \endverbatim
*/
template<class cState, class pState>
class RadMom1D_pState {
protected:
private:
public:
static int closure_type; //!< Identifier for either M1 or P1 moment closure.
static int Absorption_Model;
static int Scattering_Func;
static double c; //!< Speed of light.
static double a; //!< Blackbody source constant.
// Planck constants
static double C1; // [W/(m2 ster m-4)]
//@}
//@{ @name Creation, copy, and assignment constructors.
//! Creation constructor.
RadMom1D_pState(void) {}
/* Destructor. */
~RadMom1D_pState(void) { }
// Use automatically generated destructor.
//@}
//! Copy operator.
void Copy(pState &W_this, const pState &W) {
for ( int i = 1; i <= W.NumVar(); i++ ){
W_this[i] = W[i];
}
}
void Copy_to_W(pState &W_copy, const pState &W) const {
// Must be const because called by const member function in derived class
for ( int i = 1; i <= W.NumVar(); i++ ){
W_copy[i] = W[i];
}
}
//! Vacuum operator.
void Vacuum(pState &W) {
for ( int i = 1; i <= W.NumVar(); i++ ){
W[i] = ZERO;
}
}
//! Ones operator.
void Ones(pState &W) {
for ( int i = 1; i <= W.NumVar(); i++ ){
W[i] = ONE;
}
}
//@}
//@{ @name Conserved solution state.
double U_from_W(const pState &W, const int &index_U) const;
cState U_from_W(const pState &W) const;
// friend cState U(const pState &W);
//@}
//@{ @name First order linear solution reconstruction
void Solution_Reconstruct( pState &Wrecon,
const pState &Wc,
const pState &phi,
const pState &dWdx,
const double &dX);
//! @name Allocators and deallocators
//@{
//! Setup state static variables
//! memory allocation / deallocation for the static arrays
static void SetupStatic( const int &ScatteringFunc,
const int &i_Moment_Closure,
const int &i_AbsorptionModel);
static void DeallocateStatic();
//@{ @name Binary arithmetic operators.
void addition(pState &W_this, const pState &W2);
void subtraction(pState &W_this, const pState &W2);
void multiplication(pState &W_this, const double &b);
void multiplication(const double &b, pState &W_this);
void division(pState &W_this, const double &b);
void division(pState &W_this, const pState &W_denom);
double multiplication(pState &W_this, const pState &W2);
void dot_product(pState &W_this, const pState &W2);
/* Assignment operator. */
void equals(pState &W_this, const pState &W);
//@{ @name Shortcut arithmetic operators.
void plus_equal(pState &W_this, const pState &W2);
void minus_equal(pState &W_this, const pState &W2);
void times_equal(pState &W_this, const double &b);
void times_equal(pState &W_this, const pState &W2);
void divide_equal(pState &W_this, const double &b);
void divide_equal(pState &W_this, const pState &W2);
//@}
//@{ @name Input-output operators.
void output(ostream &out_file, const pState &W);
void input(istream &in_file, pState &W);
//@}
//! Index operator.
double& W_index(pState &W, int index) {
assert( index >= 1 && index <= W.NumVar() );
return W.m_values[index-1];
}
const double& W_index(const pState &W, int index) const {
assert( index >= 1 && index <= W.NumVar() );
return W.m_values[index-1];
}
// Routines for computing approximate Roe matrix
pState U_to_W_Roe(const cState &U) const;
cState W_Roe_to_U(const pState &W_Roe) const;
void AverageStates(pState &Wstar, const pState &Wl, const pState &Wr);
pState RoeAverage(const pState &Wl, const pState &Wr);
};
// end of RadMom1D_pState class
/*!
* Class: RadMom1D_cState
*
* @brief Base class for conserved variable solution state class .
*
* \verbatim
* Member functions
* closure_type -- moment closure type for solving the radiative transfer equation.
* Absorption_Model -- absorption model for the absorption coefficient.
* Scattering_Func -- model for scattering phase function.
* C1 -- Return Planck constant
* a -- Return blackbody source constant 8*pi^5*k^4/(15*h^3*c^3).
* Sr -- Return source term.
* Member operators
* U -- a primitive solution state
* b -- a scalar (double)
*
* U = U;
* c = U[i];
* U = U + U;
* U = U - U;
* c = U * U; (inner product)
* U = c * U;
* U = U * c;
* U = U / c;
* U = U ^ U; (a useful product)
* U = +U;
* U = -U;
* U += U;
* U -= U;
* U == U;
* U != U;
* cout << U; (output function)
* cin >> U; (input function)
* \endverbatim
*/
template<class cState, class pState>
class RadMom1D_cState {
protected:
private:
public:
static int closure_type; //!< Identifier for either M1 or P1 moment closure.
static int Absorption_Model;
static int Scattering_Func;
static double c; //!< Speed of light.
static double a; //!< Blackbody source constant.
// Planck constants
static double C1; // [W/(m2 ster m-4)]static
//@{ @name Creation, copy, and assignment constructors.
//! Creation constructor.
RadMom1D_cState(void) { }
/* Destructor. */
~RadMom1D_cState(void) { }
// Use automatically generated destructor.
//@}
//! Copy operator.
void Copy(cState &U_this, const cState &U) {
for ( int i = 1; i <= U.NumVar(); i++ ){
U_this[i] = U[i];
}
}
void Copy_to_U(cState &U_copied, const cState &U) const {
for ( int i = 1; i <= U.NumVar(); i++ ){
U_copied[i] = U[i];
}
}
//! Vacuum operator.
void Vacuum(cState &U) {
for ( int i = 1; i <= U.NumVar(); i++ ){
U[i] = ZERO;
}
}
//! Ones operator.
void Ones(cState &U) {
for ( int i = 1; i <= U.NumVar(); i++ ){
U[i] = ONE;
}
}
//@{ @name Primitive solution state.
pState W_from_U(const cState &U) const ;
// friend pState W <cState, pState>(const cState &U);
//@}
//@{ @name Include all source vectors and Jacobians.
double Srad(const cState &U, const Medium1D_State &M) const;
//! Setup state static variables
//! memory allocation / deallocation for the static arrays
static void SetupStatic( const int &ScatteringFunc,
const int &i_Moment_Closure,
const int &i_AbsorptionModel);
static void DeallocateStatic();
//@{ @name Binary arithmetic operators.
void addition(cState &U_this, const cState &U2);
void subtraction(cState &U_this, const cState &U2);
void multiplication(cState &U_this, const double &b);
void multiplication(const double &b, cState &U_this);
void division(cState &U_this, const double &b);
void division(cState &U_this, const cState &U_denom);
double multiplication(cState &U_this, const cState &U2);
void dot_product(cState &U_this, const cState &U2);
/* Assignment operator. */
void equals(cState &U_this, const cState &U);
//@{ @name Shortcut arithmetic operators.
void plus_equal(cState &U_this, const cState &U2);
void minus_equal(cState &U_this, const cState &U2);
void times_equal(cState &U_this, const double &b);
void times_equal(cState &U_this, const cState &U2);
void divide_equal(cState &U_this, const double &b);
void divide_equal(cState &U_this, const cState &U2);
//@}
//@{ @name Input-output operators.
void output(ostream &out_file, const cState &U);
void input(istream &in_file, cState &U);
//@}
//! Index operator.
double& U_index(cState &U, int index) {
assert( index >= 1 && index <= U.NumVar() );
return U.m_values[index-1];
}
const double& U_index(const cState &U, int index) const {
assert( index >= 1 && index <= U.NumVar() );
return U.m_values[index-1];
}
};
// End of RadMom1D_cState class
/****************************************************************//**
* RadMom1D_pState -- Binary arithmetic operators.
********************************************************************/
//! addition
template<class cState, class pState>
inline void RadMom1D_pState<cState, pState> :: addition(pState &W_this, const pState &W2) {
plus_equal(W_this, W2);
}
//! subtraction
template<class cState, class pState>
inline void RadMom1D_pState<cState, pState> :: subtraction(pState &W_this, const pState &W2) {
minus_equal(W_this, W2);
}
//! scalar multiplication
template<class cState, class pState>
inline void RadMom1D_pState<cState, pState> :: multiplication(pState &W_this, const double &b) {
times_equal(W_this, b);
}
template<class cState, class pState>
inline void RadMom1D_pState<cState, pState> :: multiplication(const double &b, pState &W_this) {
times_equal(W_this, b);
}
//! scalar division
template<class cState, class pState>
inline void RadMom1D_pState<cState, pState> :: division(pState &W_this, const double &b) {
divide_equal(W_this, b);
}
//! solution state division operator
template<class cState, class pState>
inline void RadMom1D_pState<cState, pState> :: division(pState &W_this, const pState &W_denom) {
divide_equal(W_this, W_denom);
}
//! inner product
template<class cState, class pState>
inline double RadMom1D_pState<cState, pState> :: multiplication(pState &W1, const pState &W2) {
double sum=0.0;
for ( int i = 1; i <= W1.NumVar(); i++ ) {
sum += W1[i]*W2[i];
}
return sum;
}
//! solution state product operator
template<class cState, class pState>
inline void RadMom1D_pState<cState, pState> :: dot_product(pState &W_this, const pState &W2) {
times_equal(W_this, W2);
}
/****************************************************************//**
* RadMom1D_pState -- Assignment operator.
********************************************************************/
template<class cState, class pState>
inline void RadMom1D_pState<cState, pState> :: equals(pState &W_this, const pState &W) {
Copy_to_W(W_this, W);
}
/****************************************************************//**
* RadMom1D_pState -- Shortcut operators.
********************************************************************/
template<class cState, class pState>
inline void RadMom1D_pState<cState, pState> :: plus_equal(pState &W_this, const pState &W2) {
for ( int i = 1; i <= W_this.NumVar(); i++ ) {
W_this[i] += W2[i];
}
}
template<class cState, class pState>
inline void RadMom1D_pState<cState, pState> :: minus_equal(pState &W_this, const pState &W2) {
for ( int i = 1; i <= W_this.NumVar(); i++ ) {
W_this[i] -= W2[i];
}
}
template<class cState, class pState>
inline void RadMom1D_pState<cState, pState>::times_equal(pState &W_this, const double &b) {
for ( int i = 1; i <= W_this.NumVar(); i++ ) {
W_this[i] *= b;
}
}
template<class cState, class pState>
inline void RadMom1D_pState<cState, pState>::times_equal(pState &W_this, const pState &W2) {
for ( int i = 1; i <= W_this.NumVar(); i++ ) {
W_this[i] *= W2[i];
}
}
template<class cState, class pState>
inline void RadMom1D_pState<cState, pState>::divide_equal(pState &W_this, const double &b) {
for ( int i = 1; i <= W_this.NumVar(); i++ ) {
W_this[i] /= b;
}
}
template<class cState, class pState>
inline void RadMom1D_pState<cState, pState>::divide_equal(pState &W_this, const pState &W2) {
for ( int i = 1; i <= W_this.NumVar(); i++ ) {
W_this[i] /= W2[i];
}
}
/****************************************************************//**
* RadMom1D_cState -- Binary arithmetic operators.
********************************************************************/
//! addition
template<class cState, class pState>
inline void RadMom1D_cState<cState, pState> :: addition(cState &U_this, const cState &U2) {
plus_equal(U_this, U2);
}
//! subtraction
template<class cState, class pState>
inline void RadMom1D_cState<cState, pState> :: subtraction(cState &U_this, const cState &U2) {
minus_equal(U_this, U2);
}
//! scalar multiplication
template<class cState, class pState>
inline void RadMom1D_cState<cState, pState> :: multiplication(cState &U_this, const double &b) {
times_equal(U_this, b);
}
template<class cState, class pState>
inline void RadMom1D_cState<cState, pState> :: multiplication(const double &b, cState &U_this) {
times_equal(U_this, b);
}
//! scalar division
template<class cState, class pState>
inline void RadMom1D_cState<cState, pState> :: division(cState &U_this, const double &b) {
divide_equal(U_this, b);
}
//! solution state division operator
template<class cState, class pState>
inline void RadMom1D_cState<cState, pState> :: division(cState &U_this, const cState &U_denom) {
divide_equal(U_this, U_denom);
}
//! inner product
template<class cState, class pState>
inline double RadMom1D_cState<cState, pState> :: multiplication(cState &U1, const cState &U2) {
double sum=0.0;
for ( int i = 1; i <= U1.NumVar(); i++ ) {
sum += U1[i]*U2[i];
}
return sum;
}
//! solution state product operator
template<class cState, class pState>
inline void RadMom1D_cState<cState, pState> :: dot_product(cState &U_this, const cState &U2) {
times_equal(U_this, U2);
}
/****************************************************************//**
* RadMom1D_cState -- Assignment operator.
********************************************************************/
template<class cState, class pState>
inline void RadMom1D_cState<cState, pState> :: equals(cState &U_this, const cState &U) {
Copy_to_U(U_this, U);
}
/****************************************************************//**
* RadMom1D_cState -- Shortcut operators.
********************************************************************/
template<class cState, class pState>
inline void RadMom1D_cState<cState, pState> :: plus_equal(cState &U_this, const cState &U2) {
for ( int i = 1; i <= U_this.NumVar(); i++ ) {
U_this[i] += U2[i];
}
}
template<class cState, class pState>
inline void RadMom1D_cState<cState, pState> :: minus_equal(cState &U_this, const cState &U2) {
for ( int i = 1; i <= U_this.NumVar(); i++ ) {
U_this[i] -= U2[i];
}
}
template<class cState, class pState>
inline void RadMom1D_cState<cState, pState>::times_equal(cState &U_this, const double &b) {
for ( int i = 1; i <= U_this.NumVar(); i++ ) {
U_this[i] *= b;
}
}
template<class cState, class pState>
inline void RadMom1D_cState<cState, pState>::times_equal(cState &U_this, const cState &U2) {
for ( int i = 1; i <= U_this.NumVar(); i++ ) {
U_this[i] *= U2[i];
}
}
template<class cState, class pState>
inline void RadMom1D_cState<cState, pState>::divide_equal(cState &U_this, const double &b) {
for ( int i = 1; i <= U_this.NumVar(); i++ ) {
U_this[i] /= b;
}
}
template<class cState, class pState>
inline void RadMom1D_cState<cState, pState>::divide_equal(cState &U_this, const cState &U2) {
for ( int i = 1; i <= U_this.NumVar(); i++ ) {
U_this[i] /= U2[i];
}
}
/********************************************************
* RadMom1D_pState -- Input-output operators. *
********************************************************/
template<class cState, class pState>
inline void RadMom1D_pState<cState, pState> :: output(ostream &out_file, const pState &W) {
out_file.setf(ios::scientific);
out_file << " ";
for (int i = 0; i < W.NumVar(); i++) {
out_file << W[i+1];
if (i < W.NumVar() - 1) {
out_file << " ";
}
}
out_file << "\n";
out_file.unsetf(ios::scientific);
}
template<class cState, class pState>
inline void RadMom1D_pState<cState, pState> :: input(istream &in_file, pState &W) {
in_file.setf(ios::skipws);
for (int i = 0; i < W.NumVar(); i++) {
in_file >> W[i+1];
}
in_file.unsetf(ios::skipws);
}
/********************************************************
* RadMom1D_cState -- Input-output operators. *
********************************************************/
template<class cState, class pState>
inline void RadMom1D_cState<cState, pState> :: output(ostream &out_file, const cState &U) {
out_file.setf(ios::scientific);
out_file << " ";
for (int i = 0; i < U.NumVar(); i++) {
out_file << U[i+1];
if (i < U.NumVar() - 1) {
out_file << " ";
}
}
out_file << "\n";
out_file.unsetf(ios::scientific);
}
template<class cState, class pState>
inline void RadMom1D_cState<cState, pState> :: input(istream &in_file, cState &U) {
in_file.setf(ios::skipws);
for (int i = 0; i < U.NumVar(); i++) {
in_file >> U[i+1];
}
in_file.unsetf(ios::skipws);
}
/****************************************************************//**
* RadMom1D_pState :: Setting up static variables.
********************************************************************/
template<class cState, class pState>
inline void RadMom1D_pState<cState, pState> :: SetupStatic( const int &ScatteringFunc,
const int &i_Moment_Closure,
const int &i_AbsorptionModel)
{
closure_type = i_Moment_Closure;
Absorption_Model = i_AbsorptionModel;
Scattering_Func = ScatteringFunc;
if (closure_type != MOMENT_CLOSURE_P1 &&
closure_type != MOMENT_CLOSURE_M1 &&
closure_type != MOMENT_CLOSURE_P3) {
cout << "Closure type not specified properly !!!!" << endl;
cout << "Should specify MOMENT_CLOSURE_M1 or MOMENT_CLOSURE_P1 or MOMENT_CLOSURE_P3" << endl;
exit(0);
}
}
template<class cState, class pState>
inline void RadMom1D_pState<cState, pState> :: DeallocateStatic()
{
}
/****************************************************************//**
* RadMom1D_cState :: Setting up static variables.
********************************************************************/
template<class cState, class pState>
inline void RadMom1D_cState<cState, pState> :: SetupStatic( const int &ScatteringFunc,
const int &i_Moment_Closure,
const int &i_AbsorptionModel)
{
// deallocate static vars first, just to be safe
DeallocateStatic();
closure_type = i_Moment_Closure;
Absorption_Model = i_AbsorptionModel;
Scattering_Func = ScatteringFunc;
if (closure_type != MOMENT_CLOSURE_P1 &&
closure_type != MOMENT_CLOSURE_M1 &&
closure_type != MOMENT_CLOSURE_P3) {
cout << "Closure type not specified properly !!!!" << endl;
cout << "Should specify MOMENT_CLOSURE_M1 or MOMENT_CLOSURE_P1 or MOMENT_CLOSURE_P3" << endl;
exit(0);
}
}
template<class cState, class pState>
inline void RadMom1D_cState<cState, pState> :: DeallocateStatic()
{
}
/********************************************************
* RadMom1D_pState::U -- Conserved solution state. * (Start adding closure_type here)
********************************************************/
template<class cState, class pState>
inline double RadMom1D_pState<cState, pState> :: U_from_W(const pState &W, const int &index_U) const {
double U_val;
switch (index_U) {
case 1:
U_val = W[1];
break;
case 2:
U_val = W[1]*W[index_U];
break;
default:
cout << "Incorrect value for index_U = " << index_U << endl;
exit(0);
break;
};
return U_val;
}
template<class cState, class pState>
inline cState RadMom1D_pState<cState, pState>::U_from_W(const pState &W) const {
cState U_temp;
U_temp[1] = W[1];
for (int i = 2; i <= W.NumVar(); i++) {
U_temp[i] = W[1]*W[i];
}
return U_temp;
}
template<class cState, class pState>
inline cState U(const pState &W) {
return W.U();
}
/********************************************************
* RadMom1D_cState::W -- Primitive solution state. *
********************************************************/
template<class cState, class pState>
inline pState RadMom1D_cState<cState, pState>::W_from_U(const cState &U) const {
pState W_temp;
W_temp[1] = U[1];
for (int i = 2; i <= U.NumVar(); i++) {
W_temp[i] = U[i]/U[1];
}
return W_temp;
}
template<class cState, class pState>
inline pState W(const cState &U) {
return U.W();
}
/********************************************************
* RadMom1D_pState::U_to_W_Roe
* This routine allows to compute parameter vector in
* primitive form, used for computing the Roe Matrix
********************************************************/
template<class cState, class pState>
inline pState RadMom1D_pState<cState, pState> :: U_to_W_Roe(const cState &U) const {
pState W_Roe;
W_Roe[1] = sqrt(U[1]);
for (int i = 2; i <= U.NumVar(); i++) {
W_Roe[i] = U[i]/sqrt(U[1]);
}
return W_Roe;
}
/********************************************************
* RadMom1D_pState::W_Roe_to_U
* This routine allows to compute parameter vector in
* conserved form, used for computing the Roe Matrix
********************************************************/
template<class cState, class pState>
inline cState RadMom1D_pState<cState, pState> :: W_Roe_to_U(const pState &W_Roe) const {
cState U;
U[1] = pow(W_Roe[1], 2);
for (int i = 2; i <= W_Roe.NumVar(); i++) {
U[i] = W_Roe[1]*W_Roe[i];
}
return U;
}
/********************************************************
* Routine: RoeAverage (Roe Averages) *
* *
* This function returns the Roe-averaged (linearized) *
* primitive solution state given left and right *
* primitive solution variables. *
* *
********************************************************/
template<class cState, class pState>
pState RadMom1D_pState<cState, pState> :: RoeAverage(const pState &Wl,
const pState &Wr) {
pState Wl_Roe, Wr_Roe, Wstar_Roe;
cState Ul, Ur, Ustar;
// Determine the left and right conserved states.
Ul = Wl.U();
Ur = Wr.U();
Wl_Roe = U_to_W_Roe(Ul);
Wr_Roe = U_to_W_Roe(Ur);
AverageStates(Wstar_Roe, Wl_Roe, Wr_Roe);
Ustar = W_Roe_to_U(Wstar_Roe);
/* Return the Roe-averged state. */
return Ustar.W();
}
template<class cState, class pState>
void RadMom1D_pState<cState, pState> :: AverageStates(pState &Wstar,
const pState &Wl,
const pState &Wr) {
for (int i = 1; i <= Wstar.NumVar(); i++) {
Wstar[i] = HALF*(Wl[i] + Wr[i]);
}
}
/**********************************************************************
* RadMom1D_pState::S -- Include all source term vectors and *
* Jacobians. *
* Regular Source Term
**********************************************************************/
template<class cState, class pState>
inline double RadMom1D_cState<cState, pState>::Srad(const cState &U, const Medium1D_State &M ) const {
double Source_term;
Source_term = M.kappa()*(FOUR*PI*M.Ib() - U.I0());
return -Source_term;
}
/*****************************************************************
* First order piecewise linear solution reconstruction
******************************************************************/
template<class cState, class pState>
inline void RadMom1D_pState<cState, pState>::Solution_Reconstruct( pState &Wrecon,
const pState &Wc,
const pState &phi,
const pState &dWdx,
const double &dX) {
for (int i = 1; i <= Wc.NumVar(); i++) {
Wrecon[i] = Wc[i] + phi[i]*dWdx[i]*dX;
}
}
#endif /* _RADMOM1D_STATE_INCLUDED */