-
Notifications
You must be signed in to change notification settings - Fork 0
/
wwm_snl42.F90
804 lines (724 loc) · 28.1 KB
/
wwm_snl42.F90
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
#include "wwm_functions.h"
! Last change: 1 20 Apr 2004 2:05 am
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE PARAMETER4SNL2()
USE DATAPOOL
IMPLICIT NONE
INTEGER :: IS
REAL(rkind) :: AUX1, FREQ
REAL(rkind) :: LAMBDA, LAMM2, LAMP2
REAL(rkind) :: DELTH3, DELTH4
INTEGER :: IDP, IDP1, IDM, IDM1
REAL(rkind) :: CIDP, WIDP, WIDP1, CIDM, WIDM, WIDM1
INTEGER :: ISP, ISP1, ISM, ISM1
REAL(rkind) :: WISP, WISP1, WISM, WISM1
REAL(rkind) :: AWG1, AWG2, AWG3, AWG4, AWG5, AWG6, AWG7, AWG8
REAL(rkind) :: SWG1, SWG2, SWG3, SWG4, SWG5, SWG6, SWG7, SWG8
INTEGER :: ISLOW, ISHGH, ISCLW, ISCHG, IDLOW, IDHGH
!
! *** set values for the nonlinear four-wave interactions ***
!
LAMBDA = PQUAD(1)
LAMM2 = (1.0-LAMBDA)**2.0
LAMP2 = (1.0+LAMBDA)**2.0
DELTH3 = ACOS((LAMM2**2.0+4.0-LAMP2**2.0)/(4.0*LAMM2))
AUX1 = SIN(DELTH3)
DELTH4 = ASIN(-AUX1*LAMM2/LAMP2)
!
! *** Compute directional indices in sigma and theta space ***
!
CIDP = ABS(DELTH4/DDIR)
IDP = INT(CIDP)
IDP1 = IDP + 1
WIDP = CIDP - MyREAL(IDP)
WIDP1 = 1.0 - WIDP
CIDM = ABS(DELTH3/DDIR)
IDM = INT(CIDM)
IDM1 = IDM + 1
WIDM = CIDM - MyREAL(IDM)
WIDM1 = 1.0 - WIDM
ISP = INT(LOG(1.0+LAMBDA)/XISLN)
ISP1 = ISP + 1
WISP = (1.0+LAMBDA-XIS**ISP)/(XIS**ISP1-XIS**ISP)
WISP1 = 1.0 - WISP
ISM = INT(LOG(1.0-LAMBDA)/XISLN)
ISM1 = ISM - 1
WISM = (XIS**ISM-(1.0-LAMBDA))/(XIS**ISM-XIS**ISM1)
WISM1 = 1.0 - WISM
!
! *** Range of calculations ***
!
ISLOW = 1 + ISM1
ISHGH = MSC + ISP1 - ISM1
ISCLW = 1
ISCHG = MSC - ISM1
IDLOW = 1 - MAX(IDM1,IDP1)
IDHGH = MDC + MAX(IDM1,IDP1)
MSC4MI = ISLOW
MSC4MA = ISHGH
MDC4MI = IDLOW
MDC4MA = IDHGH
MSCMAX = MSC4MA - MSC4MI + 1
MDCMAX = MDC4MA - MDC4MI + 1
!
! *** Interpolation weights ***
!
AWG1 = WIDP *WISP
AWG2 = WIDP1*WISP
AWG3 = WIDP *WISP1
AWG4 = WIDP1*WISP1
AWG5 = WIDM *WISM
AWG6 = WIDM1*WISM
AWG7 = WIDM *WISM1
AWG8 = WIDM1*WISM1
!
! *** quadratic interpolation
!
SWG1 = AWG1**2.0
SWG2 = AWG2**2.0
SWG3 = AWG3**2.0
SWG4 = AWG4**2.0
SWG5 = AWG5**2.0
SWG6 = AWG6**2.0
SWG7 = AWG7**2.0
SWG8 = AWG8**2.0
!
! *** fill the arrays
!
WWINT(1) = IDP
WWINT(2) = IDP1
WWINT(3) = IDM
WWINT(4) = IDM1
WWINT(5) = ISP
WWINT(6) = ISP1
WWINT(7) = ISM
WWINT(8) = ISM1
WWINT(9) = ISLOW
WWINT(10) = ISHGH
WWINT(11) = ISCLW
WWINT(12) = ISCHG
WWINT(13) = IDLOW
WWINT(14) = IDHGH
WWINT(15) = MSC4MI
WWINT(16) = MSC4MA
WWINT(17) = MDC4MI
WWINT(18) = MDC4MA
WWINT(19) = MSCMAX
WWINT(20) = MDCMAX
WWAWG(1) = AWG1
WWAWG(2) = AWG2
WWAWG(3) = AWG3
WWAWG(4) = AWG4
WWAWG(5) = AWG5
WWAWG(6) = AWG6
WWAWG(7) = AWG7
WWAWG(8) = AWG8
WWSWG(1) = SWG1
WWSWG(2) = SWG2
WWSWG(3) = SWG3
WWSWG(4) = SWG4
WWSWG(5) = SWG5
WWSWG(6) = SWG6
WWSWG(7) = SWG7
WWSWG(8) = SWG8
!
! *** Fill scaling array (f**11) ***
! *** compute the radian frequency**11 for IS=ISHGH, ISLOW ***
!
IF (LTEST) THEN
WRITE(STAT % FHNDL,*) 'PARAMETERS FOR SNL'
WRITE(STAT % FHNDL,*) IDP, IDP1, IDM, IDM1
WRITE(STAT % FHNDL,*) ISP, ISP1, ISM, ISM1
WRITE(STAT % FHNDL,*) ISLOW, ISHGH, ISCLW, ISCHG, IDLOW, IDHGH
WRITE(STAT % FHNDL,*) XIS
WRITE(STAT % FHNDL,*) AWG1, AWG2, AWG3, AWG4
WRITE(STAT % FHNDL,*) AWG5, AWG6, AWG7, AWG8
WRITE(STAT % FHNDL,*) '---------------------------------------'
END IF
!
IF (ALLOCATED (AF11)) DEALLOCATE (AF11)
ALLOCATE( AF11(MSC4MI:MSC4MA), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_snl42, allocate error 1')
DO IS = 1, MSC
AF11(IS) = (SPSIG(IS)/PI2)**11.0
END DO
FREQ = SPSIG(MSC)/PI2
DO IS = MSC+1, ISHGH
FREQ = FREQ*XIS
AF11(IS) = FREQ**11.0
END DO
FREQ = SPSIG(1)/PI2
DO IS = 0, ISLOW, -1
FREQ = FREQ/XIS
AF11(IS) = FREQ**11.0
END DO
RETURN
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE SNL41(IP,KMESPC, ACLOC, IMATRA, IMATDA, SFNL, DSNL)
USE DATAPOOL
IMPLICIT NONE
INTEGER, INTENT(IN) :: IP
REAL(rkind), INTENT(IN) :: KMESPC
REAL(rkind), INTENT(IN) :: ACLOC(MSC,MDC)
REAL(rkind), INTENT(INOUT) :: IMATRA(MSC,MDC), IMATDA(MSC,MDC)
REAL(rkind), INTENT(OUT) :: SFNL(MSC,MDC), DSNL(MSC,MDC)
INTEGER :: ISHGH, ISCLW, ISCHG, IDLOW, IDHGH
INTEGER :: IDP, IDP1, IDM, IDM1
INTEGER :: ISP, ISP1, ISM, ISM1
INTEGER :: I, J, IS, ID, ID0, IDDUM
REAL(rkind) :: AWG1, AWG2, AWG3, AWG4, AWG5, AWG6, AWG7, AWG8
REAL(rkind) :: SWG1, SWG2, SWG3, SWG4, SWG5, SWG6, SWG7, SWG8
REAL(rkind) :: AUX, AUX2
REAL(rkind) :: SNLC1, SNLCS1, SNLCS2, SNLCS3, CONS, FACTOR
REAL(rkind) :: JACOBI, SIGPI, PI3
REAL(rkind) :: FACHFR, PWTAIL
REAL(rkind) :: LAMBDA
REAL(rkind) :: E00, EP1, EM1, EP2, EM2
REAL(rkind) :: SA1A, SA1B, SA2A, SA2B
REAL(rkind) :: UE(MSC4MI:MSC4MA, MDC4MI:MDC4MA)
REAL(rkind) :: SA1(MSC4MI:MSC4MA, MDC4MI:MDC4MA)
REAL(rkind) :: SA2(MSC4MI:MSC4MA, MDC4MI:MDC4MA)
REAL(rkind) :: DA1C(MSC4MI:MSC4MA, MDC4MI:MDC4MA)
REAL(rkind) :: DA1P(MSC4MI:MSC4MA, MDC4MI:MDC4MA)
REAL(rkind) :: DA1M(MSC4MI:MSC4MA, MDC4MI:MDC4MA)
REAL(rkind) :: DA2C(MSC4MI:MSC4MA, MDC4MI:MDC4MA)
REAL(rkind) :: DA2P(MSC4MI:MSC4MA, MDC4MI:MDC4MA)
REAL(rkind) :: DA2M(MSC4MI:MSC4MA, MDC4MI:MDC4MA)
IDP = WWINT(1)
IDP1 = WWINT(2)
IDM = WWINT(3)
IDM1 = WWINT(4)
ISP = WWINT(5)
ISP1 = WWINT(6)
ISM = WWINT(7)
ISM1 = WWINT(8)
ISHGH = WWINT(10)
ISCLW = WWINT(11)
ISCHG = WWINT(12)
IDLOW = WWINT(13)
IDHGH = WWINT(14)
AWG1 = WWAWG(1)
AWG2 = WWAWG(2)
AWG3 = WWAWG(3)
AWG4 = WWAWG(4)
AWG5 = WWAWG(5)
AWG6 = WWAWG(6)
AWG7 = WWAWG(7)
AWG8 = WWAWG(8)
SWG1 = WWSWG(1)
SWG2 = WWSWG(2)
SWG3 = WWSWG(3)
SWG4 = WWSWG(4)
SWG5 = WWSWG(5)
SWG6 = WWSWG(6)
SWG7 = WWSWG(7)
SWG8 = WWSWG(8)
UE(:,:) = 0.0
SA1(:,:) = 0.0
SA2(:,:) = 0.0
SFNL(:,:) = 0.0
DA1C(:,:) = 0.0
DA1P(:,:) = 0.0
DA1M(:,:) = 0.0
DA2C(:,:) = 0.0
DA2P(:,:) = 0.0
DA2M(:,:) = 0.0
DSNL(:,:) = 0.0
PWTAIL = PTAIL(1)
!
! *** Calculate factor R(X) to calculate the NL wave-wave ***
! *** interaction for shallow water ***
! *** SNLC1 = CONSTANT * GRAV**-4 (CONSTANT = 3.E7) ***
!
JACOBI = PI2
LAMBDA = PQUAD(1)
DAL1 = 1.0 / (1.0 + LAMBDA)**4.0
DAL2 = 1.0 / (1.0 - LAMBDA)**4.0
DAL3 = 2.0 * DAL1 * DAL2
SNLC1 = 1.0 / (G9**4.0)
SNLCS1 = PQUAD(3)
SNLCS2 = PQUAD(4)
SNLCS3 = PQUAD(5)
AUX = MAX(DEP(IP)*KMESPC,1.3_rkind)
AUX2 = MAX ( -1.E15_rkind, SNLCS3*AUX)
CONS = SNLC1 * ( 1. + SNLCS1/AUX * (1.-SNLCS2*AUX) * EXP(AUX2))
UE = 0.
SA1 = 0.
SA2 = 0.
SFNL = 0.
DA1C = 0.
DA1P = 0.
DA1M = 0.
DA2C = 0.
DA2P = 0.
DA2M = 0.
DSNL = 0.
!
! High frequency factor:
!
FACHFR = 1.0 / (XIS**PWTAIL)
!
! *** Prepare auxiliary spectrum ***
! *** set action original spectrum in array UE ***
!
DO IDDUM = IDLOW, IDHGH
ID = MOD( IDDUM - 1 + MDC, MDC ) + 1
DO IS = 1, MSC
UE(IS,IDDUM) = ACLOC(IS,ID) * SPSIG(IS) * JACOBI
END DO
END DO
DO IS = MSC+1, ISHGH
DO ID = IDLOW, IDHGH
UE(IS,ID) = UE(IS-1,ID)*FACHFR
END DO
END DO
!
! *** Calculate interactions ***
! *** Energy at interacting bins ***
!
DO IS = ISCLW, ISCHG
DO ID = 1, MDC
E00 = UE(IS ,ID )
EP1 = AWG1 * UE(IS+ISP1,ID+IDP1) + &
& AWG2 * UE(IS+ISP1,ID+IDP ) + &
& AWG3 * UE(IS+ISP ,ID+IDP1) + &
& AWG4 * UE(IS+ISP ,ID+IDP )
EM1 = AWG5 * UE(IS+ISM1,ID-IDM1) + &
& AWG6 * UE(IS+ISM1,ID-IDM ) + &
& AWG7 * UE(IS+ISM ,ID-IDM1) + &
& AWG8 * UE(IS+ISM ,ID-IDM )
EP2 = AWG1 * UE(IS+ISP1,ID-IDP1) + &
& AWG2 * UE(IS+ISP1,ID-IDP ) + &
& AWG3 * UE(IS+ISP ,ID-IDP1) + &
& AWG4 * UE(IS+ISP ,ID-IDP )
EM2 = AWG5 * UE(IS+ISM1,ID+IDM1) + &
& AWG6 * UE(IS+ISM1,ID+IDM ) + &
& AWG7 * UE(IS+ISM ,ID+IDM1) + &
& AWG8 * UE(IS+ISM ,ID+IDM )
!
SA1A = E00 * ( EP1*DAL1 + EM1*DAL2 ) * PQUAD(2)
SA1B = SA1A - EP1*EM1*DAL3 * PQUAD(2)
SA2A = E00 * ( EP2*DAL1 + EM2*DAL2 ) * PQUAD(2)
SA2B = SA2A - EP2*EM2*DAL3 * PQUAD(2)
FACTOR = CONS * AF11(IS) * E00
SA1(IS,ID) = FACTOR*SA1B
SA2(IS,ID) = FACTOR*SA2B
DA1C(IS,ID) = CONS * AF11(IS) * ( SA1A + SA1B )
DA1P(IS,ID) = FACTOR * ( DAL1*E00 - DAL3*EM1 ) * PQUAD(2)
DA1M(IS,ID) = FACTOR * ( DAL2*E00 - DAL3*EP1 ) * PQUAD(2)
DA2C(IS,ID) = CONS * AF11(IS) * ( SA2A + SA2B )
DA2P(IS,ID) = FACTOR * ( DAL1*E00 - DAL3*EM2 ) * PQUAD(2)
DA2M(IS,ID) = FACTOR * ( DAL2*E00 - DAL3*EP2 ) * PQUAD(2)
END DO
END DO
!
! *** Fold interactions to side angles if spectral domain ***
! *** is periodic in directional space ***
!
DO ID = 1, IDHGH - MDC
ID0 = 1 - ID
DO IS = ISCLW, ISCHG
SA1 (IS,MDC+ID) = SA1 (IS,ID )
SA2 (IS,MDC+ID) = SA2 (IS,ID )
DA1C(IS,MDC+ID) = DA1C(IS,ID )
DA1P(IS,MDC+ID) = DA1P(IS,ID )
DA1M(IS,MDC+ID) = DA1M(IS,ID )
DA2C(IS,MDC+ID) = DA2C(IS,ID )
DA2P(IS,MDC+ID) = DA2P(IS,ID )
DA2M(IS,MDC+ID) = DA2M(IS,ID )
SA1 (IS,ID0 ) = SA1 (IS,MDC+ID0)
SA2 (IS,ID0 ) = SA2 (IS,MDC+ID0)
DA1C(IS,ID0 ) = DA1C(IS,MDC+ID0)
DA1P(IS,ID0 ) = DA1P(IS,MDC+ID0)
DA1M(IS,ID0 ) = DA1M(IS,MDC+ID0)
DA2C(IS,ID0 ) = DA2C(IS,MDC+ID0)
DA2P(IS,ID0 ) = DA2P(IS,MDC+ID0)
DA2M(IS,ID0 ) = DA2M(IS,MDC+ID0)
END DO
END DO
!
! *** Put source term together ***
!
PI3 = ( PI2 )**3.0
DO I = 1, MSC
SIGPI = SPSIG(I) * JACOBI
DO J = 1, MDC
SFNL(I,J) = -2.0 * ( SA1(I,J) + SA2(I,J) ) &
& + AWG1 * ( SA1(I-ISP1,J-IDP1) + SA2(I-ISP1,J+IDP1) ) &
& + AWG2 * ( SA1(I-ISP1,J-IDP ) + SA2(I-ISP1,J+IDP ) ) &
& + AWG3 * ( SA1(I-ISP ,J-IDP1) + SA2(I-ISP ,J+IDP1) ) &
& + AWG4 * ( SA1(I-ISP ,J-IDP ) + SA2(I-ISP ,J+IDP ) ) &
& + AWG5 * ( SA1(I-ISM1,J+IDM1) + SA2(I-ISM1,J-IDM1) ) &
& + AWG6 * ( SA1(I-ISM1,J+IDM ) + SA2(I-ISM1,J-IDM ) ) &
& + AWG7 * ( SA1(I-ISM ,J+IDM1) + SA2(I-ISM ,J-IDM1) ) &
& + AWG8 * ( SA1(I-ISM ,J+IDM ) + SA2(I-ISM ,J-IDM ) )
DSNL(I,J) = -2.0 * ( DA1C(I,J) + DA2C(I,J) ) &
& + SWG1 * ( DA1P(I-ISP1,J-IDP1) + DA2P(I-ISP1,J+IDP1) ) &
& + SWG2 * ( DA1P(I-ISP1,J-IDP ) + DA2P(I-ISP1,J+IDP ) ) &
& + SWG3 * ( DA1P(I-ISP ,J-IDP1) + DA2P(I-ISP ,J+IDP1) ) &
& + SWG4 * ( DA1P(I-ISP ,J-IDP ) + DA2P(I-ISP ,J+IDP ) ) &
& + SWG5 * ( DA1M(I-ISM1,J+IDM1) + DA2M(I-ISM1,J-IDM1) ) &
& + SWG6 * ( DA1M(I-ISM1,J+IDM ) + DA2M(I-ISM1,J-IDM ) ) &
& + SWG7 * ( DA1M(I-ISM ,J+IDM1) + DA2M(I-ISM ,J-IDM1) ) &
& + SWG8 * ( DA1M(I-ISM ,J+IDM ) + DA2M(I-ISM ,J-IDM ) )
IF (ICOMP .GE. 2) THEN
IMATRA(I,J) = IMATRA(I,J) + SFNL(I,J) / SIGPI
IMATDA(I,J) = IMATDA(I,J) - DSNL(I,J) / PI3
ELSE
IMATRA(I,J) = IMATRA(I,J) + SFNL(I,J) / SIGPI
IMATDA(I,J) = IMATDA(I,J) + DSNL(I,J) / PI3
END IF
END DO
END DO
RETURN
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE SNL42(IP, KMESPC, ACLOC, IMATRA, IMATDA)
USE DATAPOOL
IMPLICIT NONE
INTEGER :: IP
REAL(rkind) :: KMESPC
REAL(rkind), INTENT(INOUT) :: IMATRA(MSC,MDC), IMATDA(MSC,MDC)
REAL(rkind), INTENT(IN) :: ACLOC(MSC,MDC)
REAL(rkind) :: PWTAIL, FACHFR
REAL(rkind) :: LAMBDA
REAL(rkind) :: SNLC1, SNLCS1, SNLCS2, SNLCS3
REAL(rkind) :: CONS, FACTOR
INTEGER :: K3SF, K3SB, K4SF, K4SB
INTEGER :: K3D1, K3D2, K3D3, K3D4
INTEGER :: K4D1, K4D2, K4D3, K4D4
INTEGER :: ISHGH, ISCLO, ISCHG, IDLOW, IDHGH
INTEGER :: IDP, IDP1, IDM, IDM1
INTEGER :: ISP, ISP1, ISM, ISM1
INTEGER :: IS, ID, ID0
REAL(rkind) :: AWG1, AWG2, AWG3, AWG4, AWG5, AWG6, AWG7, AWG8
REAL(rkind) :: E00, EP1, EM1, EP2, EM2, SIGPI2
REAL(rkind) :: SA11, SA22, AUX, AUX2
REAL(rkind) :: SA1A, SA1B, SA2A, SA2B, SFNL(MSC,MDC)
REAL(rkind) :: UE(MSC4MI:MSC4MA, MDC4MI:MDC4MA)
IDP = WWINT(1)
IDP1 = WWINT(2)
IDM = WWINT(3)
IDM1 = WWINT(4)
ISP = WWINT(5)
ISP1 = WWINT(6)
ISM = WWINT(7)
ISM1 = WWINT(8)
ISHGH = WWINT(10)
ISCLO = WWINT(11)
ISCHG = WWINT(12)
IDLOW = WWINT(13)
IDHGH = WWINT(14)
AWG1 = WWAWG(1)
AWG2 = WWAWG(2)
AWG3 = WWAWG(3)
AWG4 = WWAWG(4)
AWG5 = WWAWG(5)
AWG6 = WWAWG(6)
AWG7 = WWAWG(7)
AWG8 = WWAWG(8)
UE(:,:) = 0.0
SFNL(:,:) = 0.0
!
! *** Calculate factor R(X) to calculate the NL wave-wave ***
! *** interaction for shallow water ***
! *** SNLC1 = CONSTANT * GRAV**-4 (CONSTANT = 3.E7) ***
!
PWTAIL = PTAIL(1)
LAMBDA = PQUAD(1)
DAL1 = 1.0/(1.0+LAMBDA)**4.0
DAL2 = 1.0/(1.0-LAMBDA)**4.0
DAL3 = 2.0*DAL1*DAL2
SNLC1 = PQUAD(2)/G9**4.0
SNLCS1 = PQUAD(3)
SNLCS2 = PQUAD(4)
SNLCS3 = PQUAD(5)
AUX = MAX(DEP(IP)*KMESPC,1.3_rkind)
AUX2 = MAX ( -1.E15_rkind, SNLCS3*AUX)
CONS = SNLC1 * ( 1.0_rkind + SNLCS1/AUX * (1.-SNLCS2*AUX) * EXP(AUX2))
FACHFR = 1.0/XIS**PWTAIL
DO ID = 1, MDC
DO IS = 1, MSC
UE(IS,ID) = ACLOC(IS,ID)*SPSIG(IS)*PI2
END DO
END DO
DO ID = 1, IDHGH - MDC
ID0 = 1 - ID
DO IS = 1, MSC
UE(IS,MDC+ID) = UE(IS,ID )
UE(IS,ID0 ) = UE(IS,MDC+ID0)
END DO
END DO
DO IS = MSC + 1, ISHGH
DO ID = IDLOW, IDHGH
UE(IS,ID) = UE(IS-1,ID)*FACHFR
END DO
END DO
DO IS = ISCLO, ISCHG
DO ID = 1, MDC
K3SF = IS+ISP1
K3SB = IS+ISP
K4SF = IS+ISM1
K4SB = IS+ISM
K3D1 = ID+IDP1
K3D2 = ID+IDP
K4D1 = ID-IDM1
K4D2 = ID-IDM
K3D3 = ID-IDP1
K3D4 = ID-IDP
K4D3 = ID+IDM1
K4D4 = ID+IDM
E00 = UE(IS,ID)
EP1 = AWG1 * UE(K3SF ,K3D1 ) &
& +AWG2 * UE(K3SF ,K3D2 ) &
& +AWG3 * UE(K3SB ,K3D1 ) &
& +AWG4 * UE(K3SB ,K3D2 )
EM1 = AWG5 * UE(K4SF ,K4D1 ) &
& +AWG6 * UE(K4SF ,K4D2 ) &
& +AWG7 * UE(K4SB ,K4D1 ) &
& +AWG8 * UE(K4SB ,K4D2 )
EP2 = AWG1 * UE(K3SF ,K3D3 ) &
& +AWG2 * UE(K3SF ,K3D4 ) &
& +AWG3 * UE(K3SB ,K3D3 ) &
& +AWG4 * UE(K3SB ,K3D4 )
EM2 = AWG5 * UE(K4SF ,K4D3 ) &
& +AWG6 * UE(K4SF ,K4D4 ) &
& +AWG7 * UE(K4SB ,K4D3 ) &
& +AWG8 * UE(K4SB ,K4D4 )
FACTOR = CONS*AF11(IS)*E00
SA1A = E00*(EP1*DAL1+EM1*DAL2)
SA1B = SA1A-EP1*EM1*DAL3
SA2A = E00*(EP2*DAL1+EM2*DAL2)
SA2B = SA2A-EP2*EM2*DAL3
SA11 = FACTOR*SA1B
SA22 = FACTOR*SA2B
IF ((IS >= 1) .AND. (IS <= MSC)) THEN
SFNL(IS,ID) = SFNL(IS,ID) - 2.0 * ( SA11 + SA22 )
END IF
IF (K3D1 > MDC) K3D1 = K3D1 - MDC
IF (K3D2 > MDC) K3D2 = K3D2 - MDC
IF (K4D1 < 1 ) K4D1 = MDC + K4D1
IF (K4D2 < 1 ) K4D2 = MDC + K4D2
IF (K3D3 < 1 ) K3D3 = MDC + K3D3
IF (K3D4 < 1 ) K3D4 = MDC + K3D4
IF (K4D3 > MDC) K4D3 = K4D3 - MDC
IF (K4D4 > MDC) K4D4 = K4D4 - MDC
IF ((K3SF >= 1) .AND. (K3SF <= MSC) .AND. (K3SB >= 1) .AND. (K3SB <= MSC)) THEN
SFNL(K3SF,K3D1) = SFNL(K3SF,K3D1) + AWG1 * SA11
SFNL(K3SF,K3D2) = SFNL(K3SF,K3D2) + AWG2 * SA11
SFNL(K3SB,K3D1) = SFNL(K3SB,K3D1) + AWG3 * SA11
SFNL(K3SB,K3D2) = SFNL(K3SB,K3D2) + AWG4 * SA11
SFNL(K3SF,K3D3) = SFNL(K3SF,K3D3) + AWG1 * SA22
SFNL(K3SF,K3D4) = SFNL(K3SF,K3D4) + AWG2 * SA22
SFNL(K3SB,K3D3) = SFNL(K3SB,K3D3) + AWG3 * SA22
SFNL(K3SB,K3D4) = SFNL(K3SB,K3D4) + AWG4 * SA22
END IF
IF ((K4SF >= 1) .AND. (K4SF <= MSC) .AND. (K4SB >= 1) .AND. (K4SB <= MSC)) THEN
SFNL(K4SF,K4D1) = SFNL(K4SF,K4D1) + AWG5 * SA11
SFNL(K4SF,K4D2) = SFNL(K4SF,K4D2) + AWG6 * SA11
SFNL(K4SB,K4D1) = SFNL(K4SB,K4D1) + AWG7 * SA11
SFNL(K4SB,K4D2) = SFNL(K4SB,K4D2) + AWG8 * SA11
SFNL(K4SF,K4D3) = SFNL(K4SF,K4D3) + AWG5 * SA22
SFNL(K4SF,K4D4) = SFNL(K4SF,K4D4) + AWG6 * SA22
SFNL(K4SB,K4D3) = SFNL(K4SB,K4D3) + AWG7 * SA22
SFNL(K4SB,K4D4) = SFNL(K4SB,K4D4) + AWG8 * SA22
END IF
END DO
END DO
!
! *** SFNL -> energy density, IMATRA -> action density
!
DO IS = 1, MSC
SIGPI2 = SPSIG(IS)*PI2
DO ID = 1, MDC
IF (ICOMP >= 2) THEN
IF (SFNL(IS,ID).GT.0.) THEN
IMATRA(IS,ID) = IMATRA(IS,ID) + SFNL(IS,ID) / SIGPI2
ELSE
IMATDA(IS,ID) = IMATDA(IS,ID) - SFNL(IS,ID) / MAX(1.E-18_rkind,ACLOC(IS,ID)*SIGPI2)
END IF
ELSE
IMATRA(IS,ID) = IMATRA(IS,ID) + SFNL(IS,ID) / SIGPI2
IMATDA(IS,ID) = IMATDA(IS,ID) + SFNL(IS,ID) / MAX(1.E-18_rkind,ACLOC(IS,ID)*SIGPI2)
END IF
END DO
END DO
RETURN
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE SNL43(IP,KMESPC, ACLOC, IMATRA, IMATDA)
USE DATAPOOL
IMPLICIT NONE
INTEGER, INTENT(IN) :: IP
REAL(rkind), INTENT(IN) :: KMESPC
REAL(rkind), INTENT(IN) :: ACLOC(MSC,MDC)
REAL(rkind), INTENT(INOUT) :: IMATRA(MSC,MDC), IMATDA(MSC,MDC)
INTEGER :: ISHGH, ISCLW, ISCHG, IDLOW, IDHGH
INTEGER :: IDP, IDP1, IDM, IDM1
INTEGER :: ISP, ISP1, ISM, ISM1
INTEGER :: I, J, IS, ID, ID0, IDDUM
REAL(rkind) :: AWG1, AWG2, AWG3, AWG4, AWG5, AWG6, AWG7, AWG8
REAL(rkind) :: AUX, AUX2
REAL(rkind) :: SNLC1, SNLCS1, SNLCS2, SNLCS3, CONS, FACTOR
REAL(rkind) :: JACOBI, SIGPI
REAL(rkind) :: FACHFR, PWTAIL
REAL(rkind) :: LAMBDA
REAL(rkind) :: E00, EP1, EM1, EP2, EM2
REAL(rkind) :: SA1A, SA1B, SA2A, SA2B, SFNL(MSC,MDC)
REAL(rkind) :: UE(MSC4MI:MSC4MA, MDC4MI:MDC4MA)
REAL(rkind) :: SA1(MSC4MI:MSC4MA, MDC4MI:MDC4MA)
REAL(rkind) :: SA2(MSC4MI:MSC4MA, MDC4MI:MDC4MA)
IDP = WWINT(1)
IDP1 = WWINT(2)
IDM = WWINT(3)
IDM1 = WWINT(4)
ISP = WWINT(5)
ISP1 = WWINT(6)
ISM = WWINT(7)
ISM1 = WWINT(8)
ISHGH = WWINT(10)
ISCLW = WWINT(11)
ISCHG = WWINT(12)
IDLOW = WWINT(13)
IDHGH = WWINT(14)
AWG1 = WWAWG(1)
AWG2 = WWAWG(2)
AWG3 = WWAWG(3)
AWG4 = WWAWG(4)
AWG5 = WWAWG(5)
AWG6 = WWAWG(6)
AWG7 = WWAWG(7)
AWG8 = WWAWG(8)
UE(:,:) = 0.0
SA1(:,:) = 0.0
SA2(:,:) = 0.0
SFNL(:,:) = 0.0
PWTAIL = PTAIL(1)
!
! *** Calculate factor R(X) to calculate the SNL4 wave-wave ***
! *** interaction for shallow water ***
! *** SNLC1 = CONSTANT * GRAV**-4 (CONSTANT = 3.E7) ***
!
JACOBI = PI2
LAMBDA = PQUAD(1)
DAL1 = 1.0 / (1.0 + LAMBDA)**4.0
DAL2 = 1.0 / (1.0 - LAMBDA)**4.0
DAL3 = 2.0 * DAL1 * DAL2
SNLC1 = 1.0 / (G9**4.0)
SNLCS1 = PQUAD(3)
SNLCS2 = PQUAD(4)
SNLCS3 = PQUAD(5)
AUX = MAX(DEP(IP)*KMESPC,1.3_rkind)
AUX2 = MAX ( -1.E15_rkind, SNLCS3*AUX)
CONS = SNLC1 * ( 1. + SNLCS1/AUX * (1.-SNLCS2*AUX) * EXP(AUX2))
UE = 0.
SA1 = 0.
SA2 = 0.
SFNL = 0.
!
! High frequency factor:
!
FACHFR = 1.0 / (XIS**PWTAIL)
!
! *** Prepare auxiliary spectrum ***
! *** set action original spectrum in array UE ***
!
DO IDDUM = IDLOW, IDHGH
ID = MOD( IDDUM - 1 + MDC, MDC ) + 1
DO IS = 1, MSC
UE(IS,IDDUM) = ACLOC(IS,ID) * SPSIG(IS) * JACOBI
END DO
END DO
DO IS = MSC+1, ISHGH
DO ID = IDLOW, IDHGH
UE(IS,ID) = UE(IS-1,ID)*FACHFR
END DO
END DO
!
! *** Calculate interactions ***
! *** Energy at interacting bins ***
!
DO IS = ISCLW, ISCHG
DO ID = 1, MDC
E00 = UE(IS ,ID )
EP1 = AWG1 * UE(IS+ISP1,ID+IDP1) + &
& AWG2 * UE(IS+ISP1,ID+IDP ) + &
& AWG3 * UE(IS+ISP ,ID+IDP1) + &
& AWG4 * UE(IS+ISP ,ID+IDP )
EM1 = AWG5 * UE(IS+ISM1,ID-IDM1) + &
& AWG6 * UE(IS+ISM1,ID-IDM ) + &
& AWG7 * UE(IS+ISM ,ID-IDM1) + &
& AWG8 * UE(IS+ISM ,ID-IDM )
EP2 = AWG1 * UE(IS+ISP1,ID-IDP1) + &
& AWG2 * UE(IS+ISP1,ID-IDP ) + &
& AWG3 * UE(IS+ISP ,ID-IDP1) + &
& AWG4 * UE(IS+ISP ,ID-IDP )
EM2 = AWG5 * UE(IS+ISM1,ID+IDM1) + &
& AWG6 * UE(IS+ISM1,ID+IDM ) + &
& AWG7 * UE(IS+ISM ,ID+IDM1) + &
& AWG8 * UE(IS+ISM ,ID+IDM )
!
SA1A = E00 * ( EP1*DAL1 + EM1*DAL2 ) * PQUAD(2)
SA1B = SA1A - EP1*EM1*DAL3 * PQUAD(2)
SA2A = E00 * ( EP2*DAL1 + EM2*DAL2 ) * PQUAD(2)
SA2B = SA2A - EP2*EM2*DAL3 * PQUAD(2)
FACTOR = CONS * AF11(IS) * E00
SA1(IS,ID) = FACTOR*SA1B
SA2(IS,ID) = FACTOR*SA2B
END DO
END DO
!
! *** Fold interactions to side angles if spectral domain ***
! *** is periodic in directional space ***
!
DO ID = 1, IDHGH - MDC
ID0 = 1 - ID
DO IS = ISCLW, ISCHG
SA1 (IS,MDC+ID) = SA1 (IS,ID )
SA2 (IS,MDC+ID) = SA2 (IS,ID )
SA1 (IS,ID0 ) = SA1 (IS,MDC+ID0)
SA2 (IS,ID0 ) = SA2 (IS,MDC+ID0)
END DO
END DO
!
! *** Put source term together ***
!
DO I = 1, MSC
SIGPI = SPSIG(I) * JACOBI
DO J = 1, MDC
ID = MOD( J - 1 + MDC, MDC ) + 1
SFNL(I,ID) = -2.0 * ( SA1(I,J) + SA2(I,J) ) &
& + AWG1 * ( SA1(I-ISP1,J-IDP1) + SA2(I-ISP1,J+IDP1) ) &
& + AWG2 * ( SA1(I-ISP1,J-IDP ) + SA2(I-ISP1,J+IDP ) ) &
& + AWG3 * ( SA1(I-ISP ,J-IDP1) + SA2(I-ISP ,J+IDP1) ) &
& + AWG4 * ( SA1(I-ISP ,J-IDP ) + SA2(I-ISP ,J+IDP ) ) &
& + AWG5 * ( SA1(I-ISM1,J+IDM1) + SA2(I-ISM1,J-IDM1) ) &
& + AWG6 * ( SA1(I-ISM1,J+IDM ) + SA2(I-ISM1,J-IDM ) ) &
& + AWG7 * ( SA1(I-ISM ,J+IDM1) + SA2(I-ISM ,J-IDM1) ) &
& + AWG8 * ( SA1(I-ISM ,J+IDM ) + SA2(I-ISM ,J-IDM ) )
IF (ICOMP .EQ. 2) THEN
IF (SFNL(I,ID).GT.0.) THEN ! Patankar rule's ...
IMATRA(I,ID) = IMATRA(I,ID) + SFNL(I,ID) / SIGPI
ELSE
IMATDA(I,ID) = IMATDA(I,ID) - SFNL(I,ID) / MAX(10E-18_rkind,ACLOC(I,ID)*SIGPI)
END IF
ELSE
IMATRA(I,ID) = IMATRA(I,ID) + SFNL(I,ID) / SIGPI
IMATDA(I,ID) = IMATDA(I,ID) + SFNL(I,ID) / MAX(10E-18_rkind,ACLOC(I,ID)*SIGPI)
END IF
END DO
END DO
RETURN
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************