-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwanCompUnstruc.ftn90
1699 lines (1699 loc) · 80.7 KB
/
SwanCompUnstruc.ftn90
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
subroutine SwanCompUnstruc ( ac2, ac1, compda, spcsig, spcdir, xytst, cross, it )
!
! --|-----------------------------------------------------------|--
! | Delft University of Technology |
! | Faculty of Civil Engineering and Geosciences |
! | Environmental Fluid Mechanics Section |
! | P.O. Box 5048, 2600 GA Delft, The Netherlands |
! | |
! | Programmer: Marcel Zijlema |
! --|-----------------------------------------------------------|--
!
!
! SWAN (Simulating WAves Nearshore); a third generation wave model
! Copyright (C) 1993-2024 Delft University of Technology
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <http://www.gnu.org/licenses/>.
!
!
! Authors
!
! 40.80: Marcel Zijlema
! 40.85: Marcel Zijlema
! 40.95: Marcel Zijlema
! 41.02: Marcel Zijlema
! 41.07: Marcel Zijlema
! 41.10: Marcel Zijlema
! 41.20: Casey Dietrich
! 41.60: Marcel Zijlema
! 41.63: Marcel Zijlema
! 41.67: Marcel Zijlema
! 41.68: Marcel Zijlema
! 41.80: Dirk Rijnsdorp and Ad Reniers
! 41.90: Gal Akrish, Pieter Smit and Marcel Zijlema
! 41.91: Marcel Zijlema
!
! Updates
!
! 40.80, July 2007: New subroutine
! 40.85, August 2008: add propagation, generation and redistribution terms for output purposes
! 40.95, June 2008: parallelization of unSWAN
! 41.02, February 2009: implementation of diffraction
! 41.07, August 2009: bug fix: never-ending sweep is prevented
! 41.10, August 2009: parallelization using OpenMP directives
! 41.20, June 2010: extension to tightly coupled ADCIRC+SWAN model
! 41.60, July 2015: more accurate computation of gradients of depth or wave number for turning rate
! 41.63, August 2015: efficiency UnSWAN algorithm improved; one sweep per iteration instead of undetermined number of sweeps
! 41.68, August 2015: introduction of a fixed number of sweeps per iteration
! 41.67, August 2017: more accurate computation of gradients of ambient currents for transport velocities
! 41.80,September 2021: adding Bragg scattering
! 41.90, October 2021: adding QC scattering
! 41.91, February 2022: adding QC surf breaking
!
! Purpose
!
! Performs one time step for solution of wave action equation on unstructured grid
!
! Method
!
! A vertex-based algorithm is employed in which the variables are stored at the vertices of the mesh
! The equation is solved in each vertex assuming a constant spectral grid resolution in all vertices
! The propagation terms in both geographic and spectral spaces are integrated implicitly
! Sources are treated explicitly and sinks implicitly
! The calculation of the source terms is carried out in the original SWAN routines, e.g., SOURCE
!
! The wave action equation is solved iteratively
! A number of iterations are carried out until convergence is reached
! In each iteration, a fixed number of sweeps are carried out
! Per sweep direction, a loop over ordered vertices is executed
! The solution of each vertex must be updated geographically before proceeding to the next one
! Per vertex, a loop over cells is executed
! The solution of each cell (partly) enclosed by the present sweep must be updated
! The two upwave faces connecting the vertex to be updated enclose those wave directions that can be processed in the spectral space
!
! Modules used
!
use ocpcomm4
use swcomm1
use swcomm2
use swcomm3
use swcomm4
use SwanGriddata
use SwanGridobjects
use SwanCompdata
use SwanQCM
use m_snl3
use m_parall
!METIS use SwanParallel
!ADC use couple2adcirc, only: MakeBoundariesReflective
!ADC use NodalAttributes, only: FoundSwanWaveRefrac, LoadSwanWaveRefrac, SwanWaveRefrac
!
implicit none
!
! Argument variables
!
integer, dimension(nfaces), intent(in) :: cross ! contains sequence number of obstacles for each face
! where they crossing or zero if no crossing
integer, intent(in) :: it ! counter in time space
integer, dimension(NPTST), intent(in) :: xytst ! test points for output purposes
!
real, dimension(MDC,MSC,nverts), intent(in) :: ac1 ! action density at previous time level
real, dimension(MDC,MSC,nverts), intent(inout) :: ac2 ! action density at current time level
real, dimension(nverts,MCMVAR), intent(inout) :: compda ! array containing space-dependent info (e.g. depth)
real, dimension(MDC,6), intent(in) :: spcdir ! (*,1): spectral direction bins (radians)
! (*,2): cosine of spectral directions
! (*,3): sine of spectral directions
! (*,4): cosine^2 of spectral directions
! (*,5): cosine*sine of spectral directions
! (*,6): sine^2 of spectral directions
real, dimension(MSC), intent(in) :: spcsig ! relative frequency bins
!
! Parameter variables
!
integer, parameter :: itswp = 4 ! the number of iterations needed prior to switch to a lower number of sweeps
!
! Local variables
!
integer :: icell ! cell index / loop counter
integer :: id ! loop counter over direction bins
integer :: iddlow ! minimum direction bin that is propagated within a sweep
integer :: iddtop ! maximum direction bin that is propagated within a sweep
integer :: iddum ! counter in directional space for considered sweep
integer, parameter :: idebug=0 ! level of debug output:
! 0 = no output
! 1 = print extra output for debug purposes
integer :: idtot ! maximum number of bins in directional space for considered sweep
integer :: idwmax ! maximum counter for spectral wind direction
integer :: idwmin ! minimum counter for spectral wind direction
integer, save :: ient = 0 ! number of entries in this subroutine
integer :: ierror ! error indicator
integer :: iface ! face index
integer :: inocnt ! inocnv counter for calling thread
integer :: inocnv ! integer indicating number of vertices in which solver does not converged
integer :: is ! loop counter over frequency bins
integer :: isslow ! minimum frequency that is propagated within a sweep
integer :: isstop ! maximum frequency that is propagated within a sweep
integer :: istat ! indicate status of allocation
integer :: istot ! maximum number of bins in frequency space for considered sweep
integer :: iter ! iteration counter
integer :: ivert ! vertex index
integer :: ivlow ! lower index in range of vertices in calling thread
integer :: ivup ! upper index in range of vertices in calling thread
integer :: j ! loop counter
integer :: jc ! loop counter
integer :: k ! loop counter
integer :: kvert ! loop counter over vertices
integer, dimension(2) :: link ! local face connected to considered vertex where an obstacle crossed
integer :: mnisl ! minimum sigma-index occured in applying limiter
integer :: mxnfl ! maximum number of use of limiter in spectral space
integer :: mxnfr ! maximum number of use of rescaling in spectral space
integer :: n ! actual number of sweeps (during the iteration process)
integer :: npfl ! number of vertices in which limiter is used
integer :: npfr ! number of vertices in which rescaling is used
integer :: swpdir ! sweep counter
integer :: swpnr ! sweep number
integer :: tid ! thread number
integer, dimension(3) :: v ! vertices in present cell
integer :: vb ! vertex of begin of present face
integer :: ve ! vertex of end of present face
integer, dimension(2) :: vu ! upwave vertices in present cell
integer, dimension(24) :: wwint ! counters for 4 wave-wave interactions (see routine FAC4WW)
!
integer, dimension(:), allocatable :: idcmax ! maximum frequency-dependent counter in directional space
integer, dimension(:), allocatable :: idcmin ! minimum frequency-dependent counter in directional space
integer, dimension(:), allocatable :: iscmax ! maximum direction-dependent counter in frequency space
integer, dimension(:), allocatable :: iscmin ! minimum direction-dependent counter in frequency space
integer, dimension(:), allocatable :: islmin ! lowest sigma-index occured in applying limiter
integer, dimension(:), allocatable :: nflim ! number of frequency use of limiter in each vertex
integer, dimension(:), allocatable :: nrscal ! number of frequency use of rescaling in each vertex
!$ integer, dimension(:), allocatable :: tlist ! vertex list for calling thread
!
real :: abrbot ! near bottom excursion
real :: accur ! percentage of active vertices in which required accuracy has been reached
real :: acnrmo ! norm of difference of previous iteration
real, dimension(2) :: acnrms ! array containing infinity norms
real :: dal1 ! a coefficent for the 4 wave-wave interactions
real :: dal2 ! another coefficent for the 4 wave-wave interactions
real :: dal3 ! just another coefficent for the 4 wave-wave interactions
real :: dhdx ! derivative of depth in x-direction
real :: dhdy ! derivative of depth in y-direction
real :: dummy ! dummy variable (to be used in existing SWAN routine call)
real :: duxdx ! derivative of ux2 to x
real :: duxdy ! derivative of ux2 to y
real :: duydx ! derivative of uy2 to x
real :: duydy ! derivative of uy2 to y
real :: etot ! total wave energy density
real :: fpm ! Pierson Moskowitz frequency
real :: frac ! fraction of total active vertices
real :: hm ! maximum wave height
real :: hs ! significant wave height
real :: kmespc ! mean average wavenumber based on the WAM formulation
real :: kteta ! number of directional partitions
real :: nwetp ! total number of active vertices
real :: qbloc ! fraction of breaking waves
real, dimension(2) :: rdx ! first component of contravariant base vector rdx(b) = a^(b)_1
real, dimension(2) :: rdy ! second component of contravariant base vector rdy(b) = a^(b)_2
real :: rhof ! asymptotic convergence factor
real :: rval1 ! a dummy value
real :: rval2 ! a dummy value
real :: sdir ! sweep direction
real :: smebrk ! mean frequency based on the first order moment
real :: snlc1 ! a coefficent for the 4 wave-wave interactions
real :: stopcr ! stopping criterion for stationary solution
real :: th1 ! direction of one face pointing to present vertex
real :: th2 ! direction of another face pointing to present vertex
real :: thmax ! maximum direction of present sweep
real :: thmin ! minimum direction of present sweep
real :: thetaw ! mean direction of the wind speed vector with respect to ambient current
real :: ufric ! wind friction velocity
real, dimension(nverts) :: urmstop
real, dimension(5) :: usrset ! auxiliary array to store user-defined settings of 3rd generation mode
real :: wind10 ! magnitude of the wind speed vector with respect to ambient current
real, dimension(8) :: wwawg ! weight coefficients for the 4 wave-wave interactions (see routine FAC4WW)
real, dimension(8) :: wwswg ! weight coefficients for the 4 wave-wave interactions semi-implicitly (see routine FAC4WW)
real :: xis ! difference between succeeding frequencies for computing 4 wave-wave interactions
!
real, dimension(:,:), allocatable :: ac2old ! array to store action density before solving system of equations
real, dimension(:,:), allocatable :: alimw ! maximum energy by wind growth
! this auxiliary array is used because the maximum value has to be checked
! direct after solving the action balance equation
real, dimension(:,:,:), allocatable :: amat ! coefficient matrix of system of equations in spectral space
real, dimension(:,:), allocatable :: rhs ! right-hand side of system of equations in spectral space
real, dimension(:,:), allocatable :: cad ! wave transport velocity in theta-direction
real, dimension(:,:), allocatable :: cas ! wave transport velocity in sigma-direction
real, dimension(:,:,:), allocatable :: cax ! wave transport velocity in x-direction
real, dimension(:,:,:), allocatable :: cay ! wave transport velocity in y-direction
real, dimension(:,:,:), allocatable :: cgft ! Fourier-transformed modulation of group velocity
real, dimension(:,:), allocatable :: cgo ! group velocity
real, dimension(:,:), allocatable :: da1c ! implicit interaction contribution of first quadruplet, current bin (unfolded space)
real, dimension(:,:), allocatable :: da1m ! implicit interaction contribution of first quadruplet, current bin -1 (unfolded space)
real, dimension(:,:), allocatable :: da1p ! implicit interaction contribution of first quadruplet, current bin +1 (unfolded space)
real, dimension(:,:), allocatable :: da2c ! implicit interaction contribution of second quadruplet, current bin (unfolded space)
real, dimension(:,:), allocatable :: da2m ! implicit interaction contribution of second quadruplet, current bin -1 (unfolded space)
real, dimension(:,:), allocatable :: da2p ! implicit interaction contribution of second quadruplet, current bin +1 (unfolded space)
real, dimension(:,:,:), allocatable :: disc0 ! explicit part of dissipation in present vertex for output purposes
real, dimension(:,:,:), allocatable :: disc1 ! implicit part of dissipation in present vertex for output purposes
real, dimension(:), allocatable :: dkdx ! derivative of wave number in x-direction
real, dimension(:), allocatable :: dkdy ! derivative of wave number in y-direction
real, dimension(:,:), allocatable :: dmw ! mud dissipation rate
real, dimension(:,:), allocatable :: dsnl ! total interaction contribution of quadruplets to the main diagonal matrix
real, dimension(:,:,:), allocatable :: fbd ! bottom spectrum for Bragg scattering
real, dimension(:,:,:), allocatable :: genc0 ! explicit part of generation in present vertex for output purposes
real, dimension(:,:,:), allocatable :: genc1 ! implicit part of generation in present vertex for output purposes
real, dimension(:), allocatable :: hscurr ! wave height at current iteration level
real, dimension(:), allocatable :: hsdifc ! difference in wave height of current and one before previous iteration
real, dimension(:), allocatable :: hsprev ! wave height at previous iteration level
real, dimension(:,:), allocatable :: kwave ! wave number
real, dimension(:,:), allocatable :: leakcf ! leak coefficient in present vertex for output purposes
real, dimension(:,:,:), allocatable :: membrg ! auxiliary array to store results of Bragg scattering in full spectral space
real, dimension(:,:,:), allocatable :: memnl4 ! auxiliary array to store results of 4 wave-wave interactions in full spectral space
real, dimension(:,:,:), allocatable :: memqcb ! auxiliary array to store results of QC surf breaking in full spectral space
real, dimension(:,:,:), allocatable :: memqcm ! auxiliary array to store results of QC scattering in full spectral space
real, dimension(:,:,:), allocatable :: memsina ! auxiliary array to store results of linear wind input in full spectral space
real, dimension(:,:,:), allocatable :: memsinb ! auxiliary array to store results of exponential wind input in full spectral space
real, dimension(:,:,:), allocatable :: obredf ! action reduction coefficient based on transmission
real, dimension(:,:), allocatable :: qtl1 ! local interpolation factors for triads
real, dimension(:,:), allocatable :: qtl2 ! local scaling factors for triads
real, dimension(:,:,:), allocatable :: redc0 ! explicit part of redistribution in present vertex for output purposes
real, dimension(:,:,:), allocatable :: redc1 ! implicit part of redistribution in present vertex for output purposes
real, dimension(:,:), allocatable :: reflso ! contribution to the source term due to reflection
real, dimension(:,:), allocatable :: sa1 ! explicit interaction contribution of first quadruplet (unfolded space)
real, dimension(:,:), allocatable :: sa2 ! explicit interaction contribution of second quadruplet (unfolded space)
real, dimension(:,:), allocatable :: sfnl ! total interaction contribution of quadruplets to the right-hand side
real, dimension(:,:,:), allocatable :: sigft ! Fourier-transformed modulation of intrinsic frequency
real, dimension(:,:,:,:), allocatable :: swtsda ! several source terms computed at test points
real, dimension(:), allocatable :: temp ! temporary array to store data for MPI communication
real, dimension(:), allocatable :: tmcurr ! mean period at current iteration level
real, dimension(:), allocatable :: tmdifc ! difference in mean period of current and one before previous iteration
real, dimension(:), allocatable :: tmprev ! mean period at previous iteration level
real, dimension(:,:,:), allocatable :: trac0 ! explicit part of propagation in present vertex for output purposes
real, dimension(:,:,:), allocatable :: trac1 ! implicit part of propagation in present vertex for output purposes
real, dimension(:,:), allocatable :: ue ! energy density for computing 4 wave-wave interactions (unfolded space)
complex, dimension(:,:), allocatable :: uxft ! u-component of Fourier-transformed modulation of ambient current
complex, dimension(:,:), allocatable :: uyft ! v-component of Fourier-transformed modulation of ambient current
!
logical :: fguess ! indicate whether first guess need to be applied or not
logical :: lpredt ! indicate whether action density in first iteration need to be estimated or not
!
logical, dimension(:,:), allocatable :: anybin ! true if bin is active in considered sweep
logical, dimension(:,:), allocatable :: anyblk ! true if bin is blocked by a counter current based on a CFL criterion
logical, dimension(:), allocatable :: anywnd ! true if wind input is active in considered bin
logical, dimension(:,:), allocatable :: groww ! check for each frequency whether the waves are growing or not
! in a spectral direction
!
character(80) :: msgstr ! string to pass message
!
type(celltype), dimension(:), pointer :: cell ! datastructure for cells with their attributes
type(verttype), dimension(:), pointer :: vert ! datastructure for vertices with their attributes
!
! help arrays for FFT in relation to QC scattering
complex(kind=8), dimension(:,:), allocatable :: cft ! Fourier coefficients (FFT)
real (kind=8), dimension(:,:), allocatable :: rft ! input data (FFT)
real (kind=8), dimension(:,:), allocatable :: sft ! input data (FFT)
real (kind=8), dimension(:) , allocatable :: wft ! work array (FFT)
real (kind=8), dimension(:) , allocatable :: wsave ! work array (FFT)
!
! help arrays for FFT in relation to QC surf breaking
complex(kind=8), dimension(:,:), allocatable :: cfd ! Fourier coefficients (FFT)
real (kind=8), dimension(:) , allocatable :: wfd ! work array (FFT)
real (kind=8), dimension(:) , allocatable :: wsavd ! work array (FFT)
!
!$ integer, external :: omp_get_num_threads ! number of OpenMP threads being used
!$ integer, external :: omp_get_thread_num ! get thread number
!
! Structure
!
! Description of the pseudo code
!
! Source text
!
if (ltrace) call strace (ient,'SwanCompUnstruc')
!
! point to vertex and cell objects
!
vert => gridobject%vert_grid
cell => gridobject%cell_grid
!
! some initializations
!
ICMAX = 3 ! stencil size
PROPSL = PROPSC
!
IXCGRD(1) = -9999 ! to be used in routines SINTGRL and SOURCE so that Ursell number and
IYCGRD(1) = -9999 ! quadruplets are calculated once in each vertex during an iteration
!
tid = 0
ivlow = 1
ivup = nverts
!
! print all the settings used in SWAN run
!
if ( it == 1 .and. ITEST > 0 ) call SWPRSET (spcsig,spcdir)
!
! print test points
!
if ( NPTST > 0 ) then
do j = 1, NPTST
write (PRINTF,107) j, xytst(j)
enddo
endif
!
! allocation of shared arrays
!
!TIMG call SWTSTA(101)
allocate(islmin(nverts))
allocate( nflim(nverts))
allocate(nrscal(nverts))
!
allocate(hscurr(nverts))
allocate(hsprev(nverts))
allocate(hsdifc(nverts))
allocate(tmcurr(nverts))
allocate(tmprev(nverts))
allocate(tmdifc(nverts))
allocate(temp (nverts))
!
allocate(swtsda(MDC,MSC,NPTSTA,MTSVAR))
!
if ( IQUAD > 2 ) then
allocate(memnl4(MDC,MSC,nverts), stat = istat)
if ( istat /= 0 ) then
call msgerr ( 4, 'Allocation problem in SwanCompUnstruc: array memnl4 ' )
return
endif
else
allocate(memnl4(0,0,0))
endif
!
if ( IBRAG == 3 ) then
allocate(membrg(MDC,MSC,nverts), stat = istat)
if ( istat /= 0 ) then
call msgerr ( 4, 'Allocation problem in SwanCompUnstruc: array membrg ' )
return
endif
else
allocate(membrg(0,0,0))
endif
!
if ( IQCM > 0 ) then
allocate(memqcm(MDC,MSC,nverts), stat = istat)
if ( istat /= 0 ) then
call msgerr ( 4, 'Allocation problem in SwanCompUnstruc: array memqcm ' )
return
endif
else
allocate(memqcm(0,0,0))
endif
!
if ( ISURF > 0 .and. IGEN == 4 ) then
allocate(memqcb(MDC,MSC,nverts), stat = istat)
if ( istat /= 0 ) then
call msgerr ( 4, 'Allocation problem in SwanCompUnstruc: array memqcb ' )
return
endif
else
allocate(memqcb(0,0,0))
endif
!
if ( IWIND == 8 ) then
istat = 0
allocate(memsina(MDC,MSC,nverts), stat = istat)
if ( istat == 0 ) allocate(memsinb(MDC,MSC,nverts), stat = istat)
if ( istat /= 0 ) then
call msgerr ( 4, 'Allocation problem in SwanCompUnstruc: array memsin ' )
return
endif
else
allocate(memsina(0,0,0))
allocate(memsinb(0,0,0))
endif
!
!$ allocate(tlist(nverts))
!TIMG call SWTSTO(101)
!
! initialization of shared arrays
!
hscurr = 0.
hsprev = 0.
hsdifc = 0.
tmcurr = 0.
tmprev = 0.
tmdifc = 0.
!
swtsda = 0.
!
! spawn a parallel region
!
!$omp parallel default(shared) &
!$omp private(cad, cas, cax, cay, cgo, kwave, dmw) &
!$omp private(idcmin, idcmax, iscmin, iscmax, anybin) &
!$omp private(amat, rhs, ac2old) &
!$omp private(anywnd, obredf, reflso, alimw, groww, anyblk, fbd) &
!$omp private(disc0, disc1, genc0, genc1, redc0, redc1, trac0, trac1, leakcf) &
!$omp private(sigft, cgft, uxft, uyft, cft, rft, sft, wft, wsave, cfd, wfd, wsavd) &
!$omp private(ue, sa1, sa2, sfnl) &
!$omp private(qtl1, qtl2) &
!$omp private(da1c, da1p, da1m, da2c, da2p, da2m, dsnl) &
!$omp private(tid, ivlow, ivup, iter, kvert) &
!$omp private(ivert, jc, k, j, icell, n, v, vu, swpnr, swpdir, sdir, rdx, rdy, lpredt, vb, ve, iface, link, inocnt, thmin, thmax, th1, th2) &
!$omp private(iddlow, iddtop, idtot, isslow, isstop, istot) &
!$omp private(abrbot, kmespc, idwmin, idwmax, hs, etot, qbloc, ufric, fpm, thetaw, hm, wind10, smebrk, kteta) &
!$omp private(dhdx, dhdy, dkdx, dkdy) &
!$omp copyin(ICMAX, COSLAT, IPTST, TESTFL, RDFSIN)
!
! print number of threads set by environment
!
!$omp master
!$ if ( it == 1 ) &
!$ write (SCREEN,'(a,i2/)') ' Number of threads during execution of parallel region = ', omp_get_num_threads()
!$omp end master
!
! get thread number
!
!$ tid = omp_get_thread_num()
tid = tid + 1
!
! allocation of private arrays
!
!TIMG call SWTSTA(101)
allocate( cad(MDC,MSC ))
allocate( cas(MDC,MSC ))
allocate( cax(MDC,MSC,ICMAX))
allocate( cay(MDC,MSC,ICMAX))
allocate ( cgo( MSC,ICMAX))
allocate (kwave( MSC,ICMAX))
allocate ( dmw( MSC,ICMAX))
!
allocate(idcmax( MSC))
allocate(idcmin( MSC))
allocate(iscmax(MDC ))
allocate(iscmin(MDC ))
allocate(anybin(MDC,MSC))
!
allocate( amat(MDC,MSC,5))
allocate( rhs(MDC,MSC ))
allocate(ac2old(MDC,MSC ))
!
allocate(anywnd(MDC))
allocate(obredf(MDC,MSC,2))
allocate(reflso(MDC,MSC))
allocate( alimw(MDC,MSC))
allocate( groww(MDC,MSC))
allocate(anyblk(MDC,MSC))
!
allocate( disc0(MDC,MSC,MDISP))
allocate( disc1(MDC,MSC,MDISP))
allocate( genc0(MDC,MSC,MGENR))
allocate( genc1(MDC,MSC,MGENR))
allocate( redc0(MDC,MSC,MREDS))
allocate( redc1(MDC,MSC,MREDS))
allocate( trac0(MDC,MSC,MTRNP))
allocate( trac1(MDC,MSC,MTRNP))
allocate(leakcf(MDC,MSC ))
!
allocate(dkdx(MSC))
allocate(dkdy(MSC))
!
if ( IBRAG > 1 ) then
allocate(fbd(MDC,MDC,MSC))
else
allocate(fbd(0,0,0))
endif
!
if ( IQCM > 0 ) then
!
! allocate work arrays for FFT
!
allocate(rft(ncoz,ncoz))
allocate(sft(ncoz,ncoz))
allocate(cft(ncoz,ncoz))
!
allocate(wft (lenwft))
allocate(wsave(lensav))
!
! initialization FFT
!
call cfft2i ( ncoz, ncoz, wsave, lensav, ierror )
if ( ierror /= 0 ) then
write (msgstr, '(a,i6)') 'something went wrong with the FFT initialization - return code is ',ierror
call msgerr ( 4, trim(msgstr) )
endif
!
! allocate and initialize Fourier-transformed modulations of relative frequency, group velocity and ambient current
!
allocate(sigft(ncoz,ncoz,MSC))
allocate(cgft (ncoz,ncoz,MSC))
allocate(uxft (ncoz,ncoz) )
allocate(uyft (ncoz,ncoz) )
!
sigft = 0.
cgft = 0.
uxft = (0.,0.)
uyft = (0.,0.)
!
else
allocate(rft (0,0))
allocate(sft (0,0))
allocate(cft (0,0))
allocate(wft (0))
allocate(wsave(0))
allocate(sigft(0,0,0))
allocate(cgft (0,0,0))
allocate(uxft (0,0))
allocate(uyft (0,0))
endif
!
if ( ISURF > 0 .and. IGEN == 4 ) then
!
! allocate work arrays for FFT
!
allocate(cfd(myd,mxd))
!
allocate(wfd (lenwfd))
allocate(wsavd(lensvd))
!
! initialization FFT
!
call cfft2i ( myd, mxd, wsavd, lensvd, ierror )
if ( ierror /= 0 ) then
write (msgstr, '(a,i6)') 'something went wrong with the FFT initialization - return code is ',ierror
call msgerr ( 4, trim(msgstr) )
endif
!
else
allocate(cfd (0,0))
allocate(wfd (0))
allocate(wsavd(0))
endif
!
! calculate ranges of spectral space for arrays related to 4 wave-wave interactions
!
!$omp single
!TIMG call SWTSTA(135)
if ( IQUAD > 0 ) call FAC4WW ( xis, snlc1, dal1, dal2, dal3, spcsig, wwint, wwawg, wwswg )
!TIMG call SWTSTO(135)
!$omp end single
!
! store frequency- and space-dependent data for triads
!
!$omp single
!TIMG call SWTSTA(134)
if ( ITRIAD > 0 ) then
if ( it == 1 .or. DYNDEP ) call FAC3WW ( compda(1,JDP2), spcsig )
endif
!TIMG call SWTSTO(134)
!$omp end single
!
if ( IQUAD > 0 ) then
allocate( ue(MSC4MI:MSC4MA,MDC4MI:MDC4MA))
allocate( sa1(MSC4MI:MSC4MA,MDC4MI:MDC4MA))
allocate( sa2(MSC4MI:MSC4MA,MDC4MI:MDC4MA))
allocate(sfnl(MSC4MI:MSC4MA,MDC4MI:MDC4MA))
if ( IQUAD == 1 ) then
allocate(da1c(MSC4MI:MSC4MA,MDC4MI:MDC4MA))
allocate(da1p(MSC4MI:MSC4MA,MDC4MI:MDC4MA))
allocate(da1m(MSC4MI:MSC4MA,MDC4MI:MDC4MA))
allocate(da2c(MSC4MI:MSC4MA,MDC4MI:MDC4MA))
allocate(da2p(MSC4MI:MSC4MA,MDC4MI:MDC4MA))
allocate(da2m(MSC4MI:MSC4MA,MDC4MI:MDC4MA))
allocate(dsnl(MSC4MI:MSC4MA,MDC4MI:MDC4MA))
else
allocate(da1c(0,0))
allocate(da1p(0,0))
allocate(da1m(0,0))
allocate(da2c(0,0))
allocate(da2p(0,0))
allocate(da2m(0,0))
allocate(dsnl(0,0))
endif
else
allocate( ue(0,0))
allocate( sa1(0,0))
allocate( sa2(0,0))
allocate(sfnl(0,0))
allocate(da1c(0,0))
allocate(da1p(0,0))
allocate(da1m(0,0))
allocate(da2c(0,0))
allocate(da2p(0,0))
allocate(da2m(0,0))
allocate(dsnl(0,0))
endif
!
if ( ITRIAD > 0 ) then
if (ITRIAD == 1 .or. ITRIAD == 11) then
allocate(qtl1( 0,0))
allocate(qtl2(MSC,2))
else if (ITRIAD == 2 .or. ITRIAD == 3) then
allocate(qtl1(MSC4D,2))
allocate(qtl2(MSC4D,4))
else if (ITRIAD == 5) then
allocate(qtl1(MSC4D,2))
allocate(qtl2(MSC4D,2))
endif
else
allocate(qtl1(0,0))
allocate(qtl2(0,0))
endif
!TIMG call SWTSTO(101)
!
! marks vertices active and non-active
!
!$omp single
nwetp = 0.
do kvert = 1, nverts
if ( compda(kvert,JDP2) > DEPMIN ) then
vert(kvert)%active = .true.
nwetp = nwetp +1.
else
vert(kvert)%active = .false.
endif
enddo
if ( it == 1 .and. ITEST > 0 ) write (PRINTF,108) nint(nwetp), nwetp*100./real(nverts)
!
! First guess of action density will be applied if 3rd generation mode is employed and wind is active (IWIND > 2)
! Note: this first guess is not used in nonstationary run (NSTATC > 0) or hotstart (ICOND = 4)
!
if ( IWIND > 2 .and. NSTATC == 0 .and. ICOND /= 4 ) then
fguess = .true.
else
fguess = .false.
endif
!$omp end single
!
!TIMG call SWTSTA(103)
iterloop: do iter = 1, ITERMX
!
! some initializations
!
if ( IQUAD > 2 ) memnl4(1:MDC,1:MSC,1:nverts) = 0.
if ( IBRAG == 3 ) membrg(1:MDC,1:MSC,1:nverts) = 0.
if ( IQCM > 0 ) memqcm(1:MDC,1:MSC,1:nverts) = 0.
if ( IWIND == 8 ) memsina(1:MDC,1:MSC,1:nverts) = 0.
if ( IWIND == 8 ) memsinb(1:MDC,1:MSC,1:nverts) = 0.
if ( ISURF > 0 .and. IGEN == 4 ) memqcb(1:MDC,1:MSC,1:nverts) = 0.
if ( ITRIAD > 0 &
.or. ISURF == 7 &
) then
compda(1:nverts,JURSEL) = 0.
compda(1:nverts,JBIPH ) = 0.
endif
!
compda(1:nverts,JDISS) = 0.
compda(1:nverts,JLEAK) = 0.
compda(1:nverts,JDSXB) = 0.
compda(1:nverts,JDSXS) = 0.
compda(1:nverts,JDSXW) = 0.
compda(1:nverts,JDSXM) = 0.
compda(1:nverts,JDSXI) = 0.
compda(1:nverts,JDSXV) = 0.
compda(1:nverts,JDSXT) = 0.
compda(1:nverts,JDSXL) = 0.
compda(1:nverts,JGENR) = 0.
compda(1:nverts,JGSXW) = 0.
compda(1:nverts,JREDS) = 0.
compda(1:nverts,JRSXQ) = 0.
compda(1:nverts,JRSXT) = 0.
compda(1:nverts,JRSXB) = 0.
compda(1:nverts,JRSXC) = 0.
compda(1:nverts,JTRAN) = 0.
compda(1:nverts,JTSXG) = 0.
compda(1:nverts,JTSXT) = 0.
compda(1:nverts,JTSXS) = 0.
compda(1:nverts,JRADS) = 0.
compda(1:nverts,JQB ) = 0.
!
inocnt = 0
!
! synchronize threads
!$omp barrier
!
!$omp master
inocnv = 0
!
islmin = 9999
nflim = 0
nrscal = 0
!
acnrms = -9999.
!
! During first iteration, first guess of action density is based on 2nd generation mode
! After first iteration, user-defined settings are re-used
!
if ( fguess ) then
!
if ( iter == 1 )then
!
! save user-defined settings of 3rd generation mode
! Note: surf breaking, bottom friction and triads may be still active
!
usrset(1) = IWIND
usrset(2) = IWCAP
usrset(3) = IQUAD
usrset(4) = PNUMS(20)
usrset(5) = PNUMS(30)
!
! first guess settings
!
IWIND = 2 ! if first guess should be based on 1st generation mode, set IWIND = 1
IWCAP = 0
IQUAD = 0
PNUMS(20) = 1.E22 ! no limiter
PNUMS(30) = 0. ! no under-relaxation
!
write (PRINTF,101)
!
elseif ( iter == 2 ) then
!
! re-activate user-defined settings of 3rd generation mode
!
IWIND = usrset(1)
IWCAP = usrset(2)
IQUAD = usrset(3)
PNUMS(20) = usrset(4)
PNUMS(30) = usrset(5)
!
write (PRINTF,102)
!
endif
!
! print info
!
if ( iter < 3 ) then
write (PRINTF,103) iter, PNUMS(20), PNUMS(30)
write (PRINTF,104) IWIND, IWCAP, IQUAD
write (PRINTF,105) ISURF, IBOT , ITRIAD
write (PRINTF,106) IVEG , ITURBV, IMUD, IICE, IBRAG
endif
!
endif
!
! calculate diffraction parameter and its derivatives
!
if ( IDIFFR /= 0 ) call SwanDiffPar ( ac2, compda(1,JDP2), spcsig )
!
! spatially filter the De Wit's biphase to prevent abrupt changes
! note: just copy the unfiltered one to array BIPHAS
!
if ( IBIPH == 3 ) call SWBIPM ( compda(1,JBIPH), compda(1,JDP2), compda(1,JHSIBC) )
!
! all vertices are set untagged except non-active ones
!
do kvert = 1, nverts
do jc = 1, vert(kvert)%noc ! all cells around vertex
vert(kvert)%updated(jc) = 0
enddo
enddo
!
do kvert = 1, nverts
!
! in case of non-active vertex set action density equal to zero
!
if ( .not.vert(kvert)%active ) then
!
do jc = 1, vert(kvert)%noc
icell = vert(kvert)%cell(jc)%atti(CELLID)
vert(kvert)%updated(jc) = icell
enddo
!
ac2(:,:,kvert) = 0.
!
endif
!
enddo
!$omp end master
!
! synchronize threads before loop over sweep directions
!$omp barrier
!
!$omp single
if ( SCREEN /= PRINTF ) then
if ( NSTATC == 1 ) then
if ( IAMMASTER ) write (SCREEN,110) CHTIME, it, iter
else
write (PRINTF,120) iter
if ( IAMMASTER ) write (SCREEN,120) iter
endif
endif
!$omp end single
!
! loop over a fixed number of sweeps through grid
!
if ( iter < itswp ) then
n = nsweep
elseif ( .not.FULCIR ) then
n = nsweep
else
n = 1
endif
!
sdir = asort + PI/real(n)
!
sweeploop: do swpdir = 1, n
!
! compute load-balanced spatial loop bounds for each thread
!
!$ call SwanThreadBounds( nwetp, ivlow, ivup, tlist, swpdir )
!
! loop over vertices in the grid
!
vertloop: do kvert = ivlow, ivup
!
ivert = vlist(kvert,swpdir)
!$ ivert = tlist(kvert)
!ADC !
!ADC ! allow SWAN to handle wave refraction as a nodal attribute
!ADC if ( LoadSwanWaveRefrac .and. FoundSwanWaveRefrac ) then
!ADC IREFR = nint(SwanWaveRefrac(ivert))
!ADC endif
!
if ( vert(ivert)%active ) then ! this active vertex needs to be updated
!
! determine whether the present vertex is a test point
!
IPTST = 0
TESTFL = .false.
if ( NPTST > 0 ) then
do j = 1, NPTST
if ( ivert /= xytst(j) ) cycle
IPTST = j
TESTFL = .true.
enddo
endif
!
! compute gradients of depth or wave number in present vertex meant for computing turning rate
!
call SwanGradDepthorK ( compda(1,JDP2), compda(1,JMUDL2), spcsig, dhdx, dhdy, dkdx, dkdy, ivert )
!
! compute the derivatives of the ambient current for computing transport velocities in spectral space
!
if ( ICUR /= 0 ) then
!
call SwanGradVel ( compda(1,JDP2), compda(1,JVX2), compda(1,JVY2), duxdx, duxdy, duydx, duydy, ivert )
!
endif
!
celloop: do jc = 1, vert(ivert)%noc
!
icell = vert(ivert)%cell(jc)%atti(CELLID)
!
v(1) = cell(icell)%atti(CELLV1)
v(2) = cell(icell)%atti(CELLV2)
v(3) = cell(icell)%atti(CELLV3)
!
! pick up two upwave vertices
!
do k = 1, 3
if ( v(k) == ivert ) then
vu(1) = v(mod(k ,3)+1)
vu(2) = v(mod(k+1,3)+1)
exit
endif
enddo
!
! stores vertices of computational stencil
!
vs(1) = ivert
vs(2) = vu(1)
vs(3) = vu(2)
!
KCGRD = vs ! to be used in some original SWAN routines
!
swpnr = 0 ! this trick assures to calculate Ursell number and
if ( all(mask=vert(ivert)%updated(:)==0) ) swpnr = 1 ! quadruplets only once in each vertex during an iteration
!
! compute wavenumber and group velocity in points of stencil
!
!TIMG call SWTSTA(110)
call SwanDispParm ( kwave, cgo, dmw, compda(1,JDP2), compda(1,JMUDL2), spcsig )
!TIMG call SWTSTO(110)
!
! compute wave transport velocities in points of stencil for all directions
!
!TIMG call SWTSTA(111)
call SwanPropvelX ( cax, cay, compda(1,JVX2), compda(1,JVY2), cgo, spcdir(1,2), spcdir(1,3) )
!TIMG call SWTSTO(111)
!
! get local contravariant base vectors and their directions at present vertex
!
do k = 1, 3
if ( v(k) == ivert ) then
rdx(1) = cell(icell)%geom(k)%rdx1
rdx(2) = cell(icell)%geom(k)%rdx2
rdy(1) = cell(icell)%geom(k)%rdy1
rdy(2) = cell(icell)%geom(k)%rdy2
th1 = cell(icell)%geom(k)%th1
th2 = cell(icell)%geom(k)%th2
exit
endif
enddo
!
! in case of spherical coordinates determine cosine of latitude (in degrees)
! and recalculate local contravariant base vectors
!
if ( KSPHER > 0 ) then
do k = 1, ICMAX
COSLAT(k) = cos(DEGRAD*(vert(vs(k))%attr(VERTY) + YOFFS))
enddo
do j = 1, 2
rdx(j) = rdx(j) / (COSLAT(1) * LENDEG)
rdy(j) = rdy(j) / LENDEG
enddo
endif
!
! check out of bounds of face directions of present cell
!
if ( th1 < asort .and. th2 < asort ) then
th1 = th1 + PI2
th2 = th2 + PI2
endif
!
if ( th1 > asort+PI2 .and. th2 > asort+PI2 ) then
th1 = th1 - PI2
th2 = th2 - PI2
endif
!
! compute bounds of present sweep
!
thmin = sdir - PI/real(n)
thmax = sdir + PI/real(n)
!
if ( th1 < asort .and. swpdir == n ) then
thmin = thmin - PI2
thmax = thmax - PI2
endif
!
if ( th2 > asort+PI2 .and. swpdir == 1 ) then
thmin = thmin + PI2
thmax = thmax + PI2
endif
!
! in case no intersection of present cell and sweep, cycle to next cell
!
if ( ( thmin < th1 .and. thmax < th1 ) .or. &
( thmin > th2 .and. thmax > th2 ) ) cycle celloop
!
! compute spectral directions for the considered sweep in present vertex
!
!TIMG call SWTSTA(112)
call SwanSweepSel ( idcmin, idcmax, anybin, iscmin, iscmax, &
iddlow, iddtop, idtot , isslow, isstop, &
istot , cax , cay , rdx , rdy , &
spcsig)
!TIMG call SWTSTO(112)
!
if ( idtot > 0 ) then
!
! compute propagation velocities in spectral space for the considered sweep in present vertex
!
!TIMG call SWTSTA(113)