-
Notifications
You must be signed in to change notification settings - Fork 3
/
orrsom.f
979 lines (923 loc) · 29.1 KB
/
orrsom.f
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
c***********************************************************************
c> \file orrsom.f
c> \brief Solves the Orr-Sommerfeld equation for incompressible boundary
c> layers solving first the Blasius equation
c> \author S. Scott Collis
c***********************************************************************
program OrrSom
c***********************************************************************
c
c Purpose: Solve the Orr-Sommerfeld equation using 4th order Runge-
c Kutta explicit integration with orthogonalization using
c the method of Conte.
c
c This routine finds a single eigensolution to the Orr-
c Sommerfeld equation for the boundary layer.
c
c This routine works rather well but to get good
c eigenvalues you must really resolve the boundary-layer
c profile well. The OS shooting solution appears to be
c quite sensitive to the profile.
c
c Author: Scott Collis
c
c Date: 7-17-92
c
c Revised: 10-29-92 changed tabs to spaces <-- big deal
c Revised: 1-11-2020 code cleanup
c
c***********************************************************************
c Common variables
c***********************************************************************
parameter (idim=20000)
integer n
complex alpha, c, gamma
real U(0:idim), d2U(0:idim), Re, ymin, ymax, h, beta
real Uspl(0:idim), d2Uspl(0:idim), ydat(0:idim), f2p
common /data/ n, u, d2u, ymin, ymax, h, f2p,
& gamma, beta, uspl, d2uspl, ydat
common /eig/ c, alpha, Re
c***********************************************************************
parameter (neq=4)
integer inunit
complex bc1(neq), bc2(neq), omega
real testalpha
integer north, nstep
logical eigfun
character*1 input
character*20 infile
character*80 string
inunit = 20
write (*,10)
10 format (/,5x,'Solve Orr-Sommerfeld (Shooting) Temporal Problem',/)
#ifdef USE_FILE_INPUT
write (*,60)
60 format (/,1x,'Enter filename ==> ',$)
read (*,'(a)') infile
open (unit=inunit, file=infile, form='formatted')
#else
inunit = 5
#endif
string(1:1) = '#'
do while (string(1:1) .eq. '#')
read(inunit,'(a)',err=99) string
end do
call readi (string,n)
read(inunit,'(a)') string
call readi (string,nstep)
read(inunit,'(a)') string
call readr (string,testalpha)
read(inunit,'(a)') string
call readr (string,Re)
read(inunit,'(a)') string
call readr (string,beta)
read(inunit,'(a)') string
call readr (string,f2p)
read(inunit,'(a)') string
call readr (string,alphar)
read(inunit,'(a)') string
call readr (string,alphai)
read(inunit,'(a)') string
call readr (string,cr)
read(inunit,'(a)') string
call readr (string,ci)
read(inunit,'(a)') string
call readr (string,Ymin)
read(inunit,'(a)') string
call readr (string,Ymax)
c
c Echo input
c
write (*,100) n
100 format (/,1x,'n = ',i5)
write (*,102) nstep
102 format (1x,'nstep = ',i5)
write (*,105) testalpha
105 format (1x,'Test Alpha = ',e20.10)
write (*,110) Re
110 format (1x,'Re = ',e20.10)
write (*,115) beta
115 format (1x,'Beta = ',e20.10)
write (*,117) f2p
117 format (1x,'f2p = ',e20.10)
write (*,140) ymin, ymax
140 format (1x,'Ymin = ',e20.10,' Ymax = ',e20.10)
write (*,120) alphar, alphai
120 format (1x,'alpha = (',e20.10,', ',e20.10,')')
write (*,130) cr, ci
130 format (1x,'c = (',e20.10,', ',e20.10,')',/)
c
c Set constants
c
alpha = cmplx(alphar,alphai)
c = cmplx(cr,ci)
h = (ymax-ymin)/float(n)
c
c Fix to make my nondimensionalization match Mack's
c
#ifdef USE_MACK_NORMALIZATION
c
c SSC: 1/7/2020 Why using the 1.7207877 ?
c
Re = Re*SQRT(2.)/1.7207877
alpha = alpha*SQRT(2.)/1.7207877
#else
Re = Re*SQRT(2.)
alpha = alpha*SQRT(2.)
#endif
ymin = ymin
ymax = ymax
if (n .gt. idim) then
write (*,300)
300 format (/,/,1x,'N > Idim...Stopping',/,/)
goto 210
end if
call SOLVE_BL
c
c set the boundary conditions
c
do i = 1, neq
bc1(i) = 0.0
bc2(i) = 0.0
end do
eigfun = .true.
call CONTE(nstep,testalpha,neq,2,bc1,bc2,ymin,ymax,eigfun)
goto 210
c
c Read error
c
99 write (*,200)
200 format(/,/1x,'Error in input file...',/,/)
210 continue
stop
end
C***********************************************************************
subroutine CONTE(nstep, testalpha, n, r, yo, yf, to, tf, eigfun)
C***********************************************************************
C
C First order linear boundary value problem solver using Conte's
C method. Fourth order Runge-Kutta is used for time advancement
C
c***********************************************************************
complex c, alpha
real Re
common /eig/ c, alpha, Re
C***********************************************************************
integer i, m, q, r, s, mi, mj, qend, IPVT(n-r), icount, north
real t, tq(0:nstep), to, tf, h
complex yo(n), yf(n), B(n-r,0:nstep), err, cold, ctemp
complex U(n,n-r,0:nstep), P(n-r,n-r,0:nstep), z(n,n-r)
complex y(n,0:nstep), v(n,0:nstep), w(n-r), omega(n,0:nstep)
complex eta(n),A(n,n-r),x(n),FAC(n-r,n-r), det1, det
complex olderr, INPROD, ut(n,n-r), fd, max, gamma
complex cm1, cm2, errm1, errm2, qt, At, Bt, Ct, Utemp(n)
real aa, bb, cc
real test, testalpha, pi, det2, AI(n,n-r)
real fdxr, fdxi, fdyr, fdyi
logical norm, eigfun
external INPROD, FHOMO, FPART, RKQC
c
c set the normalization constraint
c
pi = ACOS(-1.0)
c
c compute the step size
c
h = (tf-to)/nstep
c
c Begin the eigenvalue iteration loop
c
icount = 1
err = 1.
do while ((abs(err) .ge. 1.0e-8) .and. (icount .le. 20) .and.
& (abs(c-cm1) .ge. 1.0e-12) )
q = 0
tq(0) = tf
c
c Set the initial conditions
c
k = 0
U(1,1,0) = CEXP(-alpha*tf)
U(2,1,0) = (-alpha)*CEXP(-alpha*tf)
U(3,1,0) = (alpha**2)*CEXP(-alpha*tf)
U(4,1,0) = (-alpha**3)*CEXP(-alpha*tf)
gamma = SQRT(alpha**2+(0.,1.)*alpha*Re*(1.0-c))
U(1,2,0) = CEXP(-gamma*tf)
U(2,2,0) = (-gamma)*CEXP(-gamma*tf)
U(3,2,0) = (gamma**2)*CEXP(-gamma*tf)
U(4,2,0) = (-gamma**3)*CEXP(-gamma*tf)
c
c Gram-Schmidt
c
w(1) = SQRT(inprod(n, U(1,1,k), U(1,1,k)))
do i = 1, n
z(i,1) = U(i,1,k)/w(1)
end do
do mi = 2, (n-r)
do i = 1, n
eta(i) = U(i,mi,k)
end do
do mj = mi-1, 1, -1
do i = 1, n
eta(i) = eta(i) - inprod(n, U(1,mi,k), z(1,mj))*z(i,mj)
end do
end do
w(mi) = SQRT(inprod(n, eta, eta))
do i = 1, n
z(i,mi) = eta(i)/w(mi)
end do
end do
c
c Now update the U matrix with the orthonormal values
c
do i = 1, n
do m = 1, n-r
U(i,m,k) = z(i,m)
end do
end do
c aa = ABS(inprod(n, U(1,1,k), U(1,1,k)))
c bb = ABS(inprod(n, U(1,2,k), U(1,2,k)))
c cc = ABS(inprod(n, U(1,1,k), U(1,2,k)))
c test = ACOS(cc/SQRT(aa*bb))*180./pi
c write (*,*) k, mi, mj, test
c
c Integrate the homo. and particular equations
c
do k = 1, nstep
t = tf - h*k
c
c Loop thru all homogeneous solutions
c
do m = 1, n-r
#ifdef USE_NR_ODEINT
do i = 1, n
Utemp(i) = U(i,m,k-1)
end do
call NR_CODEINT(Utemp,n,t+h,t,1.E-5,-h/2.,1.e-20,nok,nbad,
& FHOMO,NR_CRKQC)
c write (*,*) k, nok, nbad
do i = 1, n
U(i,m,k) = Utemp(i)
end do
#else
call CRK4(n, U(1,m,k-1), U(1,m,k), t+h, -h, FHOMO)
#endif
end do
c
c Test to see if normalization is required
c
norm = .false.
do mi = 1, n-r
do mj = 1, n-r
if (mi .ne. mj) then
aa = ABS(inprod(n, U(1,mi,k), U(1,mi,k)))
bb = ABS(inprod(n, U(1,mj,k), U(1,mj,k)))
cc = ABS(inprod(n, U(1,mi,k), U(1,mj,k)))
#ifdef USE_ANALYTIC_INPROD
test = 180.0*ACOS(MIN(1.0,ABS(cc)/SQRT(aa*bb)))/pi
#else
test = 180.0*ACOS(ABS(cc)/SQRT(aa*bb))/pi
#endif
c write (*,*) k, mi, mj, test
c
c test = ACOS( ABS ( inprod(n, U(1,mi,k), U(1,mj,k)) /
c & SQRT( inprod(n, U(1,mi,k), U(1,mi,k))*
c & inprod(n, U(1,mj,k), U(1,mj,k)) ) ) )
c
c test = cc/SQRT(aa*bb)
c if (test .gt. testalpha) norm = .true.
if (test .le. testalpha) norm = .true.
end if
end do
end do
c
c Perform normalization
c
if ( norm .or. (k .eq. nstep) ) then
q = q + 1
tq(q) = t
if (k .eq. nstep) then
qend = q
c write (*,*) 'qend = ',qend
end if
c
c Gram-Schmidt
c
w(1) = SQRT(inprod(n, U(1,1,k), U(1,1,k)))
do i = 1, n
z(i,1) = U(i,1,k)/w(1)
end do
do mi = 2, (n-r)
do i = 1, n
eta(i) = U(i,mi,k)
end do
do mj = mi-1, 1, -1
do i = 1, n
eta(i) = eta(i)-inprod(n,U(1,mi,k),z(1,mj))*z(i,mj)
end do
end do
w(mi) = SQRT(inprod(n, eta, eta))
do i = 1, n
z(i,mi) = eta(i)/w(mi)
end do
end do
c
c Now I have the orthonormal basis in z and
c the norms in w so I can compute the P orthonormalization
c matrix
c
do j = 1, n-r
do i = 1, j
if (j .eq. i) then
P(j,i,q) = 1.0/w(j)
else
P(j,i,q) = 0.0
do s = i, j-1
P(j,i,q) = P(j,i,q)-inprod(n,U(1,j,k),z(1,s))/w(j)*
& P(s,i,q)
end do
end if
end do
end do
c
c Check the P matrix
c
if (.false.) then
do i = 1, n
do m = 1, n-r
ut(i,m) = 0.0
do j = 1, n-r
ut(i,m) = ut(i,m) + U(i,j,k)*P(m,j,q)
end do
end do
end do
do i = 1,n
write (*,*) i,(ut(i,m), m = 1, n-r)
end do
write (*,*)
do i = 1,n
write (*,*) i,( z(i,m), m = 1, n-r)
end do
write (*,*)
write (*,*)
end if
c
c Now update the U matrix with the orthonormal values
c
do i = 1, n
do m = 1, n-r
U(i,m,k) = z(i,m)
end do
end do
end if
end do
c
c check boundary conditions
c
if (.true.) then
c
c strictly enforce the zero BC
c
B(1,qend) = -U(1,2,nstep)/U(1,1,nstep)
B(2,qend) = 1.0
c olderr = err
c err = U(2,1,nstep)*B(1,qend) + U(2,2,nstep)*B(2,qend)
else
c
c strictly enforce the zero slope BC
c
B(1,qend) = 1.0
B(2,qend) = -U(2,1,nstep)/U(2,2,nstep)
c olderr = err
c err = U(1,1,nstep)*B(1,qend) + U(1,2,nstep)*B(2,qend)
end if
ctemp = c
if (icount .eq. 1) then
cm2 = c
err = U(2,1,nstep)*B(1,qend) + U(2,2,nstep)*B(2,qend)
errm2 = err
c = CMPLX( REAL(c)*.9999, AIMAG(c) )
else if (icount .eq. 2) then
cm1 = c
err = U(2,1,nstep)*B(1,qend) + U(2,2,nstep)*B(2,qend)
errm1 = err
c c = CMPLX( REAL(c), AIMAG(c)*.9999 )
fdxr = REAL(err-errm2) / REAL(c-cm2)
fdxi = AIMAG(err-errm2) / REAL(c-cm2)
fd = CMPLX( fdxr, fdxi )
c = c - err/fd
else
err = U(2,1,nstep)*B(1,qend) + U(2,2,nstep)*B(2,qend)
qt = (c-cm1)/(cm1-cm2)
At = qt*err-qt*(1.+qt)*errm1+qt**2*errm2
Bt = (2.*qt+1.)*err-(1.+qt)**2*errm1+qt**2*errm2
Ct = (1.+qt)*err
if ( ABS(Bt+SQRT(Bt**2-4.*At*Ct)) .gt.
& ABS(Bt-SQRT(Bt**2-4.*At*Ct)) ) then
c = ctemp-(ctemp-cm1)*2.*Ct/(Bt+SQRT(Bt**2-4.*At*Ct))
else
c = ctemp-(ctemp-cm1)*2.*Ct/(Bt-SQRT(Bt**2-4.*At*Ct))
end if
cm2 = cm1
cm1 = ctemp
errm2 = errm1
errm1 = err
end if
write (*,30) icount,real(ctemp),aimag(ctemp),real(err),
& aimag(err)
30 format (1x,i4,2(e17.8,e17.8,3x))
icount = icount + 1
end do
write (*,40) real(ctemp),aimag(ctemp),qend
40 format (/,'Eigenvalue = ',e17.8,1x,e17.8,2x,i5/)
c
c Second Pass
c
if (eigfun) then
write(*,50)
50 format('Second pass: computing and writing eigenfunction')
max = 0.0
k = nstep
do i = 1, n
y(i,k) = v(i,k)
do m = 1, n-r
y(i,k) = y(i,k) + U(i,m,k)*B(m,q)
end do
end do
do m = 1, n-r
B(m,q-1) = 0.0
do j = 1, n-r
B(m,q-1) = B(m,q-1) + P(j,m,q)*B(j,q)
end do
end do
do k = nstep-1, 0, -1
t = tf - h*k
if ( t .gt. tq(q-1) ) then
q = q - 1
do m = 1, n-r
B(m,q-1) = 0.0
do j = 1, n-r
B(m,q-1) = B(m,q-1) + P(j,m,q)*B(j,q)
end do
end do
end if
do i = 1, n
y(i,k) = 0.0
do m = 1, n-r
y(i,k) = y(i,k) + U(i,m,k)*B(m,q-1)
end do
end do
if ( ABS(y(i,k)) .gt. ABS(max) ) then
max = y(i,k)
end if
end do
do k = 0, nstep
t = tf - h*k
write (11,20) t, REAL(y(1,k)/max),AIMAG(y(1,k)/max)
write (12,20) t, REAL(y(2,k)/max),AIMAG(y(2,k)/max)
write (13,20) t, REAL(y(3,k)/max),AIMAG(y(3,k)/max)
write (14,20) t, REAL(y(4,k)/max),AIMAG(y(4,k)/max)
write (15,20) t, REAL(y(2,k)/max),REAL((0.,-1.)*ALPHA*y(1,k)/max)
20 format (1x,3(ES17.8E3,1x) )
end do
end if
return
end
C***********************************************************************
function INPROD(n, v1, v2)
C***********************************************************************
C
C Perform and inner product on two complex vectors, v1 and v2
C
c***********************************************************************
complex v1(n), v2(n)
complex INPROD
integer n, i
INPROD = 0.0
do i = 1, n
INPROD = INPROD + v1(i)*conjg(v2(i))
c INPROD = INPROD + v1(i)*v2(i)
end do
return
end
C***********************************************************************
subroutine SRK4(neq, yo, yf, to, h, FUNC)
C***********************************************************************
C
C Advance one time step using fourth order (real) Runge-Kutta
C
c***********************************************************************
external FUNC
integer neq
real to, h
real yo(neq), yf(neq)
real f(neq), k1(neq), k2(neq), k3(neq), k4(neq), q(neq)
call FUNC(neq, yo, to, f)
do j = 1 , neq
k1(j) = h*f(j)
q(j) = yo(j) + 0.5*k1(j)
end do
call FUNC(neq, q, to+0.5*h, f)
do j = 1 , neq
k2(j) = h*f(j)
q(j) = yo(j) + 0.5*k2(j)
end do
call FUNC(neq, q, to+0.5*h, f)
do j = 1 , neq
k3(j) = h*f(j)
q(j) = yo(j) + k3(j)
end do
call FUNC(neq, q, to+h, f)
do j = 1 , neq
k4(j) = h*f(j)
yf(j) = yo(j)+k1(j)/6.+(k2(j)+k3(j))/3.+k4(j)/6.
end do
return
end
C***********************************************************************
subroutine CRK4(neq, yo, yf, to, h, FUNC)
C***********************************************************************
C
C Advance one time step using fourth order (complex) Runge-Kutta
C
c***********************************************************************
external FUNC
integer neq
real to, h
complex yo(neq), yf(neq)
complex f(neq), k1(neq), k2(neq), k3(neq), k4(neq), q(neq)
call FUNC(neq, yo, to, f)
do j = 1 , neq
k1(j) = h*f(j)
q(j) = yo(j) + 0.5*k1(j)
end do
call FUNC(neq, q, to+0.5*h, f)
do j = 1 , neq
k2(j) = h*f(j)
q(j) = yo(j) + 0.5*k2(j)
end do
call FUNC(neq, q, to+0.5*h, f)
do j = 1 , neq
k3(j) = h*f(j)
q(j) = yo(j) + k3(j)
end do
call FUNC(neq, q, to+h, f)
do j = 1 , neq
k4(j) = h*f(j)
yf(j) = yo(j)+k1(j)/6.+(k2(j)+k3(j))/3.+k4(j)/6.
end do
return
end
C***********************************************************************
subroutine FHOMO(neq, yo,t,yf)
C***********************************************************************
C
C Function evaluation for the Orr-Sommerfeld equation
C
c***********************************************************************
c Common variables
c***********************************************************************
parameter (idim=20000)
integer n
complex alpha, c, gamma
real U(0:idim), d2U(0:idim), Re, ymin, ymax, h, beta
real Uspl(0:idim), d2Uspl(0:idim), ydat(0:idim), f2p
common /data/ n, u, d2u, ymin, ymax, h, f2p,
& gamma, beta, uspl, d2uspl, ydat
common /eig/ c, alpha, Re
c***********************************************************************
integer neq
complex yo(neq), yf(neq)
real t
real UU, d2UU
real Pi
pi = acos(-1.0)
c
c Get the velocity field
c
call SPEVAL(n+1,ydat,U,Uspl,t,UU)
call SPEVAL(n+1,ydat,d2U,d2Uspl,t,d2UU)
do j = 1 , neq-1
yf(j) = yo(j+1)
end do
yf(neq) = (1./alpha/Re*(2.*alpha**2*yo(3)-alpha**4*yo(1)) +
& (0.,1.)*((UU-c)*(yo(3)-alpha**2*yo(1))-
& d2UU*yo(1)))*alpha*Re
return
end
C***********************************************************************
subroutine FPART(neq, yo,t,yf)
C***********************************************************************
C
C Function evaluation for the Orr-Sommerfeld equation
C
c***********************************************************************
c Common variables
c***********************************************************************
parameter (idim=20000)
integer n
complex alpha, c, gamma
real U(0:idim), d2U(0:idim), Re, ymin, ymax, h, beta
real Uspl(0:idim), d2Uspl(0:idim), ydat(0:idim), f2p
common /data/ n, u, d2u, ymin, ymax, h, f2p,
& gamma, beta, uspl, d2uspl, ydat
common /eig/ c, alpha, Re
c***********************************************************************
integer neq
complex yo(neq), yf(neq)
real t
real UU, d2UU
real Pi
pi = acos(-1.0)
c
c Get the velocity field
c
call SPEVAL(n+1,ydat,U,Uspl,t,UU)
call SPEVAL(n+1,ydat,d2U,d2Uspl,t,d2UU)
do j = 1 , neq-1
yf(j) = yo(j+1)
end do
yf(neq) = 2.*alpha**2*yo(3)-alpha**4*yo(1) +
& (0.,1.)*alpha*Re*((UU-c)*(yo(3)-alpha**2*yo(1))-
& d2UU*yo(1))
return
end
C***********************************************************************
subroutine SOLVE_BL
C***********************************************************************
C
C Integrate the boundary layer similarity equation to get velocity
C profile.
C
c***********************************************************************
c Common variables
c***********************************************************************
parameter (idim=20000)
integer n
complex alpha, c, gamma
real U(0:idim), d2U(0:idim), Re, ymin, ymax, h, beta
real Uspl(0:idim), d2Uspl(0:idim), ydat(0:idim), f2p
common /data/ n, u, d2u, ymin, ymax, h, f2p,
& gamma, beta, uspl, d2uspl, ydat
common /eig/ c, alpha, Re
c***********************************************************************
integer i, j, k, p
real xi(3,0:idim), f(3), eta(3), y
real k1(3), k2(3), k3(3), k4(3), err, x2old, f1old
external BLASIUS, RKQCR
do j = 1,3
do i = 0,n
xi(j,i) = 0.0
end do
f(j) = 0.0
eta(j) = 0.0
end do
c
c Set the boundary conditions including guess for d2f(0)
c
xi(1,0) = 0
xi(2,0) = 0
xi(3,0) = f2p
err = 1.0
p = 1
do while ( abs(err) .gt. 1.e-10)
do i = 1, n
y = ymin + float(i)*h
#ifdef USE_NR_ODEINT
do j = 1, 3
eta(j) = xi(j,i-1)
end do
call ODEINTR(eta,3,y-h,y,1.E-7,h/2.,1.e-20,nok,nbad,
& BLASIUS,RKQCR)
do j = 1, 3
xi(j,i) = eta(j)
end do
#else
call SRK4(3, xi(1,i-1), xi(1,i), y-h, h, BLASIUS)
#endif
end do
c
c Check df(ymax)
c
if (p .eq. 1) then
xi3old = xi(3,0)
xi(3,0) = xi(3,0)*.99
else
xi3temp = xi(3,0)
xi(3,0) = xi(3,0)+((xi3old-xi(3,0))/(xi2old-xi(2,n)))*
& (1.0 - xi(2,n))
xi3old = xi3temp
end if
p = p + 1
xi2old = xi(2,n)
err = 1.0 - xi2old
c write (*,*) p, err
end do
c
c Now assemble the velocity field
c
do i = 0, n
u(i) = xi(2,i)
end do
c
c Compute 2nd order finite difference approximation to
c second derivative
c
do i = 1, n-1
d2u(i) = (u(i+1)-2*u(i)+u(i-1))/(h)**2
end do
d2u(0) = (-u(4)+4*u(3)-5*u(2)+2*u(1))/(h)**2
d2u(n) = (2*u(n)-5*u(n-1)+4*u(n-2)-u(n-3))/(h)**2
c
c Need to interpolate the velocity profile to evaluate it at
c arbitrary y
c
do i = 0, n
ydat(i) = ymin + i*h
end do
call SPLINE(n+1,ydat,u,uspl)
c
c Use the spline result for the second derivative
c
do i = 0, n
d2u(i) = uspl(i)
end do
call SPLINE(n+1,ydat,d2u,d2uspl)
do i = 0, n
y = ymin + i*h
call SPEVAL(n+1,ydat,u,uspl,y,us)
call SPEVAL(n+1,ydat,d2u,d2uspl,y,d2us)
write (10,10) y, us, d2us, u(i), d2u(i)
10 format (1x,5(1PE20.12E3,1x))
end do
write (*,20)
20 format (1x,'Velocity Profile completed...',/)
return
end
C***********************************************************************
subroutine BLASIUS(neq,xi,y,f)
C***********************************************************************
C
C Function evaluation for the boundary-layer similarity equation
C
c***********************************************************************
c Common variables
c***********************************************************************
parameter (idim=20000)
integer n
complex alpha, c, gamma
real U(0:idim), d2U(0:idim), Re, ymin, ymax, h, beta
real Uspl(0:idim), d2Uspl(0:idim), ydat(0:idim), f2p
common /data/ n, u, d2u, ymin, ymax, h, f2p,
& gamma, beta, uspl, d2uspl, ydat
common /eig/ c, alpha, Re
c***********************************************************************
integer neq
real xi(neq), f(neq), y
do j = 1 , 2
f(j) = xi(j+1)
end do
f(3) = -xi(1)*xi(3)-beta*(1.-xi(2)**2)
return
end
C***********************************************************************
SUBROUTINE SPLINE (N,X,Y,FDP)
C***********************************************************************
C-----THIS SUBROUTINE COMPUTES THE SECOND DERIVATIVES NEEDED
C-----IN CUBIC SPLINE INTERPOLATION. THE INPUT DATA ARE:
C-----N = NUMBER OF DATA POINTS
C-----X = ARRAY CONTAINING THE VALUES OF THE INDEPENDENT VARIABLE
C----- (ASSUMED TO BE IN ASCENDING ORDER)
C-----Y = ARRAY CONTAINING THE VALUES OF THE FUNCTION AT THE
C----- DATA POINTS GIVEN IN THE X ARRAY
C-----THE OUTPUT IS THE ARRAY FDP WHICH CONTAINS THE SECOND
C-----DERIVATIVES OF THE INTERPOLATING CUBIC SPLINE.
DIMENSION X(N),Y(N),A(N),B(N),C(N),R(N),FDP(N)
C-----COMPUTE THE COEFFICIENTS AND THE RHS OF THE EQUATIONS.
C-----THIS ROUTINE USES THE CANTILEVER CONDITION. THE PARAMETER
C-----ALAMDA (LAMBDA) IS SET TO 1. BUT THIS CAN BE USER-MODIFIED.
C-----A,B,C ARE THE THREE DIAGONALS OF THE TRIDIAGONAL SYSTEM;
C-----R IS THE RIGHT HAND SIDE. THESE ARE NOW ASSEMBLED.
ALAMDA = 1.
NM2 = N - 2
NM1 = N - 1
C(1) = X(2) - X(1)
DO 1 I=2,NM1
C(I) = X(I+1) - X(I)
A(I) = C(I-1)
B(I) = 2.*(A(I) + C(I))
R(I) = 6.*((Y(I+1) - Y(I))/C(I) - (Y(I) - Y(I-1))/C(I-1))
1 CONTINUE
B(2) = B(2) + ALAMDA * C(1)
B(NM1) = B(NM1) + ALAMDA * C(NM1)
C-----AT THIS POINT WE COULD CALL A TRIDIAGONAL SOLVER SUBROUTINE
C-----BUT THE NOTATION IS CLUMSY SO WE WILL SOLVE DIRECTLY. THE
C-----NEXT SECTION SOLVES THE SYSTEM WE HAVE JUST SET UP.
DO 2 I=3,NM1
T = A(I)/B(I-1)
B(I) = B(I) - T * C(I-1)
R(I) = R(I) - T * R(I-1)
2 CONTINUE
FDP(NM1) = R(NM1)/B(NM1)
DO 3 I=2,NM2
NMI = N - I
FDP(NMI) = (R(NMI) - C(NMI)*FDP(NMI+1))/B(NMI)
3 CONTINUE
FDP(1) = ALAMDA * FDP(2)
FDP(N) = ALAMDA * FDP(NM1)
C-----WE NOW HAVE THE DESIRED DERIVATIVES SO WE RETURN TO THE
C-----MAIN PROGRAM.
RETURN
END
C***********************************************************************
SUBROUTINE SPEVAL (N,X,Y,FDP,XX,F)
C***********************************************************************
C-----THIS SUBROUTINE EVALUATES THE CUBIC SPLINE GIVEN
C-----THE DERIVATIVE COMPUTED BY SUBROUTINE SPLINE.
C-----THE INPUT PARAMETERS N,X,Y,FDP HAVE THE SAME
C-----MEANING AS IN SPLINE.
C-----XX = VALUE OF INDEPENDENT VARIABLE FOR WHICH
C----- AN INTERPOLATED VALUE IS REQUESTED
C-----F = THE INTERPOLATED RESULT
DIMENSION X(N),Y(N),FDP(N)
C-----THE FIRST JOB IS TO FIND THE PROPER INTERVAL.
NM1 = N - 1
DO 1 I=1,NM1
IF (XX.LE.X(I+1)) GO TO 10
1 CONTINUE
C-----NOW EVALUATE THE CUBIC
10 DXM = XX - X(I)
DXP = X(I+1) - XX
DEL = X(I+1) - X(I)
F = FDP(I)*DXP*(DXP*DXP/DEL - DEL)/6.
1 +FDP(I+1)*DXM*(DXM*DXM/DEL - DEL)/6.
2 +Y(I)*DXP/DEL + Y(I+1)*DXM/DEL
RETURN
END
C***********************************************************************
subroutine READI(string, I)
C***********************************************************************
C
C Read an integer from an input file
C
c***********************************************************************
integer I, iloc, floc
character*80 string
iloc = index (string,'=')
if (iloc .ne. 0) then
iloc = iloc + 1
floc = index (string,'#')
if (floc .eq. 0) then
floc = 80
else
floc = floc - 1
end if
read (string(iloc:floc),'(I10)',err=99) I
else
write (*,10)
10 format (/,/,1x,'ERROR in input file...',/,/)
stop
end if
goto 100
c
c Error
c
99 continue
write (*,10)
stop
100 return
end
C***********************************************************************
subroutine READR(string, R)
C***********************************************************************
C
C Read an integer from an input file
C
c***********************************************************************
integer iloc, floc
real R
character*80 string
iloc = index (string,'=')
if (iloc .ne. 0) then
iloc = iloc + 1
floc = index (string,'#')
if (floc .eq. 0) then
floc = 80
else
floc = floc - 1
end if
read (string(iloc:floc),'(g20.10)',err=99) R
else
write (*,10)
10 format (/,/,1x,'ERROR in input file...',/,/)
stop
end if
goto 100
c
c Error
c
99 continue
write (*,10)
stop
100 return
end