-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoisson.F
1941 lines (1858 loc) · 56.4 KB
/
poisson.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
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifdef test_poisson
# define driver_only
# include "congrad.F"
# include "grids.F"
# include "hyper3.F"
# include "iomngr.F"
# include "isleperim.F"
# include "relax1.F"
# include "size_check.F"
# include "timer.F"
# include "topog.F"
# include "tropic.F"
# include "util.F"
program driver
c
c=======================================================================
c
c P O I S S O N M O D U L E
c
c This module solves TWO TYPES of elliptic equations.
c
c***********************************************************************
c
c TYPE I is a STREAM FUNCTION equation of the form:
c
c grad{(1/h)*grad(dpsi)} - 2dt*acor*{grad(f/h) X grad(dpsi)} = forc
c
c solved for "dpsi" with "no slip" boundary conditions where...
c
c h = h(x,y) = topography on "u,v" points
c forc = forc(x,y) = forcing on "t" points
c f = f(y) = coriolis factor 2*omega*sin(phi) on "u,v" points
c dpsi = psi(tau+1) - psi(tau-1) where psi is the stream function
c defined on "t" points. tau refers to the time level.
c 2dt = twice the time step
c acor = (0..1) for controlling the implicit treatment of the
c coriolis term
c
c
c***********************************************************************
c
c TYPE II is a PRESSURE EQUATION of the form:
c
c grad{h*grad(surfpress)} = forc
c
c with "free slip" boundary conditions where:
c
c h = h(x,y) = topography on "u,v" points
c forc = forc(x,y) = forcing on "t" points
c
c
c To run a stand-alone test of the Poisson solvers, use the
c "run_poisson" script
c
c
c author: c.h.goldberg e-mail=> [email protected]
c based on code by: r.c.pacanowski e-mail=> [email protected]
c
c=======================================================================
c
#include "size.h"
#include "stdunits.h"
#include "topog.h"
#include "coord.h"
c
dimension dxt(imt), dyt(jmt), dxu(imt), dyu(jmt), csu(jmt)
dimension cst(jmt)
dimension phi(jmt), phit(jmt)
dimension f(jmt)
dimension h(imt,jmt), hr(imt,jmt)
dimension cf(imt,jmt,-1:1,-1:1)
dimension forc(imt,jmt), dpsi(imt,jmt)
dimension res(imt,jmt), kmt(imt,jmt), guess(imt,jmt)
dimension iofs(mnisle), iperm(maxipp), jperm(maxipp)
dimension nippts(mnisle)
dimension surfpres(imt,jmt)
dimension seaht(imt,jmt)
dimension solution(imt,jmt)
dimension du(imt,jmt), dv(imt,jmt)
c
dimension zu(imt,jmt,2)
dimension zumod(imt,jmt,2)
dimension tauu(imt,jmt), tauv(imt,jmt)
dimension psx(imt,jmt), psy(imt,jmt)
c
dimension map (imt,jmt)
logical imask (-mnisle:mnisle)
c
parameter (maxtest=100)
character*16 testlist(maxtest), sortestlist(maxtest), csor
character*32 atest
c
logical converged, solver, noslip
logical show_sea_heights
character*16 variable
c
# ifdef cyclic
print *, ' option "cyclic" enabled'
# endif
# ifdef symmetry
print *, ' option "symmetry" enabled for equator at j=',jmt-1
# endif
c
c-----------------------------------------------------------------------
c initialize individual and sor optimizaion test lists
c-----------------------------------------------------------------------
c
ntest = 0
nsortest = 0
c
c-----------------------------------------------------------------------
c ==> USER INPUT SECTION #1: choose solvers to test
c-----------------------------------------------------------------------
c
c test the stream function formulation (no slip assumed)
c
call select ('stream function', testlist, ntest)
c
c turn on 5 point numerics
c
call select ('5 point', testlist, ntest)
c call select ('relax1', testlist, ntest)
c call select ('hyper3', testlist, ntest)
call select ('congrad', testlist, ntest)
c
c try 9 point solvers with 5 point coefficients (zero corner terms)
c
c call select ('59 test', testlist, ntest)
c call select ('hyper3', testlist, ntest)
c call select ('congrad', testlist, ntest)
c
c turn on 9 point numerics
c
c call select ('9 point', testlist, ntest)
c call select ('congrad', testlist, ntest)
c call select ('hyper3', testlist, ntest)
c
c test the surface pressure formulation using 9 point numerics
c (surface pressure automatically turns on 9 point numerics)
c (5 point numerics do not conserve energy)
c
call select ('surface pressure', testlist, ntest)
call select ('congrad', testlist, ntest)
c call select ('hyper3', testlist, ntest)
c
c-----------------------------------------------------------------------
c choose individual solver test parameters
c c2dtsf = 2*dt
c acor = (0..1) for implicit treatment of coriolis term
c sor = over-relaxation coefficient (1..2)
c mxscan = maximum allowable iterations
c precision = minimum solver step / expected_dpsimax
c crit = estimated maximum error in dpsi -- all solvers
c-----------------------------------------------------------------------
c
c2dtsf = 2*3600.0
acor = 0.0
sor_sp = 1.87
sor_sf = 1.87
mxscan = 6000
precision = 1.0e-7
expected_dpsimax = 1.0e12
tolrsf = precision * expected_dpsimax
expected_surfpresmax = 1.0e3
tolrsp = precision * expected_surfpresmax
c
c-----------------------------------------------------------------------
c Successive overrelaxation solvers can be optimized by finding
c the "sor" (successive overrelaxation constant) which minimizes the
c number of iterations needed to reduce the error below some
c desired tolerence. "sor" is dependent on the geometry and
c topography of the grid but independent of the forcing. For a
c given setup, the optimzation test will show the number of
c iterations needed to achieve the error tolerence as a function of
c "sor".
c choose solvers for the sor optimization test
c-----------------------------------------------------------------------
c
call select ('stream function', sortestlist, nsortest)
call select ('5 point', sortestlist, nsortest)
c call select ('relax1', sortestlist, nsortest)
call select ('hyper3', sortestlist, nsortest)
c call select ('9 point', sortestlist, nsortest)
c call select ('hyper3', sortestlist, nsortest)
c
c call select ('surface pressure', sortestlist, nsortest)
c call select ('hyper3', sortestlist, nsortest)
c
c-----------------------------------------------------------------------
c sor is the sucessive over-relaxation constant
c choose sor optimization ranges
c
c mxscansoropt = max number of scans for sor optimization test
c nsor = number of tests per solver
c sorstart = minimum value of sor
c sorstep = increment between sor values
c
c note: any "sor" that results in the maximum number of scans being
c reached will teriminate the test of that solver
c-----------------------------------------------------------------------
c
mxscansoropt = 6000
nsor = 31
sorstart = 1.7
sorstep = .01
c
c-----------------------------------------------------------------------
c ==> END USER INPUT SECTION #1
c-----------------------------------------------------------------------
c
call inittimers
c
c-----------------------------------------------------------------------
c calculate coordinates for "t" and "u" grid cells.
c-----------------------------------------------------------------------
c
maxlen = max(imt, jmt, km)
call gcoord (maxlen, imt2, jmt2, km2
&, dxtdeg, dytdeg, dxudeg, dyudeg
&, dzt, dzw, xt, xu, yt, yu, zt, zw)
c
c check that returned grid sizes match those in file "size.h"
c
call size_check (imt2, jmt2, km2, 'driver for poisson', 'stop')
c
c-----------------------------------------------------------------------
c define some constants
c-----------------------------------------------------------------------
c
pi = 4.0*atan(1.0)
omega = pi/43082.0
crad = pi/180.0
degtcm = pi/180.0
c
c-----------------------------------------------------------------------
c convert grid resolution to cm
c-----------------------------------------------------------------------
c
do jrow=1,jmt
dyt(jrow) = dytdeg(jrow)*degtcm
dyu(jrow) = dyudeg(jrow)*degtcm
enddo
c
do i=1,imt
dxt(i) = dxtdeg(i)*degtcm
dxu(i) = dxudeg(i)*degtcm
enddo
#ifdef cyclic
dxt(1) = dxt(imt-1)
dxt(imt) = dxt(2)
dxu(1) = dxu(imt-1)
dxu(imt) = dxu(2)
#endif
c
c-----------------------------------------------------------------------
c build latitude arrays for grid
c-----------------------------------------------------------------------
c
do j=1,jmt
if (yu(j) .eq. 90.0) yu(j) = yu(j) - 1.e-4
phi(j) = yu(j)*crad
csu(j) = cos(phi(j))
phit(j) = yt(j)*crad
cst(j) = cos(phit(j))
enddo
c
c-----------------------------------------------------------------------
c build coriolis term
c-----------------------------------------------------------------------
c
do j=1,jmt
f(j) = 2.0*omega*sin(phi(j))
enddo
c
c-----------------------------------------------------------------------
c generate "kmt" = number of vertical levels on "t" cells
c-----------------------------------------------------------------------
c
call topog (kmt, map, xt, yt, zt, xu, yu, zw, imt, jmt, km)
c
print *,' '
print *,' Land/sea mask for testing POISSON MODULE:'
print *,' '
c
print *,' '
do n=1,ntest
print '(a,a)', ' ==> Selecting ', testlist(n)
end do
do n=1,nsortest
print '(a,a)', ' ==> Optimizing sor ', sortestlist(n)
end do
print *,' '
c
c-----------------------------------------------------------------------
c calculate island perimeters
c-----------------------------------------------------------------------
c
auto_kmt_changes = .false.
call isleperim (kmt, map, iperm, jperm, iofs, nippts, nisle
&, imt, jmt, km, mnisle, maxipp
&, xu, yu, zw)
c
c-----------------------------------------------------------------------
c count ocean points
c-----------------------------------------------------------------------
c
nocean = 0
do i=2,imt-1
do j=2,jmt-1
if (map(i,j) .le. 0) nocean = nocean + 1
end do
end do
c
c-----------------------------------------------------------------------
c set mask for island perimeters on which to perform calculations
c imask(-n) = .false. [no equations ever on dry land mass n]
c imask(0) = .true. [equations at all mid ocean points]
c imask(n) = .true./.false [controls whether there will be
c equations on the ocean perimeter of
c land mass n]
c note: land mass 1 is the northwest-most land mass
c usually includes the "north pole", and at low resolutions,
c the "main continent"
c for the numbering of the other landmasses, see generated map(i,j)
c-----------------------------------------------------------------------
c
do isle=-mnisle,mnisle
if (isle .ge. 0 .and. isle .le. nisle) then
imask(isle) = .true.
else
imask(isle) = .false.
end if
end do
c
c-----------------------------------------------------------------------
c ==> USER INPUT SECTION #2: user-specified changes to island mask
c-----------------------------------------------------------------------
c
c there are problems if imask is set .true. for a nonexistent
c island. it is recommended that no changes be made in this section
c
c imask(1) = .false.
c imask(2) = .false.
c
c-----------------------------------------------------------------------
c ==> END USER INPUT SECTION #2:
c-----------------------------------------------------------------------
c
c print diagnostic information
c
print *, ' => Number of ocean points = ', nocean
do isle=-mnisle,mnisle
if (imask(isle)) then
if (isle .eq. 0) then
print '(a)','=> calculations enabled for mid ocean points'
else
print '(2a,i3)','=> calculations enabled for ocean ',
& 'perimeter of land mass',isle
end if
end if
end do
do isle=0,nisle
if (.not. imask(isle)) then
print '(2a,i3)','=> calculations disabled for ocean ',
& 'perimeter of land mass',isle
end if
end do
c
c-----------------------------------------------------------------------
c ==> USER INPUT SECTION #3: "dpsi" normalization
c-----------------------------------------------------------------------
c
c imain is the land mass on which dpsi is normalized to 0
c if imain is 0, then dpsi is not normalized.
c
imain = min(2,nisle)
do isle=1,nisle
if (.not.imask(isle)) imain = isle
enddo
c
c-----------------------------------------------------------------------
c ==> END USER INPUT SECTION #3:
c-----------------------------------------------------------------------
c
if (imain .gt. 0 .and. imain .le. nisle) then
print '(a,i4)', 'dpsi normalized to zero on land mass',imain
else if (imain .eq. 0) then
print *, 'no normalization on dpsi'
else
print *, 'ERROR: illegal value for choice of normalization ',
& 'land mass, imain =', imain
end if
print *,' (user may set "imain" to any valid land mass number)'
c
c-----------------------------------------------------------------------
c calculate h and reciprocal h at u/v points
c-----------------------------------------------------------------------
c
do j=1,jmt-1
do i=1,imt-1
kmu = min(kmt(i,j), kmt(i+1,j), kmt(i+1,j+1), kmt(i,j+1))
if (kmu .ne. 0) then
h(i,j) = zw(kmu)
hr(i,j) = 1.0/h(i,j)
else
h(i,j) = 0.0
hr(i,j) = 0.0
endif
enddo
enddo
call border (h, 'u even')
call border (hr, 'u even')
c
c-----------------------------------------------------------------------
c show the value of acor
c-----------------------------------------------------------------------
c
print *,' '
if (acor .ne. 0.0) then
print *,' => Note: implicit coriolis term ... acor=',acor
else
print *,' => No implicit coriolis term'
endif
print *,' '
c
c-----------------------------------------------------------------------
c construct a simplified zonal wind stress (dynes/cm**2)
c-----------------------------------------------------------------------
c
# define hellerman_winds
#ifdef hellerman_winds
c
c Zonally averaged annual mean Hellerman & Rosenstein wind stress
c
do j=1,jmt
do i=1,imt
if (h(i,j) .ne. 0) then
ulat = phi(j) / crad
call hellerman (ulat, taux, tauy)
tauu(i,j) = taux
tauv(i,j) = tauy
else
tauu(i,j) = 0.0
tauv(i,j) = 0.0
end if
end do
end do
#else
c
c constant west-east winds
c
do i=1,imt
do j=1,jmt
if (j.ge.2 .and. j.le.jmt-2) then
tauu(i,j) = 1.0
tauv(i,j) = 0.0
end if
end do
end do
#endif
c
c-----------------------------------------------------------------------
c calculate vertically averaged forcing
c-----------------------------------------------------------------------
c
do j=1,jmt
do i=1,imt
zu(i,j,1) = tauu(i,j)
zu(i,j,2) = tauv(i,j)
end do
end do
do j=1,jmt
do i=1,imt
zumod(i,j,1) = zu(i,j,1)*c2dtsf
zumod(i,j,2) = zu(i,j,2)*c2dtsf
end do
end do
c
c-----------------------------------------------------------------------
c set initial guess/estimate
c-----------------------------------------------------------------------
c
do i=1,imt
do j=1,jmt
guess(i,j) = 0.0
end do
end do
c
c-----------------------------------------------------------------------
c initialize
c-----------------------------------------------------------------------
c
show_sea_heights = .true.
nisle_sp = 0
nisle_sf = nisle
c
c=======================================================================
c test individual solvers
c=======================================================================
c
do n=1,ntest
print '(/,i2,a,a)', n, '. Testing ', testlist(n)
solver = .false.
c
write (atest,'(i2,a,a)') n,'.',testlist(n)
#ifdef timing
call tic ('solver test', atest)
#endif
c
call do_test (testlist(n)
&, map, imask
&, zu, hr, dxu, dyu, phi, csu, f
&, zumod
&, forc
&, acor, omega, c2dtsf
&, cf
&, h
&, sor, sor_sf, sor_sp
&, mxscan, mscan, tolrsf, tolrsp
&, iperm, jperm, iofs, nisle, nippts
&, crit, estimated_error
&, mode, variable
&, converged
&, guess, dpsi, res
&, solution, surfpres
&, npt
&, noslip, nisle_sp, nisle_sf
&, solver)
c
if (solver) then
c
c estimate convergence rate and theoretical maximum change in
c dpsi if iterated to infinity, assuming geometric convergence.
c
print '(a,a,a,e15.8)'
&, 'Estimated maximum error in ', variable, ' = '
&, estimated_error
c
if (mode .eq. 1) then
c
c stream function: zero dpsi on land mass imain
c
if (imain .gt. 0) then
dpsi1 = dpsi(iperm(iofs(imain)+1), jperm(iofs(imain)+1))
call con_adjust (dpsi, dpsi1, map)
call con_adjust (solution, dpsi1, map)
end if
c
c stream function: fill land areas with constant dpsi
c
call fill_land (dpsi, map, noslip
&, nisle, iperm, jperm, iofs, nippts)
call fill_land (solution, map, noslip
&, nisle, iperm, jperm, iofs, nippts)
c
c construct delta u velocity and delta v velocity
c
call ddyu (dpsi, du, dyu)
do j=2,jmt-1
do i=2,imt-1
du(i,j) = du(i,j)*hr(i,j)
enddo
enddo
call border(du, 'u even')
call neg_vec (du)
c
call ddxu (dpsi, dv, dxu, csu)
do j=2,jmt-1
do i=2,imt-1
dv(i,j) = dv(i,j)*hr(i,j)
enddo
enddo
call border(dv, 'u odd')
end if
c
if (mode .eq. 2) then
c
c make average surfpres = zero
c
call zero_level (surfpres, variable, map, dxt, dyt, cst)
c
c calculate grad (surfpres)
c
call ddxu (surfpres, psx, dxu, csu)
call border(psx, 'u even')
call ddyu (surfpres, psy, dyu)
call border(psy, 'u odd')
endif
c
c-----------------------------------------------------------------------
c show a slice through solution
c-----------------------------------------------------------------------
c
call slice (solution, variable, res, imt/2)
c
if (mode .eq. 2) then
c
c write (*,'(/a/)') ' psx'
c call slice (psx, 'psx', res, imt/2)
c
c write (*,'(/a/)') ' psy'
c call slice (psy, 'psy', res, imt/2)
c
c surface pressure solution is subject to a checkerboard
c null space (especially at low resolutions)
c remove the null space. however, global checkerboard
c removal may not remove local checkerboard patterns.
c
call checkerboard (surfpres, map)
c
c correct average surfpres to zero since checkerboard
c correction can alter mean
c
call zero_level (surfpres, variable, map, dxt, dyt, cst)
c
c show a slice through solution
c
write (*,'(/a/)')
& ' surf pressure uncheckerboarded with zero mean'
call slice (surfpres, variable, res, imt/2)
c
if (show_sea_heights) then
c
c convert surface pressure to virtual sea heights (cm)
c
grav=980.0
do i=1,imt
do j=1,jmt
seaht(i,j) = surfpres(i,j) / grav
res(i,j) = res(i,j) / grav
end do
end do
c
write (*,'(/a/)') ' EQUIVALENT SEA HEIGHTS (cm) '
call slice (seaht, 'sea height', res, imt/2)
end if
end if
end if
c
#ifdef timing
call toc ('solver test', atest)
#endif
end do
c
c=======================================================================
c optimize "sor" for the test geometry
c=======================================================================
c
if (nsortest .ne. 0) then
write (stdout,'(/,a,/)') ' => Optomizing "sor" now ...'
write (stdout,'(/a/)')
& ' This section may take substantial time... be prepared to wait'
endif
c
c-----------------------------------------------------------------------
c set initial guess to zero
c-----------------------------------------------------------------------
c
do j=1,jmt
do i=1,imt
guess(i,j) = 0.0
end do
end do
c
mxscan = mxscansoropt
c
c optimization for selected solvers
c
do n=1,nsortest
do m=1,nsor
sor = sorstart + (m-1)*sorstep
converged = .false.
solver = .false.
c
csor = sortestlist(n)
write (atest,'(a,a,f6.4)') csor(1:len_trim(csor)),' sor=',sor
if (csor .eq. 'hyper3' .or. csor .eq. 'relax1') then
#ifdef timing
call tic('sor optimization', atest)
#endif
endif
c
call do_test (sortestlist(n)
&, map, imask
&, zu, hr, dxu, dyu, phi, csu, f
&, zumod
&, forc
&, acor, omega, c2dtsf
&, cf
&, h
&, sor, sor_sf, sor_sp
&, mxscan, mscan, tolrsf, tolrsp
&, iperm, jperm, iofs, nisle, nippts
&, crit, estimated_error
&, mode, variable
&, converged
&, guess, dpsi, res
&, solution, surfpres
&, npt
&, noslip, nisle_sp, nisle_sf
&, solver)
c
if (csor .eq. 'hyper3' .or. csor .eq. 'relax1') then
#ifdef timing
call toc('sor optimization', atest)
#endif
endif
c
if (solver) then
c
c skip higher sor values if this sor causes divergence
c
if (.not. converged) goto 999
c
if (mode .eq. 1) then
c
c zero dpsi on land mass imain
c
if (imain .gt. 0) then
dpsi1 = dpsi(iperm(iofs(imain)+1), jperm(iofs(imain)+1))
call con_adjust (dpsi, dpsi1, map)
end if
else if (mode .eq. 2) then
c
c correct average surf pressure to zero
c
c
c surface pressure solution is subject to a checkerboard
c null space (especially at low resolutions)
c remove the null space. however, global checkerboard
c removal may not remove local checkerboard patterns.
c
call checkerboard (surfpres, map)
c
c correct average surfpres to zero since checkerboard
c correction can alter mean
c
call zero_level (surfpres, variable, map, dxt, dyt, cst)
c
end if
end if
end do
999 continue
end do
c
call showtimers
stop
end
subroutine select (test, testlist, ntest)
c
c builds a list of solver tests
c
parameter (maxtest=100)
character*(*) testlist(maxtest), test
c
ntest = ntest + 1
if (ntest .gt. maxtest) then
print *,' ==> ERROR: too many tests of Poisson solvers'
print *,' Increase maxtest above ',maxtest
print *,' in main program and subroutine select'
stop '==>select'
else
testlist(ntest) = test
end if
return
end
subroutine do_test (test
&, map, imask
&, zu, hr, dxu, dyu, phi, csu, f
&, zumod
&, forc
&, acor, omega, c2dtsf
&, cf
&, h
&, sor, sor_sf, sor_sp
&, mxscan, mscan, tolrsf, tolrsp
&, iperm, jperm, iofs, nisle, nippts
&, crit, estimated_error
&, mode, variable
&, converged
&, guess, dpsi, res
&, solution, surfpres
&, npt
&, noslip, nisle_sp, nisle_sf
&, solver)
c
#include "size.h"
dimension dxu(imt), dyu(jmt), phi(jmt), f(jmt), csu(jmt)
dimension h(imt,jmt), hr(imt,jmt)
dimension cf(imt,jmt,-1:1,-1:1)
dimension forc(imt,jmt), dpsi(imt,jmt)
dimension res(imt,jmt), kmt(imt,jmt), guess(imt,jmt)
dimension iofs(mnisle), iperm(maxipp), jperm(maxipp)
dimension nippts(mnisle)
dimension surfpres(imt,jmt)
dimension solution(imt,jmt)
c
dimension zu(imt,jmt,2)
dimension zumod(imt,jmt,2)
c
dimension map (imt,jmt)
logical imask (-mnisle:mnisle)
c
parameter (maxtest=32)
character*16 test, prev_test
c
logical converged, solver, noslip
character*11 conv
character*16 variable
character*8 bc_symm
data prev_test /'none'/
c
if (test .eq. 'none') then
c
print *, 'no individual solver tests requested'
solver = .false.
noslip = .true.
c
else if (test .eq. 'stream function') then
c
c-----------------------------------------------------------------------
c define stream function forcing on t grid boxes
c-----------------------------------------------------------------------
c
call sfforc (zu, dxu, dyu, csu, forc)
c
solver = .false.
mode = 1
variable = 'dpsi'
bc_symm = 't odd'
noslip = .true.
nisle = nisle_sf
sor = sor_sf
crit = tolrsf
c
else if (test .eq. '5 point') then
c
c-----------------------------------------------------------------------
c initialize the coefficients for the elliptic solvers using
c stream function 5 point numerics (all 5 pt solvers)
c ne, nw, se, and sw coefficients are set to zero
c to permit testing 9 pt solvers on 5 pt coefficients.
c-----------------------------------------------------------------------
c
call sfc5pt (acor, f, c2dtsf, dxu, dyu, csu, hr, cf)
c
npt = 5
solver = .false.
mode = 1
variable = 'dpsi'
bc_symm = 't odd'
c
call subset (forc, cf(1,1,0,0), nerror)
if (test .ne. prev_test) then
print *
&, 'forc nonzero at ',nerror,' pts with cf(i,j,0,0)=0'
endif
c
else if (test .eq. '9 point') then
c
if (mode .eq. 1) then
c
c initialize the coefficients for the elliptic solvers using
c stream function 9 point numerics (all 9 pt solvers)
c
call sfc9pt (acor, f, c2dtsf, dxu, dyu, csu, hr, cf)
c
npt = 9
solver = .false.
c
call subset (forc, cf(1,1,0,0), nerror)
if (test .ne. prev_test) then
print *
&, 'forc nonzero at ',nerror,' pts with cf(i,j,0,0)=0'
endif
else if (mode .eq. 2) then
npt = 9
solver = .false.
end if
else if (test .eq. 'surface pressure') then
c
c-----------------------------------------------------------------------
c initialize the coefficients for the surface pressure equation
c 9 point coeffiecients
c-----------------------------------------------------------------------
c
call spc9pt (dxu, dyu, csu, h, cf)
c
c calculate "forcing" (i.e. right side) for surface pressure
c
call spforc (zumod, dxu, dyu, csu, h, forc)
c
npt = 9
solver = .false.
mode = 2
variable = 'surfpres'
bc_symm = 't even'
noslip = .false.
nisle = nisle_sp
sor = sor_sp
crit = tolrsp
c
call subset (forc, cf(1,1,0,0), nerror)
if (test .ne. prev_test) then
print *
&, 'forc nonzero at ',nerror,' pts with cf(i,j,0,0)=0'
endif
else if (test .eq. '59 test') then
c
c-----------------------------------------------------------------------
c switch to testing 9 pt solvers on (5 pt) coefficients
c-----------------------------------------------------------------------
c
npt = 9
solver = .false.
else if (test .eq. 'relax1') then
c
c-----------------------------------------------------------------------
c "oldrelax" method, south & west vectorization trick(5 pt only)
c-----------------------------------------------------------------------
c
#ifdef timing
call tic ('solvers','relax1')
#endif
c
call relax1 (npt, variable, bc_symm
&, guess, solution, forc, res
&, cf
&, sor, mxscan, mscan, crit
&, imask, iperm, jperm, iofs, nisle, nippts
&, map
&, converged
&, estimated_error
& )
#ifdef timing
call toc ('solvers','relax1')
#endif
c
print *, ' '
print '(a26,tr1,a11,tr1,a,i6,a,f7.5,a,e10.3)',
& '=> relax1:',conv(converged),
& 'scans =',mscan, ' using sor=',sor
&, ' estimated err=',estimated_error
print '(tr20,a,i1,a)',
& 'parallelization/south,west update/MOM1 coeff'
solver = .true.
else if (test .eq. 'hyper3') then
c
c-----------------------------------------------------------------------
c "hypergrid" method, symmetric coefficients, 4 passes
c-----------------------------------------------------------------------
c
#ifdef timing
call tic ('solvers','hyper3')
#endif
call hyper3 (npt, variable, bc_symm
&, guess, solution, forc, res
&, cf
&, sor, mxscan, mscan, crit
&, imask, iperm, jperm, iofs, nisle, nippts
&, map
&, converged
&, estimated_error
& )
#ifdef timing
call toc ('solvers','hyper3')
#endif
c
print *, ' '
print '(a26,tr1,a11,tr1,a,i6,a,f7.5,a,e10.3)',
& '=> hyper3:',conv(converged),
& 'scans =',mscan, ' using sor=',sor
&, ' estimated err=',estimated_error
print '(tr20,a,i1,a)',
& 'uses ',npt,' pt symmetric coeff, 4 passes'
solver = .true.
else if (test .eq. 'congrad') then
c
c-----------------------------------------------------------------------
c "conjugate gradient method"
c-----------------------------------------------------------------------
c
#ifdef timing
call tic ('solvers','congrad')
#endif
call congr (npt, variable, bc_symm
&, guess, solution, forc, res
&, cf
&, mxscan , mscan , crit