-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesmFldsExchange_ufs_mod.F90
815 lines (755 loc) · 36.1 KB
/
esmFldsExchange_ufs_mod.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
805
806
807
808
809
810
811
812
813
814
815
module esmFldsExchange_ufs_mod
!---------------------------------------------------------------------
! This is a mediator specific routine that determines ALL possible
! fields exchanged between components and their associated routing,
! mapping and merging
!---------------------------------------------------------------------
implicit none
public
public :: esmFldsExchange_ufs
character(*), parameter :: u_FILE_u = &
__FILE__
!================================================================================
contains
!================================================================================
subroutine esmFldsExchange_ufs(gcomp, phase, rc)
use ESMF
use NUOPC
use med_kind_mod , only : CX=>SHR_KIND_CX, CS=>SHR_KIND_CS, CL=>SHR_KIND_CL, R8=>SHR_KIND_R8
use med_utils_mod , only : chkerr => med_utils_chkerr
use med_methods_mod , only : fldchk => med_methods_FB_FldChk
use med_internalstate_mod , only : InternalState
use med_internalstate_mod , only : compmed, compatm, compocn, compice, complnd, compwav, ncomps
use med_internalstate_mod , only : mapbilnr, mapconsf, mapconsd, mappatch
use med_internalstate_mod , only : mapfcopy, mapnstod, mapnstod_consd, mapnstod_consf
use med_internalstate_mod , only : mapconsf_aofrac, mapbilnr_nstod
use med_internalstate_mod , only : coupling_mode, mapnames
use esmFlds , only : med_fldList_type
use esmFlds , only : addfld_to => med_fldList_addfld_to
use esmFlds , only : addmrg_to => med_fldList_addmrg_to
use esmFlds , only : addfld_from => med_fldList_addfld_from
use esmFlds , only : addmap_from => med_fldList_addmap_from
use esmFlds , only : addfld_aoflux => med_fldList_addfld_aoflux
use esmFlds , only : addmap_aoflux => med_fldList_addmap_aoflux
use esmFlds , only : addfld_ocnalb => med_fldList_addfld_ocnalb
use esmFlds , only : addmap_ocnalb => med_fldList_addmap_ocnalb
use esmFlds , only : addfld_ocnnst => med_fldList_addfld_ocnnst
use esmFlds , only : addmap_ocnnst => med_fldList_addmap_ocnnst
! input/output parameters:
type(ESMF_GridComp) :: gcomp
character(len=*) , intent(in) :: phase
integer , intent(inout) :: rc
! local variables:
type(InternalState) :: is_local
integer :: n, maptype
logical :: med_aoflux_to_ocn
logical :: med_ocnnst
character(len=CX) :: msgString
character(len=CL) :: cvalue
character(len=CS) :: fldname
character(len=CS), allocatable :: flds(:), oflds(:), aflds(:), iflds(:)
character(len=*) , parameter :: subname='(esmFldsExchange_ufs)'
!--------------------------------------
rc = ESMF_SUCCESS
!---------------------------------------
! Get the internal state
!---------------------------------------
nullify(is_local%wrap)
call ESMF_GridCompGetInternalState(gcomp, is_local, rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
! Set maptype according to coupling_mode
if (trim(coupling_mode) == 'ufs.nfrac' .or. trim(coupling_mode) == 'ufs.nfrac.aoflux') then
maptype = mapnstod_consf
else
maptype = mapconsf
end if
write(msgString,'(A,i6,A)') trim(subname)//': maptype is ',maptype,', '//mapnames(maptype)
call ESMF_LogWrite(trim(msgString), ESMF_LOGMSG_INFO)
if (trim(coupling_mode) == 'ufs.nfrac.aoflux' .or. trim(coupling_mode) == 'ufs.frac.aoflux') then
med_aoflux_to_ocn = .true.
else
med_aoflux_to_ocn = .false.
end if
!=====================================================================
! scalar information
!=====================================================================
if (phase == 'advertise') then
call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldName", value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
do n = 1,ncomps
call addfld_to(n , trim(cvalue))
call addfld_from(n , trim(cvalue))
end do
end if
!=====================================================================
! Mediator fields
!=====================================================================
! masks from components
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compice)) call addfld_from(compice, 'Si_imask')
if (is_local%wrap%comp_present(compocn)) call addfld_from(compocn, 'So_omask')
if (is_local%wrap%comp_present(complnd)) call addfld_from(complnd, 'Sl_lfrin')
else
if ( fldchk(is_local%wrap%FBexp(compice) , 'So_omask', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compocn,compocn), 'So_omask', rc=rc)) then
call addmap_from(compocn, 'So_omask', compice, mapfcopy, 'unset', 'unset')
end if
end if
! fields required for atm/ocn flux calculation
if (is_local%wrap%comp_present(compocn) .and. is_local%wrap%comp_present(compatm)) then
! from atm: states for fluxes
allocate(flds(13))
flds = (/'Sa_u ', 'Sa_v ', 'Sa_z ', 'Sa_tbot', 'Sa_pbot', 'Sa_pslv', &
'Sa_shum', 'Sa_ptem', 'Sa_dens', 'Sa_u10m', 'Sa_v10m', 'Sa_t2m ', &
'Sa_q2m '/)
do n = 1,size(flds)
fldname = trim(flds(n))
if (phase == 'advertise') then
call addfld_from(compatm , fldname)
else
if ( fldchk(is_local%wrap%FBImp(compatm,compatm), fldname, rc=rc)) then
call addmap_from(compatm, fldname, compocn, maptype, 'one', 'unset')
end if
end if
end do
deallocate(flds)
! from med: fields returned by the atm/ocn flux computation, otherwise unadvertised
allocate(flds(8))
flds = (/'So_tref ', 'So_qref ', 'So_ustar ', 'So_re ','So_ssq ', 'So_u10 ', &
'So_duu10n', 'Faox_lat '/)
do n = 1,size(flds)
fldname = trim(flds(n))
if (phase == 'advertise') then
call addfld_aoflux(fldname)
end if
end do
deallocate(flds)
end if
! from med: ocean albedos (not sent to the ATM in UFS).
if (phase == 'advertise') then
call addfld_ocnalb('So_avsdr')
call addfld_ocnalb('So_avsdf')
call addfld_ocnalb('So_anidr')
call addfld_ocnalb('So_anidf')
end if
! TODO: make configurable
med_ocnnst = .true.
if (med_ocnnst) then
! from med: ocean nst
if (phase == 'advertise') then
call addfld_from(compatm, 'Sa_tskn') ! to check atm's calculation
!call addfld_from(compatm, 'Faxa_lwdn')
!call addfld_ocnnst('Sa_tskn')
!call addfld_ocnnst('Faxa_lwdn')
!sent back to ATM, will need have mapping added; So_nst should be done
!below instead of So_t
allocate(flds(16))
flds = (/'tref ', 'dconv ', 'dtcool', 'qrain ', 'xtts ', 'xzts ', &
'c0 ', 'cd ', 'w0 ', 'wd ', 'xs ', 'xt ', &
'xu ', 'xv ', 'xz ', 'zc '/)
do n = 1,size(flds)
fldname = 'Snst_'//trim(flds(n))
call addfld_ocnnst(fldname)
end do
deallocate(flds)
! wind,stress and sfcnsw should be local FB only---maybe some of these others too
allocate(flds(8))
flds = (/'tseal ', 'tsfc_water ', 'tsurf_water', 'dtzm ', 'dtm ', &
'wind ', 'stress ', 'sfcnsw '/)
do n = 1,size(flds)
fldname = 'Snst_'//trim(flds(n))
call addfld_ocnnst(fldname)
end do
deallocate(flds)
else
!call addmap_ocnnst( 'Sa_tskn', compocn, maptype, 'one', 'unset')
end if
end if
!=====================================================================
! FIELDS TO ATMOSPHERE (compatm)
!=====================================================================
! to atm: fractions (computed in med_phases_prep_atm)
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compice) .and. is_local%wrap%comp_present(compatm)) then
call addfld_from(compice , 'Si_ifrac')
call addfld_to(compatm , 'Si_ifrac')
end if
! ofrac used by atm
if (is_local%wrap%comp_present(compocn) .and. is_local%wrap%comp_present(compatm)) then
call addfld_from(compatm , 'Sa_ofrac')
end if
! lfrac used by atm
if (is_local%wrap%comp_present(complnd) .and. is_local%wrap%comp_present(compatm)) then
call addfld_to(compatm , 'Sl_lfrac')
end if
end if
! to atm: unmerged from ice
! - zonal surface stress, meridional surface stress
! - surface latent heat flux,
! - surface sensible heat flux
! - surface upward longwave heat flux
! - evaporation water flux from water
! - mean ice volume per unit area
! - mean snow volume per unit area
! - surface temperatures
allocate(flds(9))
flds = (/'Faii_taux', 'Faii_tauy', 'Faii_lat ', 'Faii_sen ', 'Faii_lwup', 'Faii_evap', &
'Si_vice ', 'Si_vsno ', 'Si_t '/)
do n = 1,size(flds)
fldname = trim(flds(n))
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compice) .and. is_local%wrap%comp_present(compatm)) then
call addfld_from(compice , fldname)
call addfld_to(compatm , fldname)
end if
else
if ( fldchk(is_local%wrap%FBexp(compatm) , fldname, rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compice,compice), fldname, rc=rc)) then
call addmap_from(compice, fldname, compatm, maptype, 'ifrac', 'unset')
call addmrg_to(compatm, fldname, mrg_from=compice, mrg_fld=fldname, mrg_type='copy')
end if
end if
end do
deallocate(flds)
! to atm: unmerged sea ice albedo, 4 bands
allocate(flds(4))
flds = (/'Si_avsdr', 'Si_avsdf', 'Si_anidr', 'Si_anidf'/)
do n = 1,size(flds)
fldname = trim(flds(n))
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compice) .and. is_local%wrap%comp_present(compatm)) then
call addfld_from(compice , fldname)
call addfld_to(compatm , fldname)
end if
else
if ( fldchk(is_local%wrap%FBexp(compatm) , fldname, rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compice,compice), fldname, rc=rc)) then
call addmap_from(compice, fldname, compatm, maptype, 'ifrac', 'unset')
call addmrg_to(compatm, fldname, mrg_from=compice, mrg_fld=fldname, mrg_type='copy')
end if
end if
end do
deallocate(flds)
! to atm: unmerged surface temperatures from ocn
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compocn) .and. is_local%wrap%comp_present(compatm)) then
call addfld_from(compocn , 'So_t')
call addfld_to(compatm , 'So_t')
end if
else
if ( fldchk(is_local%wrap%FBexp(compatm) , 'So_t', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compocn,compocn), 'So_t', rc=rc)) then
call addmap_from(compocn, 'So_t', compatm, maptype, 'ofrac', 'unset')
call addmrg_to(compatm, 'So_t', mrg_from=compocn, mrg_fld='So_t', mrg_type='copy')
end if
end if
! to atm: unmerged surface temperatures from lnd
if (phase == 'advertise') then
if (is_local%wrap%comp_present(complnd) .and. is_local%wrap%comp_present(compatm)) then
call addfld_from(complnd , 'Sl_t')
call addfld_to(compatm , 'Sl_t')
end if
else
if ( fldchk(is_local%wrap%FBexp(compatm) , 'Sl_t', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(complnd,complnd), 'Sl_t', rc=rc)) then
call addmap_from(complnd, 'Sl_t', compatm, maptype, 'lfrin', 'unset')
call addmrg_to(compatm, 'Sl_t', mrg_from=complnd, mrg_fld='Sl_t', mrg_type='copy')
end if
end if
! to atm: unmerged from mediator, merge will be done under FV3/CCPP composite step
! - zonal surface stress, meridional surface stress
! - surface latent heat flux,
! - surface sensible heat flux
! - surface upward longwave heat flux
allocate(flds(5))
flds = (/ 'Faox_lat ', 'Faox_sen ', 'Faox_lwup', 'Faox_taux', 'Faox_tauy' /)
do n = 1,size(flds)
fldname = trim(flds(n))
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compatm) .and. is_local%wrap%comp_present(compocn)) then
call addfld_aoflux(fldname)
call addfld_to(compatm , fldname)
end if
else
if (fldchk(is_local%wrap%FBMed_aoflux_o, fldname, rc=rc)) then
if (trim(is_local%wrap%aoflux_grid) == 'ogrid') then
call addmap_aoflux(fldname, compatm, maptype, 'ofrac', 'unset')
end if
call addmrg_to(compatm, fldname, mrg_from=compmed, mrg_fld=fldname, mrg_type='copy')
end if
end if
end do
deallocate(flds)
! to atm: surface roughness length from wav
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compwav) .and. is_local%wrap%comp_present(compatm)) then
call addfld_from(compwav , 'Sw_z0')
call addfld_to(compatm , 'Sw_z0')
end if
else
if ( fldchk(is_local%wrap%FBexp(compatm) , 'Sw_z0', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compwav,compwav), 'Sw_z0', rc=rc)) then
call addmap_from(compwav, 'Sw_z0', compatm, mapbilnr_nstod, 'one', 'unset')
call addmrg_to(compatm, 'Sw_z0', mrg_from=compwav, mrg_fld='Sw_z0', mrg_type='copy')
end if
end if
!=====================================================================
! FIELDS TO OCEAN (compocn)
!=====================================================================
! to ocn: sea level pressure from atm
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compatm) .and. is_local%wrap%comp_present(compocn)) then
call addfld_from(compatm , 'Sa_pslv')
call addfld_to(compocn , 'Sa_pslv')
end if
else
if ( fldchk(is_local%wrap%FBexp(compocn) , 'Sa_pslv', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm), 'Sa_pslv', rc=rc)) then
call addmap_from(compatm, 'Sa_pslv', compocn, maptype, 'one', 'unset')
call addmrg_to(compocn, 'Sa_pslv', mrg_from=compatm, mrg_fld='Sa_pslv', mrg_type='copy')
end if
end if
! to ocn: swpen thru ice w/o bands
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compice) .and. is_local%wrap%comp_present(compocn)) then
call addfld_from(compice , 'Fioi_swpen')
end if
else
if (fldchk(is_local%wrap%FBImp(compice,compice), 'Fioi_swpen', rc=rc)) then
call addmap_from(compice, 'Fioi_swpen', compocn, mapfcopy, 'unset', 'unset')
end if
end if
! to ocn: from sw from atm and sw net from ice (custom merge in med_phases_prep_ocn)
! - downward direct near-infrared ("n" or "i") incident solar radiation
! - downward diffuse near-infrared ("n" or "i") incident solar radiation
! - downward direct visible ("v") incident solar radiation
! - downward diffuse visible ("v") incident solar radiation
allocate(oflds(4))
allocate(aflds(4))
allocate(iflds(4))
oflds = (/'Foxx_swnet_idr', 'Foxx_swnet_idf', 'Foxx_swnet_vdr', 'Foxx_swnet_vdf'/)
aflds = (/'Faxa_swndr' , 'Faxa_swndf' , 'Faxa_swvdr' , 'Faxa_swvdf'/)
iflds = (/'Fioi_swpen_idr', 'Fioi_swpen_idf', 'Fioi_swpen_vdr', 'Fioi_swpen_vdf'/)
do n = 1,size(oflds)
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compatm) .and. is_local%wrap%comp_present(compocn)) then
call addfld_from(compatm , trim(aflds(n)))
call addfld_to(compocn , trim(oflds(n)))
end if
else
if ( fldchk(is_local%wrap%FBexp(compocn) , trim(oflds(n)), rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm), trim(aflds(n)), rc=rc)) then
call addmap_from(compatm, trim(aflds(n)), compocn, maptype, 'one', 'unset')
end if
end if
end do
do n = 1,size(oflds)
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compice) .and. is_local%wrap%comp_present(compocn)) then
call addfld_from(compice , trim(iflds(n)))
call addfld_to(compocn , trim(oflds(n)))
end if
else
if ( fldchk(is_local%wrap%FBexp(compocn) , trim(oflds(n)), rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compice,compice), trim(iflds(n)), rc=rc)) then
call addmap_from(compice, trim(iflds(n)), compocn, mapfcopy, 'unset', 'unset')
end if
end if
end do
deallocate(oflds)
deallocate(aflds)
deallocate(iflds)
! to ocn: rain and snow via auto merge
allocate(flds(2))
flds = (/'Faxa_rain', 'Faxa_snow'/)
do n = 1,size(flds)
fldname = trim(flds(n))
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compatm) .and. is_local%wrap%comp_present(compocn)) then
call addfld_from(compatm , fldname)
call addfld_to(compocn , fldname)
end if
else
if ( fldchk(is_local%wrap%FBexp(compocn) , fldname, rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm), fldname, rc=rc)) then
call addmap_from(compatm, fldname, compocn, maptype, 'one', 'unset')
call addmrg_to(compocn, fldname, &
mrg_from=compatm, mrg_fld=fldname, mrg_type='copy_with_weights', mrg_fracname='ofrac')
end if
end if
end do
!to ocn: surface stress from mediator or atm and ice stress via auto merge
flds = (/'taux', 'tauy'/)
do n = 1,size(flds)
fldname = trim(flds(n))
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compice) .and. is_local%wrap%comp_present(compocn)) then
call addfld_aoflux('Faox_'//fldname)
call addfld_from(compatm , 'Faxa_'//fldname)
call addfld_from(compice , 'Fioi_'//fldname)
call addfld_to(compocn , 'Foxx_'//fldname)
end if
else
if (med_aoflux_to_ocn) then
if ( fldchk(is_local%wrap%FBexp(compocn) , 'Foxx_'//fldname, rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compice,compice), 'Fioi_'//fldname, rc=rc) .and. &
fldchk(is_local%wrap%FBMed_aoflux_o , 'Faox_'//fldname, rc=rc)) then
call addmap_from(compice, 'Fioi_'//fldname, compocn, mapfcopy, 'unset', 'unset')
call addmrg_to(compocn, 'Foxx_'//fldname, &
mrg_from=compmed, mrg_fld='Faox_'//fldname, mrg_type='merge', mrg_fracname='ofrac')
call addmrg_to(compocn, 'Foxx_'//fldname, &
mrg_from=compice, mrg_fld='Fioi_'//fldname, mrg_type='merge', mrg_fracname='ifrac')
end if
else
if ( fldchk(is_local%wrap%FBexp(compocn) , 'Foxx_'//fldname, rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compice,compice), 'Fioi_'//fldname, rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm), 'Faxa_'//fldname, rc=rc)) then
call addmap_from(compice, 'Fioi_'//fldname, compocn, mapfcopy, 'unset', 'unset')
call addmap_from(compatm, 'Faxa_'//fldname, compocn, mapconsf_aofrac, 'aofrac', 'unset')
call addmrg_to(compocn, 'Foxx_'//fldname, &
mrg_from=compice, mrg_fld='Fioi_'//fldname, mrg_type='merge', mrg_fracname='ifrac')
call addmrg_to(compocn, 'Foxx_'//fldname, &
mrg_from=compatm, mrg_fld='Faxa_'//fldname, mrg_type='merge', mrg_fracname='ofrac')
end if
end if
end if
end do
deallocate(flds)
! to ocn: net long wave via auto merge
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compatm) .and. is_local%wrap%comp_present(compocn)) then
call addfld_aoflux('Faox_lwup')
call addfld_from(compatm , 'Faxa_lwnet')
call addfld_from(compatm , 'Faxa_lwdn')
call addfld_to(compocn , 'Foxx_lwnet')
! ocnnst
call addfld_to(compocn , 'Faxa_lwdn')
end if
else
if (med_aoflux_to_ocn) then
if ( fldchk(is_local%wrap%FBexp(compocn) , 'Foxx_lwnet', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm), 'Faxa_lwdn' , rc=rc) .and. &
fldchk(is_local%wrap%FBMed_aoflux_o , 'Faox_lwup' , rc=rc)) then
call addmap_from(compatm, 'Faxa_lwdn', compocn, maptype, 'one', 'unset')
call addmrg_to(compocn, 'Foxx_lwnet', &
mrg_from=compmed, mrg_fld='Faox_lwup', mrg_type='merge', mrg_fracname='ofrac')
call addmrg_to(compocn, 'Foxx_lwnet', &
mrg_from=compatm, mrg_fld='Faxa_lwdn', mrg_type='merge', mrg_fracname='ofrac')
end if
else
if ( fldchk(is_local%wrap%FBexp(compocn) , 'Foxx_lwnet', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm), 'Faxa_lwnet', rc=rc)) then
call addmap_from(compatm, 'Faxa_lwnet', compocn, mapconsf_aofrac, 'aofrac', 'unset')
call addmrg_to(compocn, 'Foxx_lwnet', &
mrg_from=compatm, mrg_fld='Faxa_lwnet', mrg_type='copy_with_weights', mrg_fracname='ofrac')
end if
! ocnnst
if ( fldchk(is_local%wrap%FBexp(compocn) , 'Faxa_lwdn', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm), 'Faxa_lwdn', rc=rc)) then
call addmap_from(compatm, 'Faxa_lwdn', compocn, mapconsf_aofrac, 'aofrac', 'unset')
call addmrg_to(compocn, 'Faxa_lwdn', &
mrg_from=compatm, mrg_fld='Faxa_lwdn', mrg_type='copy_with_weights', mrg_fracname='ofrac')
end if
end if
end if
! to ocn: sensible heat flux
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compatm) .and. is_local%wrap%comp_present(compocn)) then
call addfld_aoflux('Faox_sen')
call addfld_from(compatm , 'Faxa_sen')
call addfld_to(compocn , 'Foxx_sen')
end if
else
if (med_aoflux_to_ocn) then
if ( fldchk(is_local%wrap%FBexp(compocn) , 'Foxx_sen', rc=rc) .and. &
fldchk(is_local%wrap%FBMed_aoflux_o , 'Faox_sen' , rc=rc)) then
call addmrg_to(compocn, 'Foxx_sen', &
mrg_from=compmed, mrg_fld='Faox_sen', mrg_type='copy_with_weights', mrg_fracname='ofrac')
end if
else
if ( fldchk(is_local%wrap%FBexp(compocn) , 'Foxx_sen', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm), 'Faxa_sen', rc=rc)) then
call addmap_from(compatm, 'Faxa_sen', compocn, mapconsf_aofrac, 'aofrac', 'unset')
call addmrg_to(compocn, 'Foxx_sen', &
mrg_from=compatm, mrg_fld='Faxa_sen', mrg_type='copy_with_weights', mrg_fracname='ofrac')
end if
end if
end if
! to ocn: evaporation water flux
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compatm) .and. is_local%wrap%comp_present(compocn)) then
call addfld_aoflux('Faox_evap')
call addfld_from(compatm , 'Faxa_evap')
call addfld_to(compocn , 'Foxx_evap')
end if
else
if (med_aoflux_to_ocn) then
if ( fldchk(is_local%wrap%FBexp(compocn) , 'Foxx_evap', rc=rc) .and. &
fldchk(is_local%wrap%FBMed_aoflux_o , 'Faox_evap' , rc=rc)) then
call addmrg_to(compocn, 'Foxx_evap', &
mrg_from=compmed, mrg_fld='Faox_evap', mrg_type='copy_with_weights', mrg_fracname='ofrac')
end if
else
if ( fldchk(is_local%wrap%FBexp(compocn) , 'Foxx_evap', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm), 'Faxa_evap' , rc=rc)) then
call addmap_from(compatm, 'Faxa_evap', compocn, mapconsf_aofrac, 'aofrac', 'unset')
call addmrg_to(compocn, 'Foxx_evap', &
mrg_from=compatm, mrg_fld='Faxa_evap', mrg_type='copy_with_weights', mrg_fracname='ofrac')
end if
end if
end if
! to ocn: unmerged fluxes from ice
! - water flux due to melting ice from ice
! - heat flux from melting ice from ice
! - salt flux from ice
allocate(flds(3))
flds = (/'Fioi_meltw', 'Fioi_melth', 'Fioi_salt '/)
do n = 1,size(flds)
fldname = trim(flds(n))
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compice) .and. is_local%wrap%comp_present(compocn)) then
call addfld_from(compice , fldname)
call addfld_to(compocn , fldname)
end if
else
if ( fldchk(is_local%wrap%FBexp(compocn) , fldname, rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compice,compice), fldname, rc=rc)) then
call addmap_from(compice, fldname, compocn, mapfcopy, 'unset', 'unset')
call addmrg_to(compocn, fldname, &
mrg_from=compice, mrg_fld=fldname, mrg_type='copy_with_weights', mrg_fracname='ifrac')
end if
end if
end do
deallocate(flds)
! to ocn: ice fraction for ocnnst
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compice) .and. is_local%wrap%comp_present(compocn)) then
call addfld_from(compice , 'Si_ifrac')
call addfld_to(compocn , 'Si_ifrac')
end if
else
if ( fldchk(is_local%wrap%FBexp(compocn) , 'Si_ifrac', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compice,compice), 'Si_ifrac', rc=rc)) then
call addmap_from(compice, 'Si_ifrac', compocn, mapfcopy, 'unset', 'unset')
call addmrg_to(compocn, 'Si_ifrac', mrg_from=compice, mrg_fld='Si_ifrac', mrg_type='copy')
end if
end if
! to ocn: partitioned stokes drift from wav
allocate(flds(2))
flds = (/'Sw_pstokes_x', 'Sw_pstokes_y'/)
do n = 1,size(flds)
fldname = trim(flds(n))
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compwav) .and. is_local%wrap%comp_present(compocn)) then
call addfld_from(compwav , fldname)
call addfld_to(compocn , fldname)
end if
else
if ( fldchk(is_local%wrap%FBexp(compocn) , fldname, rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compwav,compwav), fldname, rc=rc)) then
call addmap_from(compwav, fldname, compocn, mapbilnr_nstod, 'one', 'unset')
call addmrg_to(compocn, fldname, mrg_from=compwav, mrg_fld=fldname, mrg_type='copy')
end if
end if
end do
deallocate(flds)
!=====================================================================
! FIELDS TO ICE (compice)
!=====================================================================
! to ice: fluxes from atm
! - downward longwave heat flux from atm
! - downward direct near-infrared incident solar radiation from atm
! - downward direct visible incident solar radiation from atm
! - downward diffuse near-infrared incident solar radiation from atm
! - downward Diffuse visible incident solar radiation from atm
! - rain from atm
! - snow from atm
allocate(flds(7))
flds = (/'Faxa_lwdn ', 'Faxa_swndr', 'Faxa_swvdr', 'Faxa_swndf', 'Faxa_swvdf', &
'Faxa_rain ', 'Faxa_snow '/)
do n = 1,size(flds)
fldname = trim(flds(n))
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compatm) .and. is_local%wrap%comp_present(compice)) then
call addfld_from(compatm , fldname)
call addfld_to(compice , fldname)
end if
else
if ( fldchk(is_local%wrap%FBexp(compice) , fldname, rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm), fldname, rc=rc)) then
call addmap_from(compatm, fldname, compice, maptype, 'one', 'unset')
call addmrg_to(compice, fldname, mrg_from=compatm, mrg_fld=fldname, mrg_type='copy')
end if
end if
end do
deallocate(flds)
! to ice: states from atm
! - height at the lowest model level from atm
! - pressure at the lowest model level from atm
! - temperature at the lowest model level from atm
! - zonal wind at the lowest model level from atm
! - meridional wind at the lowest model level from atm
! - specific humidity at the lowest model level from atm
allocate(flds(6))
flds = (/'Sa_u ', 'Sa_v ', 'Sa_z ', 'Sa_tbot', 'Sa_pbot', 'Sa_shum'/)
do n = 1,size(flds)
fldname = trim(flds(n))
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compatm) .and. is_local%wrap%comp_present(compice)) then
call addfld_from(compatm , fldname)
call addfld_to(compice , fldname)
endif
else
if ( fldchk(is_local%wrap%FBexp(compice) , fldname, rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm), fldname, rc=rc)) then
call addmap_from(compatm, fldname, compice, maptype, 'one', 'unset')
call addmrg_to(compice, fldname, mrg_from=compatm, mrg_fld=fldname, mrg_type='copy')
end if
end if
end do
deallocate(flds)
! to ice: states and fluxes from ocn
! - sea surface temperature from ocn
! - sea surface salinity from ocn
! - zonal sea water velocity from ocn
! - meridional sea water velocity from ocn
! - zonal sea surface slope from ocn
! - meridional sea surface slope from ocn
! - ocean melt and freeze potential from ocn
allocate(flds(7))
flds = (/'So_t ', 'So_s ', 'So_u ', 'So_v ','So_dhdx', 'So_dhdy', 'Fioo_q '/)
do n = 1,size(flds)
fldname = trim(flds(n))
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compocn) .and. is_local%wrap%comp_present(compice)) then
call addfld_from(compocn , fldname)
call addfld_to(compice , fldname)
endif
else
if ( fldchk(is_local%wrap%FBexp(compice) , fldname, rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compocn,compocn), fldname, rc=rc)) then
call addmap_from(compocn, fldname, compice, mapfcopy , 'unset', 'unset')
call addmrg_to(compice, fldname, mrg_from=compocn, mrg_fld=fldname, mrg_type='copy')
end if
end if
end do
deallocate(flds)
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compice) .and. is_local%wrap%comp_present(compwav)) then
call addfld_from(compwav , 'Sw_elevation_spectrum')
call addfld_to(compice , 'Sw_elevation_spectrum')
end if
else
if ( fldchk(is_local%wrap%FBExp(compice) , 'Sw_elevation_spectrum', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compwav,compwav), 'Sw_elevation_spectrum', rc=rc)) then
call addmap_from(compwav, 'Sw_elevation_spectrum', compice, mapbilnr_nstod, 'one', 'unset')
call addmrg_to(compice, 'Sw_elevation_spectrum', mrg_from=compwav, &
mrg_fld='Sw_elevation_spectrum', mrg_type='copy')
end if
end if
!=====================================================================
! FIELDS TO WAV (compwav)
!=====================================================================
! to wav: states from atm
! - 10m meridonal and zonal winds
! - bottom temperature from atm
allocate(flds(3))
flds = (/'Sa_u10m', 'Sa_v10m', 'Sa_tbot'/)
do n = 1,size(flds)
fldname = trim(flds(n))
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compatm) .and. is_local%wrap%comp_present(compwav)) then
call addfld_from(compatm , fldname)
call addfld_to(compwav , fldname)
end if
else
if ( fldchk(is_local%wrap%FBexp(compwav) , fldname, rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm), fldname, rc=rc)) then
call addmap_from(compatm, fldname, compwav, mapbilnr_nstod, 'one', 'unset')
call addmrg_to(compwav, fldname, mrg_from=compatm, mrg_fld=fldname, mrg_type='copy')
end if
end if
end do
deallocate(flds)
! to wav: states from ice
! - sea ice fraction
! - sea ice thickness
! - sea ice floe diameter
allocate(flds(3))
flds = (/'Si_ifrac ', 'Si_floediam', 'Si_thick '/)
do n = 1,size(flds)
fldname = trim(flds(n))
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compice) .and. is_local%wrap%comp_present(compwav)) then
call addfld_from(compice , fldname)
call addfld_to(compwav , fldname)
end if
else
if ( fldchk(is_local%wrap%FBexp(compwav) , fldname, rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compice,compice), fldname, rc=rc)) then
call addmap_from(compice, fldname, compwav, mapbilnr_nstod , 'one', 'unset')
call addmrg_to(compwav, fldname, mrg_from=compice, mrg_fld=fldname, mrg_type='copy')
end if
end if
end do
deallocate(flds)
! to wav: states from ocn
! - zonal sea water velocity from ocn
! - meridional sea water velocity from ocn
! - surface temperature from ocn
allocate(flds(3))
flds = (/'So_u', 'So_v', 'So_t'/)
do n = 1,size(flds)
fldname = trim(flds(n))
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compocn) .and. is_local%wrap%comp_present(compwav)) then
call addfld_from(compocn , fldname)
call addfld_to(compwav , fldname)
end if
else
if ( fldchk(is_local%wrap%FBexp(compwav) , fldname, rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compocn,compocn), fldname, rc=rc)) then
call addmap_from(compocn, fldname, compwav, mapbilnr_nstod , 'one', 'unset')
call addmrg_to(compwav, fldname, mrg_from=compocn, mrg_fld=fldname, mrg_type='copy')
end if
end if
end do
deallocate(flds)
!=====================================================================
! FIELDS TO LAND (complnd)
!=====================================================================
! to lnd - states and fluxes from atm
if ( trim(coupling_mode) == 'ufs.nfrac.aoflux') then
allocate(flds(21))
flds = (/'Sa_z ', 'Sa_topo ', 'Sa_tbot ', 'Sa_pbot ', &
'Sa_shum ', 'Sa_u ', 'Sa_v ', 'Faxa_lwdn ', &
'Sa_ptem ', 'Sa_dens ', 'Faxa_swdn ', 'Sa_pslv ', &
'Faxa_snowc', 'Faxa_snowl', 'Faxa_rainc', 'Faxa_rainl', &
'Faxa_swndr', 'Faxa_swndf', 'Faxa_swvdr', 'Faxa_swvdf', &
'Faxa_swnet'/)
else
allocate(flds(18))
flds = (/'Sa_z ', 'Sa_ta ', 'Sa_pslv ', 'Sa_qa ', &
'Sa_ua ', 'Sa_va ', 'Faxa_swdn ', 'Faxa_lwdn ', &
'Faxa_swnet', 'Faxa_rain ', 'Sa_prsl ', 'vfrac ', &
'Faxa_snow ', 'Faxa_rainc', 'Sa_tskn ', 'Sa_exner ', &
'Sa_ustar ', 'zorl ' /)
end if
do n = 1,size(flds)
fldname = trim(flds(n))
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compatm) .and. is_local%wrap%comp_present(complnd)) then
call addfld_from(compatm , fldname)
call addfld_to(complnd , fldname)
end if
else
if ( fldchk(is_local%wrap%FBexp(complnd) , fldname, rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm), fldname, rc=rc)) then
call addmap_from(compatm, fldname, complnd, maptype, 'one', 'unset')
call addmrg_to(complnd, fldname, mrg_from=compatm, mrg_fld=fldname, mrg_type='copy')
end if
end if
end do
deallocate(flds)
end subroutine esmFldsExchange_ufs
end module esmFldsExchange_ufs_mod