forked from HiFiLES/HiFiLES-solver
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbdy_inters.cpp
executable file
·1128 lines (940 loc) · 40.6 KB
/
bdy_inters.cpp
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
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* \file bdy_inters.cpp
* \author - Original code: HiFiLES Aerospace Computing Laboratory (ACL)
* Aero/Astro Department. Stanford University.
* - Current development: Weiqi Shen
* University of Florida
*
* High Fidelity Large Eddy Simulation (HiFiLES) Code.
*
* HiFiLES is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HiFiLES is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HiFiLES. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <cmath>
#include "../include/global.h"
#include "../include/bdy_inters.h"
#include "../include/solver.h"
#include "../include/flux.h"
#include "wall_model_funcs.h"
#ifdef _GPU
#include "../include/cuda_kernels.h"
#endif
using namespace std;
// #### constructors ####
// default constructor
bdy_inters::bdy_inters()
{
}
bdy_inters::~bdy_inters() { }
// #### methods ####
// setup inters
void bdy_inters::setup(int in_n_inters, int in_inters_type)
{
(*this).setup_inters(in_n_inters,in_inters_type);
boundary_id.setup(in_n_inters);
}
void bdy_inters::set_boundary(int in_inter, int bc_id, int in_ele_type_l, int in_ele_l, int in_local_inter_l, struct solution* FlowSol)
{
boundary_id(in_inter) = bc_id;
for(int i=0; i<n_fields; i++)
{
for(int j=0; j<n_fpts_per_inter; j++)
{
disu_fpts_l(j,in_inter,i)=get_disu_fpts_ptr(in_ele_type_l,in_ele_l,i,in_local_inter_l,j,FlowSol);
norm_tconf_fpts_l(j,in_inter,i)=get_norm_tconf_fpts_ptr(in_ele_type_l,in_ele_l,i,in_local_inter_l,j,FlowSol);
if(viscous)
{
delta_disu_fpts_l(j,in_inter,i)=get_delta_disu_fpts_ptr(in_ele_type_l,in_ele_l,i,in_local_inter_l,j,FlowSol);
}
}
}
for(int i=0; i<n_fields; i++)
{
for(int j=0; j<n_fpts_per_inter; j++)
{
for(int k=0; k<n_dims; k++)
{
if(viscous)
{
grad_disu_fpts_l(j,in_inter,i,k) = get_grad_disu_fpts_ptr(in_ele_type_l,in_ele_l,in_local_inter_l,i,k,j,FlowSol);
}
// Subgrid-scale flux
if(LES)
{
sgsf_fpts_l(j,in_inter,i,k) = get_sgsf_fpts_ptr(in_ele_type_l,in_ele_l,in_local_inter_l,i,k,j,FlowSol);
}
}
}
}
for(int j=0; j<n_fpts_per_inter; j++)
{
tdA_fpts_l(j,in_inter)=get_tdA_fpts_ptr(in_ele_type_l,in_ele_l,in_local_inter_l,j,FlowSol);
for(int k=0; k<n_dims; k++)
{
norm_fpts(j,in_inter,k)=get_norm_fpts_ptr(in_ele_type_l,in_ele_l,in_local_inter_l,j,k,FlowSol);
#ifdef _CPU
pos_fpts(j,in_inter,k)=get_loc_fpts_ptr_cpu(in_ele_type_l,in_ele_l,in_local_inter_l,j,k,FlowSol);
#endif
#ifdef _GPU
pos_fpts(j,in_inter,k)=get_loc_fpts_ptr_gpu(in_ele_type_l,in_ele_l,in_local_inter_l,j,k,FlowSol);
#endif
}
}
//setup use wall model
if (run_input.bc_list(bc_id).use_wm)
{
int upt_idx;
hf_array<double *> temp_disu_ptr(n_fields);
//find the farthest solution point to the boundary interface, calculate the distance
wm_dist.push_back(calc_wm_upts_dist(in_ele_type_l, in_ele_l, in_local_inter_l, FlowSol, upt_idx));
//get pointer of input point solution
for (int i = 0; i < n_fields; i++)
{
temp_disu_ptr(i) = get_wm_disu_ptr(in_ele_type_l, in_ele_l, upt_idx, i, FlowSol);
}
wm_disu_ptr.push_back(temp_disu_ptr);
}
// Get coordinates and solution at closest solution points to boundary
// for(int j=0;j<n_fpts_per_inter;j++)
// {
// // flux point location
// // get CPU ptr regardless of ifdef _CPU or _GPU
// // - we need a CPU ptr to pass to get_normal_disu_fpts_ptr below
// for (int k=0;k<n_dims;k++)
// temp_loc(k) = *get_loc_fpts_ptr_cpu(in_ele_type_l,in_ele_l,in_local_inter_l,j,k,FlowSol);
// // location of the closest solution point
// double temp_pos[3];
// if(viscous) {
// for(int i=0;i<n_fields;i++)
// normal_disu_fpts_l(j,in_inter,i) = get_normal_disu_fpts_ptr(in_ele_type_l,in_ele_l,in_local_inter_l,i,j,FlowSol, temp_loc, temp_pos);
// for(int i=0;i<n_dims;i++)
// pos_disu_fpts_l(j,in_inter,i) = temp_pos[i];
// }
// }
}
// move all from cpu to gpu
void bdy_inters::mv_all_cpu_gpu(void)
{
#ifdef _GPU
disu_fpts_l.mv_cpu_gpu();
norm_tconf_fpts_l.mv_cpu_gpu();
tdA_fpts_l.mv_cpu_gpu();
norm_fpts.mv_cpu_gpu();
pos_fpts.mv_cpu_gpu();
delta_disu_fpts_l.mv_cpu_gpu();
if(viscous)
{
grad_disu_fpts_l.mv_cpu_gpu();
//normal_disu_fpts_l.mv_cpu_gpu();
//pos_disu_fpts_l.mv_cpu_gpu();
//norm_tconvisf_fpts_l.mv_cpu_gpu();
}
//detjac_fpts_l.mv_cpu_gpu();
sgsf_fpts_l.mv_cpu_gpu();
boundary_id.mv_cpu_gpu();
bdy_params.mv_cpu_gpu();
#endif
}
/*! Calculate normal transformed continuous inviscid flux at the flux points on the boundaries.*/
void bdy_inters::evaluate_boundaryConditions_invFlux(double time_bound)
{
#ifdef _CPU
hf_array<double> norm(n_dims), fn(n_fields);
//viscous
hf_array<double> u_c(n_fields);
for(int i=0; i<n_inters; i++)//loop over boundary interfaces
{
int temp_bc_flag=run_input.bc_list(boundary_id(i)).get_bc_flag();
for(int j=0; j<n_fpts_per_inter; j++)//loop over flux pts on that interface
{
for (int m=0; m<n_dims; m++)
norm(m) = *norm_fpts(j,i,m);
/*! calculate discontinuous solution at flux points */
for(int k=0; k<n_fields; k++)
temp_u_l(k)=(*disu_fpts_l(j,i,k));
// Get static-physical flux point location
for (int m=0; m<n_dims; m++)
temp_loc(m) = *pos_fpts(j,i,m);
//calculate inviscid boundary solution
set_boundary_conditions(0, boundary_id(i), temp_u_l.get_ptr_cpu(), temp_u_r.get_ptr_cpu(),
norm.get_ptr_cpu(), temp_loc.get_ptr_cpu(), run_input.gamma, run_input.R_ref, time_bound, run_input.equation);
/*! calculate flux from discontinuous solution at flux points */
if(n_dims==2)
{
calc_invf_2d(temp_u_l,temp_f_l);
calc_invf_2d(temp_u_r,temp_f_r);
}
else if(n_dims==3)
{
calc_invf_3d(temp_u_l,temp_f_l);
calc_invf_3d(temp_u_r,temp_f_r);
}
else
FatalError("ERROR: Invalid number of dimensions ... ");
if (temp_bc_flag==SLIP_WALL_DUAL) // Dual consistent BC
{
/*! Set common numerical flux to be normal left flux*/
right_flux(temp_f_l,norm,fn,n_dims,n_fields,run_input.gamma);
}
else // Call Riemann solver
{
/*! Calling Riemann solver */
if (run_input.riemann_solve_type==0) //Rusanov
{
rusanov_flux(temp_u_l, temp_u_r, temp_f_l, temp_f_r, norm, fn, n_dims, n_fields, run_input.gamma);
}
else if (run_input.riemann_solve_type==1) // Lax-Friedrich
{
lax_friedrich(temp_u_l,temp_u_r,norm,fn,n_dims,n_fields,run_input.lambda,run_input.wave_speed);
}
else if (run_input.riemann_solve_type==2) // ROEM
{
roeM_flux(temp_u_l, temp_u_r, temp_f_l, temp_f_r, norm, fn, n_dims, n_fields, run_input.gamma);
}
else if(run_input.riemann_solve_type==3)//HLLC
{
hllc_flux(temp_u_l,temp_u_r,temp_f_l,temp_f_r,norm,fn,n_dims,n_fields,run_input.gamma);
}
else
FatalError("Riemann solver not implemented");
}
/*! Transform back to reference space */
for(int k=0; k<n_fields; k++)
{
(*norm_tconf_fpts_l(j,i,k))=fn(k)*(*tdA_fpts_l(j,i));
}
if(viscous)
{
//calculate viscous boundary solution if is wall boundary
if (temp_bc_flag == SLIP_WALL || temp_bc_flag == ISOTHERM_WALL || temp_bc_flag == ADIABAT_WALL || temp_bc_flag == AD_WALL || temp_bc_flag == SLIP_WALL_DUAL)
set_boundary_conditions(1, boundary_id(i), temp_u_l.get_ptr_cpu(), temp_u_r.get_ptr_cpu(),
norm.get_ptr_cpu(), temp_loc.get_ptr_cpu(), run_input.gamma, run_input.R_ref, time_bound, run_input.equation);
// Calling viscous riemann solver
if (run_input.vis_riemann_solve_type==0)
ldg_solution(1,temp_u_l,temp_u_r,u_c,run_input.ldg_beta,norm);
else
FatalError("Viscous Riemann solver not implemented");
for(int k=0; k<n_fields; k++)
{
*delta_disu_fpts_l(j,i,k) = (u_c(k) - temp_u_l(k));
}
}
}
}
#endif
#ifdef _GPU
if (n_inters != 0)
evaluate_boundaryConditions_invFlux_gpu_kernel_wrapper(n_fpts_per_inter, n_dims, n_fields, n_inters, disu_fpts_l.get_ptr_gpu(), norm_tconf_fpts_l.get_ptr_gpu(), tdA_fpts_l.get_ptr_gpu(), ndA_dyn_fpts_l.get_ptr_gpu(), J_dyn_fpts_l.get_ptr_gpu(), norm_fpts.get_ptr_gpu(), norm_dyn_fpts.get_ptr_gpu(), pos_fpts.get_ptr_gpu(), pos_dyn_fpts.get_ptr_gpu(), grid_vel_fpts.get_ptr_gpu(), boundary_type.get_ptr_gpu(), bdy_params.get_ptr_gpu(), run_input.riemann_solve_type, delta_disu_fpts_l.get_ptr_gpu(), run_input.gamma, run_input.R_ref, viscous, motion, run_input.vis_riemann_solve_type, time_bound, run_input.wave_speed(0), run_input.wave_speed(1), run_input.wave_speed(2), run_input.lambda, run_input.equation, run_input.RANS);
#endif
}
void bdy_inters::set_boundary_conditions(int sol_spec, int bc_id, double *u_l, double *u_r, double *norm, double *loc, double gamma, double R_ref, double time_bound, int equation)
{
double rho_l, rho_r;
double v_l[n_dims], v_r[n_dims];
double e_l, e_r;
double p_l, p_r;
double T_l,T_r;
double vn_l;//initialize to 0 before use
double v_sq;//initialize to 0 before use
double machn_l;
int bc_flag=run_input.bc_list(bc_id).get_bc_flag();
// Navier-Stokes Boundary Conditions
if(equation==0)
{
// Store primitive variables for clarity
rho_l = u_l[0];
for (int i=0; i<n_dims; i++)
v_l[i] = u_l[i+1]/u_l[0];
e_l = u_l[n_dims+1];
// Compute pressure on left side
v_sq = 0.;
for (int i=0; i<n_dims; i++)
v_sq += (v_l[i]*v_l[i]);
p_l = (gamma-1.0)*(e_l - 0.5*rho_l*v_sq);
if(!viscous)//use dimensional gas constant
R_ref=run_input.R_gas;
T_l=p_l/(rho_l*R_ref);
// Subsonic inflow simple (free pressure)
if(bc_flag == SUB_IN_SIMP)
{
// fix density
rho_r = run_input.bc_list(bc_id).rho;
// fix velocity
for (int i = 0; i < n_dims; i++)
v_r[i] = run_input.bc_list(bc_id).velocity[i];
// compute energy
v_sq = 0.;
for (int i = 0; i < n_dims; i++)
v_sq += (v_r[i] * v_r[i]);
e_r = p_l / (gamma - 1.0) + 0.5 * rho_r * v_sq;
// SA model
if (run_input.RANS == 1)
{
// set turbulent eddy viscosity
u_r[n_dims+2] = run_input.mu_tilde_inf;
}
}
//outflow simple (fixed pressure)
//Adapted implementation from FUN3D
else if(bc_flag == SUB_OUT_SIMP)
{
// Compute normal velocity on left side
vn_l = 0.;
for (int i=0; i<n_dims; i++)
vn_l += v_l[i]*norm[i];
//compute local normal mach number
machn_l = fabs(vn_l)/sqrt(gamma*p_l/rho_l);
if(vn_l<0)//reverse flow, back pressure as total pressure
{
for (int i=0; i<n_dims; i++)
v_r[i]=vn_l*norm[i];//retain only the normal component
v_sq = 0.;
for (int i=0; i<n_dims; i++)
v_sq += (v_r[i]*v_r[i]);
T_r=run_input.bc_list(bc_id).T_total-0.5*v_sq*(gamma-1.0)/(R_ref*gamma);//total enthalpy constant
p_r = run_input.bc_list(bc_id).p_static*pow((1.0+0.5*(gamma-1.0)*(v_sq/(gamma*R_ref*T_r))),-gamma/(gamma-1.0));//use isentropic relation between boundary value and total value
rho_r=p_r/(R_ref*T_r);
// compute energy
e_r = (p_r/(gamma-1.0)) + 0.5*rho_r*v_sq;
// SA model
if (run_input.RANS == 1)
{
// set turbulent eddy viscosity
u_r[n_dims + 2] = run_input.mu_tilde_inf;
}
}
else if(vn_l>=0 && machn_l>=1)//if mach >=1 extrapolate all
{
rho_r = rho_l;
for (int i=0; i<n_dims; i++)
v_r[i] = v_l[i];
e_r = e_l;
}
else//subsonic outlet
{
//extrapolate velocity
for (int i=0; i<n_dims; i++)
v_r[i] = v_l[i];
//extrapolate density
rho_r = rho_l;
// fix pressure
p_r = run_input.bc_list(bc_id).p_static;
// compute energy
v_sq = 0.;
for (int i=0; i<n_dims; i++)
v_sq += (v_r[i]*v_r[i]);
e_r = (p_r/(gamma-1.0)) + 0.5*rho_r*v_sq;
// SA model
if (run_input.RANS == 1)
{
// extrapolate turbulent eddy viscosity
u_r[n_dims+2] = u_l[n_dims+2];
}
}
}
// Subsonic inflow characteristic
// there is one outgoing characteristic (u-c), therefore we can specify
// all but one state variable at the inlet. The outgoing Riemann invariant
// provides the final piece of info. Adapted from an implementation in
// SU2.
else if(bc_flag == SUB_IN_CHAR)
{
double V_r;
double c_l, c_r_sq, c_total_sq;
double R_plus;
double aa, bb, cc, dd;
double Mach_sq, alpha;
double p_total_temp ;
double T_total_temp;
//Pressure/Temperature Ramp
if (run_input.bc_list(bc_id).pressure_ramp)
{
if(run_input.bc_list(bc_id).p_ramp_coeff)
{
p_total_temp = run_input.bc_list(bc_id).p_total_old + (run_input.bc_list(bc_id).p_total-run_input.bc_list(bc_id).p_total_old) * run_input.bc_list(bc_id).p_ramp_coeff * run_input.ramp_counter;
if(p_total_temp >= run_input.bc_list(bc_id).p_total)
p_total_temp = run_input.bc_list(bc_id).p_total;
}
else//coeff=0 then no ramping
p_total_temp = run_input.bc_list(bc_id).p_total;
if (run_input.bc_list(bc_id).T_ramp_coeff>0) //>0 Temperature Ramp
{
T_total_temp = run_input.bc_list(bc_id).T_total_old + (run_input.bc_list(bc_id).T_total-run_input.bc_list(bc_id).T_total_old) * run_input.bc_list(bc_id).T_ramp_coeff * run_input.ramp_counter;
if(T_total_temp >= run_input.bc_list(bc_id).T_total)
T_total_temp = run_input.bc_list(bc_id).T_total;
}
else if (run_input.bc_list(bc_id).T_ramp_coeff<0) //-1 isentropic relation across the boundary interface
T_total_temp = T_l*pow(p_total_temp/p_l, (gamma-1.0)/gamma);
else
T_total_temp = run_input.bc_list(bc_id).T_total;
}
else
{
p_total_temp = run_input.bc_list(bc_id).p_total;
T_total_temp = run_input.bc_list(bc_id).T_total;
}
// Specify Inlet conditions
double n_free_stream[3];
n_free_stream[0]=run_input.bc_list(bc_id).nx;
n_free_stream[1]=run_input.bc_list(bc_id).ny;
n_free_stream[2]=run_input.bc_list(bc_id).nz;
// Compute normal velocity on left side
vn_l = 0.;
for (int i=0; i<n_dims; i++)
vn_l += v_l[i]*norm[i];
// Compute speed of sound
c_l = sqrt(gamma*p_l/rho_l);
// Extrapolate Riemann invariant
R_plus = vn_l + 2.0*c_l/(gamma-1.0);
// Specify total enthalpy
//h_total = gamma*R_ref/(gamma-1.0)*T_total_temp;
// Compute total speed of sound squared
c_total_sq = gamma*R_ref*T_total_temp;
// Dot product of normal flow velocity
alpha = 0.;
for (int i=0; i<n_dims; i++)
alpha += norm[i]*n_free_stream[i];
// Coefficients of quadratic equation
aa = 1.0 + 0.5*(gamma-1.0)*alpha*alpha;
bb = -(gamma-1.0)*alpha*R_plus;
cc = 0.5*(gamma-1.0)*R_plus*R_plus - 2.0*c_total_sq/(gamma-1.0);
// Solve quadratic equation for velocity on right side
// (Note: largest value will always be the positive root)
// (Note: Will be set to zero if NaN)
dd = bb*bb - 4.0*aa*cc;
dd = sqrt(max(dd, 0.0));
V_r = (-bb + dd)/(2.0*aa);
V_r = max(V_r, 0.0);
v_sq = V_r*V_r;
// Compute speed of sound
c_r_sq = c_total_sq - 0.5*(gamma-1.0)*v_sq;
// Compute Mach number (cutoff at Mach = 1.0)
Mach_sq = v_sq/(c_r_sq);
Mach_sq = min(Mach_sq, 1.0);
v_sq = Mach_sq*c_r_sq;
V_r = sqrt(v_sq);
c_r_sq = c_total_sq - 0.5*(gamma-1.0)*v_sq;
// Compute velocity (based on free stream direction)
for (int i=0; i<n_dims; i++)
v_r[i] = V_r*n_free_stream[i];
// Compute temperature
T_r = c_r_sq/(gamma*R_ref);
// Compute pressure
p_r = p_total_temp*pow(T_r/T_total_temp, gamma/(gamma-1.0));
// Compute density
rho_r = p_r/(R_ref*T_r);
// Compute energy
e_r = (p_r/(gamma-1.0)) + 0.5*rho_r*v_sq;
// SA model
if (run_input.RANS == 1)
{
// set turbulent eddy viscosity
u_r[n_dims+2] = run_input.mu_tilde_inf;
}
}
// Subsonic outflow characteristic(fix pressure)
// there is one incoming characteristic, therefore one variable can be
// specified (back pressure) and is used to update the conservative
// variables. Compute the entropy and the acoustic Riemann variable.
// These invariants, as well as the tangential velocity components,
// are extrapolated. Adapted from an implementation in SU2.
else if(bc_flag == SUB_OUT_CHAR)
{
double c_l, c_r;
double R_plus, s;
double vn_r;
// Compute normal velocity on left side
vn_l = 0.;
for (int i=0; i<n_dims; i++)
vn_l += v_l[i]*norm[i];
// Compute speed of sound
c_l = sqrt(gamma*p_l/rho_l);
// Extrapolate Riemann invariant
R_plus = vn_l + 2.0*c_l/(gamma-1.0);
// Extrapolate entropy
s = p_l/pow(rho_l,gamma);
// fix pressure on the right side
p_r = run_input.bc_list(bc_id).p_static;
// Compute density
rho_r = pow(p_r/s, 1.0/gamma);
// Compute speed of sound
c_r = sqrt(gamma*p_r/rho_r);
// Compute normal velocity
vn_r = R_plus - 2.0*c_r/(gamma-1.0);
// Compute velocity and energy
v_sq = 0.;
for (int i=0; i<n_dims; i++)
{
v_r[i] = v_l[i] + (vn_r - vn_l)*norm[i];
v_sq += (v_r[i]*v_r[i]);
}
e_r = (p_r/(gamma-1.0)) + 0.5*rho_r*v_sq;
// SA model
if (run_input.RANS == 1)
{
// extrapolate turbulent eddy viscosity
u_r[n_dims+2] = u_l[n_dims+2];
}
}
// Supersonic inflow
else if(bc_flag == SUP_IN)
{
// fix density and velocity
rho_r = run_input.bc_list(bc_id).rho;
for (int i=0; i<n_dims; i++)
v_r[i] = run_input.bc_list(bc_id).velocity[i];
// fix pressure
p_r = run_input.bc_list(bc_id).p_static;
// compute energy
v_sq = 0.;
for (int i=0; i<n_dims; i++)
v_sq += (v_r[i]*v_r[i]);
e_r = (p_r/(gamma-1.0)) + 0.5*rho_r*v_sq;
}
// Supersonic outflow
else if(bc_flag == SUP_OUT)
{
// extrapolate density, velocity, energy
rho_r = rho_l;
for (int i=0; i<n_dims; i++)
v_r[i] = v_l[i];
e_r = e_l;
}
// Slip wall
else if(bc_flag == SLIP_WALL)
{
// extrapolate density
rho_r = rho_l;
// Compute normal velocity on left side
vn_l = 0.;
for (int i=0; i<n_dims; i++)
vn_l += v_l[i]*norm[i];
// set velocity
if (sol_spec == 0) //inviscid solution
{
for (int i = 0; i < n_dims; i++)
v_r[i] = v_l[i] - 2 * vn_l * norm[i];
}
else//viscous solution
{
for (int i = 0; i < n_dims; i++)
v_r[i] = v_l[i] - vn_l * norm[i];
}
// energy
v_sq = 0.;
for (int i=0; i<n_dims; i++)
v_sq += (v_r[i]*v_r[i]);
e_r = p_l / (gamma - 1.0) + 0.5 * rho_r * v_sq;
}
// Isothermal, no-slip wall
else if(bc_flag == ISOTHERM_WALL)
{
// isothermal temperature
T_r = run_input.bc_list(bc_id).T_static;
// extrapolate density
rho_r = rho_l;
if (run_input.bc_list(bc_id).use_wm)//wall model on
{
if (sol_spec == 0) //inverse slip inviscid solution
{
// Compute normal velocity on left side
vn_l = 0.;
for (int i = 0; i < n_dims; i++)
vn_l += v_l[i] * norm[i];
//inverse normal velocity
for (int i = 0; i < n_dims; i++)
v_r[i] = v_l[i] - 2 * vn_l * norm[i];
// energy extraploate temperature
v_sq = 0.;
for (int i = 0; i < n_dims; i++)
v_sq += (v_r[i] * v_r[i]);
e_r = p_l / (gamma - 1.0) + 0.5 * rho_r * v_sq;
}
else if (sol_spec == 1) //slip viscous solution
{
// Compute normal velocity on left side
vn_l = 0.;
for (int i = 0; i < n_dims; i++)
vn_l += v_l[i] * norm[i];
//substract normal velocity
for (int i = 0; i < n_dims; i++)
v_r[i] = v_l[i] - vn_l * norm[i];
// energy extrapolate temperature
v_sq = 0.;
for (int i = 0; i < n_dims; i++)
v_sq += (v_r[i] * v_r[i]);
e_r = p_l / (gamma - 1.0) + 0.5 * rho_r * v_sq;
}
else if (sol_spec == 2) //no-slip viscous solution
{
for (int i = 0; i < n_dims; i++)
v_r[i] = run_input.bc_list(bc_id).velocity(i);
// energy use wall temperature
v_sq = 0.;
for (int i = 0; i < n_dims; i++)
v_sq += (v_r[i] * v_r[i]);
e_r = rho_r * (R_ref / (gamma - 1.0) * T_r) + 0.5 * rho_r * v_sq;
}
}
else //wall model off
{
if (sol_spec == 0) //inverse no-slip inviscid solution
{
for (int i = 0; i < n_dims; i++)
v_r[i] = 2 * run_input.bc_list(bc_id).velocity(i) - v_l[i];
}
else if (sol_spec == 1) // no-slip viscous solution
{
for (int i = 0; i < n_dims; i++)
v_r[i] = run_input.bc_list(bc_id).velocity(i);
}
else
{
FatalError("Unrecognized flux type");
}
// energy use wall temperature
v_sq = 0.;
for (int i = 0; i < n_dims; i++)
v_sq += (v_r[i] * v_r[i]);
e_r = rho_r * (R_ref / (gamma - 1.0) * T_r) + 0.5 * rho_r * v_sq;
}
// SA model
if (run_input.RANS == 1)
{
// zero turbulent eddy viscosity at the wall
u_r[n_dims+2] = 0.0;
}
}
// Adiabatic, no-slip wall
else if(bc_flag == ADIABAT_WALL)
{
// extrapolate density
rho_r = rho_l; // only useful part
if (run_input.bc_list(bc_id).use_wm)//wall model on
{
if (sol_spec == 0) //inverse slip inviscid solution
{
// Compute normal velocity on left side
vn_l = 0.;
for (int i = 0; i < n_dims; i++)
vn_l += v_l[i] * norm[i];
//inverse normal velocity
for (int i = 0; i < n_dims; i++)
v_r[i] = v_l[i] - 2 * vn_l * norm[i];
}
else if (sol_spec == 1) //slip viscous solution
{
// Compute normal velocity on left side
vn_l = 0.;
for (int i = 0; i < n_dims; i++)
vn_l += v_l[i] * norm[i];
//subtract normal velocity
for (int i = 0; i < n_dims; i++)
v_r[i] = v_l[i] - vn_l * norm[i];
}
else if (sol_spec == 2) //no-slip viscous solution
{
for (int i = 0; i < n_dims; i++)
v_r[i] = run_input.bc_list(bc_id).velocity(i);
}
}
else //wall model off
{
if (sol_spec == 0) //inverse no-slip inviscid solution
{
for (int i = 0; i < n_dims; i++)
v_r[i] = 2 * run_input.bc_list(bc_id).velocity(i) - v_l[i];
}
else if (sol_spec == 1) // no-slip viscous solution
{
for (int i = 0; i < n_dims; i++)
v_r[i] = run_input.bc_list(bc_id).velocity(i);
}
else
{
FatalError("Unrecognized flux type");
}
}
// energy extrapolate temperature
v_sq = 0.;
for (int i=0; i<n_dims; i++)
v_sq += (v_r[i]*v_r[i]);
e_r = p_l / (gamma - 1.0) + 0.5 * rho_r * v_sq;
// SA model
if (run_input.RANS == 1)
{
// zero turbulent eddy viscosity at the wall
u_r[n_dims+2] = 0.0;
}
}
// Characteristic/Riemann(far field)
//Adapted implementation from FUN3D
else if (bc_flag == CHAR)
{
double c_star;
double vn_star;
double vn_r;//normal velocity from outside
double r_plus,r_minus;
double c_l,c_r;
double one_over_s;
double mach;
// Compute normal velocity on left side, >0 out, <0 in
vn_l = 0.;
for (int i=0; i<n_dims; i++)
vn_l += v_l[i]*norm[i];
//compute normal velocity on right side, >0 in,<0 out
vn_r = 0;
for (int i=0; i<n_dims; i++)
vn_r += run_input.bc_list(bc_id).velocity[i]*norm[i];
c_l=sqrt(gamma*p_l/rho_l);
c_r=sqrt(gamma*run_input.bc_list(bc_id).p_static/run_input.bc_list(bc_id).rho);
mach = fabs(vn_l) / c_l;
// Inflow
if (vn_l<0)
{
//if supersonic inflow set the outgoing Riemann invariant to be far field value
if (mach >= 1)
{
r_minus = vn_r - 2. / (gamma - 1.) * c_r;
r_plus = vn_r + 2. / (gamma - 1.) * c_r;
}
else //subsonically inflow
{
r_plus = vn_l + 2. / (gamma - 1.) * c_l;
r_minus = vn_r - 2. / (gamma - 1.) * c_r;
}
c_star = 0.25 * (gamma - 1.) * (r_plus - r_minus);
vn_star = 0.5 * (r_plus + r_minus);
//use free stream entropy to calculate density
one_over_s = pow(run_input.bc_list(bc_id).rho,gamma)/run_input.bc_list(bc_id).p_static;
rho_r = pow(1./gamma*(one_over_s*c_star*c_star),1./(gamma-1.));
// Compute velocity on the right side, extrapolate tangetal right velocity
for (int i=0; i<n_dims; i++)
v_r[i] = vn_star*norm[i] + (run_input.bc_list(bc_id).velocity[i] - vn_r*norm[i]);
v_sq = 0.;
for (int i=0; i<n_dims; i++)
v_sq += (v_r[i]*v_r[i]);
p_r = rho_r/gamma*c_star*c_star;
e_r = (p_r/(gamma-1.0)) + 0.5*rho_r*v_sq;
// SA model
if (run_input.RANS == 1)
{
// set turbulent eddy viscosity
u_r[n_dims+2] = run_input.mu_tilde_inf;
}
}
// Outflow
else
{
//if supersonic outflow
if (mach>=1)
{
r_minus = vn_l - 2./(gamma-1.)*c_l;
r_plus = vn_l + 2. / (gamma - 1.) * c_l;
}
else //subsonically outflow
{
r_plus = vn_l + 2. / (gamma - 1.) * c_l;
r_minus = vn_r - 2. / (gamma - 1.) * c_r;
}
c_star = 0.25 * (gamma - 1.) * (r_plus - r_minus);
vn_star = 0.5 * (r_plus + r_minus);
//extrapolate entropy
one_over_s = pow(rho_l,gamma)/p_l;
rho_r = pow(1./gamma*(one_over_s*c_star*c_star), 1./(gamma-1.));
// Compute velocity on the right side, extrapolate tangental left velocity
for (int i=0; i<n_dims; i++)
v_r[i] = vn_star*norm[i] + (v_l[i] - vn_l*norm[i]);
v_sq = 0.;
for (int i=0; i<n_dims; i++)
v_sq += (v_r[i]*v_r[i]);
p_r = rho_r/gamma*c_star*c_star;
e_r = (p_r/(gamma-1.0)) + 0.5*rho_r*v_sq;
// SA model
if (run_input.RANS == 1)
{
// extrapolate turbulent eddy viscosity
u_r[n_dims+2] = u_l[n_dims+2];
}
}
}
// Dual consistent BC (see SD++ for more comments)
else if (bc_flag==SLIP_WALL_DUAL)//TODO: what is this
{
// extrapolate density
rho_r = rho_l;
// Compute normal velocity on left side
vn_l = 0.;
for (int i=0; i<n_dims; i++)
vn_l += v_l[i]*norm[i];
// set u = u - (vn_l)nx
// set v = v - (vn_l)ny
// set w = w - (vn_l)nz
for (int i=0; i<n_dims; i++)
v_r[i] = v_l[i] - 2 * vn_l * norm[i];
// extrapolate energy
e_r = e_l;
}
// Boundary condition not implemented yet
else
{
printf("bdy_type= %s\n",run_input.bc_list(bc_id).get_bc_type().c_str());
printf("Boundary conditions yet to be implemented");
}
// Conservative variables on right side
u_r[0] = rho_r;
for (int i=0; i<n_dims; i++)
u_r[i+1] = rho_r*v_r[i];
u_r[n_dims+1] = e_r;
}
// Advection, Advection-Diffusion Boundary Conditions
else if(equation==1)
{
// Trivial Dirichlet
if(bc_flag==AD_WALL)
{
u_r[0]=0.0;
}
}
}
/*! Calculate normal transformed continuous viscous flux at the flux points on the boundaries. */
void bdy_inters::evaluate_boundaryConditions_viscFlux(double time_bound)
{
hf_array<double> norm(n_dims), fn(n_fields);
hf_array<double> temp_u_wm(n_fields);
int ctr = 0;
for (int i = 0; i < n_inters; i++)
{
/*! boundary specification */
int temp_bc_flag = run_input.bc_list(boundary_id(i)).get_bc_flag();
if (temp_bc_flag != SLIP_WALL) //if not slip wall(slip wall dont need to calculate viscous flux)
{
if (!run_input.bc_list(boundary_id(i)).use_wm)//if not use wall model
{
for (int j = 0; j < n_fpts_per_inter; j++)
{
/*! obtain discontinuous solution at flux points */
for (int k = 0; k < n_fields; k++)
temp_u_l(k) = (*disu_fpts_l(j, i, k));
/*! Get normal components and flux points location */