This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3dmhdsub.f
3169 lines (3141 loc) · 110 KB
/
3dmhdsub.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
C**********************************************************************
SUBROUTINE SLENGTH(STRNG,JLEN)
C
CHARACTER*80 STRNG
C
ILEN = LEN(STRNG)
DO 10 I=1,ILEN
IF (STRNG(I:I).EQ.'@') THEN
JLEN = I-1
GOTO 20
ENDIF
10 CONTINUE
C
20 RETURN
END
C**********************************************************************
SUBROUTINE MKGRID(SCODE,SPHYS,DSSDS,D2SSDS2,ICOORD)
C----------------------------------------------------------------------
C If ICOORD=1 then: gets XCODE and returns XPHYS, DXXDX and D2XXDX2
C If ICOORD=2 then: gets YCODE and returns YPHYS, DYYDY and D2YYDY2
C If ICOORD=3 then: gets ZCODE and returns ZPHYS, DZZDX and D2ZZDZ2
C----------------------------------------------------------------------
INCLUDE '3dmhdparam.f'
C
COMMON/BOUNDS/XMAX,YMAX,ZMAX
C----------------------------------------------------------------------
C Grid selection
C----------------------------------------------------------------------
SELECT CASE (NGRID)
C----------------------------------------------------------------------
C Uniform grid.
C----------------------------------------------------------------------
CASE(0)
SELECT CASE (ICOORD)
CASE(1)
SMAX=XMAX
CASE(2)
SMAX=YMAX
CASE(3)
SMAX=ZMAX
CASE DEFAULT
WRITE(6,*)'MKGRID: Invalid ICOORD number'
CALL MPI_FINALIZE(IERR)
STOP
END SELECT
C
SPHYS = SCODE*SMAX
DSSDS = 1.0E00/SMAX
D2SSDS2 = 0.0E00
C----------------------------------------------------------------------
C NOTE: The nonuniform grid NGRID > 0 has some problems that must be
C fixed before using. These are:
C 1. Horizontal grid stretching must be symmetric about domain
C center so that the hard wired periodicity of the domain
C Makes sense. The domain is periodic over XMAX+DX.
C 2. Horizontal inegration for mean values (SPLINEX and SPLINEY)
C must be extended to include ghost point on right (I=2,NX).
C 3. Normalization of integration for mean values must be changed
C from XMAX or YMAX to XMAX+DELTAX or YMAX+DELTAY where DELTAX
C and DELTAY are the physical grid distances to the ghost point.
C 4. In general the derviative metrics should be calculated
C numerically, using the same difference scheme and the code,
C rather than analytically to take advatage of truncation error
C cancelation.
C----------------------------------------------------------------------
C Original grid (by Mark Rast)
C----------------------------------------------------------------------
CASE(1)
SELECT CASE (ICOORD)
CASE(1)
S1 = XX1
S2 = XX2
SMAX = XMAX
CASE(2)
S1 = YY1
S2 = YY2
SMAX = YMAX
CASE(3)
S1 = ZZ1
S2 = ZZ2
SMAX = ZMAX
CASE DEFAULT
WRITE(6,*)'MKGRID: Invalid ICOORD number'
CALL MPI_FINALIZE(IERR)
STOP
END SELECT
C
A1=(S2-S1)/SMAX
A3=ATAN(S1)
A2=ATAN(S2)-A3
IF (SCODE.EQ.0.0E00) THEN
SPHYS=0.0E00
ELSE IF (SCODE.EQ.1.0E00) THEN
SPHYS=SMAX
ELSE
SPHYS=(TAN(A2*SCODE+A3)-S1)/A1
ENDIF
DSSDS=A1/A2/(1.0E00+(S1+A1*SPHYS)**2)
D2SSDS2=-2.0E00*A1**2*(S1+A1*SPHYS)/A2/
1 (1.0E00+(S1+A1*SPHYS)**2)**2
C----------------------------------------------------------------------
C Second grid (by Thierry Emonet 98/05/30)
C----------------------------------------------------------------------
CASE(2)
PI=2.0E00*ASIN(1.0E00)
SELECT CASE (ICOORD)
CASE(1)
A=XA
B=XB
C=XC
D=XD
SMAX = XMAX
CASE(2)
A=YA
B=YB
C=YC
D=YD
SMAX = YMAX
CASE(3)
A=ZA
B=ZB
C=ZC
D=ZD
SMAX = ZMAX
CASE DEFAULT
WRITE(6,*)'MKGRID: Invalid ICOORD number'
CALL MPI_FINALIZE(IERR)
STOP
END SELECT
C
IF (C.LE.1.0E-09) THEN
SPHYS = SCODE*SMAX
DSSDS = 1.0E00/SMAX
D2SSDS2 = 0.0E00
ELSE
SH=(1.0E00-D)*PI / ( D*ATAN((A-B)*C) + 2.0E00*ATAN(B*C) - D
1 *ATAN((A+B)*C) )
SK=2.0E00*C*PI*SMAX / (2.0E00*C*PI + SH*(2.0E00*C*
1 (ATAN((A-B)*C)*(A-B) - ATAN((A+B)*C)*(A+B) +
2 ATAN((A-B-1.0E00)*C) +
3 ATAN((A+B-1.0E00)*C)*(A+B-1.0E00) +
4 ATAN((1.0E00-A+B)*C)*(A-B) ) -
5 LOG(1.0E00+(A-B)**2*C**2) +
6 LOG(1.0E00+(A+B)**2*C**2) -
7 LOG(1.0E00+(A+B-1.0E00)**2*C**2) +
8 LOG(1.0E00+(1.0E00-A+B)**2*C**2) ))
DSSDS=1.0E00 / (SK * (1.0E00 + SH/PI *
1 (ATAN(C*(SCODE-A-B))+ATAN(C*(A-SCODE-B))) ))
D2SSDS2=-DSSDS**3 * C*SH*SK/PI *
1 (1.0E00/(1.0E00+C**2*(A+B-SCODE)**2) -
2 1.0E00/(1.0E00+C**2*(A-B-SCODE)**2))
SPHYS=SK/(2.0E00*C*PI) * (2.0E00*C*PI*SCODE + SH*(2.0E00*C*
1 (ATAN((A-B)*C)*(A-B) -
2 ATAN((A+B)*C)*(A+B) +
3 ATAN((A-B-SCODE)*C)*SCODE +
4 ATAN((A+B-SCODE)*C)*(A+B-SCODE) +
5 ATAN((SCODE-A+B)*C)*(A-B) ) -
6 LOG(1.0E00+(A-B)**2*C**2) +
7 LOG(1.0E00+(A+B)**2*C**2) -
8 LOG(1.0E00+(A+B-SCODE)**2*C**2) +
9 LOG(1.0E00+(SCODE-A+B)**2*C**2) ))
ENDIF
IF (SCODE.EQ.0.0E00) SPHYS=0.0E00
IF (SCODE.EQ.1.0E00) SPHYS=SMAX
C----------------------------------------------------------------------
C If error then... and calculation of dxx
C----------------------------------------------------------------------
CASE DEFAULT
WRITE(6,*)'MKGRID: Invalid NGRID number'
CALL MPI_FINALIZE(IERR)
STOP
END SELECT
C
RETURN
END
C**********************************************************************
SUBROUTINE XJACOBI
C----------------------------------------------------------------------
C Returns the x coordinate Jacobian transformation elements.
C----------------------------------------------------------------------
INCLUDE '3dmhdparam.f'
C
DIMENSION EXX(NX),DXXDX(NX),D2XXDX2(NX),DDX(NX)
DIMENSION WYY(NY),DYYDY(NY),D2YYDY2(NY),DDY(NY)
DIMENSION ZEE(NZ),DZZDZ(NZ),D2ZZDZ2(NZ),DDZ(NZ)
C
COMMON/AJACOBI/EXX,DXXDX,D2XXDX2,DDX,WYY,DYYDY,D2YYDY2,DDY
2 ,ZEE,DZZDZ,D2ZZDZ2,DDZ
C----------------------------------------------------------------------
C Computational grid has evenly spaced x values between zero and one.
C----------------------------------------------------------------------
ORX=1.0E00/FLOAT(NX-IX-1)
DO 10 I=0,NX-IX-1
EXX(I+2)=FLOAT(I)*ORX
10 CONTINUE
EXX(2)=0.0E00
EXX(NX-IX+1)=1.0E00
C
DO 20 I=2,NX-IX+1
SCODE = EXX(I)
CALL MKGRID(SCODE,SPHYS,DSSDS,D2SSDS2,1)
EXX(I) = SPHYS
DXXDX(I) = DSSDS
D2XXDX2(I) = D2SSDS2
DDX(I) = ORX*(1.0E00/DSSDS)
20 CONTINUE
C
RETURN
END
C**********************************************************************
SUBROUTINE YJACOBI
C----------------------------------------------------------------------
C Returns the y coordinate Jacobian transformation elements.
C Modified to look like ZJACOBI (M. Rempel).
C----------------------------------------------------------------------
INCLUDE '3dmhdparam.f'
C
DIMENSION EXX(NX),DXXDX(NX),D2XXDX2(NX),DDX(NX)
DIMENSION WYY(NY),DYYDY(NY),D2YYDY2(NY),DDY(NY)
DIMENSION ZEE(NZ),DZZDZ(NZ),D2ZZDZ2(NZ),DDZ(NZ)
DIMENSION YY(NPY)
C
COMMON/AJACOBI/EXX,DXXDX,D2XXDX2,DDX,WYY,DYYDY,D2YYDY2,DDY
2 ,ZEE,DZZDZ,D2ZZDZ2,DDZ
COMMON/COMMUN/MYPE,MYPEY,MYPEZ,MPISIZE
C----------------------------------------------------------------------
C Full computational grid has evenly spaced y values between zero and one.
C----------------------------------------------------------------------
ORY=1.0E00/FLOAT(NPY-1)
DO 10 J=0,NPY-1
YY(J+1)=FLOAT(J)*ORY
10 CONTINUE
YY(1) = 0.0E00
YY(NPY) = 1.0E00
C----------------------------------------------------------------------
C Domain split between processors and jacobian calculation
C----------------------------------------------------------------------
IF (MYPEY.EQ.0) THEN
DO 20 J=1,IY/2
SCODE = 0.0E00
CALL MKGRID(SCODE,SPHYS,DSSDS,D2SSDS2,2)
WYY(J) = SPHYS
DYYDY(J) = DSSDS
D2YYDY2(J) = D2SSDS2
20 CONTINUE
DO 30 J=IY/2+1,NRY+IY
SCODE = YY(J-IY/2)
CALL MKGRID(SCODE,SPHYS,DSSDS,D2SSDS2,2)
WYY(J) = SPHYS
DYYDY(J) = DSSDS
D2YYDY2(J) = D2SSDS2
30 CONTINUE
ELSE IF (MYPEY.EQ.NPEY-1) THEN
DO 40 J=1,NRY+IY/2
SCODE = YY(J+NPY-NRY-IY/2)
CALL MKGRID(SCODE,SPHYS,DSSDS,D2SSDS2,2)
WYY(J) = SPHYS
DYYDY(J) = DSSDS
D2YYDY2(J) = D2SSDS2
40 CONTINUE
DO 50 J=NRY+IY/2+1,NRY+IY
SCODE = 1.0E00
CALL MKGRID(SCODE,SPHYS,DSSDS,D2SSDS2,2)
WYY(J) = SPHYS
DYYDY(J) = DSSDS
D2YYDY2(J) = D2SSDS2
50 CONTINUE
ELSE
DO 60 J=1,NY
SCODE = YY(J+MYPEY*NRY-IY/2)
CALL MKGRID(SCODE,SPHYS,DSSDS,D2SSDS2,2)
WYY(J) = SPHYS
DYYDY(J) = DSSDS
D2YYDY2(J) = D2SSDS2
60 CONTINUE
ENDIF
C
DDY=ORY*(1.0E00/DYYDY)
C
RETURN
END
C**********************************************************************
SUBROUTINE ZJACOBI
C----------------------------------------------------------------------
C Returns the z coordinate Jacobian transformation elements.
C Modified (M. Rempel).
C----------------------------------------------------------------------
INCLUDE '3dmhdparam.f'
C
DIMENSION EXX(NX),DXXDX(NX),D2XXDX2(NX),DDX(NX)
DIMENSION WYY(NY),DYYDY(NY),D2YYDY2(NY),DDY(NY)
DIMENSION ZEE(NZ),DZZDZ(NZ),D2ZZDZ2(NZ),DDZ(NZ)
DIMENSION ZZ(NPZ)
C
COMMON/AJACOBI/EXX,DXXDX,D2XXDX2,DDX,WYY,DYYDY,D2YYDY2,DDY
2 ,ZEE,DZZDZ,D2ZZDZ2,DDZ
COMMON/COMMUN/MYPE,MYPEY,MYPEZ,MPISIZE
C----------------------------------------------------------------------
C Full computational grid has evenly space z values between zero and one.
C----------------------------------------------------------------------
ORZ=1.0E00/FLOAT(NPZ-1)
DO 10 K=0,NPZ-1
ZZ(K+1)=FLOAT(K)*ORZ
10 CONTINUE
ZZ(1) = 0.0E00
ZZ(NPZ) = 1.0E00
C----------------------------------------------------------------------
C Domain split between processors and jacobian calculation
C----------------------------------------------------------------------
IF (MYPEZ.EQ.0) THEN
DO 20 K=1,ILAP/2
SCODE = 0.0E00
CALL MKGRID(SCODE,SPHYS,DSSDS,D2SSDS2,3)
ZEE(K) = SPHYS
DZZDZ(K) = DSSDS
D2ZZDZ2(K) = D2SSDS2
20 CONTINUE
DO 30 K=ILAP/2+1,NRZ+ILAP
SCODE = ZZ(K-ILAP/2)
CALL MKGRID(SCODE,SPHYS,DSSDS,D2SSDS2,3)
ZEE(K) = SPHYS
DZZDZ(K) = DSSDS
D2ZZDZ2(K) = D2SSDS2
30 CONTINUE
ELSE IF (MYPEZ.EQ.NPEZ-1) THEN
DO 40 K=1,NRZ+ILAP/2
SCODE = ZZ(K+NPZ-NRZ-ILAP/2)
CALL MKGRID(SCODE,SPHYS,DSSDS,D2SSDS2,3)
ZEE(K) = SPHYS
DZZDZ(K) = DSSDS
D2ZZDZ2(K) = D2SSDS2
40 CONTINUE
DO 50 K=NRZ+ILAP/2+1,NRZ+ILAP
SCODE = 1.0E00
CALL MKGRID(SCODE,SPHYS,DSSDS,D2SSDS2,3)
ZEE(K) = SPHYS
DZZDZ(K) = DSSDS
D2ZZDZ2(K) = D2SSDS2
50 CONTINUE
ELSE
DO 60 K=1,NZ
SCODE = ZZ(K+MYPEZ*NRZ-ILAP/2)
CALL MKGRID(SCODE,SPHYS,DSSDS,D2SSDS2,3)
ZEE(K) = SPHYS
DZZDZ(K) = DSSDS
D2ZZDZ2(K) = D2SSDS2
60 CONTINUE
ENDIF
C
DDZ=ORZ*(1.0E00/DZZDZ)
C
RETURN
END
C**********************************************************************
SUBROUTINE STATIC
C----------------------------------------------------------------------
C Generates initial profile. Upper linear adiabatic temperature
C gradient, lower linear stable gradient, linked across inversion layer
C It calls also TUBE which creates the BX, BY, BZ and modifies the
C thermodynamic variables adequatelly. The calling process is as
C follows: IF LMAG=.FALSE.: no magnetic field is created.
C IF LMAG=.TRUE. : if AMPB=/=0: a horizontal layer of magnetic
C field is constructed
C if AMPB=0: the routine TUBE is called
C if NTUBE=0 no layer, no tube, but MHD.
C----------------------------------------------------------------------
INCLUDE '3dmhdparam.f'
C
include 'mpif.h'
C
PARAMETER(NV=2)
C
DIMENSION Y(NV),DYDX(NV)
DIMENSION RU(NX,NY,NZ),RV(NX,NY,NZ),RW(NX,NY,NZ),RO(NX,NY,NZ)
2 ,TT(NX,NY,NZ)
DIMENSION UU(NX,NY,NZ),VV(NX,NY,NZ),WW(NX,NY,NZ)
DIMENSION FU(NX,NY,NZ),FV(NX,NY,NZ),FW(NX,NY,NZ),FR(NX,NY,NZ)
2 ,FT(NX,NY,NZ)
DIMENSION ZRU(NX,NY,NZ),ZRV(NX,NY,NZ),ZRW(NX,NY,NZ)
2 ,ZRO(NX,NY,NZ),ZTT(NX,NY,NZ)
DIMENSION WW1(NX,NY,NZ),WW2(NX,NY,NZ),WW3(NX,NY,NZ)
C
DIMENSION BX(NX,NY,NZ),BY(NX,NY,NZ),BZ(NX,NY,NZ)
DIMENSION ZBX(NX,NY,NZ),ZBY(NX,NY,NZ),ZBZ(NX,NY,NZ)
C
DIMENSION RND(NX,NY)
DIMENSION EXX(NX),DXXDX(NX),D2XXDX2(NX),DDX(NX)
DIMENSION WYY(NY),DYYDY(NY),D2YYDY2(NY),DDY(NY)
DIMENSION ZEE(NZ),DZZDZ(NZ),D2ZZDZ2(NZ),DDZ(NZ)
DIMENSION RKAPA(NZ),DKAPA(NZ)
DIMENSION T(NPZ),R(NPZ),RK(NPZ),DRK(NPZ)
DIMENSION SP1(IPAD),SP2(IPAD),SP3(IPAD),SP4(IPAD),SP5(IPAD)
2 ,SP6(IPAD),SP7(IPAD),SP8(IPAD),SP9(IPAD),SP10(IPAD)
3 ,SP11(IPAD),SP12(IPAD),SP13(IPAD),SP14(IPAD),SP15(IPAD)
4 ,SP16(IPAD),SP17(IPAD),SP18(IPAD),SP19(IPAD),SP20(IPAD)
C
5 ,SP21(IPAD),SP22(IPAD),SP23(IPAD),SP24(IPAD),SP25(IPAD)
6 ,SP26(IPAD)
C
DIMENSION IIR(97)
C
DIMENSION ISTATUS(MPI_STATUS_SIZE)
C
COMMON/BIG/RU,SP1,RV,SP2,RW,SP3,RO,SP4,TT,SP5,UU,SP6,VV,SP7,WW
2 ,SP8,FU,SP9,FV,SP10,FW,SP11,FR,SP12,FT,SP13
3 ,ZRU,SP14,ZRV,SP15,ZRW,SP16,ZRO,SP17,ZTT
4 ,SP18,WW1,SP19,WW2,SP20,WW3
C
5 ,SP21,BX,SP22,BY,SP23,BZ,SP24,ZBX,SP25,ZBY,SP26,ZBZ
C
COMMON/AJACOBI/EXX,DXXDX,D2XXDX2,DDX,WYY,DYYDY,D2YYDY2,DDY
2 ,ZEE,DZZDZ,D2ZZDZ2,DDZ
COMMON/CPAR/CV,OCV,ORE,RE,REPR,THETA,GRAV,AMPT,SF,GAMMA
COMMON/CMAG/ORM,RM,OBETA,AMPB,BFH,BZP
COMMON/CPEN/PZP,SIGMA,RKAPST,TB,RKAPA,DKAPA,RKAPM
COMMON/GRID/DD,HX,H2X,HY,H2Y,HZ,H2Z,C13,C23,C43
COMMON/COMMUN/MYPE,MYPEY,MYPEZ,MPISIZE
COMMON/BOUNDS/XMAX,YMAX,ZMAX
C----------------------------------------------------------------------
C If LREM: File to store RKAPPA in and rescaled boundary temperatures.
C----------------------------------------------------------------------
CHARACTER*50 FNAME
COMMON/SPECIALBOUND/TU,DZTB,DZTU
C
DZZ=1.0E00/FLOAT(NPZ-1)
EPS=1.0E-12
c EPS=1.0E-06
C----------------------------------------------------------------------
C Zero velocity fields.
C----------------------------------------------------------------------
RU = 0.0E00
RV = 0.0E00
RW = 0.0E00
C
IF (.NOT.LSHR) THEN
C
IF (LREM) THEN
C----------------------------------------------------------------------
C New (M. Rempel). Factor 8.07*REPR scales RK so that
C THETA=ETA=F/rho/Cp/T/Cs.
C----------------------------------------------------------------------
DO K=1,NPZ
SZZ=FLOAT(K-1)/FLOAT(NPZ-1)
CALL MKGRID(SZZ,SZ,SDZZDZ,SD2ZZDZ2,3)
CALL GETBACKGROUND(SZ,TZ,RZ)
CALL KAPPA(SZ,RZ,TZ,RKZ)
T(K) =TZ
R(K) =RZ
RK(K)=RKZ
END DO
C Derivative of kappa
RK=RK*8.07*THETA*REPR
DO K=2,NPZ-1
SZZ=FLOAT(K-1)/FLOAT(NPZ-1)
CALL MKGRID(SZZ,SZ,SDZZDZ,SD2ZZDZ2,3)
DRK(K)=(RK(K+1)-RK(K-1))*HZ*SDZZDZ
END DO
SZZ=0
CALL MKGRID(SZZ,SZ,SDZZDZ,SD2ZZDZ2,3)
DRK(1)=(-3.0E00*RK(1)+4.0E00*RK(2)-RK(3))*HZ*SDZZDZ
SZZ=1
CALL MKGRID(SZZ,SZ,SDZZDZ,SD2ZZDZ2,3)
DRK(NPZ)=(3.0E00*RK(NPZ)-4.0E00*RK(NPZ-1)+RK(NPZ-2))
2 *HZ*SDZZDZ
C
IF (MYPE.EQ.0) THEN
CALL SETUP(FINP,FOUT,IPAR,PAR)
I1 = INDEX(FOUT,' ')-1
FNAME = FOUT(1:I1)//'.strat'
OPEN(999,FILE=FNAME,STATUS='UNKNOWN')
WRITE(999,*)T,R,RK/REPR,DRK/REPR
CLOSE(999)
ENDIF
C
TU = T(1)
C----------------------------------------------------------------------
C DZTB and DZTU equal -2/3*DZ*dT/dz.
C----------------------------------------------------------------------
DZTB = T(NPZ)-4.0/3.0*T(NPZ-1)+1.0/3.0*T(NPZ-2)
DZTU = T(1)-4.0/3.0*T(2)+1.0/3.0*T(3)
ELSE
C----------------------------------------------------------------------
C Assign upper boundary values.
C----------------------------------------------------------------------
T(1) = 1.0E00
R(1) = 1.0E00
C----------------------------------------------------------------------
C Extrapolate for remaining values.
C----------------------------------------------------------------------
ZZ=0.0E00
FFZ=0.0E00
PLN=0.0E00
Y(1)=FFZ
Y(2)=PLN
DO 10 K=2,NPZ
HTRY=DZZ
CALL DERIVS(ZZ,Y,NV,DYDX)
CALL BSSTEP(Y,DYDX,NV,ZZ,HTRY,EPS,HDID,HNEXT)
C
IF (HDID.NE.HTRY) THEN
WRITE(6,*)'STATIC: Static structure error.'
CALL MPI_FINALIZE(IERR)
STOP
ENDIF
C
T(K) = 1.0E00+Y(1)
R(K) = EXP(Y(2))/(1.0E00+Y(1))
10 CONTINUE
ENDIF
C
ELSE
C
DO 11 K=1,NPZ
T(K)=1.0E00
R(K)=1.0E00
11 CONTINUE
C
ENDIF
C
TB=T(NPZ)
RB=R(NPZ)
C----------------------------------------------------------------------
C Divide among processors.
C----------------------------------------------------------------------
IF (MYPEZ.EQ.0) THEN
TT(2:NX-IX+1,2:NY-IY+1,1:ILAP/2)=T(1)
TT(2:NX-IX+1,2:NY-IY+1,ILAP/2+1:NZ)
2 =SPREAD(SPREAD(T(1:NRZ+ILAP/2),1,NX-IX),2,NY-IY)
RO(2:NX-IX+1,2:NY-IY+1,1:ILAP/2)=R(1)
RO(2:NX-IX+1,2:NY-IY+1,ILAP/2+1:NZ)
2 =SPREAD(SPREAD(R(1:NRZ+ILAP/2),1,NX-IX),2,NY-IY)
IF (LREM) THEN
RKAPA(1:ILAP/2) = RK(1)
RKAPA(ILAP/2+1:NZ) = RK(1:NRZ+ILAP/2)
DKAPA(1:ILAP/2) = DRK(1)
DKAPA(ILAP/2+1:NZ) = DRK(1:NRZ+ILAP/2)
ENDIF
ELSE IF (MYPEZ.EQ.NPEZ-1) THEN
TT(2:NX-IX+1,2:NY-IY+1,1:NRZ+ILAP/2)
2 =SPREAD(SPREAD(T(NPZ-NRZ-ILAP/2+1:NPZ),1,NX-IX)
3 ,2,NY-IY)
TT(2:NX-IX+1,2:NY-IY+1,NRZ+ILAP/2+1:NRZ+ILAP)=TB
RO(2:NX-IX+1,2:NY-IY+1,1:NRZ+ILAP/2)
2 =SPREAD(SPREAD(R(NPZ-NRZ-ILAP/2+1:NPZ),1,NX-IX)
3 ,2,NY-IY)
RO(2:NX-IX+1,2:NY-IY+1,NRZ+ILAP/2+1:NRZ+ILAP)=RB
IF (LREM) THEN
RKAPA(1:NRZ+ILAP/2) = RK(NPZ-NRZ-ILAP/2+1:NPZ)
RKAPA(NRZ+ILAP/2+1:NRZ+ILAP) = RK(NPZ)
DKAPA(1:NRZ+ILAP/2) = DRK(NPZ-NRZ-ILAP/2+1:NPZ)
DKAPA(NRZ+ILAP/2+1:NRZ+ILAP) = DRK(NPZ)
ENDIF
ELSE
I1=MYPEZ*NRZ-ILAP/2+1
I2=(MYPEZ+1)*NRZ+ILAP/2
TT(2:NX-IX+1,2:NY-IY+1,:)
2 =SPREAD(SPREAD(T(I1:I2),1,NX-IX),2,NY-IY)
RO(2:NX-IX+1,2:NY-IY+1,:)
2 =SPREAD(SPREAD(R(I1:I2),1,NX-IX),2,NY-IY)
IF (LREM) THEN
RKAPA(:) = RK(I1:I2)
DKAPA(:) = DRK(I1:I2)
ENDIF
ENDIF
C----------------------------------------------------------------------
C Initiate magnetic field layer of full-width at half-maximum equal
C to BFH and of maximum amplitude AMPB at depth BZP.
C----------------------------------------------------------------------
IF (LMAG) THEN
IF (AMPB.NE.0.0E00) THEN
CLN=-4.0E00*LOG(2.0E00)/BFH/BFH
DO 15 K=ILAP/2+1,NZ-ILAP/2
BX(:,:,K)=AMPB*EXP(CLN*(ZEE(K)-BZP)**2)
15 CONTINUE
BY=0.0E00
BZ=0.0E00
C
DO 16 K=ILAP/2+1,NZ-ILAP/2
DO 16 J=2,NY-IY+1
DO 16 I=2,NX-IX+1
RO(I,J,K)=RO(I,J,K)
2 -BX(I,J,K)*BX(I,J,K)/TT(I,J,K)*OBETA
16 CONTINUE
ELSE
CALL TUBE
ENDIF
ENDIF
C----------------------------------------------------------------------
C Initiate temperature perturbations. Switch ISW to set either random
C or sinusoidal perturbations (M. Rempel). Random perturbations
C changed to yield identical initial state independent of processor
C configuration (Rast 3/20/02).
C----------------------------------------------------------------------
IF (AMPT.NE.0.0E00) THEN
C
ISW=1
IF (ISW.EQ.1) THEN
C
IDUM=-062659
DO 18 NNZ=1,NPEZ
DO 19 K=ILAP/2+1,NZ-ILAP/2
ITAG=K
DO 20 NNY=1,NPEY
IF (MYPE.EQ.0) THEN
DO 21 J=IY/2+1,NY-IY/2
DO 21 I=IX/2+1,NX-IX/2
RND(I,J)=1.0E00+AMPT*(RAN2(IDUM,IIY,IIR)-0.5E00)
21 CONTINUE
IF ((NNY+NPEY*(NNZ-1)-1).NE.0) THEN
CALL MPI_SEND(RND,NX*NY,MPISIZE,NNY+NPEY*(NNZ-1)-1
2 ,ITAG,MPI_COMM_WORLD,IERR)
ELSE
WW1(:,:,K)=RND
ENDIF
ELSE
IF (MYPE.EQ.(NNY+NPEY*(NNZ-1)-1)) THEN
CALL MPI_RECV(WW1(:,:,K),NX*NY,MPISIZE,0,ITAG
2 ,MPI_COMM_WORLD,ISTATUS,IERR)
ENDIF
ENDIF
20 CONTINUE
19 CONTINUE
18 CONTINUE
C
DO 40 K=ILAP/2+1,NZ-ILAP/2
DO 40 J=IY/2+1,NY-IY/2
DO 40 I=IX/2+1,NX-IX/2
IF (.NOT.LSHR) THEN
TT(I,J,K)=TT(I,J,K)*WW1(I,J,K)
ELSE
RV(I,J,K)=RV(I,J,K)+WW1(I,J,K)-1.0E00
ENDIF
40 CONTINUE
C
ELSE
C
RPI=2.0E00*ASIN(1.0E00)
DO K=ILAP/2+1,NZ-ILAP/2
DO J=2,NY-IY+1
DO I=2,NX-IX+1
RKY=WYY(J)/YMAX*FLOAT(NPY)/FLOAT(NPY+1)*2.0*RPI*8.0
RKZ=ZEE(K)/ZMAX*2.0*RPI
IF (.NOT.LSHR) THEN
TT(I,J,K)=TT(I,J,K)+AMPT*SIN(RKY)*SIN(RKZ)/RO(I,J,K)
ELSE
RV(I,J,K)=RV(I,J,K)+AMPT*SIN(RKY)*SIN(RKZ)/RO(I,J,K)
ENDIF
END DO
END DO
END DO
C
ENDIF
C
ENDIF
C
RETURN
END
C**********************************************************************
SUBROUTINE DERIVS(ZZ,Y,NV,DYDX)
C
INCLUDE '3dmhdparam.f'
C
DIMENSION Y(NV),DYDX(NV)
DIMENSION RKAPA(NZ),DKAPA(NZ)
C
COMMON/CPAR/CV,OCV,ORE,RE,REPR,THETA,GRAV,AMPT,SF,GAMMA
COMMON/CPEN/PZP,SIGMA,RKAPST,TB,RKAPA,DKAPA,RKAPM
C-----------------------------------------------------------------------
C Calculate Z AND DZZDZ
C-----------------------------------------------------------------------
CALL MKGRID(ZZ,Z,DZZDZ,D2ZZDZ2,3)
C----------------------------------------------------------------------
C Calculate dF/dZZ and dlnP/dZZ (DYDX).
C----------------------------------------------------------------------
IF (PZP.EQ.0.0E00) THEN
RKAP=1.0E00
ELSE
RKAP=1.0E00
2 +(RKAPST-1.0E00)/2.0E00*(1.0E00+TANH((Z-PZP)/SIGMA))
ENDIF
DYDX(1)=THETA/RKAP/DZZDZ
DYDX(2)=GRAV/(1.0E00+Y(1))/DZZDZ
C
RETURN
END
C**********************************************************************
SUBROUTINE STEP
C
INCLUDE '3dmhdparam.f'
C
include 'mpif.h'
C
DIMENSION RU(NX,NY,NZ),RV(NX,NY,NZ),RW(NX,NY,NZ),RO(NX,NY,NZ)
2 ,TT(NX,NY,NZ)
DIMENSION UU(NX,NY,NZ),VV(NX,NY,NZ),WW(NX,NY,NZ)
DIMENSION FU(NX,NY,NZ),FV(NX,NY,NZ),FW(NX,NY,NZ),FR(NX,NY,NZ)
2 ,FT(NX,NY,NZ)
DIMENSION ZRU(NX,NY,NZ),ZRV(NX,NY,NZ),ZRW(NX,NY,NZ)
2 ,ZRO(NX,NY,NZ),ZTT(NX,NY,NZ)
DIMENSION WW1(NX,NY,NZ),WW2(NX,NY,NZ),WW3(NX,NY,NZ)
C
DIMENSION BX(NX,NY,NZ),BY(NX,NY,NZ),BZ(NX,NY,NZ)
DIMENSION ZBX(NX,NY,NZ),ZBY(NX,NY,NZ),ZBZ(NX,NY,NZ)
C
DIMENSION EXX(NX),DXXDX(NX),D2XXDX2(NX),DDX(NX)
DIMENSION WYY(NY),DYYDY(NY),D2YYDY2(NY),DDY(NY)
DIMENSION ZEE(NZ),DZZDZ(NZ),D2ZZDZ2(NZ),DDZ(NZ)
DIMENSION RKAPA(NZ),DKAPA(NZ)
C
DIMENSION SP1(IPAD),SP2(IPAD),SP3(IPAD),SP4(IPAD),SP5(IPAD)
2 ,SP6(IPAD),SP7(IPAD),SP8(IPAD),SP9(IPAD),SP10(IPAD)
3 ,SP11(IPAD),SP12(IPAD),SP13(IPAD),SP14(IPAD),SP15(IPAD)
4 ,SP16(IPAD),SP17(IPAD),SP18(IPAD),SP19(IPAD),SP20(IPAD)
C
5 ,SP21(IPAD),SP22(IPAD),SP23(IPAD),SP24(IPAD),SP25(IPAD)
6 ,SP26(IPAD)
C
DIMENSION WMIN(4),WMOUT(4)
C
COMMON/AJACOBI/EXX,DXXDX,D2XXDX2,DDX,WYY,DYYDY,D2YYDY2,DDY
2 ,ZEE,DZZDZ,D2ZZDZ2,DDZ
COMMON/BIG/RU,SP1,RV,SP2,RW,SP3,RO,SP4,TT,SP5,UU,SP6,VV,SP7,WW
2 ,SP8,FU,SP9,FV,SP10,FW,SP11,FR,SP12,FT,SP13
3 ,ZRU,SP14,ZRV,SP15,ZRW,SP16,ZRO,SP17,ZTT
4 ,SP18,WW1,SP19,WW2,SP20,WW3
C
5 ,SP21,BX,SP22,BY,SP23,BZ,SP24,ZBX,SP25,ZBY,SP26,ZBZ
C
COMMON/CPAR/CV,OCV,ORE,RE,REPR,THETA,GRAV,AMPT,SF,GAMMA
COMMON/CMAG/ORM,RM,OBETA,AMPB,BFH,BZP
COMMON/CPEN/PZP,SIGMA,RKAPST,TB,RKAPA,DKAPA,RKAPM
COMMON/GRID/DD,HX,H2X,HY,H2Y,HZ,H2Z,C13,C23,C43
COMMON/TRACE/UMACH
COMMON/CTIM/DT,TIMT,TIMC,TIMI
COMMON/ITER/NTOTAL,NSTEP0,NIT
COMMON/RUNGKU/GAM1,GAM2,GAM3,ZETA1,ZETA2
COMMON/COMMUN/MYPE,MYPEY,MYPEZ,MPISIZE
C----------------------------------------------------------------------
C Calculate the time-step and maximum Mach number.
C----------------------------------------------------------------------
UMACH=0.0E00
RMIN=1.0E09
VMAX=0.0E00
OGAMMA=1.0E00/GAMMA
C
c UU=SQRT((RU**2+RV**2+RW**2)/RO**2)
DO 10 K=ILAP/2+1,NZ-ILAP/2
DO 10 J=2,NY-IY+1
DO 10 I=2,NX-IX+1
UU(I,J,K)=(RU(I,J,K)*RU(I,J,K)+RV(I,J,K)*RV(I,J,K)
2 +RW(I,J,K)*RW(I,J,K))*(1.0E00/RO(I,J,K))**2
10 CONTINUE
C
c VV=SQRT(GAMMA*TT)
c UMACH=MAXVAL(UU/VV)
DO 20 K=ILAP/2+1,NZ-ILAP/2
DO 20 J=2,NY-IY+1
DO 20 I=2,NX-IX+1
UMACH=MAX(UMACH,OGAMMA*UU(I,J,K)/TT(I,J,K))
20 CONTINUE
UMACH=SQRT(UMACH)
C
c VMAX=MAXVAL(UU+VV)
IF (LMAG) THEN
DO 30 K=ILAP/2+1,NZ-ILAP/2
DO 30 J=2,NY-IY+1
DO 30 I=2,NX-IX+1
UU(I,J,K)=UU(I,J,K)+GAMMA*TT(I,J,K)
2 +(BX(I,J,K)*BX(I,J,K)
3 +BY(I,J,K)*BY(I,J,K)
4 +BZ(I,J,K)*BZ(I,J,K))
5 *OBETA/RO(I,J,K)
6 +2.0E00*SQRT(UU(I,J,K)
7 *(GAMMA*TT(I,J,K)
8 +(BX(I,J,K)*BX(I,J,K)
9 +BY(I,J,K)*BY(I,J,K)
1 +BZ(I,J,K)*BZ(I,J,K))
2 *OBETA/RO(I,J,K)))
30 CONTINUE
ELSE
DO 40 K=ILAP/2+1,NZ-ILAP/2
DO 40 J=2,NY-IY+1
DO 40 I=2,NX-IX+1
UU(I,J,K)=UU(I,J,K)+GAMMA*TT(I,J,K)
2 +2.0E00*SQRT(UU(I,J,K)
3 *GAMMA*TT(I,J,K))
40 CONTINUE
ENDIF
DO 50 K=ILAP/2+1,NZ-ILAP/2
DO 50 J=2,NY-IY+1
DO 50 I=2,NX-IX+1
VMAX=MAX(VMAX,UU(I,J,K))
RMIN=MIN(RMIN,RO(I,J,K))
50 CONTINUE
VMAX=SQRT(VMAX)
C
CALL MPI_ALLREDUCE(UMACH,WMOUT,1,MPISIZE,MPI_MAX,
2 MPI_COMM_WORLD,IERR)
UMACH=WMOUT(1)
C
ISW=1
IF (ISW.EQ.0) THEN
C----------------------------------------------------------------------
C Find global minimum timestep. Note that this approach yields a
C timestep possibly smaller than the minimum pointwise value.
C Values of DD and RKAPM are unchanged from initial time step evaluation.
C----------------------------------------------------------------------
WMIN(1)=RMIN
WMIN(2)=-1.0E00*VMAX
CALL MPI_ALLREDUCE(WMIN,WMOUT,2,MPISIZE,MPI_MIN,
2 MPI_COMM_WORLD,IERR)
RMIN=WMOUT(1)
VMAX=-1.0E00*WMOUT(2)
C
DT1=DD/VMAX
IF (LREM) THEN
C----------------------------------------------------------------------
C Thermal conductivity split into a constant and depth dependant part.
C----------------------------------------------------------------------
DT2=0.5*DD*DD*REPR*CV*RMIN/(1.0+RKAPM)
ELSE
DT2=0.5E00*DD*DD*REPR*CV*RMIN/RKAPM
ENDIF
DT3=0.375E00*DD*DD*RE*RMIN
IF (LMAG) THEN
DT4=0.5E00*DD*DD*RM
DT=SF*MIN(DT1,DT2,DT3,DT4)
ELSE
DT=SF*MIN(DT1,DT2,DT3)
ENDIF
ELSE
C----------------------------------------------------------------------
C Find the pointwise minimum timestep.
C----------------------------------------------------------------------
DO 2 K=ILAP/2+1,NZ-ILAP/2
DO 2 J=2,NY-IY+1
DO 2 I=2,NX-IX+1
IF (NX.GT.IX+1) THEN
DD=MIN(DDX(I),DDY(J),DDZ(K))
ELSE
DD=MIN(DDY(J),DDZ(K))
ENDIF
WW1(I,J,K)=DD/SQRT(UU(I,J,K))
IF (LREM) THEN
C----------------------------------------------------------------------
C Thermal conductivity split into a constant and depth dependant part.
C----------------------------------------------------------------------
WW2(I,J,K)=0.5*DD*DD*REPR*CV*RO(I,J,K)/(1.0+RKAPA(K))
ELSE
WW2(I,J,K)=0.5E00*DD*DD*REPR*CV*RO(I,J,K)/RKAPA(K)
ENDIF
WW3(I,J,K)=0.375E00*DD*DD*RE*RO(I,J,K)
IF (LMAG) THEN
VV(I,J,K)=0.5E00*DD*DD*RM
ENDIF
2 CONTINUE
C
WMIN(1)=MINVAL(WW1(2:NX-IX+1,2:NY-IY+1,ILAP/2+1:NZ-ILAP/2))
WMIN(2)=MINVAL(WW2(2:NX-IX+1,2:NY-IY+1,ILAP/2+1:NZ-ILAP/2))
WMIN(3)=MINVAL(WW3(2:NX-IX+1,2:NY-IY+1,ILAP/2+1:NZ-ILAP/2))
MINCNT=3
IF (LMAG) THEN
WMIN(4)=MINVAL(VV(2:NX-IX+1,2:NY-IY+1,ILAP/2+1:NZ-ILAP/2))
MINCNT=4
ENDIF
CALL MPI_ALLREDUCE(WMIN,WMOUT,MINCNT,MPISIZE,MPI_MIN,
2 MPI_COMM_WORLD,IERR)
IF (LMAG) THEN
DT=SF*MIN(WMOUT(1),WMOUT(2),WMOUT(3),WMOUT(4))
ELSE
DT=SF*MIN(WMOUT(1),WMOUT(2),WMOUT(3))
ENDIF
ENDIF
C----------------------------------------------------------------------
C Third-order Runge-Kutta timestepping scheme of Wray (Spalart, P.R.,
C Moser, R.D., & Rogers M.M., Spectral Methods for the Navier-Stokes
C Equations with One Infinite and Two Periodic Directions,
C J. Comp. Phys., 96 297-324 1991).
C Calculate the first Runge-Kutta substep.
C----------------------------------------------------------------------
DO 71 K=ILAP/2+1,NZ-ILAP/2
DO 71 J=2,NY-IY+1
DO 71 I=2,NX-IX+1
ZRU(I,J,K)=RU(I,J,K)
71 CONTINUE
DO 81 K=ILAP/2+1,NZ-ILAP/2
DO 81 J=2,NY-IY+1
DO 81 I=2,NX-IX+1
ZRV(I,J,K)=RV(I,J,K)
81 CONTINUE
DO 91 K=ILAP/2+1,NZ-ILAP/2
DO 91 J=2,NY-IY+1
DO 91 I=2,NX-IX+1
ZRW(I,J,K)=RW(I,J,K)
91 CONTINUE
DO 101 K=ILAP/2+1,NZ-ILAP/2
DO 101 J=2,NY-IY+1
DO 101 I=2,NX-IX+1
ZRO(I,J,K)=RO(I,J,K)
101 CONTINUE
DO 111 K=ILAP/2+1,NZ-ILAP/2
DO 111 J=2,NY-IY+1
DO 111 I=2,NX-IX+1
ZTT(I,J,K)=TT(I,J,K)
111 CONTINUE
IF (LMAG) THEN
DO 121 K=ILAP/2+1,NZ-ILAP/2
DO 121 J=2,NY-IY+1
DO 121 I=2,NX-IX+1
ZBX(I,J,K)=BX(I,J,K)
121 CONTINUE
DO 131 K=ILAP/2+1,NZ-ILAP/2
DO 131 J=2,NY-IY+1
DO 131 I=2,NX-IX+1
ZBY(I,J,K)=BY(I,J,K)
131 CONTINUE
DO 141 K=ILAP/2+1,NZ-ILAP/2
DO 141 J=2,NY-IY+1
DO 141 I=2,NX-IX+1
ZBZ(I,J,K)=BZ(I,J,K)
141 CONTINUE
ENDIF
C
CALL FLUXES
C
COEF=GAM1*DT
C
DO 70 K=ILAP/2+1,NZ-ILAP/2
DO 70 J=2,NY-IY+1
DO 70 I=2,NX-IX+1
RU(I,J,K)=ZRU(I,J,K)+COEF*FU(I,J,K)
70 CONTINUE
DO 80 K=ILAP/2+1,NZ-ILAP/2
DO 80 J=2,NY-IY+1
DO 80 I=2,NX-IX+1
RV(I,J,K)=ZRV(I,J,K)+COEF*FV(I,J,K)
80 CONTINUE
DO 90 K=ILAP/2+1,NZ-ILAP/2
DO 90 J=2,NY-IY+1
DO 90 I=2,NX-IX+1
RW(I,J,K)=ZRW(I,J,K)+COEF*FW(I,J,K)
90 CONTINUE
DO 100 K=ILAP/2+1,NZ-ILAP/2
DO 100 J=2,NY-IY+1
DO 100 I=2,NX-IX+1
RO(I,J,K)=ZRO(I,J,K)+COEF*FR(I,J,K)
100 CONTINUE
DO 110 K=ILAP/2+1,NZ-ILAP/2
DO 110 J=2,NY-IY+1
DO 110 I=2,NX-IX+1
TT(I,J,K)=ZTT(I,J,K)+COEF*FT(I,J,K)
110 CONTINUE
IF (LMAG) THEN
DO 120 K=ILAP/2+1,NZ-ILAP/2
DO 120 J=2,NY-IY+1
DO 120 I=2,NX-IX+1
BX(I,J,K)=ZBX(I,J,K)+COEF*WW1(I,J,K)
120 CONTINUE
DO 130 K=ILAP/2+1,NZ-ILAP/2
DO 130 J=2,NY-IY+1
DO 130 I=2,NX-IX+1
BY(I,J,K)=ZBY(I,J,K)+COEF*WW2(I,J,K)
130 CONTINUE
DO 140 K=ILAP/2+1,NZ-ILAP/2
DO 140 J=2,NY-IY+1
DO 140 I=2,NX-IX+1
BZ(I,J,K)=ZBZ(I,J,K)+COEF*WW3(I,J,K)
140 CONTINUE
ENDIF
C
CALL BCON
C
CALL COMMUNICATE
C----------------------------------------------------------------------
C Calculate second Runge-Kutta substep.
C----------------------------------------------------------------------
COEF=ZETA1*DT
C
DO 190 K=ILAP/2+1,NZ-ILAP/2
DO 190 J=2,NY-IY+1
DO 190 I=2,NX-IX+1
ZRU(I,J,K)=RU(I,J,K)+COEF*FU(I,J,K)
190 CONTINUE
DO 200 K=ILAP/2+1,NZ-ILAP/2
DO 200 J=2,NY-IY+1
DO 200 I=2,NX-IX+1
ZRV(I,J,K)=RV(I,J,K)+COEF*FV(I,J,K)
200 CONTINUE
DO 210 K=ILAP/2+1,NZ-ILAP/2
DO 210 J=2,NY-IY+1
DO 210 I=2,NX-IX+1
ZRW(I,J,K)=RW(I,J,K)+COEF*FW(I,J,K)
210 CONTINUE
DO 220 K=ILAP/2+1,NZ-ILAP/2
DO 220 J=2,NY-IY+1
DO 220 I=2,NX-IX+1
ZRO(I,J,K)=RO(I,J,K)+COEF*FR(I,J,K)
220 CONTINUE
DO 230 K=ILAP/2+1,NZ-ILAP/2
DO 230 J=2,NY-IY+1