-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcouple2swan.F
1266 lines (1106 loc) · 47.4 KB
/
couple2swan.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-----------------------------------------------------------------------
C-----------------------------------------------------------------------
MODULE Couple2Swan
C-----------------------------------------------------------------------
C-----------------------------------------------------------------------
USE SIZES, ONLY: SZ
USE WRITE_OUTPUT, ONLY : terminate
USE GLOBAL, ONLY : DEBUG, ECHO, INFO, WARNING, ERROR,
& setMessageSource, unsetMessageSource, allMessage,
& scratchMessage
#ifdef CSWAN
USE SWCOMM1, ONLY: NMOVAR
IMPLICIT NONE
Casey 090302: The coupling interval controls how ADCIRC and SWAN
C take turns during the simulation. It is set
C at the end of PADCSWAN_INIT.
INTEGER :: CouplingInterval
INTEGER,SAVE :: SwanTimeStep ! Counter for SWAN time steps.
Casey 090302: These logical variables will be reset to .TRUE.
C if the water levels in SWAN are coupled to ADCIRC.
LOGICAL :: COUPCUR
LOGICAL :: COUPWIND
LOGICAL :: COUPWLV
Casey 091216: Added another coupling variable.
LOGICAL :: COUPFRIC
Casey 090302: These arrays contain the radiation stresses.
Casey 090820: Be explicit about the size of these REAL variables.
REAL(4) ,ALLOCATABLE :: ADCIRC_SXX(:,:)
REAL(4) ,ALLOCATABLE :: ADCIRC_SXY(:,:)
REAL(4) ,ALLOCATABLE :: ADCIRC_SYY(:,:)
Casey 090302: The interpolation weight controls which value
C is taken when information is passed between ADCIRC
C and SWAN. If InterpoWeight = 0, then the value
C is taken from the beginning of the coupling interval.
C If InterpoWeight = 1, then the value is taken from
C the end of the coupling interval.
REAL(SZ) :: InterpoWeight
Casey 090302: The following arrays will contain the ADCIRC values
C that may be passed to SWAN.
REAL(SZ),ALLOCATABLE :: SWAN_ETA2(:,:)
REAL(SZ),ALLOCATABLE :: SWAN_UU2(:,:)
REAL(SZ),ALLOCATABLE :: SWAN_VV2(:,:)
REAL(SZ),ALLOCATABLE :: SWAN_WX2(:,:)
REAL(SZ),ALLOCATABLE :: SWAN_WY2(:,:)
Casey 091216: Added another array.
REAL(SZ),ALLOCATABLE :: SWAN_Z0(:,:)
Casey 090302: These variables control SWAN output.
! jgf51.21.25: Added target attribute to file position counters
! so that they could be pointed to from the OutputDataDescript_t
! for each output type and updated in subroutine writeOutArray in
! the write_output module.
INTEGER, ALLOCATABLE, TARGET :: IGSW(:) ! file position counters
INTEGER :: NumSwanOutput
LOGICAL :: Processed26 = .FALSE.
LOGICAL :: SWAN_OQPROC(NMOVAR)
INTEGER :: SWAN_VOQR(NMOVAR)
Casey 090303: Add variable for maximum SWAN output.
REAL(SZ),ALLOCATABLE :: SWAN_MAX(:,:)
REAL(SZ),ALLOCATABLE,TARGET :: SWAN_MAXTEMP(:)
REAL(SZ),ALLOCATABLE,TARGET :: SWAN_MAXTEMP_G(:) !...Cobell added
Casey 100205: Add variables for writing of SWAN hot-start files.
INTEGER :: SwanHotStartUnit
LOGICAL :: WriteSwanHotStart = .FALSE.
Casey 120302: Merging ice changes from Taylor Asher.
CTGA 110912: Implementing SWAN ice handling. This variable is set to
C 0 wherever ice reaches/exceeds a threshold value
INTEGER,ALLOCATABLE :: ICY(:)
REAL(SZ),ALLOCATABLE :: SWAN_CICE2(:,:)
C-----------------------------------------------------------------------
CONTAINS
C-----------------------------------------------------------------------
C-----------------------------------------------------------------------
C S U B R O U T I N E
C C O M P U T E R A D I A T I O N S T R E S S E S
C-----------------------------------------------------------------------
C-----------------------------------------------------------------------
SUBROUTINE ComputeRadiationStresses(AC2,SPCDIR,SPCSIG)
!Casey 090616: On Jade, there was a problem with getting water depths
! from the COMPDA array. Use ETA2 and DEPTH instead.
USE GLOBAL, ONLY : ETA2
USE M_GENARR, ONLY : DEPTH
USE SwanGridData, ONLY : nverts
USE SWCOMM3, ONLY : DDIR, DEPMIN, FRINTF, GRAV, MDC, MSC
IMPLICIT NONE
!Casey 090616: These REAL variables must be size(4) to match SWAN.
REAL(4) :: AC2(MDC,MSC,nverts)
INTEGER :: IT
REAL :: JunkR
REAL(4) :: SPCDIR(MDC,6)
REAL(4) :: SPCSIG(MSC)
INTEGER :: I, ID, IERR, IS
REAL(4) :: DEPLOC
REAL(4) :: WK(MSC), CG(MSC), NE(MSC), NED(MSC)
call setMessageSource("ComputeRadiationStresses")
#if defined(COUPLE2SWAN_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Enter.")
#endif
!... (Re)allocate the arrays.
IF(.NOT.ALLOCATED(ADCIRC_SXX))THEN
ALLOCATE(ADCIRC_SXX(1:nverts,1:2),STAT=IERR)
DO I=1,nverts
ADCIRC_SXX(I,1) = 0.0
ADCIRC_SXX(I,2) = 0.0
ENDDO
ENDIF
IF(.NOT.ALLOCATED(ADCIRC_SXY))THEN
ALLOCATE(ADCIRC_SXY(1:nverts,1:2))
DO I=1,nverts
ADCIRC_SXY(I,1) = 0.0
ADCIRC_SXY(I,2) = 0.0
ENDDO
ENDIF
IF(.NOT.ALLOCATED(ADCIRC_SYY))THEN
ALLOCATE(ADCIRC_SYY(1:nverts,1:2))
DO I=1,nverts
ADCIRC_SYY(I,1) = 0.0
ADCIRC_SYY(I,2) = 0.0
ENDDO
ENDIF
!... Loop over the nodes and compute radiation stresses.
DO I=1,nverts
!... Transfer the stresses from the new time level to the old time level.
ADCIRC_SXX(I,1) = ADCIRC_SXX(I,2)
ADCIRC_SXY(I,1) = ADCIRC_SXY(I,2)
ADCIRC_SYY(I,1) = ADCIRC_SYY(I,2)
!... Initialize the radiation stresses as zero at all of the nodes.
ADCIRC_SXX(I,2) = 0.0
ADCIRC_SXY(I,2) = 0.0
ADCIRC_SYY(I,2) = 0.0
!... Compute ratio of group and phase velocity.
DEPLOC = DEPTH(I) + ETA2(I)
IF(DEPLOC.LE.DEPMIN)THEN
CYCLE
ENDIF
CALL KSCIP1(MSC, SPCSIG, DEPLOC, WK, CG, NE, NED)
!... Loop over all sigma and theta.
DO ID=1,MDC
DO IS=1,MSC
!... Sum contributions to radiation stresses.
ADCIRC_SXX(I,2) = ADCIRC_SXX(I,2)
& + (NE(IS) * SPCDIR(ID,4) + NE(IS) - 0.5)
& * SPCSIG(IS) * SPCSIG(IS) * AC2(ID,IS,I)
ADCIRC_SXY(I,2) = ADCIRC_SXY(I,2)
& + NE(IS) * SPCDIR(ID,5)
& * SPCSIG(IS) * SPCSIG(IS) * AC2(ID,IS,I)
ADCIRC_SYY(I,2) = ADCIRC_SYY(I,2)
& + (NE(IS) * SPCDIR(ID,6) + NE(IS) - 0.5)
& * SPCSIG(IS) * SPCSIG(IS) * AC2(ID,IS,I)
ENDDO
ENDDO
!... Multiply summed radiation stresses by the stuff outside of the sums.
!Casey 080602: ADCIRC accepts wave-driven stresses "in units of velocity squared
! (consistent with the units of gravity). Stress in these units is obtained
! by dividing stress in units of force/area by the reference density of water."
! SO WE MUST DIVIDE BY RHO! (WJP: just ommitted RHO multiple in this
! line to avoid the division by RHO below)
ADCIRC_SXX(I,2) = GRAV * ADCIRC_SXX(I,2) * DDIR * FRINTF
ADCIRC_SXY(I,2) = GRAV * ADCIRC_SXY(I,2) * DDIR * FRINTF
ADCIRC_SYY(I,2) = GRAV * ADCIRC_SYY(I,2) * DDIR * FRINTF
!... End loop over wet nodes. The radiation stresses are ready for ADCIRC.
ENDDO
#if defined(COUPLE2SWAN_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Return.")
#endif
call unsetMessageSource()
RETURN
C-----------------------------------------------------------------------
END SUBROUTINE ComputeRadiationStresses
C-----------------------------------------------------------------------
C-----------------------------------------------------------------------
C S U B R O U T I N E
C C O M P U T E W A V E D R I V E N F O R C E S
C-----------------------------------------------------------------------
C-----------------------------------------------------------------------
SUBROUTINE ComputeWaveDrivenForces
USE GLOBAL, ONLY: NODECODE, NOFF, RSNX2, RSNY2, IFSFM
USE SIZES, ONLY: SZ
USE MESH, ONLY : NE, NM, NP, AREAS, NODELE, NEITABELE,
& FDXE, FDYE, SFacEle, SFMYEle, SFMXEle
USE BOUNDARIES, ONLY : NBDV, NBOU, NBVV, NOPE, NVDLL, NVELL
IMPLICIT NONE
INTEGER :: I
INTEGER :: IE
INTEGER :: IP
INTEGER :: K
INTEGER :: Node1
INTEGER :: Node2
INTEGER :: Node3
INTEGER :: NUMFOUND
!... To zero out forces on boundary/dry nodes
#ifdef MARCELSWAN
LOGICAL :: Marcel = .true.
#else
LOGICAL :: Marcel = .false.
#endif
REAL(SZ),ALLOCATABLE :: DSXXDX(:)
REAL(SZ),ALLOCATABLE :: DSXYDY(:)
REAL(SZ),ALLOCATABLE :: DSXYDX(:)
REAL(SZ),ALLOCATABLE :: DSYYDY(:)
REAL(SZ) :: NCELE
REAL(SZ),ALLOCATABLE :: TEMP_SXX(:)
REAL(SZ),ALLOCATABLE :: TEMP_SXY(:)
REAL(SZ),ALLOCATABLE :: TEMP_SYY(:)
REAL(SZ) :: TOTALAREA
REAL(SZ) :: FDX1, FDX2, FDX3
REAL(SZ) :: FDY1, FDY2, FDY3
REAL(SZ) :: SFacAvg, SFmxAvg, SFmyAvg, sfdxfac, sfdyfac
! Upper limit on Radiation stresses
! Default - don't limit (set to high value) but may want to use: UL = 0.1_SZ
! (0.1 m^2/s^2 is equivalent to 175 m/s wind speeds!)
REAL(SZ),parameter :: UL = 999_SZ
call setMessageSource("ComputeWaveDrivenForces")
#if defined(COUPLE2SWAN_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Enter.")
#endif
!... Check whether radiation stresses have already been computed.
!... If not, then apply forces of zero.
IF( .FALSE. )THEN
IF(.NOT.ALLOCATED(RSNX2))THEN
ALLOCATE(RSNX2(1:NP))
DO IP=1,NP
RSNX2(IP) = 0.D0
ENDDO
ENDIF
IF(.NOT.ALLOCATED(RSNY2))THEN
ALLOCATE(RSNY2(1:NP))
DO IP=1,NP
RSNY2(IP) = 0.D0
ENDDO
ENDIF
!... If so, then continue to compute wave-driven forces.
ELSE
!... Allocate arrays for radiation stresses.
IF(.NOT.ALLOCATED(TEMP_SXX)) ALLOCATE(TEMP_SXX(1:NP))
IF(.NOT.ALLOCATED(TEMP_SXY)) ALLOCATE(TEMP_SXY(1:NP))
IF(.NOT.ALLOCATED(TEMP_SYY)) ALLOCATE(TEMP_SYY(1:NP))
!... Loop over all nodes and interpolate the radiation stress for this time step.
DO IP=1,NP
TEMP_SXX(IP) = (1.0 - InterpoWeight) * DBLE(ADCIRC_SXX(IP,1))
& + InterpoWeight * DBLE(ADCIRC_SXX(IP,2))
TEMP_SXY(IP) = (1.0 - InterpoWeight) * DBLE(ADCIRC_SXY(IP,1))
& + InterpoWeight * DBLE(ADCIRC_SXY(IP,2))
TEMP_SYY(IP) = (1.0 - InterpoWeight) * DBLE(ADCIRC_SYY(IP,1))
& + InterpoWeight * DBLE(ADCIRC_SYY(IP,2))
ENDDO
!... Allocate arrays for radiation stress gradients.
IF(.NOT.ALLOCATED(DSXXDX)) ALLOCATE(DSXXDX(1:NE))
IF(.NOT.ALLOCATED(DSXYDY)) ALLOCATE(DSXYDY(1:NE))
IF(.NOT.ALLOCATED(DSXYDX)) ALLOCATE(DSXYDX(1:NE))
IF(.NOT.ALLOCATED(DSYYDY)) ALLOCATE(DSYYDY(1:NE))
!... Loop over all elements and compute the derivatives of Sxx, Sxy and Syy.
!... These derivatives are constant on an element. Note that the AREAS array
!... actually contains twice the area of each element.
DO IE=1,NE
!Casey 090707: When using the serial adcswan on Zas, I received memory errors
!... when these calls were nested into the logic below. Break them out and
!... use these variables to save on the number of calls to memory.
Node1 = NM(IE,1)
Node2 = NM(IE,2)
Node3 = NM(IE,3)
C WJP: tke into account correction factors
SFacAvg = SFacEle(IE)
C..... BEG DW/WJP
SFmxAvg= SFMXEle(IE) ;
SFmyAvg= SFMYEle(IE) ;
sfdxfac = (1 - IFSFM)*SFacAvg + IFSFM*SFmxAvg ;
sfdyfac = (1 - IFSFM)*1.0_SZ + IFSFM*SFmyAvg ;
FDX1 = FDXE(1,IE)*sfdxfac ; !c FDX1=(Y(NM2)-Y(NM3))*MX !b1*mx
FDX2 = FDXE(2,IE)*sfdxfac ; !c FDX2=(Y(NM3)-Y(NM1))*MX !b2*mx
FDX3 = FDXE(3,IE)*sfdxfac ; !c FDX3=(Y(NM1)-Y(NM2))*MX !b3*mx
FDY1 = FDYE(1,IE)*sfdyfac ; !c FDY1=(X(NM3)-X(NM2))*MY !a1*my
FDY2 = FDYE(2,IE)*sfdyfac ; !c FDY2=(X(NM1)-X(NM3))*MY !a2*my
FDY3 = FDYE(3,IE)*sfdyfac ; !c FDY3=(X(NM2)-X(NM1))*MY !a3*my
C..... END DW/WJP
DSXXDX(IE) = (1.D0/AREAS(IE)) *
& ( TEMP_SXX(Node1) * FDX1 !(Y(Node2) - Y(Node3))
& + TEMP_SXX(Node2) * FDX2 !(Y(Node3) - Y(Node1))
& + TEMP_SXX(Node3) * FDX3 ) !(Y(Node1) - Y(Node2)) )
DSXYDY(IE) = (1.D0/AREAS(IE)) *
& ( TEMP_SXY(Node1) * FDY1 !(X(Node3) - X(Node2))
& + TEMP_SXY(Node2) * FDY2 !(X(Node1) - X(Node3))
& + TEMP_SXY(Node3) * FDY3 ) !(X(Node2) - X(Node1)) )
DSXYDX(IE) = (1.D0/AREAS(IE)) *
& ( TEMP_SXY(Node1) * FDX1 !(Y(Node2) - Y(Node3))
& + TEMP_SXY(Node2) * FDX2 !(Y(Node3) - Y(Node1))
& + TEMP_SXY(Node3) * FDX3 ) !(Y(Node1) - Y(Node2)) )
DSYYDY(IE) = (1.D0/AREAS(IE)) *
& ( TEMP_SYY(Node1) * FDY1 !(X(Node3) - X(Node2))
& + TEMP_SYY(Node2) * FDY2 !(X(Node1) - X(Node3))
& + TEMP_SYY(Node3) * FDY3 ) !(X(Node2) - X(Node1)) )
ENDDO
!... Allocate arrays for wave-driven forces.
IF(.NOT.ALLOCATED(RSNX2)) ALLOCATE(RSNX2(1:NP))
IF(.NOT.ALLOCATED(RSNY2)) ALLOCATE(RSNY2(1:NP))
!... Loop over all nodes and compute the wave-driven forces:
!...
!... Fx = - DSxx/Dx - DSxy/Dy
!...
!... Fy = - DSxy/Dx - DSyy/Dy
!...
!... We project the element-based radiation stress gradients onto the nodes
!... by taking a weighted average of the gradients in the elements connected
!... to a node.
outer: DO IP=1,NP
RSNX2(IP) = 0.D0
RSNY2(IP) = 0.D0
TOTALAREA = 0.D0
IE = 0
NUMFOUND = 0
inner: DO
IE = IE + 1
IF(NEITABELE(IP,IE).EQ.0)THEN
CONTINUE
ELSE
!... Try Marcel's method of zero-ing out the forces at nodes connected to dry nodes/elements.
NCELE = NODECODE(NM(NEITABELE(IP,IE),1))
& * NODECODE(NM(NEITABELE(IP,IE),2))
& * NODECODE(NM(NEITABELE(IP,IE),3))
& * NOFF( NEITABELE(IP,IE) )
IF(Marcel.AND.(NCELE.EQ.0))THEN
RSNX2(IP) = 0.0d0
RSNY2(IP) = 0.0d0
CYCLE outer
ELSE
NUMFOUND = NUMFOUND + 1
RSNX2(IP) = RSNX2(IP) + 0.5d0*AREAS(NEITABELE(IP,IE))
& * ( - DSXXDX(NEITABELE(IP,IE))
& - DSXYDY(NEITABELE(IP,IE)) )
RSNY2(IP) = RSNY2(IP) + 0.5d0*AREAS(NEITABELE(IP,IE))
& * ( - DSXYDX(NEITABELE(IP,IE))
& - DSYYDY(NEITABELE(IP,IE)) )
TOTALAREA = TOTALAREA + 0.5d0*AREAS(NEITABELE(IP,IE))
ENDIF
ENDIF
IF(NUMFOUND.EQ.NODELE(IP))THEN
EXIT inner
ENDIF
ENDDO inner
RSNX2(IP) = RSNX2(IP) / TOTALAREA
RSNY2(IP) = RSNY2(IP) / TOTALAREA
C WJPs artifical limiter; UL is to a really large by default, user
C can change UL to be a strict value if they please
RSNX2(IP) = min(UL,max(-UL,RSNX2(IP)))
RSNY2(IP) = min(UL,max(-UL,RSNY2(IP)))
ENDDO outer
!... Try Marcel's method of zero-ing the forces at the boundary nodes.
IF(Marcel)THEN
DO K=1,NOPE
DO I=1,NVDLL(K)
RSNX2(NBDV(K,I)) = 0.0d0
RSNY2(NBDV(K,I)) = 0.0d0
ENDDO
ENDDO
DO K=1,NBOU
DO I=1,NVELL(K)
RSNX2(NBVV(K,I)) = 0.0d0
RSNY2(NBVV(K,I)) = 0.0d0
ENDDO
ENDDO
ENDIF
!... Deallocate the radiation stress gradients.
IF(ALLOCATED(DSXXDX)) DEALLOCATE(DSXXDX)
IF(ALLOCATED(DSXYDY)) DEALLOCATE(DSXYDY)
IF(ALLOCATED(DSXYDX)) DEALLOCATE(DSXYDX)
IF(ALLOCATED(DSYYDY)) DEALLOCATE(DSYYDY)
IF(ALLOCATED(TEMP_SXX)) DEALLOCATE(TEMP_SXX)
IF(ALLOCATED(TEMP_SXY)) DEALLOCATE(TEMP_SXY)
IF(ALLOCATED(TEMP_SYY)) DEALLOCATE(TEMP_SYY)
ENDIF
#if defined(COUPLE2SWAN_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Return.")
#endif
call unsetMessageSource()
RETURN
C-----------------------------------------------------------------------
END SUBROUTINE ComputeWaveDrivenForces
C-----------------------------------------------------------------------
C-----------------------------------------------------------------------
C S U B R O U T I N E
C C O M P U T E S W A N W I N D D R A G
C-----------------------------------------------------------------------
C @mattbilskie
C-----------------------------------------------------------------------
SUBROUTINE ComputeSwanWindDrag(CDRAG,NodeNumber)
USE GLOBAL, ONLY: NP_G, SWAN_WDragCo
IMPLICIT NONE
REAL(4) :: CDRAG
INTEGER :: NodeNumber
IF(.NOT.ALLOCATED(SWAN_WDragCo)) ALLOCATE(SWAN_WDragCo(NP_G))
SWAN_WDragCo(NodeNumber) = CDRAG
C-----------------------------------------------------------------------
END SUBROUTINE ComputeSwanWindDrag
C-----------------------------------------------------------------------
C-----------------------------------------------------------------------
C S U B R O U T I N E M A N N I N G 2 M A D S E N
C-----------------------------------------------------------------------
Casey 091216: This routine will convert the ADCIRC Manning's n values
C into roughness lengths that can be used with the Madsen
C friction formulation inside SWAN.
C-----------------------------------------------------------------------
SUBROUTINE Manning2Madsen
USE GLOBAL, ONLY: G
USE MESH, ONLY : NP, DP
USE NodalAttributes,ONLY: ManningsN
IMPLICIT NONE
INTEGER :: IN
REAL(SZ) :: H
REAL(SZ) :: K = 0.4D0
REAL(SZ) :: N
REAL(SZ) :: Z0
call setMessageSource("Manning2Madsen")
#if defined(COUPLE2SWAN_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Enter.")
#endif
DO IN=1,NP
H = SWAN_ETA2(IN,2) + DP(IN)
N = ManningsN(IN)
Casey 110518: Enforce a lower limit on the Manning's n seen by SWAN.
IF(N.LT.0.02D0) N = 0.02D0
Z0 = ( H ) * EXP( -1.D0 * ( 1.D0 + K * H**(1.D0/6.D0)
& / ( N * SQRT(G) ) ) )
Casey 091216: If we get a junk number, then use the default value.
IF(Z0.LE.0.D0)THEN
Z0 = 0.05D0
ENDIF
SWAN_Z0(IN,2) = Z0
ENDDO
#if defined(COUPLE2SWAN_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Return.")
#endif
call unsetMessageSource()
C-----------------------------------------------------------------------
END SUBROUTINE Manning2Madsen
C-----------------------------------------------------------------------
C-----------------------------------------------------------------------
C S U B R O U T I N E S W A N O U T P U T
C-----------------------------------------------------------------------
C-----------------------------------------------------------------------
SUBROUTINE SwanOutput(ITIME, IT)
USE SIZES, ONLY : OFF, ASCII, SPARSE_ASCII, BINARY, NETCDF3,
& NETCDF4, XDMF
USE Couple2Adcirc,ONLY: COMPDA
USE MESH, ONLY : DP, NP, AID4
USE GLOBAL, ONLY:
& NT,
& NP_G,
& NODES_LG,
& DT,
& ETA2,
& NDSETSW,
& NODECODE,
& NOUTGW,
& NSCOUGW,
& NSPOOLGW,
& NTCYSGW,
& NTCYFGW,
& NWS,
& OutputDataDescript_t,
& RDES4,
& RID4,
& UU2,
& VV2,
& DTDP, StaTim,
& h0
#ifdef CSWAN
& ,SWAN_OutputHS,
& SWAN_OutputDIR,
& SWAN_OutputTM01,
& SWAN_OutputTPS,
& SWAN_OutputWIND,
& SWAN_OutputTM02,
& SWAN_OutputTMM10,
& SWAN_OutputAgg,
& Swan_HSOut,Swan_TPSOut,Swan_TM01Out,Swan_DirOut,
& Swan_TMM10Out,Swan_WindXOut,Swan_WindYOut,
& Swan_HSMaxOut,Swan_TPSMaxOut,Swan_TM01MaxOut,
& Swan_TMM10MaxOut,Swan_WindMaxOut,Swan_DirMaxOut,
& Swan_TM02Out,Swan_TM02MaxOut
#endif
USE GLOBAL_IO, ONLY: Header73,
& Header74,
& HEADER_MAX,
& OPEN_GBL_FILE,
& OPEN_MINMAX_FILE,
& PackOne,
& PackTwo,
& StoreOne,
& StoreTwo,
& UnPackOne,
& UnPackTwo
USE M_GENARR, ONLY: AC2,
& KGRPNT,
& SPCDIR,
& SPCSIG
USE SIZES, ONLY: GLOBALDIR,
& LOCALDIR,
& MNPROC,
& MNWPROC,
& NBYTE,
& SZ,
& MYPROC,
& numFormats
USE SwanGriddata, ONLY: nverts,
& xcugrd,
& ycugrd
USE SWCOMM1, ONLY: COSCQ,
& OVEXCV,
& SINCQ
USE SWCOMM2, ONLY: XOFFS,
& YOFFS
USE SWCOMM3, ONLY: MCGRD,
& MDC,
& MSC,
& MTC,
& MXC,
& MYC
#ifdef CMPI
USE WRITER, ONLY: FLUSH_WRITERS,
& NUM_BUF_MAX, !st3 100708: check writer buffer
& sendDataToWriter
USE MESSENGER, ONLY : MSG_FINI, !st3 100708: check writer buffer
& subDomainFatalError
#endif
USE WRITE_OUTPUT, ONLY : SwanHSDescript,SwanDIRDescript,SwanTM01Descript,
& SwanTPSDescript,SwanWindDescript,SwanTM02Descript,
& SwanTMM10Descript,SwanHSMaxDescript,
& SwanDIRMaxDescript,SwanTM01MaxDescript,
& SwanTPSMaxDescript,SwanWindMaxDescript,
& SwanTM02MaxDescript,SwanTMM10MaxDescript,
& OutputDataDescript_t,writeOutArrayMinMax
IMPLICIT NONE
INTRINSIC :: ALLOCATED
INTRINSIC :: INDEX
INTRINSIC :: TRIM
CHARACTER(LEN=15),ALLOCATABLE :: FileName(:)
CHARACTER(LEN=20) :: FileNameMax
CHARACTER(LEN=10),ALLOCATABLE :: Names(:)
CHARACTER(LEN=30) :: TempC
INTEGER :: I
INTEGER :: IO
INTEGER :: IONOD(NP)
INTEGER :: IP
INTEGER :: IS
INTEGER :: IT
INTEGER :: ITIME
INTEGER :: IVTYPE
INTEGER :: IW
INTEGER :: SWAN_BKC
INTEGER,SAVE :: SWAN_MTC
INTEGER :: UnitNumber
INTEGER :: IFileCounter !st3 100708:
INTEGER :: UpdateMax(NP)
LOGICAL :: CROSS(4,NP)
#ifdef ADCNETCDF
LOGICAL :: NETCDF_ERROR(14)
#endif
REAL(8) :: TimeLoc
!Casey 090820: Sapphire doesn't like it if these variables
! are declared as only REAL. They must be declared
! as REAL(4) to interface correctly with the
! SWAN output subroutines.
REAL(4) :: ACLOC(MDC,MSC)
REAL(4) :: DEPXY(NP)
REAL(4) :: FORCE(NP,2)
REAL(4) :: SWAN_CG(MSC)
REAL(4) :: SWAN_NE(MSC)
REAL(4) :: SWAN_NED(MSC)
REAL(4),ALLOCATABLE :: SWAN_VOQ(:,:)
REAL(4) :: SWAN_WK(MSC)
REAL(SZ),POINTER :: SwanOut(:)
REAL(SZ),POINTER :: SwanOut2(:)
REAL(SZ),POINTER :: SwanMaxOut(:)
C REAL(SZ),TARGET :: SwanOut_g(NP_G)
C REAL(SZ),TARGET :: SwanOut2_g(NP_G)
REAL(4) :: XC(NP)
REAL(4) :: YC(NP)
CHARACTER(len=12) :: fileExt ! character string representing integer file extension
TYPE(OutputDataDescript_t),POINTER :: SwanDescript,SwanDescriptMax
call setMessageSource("swanoutput")
#if defined(COUPLE2SWAN_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Enter.")
#endif
!... Initialize the Swan output variables.
DO IO=1,NMOVAR
SWAN_OQPROC(IO) = .FALSE.
ENDDO
NumSwanOutput = 0
!... For significant wave heights (HS).
NumSwanOutput = NumSwanOutput + 1
OVEXCV(10) = -99999.
SWAN_OQPROC(10) = .TRUE.
SWAN_VOQR(10) = 7 + NumSwanOutput
!... For mean wave directions (DIR).
NumSwanOutput = NumSwanOutput + 1
OVEXCV(13) = -99999.
SWAN_OQPROC(13) = .TRUE.
SWAN_VOQR(13) = 7 + NumSwanOutput
!... For mean wave periods (TM01).
NumSwanOutput = NumSwanOutput + 1
OVEXCV(11) = -99999.
SWAN_OQPROC(11) = .TRUE.
SWAN_VOQR(11) = 7 + NumSwanOutput
!... For peak wave periods (TPS).
NumSwanOutput = NumSwanOutput + 1
OVEXCV(53) = -99999.
SWAN_OQPROC(53) = .TRUE.
SWAN_VOQR(53) = 7 + NumSwanOutput
!... For wind speeds (WX2 and WY2).
NumSwanOutput = NumSwanOutput + 1
OVEXCV(26) = 0.
SWAN_OQPROC(26) = .TRUE.
SWAN_VOQR(26) = 7 + NumSwanOutput
!... For mean wave periods (TM02).
NumSwanOutput = NumSwanOutput + 1
OVEXCV(32) = -99999.
SWAN_OQPROC(32) = .TRUE.
SWAN_VOQR(32) = 7 + NumSwanOutput + 1
!... For mean wave periods (TMM10).
NumSwanOutput = NumSwanOutput + 1
OVEXCV(47) = -99999.
SWAN_OQPROC(47) = .TRUE.
SWAN_VOQR(47) = 7 + NumSwanOutput + 1
COSCQ = COS(0.)
SINCQ = SIN(0.)
IF(.NOT.ALLOCATED(IGSW)) ALLOCATE(IGSW(1:NumSwanOutput))
IF(.NOT.ALLOCATED(Names)) ALLOCATE(Names(1:NumSwanOutput))
Names(1) = "HS"
Names(2) = "DIR"
Names(3) = "TM01"
Names(4) = "TPS"
Names(5) = "WIND"
Names(6) = "TM02"
Names(7) = "TMM10"
IF(.NOT.ALLOCATED(FileName)) ALLOCATE(FileName(1:NumSwanOutput))
FileName(1) = "swan_"//TRIM(Names(1))//".63"//" "
FileName(2) = "swan_"//TRIM(Names(2))//".63"//" "
FileName(3) = "swan_"//TRIM(Names(3))//".63"//" "
FileName(4) = "swan_"//TRIM(Names(4))//".63"//" "
FileName(5) = "swan_"//TRIM(Names(5))//".64"//" "
FileName(6) = "swan_"//TRIM(Names(6))//".63"//" "
FileName(7) = "swan_"//TRIM(Names(7))//".63"//" "
IF(.NOT.Processed26)THEN
Cobell 20120510: At first pass, we set up the output data arrays
C.....Arrange on/off for output into array
SWAN_OutputAgg(1) = SWAN_OutputHS
SWAN_OutputAgg(2) = SWAN_OutputDIR
SWAN_OutputAgg(3) = SWAN_OutputTM01
SWAN_OutputAgg(4) = SWAN_OutputTPS
SWAN_OutputAgg(5) = SWAN_OutputWIND
SWAN_OutputAgg(6) = SWAN_OutputTM02
SWAN_OutputAgg(7) = SWAN_OutputTMM10
IF(.NOT.ALLOCATED(SWAN_MAX)) ALLOCATE(SWAN_MAX(1:NP,1:NumSwanOutput))
DO IP=1,nverts
DO IW=1,NumSwanOutput
IF(IW.EQ.1) IVTYPE=10
IF(IW.EQ.2) IVTYPE=13
IF(IW.EQ.3) IVTYPE=11
IF(IW.EQ.4) IVTYPE=53
IF(IW.EQ.5) IVTYPE=26
IF(IW.EQ.6) IVTYPE=32
IF(IW.EQ.7) IVTYPE=47
SWAN_MAX(IP,IW) = OVEXCV(IVTYPE)
ENDDO
ENDDO
!...Open the global output files
DO IW=1,NumSwanOutput
IF(.NOT.SWAN_OutputAgg(IW))CYCLE
UnitNumber = 300 + IW
IF((ABS(NOUTGW).EQ.1).OR.(ABS(NOUTGW).EQ.4))THEN
IF(IW.NE.5)THEN
CALL OPEN_GBL_FILE(UnitNumber,TRIM(GLOBALDIR)//'/'//TRIM(FileName(IW)),
& NP_G,NP,Header73)
ELSE
CALL OPEN_GBL_FILE(UnitNumber,TRIM(GLOBALDIR)//'/'//TRIM(FileName(IW)),
& NP_G,NP,Header74)
ENDIF
ENDIF
ENDDO
Processed26 = .TRUE.
ENDIF
!... I don't know what BKC does. Everything seems to work okay
!... when it is set to two, though.
SWAN_BKC = 2
!... If Swan needs these values for wave numbers, etc.,
!... then maybe it solves for them inside SWOEXA.
DO IS=1,MSC
SWAN_CG(IS) = 0.
SWAN_NE(IS) = 0.
SWAN_NED(IS) = 0.
SWAN_WK(IS) = 0.
ENDDO
!... Allocate VOQ and set up the first seven entries inside it.
IF(.NOT.ALLOCATED(SWAN_VOQ)) ALLOCATE(SWAN_VOQ(1:NP,1:(7+NumSwanOutput+1)))
DO IP=1,nverts
!... X,Y in problem coordinate system.
SWAN_OQPROC(1) = .TRUE.
SWAN_OQPROC(2) = .TRUE.
SWAN_VOQR(1) = 1
SWAN_VOQR(2) = 2
SWAN_VOQ(IP,SWAN_VOQR(1)) = xcugrd(IP)
SWAN_VOQ(IP,SWAN_VOQR(2)) = ycugrd(IP)
!... X,Y in adjusted coordinate system.
SWAN_OQPROC(24) = .TRUE.
SWAN_OQPROC(25) = .TRUE.
SWAN_VOQR(24) = 3
SWAN_VOQR(25) = 4
SWAN_VOQ(IP,SWAN_VOQR(24)) = 0.
SWAN_VOQ(IP,SWAN_VOQR(25)) = 0.
!... Depth of water.
SWAN_OQPROC(4) = .TRUE.
SWAN_VOQR(4) = 5
SWAN_VOQ(IP,SWAN_VOQR(4)) = REAL(DP(IP)) + REAL(ETA2(IP))
!
! jgf51.46: Fix from Casey to eliminate floating point
! exception in SWAN (swanser.F lines 703 and 726) when depths
! are negative.
IF (SWAN_VOQ(IP,SWAN_VOQR(4)).LT.REAL(H0)) THEN
SWAN_VOQ(IP,SWAN_VOQR(4)) = REAL(H0)
ENDIF
!... Water current velocities.
SWAN_OQPROC(5) = .TRUE.
SWAN_VOQR(5) = 6
SWAN_VOQ(IP,SWAN_VOQR(5)) = REAL(UU2(IP))
SWAN_VOQ(IP,SWAN_VOQR(5)+1) = REAL(VV2(IP))
!... Assemble other arrays?
DEPXY(IP) = REAL(DP(IP)) + REAL(ETA2(IP))
XC(IP) = xcugrd(IP)
YC(IP) = ycugrd(IP)
FORCE(IP,1) = 0.
FORCE(IP,2) = 0.
IONOD(IP) = -999
ENDDO
!... Call the Swan subroutine to interpolate internal Swan quantities.
CALL SWOEXD(SWAN_OQPROC, nverts, XC, YC, SWAN_VOQR,
& SWAN_VOQ, COMPDA, KGRPNT, FORCE, CROSS, IONOD, -999)
!... Call the Swan subroutine to compute the output quantities.
CALL SWOEXA(SWAN_OQPROC, SWAN_BKC, nverts, XC, YC,
& SWAN_VOQR, SWAN_VOQ, AC2, ACLOC, SPCSIG,
& SWAN_WK, SWAN_CG, SPCDIR, SWAN_NE, SWAN_NED,
& KGRPNT, DEPXY, CROSS)
UpdateMax = 0
IFileCounter = 0 !st3 100708: counter of file number
DO IW=1,NumSwanOutput
IF(.NOT.SWAN_OutputAgg(IW))CYCLE
UnitNumber = 300 + IW
!... Assign the output variable to our data structure.
IF(IW.EQ.1) IVTYPE=10
IF(IW.EQ.2) IVTYPE=13
IF(IW.EQ.3) IVTYPE=11
IF(IW.EQ.4) IVTYPE=53
IF(IW.EQ.5) IVTYPE=26
IF(IW.EQ.6) IVTYPE=32
IF(IW.EQ.7) IVTYPE=47
DO IP=1,NP
SELECT CASE(IW)
CASE(1)
Swan_HSOut(IP) = DBLE(SWAN_VOQ(IP,SWAN_VOQR(IVTYPE)))
SwanOut => Swan_HSOut
SwanMaxOut => Swan_HSMaxOut
CASE(2)
Swan_DIROut(IP) = DBLE(SWAN_VOQ(IP,SWAN_VOQR(IVTYPE)))
SwanOut => Swan_DIROut
SwanMaxOut => Swan_DIRMaxOut
CASE(3)
Swan_TM01Out(IP) =
& DBLE(SWAN_VOQ(IP,SWAN_VOQR(IVTYPE)))
SwanOut => Swan_TM01Out
SwanMaxOut => Swan_TM01MaxOut
CASE(4)
Swan_TPSOut(IP) = DBLE(SWAN_VOQ(IP,SWAN_VOQR(IVTYPE)))
SwanOut => Swan_TPSOut
SwanMaxOut => Swan_TPSMaxOut
CASE(5)
Swan_WindXOut(IP) =
& DBLE(SWAN_VOQ(IP,SWAN_VOQR(IVTYPE)))
Swan_WindYOut(IP) =
& DBLE(SWAN_VOQ(IP,SWAN_VOQR(IVTYPE)+1)) !jgfdebug
SwanOut => Swan_WindXOut
SwanOut2 => Swan_WindYOut
SwanMaxOut => Swan_WindMaxOut
CASE(6)
Swan_TM02Out(IP) =
& DBLE(SWAN_VOQ(IP,SWAN_VOQR(IVTYPE)))
SwanOut => Swan_TM02Out
SwanMaxOut => Swan_TM02MaxOut
CASE(7)
Swan_TMM10Out(IP) =
& DBLE(SWAN_VOQ(IP,SWAN_VOQR(IVTYPE)))
SwanOut => Swan_TMM10Out
SwanMaxOut => Swan_TMM10MaxOut
CASE DEFAULT
!...Huh? I shouldn't be here...
END SELECT
! jgf51.21.27: Move this here so it can be used to write
! data in various formats below.
! SwanDescript % alternate_value = DBLE(OVEXCV(IVTYPE))
IF(IW.NE.5)THEN
!Casey 110518: Ensure that dry nodes are written with default values.
!Casey 120522: Correct logic for the files that don't contain significant wave heights.
IF(NODECODE(IP).EQ.1)THEN
IF(IW.EQ.1)THEN
IF(SwanOut(IP).GT.SwanMaxOut(IP))THEN
UpdateMax(IP) = 1
SwanMaxOut(IP) = SwanOut(IP)
ENDIF
ELSEIF(UpdateMax(IP).EQ.1)THEN
SwanMaxOut(IP) = SwanOut(IP)
ENDIF
ENDIF
ELSE
IF((NODECODE(IP).EQ.1).AND.
& (SQRT(SwanOut(IP)*SwanOut(IP)+SwanOut2(IP)*SwanOut2(IP)).GT.SwanMaxOut(IP)))THEN
IF(UpdateMax(IP).EQ.1)THEN
SwanMaxOut(IP) = SQRT(SwanOut(IP)*SwanOut(IP)+SwanOut2(IP)*SwanOut2(IP))
ENDIF
ENDIF
ENDIF
ENDDO
ENDDO
!Casey 090620: More deallocations.
IF(ALLOCATED(FileName)) DEALLOCATE(FileName)
IF(ALLOCATED(IGSW)) DEALLOCATE(IGSW)
IF(ALLOCATED(Names)) DEALLOCATE(Names)
IF(ALLOCATED(SWAN_VOQ)) DEALLOCATE(SWAN_VOQ)
#if defined(COUPLE2SWAN_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Return.")
#endif
call unsetMessageSource()
RETURN
C-----------------------------------------------------------------------
END SUBROUTINE SwanOutput
C-----------------------------------------------------------------------
C-----------------------------------------------------------------------
C S U B R O U T I N E P A D C S W A N _ I N I T
C-----------------------------------------------------------------------
C-----------------------------------------------------------------------
SUBROUTINE PADCSWAN_INIT
!USE, INTRINSIC :: IEEE_ARITHMETIC !jgfdebug ieee_is_nan()
USE GLOBAL, ONLY: DT,
& ETA2,
Casey 120305: Merging ice changes from Taylor Asher.
CTGA 110912: Full SWAN ice implementation. Use global variables
& NCICE,
& CICE1,
& CICE2
USE WIND, ONLY : WVNX1,
& WVNX2,
& WVNY1,
& WVNY2
USE MESH, ONLY : NP, DP
CTGA 111003: Adding ability to read in ice info from fort.26 file
USE SWCOMM3, ONLY: SWAN_WBICETH => WBICETH,
& SWAN_IICE => IICE
USE TIMECOMM, ONLY: SWAN_DT => DT
IMPLICIT NONE
INTRINSIC :: ALLOCATED
INTEGER :: IN ! Node counter.
call setMessageSource("padcswan_init")
#if defined(COUPLE2SWAN_TRACE) || defined(ALL_TRACE)
call allMessage(DEBUG,"Enter.")
#endif
Casey 090302: Allocate memory for the ADCIRC values that may be
C passed to SWAN.
IF(.NOT.ALLOCATED(SWAN_ETA2)) ALLOCATE(SWAN_ETA2(1:NP,1:2))
IF(.NOT.ALLOCATED(SWAN_UU2)) ALLOCATE(SWAN_UU2(1:NP,1:2))
IF(.NOT.ALLOCATED(SWAN_VV2)) ALLOCATE(SWAN_VV2(1:NP,1:2))
IF(.NOT.ALLOCATED(SWAN_WX2)) ALLOCATE(SWAN_WX2(1:NP,1:2))
IF(.NOT.ALLOCATED(SWAN_WY2)) ALLOCATE(SWAN_WY2(1:NP,1:2))
Casey 091216: Added allocation for friction coupling.
IF(.NOT.ALLOCATED(SWAN_Z0)) ALLOCATE(SWAN_Z0(1:NP,1:2))
Casey 120302: Merging ice changes from Taylor Asher.
CTGA 110912: Full SWAN ice implementation. Allocating ice arrays.