forked from wrf-model/WRF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module_bc.F
4689 lines (4046 loc) · 160 KB
/
module_bc.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
!WRF:MODEL_LAYER:BOUNDARY
!
MODULE module_bc
USE module_configure
USE module_wrf_error
USE module_model_constants
IMPLICIT NONE
! TYPE bcs
!
! LOGICAL :: periodic_x
! LOGICAL :: symmetric_xs
! LOGICAL :: symmetric_xe
! LOGICAL :: open_xs
! LOGICAL :: open_xe
! LOGICAL :: periodic_y
! LOGICAL :: symmetric_ys
! LOGICAL :: symmetric_ye
! LOGICAL :: open_ys
! LOGICAL :: open_ye
! LOGICAL :: nested
! LOGICAL :: specified
! LOGICAL :: top_radiation
!
! END TYPE bcs
! set the bdyzone. We are hardwiring this here and we'll
! decide later where it should be set and stored
INTEGER, PARAMETER :: bdyzone = 4
INTEGER, PARAMETER :: bdyzone_x = bdyzone
INTEGER, PARAMETER :: bdyzone_y = bdyzone
INTERFACE stuff_bdy
MODULE PROCEDURE stuff_bdy_new , stuff_bdy_old
END INTERFACE
INTERFACE stuff_bdytend
MODULE PROCEDURE stuff_bdytend_new , stuff_bdytend_old
END INTERFACE
CONTAINS
SUBROUTINE boundary_condition_check ( config_flags, bzone, error, gn )
! this routine checks the boundary condition logicals
! to make sure that the boundary conditions are not over
! or under specified. The routine also checks that the
! boundary zone is sufficiently sized for the specified
! boundary conditions
IMPLICIT NONE
TYPE( grid_config_rec_type ) config_flags
INTEGER, INTENT(IN ) :: bzone, gn
INTEGER, INTENT(INOUT) :: error
! local variables
INTEGER :: xs_bc, xe_bc, ys_bc, ye_bc, bzone_min
INTEGER :: nprocx, nprocy
CALL wrf_debug( 100 , ' checking boundary conditions for grid ' )
error = 0
xs_bc = 0
xe_bc = 0
ys_bc = 0
ye_bc = 0
! sum the number of conditions specified for each lateral boundary.
! obviously, this number should be 1
IF( config_flags%periodic_x ) THEN
xs_bc = xs_bc+1
xe_bc = xe_bc+1
ENDIF
IF( config_flags%periodic_y ) THEN
ys_bc = ys_bc+1
ye_bc = ye_bc+1
ENDIF
IF( config_flags%symmetric_xs ) xs_bc = xs_bc + 1
IF( config_flags%symmetric_xe ) xe_bc = xe_bc + 1
IF( config_flags%open_xs ) xs_bc = xs_bc + 1
IF( config_flags%open_xe ) xe_bc = xe_bc + 1
IF( config_flags%symmetric_ys ) ys_bc = ys_bc + 1
IF( config_flags%symmetric_ye ) ye_bc = ye_bc + 1
IF( config_flags%open_ys ) ys_bc = ys_bc + 1
IF( config_flags%open_ye ) ye_bc = ye_bc + 1
IF( config_flags%nested ) THEN
xs_bc = xs_bc + 1
xe_bc = xe_bc + 1
ys_bc = ys_bc + 1
ye_bc = ye_bc + 1
ENDIF
IF( config_flags%specified ) THEN
IF( .NOT. config_flags%periodic_x)xs_bc = xs_bc + 1
IF( .NOT. config_flags%periodic_x)xe_bc = xe_bc + 1
ys_bc = ys_bc + 1
ye_bc = ye_bc + 1
ENDIF
IF( config_flags%polar ) THEN
ys_bc = ys_bc + 1
ye_bc = ye_bc + 1
ENDIF
! check the number of conditions for each boundary
IF( (xs_bc /= 1) .or. &
(xe_bc /= 1) .or. &
(ys_bc /= 1) .or. &
(ye_bc /= 1) ) THEN
error = 1
write( wrf_err_message ,*) ' *** Error in boundary condition specification '
CALL wrf_message ( wrf_err_message )
write( wrf_err_message ,*) ' boundary conditions at xs ', xs_bc
CALL wrf_message ( wrf_err_message )
write( wrf_err_message ,*) ' boundary conditions at xe ', xe_bc
CALL wrf_message ( wrf_err_message )
write( wrf_err_message ,*) ' boundary conditions at ys ', ys_bc
CALL wrf_message ( wrf_err_message )
write( wrf_err_message ,*) ' boundary conditions at ye ', ye_bc
CALL wrf_message ( wrf_err_message )
write( wrf_err_message ,*) ' boundary conditions logicals are '
CALL wrf_message ( wrf_err_message )
write( wrf_err_message ,*) ' periodic_x ',config_flags%periodic_x
CALL wrf_message ( wrf_err_message )
write( wrf_err_message ,*) ' periodic_y ',config_flags%periodic_y
CALL wrf_message ( wrf_err_message )
write( wrf_err_message ,*) ' symmetric_xs ',config_flags%symmetric_xs
CALL wrf_message ( wrf_err_message )
write( wrf_err_message ,*) ' symmetric_xe ',config_flags%symmetric_xe
CALL wrf_message ( wrf_err_message )
write( wrf_err_message ,*) ' symmetric_ys ',config_flags%symmetric_ys
CALL wrf_message ( wrf_err_message )
write( wrf_err_message ,*) ' symmetric_ye ',config_flags%symmetric_ye
CALL wrf_message ( wrf_err_message )
write( wrf_err_message ,*) ' open_xs ',config_flags%open_xs
CALL wrf_message ( wrf_err_message )
write( wrf_err_message ,*) ' open_xe ',config_flags%open_xe
CALL wrf_message ( wrf_err_message )
write( wrf_err_message ,*) ' open_ys ',config_flags%open_ys
CALL wrf_message ( wrf_err_message )
write( wrf_err_message ,*) ' open_ye ',config_flags%open_ye
CALL wrf_message ( wrf_err_message )
write( wrf_err_message ,*) ' polar ',config_flags%polar
CALL wrf_message ( wrf_err_message )
write( wrf_err_message ,*) ' nested ',config_flags%nested
CALL wrf_message ( wrf_err_message )
write( wrf_err_message ,*) ' specified ',config_flags%specified
CALL wrf_message ( wrf_err_message )
CALL wrf_error_fatal( ' *** Error in boundary condition specification ' )
ENDIF
! now check to see if boundary zone size is sufficient.
! we could have the necessary boundary zone size be returned
! to the calling routine.
IF( config_flags%periodic_x .or. &
config_flags%periodic_y .or. &
config_flags%symmetric_xs .or. &
config_flags%symmetric_xe .or. &
config_flags%symmetric_ys .or. &
config_flags%symmetric_ye ) THEN
bzone_min = MAX( 1, &
(config_flags%h_mom_adv_order+1)/2, &
(config_flags%h_sca_adv_order+1)/2 )
IF( bzone < bzone_min) THEN
error = 2
WRITE ( wrf_err_message , * ) ' boundary zone not large enough '
CALL wrf_message ( wrf_err_message )
WRITE ( wrf_err_message , * ) ' boundary zone specified ',bzone
CALL wrf_message ( wrf_err_message )
WRITE ( wrf_err_message , * ) ' minimum boundary zone needed ',bzone_min
CALL wrf_error_fatal ( wrf_err_message )
ENDIF
ENDIF
CALL wrf_debug ( 100 , ' boundary conditions OK for grid ' )
END subroutine boundary_condition_check
!--------------------------------------------------------------------------
SUBROUTINE set_physical_bc2d( dat, variable_in, &
config_flags, &
ids,ide, jds,jde, & ! domain dims
ims,ime, jms,jme, & ! memory dims
ips,ipe, jps,jpe, & ! patch dims
its,ite, jts,jte )
! This subroutine sets the data in the boundary region, by direct
! assignment if possible, for periodic and symmetric (wall)
! boundary conditions. Currently, we are only doing 1 variable
! at a time - lots of overhead, so maybe this routine can be easily
! inlined later or we could pass multiple variables -
! would probably want a largestep and smallstep version.
! 15 Jan 99, Dave
! Modified the incoming its,ite,jts,jte to truly be the tile size.
! This required modifying the loop limits when the "istag" or "jstag"
! is used, as this is only required at the end of the domain.
IMPLICIT NONE
INTEGER, INTENT(IN ) :: ids,ide, jds,jde
INTEGER, INTENT(IN ) :: ims,ime, jms,jme
INTEGER, INTENT(IN ) :: ips,ipe, jps,jpe
INTEGER, INTENT(IN ) :: its,ite, jts,jte
CHARACTER, INTENT(IN ) :: variable_in
CHARACTER :: variable
REAL, DIMENSION( ims:ime , jms:jme ) :: dat
TYPE( grid_config_rec_type ) config_flags
INTEGER :: i, j, istag, jstag, itime, istart, iend
LOGICAL :: debug, open_bc_copy
!------------
debug = .false.
open_bc_copy = .false.
variable = variable_in
IF ( variable_in .ge. 'A' .and. variable_in .le. 'Z' ) THEN
variable = CHAR( ICHAR(variable_in) - ICHAR('A') + ICHAR('a') )
ENDIF
IF ((variable == 'u') .or. (variable == 'v') .or. &
(variable == 'w') .or. (variable == 't') .or. &
(variable == 'x') .or. (variable == 'y') .or. &
(variable == 'r') .or. (variable == 'p') ) open_bc_copy = .true.
! begin, first set a staggering variable
istag = -1
jstag = -1
IF ((variable == 'u') .or. (variable == 'x')) istag = 0
IF ((variable == 'v') .or. (variable == 'y')) jstag = 0
if(debug) then
write(6,*) ' in bc2d, var is ',variable, istag, jstag
write(6,*) ' b.cs are ', &
config_flags%periodic_x, &
config_flags%periodic_y
end if
IF ( variable == 'd' ) then !JDM
istag = 0
jstag = 0
ENDIF
IF ( variable == 'e' ) then !JDM
istag = 0
ENDIF
IF ( variable == 'f' ) then !JDM
jstag = 0
ENDIF
! periodic conditions.
! note, patch must cover full range in periodic dir, or else
! its intra-patch communication that is handled elsewheres.
! symmetry conditions can always be handled here, because no
! outside patch communication is needed
periodicity_x: IF( ( config_flags%periodic_x ) ) THEN
IF ( ( ids == ips ) .and. ( ide == ipe ) ) THEN ! test if east and west both on-processor
IF ( its == ids ) THEN
DO j = MAX(jds,jts-1), MIN(jte+1,jde+jstag)
DO i = 0,-(bdyzone-1),-1
dat(ids+i-1,j) = dat(ide+i-1,j)
ENDDO
ENDDO
ENDIF
IF ( ite == ide ) THEN
DO j = MAX(jds,jts-1), MIN(jte+1,jde+jstag)
!! DO i = 1 , bdyzone
DO i = -istag , bdyzone
dat(ide+i+istag,j) = dat(ids+i+istag,j)
ENDDO
ENDDO
ENDIF
ENDIF
ELSE
symmetry_xs: IF( ( config_flags%symmetric_xs ) .and. &
( its == ids ) ) THEN
IF ( (variable /= 'u') .and. (variable /= 'x') ) THEN
DO j = MAX(jds,jts-1), MIN(jte+1,jde+jstag)
DO i = 1, bdyzone
dat(ids-i,j) = dat(ids+i-1,j) ! here, dat(0) = dat(1), etc
ENDDO ! symmetry about dat(0.5) (u=0 pt)
ENDDO
ELSE
IF( variable == 'u' ) THEN
DO j = MAX(jds,jts-1), MIN(jte+1,jde+jstag)
DO i = 0, bdyzone-1
dat(ids-i,j) = - dat(ids+i,j) ! here, u(0) = - u(2), etc
ENDDO ! normal b.c symmetry at u(1)
ENDDO
ELSE
DO j = MAX(jds,jts-1), MIN(jte+1,jde+jstag)
DO i = 0, bdyzone-1
dat(ids-i,j) = dat(ids+i,j) ! here, phi(0) = phi(2), etc
ENDDO ! normal b.c symmetry at phi(1)
ENDDO
END IF
ENDIF
ENDIF symmetry_xs
! now the symmetry boundary at xe
symmetry_xe: IF( ( config_flags%symmetric_xe ) .and. &
( ite == ide ) ) THEN
IF ( (variable /= 'u') .and. (variable /= 'x') ) THEN
DO j = MAX(jds,jts-1), MIN(jte+1,jde+jstag)
DO i = 1, bdyzone
dat(ide+i-1,j) = dat(ide-i,j) ! sym. about dat(ide-0.5)
ENDDO
ENDDO
ELSE
IF (variable == 'u' ) THEN
DO j = MAX(jds,jts-1), MIN(jte+1,jde+jstag)
DO i = 0, bdyzone-1
dat(ide+i,j) = - dat(ide-i,j) ! u(ide+1) = - u(ide-1), etc.
ENDDO
ENDDO
ELSE
DO j = MAX(jds,jts-1), MIN(jte+1,jde+jstag)
DO i = 0, bdyzone-1
dat(ide+i,j) = dat(ide-i,j) ! phi(ide+1) = phi(ide-1), etc.
ENDDO
ENDDO
END IF
END IF
END IF symmetry_xe
! set open b.c in X copy into boundary zone here. WCS, 19 March 2000
open_xs: IF( ( config_flags%open_xs .or. &
config_flags%specified .or. &
config_flags%nested ) .and. &
( its == ids ) .and. open_bc_copy ) THEN
DO j = MAX(jds,jts-1), MIN(jte+1,jde+jstag)
dat(ids-1,j) = dat(ids,j) ! here, dat(0) = dat(1)
dat(ids-2,j) = dat(ids,j)
dat(ids-3,j) = dat(ids,j)
ENDDO
ENDIF open_xs
! now the open boundary copy at xe
open_xe: IF( ( config_flags%open_xe .or. &
config_flags%specified .or. &
config_flags%nested ) .and. &
( ite == ide ) .and. open_bc_copy ) THEN
IF ( variable /= 'u' .and. variable /= 'x') THEN
DO j = MAX(jds,jts-1), MIN(jte+1,jde+jstag)
dat(ide ,j) = dat(ide-1,j)
dat(ide+1,j) = dat(ide-1,j)
dat(ide+2,j) = dat(ide-1,j)
ENDDO
ELSE
DO j = MAX(jds,jts-1), MIN(jte+1,jde+jstag)
dat(ide+1,j) = dat(ide,j)
dat(ide+2,j) = dat(ide,j)
dat(ide+3,j) = dat(ide,j)
ENDDO
END IF
END IF open_xe
! end open b.c in X copy into boundary zone addition. WCS, 19 March 2000
END IF periodicity_x
! same procedure in y
! Set the starting and ending loop indexes in the 'i' direction, so that
! halo cells on the edge of the domain are also updated. Begin with a default
! start and end index for inner tiles, and then modify if the tile is on the
! edge of the domain.
istart = MAX(ids, its-1)
iend = MIN(ite+1, ide+istag)
IF ( its .eq. ids) THEN
istart = ims
END IF
IF ( ite .eq. ide) THEN
iend = ime
END IF
periodicity_y: IF( ( config_flags%periodic_y ) ) THEN
IF ( ( jds == jps ) .and. ( jde == jpe ) ) THEN ! test of both north and south on processor
IF( jts == jds ) then
DO j = 0, -(bdyzone-1), -1
!DO i = MAX(ids,its-1), MIN(ite+1,ide+istag)
DO i = istart, iend
dat(i,jds+j-1) = dat(i,jde+j-1)
ENDDO
ENDDO
END IF
IF( jte == jde ) then
DO j = -jstag, bdyzone
!DO i = MAX(ids,its-1), MIN(ite+1,ide+istag)
DO i = istart, iend
dat(i,jde+j+jstag) = dat(i,jds+j+jstag)
ENDDO
ENDDO
END IF
END IF
ELSE
symmetry_ys: IF( ( config_flags%symmetric_ys ) .and. &
( jts == jds) ) THEN
IF ( (variable /= 'v') .and. (variable /= 'y') ) THEN
DO j = 1, bdyzone
!DO i = MAX(ids,its-1), MIN(ite+1,ide+istag)
DO i = istart, iend
dat(i,jds-j) = dat(i,jds+j-1)
ENDDO
ENDDO
ELSE
IF (variable == 'v') THEN
DO j = 1, bdyzone
!DO i = MAX(ids,its-1), MIN(ite+1,ide+istag)
DO i = istart, iend
dat(i,jds-j) = - dat(i,jds+j)
ENDDO
ENDDO
ELSE
DO j = 1, bdyzone
!DO i = MAX(ids,its-1), MIN(ite+1,ide+istag)
DO i = istart, iend
dat(i,jds-j) = dat(i,jds+j)
ENDDO
ENDDO
END IF
ENDIF
ENDIF symmetry_ys
! now the symmetry boundary at ye
symmetry_ye: IF( ( config_flags%symmetric_ye ) .and. &
( jte == jde ) ) THEN
IF ( (variable /= 'v') .and. (variable /= 'y') ) THEN
DO j = 1, bdyzone
!DO i = MAX(ids,its-1), MIN(ite+1,ide+istag)
DO i = istart, iend
dat(i,jde+j-1) = dat(i,jde-j)
ENDDO
ENDDO
ELSE
IF (variable == 'v' ) THEN
DO j = 1, bdyzone
!DO i = MAX(ids,its-1), MIN(ite+1,ide+istag)
DO i = istart, iend
dat(i,jde+j) = - dat(i,jde-j) ! bugfix: changed jds on rhs to jde , JM 20020410
ENDDO
ENDDO
ELSE
DO j = 1, bdyzone
!DO i = MAX(ids,its-1), MIN(ite+1,ide+istag)
DO i = istart, iend
dat(i,jde+j) = dat(i,jde-j)
ENDDO
ENDDO
END IF
ENDIF
END IF symmetry_ye
! set open b.c in Y copy into boundary zone here. WCS, 19 March 2000
open_ys: IF( ( config_flags%open_ys .or. &
config_flags%polar .or. &
config_flags%specified .or. &
config_flags%nested ) .and. &
( jts == jds) .and. open_bc_copy ) THEN
!DO i = MAX(ids,its-1), MIN(ite+1,ide+istag)
DO i = istart, iend
dat(i,jds-1) = dat(i,jds)
dat(i,jds-2) = dat(i,jds)
dat(i,jds-3) = dat(i,jds)
ENDDO
ENDIF open_ys
! now the open boundary copy at ye
open_ye: IF( ( config_flags%open_ye .or. &
config_flags%polar .or. &
config_flags%specified .or. &
config_flags%nested ) .and. &
( jte == jde ) .and. open_bc_copy ) THEN
IF (variable /= 'v' .and. variable /= 'y' ) THEN
!DO i = MAX(ids,its-1), MIN(ite+1,ide+istag)
DO i = istart, iend
dat(i,jde ) = dat(i,jde-1)
dat(i,jde+1) = dat(i,jde-1)
dat(i,jde+2) = dat(i,jde-1)
ENDDO
ELSE
!DO i = MAX(ids,its-1), MIN(ite+1,ide+istag)
DO i = istart, iend
dat(i,jde+1) = dat(i,jde)
dat(i,jde+2) = dat(i,jde)
dat(i,jde+3) = dat(i,jde)
ENDDO
ENDIF
END IF open_ye
! end open b.c in Y copy into boundary zone addition. WCS, 19 March 2000
END IF periodicity_y
! fix corners for doubly periodic domains
IF ( config_flags%periodic_x .and. config_flags%periodic_y &
.and. (ids == ips) .and. (ide == ipe) &
.and. (jds == jps) .and. (jde == jpe) ) THEN
IF ( (its == ids) .and. (jts == jds) ) THEN ! lower left corner fill
DO j = 0, -(bdyzone-1), -1
DO i = 0, -(bdyzone-1), -1
dat(ids+i-1,jds+j-1) = dat(ide+i-1,jde+j-1)
ENDDO
ENDDO
END IF
IF ( (ite == ide) .and. (jts == jds) ) THEN ! lower right corner fill
DO j = 0, -(bdyzone-1), -1
DO i = 1, bdyzone
dat(ide+i+istag,jds+j-1) = dat(ids+i+istag,jde+j-1)
ENDDO
ENDDO
END IF
IF ( (ite == ide) .and. (jte == jde) ) THEN ! upper right corner fill
DO j = 1, bdyzone
DO i = 1, bdyzone
dat(ide+i+istag,jde+j+jstag) = dat(ids+i+istag,jds+j+jstag)
ENDDO
ENDDO
END IF
IF ( (its == ids) .and. (jte == jde) ) THEN ! upper left corner fill
DO j = 1, bdyzone
DO i = 0, -(bdyzone-1), -1
dat(ids+i-1,jde+j+jstag) = dat(ide+i-1,jds+j+jstag)
ENDDO
ENDDO
END IF
END IF
END SUBROUTINE set_physical_bc2d
!-----------------------------------
SUBROUTINE set_physical_bc3d( dat, variable_in, &
config_flags, &
ids,ide, jds,jde, kds,kde, & ! domain dims
ims,ime, jms,jme, kms,kme, & ! memory dims
ips,ipe, jps,jpe, kps,kpe, & ! patch dims
its,ite, jts,jte, kts,kte )
! This subroutine sets the data in the boundary region, by direct
! assignment if possible, for periodic and symmetric (wall)
! boundary conditions. Currently, we are only doing 1 variable
! at a time - lots of overhead, so maybe this routine can be easily
! inlined later or we could pass multiple variables -
! would probably want a largestep and smallstep version.
! 15 Jan 99, Dave
! Modified the incoming its,ite,jts,jte to truly be the tile size.
! This required modifying the loop limits when the "istag" or "jstag"
! is used, as this is only required at the end of the domain.
IMPLICIT NONE
INTEGER, INTENT(IN ) :: ids,ide, jds,jde, kds,kde
INTEGER, INTENT(IN ) :: ims,ime, jms,jme, kms,kme
INTEGER, INTENT(IN ) :: ips,ipe, jps,jpe, kps,kpe
INTEGER, INTENT(IN ) :: its,ite, jts,jte, kts,kte
CHARACTER, INTENT(IN ) :: variable_in
CHARACTER :: variable
REAL, DIMENSION( ims:ime , kms:kme , jms:jme ) :: dat
TYPE( grid_config_rec_type ) config_flags
INTEGER :: i, j, k, istag, jstag, itime, k_end, &
i_start, i_end
LOGICAL :: debug, open_bc_copy
!------------
debug = .false.
open_bc_copy = .false.
variable = variable_in
IF ( variable_in .ge. 'A' .and. variable_in .le. 'Z' ) THEN
variable = CHAR( ICHAR(variable_in) - ICHAR('A') + ICHAR('a') )
ENDIF
IF ((variable == 'u') .or. (variable == 'v') .or. &
(variable == 'w') .or. (variable == 't') .or. &
(variable == 'd') .or. (variable == 'e') .or. &
(variable == 'x') .or. (variable == 'y') .or. &
(variable == 'f') .or. (variable == 'r') .or. &
(variable == 'p') ) open_bc_copy = .true.
! begin, first set a staggering variable
istag = -1
jstag = -1
k_end = max(1,min(kde-1,kte))
IF ((variable == 'u') .or. (variable == 'x')) istag = 0
IF ((variable == 'v') .or. (variable == 'y')) jstag = 0
IF ((variable == 'd') .or. (variable == 'xy')) then
istag = 0
jstag = 0
ENDIF
IF ((variable == 'e') ) then
istag = 0
k_end = min(kde,kte)
ENDIF
IF ((variable == 'f') ) then
jstag = 0
k_end = min(kde,kte)
ENDIF
IF ( variable == 'w') k_end = min(kde,kte)
! k_end = kte
if(debug) then
write(6,*) ' in bc, var is ',variable, istag, jstag, kte, k_end
write(6,*) ' b.cs are ', &
config_flags%periodic_x, &
config_flags%periodic_y
end if
! periodic conditions.
! note, patch must cover full range in periodic dir, or else
! its intra-patch communication that is handled elsewheres.
! symmetry conditions can always be handled here, because no
! outside patch communication is needed
periodicity_x: IF( ( config_flags%periodic_x ) ) THEN
IF ( ( ids == ips ) .and. ( ide == ipe ) ) THEN ! test if both east and west on-processor
IF ( its == ids ) THEN
DO j = MAX(jds,jts-1), MIN(jte+1,jde+jstag)
DO k = kts, k_end
DO i = 0,-(bdyzone-1),-1
dat(ids+i-1,k,j) = dat(ide+i-1,k,j)
ENDDO
ENDDO
ENDDO
ENDIF
IF ( ite == ide ) THEN
DO j = MAX(jds,jts-1), MIN(jte+1,jde+jstag)
DO k = kts, k_end
DO i = -istag , bdyzone
dat(ide+i+istag,k,j) = dat(ids+i+istag,k,j)
ENDDO
ENDDO
ENDDO
ENDIF
ENDIF
ELSE
symmetry_xs: IF( ( config_flags%symmetric_xs ) .and. &
( its == ids ) ) THEN
IF ( istag == -1 ) THEN
DO j = MAX(jds,jts-1), MIN(jte+1,jde+jstag)
DO k = kts, k_end
DO i = 1, bdyzone
dat(ids-i,k,j) = dat(ids+i-1,k,j) ! here, dat(0) = dat(1), etc
ENDDO ! symmetry about dat(0.5) (u = 0 pt)
ENDDO
ENDDO
ELSE
IF ( variable == 'u' ) THEN
DO j = MAX(jds,jts-1), MIN(jte+1,jde+jstag)
DO k = kts, k_end
DO i = 1, bdyzone
dat(ids-i,k,j) = - dat(ids+i,k,j) ! here, u(0) = - u(2), etc
ENDDO ! normal b.c symmetry at u(1)
ENDDO
ENDDO
ELSE
DO j = MAX(jds,jts-1), MIN(jte+1,jde+jstag)
DO k = kts, k_end
DO i = 1, bdyzone
dat(ids-i,k,j) = dat(ids+i,k,j) ! here, phi(0) = phi(2), etc
ENDDO ! normal b.c symmetry at phi(1)
ENDDO
ENDDO
END IF
ENDIF
ENDIF symmetry_xs
! now the symmetry boundary at xe
symmetry_xe: IF( ( config_flags%symmetric_xe ) .and. &
( ite == ide ) ) THEN
IF ( istag == -1 ) THEN
DO j = MAX(jds,jts-1), MIN(jte+1,jde+jstag)
DO k = kts, k_end
DO i = 1, bdyzone
dat(ide+i-1,k,j) = dat(ide-i,k,j) ! sym. about dat(ide-0.5)
ENDDO
ENDDO
ENDDO
ELSE
IF (variable == 'u') THEN
DO j = MAX(jds,jts-1), MIN(jte+1,jde+jstag)
DO k = kts, k_end
DO i = 1, bdyzone
dat(ide+i,k,j) = - dat(ide-i,k,j) ! u(ide+1) = - u(ide-1), etc.
ENDDO
ENDDO
ENDDO
ELSE
DO j = MAX(jds,jts-1), MIN(jte+1,jde+jstag)
DO k = kts, k_end
DO i = 1, bdyzone
dat(ide+i,k,j) = dat(ide-i,k,j) ! phi(ide+1) = - phi(ide-1), etc.
ENDDO
ENDDO
ENDDO
END IF
END IF
END IF symmetry_xe
! set open b.c in X copy into boundary zone here. WCS, 19 March 2000
open_xs: IF( ( config_flags%open_xs .or. &
config_flags%specified .or. &
config_flags%nested ) .and. &
( its == ids ) .and. open_bc_copy ) THEN
DO j = jts-bdyzone, MIN(jte,jde+jstag)+bdyzone
#if defined(INTEL_ALIGN64)
!DEC$ ASSUME_ALIGNED dat:64
!DEC$ UNROLL(4)
!DEC$ IVDEP
#endif
DO k = kts, k_end
dat(ids-1,k,j) = dat(ids,k,j) ! here, dat(0) = dat(1), etc
dat(ids-2,k,j) = dat(ids,k,j)
dat(ids-3,k,j) = dat(ids,k,j)
ENDDO
ENDDO
ENDIF open_xs
! now the open_xe boundary copy
open_xe: IF( ( config_flags%open_xe .or. &
config_flags%specified .or. &
config_flags%nested ) .and. &
( ite == ide ) .and. open_bc_copy ) THEN
IF (variable /= 'u' .and. variable /= 'x' ) THEN
DO j = jts-bdyzone, MIN(jte,jde+jstag)+bdyzone
#if defined(INTEL_ALIGN64)
!DEC$ ASSUME_ALIGNED dat:64
!DEC$ UNROLL(4)
!DEC$ IVDEP
#endif
DO k = kts, k_end
dat(ide ,k,j) = dat(ide-1,k,j)
dat(ide+1,k,j) = dat(ide-1,k,j)
dat(ide+2,k,j) = dat(ide-1,k,j)
ENDDO
ENDDO
ELSE
!!!!!!! I am not sure about this one! JM 20020402
DO j = MAX(jds,jts-1)-bdyzone, MIN(jte+1,jde+jstag)+bdyzone
DO k = kts, k_end
dat(ide+1,k,j) = dat(ide,k,j)
dat(ide+2,k,j) = dat(ide,k,j)
dat(ide+3,k,j) = dat(ide,k,j)
ENDDO
ENDDO
END IF
END IF open_xe
! end open b.c in X copy into boundary zone addition. WCS, 19 March 2000
END IF periodicity_x
! same procedure in y
! Set the starting and ending loop indexes in the 'i' direction, so that
! halo cells on the edge of the domain are also updated. Begin with a default
! start and end index for inner tiles, and then modify if the tile is on the
! edge of the domain.
i_start = MAX(ids, its-1)
i_end = MIN(ite+1, ide+istag)
IF ( its .eq. ids) THEN
i_start = ims
END IF
IF ( ite .eq. ide) THEN
i_end = ime
END IF
periodicity_y: IF( ( config_flags%periodic_y ) ) THEN
IF ( ( jds == jps ) .and. ( jde == jpe ) ) THEN ! test if both north and south on processor
IF( jts == jds ) then
DO j = 0, -(bdyzone-1), -1
DO k = kts, k_end
DO i = i_start, i_end
dat(i,k,jds+j-1) = dat(i,k,jde+j-1)
ENDDO
ENDDO
ENDDO
END IF
IF( jte == jde ) then
DO j = -jstag, bdyzone
DO k = kts, k_end
DO i = i_start, i_end
dat(i,k,jde+j+jstag) = dat(i,k,jds+j+jstag)
ENDDO
ENDDO
ENDDO
END IF
END IF
ELSE
symmetry_ys: IF( ( config_flags%symmetric_ys ) .and. &
( jts == jds) ) THEN
IF ( jstag == -1 ) THEN
DO j = 1, bdyzone
DO k = kts, k_end
DO i = i_start, i_end
dat(i,k,jds-j) = dat(i,k,jds+j-1)
ENDDO
ENDDO
ENDDO
ELSE
IF (variable == 'v') THEN
DO j = 1, bdyzone
DO k = kts, k_end
DO i = i_start, i_end
dat(i,k,jds-j) = - dat(i,k,jds+j)
ENDDO
ENDDO
ENDDO
ELSE