-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmom_cap.F90
2159 lines (1898 loc) · 96.1 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
!>
!! @mainpage MOM NUOPC Cap
!! @author Fei Liu (fei.liu@gmail.com)
!! @date 5/10/13 Original documentation
!! @author Rocky Dunlap (rocky.dunlap@noaa.gov)
!! @date 1/12/17 Moved to doxygen
!!
!! @tableofcontents
!!
!! @section Overview Overview
!!
!! **This MOM cap has been tested with MOM5 and MOM6.**
!!
!! This document describes the MOM "cap", which is a small software layer that is
!! required when the [MOM ocean model] (http://mom-ocean.org/web)
!! is used in [National Unified Operation Prediction Capability]
!! (http://www.earthsystemcog.org/projects/nuopc) (NUOPC) coupled systems.
!! The NUOPC Layer is a software layer built on top of the [Earth System Modeling
!! Framework] (https://www.earthsystemcog.org/projects/esmf) (ESMF).
!! ESMF is a high-performance modeling framework that provides
!! data structures, interfaces, and operations suited for building coupled models
!! from a set of components. NUOPC refines the capabilities of ESMF by providing
!! a more precise definition of what it means for a model to be a component and
!! how components should interact and share data in a coupled system. The NUOPC
!! Layer software is designed to work with typical high-performance models in the
!! Earth sciences domain, most of which are written in Fortran and are based on a
!! distributed memory model of parallelism (MPI).
!! A NUOPC "cap" is a Fortran module that serves as the interface to a model
!! when it's used in a NUOPC-based coupled system.
!! The term "cap" is used because it is a small software layer that sits on top
!! of model code, making calls into it and exposing model data structures in a
!! standard way. For more information about creating NUOPC caps in general, please
!! see the [Building a NUOPC Model]
!! (http://www.earthsystemmodeling.org/esmf_releases/non_public/ESMF_7_0_0/NUOPC_howtodoc/)
!! how-to document.
!!
!! The MOM cap package includes the cap itself (mom_cap.F90, a Fortran module), a
!! set of time utilities (time_utils.F90) for converting between ESMF and FMS
!! time types, and two makefiles. Also included are self-describing dependency
!! makefile fragments (mom.mk and mom.mk.template), although these can be generated
!! by the makefiles for specific installations of the MOM cap.
!!
!! @subsection CapSubroutines Cap Subroutines
!!
!! The MOM cap Fortran module contains a set of subroutines that are required
!! by NUOPC. These subroutines are called by the NUOPC infrastructure according
!! to a predefined calling sequence. Some subroutines are called during
!! initialization of the coupled system, some during the run of the coupled
!! system, and some during finalization of the coupled system. The initialization
!! sequence is the most complex and is governed by the NUOPC technical rules.
!! Details about the initialization sequence can be found in the [NUOPC Reference Manual]
!! (http://www.earthsystemmodeling.org/esmf_releases/non_public/ESMF_7_0_0/NUOPC_refdoc/node3.html#SECTION00034000000000000000).
!!
!! A particularly important part of the NUOPC intialization sequence is to establish
!! field connections between models. Simply put, a field connection is established
!! when a field output by one model can be consumed by another. As an example, the
!! MOM model is able to accept a precipitation rate when coupled to an atmosphere
!! model. In this case a field connection will be established between the precipitation
!! rate exported from the atmosphere and the precipitation rate imported into the
!! MOM model. Because models may uses different variable names for physical
!! quantities, NUOPC relies on a set of standard names and a built-in, extensible
!! standard name dictionary to match fields between models. More information about
!! the use of standard names can be found in the [NUOPC Reference Manual]
!! (http://www.earthsystemmodeling.org/esmf_releases/non_public/ESMF_7_0_0/NUOPC_refdoc/node3.html#SECTION00032000000000000000).
!!
!! Two key initialization phases that appear in every NUOPC cap, including this MOM
!! cap are the field "advertise" and field "realize" phases. *Advertise* is a special
!! NUOPC term that refers to a model participating in a coupled system
!! providing a list of standard names of required import fields and available export
!! fields. In other words, each model will advertise to the other models which physical fields
!! it needs and which fields it can provide when coupled. NUOPC compares all of the advertised
!! standard names and creates a set of unidirectional links, each from one export field
!! in a model to one import field in another model. When these connections have been established,
!! all models in the coupled system need to provide a description of their geographic
!! grid (e.g., lat-lon, tri-polar, cubed sphere, etc.) and allocate their connected
!! fields on that grid. In NUOPC terms, this is refered to as *realizing* a set of
!! fields. NUOPC relies on ESMF data types for this, such as the [ESMF_Grid]
!! (http://www.earthsystemmodeling.org/esmf_releases/public/last/ESMF_refdoc/node5.html#SECTION05080000000000000000)
!! type, which describes logically rectangular grids and the [ESMF_Field]
!! (http://www.earthsystemmodeling.org/esmf_releases/public/last/ESMF_refdoc/node5.html#SECTION05030000000000000000)
!! type, which wraps a models data arrays and provides basic metadata. Because ESMF supports
!! interpolation between different grids (sometimes called "regridding" or "grid remapping"),
!! it is not necessary that models share a grid. As you will see below
!! the *advertise* and *realize* phases each have a subroutine in the HYCOM cap.
!!
!! The following table summarizes the NUOPC-required subroutines that appear in the
!! MOM cap. The "Phase" column says whether the subroutine is called during the
!! initialization, run, or finalize part of the coupled system run.
!!
!! Phase | MOM Cap Subroutine | Description
!! ---------|--------------------------------------------------------------------|-------------------------------------------------------------
!! Init | [InitializeP0] (@ref mom_cap_mod::initializep0) | Sets the Initialize Phase Definition (IPD) version to use
!! Init | [InitializeAdvertise] (@ref mom_cap_mod::initializeadvertise) | Advertises standard names of import and export fields
!! Init | [InitializeRealize] (@ref mom_cap_mod::initializerealize) | Creates an ESMF_Grid for the MOM grid as well as ESMF_Fields for import and export fields
!! Run | [ModelAdvance] (@ref mom_cap_mod::modeladvance) | Advances the model by a timestep
!! Final | [Finalize] (@ref mom_cap_mod::ocean_model_finalize) | Cleans up
!!
!! @section UnderlyingModelInterfaces Underlying Model Interfaces
!!
!!
!! @subsection DomainCreation Domain Creation
!!
!! The MOM tripolar grid is represented as a 2D `ESMF_Grid` and coupling fields are placed
!! on this grid. Calls related to creating the grid are located in the [InitializeRealize]
!! (@ref mom_cap_mod::initializerealize) subroutine, which is called by the NUOPC infrastructure
!! during the intialization sequence.
!!
!! The cap determines parameters for setting up the grid by calling subroutines in the
!! `mpp_domains_mod` module. The global domain size is determined by calling `mpp_get_global_domain()`.
!! A check is in place to ensure that there is only a single tile in the domain (the
!! cap is currently limited to one tile; multi-tile mosaics are not supported). The
!! decomposition across processors is determined via calls to `mpp_get_compute_domains()`
!! (to retrieve decomposition block indices) and `mpp_get_pelist()` (to determine how
!! blocks are assigned to processors).
!!
!! The grid is created in several steps:
!! - an `ESMF_DELayout` is created based on the pelist from MOM
!! - an `ESMF_DistGrid` is created over the global index space. Connections are set
!! up so that the index space is periodic in the first dimension and has a
!! fold at the top for the bipole. The decompostion blocks are also passed in
!! along with the `ESMF_DELayout` mentioned above.
!! - an `ESMF_Grid` is then created by passing in the above `ESMF_DistGrid`.
!!
!! Masks, areas, center (tlat, tlon), and corner (ulat, ulon) coordinates are then added to the `ESMF_Grid`
!! by retrieving those fields from MOM with calls to `ocean_model_data_get()`.
!!
!! @subsection Initialization Initialization
!!
!! During the [InitializeAdvertise] (@ref mom_cap_mod::initializeadvertise) phase, calls are
!! made to MOM's native initialization subroutines, including `fms_init()`, `constants_init()`,
!! `field_manager_init()`, `diag_manager_init()`, and `set_calendar_type()`. The MPI communicator
!! is pulled in through the ESMF VM object for the MOM component. The dt and start time are set
!! from parameters from the incoming ESMF clock with calls to `set_time()` and `set_date().`
!!
!!
!! @subsection Run Run
!!
!! The [ModelAdvance] (@ref mom_cap_mod::modeladvance) subroutine is called by the NUOPC
!! infrastructure when it's time for MOM to advance in time. During this subroutine, there is a
!! call into the MOM update routine:
!!
!! call update_ocean_model(Ice_ocean_boundary, Ocean_state, Ocean_sfc, Time, Time_step_coupled)
!!
!! Prior to this call, the cap performs a few steps:
!! - the `Time` and `Time_step_coupled` parameters, which are based on FMS types, are derived from the incoming ESMF clock
!! - there are calls to two stubs: `ice_ocn_bnd_from_data()` and `external_coupler_sbc_before()` - these are currently
!! inactive, but may be modified to read in import data from file or from an external coupler
!! - diagnostics are optionally written to files `field_ocn_import_*`, one for each import field
!! - import fields are prepared:
!! - the sign is reversed on `mean_evap_rate` and `mean_sensi_heat_flux`
!! - momentum flux vectors are rotated to internal grid
!! - optionally, a call is made to `ocean_model_restart()` at the interval `restart_interval`
!!
!! After the call to `update_ocean_model()`, the cap performs these steps:
!! - the `ocean_mask` export is set to match that of the internal MOM mask
!! - the `freezing_melting_potential` export is converted from J m-2 to W m-2 by dividing by the coupling interval
!! - vector rotations are applied to the `ocean_current_zonal` and `ocean_current_merid` exports, back to lat-lon grid
!! - diagnostics are optionally written to files `field_ocn_export_*`, one for each export field
!! - a call is made to `external_coupler_sbc_after()` to update exports from an external coupler (currently an inactive stub)
!! - calls are made to `dumpMomInternal()` to write files `field_ocn_internal_*` for all internal fields (both import and export)
!!
!! @subsubsection VectorRotations Vector Rotations
!!
!! Vector rotations are applied to incoming momentum fluxes (from regular lat-lon to tripolar grid) and
!! outgoing ocean currents (from tripolar to regular lat-lon). The rotation angles are provided
!! from the native MOM grid by a call to `get_ocean_grid(Ocean_grid)`.
!! The cosine and sine of the rotation angle are:
!!
!! Ocean_grid%cos_rot(i,j)
!! Ocean_grid%sin_rot(i,j)
!!
!! The rotation of momentum flux from regular lat-lon to tripolar is:
!! \f[
!! \begin{bmatrix}
!! \tau_x' \\
!! \tau_y'
!! \end{bmatrix} =
!! \begin{bmatrix}
!! cos \theta & sin \theta \\
!! -sin \theta & cos \theta
!! \end{bmatrix} *
!! \begin{bmatrix}
!! \tau_x \\
!! \tau_y
!! \end{bmatrix}
!! \f]
!!
!! The rotation of ocean current from tripolar to regular lat-lon is:
!! \f[
!! \begin{bmatrix}
!! u' \\
!! v'
!! \end{bmatrix} =
!! \begin{bmatrix}
!! cos \theta & -sin \theta \\
!! sin \theta & cos \theta
!! \end{bmatrix} *
!! \begin{bmatrix}
!! u \\
!! v
!! \end{bmatrix}
!! \f]
!! @subsection Finalization Finalization
!!
!! NUOPC infrastructure calls [ocean_model_finalize] (@ref mom_cap_mod::ocean_model_finalize)
!! at the end of the run. This subroutine is a hook to call into MOM's native shutdown
!! procedures:
!!
!! call ocean_model_end (Ocean_sfc, Ocean_State, Time)
!! call diag_manager_end(Time )
!! call field_manager_end
!! call fms_io_exit
!! call fms_end
!!
!! @section ModelFields Model Fields
!!
!! The following tables list the import and export fields currently set up in the MOM cap.
!!
!! @subsection ImportFields Import Fields
!!
!! Standard Name | Units | Model Variable | Description | Notes
!! ----------------------------------|------------|-----------------|-----------------------------------------------|--------------------------------------
!! inst_pres_height_surface | Pa | p | pressure of overlying sea ice and atmosphere | |
!! mass_of_overlying_sea_ice | kg | mi | mass of overlying sea ice | |
!! mean_calving_heat_flx | W m-2 | calving_hflx | heat flux, relative to 0C, of frozen land water into ocean | |
!! mean_calving_rate | kg m-2 s-1 | calving | mass flux of frozen runoff | |
!! mean_evap_rate | kg m-2 s-1 | q_flux | specific humidity flux | sign reversed (- evap)
!! mean_fprec_rate | kg m-2 s-1 | fprec | mass flux of frozen precip | |
!! mean_merid_moment_flx | Pa | v_flux | j-directed wind stress into ocean | [vector rotation] (@ref VectorRotations) applied - lat-lon to tripolar
!! mean_net_lw_flx | W m-2 | lw_flux | long wave radiation | |
!! mean_net_sw_ir_dif_flx | W m-2 | sw_flux_nir_dif | diffuse near IR shortwave radiation | |
!! mean_net_sw_ir_dir_flx | W m-2 | sw_flux_nir_dir | direct near IR shortwave radiation | |
!! mean_net_sw_vis_dif_flx | W m-2 | sw_flux_vis_dif | diffuse visible shortware radiation | |
!! mean_net_sw_vis_dir_flx | W m-2 | sw_flux_vis_dir | direct visible shortware radiation | |
!! mean_prec_rate | kg m-2 s-1 | lprec | mass flux of liquid precip | |
!! mean_runoff_heat_flx | W m-2 | runoff_hflx | heat flux, relative to 0C, of liquid land water into ocean | |
!! mean_runoff_rate | kg m-2 s-1 | runoff | mass flux of liquid runoff | |
!! mean_salt_rate | kg m-2 s-1 | salt_flux | salt flux | |
!! mean_sensi_heat_flx | W m-2 | t_flux | sensible heat flux into ocean | sign reversed (- sensi)
!! mean_zonal_moment_flx | Pa | u_flux | j-directed wind stress into ocean | [vector rotation] (@ref VectorRotations) applied - lat-lon to tripolar
!!
!!
!! @subsection ExportField Export Fields
!!
!! Export fields are populated from the `ocean_sfc` parameter (type `ocean_public_type`)
!! after the call to `update_ocean_model()`.
!!
!! Standard Name | Units | Model Variable | Description | Notes
!! ----------------------------------|------------|-----------------|-------------------------------------------|---------------------------------------------------------------------
!! freezing_melting_potential | W m-2 | frazil | accumulated heating from frazil formation | cap converts model units (J m-2) to (W m-2) for export
!! ocean_mask | | | ocean mask | |
!! ocn_current_merid | m s-1 | v_surf | j-directed surface velocity on u-cell | [vector rotation] (@ref VectorRotations) applied - tripolar to lat-lon
!! ocn_current_zonal | m s-1 | u_surf | i-directed surface velocity on u-cell | [vector rotation] (@ref VectorRotations) applied - tripolar to lat-lon
!! s_surf | psu | s_surf | sea surface salinity on t-cell | |
!! sea_lev | m | sea_lev | sea level | model computation is eta_t + patm/(rho0*grav) - eta_geoid - eta_tide
!! sea_surface_temperature | K | t_surf | sea surface temperature on t-cell | |
!!
!! @subsection MemoryManagement Memory Management
!!
!! The MOM cap has an internal state type with pointers to three
!! types defined by MOM. There is also a small wrapper derived type
!! required to associate an internal state instance
!! with the ESMF/NUOPC component:
!!
!! 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
!!
!! type ocean_internalstate_wrapper
!! type(ocean_internalstate_type), pointer :: ptr
!! end type
!!
!! The member of type `ocean_public_type` stores ocean surface fields used during the coupling.
!! The member of type `ocean_state_type` is required by the ocean driver,
!! although its internals are private (not to be used by the coupling directly).
!! This type is passed to the ocean init and update routines
!! so that it can maintain state there if desired.
!! The member of type `ice_ocean_boundary_type` is populated by this cap
!! with incoming coupling fields from other components. These three derived types are allocated during the
!! [InitializeAdvertise] (@ref mom_cap_mod::initializeadvertise) phase. Also during that
!! phase, the `ice_ocean_boundary` type members are all allocated using bounds retrieved
!! from `mpp_get_compute_domain()`.
!!
!! During the [InitializeRealize] (@ref mom_cap_mod::initializerealize) phase,
!! `ESMF_Field`s are created for each of the coupling fields in the `ice_ocean_boundary`
!! and `ocean_public_type` members of the internal state. These fields directly reference into the members of
!! the `ice_ocean_boundary` and `ocean_public_type` so that memory-to-memory copies are not required to move
!! data from the cap's import and export states to the memory areas used internally
!! by MOM.
!!
!! @subsection IO I/O
!!
!! The cap can optionally output coupling fields for diagnostic purposes if the ESMF attribute
!! "DumpFields" has been set to "true". In this case the cap will write out NetCDF files
!! with names "field_ocn_import_<fieldname>.nc" and "field_ocn_export_<fieldname>.nc".
!! Additionally, calls will be made to the cap subroutine [dumpMomInternal]
!! (@ref mom_cap_mod::dumpmominternal) to write out model internal fields to files
!! named "field_ocn_internal_<fieldname>.nc". In all cases these NetCDF files will
!! contain a time series of field data.
!!
!! @section BuildingAndInstalling Building and Installing
!!
!! There are two makefiles included with the MOM cap, makefile and makefile.nuopc.
!! The makefile.nuopc file is intended to be used within another build system, such
!! as the NEMSAppBuilder. The regular makefile can be used generally for building
!! and installing the cap. Two variables must be customized at the top:
!! - `INSTALLDIR` - where to copy the cap library and dependent libraries
!! - `NEMSMOMDIR` - location of the MOM library and FMS library
!!
!! To install run:
!! $ make install
!!
!! A makefile fragment, mom.mk, will also be copied into the directory. The fragment
!! defines several variables that can be used by another build system to include the
!! MOM cap and its dependencies.
!!
!! @subsection Dependencies Dependencies
!!
!! The MOM cap is dependent on the MOM library itself (lib_ocean.a) and the FMS
!! library (lib_FMS.a).
!!
!! @section RuntimeConfiguration Runtime Configuration
!!
!! At runtime, the MOM cap can be configured with several options provided
!! as ESMF attributes. Attributes can be set in the cap by the NUOPC Driver
!! above this cap, or in some systems (e.g., NEMS) attributes are set by
!! reading in from a configuration file. The available attributes are:
!!
!! * `DumpFields` - when set to "true", write out diagnostic NetCDF files for import/export/internal fields
!! * `ProfileMemory` - when set to "true", write out memory usage information to the ESMF log files; this
!! information is written when entering and leaving the [ModelAdvance]
!! (@ref mom_cap_mod::modeladvance) subroutine and before and after the call to
!! `update_ocean_model()`.
!! * `OceanSolo` - when set to "true", this option indicates that MOM is being run
!! uncoupled; in this case the vector rotations and other data manipulations
!! on import fields are skipped
!! * `restart_interval` - integer number of seconds indicating the interval at
!! which to call `ocean_model_restart()`; no restarts written if set to 0
!! * `GridAttachArea` - when set to "true", this option indicates that MOM grid attaches cell area
!! using internal values computed in MOM. The default value is "false", grid cell area will
!! be computed in ESMF.
!!
!!
!! @section Repository
!! The MOM NUOPC cap is maintained in a GitHub repository:
!! https://github.com/feiliuesmf/nems_mom_cap
!!
!! @section References
!!
!! - [MOM Home Page] (http://mom-ocean.org/web)
!!
!!
module mom_cap_mod
use constants_mod, only: constants_init
use data_override_mod, only: data_override_init, data_override
use diag_manager_mod, only: diag_manager_init, diag_manager_end
use field_manager_mod, only: field_manager_init, field_manager_end
use fms_mod, only: fms_init, fms_end, open_namelist_file, check_nml_error
use fms_mod, only: close_file, file_exist, uppercase
use fms_io_mod, only: fms_io_exit
use mpp_domains_mod, only: domain2d, mpp_get_compute_domain, 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, mpp_global_field
use mpp_io_mod, only: mpp_open, MPP_RDONLY, MPP_ASCII, MPP_OVERWR, MPP_APPEND, mpp_close, MPP_SINGLE
use mpp_mod, only: input_nml_file, mpp_error, FATAL, NOTE, mpp_pe, mpp_npes, mpp_set_current_pelist
use mpp_mod, only: stdlog, stdout, mpp_root_pe, mpp_clock_id
use mpp_mod, only: mpp_clock_begin, mpp_clock_end, MPP_CLOCK_SYNC
use mpp_mod, only: MPP_CLOCK_DETAILED, CLOCK_COMPONENT, MAXPES
use time_interp_external_mod, only: time_interp_external_init
use time_manager_mod, only: set_calendar_type, time_type, increment_date
use time_manager_mod, only: set_time, set_date, get_time, get_date, month_name
use time_manager_mod, only: GREGORIAN, JULIAN, NOLEAP, THIRTY_DAY_MONTHS, NO_CALENDAR
use time_manager_mod, only: operator( <= ), operator( < ), operator( >= )
use time_manager_mod, only: operator( + ), operator( - ), operator( / )
use time_manager_mod, only: operator( * ), operator( /= ), operator( > )
use time_manager_mod, only: date_to_string
use time_manager_mod, only: fms_get_calendar_type => get_calendar_type
use ocean_model_mod, only: ocean_model_restart, ocean_public_type, ocean_state_type
use ocean_model_mod, only: ocean_model_data_get
use ocean_model_mod, only: ocean_model_init , update_ocean_model, ocean_model_end, get_ocean_grid
#ifdef MOM6_CAP
use ocean_model_mod, only: ice_ocean_boundary_type
use MOM_grid, only: ocean_grid_type
#else
use ocean_types_mod, only: ice_ocean_boundary_type, ocean_grid_type
#endif
use ESMF
use NUOPC
use NUOPC_Model, &
model_routine_SS => SetServices, &
model_label_Advance => label_Advance, &
model_label_Finalize => label_Finalize
use time_utils_mod
implicit none
private
public SetServices
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
type(ocean_grid_type), pointer :: ocean_grid_ptr
end type
type ocean_internalstate_wrapper
type(ocean_internalstate_type), pointer :: ptr
end type
type fld_list_type
character(len=64) :: stdname
character(len=64) :: shortname
character(len=64) :: transferOffer
logical :: assoc ! is the farrayPtr associated with internal data
real(ESMF_KIND_R8), dimension(:,:), pointer :: farrayPtr
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 :: import_slice = 1
integer :: export_slice = 1
character(len=256) :: tmpstr
integer :: dbrc
type(ESMF_Grid), save :: mom_grid_i
logical :: write_diagnostics = .true.
logical :: profile_memory = .true.
logical :: ocean_solo = .true.
logical :: grid_attach_area = .false.
integer(ESMF_KIND_I8) :: restart_interval
contains
!-----------------------------------------------------------------------
!------------------- Solo Ocean code starts here -----------------------
!-----------------------------------------------------------------------
!> 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
integer, intent(out) :: rc
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 (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
! switching to IPD versions
call ESMF_GridCompSetEntryPoint(gcomp, ESMF_METHOD_INITIALIZE, &
userRoutine=InitializeP0, phase=0, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
! set entry point for methods that require specific implementation
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_INITIALIZE, &
phaseLabelList=(/"IPDv01p1"/), userRoutine=InitializeAdvertise, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_INITIALIZE, &
phaseLabelList=(/"IPDv01p3"/), userRoutine=InitializeRealize, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
! attach specializing method(s)
call NUOPC_CompSpecialize(gcomp, specLabel=model_label_Advance, &
specRoutine=ModelAdvance, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call NUOPC_CompSpecialize(gcomp, specLabel=model_label_Finalize, &
specRoutine=ocean_model_finalize, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
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
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc
character(len=10) :: value
rc = ESMF_SUCCESS
! Switch to IPDv01 by filtering all other phaseMap entries
call NUOPC_CompFilterPhaseMap(gcomp, ESMF_METHOD_INITIALIZE, &
acceptStringList=(/"IPDv01p"/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_AttributeGet(gcomp, name="DumpFields", value=value, defaultValue="true", &
convention="NUOPC", purpose="Instance", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
write_diagnostics=(trim(value)=="true")
call ESMF_LogWrite('MOM_CAP:DumpFields = '//trim(value), ESMF_LOGMSG_INFO, rc=dbrc)
call ESMF_AttributeGet(gcomp, name="ProfileMemory", value=value, defaultValue="true", &
convention="NUOPC", purpose="Instance", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
profile_memory=(trim(value)/="false")
call ESMF_LogWrite('MOM_CAP:ProfileMemory = '//trim(value), ESMF_LOGMSG_INFO, rc=dbrc)
call ESMF_AttributeGet(gcomp, name="OceanSolo", value=value, defaultValue="false", &
convention="NUOPC", purpose="Instance", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
ocean_solo=(trim(value)=="true")
call ESMF_LogWrite('MOM_CAP:OceanSolo = '//trim(value), ESMF_LOGMSG_INFO, rc=dbrc)
! Retrieve restart_interval in (seconds)
! A restart_interval value of 0 means no restart will be written.
call ESMF_AttributeGet(gcomp, name="restart_interval", value=value, defaultValue="0", &
convention="NUOPC", purpose="Instance", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
restart_interval = ESMF_UtilString2Int(value, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
if(restart_interval < 0) then
call ESMF_LogSetError(ESMF_RC_NOT_VALID, &
msg="MOM_CAP: OCN attribute: restart_interval cannot be negative.", &
line=__LINE__, &
file=__FILE__, rcToReturn=rc)
return
endif
call ESMF_LogWrite('MOM_CAP:restart_interval = '//trim(value), ESMF_LOGMSG_INFO, rc=dbrc)
call ESMF_AttributeGet(gcomp, name="GridAttachArea", value=value, defaultValue="false", &
convention="NUOPC", purpose="Instance", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
grid_attach_area=(trim(value)=="true")
call ESMF_LogWrite('MOM_CAP:GridAttachArea = '//trim(value), ESMF_LOGMSG_INFO, rc=dbrc)
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
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc
type(ESMF_VM) :: vm
type(ESMF_Time) :: MyTime
type(ESMF_TimeInterval) :: TINT
type (ocean_public_type), pointer :: Ocean_sfc => 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(time_type) :: Run_len ! length of experiment
type(time_type) :: Time
type(time_type) :: Time_restart
type(time_type) :: DT
integer :: DT_OCEAN
integer :: isc,iec,jsc,jec
integer :: dt_cpld = 86400
integer :: year=0, month=0, day=0, hour=0, minute=0, second=0
integer :: mpi_comm_mom
type(ESMF_Grid) :: gridIn
type(ESMF_Grid) :: gridOut
integer :: npet, npet_x, npet_y
character(len=*),parameter :: subname='(mom_cap:InitializeAdvertise)'
rc = ESMF_SUCCESS
allocate(Ice_ocean_boundary)
!allocate(Ocean_state) ! ocean_model_init allocate this pointer
allocate(Ocean_sfc)
allocate(ocean_internalstate%ptr)
ocean_internalstate%ptr%ice_ocean_boundary_type_ptr => Ice_ocean_boundary
ocean_internalstate%ptr%ocean_public_type_ptr => Ocean_sfc
ocean_internalstate%ptr%ocean_state_type_ptr => Ocean_state
call ESMF_VMGetCurrent(vm, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_VMGet(VM, mpiCommunicator=mpi_comm_mom, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_ClockGet(CLOCK, currTIME=MyTime, TimeStep=TINT, RC=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_TimeGet (MyTime, &
YY=YEAR, MM=MONTH, DD=DAY, &
H=HOUR, M =MINUTE, S =SECOND, &
RC=rc )
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
CALL ESMF_TimeIntervalGet(TINT, S=DT_OCEAN, RC=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call fms_init(mpi_comm_mom)
call constants_init
call field_manager_init
call set_calendar_type (JULIAN )
call diag_manager_init
! this ocean connector will be driven at set interval
dt_cpld = DT_OCEAN
DT = set_time (DT_OCEAN, 0)
Time = set_date (YEAR,MONTH,DAY,HOUR,MINUTE,SECOND)
Ocean_sfc%is_ocean_pe = .true.
call ocean_model_init(Ocean_sfc, Ocean_state, Time, Time)
call data_override_init(Ocean_domain_in = Ocean_sfc%domain)
call mpp_get_compute_domain(Ocean_sfc%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% runoff (isc:iec,jsc:jec), &
Ice_ocean_boundary% calving (isc:iec,jsc:jec), &
Ice_ocean_boundary% runoff_hflx (isc:iec,jsc:jec), &
Ice_ocean_boundary% calving_hflx (isc:iec,jsc:jec), &
Ice_ocean_boundary% mi (isc:iec,jsc:jec), &
Ice_ocean_boundary% p (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%runoff = 0.0
Ice_ocean_boundary%calving = 0.0
Ice_ocean_boundary%runoff_hflx = 0.0
Ice_ocean_boundary%calving_hflx = 0.0
Ice_ocean_boundary%mi = 0.0
Ice_ocean_boundary%p = 0.0
call external_coupler_sbc_init(Ocean_sfc%domain, dt_cpld, Run_len)
ocean_internalstate%ptr%ocean_state_type_ptr => Ocean_state
call ESMF_GridCompSetInternalState(gcomp, ocean_internalstate, rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call MOM_FieldsSetup(ice_ocean_boundary, ocean_sfc)
call MOM_AdvertiseFields(importState, fldsToOcn_num, fldsToOcn, rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call MOM_AdvertiseFields(exportState, fldsFrOcn_num, fldsFrOcn, rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
#ifdef MOM6_CAP
! When running mom6 solo, the rotation angles are not computed internally
! in MOM6. We need to
! calculate cos and sin of rotational angle for MOM6; the values
! are stored in ocean_internalstate%ptr%ocean_grid_ptr%cos_rot and sin_rot
! The rotation angles are retrieved during run time to rotate incoming
! and outgoing vectors
!
call calculate_rot_angle(Ocean_state, ocean_sfc, &
ocean_internalstate%ptr%ocean_grid_ptr)
#endif
write(*,*) '----- MOM initialization phase Advertise completed'
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
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc
! Local Variables
type(ESMF_VM) :: vm
type(ESMF_Grid) :: gridIn
type(ESMF_Grid) :: gridOut
type(ESMF_DeLayout) :: delayout
type(ESMF_Distgrid) :: Distgrid
type(ESMF_DistGridConnection), allocatable :: connectionList(:)
type (ocean_public_type), pointer :: Ocean_sfc => 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
integer :: npet, ntiles
integer :: nxg, nyg, cnt
integer :: isc,iec,jsc,jec
integer, allocatable :: xb(:),xe(:),yb(:),ye(:),pe(:)
integer, allocatable :: deBlockList(:,:,:), &
petMap(:),deLabelList(:), &
indexList(:)
integer :: ioff, joff
integer :: i, j, n, i1, j1, n1, icount
integer :: lbnd1,ubnd1,lbnd2,ubnd2
integer :: lbnd3,ubnd3,lbnd4,ubnd4
integer :: nblocks_tot
logical :: found
real(ESMF_KIND_R8), allocatable :: ofld(:,:), gfld(:,:)
real(ESMF_KIND_R8), pointer :: t_surf(:,:)
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(:,:)
type(ESMF_Field) :: field_t_surf
character(len=*),parameter :: subname='(mom_cap:InitializeRealize)'
rc = ESMF_SUCCESS
call ESMF_GridCompGetInternalState(gcomp, ocean_internalstate, rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
Ice_ocean_boundary => ocean_internalstate%ptr%ice_ocean_boundary_type_ptr
Ocean_sfc => ocean_internalstate%ptr%ocean_public_type_ptr
Ocean_state => ocean_internalstate%ptr%ocean_state_type_ptr
call ESMF_VMGetCurrent(vm, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_VMGet(vm, petCount=npet, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
!---------------------------------
! global mom grid size
!---------------------------------
call mpp_get_global_domain(Ocean_sfc%domain, xsize=nxg, ysize=nyg)
write(tmpstr,'(a,2i6)') subname//' nxg,nyg = ',nxg,nyg
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, rc=dbrc)
!---------------------------------
! number of tiles per PET, assumed to be 1, and number of pes (tiles) total
!---------------------------------
ntiles=mpp_get_ntile_count(Ocean_sfc%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, rc=dbrc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
endif
ntiles=mpp_get_domain_npes(Ocean_sfc%domain)
write(tmpstr,'(a,1i6)') subname//' ntiles = ',ntiles
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, rc=dbrc)
!---------------------------------
! get start and end indices of each tile and their PET
!---------------------------------
allocate(xb(ntiles),xe(ntiles),yb(ntiles),ye(ntiles),pe(ntiles))
call mpp_get_compute_domains(Ocean_sfc%domain, xbegin=xb, xend=xe, ybegin=yb, yend=ye)
call mpp_get_pelist(Ocean_sfc%domain, pe)
do n = 1,ntiles
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, rc=dbrc)
enddo
!---------------------------------
! create delayout and distgrid
!---------------------------------
allocate(deBlockList(2,2,ntiles))
allocate(petMap(ntiles))
allocate(deLabelList(ntiles))
do n = 1, ntiles
deLabelList(n) = n
deBlockList(1,1,n) = xb(n)
deBlockList(1,2,n) = xe(n)
deBlockList(2,1,n) = yb(n)
deBlockList(2,2,n) = ye(n)
petMap(n) = pe(n)
! write(tmpstr,'(a,3i8)') subname//' iglo = ',n,deBlockList(1,1,n),deBlockList(1,2,n)
! call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, rc=dbrc)
! write(tmpstr,'(a,3i8)') subname//' jglo = ',n,deBlockList(2,1,n),deBlockList(2,2,n)
! call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, rc=dbrc)
! write(tmpstr,'(a,2i8)') subname//' pe = ',n,petMap(n)
! call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, rc=dbrc)
!--- assume a tile with starting index of 1 has an equivalent wraparound tile on the other side
enddo
delayout = ESMF_DELayoutCreate(petMap, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
allocate(connectionList(2))
! bipolar boundary condition at top row: nyg
call ESMF_DistGridConnectionSet(connectionList(1), tileIndexA=1, &
tileIndexB=1, positionVector=(/nxg+1, 2*nyg+1/), &
orientationVector=(/-1, -2/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
! periodic boundary condition along first dimension
call ESMF_DistGridConnectionSet(connectionList(2), tileIndexA=1, &
tileIndexB=1, positionVector=(/nxg, 0/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
distgrid = ESMF_DistGridCreate(minIndex=(/1,1/), maxIndex=(/nxg,nyg/), &
! indexflag = ESMF_INDEX_DELOCAL, &
deBlockList=deBlockList, &
! deLabelList=deLabelList, &
delayout=delayout, &
connectionList=connectionList, &
rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
deallocate(xb,xe,yb,ye,pe)
deallocate(connectionList)
deallocate(deLabelList)
deallocate(deBlockList)
deallocate(petMap)
call ESMF_DistGridGet(distgrid=distgrid, localDE=0, elementCount=cnt, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
allocate(indexList(cnt))
write(tmpstr,'(a,i8)') subname//' distgrid cnt= ',cnt
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, rc=dbrc)
call ESMF_DistGridGet(distgrid=distgrid, localDE=0, seqIndexList=indexList, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
write(tmpstr,'(a,4i8)') subname//' distgrid list= ',&
indexList(1),indexList(cnt),minval(indexList), maxval(indexList)
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, rc=dbrc)
deallocate(IndexList)
!---------------------------------
! create grid
!---------------------------------
gridIn = ESMF_GridCreate(distgrid=distgrid, &
gridEdgeLWidth=(/0,0/), gridEdgeUWidth=(/0,1/), &
coordSys = ESMF_COORDSYS_SPH_DEG, &
rc = rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
mom_grid_i = gridIn
call ESMF_GridAddCoord(gridIn, staggerLoc=ESMF_STAGGERLOC_CENTER, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_GridAddCoord(gridIn, staggerLoc=ESMF_STAGGERLOC_CORNER, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_GridAddItem(gridIn, itemFlag=ESMF_GRIDITEM_MASK, itemTypeKind=ESMF_TYPEKIND_I4, &
staggerLoc=ESMF_STAGGERLOC_CENTER, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out