-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathinitialize.f90
2609 lines (2609 loc) · 75 KB
/
initialize.f90
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
module initialization_mod
!
! Module containing the functions and routines to
! initialize the solution
!
use module_kind_types
use eqn_idx, only : nec,nmx,nmy,nmz,nmb,nme,nee,ntk,ntl,nq
!
implicit none
!
private
!
public :: initialize_flow
public :: initialize_reference
!
contains
!
!###############################################################################
!
subroutine initialize_flow()
!
! Routine to initialize the flow
!
!.. Use Statements ..
use generic_types_mod, only : matrix
!
use geovar, only : nr,n_solpts,ncell,cell,xyz,grid
!
use ovar, only : rhoref,aref,itestcase
use ovar, only : cv_in
use ovar, only : load_restart_file,d_t,constant_dt,itcur,time
use ovar, only : dtrst,itrst,tmrst
use ovar, only : rhoref,pref,tref,gam,rgasref,cpref
use ovar, only : aref,machref,velref,uref,muref,reyref
use ovar, only : alpha_aoaref,beta_aoaref
use ovar, only : pref_nd,velref_nd,muref_nd
use ovar, only : rgasref_nd,cpref_nd
use ovar, only : adjust_cfl_cycles
!use ovar, only : output_time_averaging
!
use flowvar, only : usp,uoldsp
use flowvar, only : allocate_flowvar_arrays
!
use order_mod, only : maxpts
!
use restart_mod, only : read_restart_file
use restart_mod, only : create_restart_fname_formats
!
use projection_mod, only : project_to_porder
!
use interpolation_mod, only : outerp
!
!use time_mod, only : initialize_time_ave
!
!.. Local Scalars ..
integer :: n,n1,n2,np,l,l1,l2,m
integer :: gmin,gmax,omin,omax,ierr
integer :: this_geom,this_order
integer :: init_cond
real(wp) :: rhoa2
character(len=200) :: array_name
!
!.. Local Allocatable Arrays ..
real(wp), allocatable :: xyz_init(:,:)
type(matrix), allocatable, target :: outerp_inv(:,:)
!
!.. Local Pointers ..
!real(wp), pointer, contiguous :: numer2init(:,:)
!real(wp), pointer, contiguous :: init2numer(:,:)
real(wp), pointer :: numer2init(:,:)
real(wp), pointer :: init2numer(:,:)
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "initialize_flow"
!
continue
!
call debug_timer(entering_procedure,pname)
!
! Initialize the bc_in array
!
call create_bc_in
!
! Initialize all local pointers to disassociated
!
numer2init => null()
init2numer => null()
!
! Some constants from the free-stream conditions
!
rhoa2 = rhoref * aref * aref
!
! Allocate the arrays within the module flowvar
!
call allocate_flowvar_arrays
!
! Check for a restart job, otherwise initialize usp
!
if (load_restart_file) then
!
! Read in usp and the current iteration, time step,
! and elapsed time from the restart file
!
call read_restart_file
!
! Initialize the iteration counter, time step,
! and elapsed time to that in the restart file
!
d_t = dtrst
itcur = itrst
time = tmrst
!
else
!
if (itestcase == Nozzle_Jet) then
call find_elem_for_initial_jet_profile(point_is_in_smc000_nozzle)
else if (itestcase == -Nozzle_Jet) then
call find_elem_for_initial_jet_profile(point_is_in_arn2_nozzle)
end if
!
allocate ( xyz_init(1:nr,1:maxpts) , source=zero , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"xyz_init",1,__LINE__,__FILE__,ierr,error_message)
!
! Allocate the local array that stores the inverse of the matrix used for
! interpolating from the solution points to the initialization points.
! NOTE: This is array is used so that we only invert the matrix once for a
! given cell geometry/order combination. We dont want to keep
! inverting the same matrix over and over for cells with the same
! geometry/order combination.
!
gmin = lbound(outerp,dim=1)
gmax = ubound(outerp,dim=1)
omin = lbound(outerp,dim=2)
omax = ubound(outerp,dim=2)
!
allocate ( outerp_inv(gmin:gmax,omin:omax) , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"outerp_inv",1,__LINE__,__FILE__,ierr,error_message)
!
! Initialize the solution in each cell
!
do n = 1,ncell
!
this_geom = cell(n)%geom
this_order = cell(n)%order
!
n1 = cell(n)%beg_sp
n2 = cell(n)%end_sp
np = n2-n1+1
!
init_cond = 0
if (allocated(grid)) then
if (allocated(grid%elem)) then
if (allocated(grid%elem(n)%tags)) then
if (size(grid%elem(n)%tags) >= 2) then
init_cond = grid%elem(n)%tags(2)
end if
end if
end if
end if
!
! Check whether the init component of outerp is associated with
! an interpolation matrix to determine where we need to compute
! the initial conditions.
!
if (.not. allocated(outerp(this_geom,this_order)%init)) then
!
! The init component of outerp is not associated so just compute
! the initial conditions at the solution points
!
usp(1:nq,n1:n2) = initial_conditions( xyz(1:nr,n1:n2) , init_cond )
!
else
!
! The init component of outerp is associated so we need to compute
! the initial conditions at the initialization points before
! interpolating it back to the solution points.
!
! Assign local pointer to this matrix as an alias to simplify the code
!
numer2init => outerp(this_geom,this_order)%init%mat
!
! Check if we have already created an inverse of this interpolation
! matrix. If we havent, allocate its location in outerp_inv and
! compute this inverse matrix.
!
if (.not. allocated(outerp_inv(this_geom,this_order)%mat)) then
!
l1 = size(numer2init,dim=1)
l2 = size(numer2init,dim=2)
!
allocate ( outerp_inv(this_geom,this_order)%mat(1:l1,1:l2) , &
source=zero , stat=ierr , errmsg = error_message )
write (array_name,1) Geom_Name(this_geom),this_order
call alloc_error(pname,array_name,1,__LINE__,__FILE__,ierr, &
error_message)
!
outerp_inv(this_geom,this_order)%mat = invert_matrix(numer2init)
!
end if
!
! Assign local pointer to this matrix as an alias to simplify the code
!
init2numer => outerp_inv(this_geom,this_order)%mat
!
! Interpolate the cell solution points to the initialization points
!
do l = 1,nr
xyz_init(l,1:np) = matmul( numer2init , xyz(l,n1:n2) )
end do
!
! Evaluate the initial conditions at the initialization points
!
usp(1:nq,n1:n2) = initial_conditions( xyz_init(1:nr,1:np) , init_cond )
!
! Interpolate the initial conditions from the initialization points
! to the solution points
!
do m = 1,nq
usp(m,n1:n2) = matmul( init2numer , usp(m,n1:n2) )
end do
!
! Disassociate all local pointers before continuing
!
if (associated(numer2init)) numer2init => null()
if (associated(init2numer)) init2numer => null()
!
end if
!
end do
!
! Project the initial solution from the
! initialization points to the solution points
!
!call project_to_porder(cell,usp)
!
! Initialize the iteration counter, time step, and elapsed time
!
d_t = constant_dt
itcur = 0
time = zero
!
end if
!
! Create the character format strings for the
! restart file names and the linking commands
!
call create_restart_fname_formats
!
! Initialize the time-averaging information if outputting
! time-averaged variables to solution/restart files
!
!if (output_time_averaging) then
! call initialize_time_ave
!end if
!
! Initialize the CFL cycles
!
call adjust_cfl_cycles
!
! Deallocate the grid derived type
!
if (allocated(grid)) then
deallocate ( grid , stat=ierr , errmsg=error_message )
call alloc_error(pname,"grid",2,__LINE__,__FILE__,ierr,error_message)
end if
!
! Initialize the solution at previous timestep array
!
if (allocated(uoldsp)) then
uoldsp(1:nq,1:n_solpts) = usp(1:nq,1:n_solpts)
end if
!
! Initialize the solution gradient array
!
call initialize_dusp
!
! Output the boundary conditions
!
call write_bc_conditions
!
! Output the free-stream conditions
!
if (mypnum == glb_root) then
if (all(itestcase /= [Density_Transport,Entropy_Transport])) then
!
write (iout,10) rhoref,pref,tref,machref,aref,velref(1)
if (nr >= 2) write (iout,11) velref(2)
if (nr == 3) write (iout,12) velref(3)
write (iout,13) alpha_aoaref,beta_aoaref,gam,rgasref,cpref,muref,reyref
!
write (iout,20) rhoref/rhoref,pref_nd,tref/tref,aref/aref,velref_nd(1)
if (nr >= 2) write (iout,21) velref_nd(2)
if (nr == 3) write (iout,22) velref_nd(3)
write (iout,23) rgasref_nd,cpref_nd,muref_nd
!
else
!
write (iout,30) rhoref,pref,tref,machref,uref/machref, &
velref(1),velref(2),alpha_aoaref,beta_aoaref,gam, &
rgasref,muref,reyref
!
end if
!
end if
!
! Deallocate local arrays and disassociate local pointers before leaving
!
if (allocated(outerp_inv)) then
deallocate ( outerp_inv , stat=ierr , errmsg=error_message )
call alloc_error(pname,"outerp_inv",2,__LINE__,__FILE__,ierr,error_message)
end if
!
if (allocated(xyz_init)) then
deallocate ( xyz_init , stat=ierr , errmsg=error_message )
call alloc_error(pname,"xyz_init",2,__LINE__,__FILE__,ierr,error_message)
end if
!
if (associated(numer2init)) numer2init => null()
if (associated(init2numer)) init2numer => null()
!
! Create the facexyz and edgexyz arrays if
! using the continuous output option or MMS
!
call get_face_and_edge_point_coordinates
!
call debug_timer(leaving_procedure,pname)
!
! Format Statements
!
1 format ("outerp_inv(",a,",",i0,")%mat")
!
10 format (/, &
" Dimensional Free-stream conditions",/, &
" Density = ",es14.6," kg/m^3",/, &
" Pressure = ",es14.6," N/m^2",/, &
" Temperature = ",es14.6," K",/, &
" Mach Number = ",es14.6,/, &
" Speed of Sound = ",es14.6," m/s",/, &
" X-Velocity = ",es14.6," m/s")
11 format (" Y-Velocity = ",es14.6," m/s")
12 format (" Z-Velocity = ",es14.6," m/s")
13 format (" Alpha A.o.Attack = ",es14.6," degrees"/, &
" Beta A.o.Attack = ",es14.6," degrees"/, &
" Gamma = ",es14.6,/, &
" Gas Constant = ",es14.6," J/(kg*K)",/, &
" Cp = ",es14.6," J/(kg*K)",/, &
" Viscosity = ",es14.6," kg/(m*s)",/, &
" Reynolds # = ",es14.6,/)
!
20 format (/, &
" Non-dimensional Free-stream conditions",/, &
" Density = ",es14.6,/, &
" Pressure = ",es14.6,/, &
" Temperature = ",es14.6,/, &
" Speed of Sound = ",es14.6,/, &
" X-Velocity = ",es14.6)
21 format (" Y-Velocity = ",es14.6)
22 format (" Z-Velocity = ",es14.6)
23 format (" Gas Constant = ",es14.6,/, &
" Cp = ",es14.6,/, &
" Viscosity = ",es14.6,/)
!
30 format (/, &
" The density vortex transport problem is being",/, &
" used to model the linear 2D advection equation.",//, &
" The Non-dimensional Free-stream conditions are",/, &
" Density = ",es14.6,/, &
" Pressure = ",es14.6,/, &
" Temperature = ",es14.6,/, &
" Mach Number = ",es14.6,/, &
" Speed of Sound = ",es14.6,/, &
" X-Velocity = ",es14.6,/, &
" Y-Velocity = ",es14.6,/, &
" Alpha A.o.Attack = ",es14.6," degrees"/, &
" Beta A.o.Attack = ",es14.6," degrees"/, &
" Gamma = ",es14.6,/, &
" Gas Constant = ",es14.6,/)
!
end subroutine initialize_flow
!
!###############################################################################
!
pure &
function initial_conditions(xyz,init_cond) result(return_value)
!
!.. Use Statements ..
use geovar, only : ncell
use ovar, only : bc_in
use ovar, only : itestcase
use ovar, only : mms_opt,mms_init
use ovar, only : postproc_debug_grid
use mms_mod, only : mms_solution_at_xyz
use channel_mod, only : channel_initialization
!
!.. Formal Arguments ..
real(wp), intent(in) :: xyz(:,:)
integer, intent(in) :: init_cond
!
!.. Function Result ..
real(wp), dimension(1:nq,1:size(xyz,dim=2)) :: return_value
!
!.. Local Scalars ..
integer :: k,np,ierr
real(wp) :: div,dl,r,r0,nozzle_len
!
!.. Local Allocatable Arrays ..
real(wp), allocatable :: adj_xyz(:,:)
!
continue
!
np = size(xyz,dim=2)
!
if (any(itestcase == Transport_Problems)) then
!
do k = 1,np
return_value(:,k) = vortex_solution( xyz(:,k) )
end do
!
else if (itestcase == Taylor_Green_Vortex) then
!
adj_xyz = xyz ! F2003 AUTO-REALLOCATION
!
if (postproc_debug_grid) then
dl = real(ncell,kind=wp)**(-one3)
adj_xyz = PI * (two*dl*xyz - one)
end if
!
do k = 1,np
return_value(:,k) = taylor_green_initialization( adj_xyz(:,k) )
end do
!
else if (itestcase == Channel_Flow) then
!
return_value(:,:) = channel_initialization( xyz(:,:) )
!
else if (mms_opt /= 0) then
!
do k = 1,np
return_value(:,k) = mms_init * mms_solution_at_xyz( xyz(:,k) , &
return_nondim=true, &
return_cv=true )
end do
!
else if (abs(itestcase) == Nozzle_Jet) then
!
if (init_cond == 2) then
!
nozzle_len = merge(9.875_wp,7.74_wp,itestcase > 0)
!
do k = 1,np
return_value(:,k) = jet_profile2(nozzle_len,xyz(1,k),bc_in(0)%pv(:))
end do
!
else if (init_cond == 3) then
!
nozzle_len = merge(9.875_wp,7.74_wp,itestcase > 0)
!
if (itestcase == Nozzle_Jet) then
div = eps1*smc000_interior_wall_radius(one)
else if (itestcase == -Nozzle_Jet) then
div = eps1*arn2_interior_wall_radius(one)
end if
!
do k = 1,np
!
if (itestcase == Nozzle_Jet) then
r0 = smc000_interior_wall_radius(xyz(1,k))
else if (itestcase == -Nozzle_Jet) then
r0 = arn2_interior_wall_radius(xyz(1,k))
end if
r = norm2(xyz(2:,k))
return_value(:,k) = jet_profile3(nozzle_len,xyz(1,k),r,r0,div, &
bc_in(1)%pv(:), &
bc_in(0)%pv(:))
!
end do
!
else if (init_cond /= 0) then
!
! div = thickness parameter for shear layer
! = (radius of nozzle at the lip) * 0.1
! NOTE: The nozzle lip should be located at x=0.0 so sending any value
! greater than 0.0 into the function smc000_interior_wall_radius
! should return the radius of the nozzle at the lip.
!
if (itestcase == Nozzle_Jet) then
div = eps1*smc000_interior_wall_radius(one)
else if (itestcase == -Nozzle_Jet) then
div = eps1*arn2_interior_wall_radius(one)
end if
!
do k = 1,np
!
if (itestcase == Nozzle_Jet) then
r0 = smc000_interior_wall_radius(xyz(1,k))
else if (itestcase == -Nozzle_Jet) then
r0 = arn2_interior_wall_radius(xyz(1,k))
end if
r = norm2(xyz(2:,k))
return_value(:,k) = jet_profile(r,r0,div,bc_in(0)%pv(:), &
bc_in(init_cond)%pv(:))
!
end do
!
else
!
do k = 1,np
return_value(:,k) = bc_in(init_cond)%cv(:)
end do
!
end if
!
else if (itestcase == Infinite_Cylinder) then
!
do k = 1,np
return_value(:,k) = initialize_cylinder(xyz(:,k),bc_in(0)%pv(:))
end do
!
else
!
do k = 1,np
return_value(:,k) = bc_in(init_cond)%cv(:)
end do
!
end if
!
end function initial_conditions
!
!###############################################################################
!
pure function jet_profile(r,r0,div,fs_pv,bc_pv) result(return_value)
!
!.. Formal Arguments ..
real(wp), intent(in) :: r
real(wp), intent(in) :: r0
real(wp), intent(in) :: div
real(wp), intent(in) :: fs_pv(:)
real(wp), intent(in) :: bc_pv(:)
!
!.. Function Result ..
real(wp) :: return_value(1:size(fs_pv))
!
!.. Local Scalars ..
real(wp) :: func
!
continue
!!
!! Initial profile for a jet
!!
!! r0 = radius of jet profile
!! div = thickness parameter for shear layer
!! ujet = jet velocity
!! rhojet = jet density
!!
!r0 = 1._wp/12._wp
!div = 0.1*r0
!ujet = 558.31_wp ! (feet / second)
!rhojet = 2.5019e-03_wp ! (slugs / cubic-feet)
!!
!do k = 1,mk(nb)
! do j = 1,mj(nb)
! do i = 1,mi(nb)
! if (nb < 2) then
! r0 = sqrt(x(i,mj(nb),k,2)**2+x(i,mj(nb),k,3)**2)
! end if
! r = sqrt(x(i,j,k,2)**2+x(i,j,k,3)**2)
! func = half*(one-erf((r-r0)/(div)))
! uinit = ujet*func + (one-func)*fsvel
! rhoinit = rhojet*func + (one-func)*fsrho
! q(i,j,k,1) = rhoinit
! q(i,j,k,2) = rhoinit*uinit
! q(i,j,k,3) = zero
! q(i,j,k,4) = zero
! q(i,j,k,5) = rhoinit*(pinf/(rhoinit*(gam-one)) + half*uinit**2)
! end do
! end do
!end do
!
func = half * (one - erf((r-r0)/div))
!
return_value(nec) = func*bc_pv(nec) + (one-func)*fs_pv(nec)
return_value(nmx) = func*bc_pv(nmx) + (one-func)*fs_pv(nmx)
return_value(nmx+1:nme) = zero
!return_value(nmz) = zero
return_value(nee) = fs_pv(nee)
!
return_value(:) = vsp2u_sp( return_value(:) )
!
end function jet_profile
!
!###############################################################################
!
pure function jet_profile3(nozzle_len,x,r,r0,div,bc_pv,fs_pv) &
result(return_value)
!
!.. Use Statements ..
use geovar, only : nr
use ovar, only : gam,grid_scaling_factor
!
!.. Formal Arguments ..
real(wp), intent(in) :: nozzle_len
real(wp), intent(in) :: x
real(wp), intent(in) :: r
real(wp), intent(in) :: r0
real(wp), intent(in) :: div
real(wp), intent(in) :: bc_pv(:)
real(wp), intent(in) :: fs_pv(:)
!
!.. Function Result ..
real(wp) :: return_value(1:size(fs_pv))
!
!.. Local Scalars ..
real(wp) :: xbeg,func,xfunc,rfunc
!
!.. Local Arrays ..
real(wp) :: vel(1:nr)
!
continue
!
! Initialize to the free-stream primitive variables
!
return_value(:) = fs_pv(:)
!
! If within the nozzle, initialize the velocity mach number to
! a minimum of 0.05 at the inflow plane and use the error function
! to smoothly transition this to the free-stream mach number within
! the interior of the nozzle.
!
if (x < zero) then
!
xbeg = nozzle_len*grid_scaling_factor
!
rfunc = half * (one - erf((r-r0)/div))
xfunc = half * (one + erf((ten/xbeg)*abs(x)-seven))
func = rfunc * xfunc
!
return_value(nec) = func*bc_pv(nec) + (one-func)*fs_pv(nec)
return_value(nmx) = func*bc_pv(nmx) + (one-func)*fs_pv(nmx)
return_value(nmx+1:nme) = zero
return_value(nee) = fs_pv(nee)
!
end if
!
return_value(:) = vsp2u_sp( return_value(:) )
!
end function jet_profile3
!
!###############################################################################
!
pure function jet_profile2(nozzle_len,x,fs_pv) result(return_value)
!
!.. Use Statements ..
use geovar, only : nr
use ovar, only : gam,grid_scaling_factor
!
!.. Formal Arguments ..
real(wp), intent(in) :: nozzle_len
real(wp), intent(in) :: x
real(wp), intent(in) :: fs_pv(:)
!
!.. Function Result ..
real(wp) :: return_value(1:size(fs_pv))
!
!.. Local Scalars ..
real(wp) :: aspd,mach,xbeg,func
!
!.. Local Arrays ..
real(wp) :: vel(1:nr)
!
continue
!
! Initialize to the free-stream primitive variables
!
return_value(:) = fs_pv(:)
!
! If within the nozzle, initialize the velocity mach number to
! a minimum of 0.05 at the inflow plane and use the error function
! to smoothly transition this to the free-stream mach number within
! the interior of the nozzle.
!
if (x < zero) then
!
aspd = sqrt(max(gam*fs_pv(nee)/fs_pv(nec),rndoff))
mach = norm2(fs_pv(nmb:nme)) / aspd
!
if (mach < 0.05_wp) then
!
xbeg = nozzle_len*grid_scaling_factor
!
vel(:) = 0.05_wp * aspd * unit_vector( fs_pv(nmb:nme) )
!
if (x <= -xbeg) then
!
return_value(nmb:nme) = vel(:)
!
else
!
func = half * (one - erf((ten/xbeg)*abs(x)-seven))
!
return_value(nmb:nme) = func*fs_pv(nmb:nme) + (one-func)*vel(:)
!
end if
!
end if
!
end if
!
return_value(:) = vsp2u_sp( return_value(:) )
!
end function jet_profile2
!
!###############################################################################
!
subroutine find_elem_for_initial_jet_profile(point_is_in_nozzle_interior)
!
!.. Use Statements ..
use geovar, only : grid
!
!.. Dummy Function Interface ..
interface
function point_is_in_nozzle_interior(xyz) result(return_value)
import :: wp,lk
real(wp), intent(in) :: xyz(:)
logical(lk) :: return_value
end function point_is_in_nozzle_interior
end interface
!
!.. Local Scalars ..
integer :: l,n,init
!
!.. Local Arrays ..
real(wp) :: xyz_ave(1:3)
!
!.. Local Allocatable Arrays ..
integer, allocatable :: pts(:)
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "find_elem_for_initial_jet_profile"
!
!integer, parameter :: init_val = 1 ! radial error function profile
integer, parameter :: init_val = 2 ! inflow mach number limiter
!integer, parameter :: init_val = 3 ! options 1 and 2 combined
!
continue
!
xyz_ave(:) = zero
!
do n = 1,size(grid%elem)
!
if (grid%elem(n)%tags(1) == 0) then
!
pts = grid%elem(n)%pts(:) ! USING F2003 AUTO-REALLOCATION
!
do l = 1,size(grid%xyz,dim=1)
xyz_ave(l) = sum(grid%xyz(l,pts(:))) / real(size(pts),kind=wp)
end do
!
if (xyz_ave(1) > zero) then
if (any(init_val == [2,3])) then
init = 0
else
init = init_val
end if
else
init = merge(init_val,0,point_is_in_nozzle_interior(xyz_ave))
end if
!
if (size(grid%elem(n)%tags) < 2) then
grid%elem(n)%tags = [grid%elem(n)%tags(1),init] ! F2003 AUTO-REALLOC
else
grid%elem(n)%tags(2) = init
end if
!
end if
!
end do
!
end subroutine find_elem_for_initial_jet_profile
!
!###############################################################################
!
pure &
function initialize_cylinder(xyz,fs_pv) result(return_value)
!
!.. Formal Arguments ..
real(wp), intent(in) :: xyz(:)
real(wp), intent(in) :: fs_pv(:)
!
!.. Function Result ..
real(wp) :: return_value(1:size(fs_pv))
!
!.. Local Scalars ..
real(wp) :: a,b,c,u,v,w,rho,pres
real(wp) :: r,theta,uinf
!
!.. Local Parameters ..
real(wp), parameter :: sig = one/ten
real(wp), parameter :: three2 = three/two
real(wp), parameter :: five4 = five/four
real(wp), parameter :: halfpi = half*pi
!
continue
!
r = norm2(xyz(1:2))
theta = acos(xyz(1)/r)
!
rho = fs_pv(nec)
uinf = fs_pv(nmx)
u = uinf
v = fs_pv(nmy)
w = fs_pv(nmz)
pres = fs_pv(nee)
!
if (r < three2) then
!
u = uinf * cylinder_function(r,one,half)
!
a = sin( halfpi * xyz(3) )
!
if (r > half .and. r <= one) then
b = cylinder_function(r,three4,one4)
else
b = one - cylinder_function(r,five4,one4)
end if
!
if (theta > zero .and. theta < pi) then
c = cylinder_function(theta,halfpi,halfpi)
else
c = one - cylinder_function(theta,three*halfpi,halfpi)
end if
!
v = sig * uinf * b * c
w = sig * uinf * b * a*a
!
end if
!
return_value(nec) = rho
return_value(nmx) = u
return_value(nmy) = v
return_value(nmz) = w
return_value(nee) = pres
!
return_value(:) = vsp2u_sp( return_value(:) )
!
end function initialize_cylinder
!
!###############################################################################
!
pure function cylinder_function(r,rm,ra) result(return_value)
!
!.. Formal Arguments ..
real(wp), intent(in) :: r,rm,ra
!
!.. Function Result ..
real(wp) :: return_value
!
!.. Local Scalars ..
real(wp) :: r_min_rm,numer,denom
!
continue
!
r_min_rm = r - rm
!
numer = two * ra * r_min_rm
denom = ra*ra - r_min_rm*r_min_rm
!
return_value = half * (one + tanh(numer/denom))
!
end function cylinder_function
!
!###############################################################################
!
subroutine initialize_dusp()
!
! This routine computes the discontinuous gradient at each solution point
!
!.. Use Statements ..
use order_mod, only : maxSP
use geovar, only : nr,ncell,cell
use metrics_mod, only : metrics_dt
use derivatives_mod, only : deriv
use flowvar, only : usp,dusp
!
!.. Local Scalars ..
integer :: k,l,m,n,nc,n1,n2,np
integer :: this_geom,this_order
integer :: i,i1,i2,i3
!
!.. Local Arrays ..
real(wp), dimension(1:nr) :: dudr
real(wp), dimension(1:maxSP,1:nq) :: tusp
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "initialize_dusp"
!
!logical(lk), parameter :: use_conservative_form = true
logical(lk), parameter :: use_conservative_form = fals
!
continue
!
call debug_timer(entering_procedure,pname)
!
! Loop over the cells and get the derivative of
! the primitive variables at each solution point
!
do nc = 1,ncell
!
n1 = cell(nc)%beg_sp ! beginning index for solpts in cell nc
n2 = cell(nc)%end_sp ! ending index for solpts in cell nc
np = n2-n1+1 ! number of solution points in this cell
!
this_geom = cell(nc)%geom
this_order = cell(nc)%order
!
! Store the transpose of usp for this cell to reduce cache misses
!
do k = 1,np
do m = 1,nq
tusp(k,m) = usp(m,k+n1-1)
end do
end do
!
! Compute the gradient of the conservative variables at each solution point
!
do k = 1,np
!
n = k+n1-1 ! total index of solution point on current partition
!
i = this_order+1
i3 = (k-1)/(i*i) + 1
i2 = (k-1)/i - (i3-1)*i + 1
i1 = k - (i2-1)*i - (i3-1)*i*i
!
do m = 1,nq
!
if (use_conservative_form) then
!
do l = 1,nr
!
dudr(1) = deriv(this_geom,this_order)%d(1)% &
dot( k , tusp(1:np,m)*metrics_dt(nc)%met(:,1,l) )
!
dudr(2) = deriv(this_geom,this_order)%d(2)% &
dot( k , tusp(1:np,m)*metrics_dt(nc)%met(:,2,l) )
!
dudr(3) = deriv(this_geom,this_order)%d(3)% &
dot( k , tusp(1:np,m)*metrics_dt(nc)%met(:,3,l) )
!
dusp(l,m,n) = sum(dudr)!* jacobian(n)
!
end do
!
else
!
! Compute the derivatives in r-s space
!
dudr(1:nr) = deriv(this_geom,this_order)%grad( k , tusp(1:np,m) )
!
! Transform the derivatives back to x-y space
!
do l = 1,nr
dusp(l,m,n) = dot( dudr(1:nr) , metrics_dt(nc)%met(k,1:nr,l) )
end do
!
end if
!
end do
!
end do
!
end do
!
call debug_timer(leaving_procedure,pname)
!
end subroutine initialize_dusp
!
!###############################################################################
!
subroutine get_face_and_edge_point_coordinates
!
use order_mod, only : maxSP,geom_solpts
use geovar, only : nr,cell,face,xyz
use flowvar, only : edgexyz,facexyz
use interpolation_mod, only : interp
!
!.. Local Scalars ..
integer :: n,nc,ne,nf,np,n1,n2
integer :: k,kf,l,lf,ierr
integer :: this_geom,this_order
integer :: face_geom,face_order
integer :: edge_order
!
!.. Local Arrays ..
real(wp) :: txyz(1:maxSP,1:nr)
!
!.. Local Allocatable Arrays ..
logical(lk), allocatable :: msk(:)
!