-
Notifications
You must be signed in to change notification settings - Fork 229
/
mom_cap.F90
2962 lines (2570 loc) · 120 KB
/
mom_cap.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
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
!> This module contains a set of subroutines that are required by NUOPC.
module MOM_cap_mod
use MOM_domains, only: get_domain_extent
use MOM_io, only: stdout, io_infra_end
use mpp_domains_mod, only: mpp_get_compute_domains
use mpp_domains_mod, only: mpp_get_ntile_count, mpp_get_pelist, mpp_get_global_domain
use mpp_domains_mod, only: mpp_get_domain_npes
use MOM_time_manager, only: set_calendar_type, time_type, set_time, set_date
use MOM_time_manager, only: GREGORIAN, JULIAN, NOLEAP
use MOM_time_manager, only: operator( <= ), operator( < ), operator( >= )
use MOM_time_manager, only: operator( + ), operator( - ), operator( / )
use MOM_time_manager, only: operator( * ), operator( /= ), operator( > )
use MOM_domains, only: MOM_infra_init, MOM_infra_end
use MOM_file_parser, only: get_param, log_version, param_file_type, close_param_file
use MOM_get_input, only: get_MOM_input, directories
use MOM_domains, only: pass_var, pe_here
use MOM_error_handler, only: MOM_error, FATAL, is_root_pe
use MOM_grid, only: ocean_grid_type, get_global_grid_size
use MOM_ocean_model_nuopc, only: ice_ocean_boundary_type
use MOM_ocean_model_nuopc, only: ocean_model_restart, ocean_public_type, ocean_state_type
use MOM_ocean_model_nuopc, only: ocean_model_init_sfc, ocean_model_flux_init
use MOM_ocean_model_nuopc, only: ocean_model_init, update_ocean_model, ocean_model_end
use MOM_ocean_model_nuopc, only: get_ocean_grid, get_eps_omesh, query_ocean_state
use MOM_cap_time, only: AlarmInit
use MOM_cap_methods, only: mom_import, mom_export, mom_set_geomtype, mod2med_areacor
use MOM_cap_methods, only: med2mod_areacor, state_diagnose
use MOM_cap_methods, only: ChkErr
use MOM_ensemble_manager, only: ensemble_manager_init
use MOM_coms, only: sum_across_PEs
#ifdef CESMCOUPLED
use shr_log_mod, only: shr_log_setLogUnit
use nuopc_shr_methods, only: get_component_instance
#endif
use time_utils_mod, only: esmf2fms_time
use, intrinsic :: iso_fortran_env, only: output_unit
use ESMF, only: ESMF_ClockAdvance, ESMF_ClockGet, ESMF_ClockPrint, ESMF_VMget
use ESMF, only: ESMF_ClockGetAlarm, ESMF_ClockGetNextTime, ESMF_ClockAdvance
use ESMF, only: ESMF_ClockSet, ESMF_Clock, ESMF_GeomType_Flag, ESMF_LOGMSG_INFO
use ESMF, only: ESMF_Grid, ESMF_GridCreate, ESMF_GridAddCoord
use ESMF, only: ESMF_GridGetCoord, ESMF_GridAddItem, ESMF_GridGetItem
use ESMF, only: ESMF_GridComp, ESMF_GridCompSetEntryPoint, ESMF_GridCompGet
use ESMF, only: ESMF_LogWrite, ESMF_LogSetError
use ESMF, only: ESMF_LOGERR_PASSTHRU, ESMF_KIND_R8, ESMF_RC_VAL_WRONG
use ESMF, only: ESMF_GEOMTYPE_MESH, ESMF_GEOMTYPE_GRID, ESMF_SUCCESS
use ESMF, only: ESMF_METHOD_INITIALIZE, ESMF_MethodRemove, ESMF_State
use ESMF, only: ESMF_LOGMSG_INFO, ESMF_RC_ARG_BAD, ESMF_VM, ESMF_Time
use ESMF, only: ESMF_TimeInterval, ESMF_MAXSTR, ESMF_VMGetCurrent
use ESMF, only: ESMF_VMGet, ESMF_TimeGet, ESMF_TimeIntervalGet, ESMF_MeshGet
use ESMF, only: ESMF_MethodExecute, ESMF_Mesh, ESMF_DeLayout, ESMF_Distgrid
use ESMF, only: ESMF_DistGridConnection, ESMF_StateItem_Flag, ESMF_KIND_I4
use ESMF, only: ESMF_KIND_I8, ESMF_FAILURE, ESMF_DistGridCreate, ESMF_MeshCreate
use ESMF, only: ESMF_FILEFORMAT_ESMFMESH, ESMF_DELayoutCreate, ESMF_DistGridConnectionSet
use ESMF, only: ESMF_DistGridGet, ESMF_STAGGERLOC_CORNER, ESMF_GRIDITEM_MASK
use ESMF, only: ESMF_TYPEKIND_I4, ESMF_TYPEKIND_R8, ESMF_STAGGERLOC_CENTER
use ESMF, only: ESMF_GRIDITEM_AREA, ESMF_Field, ESMF_ALARM, ESMF_VMLogMemInfo
use ESMF, only: ESMF_AlarmIsRinging, ESMF_AlarmRingerOff, ESMF_StateRemove
use ESMF, only: ESMF_FieldCreate, ESMF_LOGMSG_ERROR, ESMF_LOGMSG_WARNING
use ESMF, only: ESMF_COORDSYS_SPH_DEG, ESMF_GridCreate, ESMF_INDEX_DELOCAL
use ESMF, only: ESMF_MESHLOC_ELEMENT, ESMF_RC_VAL_OUTOFRANGE, ESMF_StateGet
use ESMF, only: ESMF_TimePrint, ESMF_AlarmSet, ESMF_FieldGet, ESMF_Array
use ESMF, only: ESMF_FieldRegridGetArea
use ESMF, only: ESMF_ArrayCreate
use ESMF, only: ESMF_RC_FILE_OPEN, ESMF_RC_FILE_READ, ESMF_RC_FILE_WRITE
use ESMF, only: ESMF_VMBroadcast, ESMF_VMReduce, ESMF_REDUCE_MAX, ESMF_REDUCE_MIN
use ESMF, only: ESMF_AlarmCreate, ESMF_ClockGetAlarmList, ESMF_AlarmList_Flag
use ESMF, only: ESMF_AlarmGet, ESMF_AlarmIsCreated, ESMF_ALARMLIST_ALL, ESMF_AlarmIsEnabled
use ESMF, only: ESMF_STATEITEM_NOTFOUND, ESMF_FieldWrite
use ESMF, only: ESMF_END_ABORT, ESMF_Finalize
use ESMF, only: ESMF_REDUCE_MAX, ESMF_REDUCE_MIN, ESMF_VMAllReduce
use ESMF, only: operator(==), operator(/=), operator(+), operator(-)
! TODO ESMF_GridCompGetInternalState does not have an explicit Fortran interface.
!! Model does not compile with "use ESMF, only: ESMF_GridCompGetInternalState"
!! Is this okay?
use NUOPC, only: NUOPC_CompDerive, NUOPC_CompSetEntryPoint, NUOPC_CompSpecialize
use NUOPC, only: NUOPC_CompFilterPhaseMap, NUOPC_CompAttributeGet, NUOPC_CompAttributeAdd
use NUOPC, only: NUOPC_Advertise, NUOPC_SetAttribute, NUOPC_IsUpdated, NUOPC_Write
use NUOPC, only: NUOPC_IsConnected, NUOPC_Realize, NUOPC_CompAttributeSet
use NUOPC_Model, only: NUOPC_ModelGet
use NUOPC_Model, only: model_routine_SS => SetServices
use NUOPC_Model, only: model_label_Advance => label_Advance
use NUOPC_Model, only: model_label_DataInitialize => label_DataInitialize
use NUOPC_Model, only: model_label_SetRunClock => label_SetRunClock
use NUOPC_Model, only: model_label_Finalize => label_Finalize
use NUOPC_Model, only: SetVM
implicit none; private
public SetServices
public SetVM
!> Internal state type with pointers to three types defined by MOM.
type ocean_internalstate_type
type(ocean_public_type), pointer :: ocean_public_type_ptr
type(ocean_state_type), pointer :: ocean_state_type_ptr
type(ice_ocean_boundary_type), pointer :: ice_ocean_boundary_type_ptr
end type
!> Wrapper-derived type required to associate an internal state instance
!! with the ESMF/NUOPC component
type ocean_internalstate_wrapper
type(ocean_internalstate_type), pointer :: ptr
end type
!> Contains field information
type fld_list_type
character(len=64) :: stdname
character(len=64) :: shortname
character(len=64) :: transferOffer
integer :: ungridded_lbound = 0
integer :: ungridded_ubound = 0
end type fld_list_type
integer,parameter :: fldsMax = 100
integer :: fldsToOcn_num = 0
type (fld_list_type) :: fldsToOcn(fldsMax)
integer :: fldsFrOcn_num = 0
type (fld_list_type) :: fldsFrOcn(fldsMax)
integer :: dbug = 0
integer :: import_slice = 1
integer :: export_slice = 1
character(len=256) :: tmpstr
logical :: write_diagnostics = .false.
logical :: overwrite_timeslice = .false.
logical :: write_runtimelog = .false.
character(len=32) :: runtype !< run type
logical :: profile_memory = .true.
logical :: grid_attach_area = .false.
logical :: use_coldstart = .true.
logical :: use_mommesh = .true.
logical :: restart_eor = .false.
character(len=128) :: scalar_field_name = ''
integer :: scalar_field_count = 0
integer :: scalar_field_idx_grid_nx = 0
integer :: scalar_field_idx_grid_ny = 0
character(len=*),parameter :: u_FILE_u = &
__FILE__
#ifdef CESMCOUPLED
logical :: cesm_coupled = .true.
type(ESMF_GeomType_Flag) :: geomtype = ESMF_GEOMTYPE_MESH
#else
logical :: cesm_coupled = .false.
type(ESMF_GeomType_Flag) :: geomtype
#endif
character(len=8) :: restart_mode = 'alarms'
character(len=16) :: inst_suffix = ''
real(8) :: timere
type(ESMF_Time), allocatable :: restartFhTimes(:)
contains
!> NUOPC SetService method is the only public entry point.
!! SetServices registers all of the user-provided subroutines
!! in the module with the NUOPC layer.
!!
!! @param gcomp an ESMF_GridComp object
!! @param rc return code
subroutine SetServices(gcomp, rc)
type(ESMF_GridComp) :: gcomp !< an ESMF_GridComp object
integer, intent(out) :: rc !< return code
! local variables
character(len=*),parameter :: subname='(MOM_cap:SetServices)'
rc = ESMF_SUCCESS
! the NUOPC model component will register the generic methods
call NUOPC_CompDerive(gcomp, model_routine_SS, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
! switching to IPD versions
call ESMF_GridCompSetEntryPoint(gcomp, ESMF_METHOD_INITIALIZE, &
userRoutine=InitializeP0, phase=0, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
! set entry point for methods that require specific implementation
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_INITIALIZE, &
phaseLabelList=(/"IPDv03p1"/), userRoutine=InitializeAdvertise, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_INITIALIZE, &
phaseLabelList=(/"IPDv03p3"/), userRoutine=InitializeRealize, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! attach specializing method(s)
!------------------
call NUOPC_CompSpecialize(gcomp, specLabel=model_label_DataInitialize, &
specRoutine=DataInitialize, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=model_label_Advance, &
specRoutine=ModelAdvance, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_MethodRemove(gcomp, label=model_label_SetRunClock, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=model_label_SetRunClock, &
specRoutine=ModelSetRunClock, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=model_label_Finalize, &
specRoutine=ocean_model_finalize, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end subroutine SetServices
!> First initialize subroutine called by NUOPC. The purpose
!! is to set which version of the Initialize Phase Definition (IPD)
!! to use.
!!
!! For this MOM cap, we are using IPDv01.
!!
!! @param gcomp an ESMF_GridComp object
!! @param importState an ESMF_State object for import fields
!! @param exportState an ESMF_State object for export fields
!! @param clock an ESMF_Clock object
!! @param rc return code
subroutine InitializeP0(gcomp, importState, exportState, clock, rc)
type(ESMF_GridComp) :: gcomp !< ESMF_GridComp object
type(ESMF_State) :: importState, exportState !< ESMF_State object for
!! import/export fields
type(ESMF_Clock) :: clock !< ESMF_Clock object
integer, intent(out) :: rc !< return code
! local variables
logical :: isPresent, isSet
integer :: iostat
character(len=64) :: value, logmsg
character(len=*),parameter :: subname='(MOM_cap:InitializeP0)'
type(ESMF_VM) :: vm
integer :: mype
rc = ESMF_SUCCESS
! Switch to IPDv03 by filtering all other phaseMap entries
call NUOPC_CompFilterPhaseMap(gcomp, ESMF_METHOD_INITIALIZE, &
acceptStringList=(/"IPDv03p"/), rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
write_diagnostics = .false.
call NUOPC_CompAttributeGet(gcomp, name="DumpFields", value=value, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) write_diagnostics=(trim(value)=="true")
write(logmsg,*) write_diagnostics
call ESMF_LogWrite('MOM_cap:DumpFields = '//trim(logmsg), ESMF_LOGMSG_INFO)
write_runtimelog = .false.
call NUOPC_CompAttributeGet(gcomp, name="RunTimeLog", value=value, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) write_runtimelog=(trim(value)=="true")
write(logmsg,*) write_runtimelog
call ESMF_LogWrite('MOM_cap:RunTimeLog = '//trim(logmsg), ESMF_LOGMSG_INFO)
overwrite_timeslice = .false.
call NUOPC_CompAttributeGet(gcomp, name="OverwriteSlice", value=value, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) overwrite_timeslice=(trim(value)=="true")
write(logmsg,*) overwrite_timeslice
call ESMF_LogWrite('MOM_cap:OverwriteSlice = '//trim(logmsg), ESMF_LOGMSG_INFO)
profile_memory = .false.
call NUOPC_CompAttributeGet(gcomp, name="ProfileMemory", value=value, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) profile_memory=(trim(value)=="true")
write(logmsg,*) profile_memory
call ESMF_LogWrite('MOM_cap:ProfileMemory = '//trim(logmsg), ESMF_LOGMSG_INFO)
grid_attach_area = .false.
call NUOPC_CompAttributeGet(gcomp, name="GridAttachArea", value=value, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) grid_attach_area=(trim(value)=="true")
write(logmsg,*) grid_attach_area
call ESMF_LogWrite('MOM_cap:GridAttachArea = '//trim(logmsg), ESMF_LOGMSG_INFO)
call NUOPC_CompAttributeGet(gcomp, name='dbug_flag', value=value, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(value,*) dbug
end if
write(logmsg,'(i6)') dbug
call ESMF_LogWrite('MOM_cap:dbug = '//trim(logmsg), ESMF_LOGMSG_INFO)
scalar_field_name = ""
call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldName", value=value, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
scalar_field_name = trim(value)
call ESMF_LogWrite('MOM_cap:ScalarFieldName = '//trim(scalar_field_name), ESMF_LOGMSG_INFO)
endif
scalar_field_count = 0
call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldCount", value=value, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(value, *, iostat=iostat) scalar_field_count
if (iostat /= 0) then
call ESMF_LogSetError(ESMF_RC_ARG_BAD, &
msg=subname//": ScalarFieldCount not an integer: "//trim(value), &
line=__LINE__, file=__FILE__, rcToReturn=rc)
return
endif
write(logmsg,*) scalar_field_count
call ESMF_LogWrite('MOM_cap:ScalarFieldCount = '//trim(logmsg), ESMF_LOGMSG_INFO)
endif
scalar_field_idx_grid_nx = 0
call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldIdxGridNX", value=value, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(value, *, iostat=iostat) scalar_field_idx_grid_nx
if (iostat /= 0) then
call ESMF_LogSetError(ESMF_RC_ARG_BAD, &
msg=subname//": ScalarFieldIdxGridNX not an integer: "//trim(value), &
line=__LINE__, file=__FILE__, rcToReturn=rc)
return
endif
write(logmsg,*) scalar_field_idx_grid_nx
call ESMF_LogWrite('MOM_cap:ScalarFieldIdxGridNX = '//trim(logmsg), ESMF_LOGMSG_INFO)
endif
scalar_field_idx_grid_ny = 0
call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldIdxGridNY", value=value, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(value, *, iostat=iostat) scalar_field_idx_grid_ny
if (iostat /= 0) then
call ESMF_LogSetError(ESMF_RC_ARG_BAD, &
msg=subname//": ScalarFieldIdxGridNY not an integer: "//trim(value), &
line=__LINE__, file=__FILE__, rcToReturn=rc)
return
endif
write(logmsg,*) scalar_field_idx_grid_ny
call ESMF_LogWrite('MOM_cap:ScalarFieldIdxGridNY = '//trim(logmsg), ESMF_LOGMSG_INFO)
endif
use_coldstart = .true.
call NUOPC_CompAttributeGet(gcomp, name="use_coldstart", value=value, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) use_coldstart=(trim(value)=="true")
write(logmsg,*) use_coldstart
call ESMF_LogWrite('MOM_cap:use_coldstart = '//trim(logmsg), ESMF_LOGMSG_INFO)
use_mommesh = .true.
call NUOPC_CompAttributeGet(gcomp, name="use_mommesh", value=value, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) use_mommesh=(trim(value)=="true")
write(logmsg,*) use_mommesh
call ESMF_LogWrite('MOM_cap:use_mommesh = '//trim(logmsg), ESMF_LOGMSG_INFO)
if(use_mommesh)then
geomtype = ESMF_GEOMTYPE_MESH
call NUOPC_CompAttributeGet(gcomp, name='mesh_ocn', isPresent=isPresent, isSet=isSet, rc=rc)
if (.not. isPresent .and. .not. isSet) then
call ESMF_LogWrite('geomtype set to mesh but mesh_ocn is not specified', ESMF_LOGMSG_INFO)
call ESMF_Finalize(endflag=ESMF_END_ABORT)
endif
else
geomtype = ESMF_GEOMTYPE_GRID
endif
! Read end of run restart config option
call NUOPC_CompAttributeGet(gcomp, name="write_restart_at_endofrun", value=value, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
if (trim(value) .eq. '.true.') restart_eor = .true.
end if
end subroutine
!> Called by NUOPC to advertise import and export fields. "Advertise"
!! simply means that the standard names of all import and export
!! fields are supplied. The NUOPC layer uses these to match fields
!! between components in the coupled system.
!!
!! @param gcomp an ESMF_GridComp object
!! @param importState an ESMF_State object for import fields
!! @param exportState an ESMF_State object for export fields
!! @param clock an ESMF_Clock object
!! @param rc return code
subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
type(ESMF_GridComp) :: gcomp !< ESMF_GridComp object
type(ESMF_State) :: importState, exportState !< ESMF_State object for
!! import/export fields
type(ESMF_Clock) :: clock !< ESMF_Clock object
integer, intent(out) :: rc !< return code
! local variables
type(ESMF_VM) :: vm
type(ESMF_Time) :: MyTime
type(ESMF_TimeInterval) :: TINT
type (ocean_public_type), pointer :: ocean_public => NULL()
type (ocean_state_type), pointer :: ocean_state => NULL()
type(ice_ocean_boundary_type), pointer :: Ice_ocean_boundary => NULL()
type(ocean_internalstate_wrapper) :: ocean_internalstate
type(ocean_grid_type), pointer :: ocean_grid => NULL()
type(directories) :: dirs
type(time_type) :: Run_len !< length of experiment
type(time_type) :: time0 !< Start time of coupled model's calendar.
type(time_type) :: time_start !< The time at which to initialize the ocean model
type(time_type) :: Time_restart
type(time_type) :: DT
integer :: DT_OCEAN
integer :: isc,iec,jsc,jec
integer :: year=0, month=0, day=0, hour=0, minute=0, second=0
integer :: mpi_comm_mom
integer :: i,n
character(len=256) :: stdname, shortname
character(len=32) :: starttype ! model start type
character(len=512) :: diro
character(len=512) :: logfile
character(ESMF_MAXSTR) :: cvalue
character(len=64) :: logmsg
logical :: isPresent, isPresentDiro, isPresentLogfile, isSet
logical :: existflag
logical :: use_waves ! If true, the wave modules are active.
character(len=40) :: wave_method ! Wave coupling method.
integer :: userRc
integer :: localPet
integer :: localPeCount
integer :: iostat
integer :: readunit
character(len=512) :: restartfile ! Path/Name of restart file
character(len=2048) :: restartfiles ! Path/Name of restart files
! (same as restartfile if single restart file)
character(len=*), parameter :: subname='(MOM_cap:InitializeAdvertise)'
character(len=32) :: calendar
character(len=:), allocatable :: rpointer_filename
integer :: inst_index
real(8) :: MPI_Wtime, timeiads
!--------------------------------
rc = ESMF_SUCCESS
if(write_runtimelog) timeiads = MPI_Wtime()
call ESMF_LogWrite(subname//' enter', ESMF_LOGMSG_INFO)
allocate(Ice_ocean_boundary)
!allocate(ocean_state) ! ocean_model_init allocate this pointer
allocate(ocean_public)
allocate(ocean_internalstate%ptr)
ocean_internalstate%ptr%ice_ocean_boundary_type_ptr => Ice_ocean_boundary
ocean_internalstate%ptr%ocean_public_type_ptr => ocean_public
ocean_internalstate%ptr%ocean_state_type_ptr => ocean_state
call ESMF_VMGetCurrent(vm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_VMGet(VM, mpiCommunicator=mpi_comm_mom, localPet=localPet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_ClockGet(CLOCK, currTIME=MyTime, TimeStep=TINT, RC=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_TimeGet (MyTime, YY=YEAR, MM=MONTH, DD=DAY, H=HOUR, M=MINUTE, S=SECOND, RC=rc )
if (ChkErr(rc,__LINE__,u_FILE_u)) return
CALL ESMF_TimeIntervalGet(TINT, S=DT_OCEAN, RC=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
#ifdef CESMCOUPLED
call get_component_instance(gcomp, inst_suffix, inst_index, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ensemble_manager_init(inst_suffix)
rpointer_filename = 'rpointer.ocn'//trim(inst_suffix)
#endif
! reset shr logging to my log file
if (localPet==0) then
call NUOPC_CompAttributeGet(gcomp, name="diro", &
isPresent=isPresentDiro, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompAttributeGet(gcomp, name="logfile", &
isPresent=isPresentLogfile, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresentDiro .and. isPresentLogfile) then
call NUOPC_CompAttributeGet(gcomp, name="diro", value=diro, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompAttributeGet(gcomp, name="logfile", value=logfile, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (cesm_coupled) then
! Multiinstance logfile name needs a correction
if(len_trim(inst_suffix) > 0) then
n = index(logfile, '.')
logfile = logfile(1:n-1)//trim(inst_suffix)//logfile(n:)
endif
endif
open(newunit=stdout,file=trim(diro)//"/"//trim(logfile))
else
stdout = output_unit
endif
else
stdout = output_unit
endif
call shr_log_setLogUnit(stdout)
call NUOPC_CompAttributeAdd(gcomp, (/"logunit"/), rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompAttributeSet(gcomp, "logunit", stdout, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call MOM_infra_init(mpi_comm_mom)
! determine the calendar
if (cesm_coupled) then
call NUOPC_CompAttributeGet(gcomp, name="calendar", value=cvalue, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue,*) calendar
select case (trim(calendar))
case ("NO_LEAP")
call set_calendar_type (NOLEAP)
case ("GREGORIAN")
call set_calendar_type (GREGORIAN)
case default
call ESMF_LogSetError(ESMF_RC_ARG_BAD, &
msg=subname//": Calendar not supported in MOM6: "//trim(calendar), &
line=__LINE__, file=__FILE__, rcToReturn=rc)
end select
else
call set_calendar_type (NOLEAP)
endif
else
call set_calendar_type (JULIAN)
endif
! this ocean connector will be driven at set interval
DT = set_time (DT_OCEAN, 0)
! get current time
time_start = set_date (YEAR,MONTH,DAY,HOUR,MINUTE,SECOND)
if (is_root_pe()) then
write(stdout,*) subname//'current time: y,m,d-',year,month,day,'h,m,s=',hour,minute,second
endif
! get start/reference time
call ESMF_ClockGet(CLOCK, refTime=MyTime, RC=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_TimeGet (MyTime, YY=YEAR, MM=MONTH, DD=DAY, H=HOUR, M=MINUTE, S=SECOND, RC=rc )
if (ChkErr(rc,__LINE__,u_FILE_u)) return
time0 = set_date (YEAR,MONTH,DAY,HOUR,MINUTE,SECOND)
if (is_root_pe()) then
write(stdout,*) subname//'start time: y,m,d-',year,month,day,'h,m,s=',hour,minute,second
endif
starttype = ""
call NUOPC_CompAttributeGet(gcomp, name='start_type', value=cvalue, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue,*) starttype
else
call ESMF_LogWrite('MOM_cap:start_type unset - using input.nml for restart option', &
ESMF_LOGMSG_INFO)
endif
runtype = ""
if (trim(starttype) == trim('startup')) then
runtype = "initial"
else if (trim(starttype) == trim('continue') ) then
runtype = "continue"
else if (trim(starttype) == trim('branch')) then
runtype = "continue"
else if (len_trim(starttype) > 0) then
call ESMF_LogSetError(ESMF_RC_ARG_BAD, &
msg=subname//": unknown starttype - "//trim(starttype), &
line=__LINE__, file=__FILE__, rcToReturn=rc)
return
endif
if (len_trim(runtype) > 0) then
call ESMF_LogWrite('MOM_cap:startup = '//trim(runtype), ESMF_LOGMSG_INFO)
endif
restartfile = ""; restartfiles = ""
if (runtype == "initial") then
if (cesm_coupled) then
restartfiles = "n"
else
call get_MOM_input(dirs=dirs)
restartfiles = dirs%input_filename(1:1)
endif
call ESMF_LogWrite('MOM_cap:restartfile = '//trim(restartfiles), ESMF_LOGMSG_INFO)
else if (runtype == "continue") then ! hybrid or branch or continuos runs
if (cesm_coupled) then
call ESMF_LogWrite('MOM_cap: restart requested, using rpointer.ocn', ESMF_LOGMSG_WARNING)
call ESMF_GridCompGet(gcomp, vm=vm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_VMGet(vm, localPet=localPet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (localPet == 0) then
! this hard coded for rpointer.ocn right now
open(newunit=readunit, file=rpointer_filename, form='formatted', status='old', iostat=iostat)
if (iostat /= 0) then
call ESMF_LogSetError(ESMF_RC_FILE_OPEN, msg=subname//' ERROR opening '//rpointer_filename, &
line=__LINE__, file=u_FILE_u, rcToReturn=rc)
return
endif
do
read(readunit,'(a)', iostat=iostat) restartfile
if (iostat /= 0) then
if (len(trim(restartfiles))>1 .and. iostat<0) then
exit ! done reading restart files list.
else
call ESMF_LogSetError(ESMF_RC_FILE_READ, msg=subname//' ERROR reading '//rpointer_filename, &
line=__LINE__, file=u_FILE_u, rcToReturn=rc)
return
endif
endif
! check if the length of restartfiles variable is sufficient:
if (len(restartfiles)-len(trim(restartfiles)) < len(trim(restartfile))) then
call MOM_error(FATAL, "Restart file name(s) too long.")
endif
restartfiles = trim(restartfiles) // " " // trim(restartfile)
enddo
close(readunit)
endif
! broadcast attribute set on master task to all tasks
call ESMF_VMBroadcast(vm, restartfiles, count=len(restartfiles), rootPet=0, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
else
call ESMF_LogWrite('MOM_cap: restart requested, use input.nml', ESMF_LOGMSG_WARNING)
endif
endif
ocean_public%is_ocean_pe = .true.
if (cesm_coupled .and. len_trim(inst_suffix)>0) then
call ocean_model_init(ocean_public, ocean_state, time0, time_start, &
input_restart_file=trim(adjustl(restartfiles)), inst_index=inst_index)
else
call ocean_model_init(ocean_public, ocean_state, time0, time_start, input_restart_file=trim(adjustl(restartfiles)))
endif
! GMM, this call is not needed in CESM. Check with EMC if it can be deleted.
call ocean_model_flux_init(ocean_state)
call ocean_model_init_sfc(ocean_state, ocean_public)
call get_domain_extent(ocean_public%domain, isc, iec, jsc, jec)
allocate ( Ice_ocean_boundary% u_flux (isc:iec,jsc:jec), &
Ice_ocean_boundary% v_flux (isc:iec,jsc:jec), &
Ice_ocean_boundary% t_flux (isc:iec,jsc:jec), &
Ice_ocean_boundary% q_flux (isc:iec,jsc:jec), &
Ice_ocean_boundary% salt_flux (isc:iec,jsc:jec), &
Ice_ocean_boundary% lw_flux (isc:iec,jsc:jec), &
Ice_ocean_boundary% sw_flux_vis_dir (isc:iec,jsc:jec), &
Ice_ocean_boundary% sw_flux_vis_dif (isc:iec,jsc:jec), &
Ice_ocean_boundary% sw_flux_nir_dir (isc:iec,jsc:jec), &
Ice_ocean_boundary% sw_flux_nir_dif (isc:iec,jsc:jec), &
Ice_ocean_boundary% lprec (isc:iec,jsc:jec), &
Ice_ocean_boundary% fprec (isc:iec,jsc:jec), &
Ice_ocean_boundary% seaice_melt_heat (isc:iec,jsc:jec),&
Ice_ocean_boundary% seaice_melt (isc:iec,jsc:jec), &
Ice_ocean_boundary% mi (isc:iec,jsc:jec), &
Ice_ocean_boundary% ice_fraction (isc:iec,jsc:jec), &
Ice_ocean_boundary% u10_sqr (isc:iec,jsc:jec), &
Ice_ocean_boundary% p (isc:iec,jsc:jec), &
Ice_ocean_boundary% lrunoff (isc:iec,jsc:jec), &
Ice_ocean_boundary% frunoff (isc:iec,jsc:jec))
Ice_ocean_boundary%u_flux = 0.0
Ice_ocean_boundary%v_flux = 0.0
Ice_ocean_boundary%t_flux = 0.0
Ice_ocean_boundary%q_flux = 0.0
Ice_ocean_boundary%salt_flux = 0.0
Ice_ocean_boundary%lw_flux = 0.0
Ice_ocean_boundary%sw_flux_vis_dir = 0.0
Ice_ocean_boundary%sw_flux_vis_dif = 0.0
Ice_ocean_boundary%sw_flux_nir_dir = 0.0
Ice_ocean_boundary%sw_flux_nir_dif = 0.0
Ice_ocean_boundary%lprec = 0.0
Ice_ocean_boundary%fprec = 0.0
Ice_ocean_boundary%seaice_melt = 0.0
Ice_ocean_boundary%seaice_melt_heat= 0.0
Ice_ocean_boundary%mi = 0.0
Ice_ocean_boundary%ice_fraction = 0.0
Ice_ocean_boundary%u10_sqr = 0.0
Ice_ocean_boundary%p = 0.0
Ice_ocean_boundary%lrunoff = 0.0
Ice_ocean_boundary%frunoff = 0.0
if (cesm_coupled) then
allocate (Ice_ocean_boundary% hrain (isc:iec,jsc:jec), &
Ice_ocean_boundary% hsnow (isc:iec,jsc:jec), &
Ice_ocean_boundary% hrofl (isc:iec,jsc:jec), &
Ice_ocean_boundary% hrofi (isc:iec,jsc:jec), &
Ice_ocean_boundary% hevap (isc:iec,jsc:jec), &
Ice_ocean_boundary% hcond (isc:iec,jsc:jec))
Ice_ocean_boundary%hrain = 0.0
Ice_ocean_boundary%hsnow = 0.0
Ice_ocean_boundary%hrofl = 0.0
Ice_ocean_boundary%hrofi = 0.0
Ice_ocean_boundary%hevap = 0.0
Ice_ocean_boundary%hcond = 0.0
endif
call query_ocean_state(ocean_state, use_waves=use_waves, wave_method=wave_method)
if (use_waves) then
if (wave_method == "EFACTOR") then
allocate( Ice_ocean_boundary%lamult(isc:iec,jsc:jec) )
Ice_ocean_boundary%lamult = 0.0
else if (wave_method == "SURFACE_BANDS") then
call query_ocean_state(ocean_state, NumWaveBands=Ice_ocean_boundary%num_stk_bands)
allocate(Ice_ocean_boundary%ustkb(isc:iec,jsc:jec,Ice_ocean_boundary%num_stk_bands), source=0.0)
allocate(Ice_ocean_boundary%vstkb(isc:iec,jsc:jec,Ice_ocean_boundary%num_stk_bands), source=0.0)
allocate(Ice_ocean_boundary%stk_wavenumbers(Ice_ocean_boundary%num_stk_bands), source=0.0)
call query_ocean_state(ocean_state, WaveNumbers=Ice_ocean_boundary%stk_wavenumbers, unscale=.true.)
else
call MOM_error(FATAL, "Unsupported WAVE_METHOD encountered in NUOPC cap.")
endif
endif
! Consider adding this:
! if (.not.use_waves) Ice_ocean_boundary%num_stk_bands = 0
ocean_internalstate%ptr%ocean_state_type_ptr => ocean_state
call ESMF_GridCompSetInternalState(gcomp, ocean_internalstate, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (len_trim(scalar_field_name) > 0) then
call fld_list_add(fldsToOcn_num, fldsToOcn, trim(scalar_field_name), "will_provide")
call fld_list_add(fldsFrOcn_num, fldsFrOcn, trim(scalar_field_name), "will_provide")
endif
!--------- import fields -------------
call fld_list_add(fldsToOcn_num, fldsToOcn, "Fioi_salt" , "will provide") ! from ice
call fld_list_add(fldsToOcn_num, fldsToOcn, "Foxx_taux" , "will provide")
call fld_list_add(fldsToOcn_num, fldsToOcn, "Foxx_tauy" , "will provide")
call fld_list_add(fldsToOcn_num, fldsToOcn, "Foxx_sen" , "will provide")
call fld_list_add(fldsToOcn_num, fldsToOcn, "Foxx_evap" , "will provide")
call fld_list_add(fldsToOcn_num, fldsToOcn, "Foxx_lwnet" , "will provide")
call fld_list_add(fldsToOcn_num, fldsToOcn, "Foxx_swnet_vdr" , "will provide")
call fld_list_add(fldsToOcn_num, fldsToOcn, "Foxx_swnet_vdf" , "will provide")
call fld_list_add(fldsToOcn_num, fldsToOcn, "Foxx_swnet_idr" , "will provide")
call fld_list_add(fldsToOcn_num, fldsToOcn, "Foxx_swnet_idf" , "will provide")
call fld_list_add(fldsToOcn_num, fldsToOcn, "Faxa_rain" , "will provide")
call fld_list_add(fldsToOcn_num, fldsToOcn, "Faxa_snow" , "will provide")
call fld_list_add(fldsToOcn_num, fldsToOcn, "Sa_pslv" , "will provide")
call fld_list_add(fldsToOcn_num, fldsToOcn, "Foxx_rofl" , "will provide") !-> liquid runoff
call fld_list_add(fldsToOcn_num, fldsToOcn, "Foxx_rofi" , "will provide") !-> ice runoff
call fld_list_add(fldsToOcn_num, fldsToOcn, "Si_ifrac" , "will provide") !-> ice fraction
call fld_list_add(fldsToOcn_num, fldsToOcn, "So_duu10n" , "will provide") !-> wind^2 at 10m
call fld_list_add(fldsToOcn_num, fldsToOcn, "Fioi_meltw" , "will provide")
call fld_list_add(fldsToOcn_num, fldsToOcn, "Fioi_melth" , "will provide")
call fld_list_add(fldsToOcn_num, fldsToOcn, "Foxx_hrain" , "will provide")
call fld_list_add(fldsToOcn_num, fldsToOcn, "Foxx_hsnow" , "will provide")
call fld_list_add(fldsToOcn_num, fldsToOcn, "Foxx_hevap" , "will provide")
call fld_list_add(fldsToOcn_num, fldsToOcn, "Foxx_hcond" , "will provide")
call fld_list_add(fldsToOcn_num, fldsToOcn, "Foxx_hrofl" , "will provide")
call fld_list_add(fldsToOcn_num, fldsToOcn, "Foxx_hrofi" , "will provide")
if (use_waves) then
if (wave_method == "EFACTOR") then
call fld_list_add(fldsToOcn_num, fldsToOcn, "Sw_lamult" , "will provide")
else if (wave_method == "SURFACE_BANDS") then
call fld_list_add(fldsToOcn_num, fldsToOcn, "Sw_pstokes_x", "will provide", &
ungridded_lbound=1, ungridded_ubound=Ice_ocean_boundary%num_stk_bands)
call fld_list_add(fldsToOcn_num, fldsToOcn, "Sw_pstokes_y", "will provide", &
ungridded_lbound=1, ungridded_ubound=Ice_ocean_boundary%num_stk_bands)
else
call MOM_error(FATAL, "Unsupported WAVE_METHOD encountered in NUOPC cap.")
endif
endif
!--------- export fields -------------
call fld_list_add(fldsFrOcn_num, fldsFrOcn, "So_omask" , "will provide")
call fld_list_add(fldsFrOcn_num, fldsFrOcn, "So_t" , "will provide")
call fld_list_add(fldsFrOcn_num, fldsFrOcn, "So_s" , "will provide")
call fld_list_add(fldsFrOcn_num, fldsFrOcn, "So_u" , "will provide")
call fld_list_add(fldsFrOcn_num, fldsFrOcn, "So_v" , "will provide")
call fld_list_add(fldsFrOcn_num, fldsFrOcn, "So_dhdx" , "will provide")
call fld_list_add(fldsFrOcn_num, fldsFrOcn, "So_dhdy" , "will provide")
call fld_list_add(fldsFrOcn_num, fldsFrOcn, "Fioo_q" , "will provide")
call fld_list_add(fldsFrOcn_num, fldsFrOcn, "So_bldepth" , "will provide")
do n = 1,fldsToOcn_num
call NUOPC_Advertise(importState, standardName=fldsToOcn(n)%stdname, name=fldsToOcn(n)%shortname, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
enddo
do n = 1,fldsFrOcn_num
call NUOPC_Advertise(exportState, standardName=fldsFrOcn(n)%stdname, name=fldsFrOcn(n)%shortname, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
enddo
if(write_runtimelog .and. is_root_pe()) write(stdout,*) 'In ',trim(subname),' time ', MPI_Wtime()-timeiads
end subroutine InitializeAdvertise
!> Called by NUOPC to realize import and export fields. "Realizing" a field
!! means that its grid has been defined and an ESMF_Field object has been
!! created and put into the import or export State.
!!
!! @param gcomp an ESMF_GridComp object
!! @param importState an ESMF_State object for import fields
!! @param exportState an ESMF_State object for export fields
!! @param clock an ESMF_Clock object
!! @param rc return code
subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
type(ESMF_GridComp) :: gcomp !< ESMF_GridComp object
type(ESMF_State) :: importState, exportState !< ESMF_State object for
!! import/export fields
type(ESMF_Clock) :: clock !< ESMF_Clock object
integer, intent(out) :: rc !< return code
! Local Variables
type(ESMF_VM) :: vm
type(ESMF_Grid) :: gridIn, gridOut
type(ESMF_Mesh) :: Emesh, EmeshTemp
type(ESMF_DeLayout) :: delayout
type(ESMF_Distgrid) :: Distgrid
type(ESMF_DistGridConnection), allocatable :: connectionList(:)
type(ESMF_StateItem_Flag) :: itemFlag
type (ocean_public_type), pointer :: ocean_public => NULL()
type (ocean_state_type), pointer :: ocean_state => NULL()
type(ice_ocean_boundary_type), pointer :: Ice_ocean_boundary => NULL()
type(ocean_grid_type) , pointer :: ocean_grid
type(ocean_internalstate_wrapper) :: ocean_internalstate
integer :: npet, ntiles
integer :: npes ! number of PEs (from FMS).
integer :: nxg, nyg, cnt
integer :: isc,iec,jsc,jec
integer, allocatable :: xb(:),xe(:),yb(:),ye(:),pe(:)
integer, allocatable :: deBlockList(:,:,:)
integer, allocatable :: petMap(:)
integer, allocatable :: deLabelList(:)
integer, allocatable :: indexList(:)
integer :: ioff, joff
integer :: i, j, n, i1, j1, n1, jlast
integer :: lbnd1,ubnd1,lbnd2,ubnd2
integer :: lbnd3,ubnd3,lbnd4,ubnd4
integer :: nblocks_tot
logical :: found
logical :: isPresent, isSet
integer(ESMF_KIND_I4), pointer :: dataPtr_mask(:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_area(:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_xcen(:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_ycen(:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_xcor(:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_ycor(:,:)
integer :: mpicom
integer :: localPet
integer :: localPeCount
integer :: lsize
integer :: ig,jg, ni,nj,k
integer, allocatable :: gindex(:) ! global index space
integer, allocatable :: gindex_ocn(:) ! global index space for ocean cells (excl. masked cells)
integer, allocatable :: gindex_elim(:) ! global index space for eliminated cells
character(len=128) :: fldname
character(len=256) :: cvalue
character(len=256) :: frmt ! format specifier for several error msgs
character(len=512) :: err_msg ! error messages
integer :: spatialDim
integer :: numOwnedElements
type(ESMF_Array) :: elemMaskArray
real(ESMF_KIND_R8) , pointer :: ownedElemCoords(:)
real(ESMF_KIND_R8) , pointer :: lat(:), latMesh(:)
real(ESMF_KIND_R8) , pointer :: lon(:), lonMesh(:)
integer(ESMF_KIND_I4) , pointer :: mask(:), maskMesh(:)
real(ESMF_KIND_R8) :: diff_lon, diff_lat
real :: eps_omesh
real(ESMF_KIND_R8) :: L2_to_rad2
type(ESMF_Field) :: lfield
real(ESMF_KIND_R8), allocatable :: mesh_areas(:)
real(ESMF_KIND_R8), allocatable :: model_areas(:)
real(ESMF_KIND_R8), pointer :: dataPtr_mesh_areas(:)
real(ESMF_KIND_R8) :: min_areacor(2)
real(ESMF_KIND_R8) :: max_areacor(2)
real(ESMF_KIND_R8) :: min_areacor_glob(2)
real(ESMF_KIND_R8) :: max_areacor_glob(2)
character(len=*), parameter :: subname='(MOM_cap:InitializeRealize)'
integer :: niproc, njproc
integer :: ip, jp, pe_ix
integer :: num_elim_blocks ! number of blocks to be eliminated
integer :: num_elim_cells_global, num_elim_cells_local, num_elim_cells_remaining
integer, allocatable :: cell_mask(:,:)
real(8) :: MPI_Wtime, timeirls
!--------------------------------
rc = ESMF_SUCCESS
if(write_runtimelog) timeirls = MPI_Wtime()
call shr_log_setLogUnit (stdout)
!----------------------------------------------------------------------------
! Get pointers to ocean internal state
!----------------------------------------------------------------------------
call ESMF_GridCompGetInternalState(gcomp, ocean_internalstate, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
Ice_ocean_boundary => ocean_internalstate%ptr%ice_ocean_boundary_type_ptr
ocean_public => ocean_internalstate%ptr%ocean_public_type_ptr
ocean_state => ocean_internalstate%ptr%ocean_state_type_ptr
!----------------------------------------------------------------------------
! Get mpi information
!----------------------------------------------------------------------------
call ESMF_VMGetCurrent(vm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_VMGet(vm, petCount=npet, mpiCommunicator=mpicom, localPet=localPet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!---------------------------------
! global mom grid size
!---------------------------------
call mpp_get_global_domain(ocean_public%domain, xsize=nxg, ysize=nyg)
write(tmpstr,'(a,2i6)') subname//' nxg,nyg = ',nxg,nyg
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO)
!---------------------------------
! number of tiles per PET, assumed to be 1, and number of pes (tiles) total
!---------------------------------
ntiles=mpp_get_ntile_count(ocean_public%domain) ! this is tiles on this pe
if (ntiles /= 1) then
rc = ESMF_FAILURE
call ESMF_LogWrite(subname//' ntiles must be 1', ESMF_LOGMSG_ERROR)
endif
npes = mpp_get_domain_npes(ocean_public%domain)
write(tmpstr,'(a,1i6)') subname//' npes = ',npes
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO)
!---------------------------------
! get start and end indices of each tile and their PET
!---------------------------------
allocate(xb(npes),xe(npes),yb(npes),ye(npes),pe(npes))
call mpp_get_compute_domains(ocean_public%domain, xbegin=xb, xend=xe, ybegin=yb, yend=ye)
call mpp_get_pelist(ocean_public%domain, pe)
if (dbug > 1) then
do n = 1,npes
write(tmpstr,'(a,6i6)') subname//' tiles ',n,pe(n),xb(n),xe(n),yb(n),ye(n)
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO)
enddo
endif
!---------------------------------
! Create either a grid or a mesh
!---------------------------------
!Get the ocean grid and sizes of global and computational domains
call get_ocean_grid(ocean_state, ocean_grid)
if (geomtype == ESMF_GEOMTYPE_MESH) then
!---------------------------------
! Create a MOM6 mesh
!---------------------------------
call get_global_grid_size(ocean_grid, ni, nj)
lsize = ( ocean_grid%iec - ocean_grid%isc + 1 ) * ( ocean_grid%jec - ocean_grid%jsc + 1 )
num_elim_blocks = 0
num_elim_cells_global = 0
num_elim_cells_local = 0
num_elim_cells_remaining = 0
! Compute the number of eliminated blocks (specified in MOM_mask_table)
if (associated(ocean_grid%Domain%maskmap)) then
njproc = size(ocean_grid%Domain%maskmap, 1)
niproc = size(ocean_grid%Domain%maskmap, 2)