-
Notifications
You must be signed in to change notification settings - Fork 1
/
LIS_NUOPC_Cap.F90
1749 lines (1507 loc) · 64.3 KB
/
LIS_NUOPC_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 NASA's Land Information System (LIS) NUOPC Cap
!! @author Daniel Rosen (daniel.rosen@noaa.gov)
!! @author ESMF Support (esmf_support@list.woc.noaa.gov)
!! @date 03/14/2017 LIS NUOPC Cap Added to GitHub
!! @date 03/15/2017 Documentation Added
!!
!! @tableofcontents
!!
!! @section Overview Overview
!!
!! The Land Information System (LIS) is a surface model wrapper developed
!! and maintained by the National Aeronautics and Space Administration (NASA).
!! LIS abstracts several land and ocean surface models with standard
!! interfaces. The LIS cap wraps LIS with NUOPC compliant interfaces. The
!! result is configurable surface model capable of coupling with other models
!! in the National Unified Operational Prediction Capability (NUOPC). As of
!! LIS version 7.1 only Noah v2.7.1 and v.3.3 have NUOPC coupling capabilities.
!!
!! This page documents the technical design of the specialized NUOPC model and
!! the LIS gluecode. For generic NUOPC model documentation please see the
!! [NUOPC Reference Manual] (https://www.earthsystemcog.org/projects/nuopc/refmans).
!!
!!
!! @section NuopcSpecialization NUOPC Model Specialized Entry Points
!!
!! This cap specializes the cap configuration, initialization, advertised
!! fields, realized fields, data initialization, clock, run, and finalize.
!!
!! @subsection SetServices Set Services (Register Subroutines)
!!
!! Table summarizing the NUOPC specialized subroutines registered during
!! [SetServices] (@ref LIS_NUOPC::SetServices). The "Phase" column says
!! whether the subroutine is called during the initialization, run, or
!! finalize part of the coupled system run.
!!
!! Phase | Cap Subroutine | Description
!! -------|---------------------------------------------------|-------------------------------------------------------------
!! Init | [InitializeP0] (@ref LIS_NUOPC::InitializeP0) | Set the Initialize Phase Definition (IPD). Configure model
!! Init | [InitializeP1] (@ref LIS_NUOPC::InitializeP1) | Initialize model. Advertize import and export fields
!! Init | [InitializeP3] (@ref LIS_NUOPC::InitializeP3) | Realize import and export fields
!! Init | [DataInitialize] (@ref LIS_NUOPC::DataInitialize) | Initialize import and export data
!! Init | [SetClock] (@ref LIS_NUOPC::SetClock) | Set model clock during initialization
!! Run | [CheckImport] (@ref LIS_NUOPC::CheckImport) | Check timestamp on import data.
!! Run | [ModelAdvance] (@ref LIS_NUOPC::ModelAdvance) | Advances the model by a timestep
!! Final | [ModelFinalize] (@ref LIS_NUOPC::ModelFinalize) | Releases memory
!!
!!
!! @section Initialize Initialize
!!
!! Description of the initialization phases and internal model calls.
!! - [InitializeP0] (@ref LIS_NUOPC::InitializeP0)
!! - [InitializeP1] (@ref LIS_NUOPC::InitializeP1)
!! - [InitializeP3] (@ref LIS_NUOPC::InitializeP3)
!! - [DataInitialize] (@ref LIS_NUOPC::DataInitialize)
!! - [SetClock] (@ref LIS_NUOPC::SetClock)
!!
!! @subsection InitializeP0 InitializeP0
!!
!! During initialize phase 0 the runtime configuration is read in from model
!! attributes and the initialization phase definition version is set to
!! IPDv03.
!!
!! @subsection InitializeP1 InitializeP1
!!
!! During initialize phase 1 the model is initialized and the import and
!! export fields are advertised in nested import and export states. Import
!! fields are configured in the forcing variables list file.
!!
!! @subsection InitializeP3 InitializeP3
!!
!! During initialize phase 3 import and export fields are realized in each
!! nested import and export state if they are connected through NUOPC.
!! Realized fields are created on the LIS grid. All export fields are realized
!! if realize all export fields is turned on.
!!
!! @subsection DataInitialize DataInitialize
!!
!! During data initialize this cap checks the timestamp of all import fields
!! dependent on a coupled model. Once all dependent import fields have been
!! initialized this cap is marked initalized.
!!
!! @subsection SetClock SetClock
!!
!! During set clock the cap creates a new clock for each nest. The time step
!! for each nest is set in LIS configuration file and initialized during LIS
!! initialization. The time accumulation tracker for each timestep is reset to
!! zero. The cap's time step is updated to the shortest time step
!! of all nests. The restart write time step is also created and the restart
!! write time accumulation tracker is reset to zero.
!!
!!
!! @section Run Run
!!
!! Description of the run phase(s) and internal model calls.
!! - [CheckImport] (@ref LIS_NUOPC::CheckImport)
!! - [ModelAdvance] (@ref LIS_NUOPC::ModelAdvance)
!!
!! @subsection CheckImport CheckImport
!!
!! During check import the import data is checked to verify that it is at
!! the beginning or end of the timestep.
!!
!! @subsection ModelAdvance ModelAdvance
!!
!! During model advance each nest time accumulation tracker is increased by
!! the timestep of the cap. If the time accumlation tracker is greater than
!! the time step of the nest then the nest is advanced.
!!
!!
!! @section Finalize Finalize
!!
!! Description of the finalize phase and internal model calls.
!! - [ModelFinalize] (@ref LIS_NUOPC::ModelFinalize)
!!
!! @subsection ModelFinalize ModelFinalize
!!
!! During model finalize LIS finalize subroutines are called and memory
!! allocated during cap initialization is released.
!!
!!
!! @subsection ModelConfiguration Model Configuration
!!
!! Custom model attributes are used to configure the model.
!!
!! Attribute | Default | Description
!! ------------------|----------------|-------------------------------------------------------------------------------------
!! Verbosity | VERBOSITY_LV1 | Verbosity levels are defined in LIS_NUOPC_Macros.h
!! RealizeAllExport | FALSE | Realize all export fields including non connected fields
!! RestartInterval | NEVER | Determine when to write NUOPC state restart files in seconds
!! ConfigFile | lis.config | Set the LIS configuraion file
!! WriteGrid | FALSE | Write a NetCDF file for the LIS domain
!! WriteImport | FALSE | Write a NetCDF file for the import state before model advance
!! WriteExport | FALSE | Write a NetCDF file for the export state after model advance
!! LogMemory | FALSE | Write memory statistics. (Not Implemented)
!! TestFillImport | FALSE | Fill the import state with ESMF_FieldFill(sincos) for testing
!! TestFillExport | FALSE | Fill the export state with ESMF_FieldFill(sincos) for testing
!!
!!
!! @section ModelFields Model Fields
!!
!! The following tables list the import and export fields.
!!
!! @subsection ImportFields Import Fields
!!
!! Import fields arelisted in the import_list parameter.
!!
!! Standard Name | Units | Model Variable | Description | Notes
!! ---------------|--------|-----------------|--------------------------------------------|--------------------------------------
!! dummy_field_1 | Pa | forcing_1 | field description for first import field | |
!! dummy_field_2 | kg | forcing_2 | field description for second import field | |
!! dummy_field_3 | W m-2 | forcing_3 | field description for third import field | field notes
!!
!! @subsection ExportField Export Fields
!!
!! Export fields are listed in the export_list parameter.
!!
!! Standard Name | Units | Model Variable | Description | Notes
!! ---------------|---------|-----------------|-------------------------------------------|---------------------------
!! dummy_field_1 | m | output_1 | field description for first export field | field notes
!! dummy_field_2 | kg | output_2 | field description for second export field | |
!! dummy_field_3 | m s-1 | output_3 | field description for third export field | field notes
!!
!!
!! @section MemoryManagement Memory Management
!!
!! Model configuration is stored in a custom internal state data type. A
!! pointer to the custom internal state data type is stored in the component.
!!
!! The cap allocates new memory for each field so that 2-D coordinate points
!! can be translated into the LIS tiled field points.
!!
!! @section IO Input and Output
!!
!! Cap diagnostic output is written to the ESMF PET Logs. Cap diagnostic
!! output can be increased or decreased by setting the Verbosity attribute.
!!
!! NUOPC state restart write files are written depending on the
!! RestartInterval attribute. If set to 0 then NUOPC state restart write files
!! will never be written.
!!
!! LIS diagnostics output is written to the LIS logs configured in the LIS
!! configuration file.
!!
!! LIS output files are written to the output directory configured in the LIS
!! configuration file. LIS output includes LIS history files and LIS restart
!! files.
!!
!! @section Dependencies Dependencies
!!
!! Dependencies
!! - [HDF5 v1.8.11+] (https://support.hdfgroup.org/HDF5/)
!! - [NetCDF v4.3.0+] (http://www.unidata.ucar.edu/software/netcdf/docs/)
!! - [NetCDF FORTRAN] (http://www.unidata.ucar.edu/software/netcdf/docs/building_netcdf_fortran.html)
!! - [JasPer v1.900.1] (https://www.ece.uvic.ca/~frodo/jasper)
!! - [Grib API v1.12.3+] (https://software.ecmwf.int/wiki/display/GRIB/Home)
!!
!! @subsection HDF5 HDF5
!!
!! Configure, Build, and Install
!! $ ./configure --enable-fortran --prefix=HDF5_DIR
!! $ make
!! $ make install
!!
!! @subsection NetCDF NetCDF
!!
!! Add the following environment variables.
!! - CPPFLAGS '-IHDF5_DIR/include'
!! - LDFLAGS '-LHDF5_DIR/lib'
!!
!! Configure, Build, and Install
!! $ ./configure --prefix=NETCDF_DIR --enable-netcdf-4 --disable-dap-remote-tests
!! $ make
!! $ make install
!!
!! @subsection NetCDFFortran NetCDF Fortran
!!
!! Add the following environment variables.
!! - LD_LIBRARY_PATH 'NETCDF_DIR/lib:$LD_LIBRARY_PATH'
!! - CPPFLAGS '-INETCDF_DIR/include'
!! - LDFLAGS '-LNETCDF_DIR/lib'
!!
!! Configure, Build, and Install
!! $ ./configure --prefix=NETCDF_DIR
!! $ make
!! $ make install
!!
!! @subsection JasPer JasPer
!!
!! Configure, Build, and Install
!! $ ./configure --enable-shared --prefix=JASPER_DIR
!! $ make
!! $ make install
!!
!! @subsection GribAPI Grib API
!!
!! Configure, Build, and Install
!! $ ./configure --with-jasper=JASPER_DIR --with-netcdf=NETCDF_DIR --prefix=GRIB_API_DIR
!! $ make
!! $ make install
!!
!! @section BuildingAndInstalling Building and Installing
!!
!! Environment Variables
!! - ESMFMKFILE
!! - JASPER
!! - GRIB_API
!!
!! NUOPC Makefile Targets
!! - nuopc
!! - nuopcinstall
!! - nuopcclean
!!
!! The build system in [Makefile] (@ref Makefile) wraps the LIS build system
!! and adds the nuopc, nuopcinstall, and nuopcclean targets. Before building
!! make sure to configure the internal model.
!!
!! To build and install into the current directory run:
!! $ make nuopc
!!
!! To install into an alternative directory run:
!! $ make nuopcinstall DESTDIR=<INSTALL_DIR> INSTDIR=<SUBDIR>
!!
!! To build with debugging information run:
!! $ make nuopc DEBUG=on
!!
!! @section Repository
!! The LIS NUOPC cap is maintained in a GitHub repository:
!! https://github.com/NESII/lis_cap
!!
!! @section References
!!
!! - [LIS] (https://modelingguru.nasa.gov/community/atmospheric/lis)
!! - [ESPS] (https://www.earthsystemcog.org/projects/esps)
!! - [ESMF] (https://www.earthsystemcog.org/projects/esmf)
!! - [NUOPC] (https://www.earthsystemcog.org/projects/nuopc/)
#define FILENAME "LIS_NUOPC_Cap.F90"
#define MODNAME "LIS_NUOPC_Cap"
#include "LIS_NUOPC_Macros.h"
module LIS_NUOPC
use ESMF
use NUOPC
use NUOPC_Model, &
model_routine_SS => SetServices, &
model_label_DataInitialize => label_DataInitialize, &
model_label_SetClock => label_SetClock, &
model_label_CheckImport => label_CheckImport, &
model_label_Advance => label_Advance, &
model_label_Finalize => label_Finalize
use LIS_NUOPC_Gluecode
use LIS_ESMF_Extensions
implicit none
private
public SetServices
CHARACTER(LEN=*), PARAMETER :: label_InternalState = 'InternalState'
INTEGER, PARAMETER :: MAXNEST = 999999999
type type_InternalStateStruct
integer :: verbosity = VERBOSITY_LV1
character(len=64) :: configFile = 'lis.config'
logical :: realizeAllExport = .FALSE.
logical :: nestToNest = .FALSE.
logical :: lwrite_debug = .FALSE.
logical :: lwrite_grid = .TRUE.
logical :: llog_memory = .FALSE.
logical :: ltestfill_imp = .FALSE.
logical :: ltestfill_exp = .FALSE.
integer :: nnests = 0
integer :: nfields = size(LIS_FieldList)
integer :: timeSlice = 0
integer :: debugImpSlice = 1
integer :: debugExpSlice = 1
integer :: debugIntvlInt = 0
type(ESMF_TimeInterval) :: debugIntvl
type(ESMF_TimeInterval) :: debugImpAccum
type(ESMF_TimeInterval) :: debugExpAccum
type(ESMF_Grid),allocatable :: grids(:)
type(ESMF_Clock),allocatable :: clocks(:)
type(ESMF_TimeInterval),allocatable :: stepAccum(:)
type(ESMF_State),allocatable :: NStateImp(:)
type(ESMF_State),allocatable :: NStateExp(:)
integer,allocatable :: modes(:)
end type
type type_InternalState
type(type_InternalStateStruct), pointer :: wrap
end type
!EOP
!-----------------------------------------------------------------------------
contains
!-----------------------------------------------------------------------------
#undef METHOD
#define METHOD "SetServices"
subroutine SetServices(gcomp, rc)
type(ESMF_GridComp) :: gcomp
integer, intent(out) :: rc
! local variables
integer :: stat
type(type_InternalState) :: is
rc = ESMF_SUCCESS
#ifdef DEBUG
call ESMF_LogSet(flush=.true., rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
call ESMF_LogWrite(MODNAME//": entered "//METHOD, ESMF_LOGMSG_INFO)
#endif
! allocate memory for this internal state and set it in the component
allocate(is%wrap, stat=stat)
if (ESMF_LogFoundAllocError(statusToCheck=stat, &
msg='Allocation of internal state memory failed.', &
method=METHOD, file=FILENAME, rcToReturn=rc)) return ! bail out
call ESMF_UserCompSetInternalState(gcomp, label_InternalState, is, rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
! the NUOPC model component will register the generic methods
call NUOPC_CompDerive(gcomp, model_routine_SS, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
! switching to IPD versions
call ESMF_GridCompSetEntryPoint(gcomp, ESMF_METHOD_INITIALIZE, &
userRoutine=InitializeP0, phase=0, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
! set entry point for methods that require specific implementation
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_INITIALIZE, &
phaseLabelList=(/"IPDv03p1"/), userRoutine=InitializeP1, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_INITIALIZE, &
phaseLabelList=(/"IPDv03p3"/), userRoutine=InitializeP3, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
! attach specializing method(s)
call NUOPC_CompSpecialize(gcomp, specLabel=model_label_DataInitialize, &
specRoutine=DataInitialize, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
call NUOPC_CompSpecialize(gcomp, speclabel=model_label_SetClock, &
specRoutine=SetClock, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
call ESMF_MethodRemove(gcomp, label=model_label_CheckImport, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail ou
call NUOPC_CompSpecialize(gcomp, specLabel=model_label_CheckImport, &
specRoutine=CheckImport, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail ou
call NUOPC_CompSpecialize(gcomp, speclabel=model_label_Advance, &
specRoutine=ModelAdvance, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
call NUOPC_CompSpecialize(gcomp, specLabel=model_label_Finalize, &
specRoutine=ModelFinalize, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
#ifdef DEBUG
call ESMF_LogWrite(MODNAME//": leaving "//METHOD, ESMF_LOGMSG_INFO)
#endif
end subroutine
!-----------------------------------------------------------------------------
#undef METHOD
#define METHOD "InitializeP0"
subroutine InitializeP0(gcomp, importState, exportState, clock, rc)
type(ESMF_GridComp) :: gcomp
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc
! local variables
character(32) :: cname
integer :: stat
logical :: configIsPresent
type(ESMF_Config) :: config
type(NUOPC_FreeFormat) :: attrFF
type(type_InternalState) :: is
character(len=64) :: value
rc = ESMF_SUCCESS
#ifdef DEBUG
call ESMF_LogWrite(MODNAME//": entered "//METHOD, ESMF_LOGMSG_INFO)
#endif
! Query component for name
call ESMF_GridCompGet(gcomp, name=cname, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
! query Component for its internal State
nullify(is%wrap)
call ESMF_UserCompGetInternalState(gcomp, label_InternalState, is, rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
! check gcomp for config
call ESMF_GridCompGet(gcomp, configIsPresent=configIsPresent, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
! read and ingest free format component attributes
if (configIsPresent) then
call ESMF_GridCompGet(gcomp, config=config, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
attrFF = NUOPC_FreeFormatCreate(config, &
label=trim(cname)//"_attributes::", relaxedflag=.true., rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
call NUOPC_CompAttributeIngest(gcomp, attrFF, addFlag=.true., rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
call NUOPC_FreeFormatDestroy(attrFF, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
endif
! Realize all export fields
call ESMF_AttributeGet(gcomp, name="realize_all_export", value=value, defaultValue="false", &
convention="NUOPC", purpose="Instance", rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
is%wrap%realizeAllExport = (trim(value)=="true")
! Debug Write Interval
call ESMF_AttributeGet(gcomp, name="debug_interval", value=value, defaultValue="default", &
convention="NUOPC", purpose="Instance", rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
is%wrap%debugIntvlInt = ESMF_UtilString2Int(value, &
specialStringList=(/"default","yearly","hourly","daily"/), &
specialValueList=(/0,31536000,3600,86400/), rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
if (is%wrap%debugIntvlInt /= 0) then
is%wrap%lwrite_debug=.TRUE.
call ESMF_TimeIntervalSet(is%wrap%debugIntvl, &
s=is%wrap%debugIntvlInt, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
call ESMF_TimeIntervalSet(is%wrap%debugImpAccum, s_r8=0._ESMF_KIND_R8, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
call ESMF_TimeIntervalSet(is%wrap%debugExpAccum, s_r8=0._ESMF_KIND_R8, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
endif
! Verbosity
call ESMF_AttributeGet(gcomp, name="verbosity", value=value, defaultValue="default", &
convention="NUOPC", purpose="Instance", rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
is%wrap%verbosity = ESMF_UtilString2Int(value, &
specialStringList=(/"none","min","max","debug","default"/), &
specialValueList=(/VERBOSITY_LV0,VERBOSITY_LV1,VERBOSITY_LV3, &
VERBOSITY_LV3,VERBOSITY_LV1/), rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
! Set configuration file name
call ESMF_AttributeGet(gcomp, name="config_file", value=is%wrap%configFile, &
defaultValue="lis.config", &
convention="NUOPC", purpose="Instance", rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
! Write coupled grid files
call ESMF_AttributeGet(gcomp, name="nest_to_nest", value=value, defaultValue="false", &
convention="NUOPC", purpose="Instance", rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
is%wrap%nestToNest = (trim(value)=="true")
! Write coupled grid files
call ESMF_AttributeGet(gcomp, name="write_grid", value=value, defaultValue="true", &
convention="NUOPC", purpose="Instance", rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
is%wrap%lwrite_grid = (trim(value)=="true")
! Log Memory
call ESMF_AttributeGet(gcomp, name="log_memory", value=value, defaultValue="false", &
convention="NUOPC", purpose="Instance", rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
is%wrap%llog_memory = (trim(value)=="true")
! Test fill import fields
call ESMF_AttributeGet(gcomp, name="testfill_imp", value=value, defaultValue="false", &
convention="NUOPC", purpose="Instance", rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
is%wrap%ltestfill_imp = (trim(value)=="true")
! Test fill export fields
call ESMF_AttributeGet(gcomp, name="testfill_exp", value=value, defaultValue="false", &
convention="NUOPC", purpose="Instance", rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
is%wrap%ltestfill_exp = (trim(value)=="true")
! Switch to IPDv03 by filtering all other phaseMap entries
call NUOPC_CompFilterPhaseMap(gcomp, ESMF_METHOD_INITIALIZE, &
acceptStringList=(/"IPDv03p"/), rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
if (is%wrap%verbosity >= VERBOSITY_LV1) &
call LogAttributes(trim(cname),gcomp)
#ifdef DEBUG
call ESMF_LogWrite(MODNAME//": leaving "//METHOD, ESMF_LOGMSG_INFO)
#endif
end subroutine
!-----------------------------------------------------------------------------
#undef METHOD
#define METHOD "InitializeP1"
subroutine InitializeP1(gcomp, importState, exportState, clock, rc)
type(ESMF_GridComp) :: gcomp
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer,intent(out) :: rc
! LOCAL VARIABLES
character(32) :: cname
type(type_InternalState) :: is
type(ESMF_VM) :: vm
integer :: localPet, petCount
integer :: stat
integer :: fIndex
integer :: nIndex
character(len=9) :: nStr
rc = ESMF_SUCCESS
#ifdef DEBUG
call ESMF_LogWrite(MODNAME//": entered "//METHOD, ESMF_LOGMSG_INFO)
#endif
! Query component for name
call ESMF_GridCompGet(gcomp, name=cname, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
! query Component for its internal State
nullify(is%wrap)
call ESMF_UserCompGetInternalState(gcomp, label_InternalState, is, rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
call ESMF_GridCompGet(gcomp, vm=vm, localPet=localPet, petCount=petCount, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
! initialize lis model for this PET
call LIS_NUOPC_Init(vm, configFile=is%wrap%configFile, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
if (is%wrap%verbosity >= VERBOSITY_LV2) then
call LIS_Log(trim(cname)//': '//METHOD,rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
endif
call LIS_FieldDictionaryAdd(rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
is%wrap%nnests = LIS_NestCntGet(rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
! Max nest check
if ( nIndex > MAXNEST ) then
call ESMF_LogSetError(ESMF_FAILURE, &
msg="Maximum nest size is 999,999,999.", &
line=__LINE__,file=__FILE__,rcToReturn=rc)
return ! bail out
endif
allocate( &
is%wrap%grids(is%wrap%nnests), &
is%wrap%clocks(is%wrap%nnests), &
is%wrap%stepAccum(is%wrap%nnests), &
is%wrap%NStateImp(is%wrap%nnests), &
is%wrap%NStateExp(is%wrap%nnests), &
is%wrap%modes(is%wrap%nnests), &
stat=stat)
if (ESMF_LogFoundAllocError(statusToCheck=stat, &
msg="Allocation of internal state nest memory failed.", &
line=__LINE__,file=__FILE__)) &
return ! bail out
is%wrap%modes=LIS_Unknown
#ifdef GSM_EXTLND
is%wrap%NStateImp(1) = importState
is%wrap%NStateExp(1) = exportState
#else
if (.NOT.is%wrap%nestToNest) then
if (is%wrap%nnests.le.1) then
is%wrap%NStateImp(1) = importState
is%wrap%NStateExp(1) = exportState
else
call ESMF_LogSetError(ESMF_FAILURE, &
msg="Nest to nest must be turned on when multiple domains exist.", &
line=__LINE__,file=__FILE__,rcToReturn=rc)
return ! bail out
endif
else
! add namespace
call NUOPC_AddNestedState(importState, &
CplSet="1", &
nestedStateName="NestedStateImp_N1", &
nestedState=is%wrap%NStateImp(1), rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
call NUOPC_AddNestedState(exportState, &
CplSet="1", &
nestedStateName="NestedStateExp_N1", &
nestedState=is%wrap%NStateExp(1), rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
endif
do nIndex = 2, is%wrap%nnests
write (nStr,"(I0)") nIndex
call NUOPC_AddNestedState(importState, &
CplSet=trim(nStr), &
nestedStateName="NestedStateImp_N"//trim(nStr), &
nestedState=is%wrap%NStateImp(nIndex), rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
call NUOPC_AddNestedState(exportState, &
CplSet=trim(nStr), &
nestedStateName="NestedStateExp_N"//trim(nStr), &
nestedState=is%wrap%NStateExp(nIndex), rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
enddo
#endif
!!
!! advertise import and export fields in each nest
!!
do nIndex = 1, is%wrap%nnests
do fIndex = 1, size(LIS_FieldList)
if (LIS_FieldList(fIndex)%adImport) then
call NUOPC_Advertise(is%wrap%NStateImp(nIndex), &
standardName=trim(LIS_FieldList(fIndex)%stdname), &
name=trim(LIS_FieldList(fIndex)%stateName), &
rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
endif
if (LIS_FieldList(fIndex)%adExport) then
call NUOPC_Advertise(is%wrap%NStateExp(nIndex), &
standardName=trim(LIS_FieldList(fIndex)%stdname), &
name=trim(LIS_FieldList(fIndex)%stateName), &
rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
endif
enddo
enddo
if (is%wrap%verbosity >= VERBOSITY_LV1) &
call LogAdvertised(trim(cname))
#ifdef DEBUG
call ESMF_LogWrite(MODNAME//": leaving "//METHOD, ESMF_LOGMSG_INFO)
#endif
end subroutine
!-----------------------------------------------------------------------------
#undef METHOD
#define METHOD "InitializeP3"
subroutine InitializeP3(gcomp, importState, exportState, clock, rc)
type(ESMF_GridComp) :: gcomp
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc
! Local Variables
character(32) :: cname
type(type_InternalState) :: is
integer :: nIndex
type(ESMF_Field) :: field
integer :: fIndex
character(len=9) :: nStr
logical :: realizeImp, realizeExp
type(ESMF_Array) :: array
rc = ESMF_SUCCESS
#ifdef DEBUG
call ESMF_LogWrite(MODNAME//": entered "//METHOD, ESMF_LOGMSG_INFO)
#endif
! Query component for name
call ESMF_GridCompGet(gcomp, name=cname, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
! query Component for its internal State
nullify(is%wrap)
call ESMF_UserCompGetInternalState(gcomp, label_InternalState, is, rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
do nIndex = 1, is%wrap%nnests
write (nStr,"(I0)") nIndex
! Call gluecode to create grid.
is%wrap%grids(nIndex) = LIS_GridCreate(nIndex, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
call LIS_ESMF_LogGrid(is%wrap%grids(nIndex), &
trim(cname)//"_D"//trim(nStr),rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
! Write grid to NetCDF file.
if (is%wrap%lwrite_grid) then
call LIS_ESMF_GridWrite(is%wrap%grids(nIndex), &
trim(cname)//'_grid_nest_'//trim(nStr)//".nc", rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
endif
do fIndex = 1, size(LIS_FieldList)
realizeImp = .FALSE.
realizeExp = .FALSE.
if (LIS_FieldList(fIndex)%adExport) then
if (is%wrap%realizeAllExport) then
realizeExp = .TRUE.
else
realizeExp = NUOPC_IsConnected(is%wrap%NStateExp(nIndex), &
fieldName=trim(LIS_FieldList(fIndex)%stateName),rc=rc)
if (ESMF_STDERRORCHECK(rc)) return
endif
endif
if (LIS_FieldList(fIndex)%adImport) then
realizeImp = NUOPC_IsConnected(is%wrap%NStateImp(nIndex), &
fieldName=trim(LIS_FieldList(fIndex)%stateName),rc=rc)
if (ESMF_STDERRORCHECK(rc)) return
endif
if (realizeImp .AND. realizeExp .AND. LIS_FieldList(fIndex)%sharedMem) then
field = ESMF_FieldCreate(name=trim(LIS_FieldList(fIndex)%stateName), &
grid=is%wrap%grids(nIndex), typekind=ESMF_TYPEKIND_FIELD, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
call NUOPC_Realize(is%wrap%NStateExp(nIndex), field=field,rc=rc)
if (ESMF_STDERRORCHECK(rc)) return
LIS_FieldList(fIndex)%realizedExport = .TRUE.
call ESMF_FieldGet(field=field,array=array,rc=rc)
if (ESMF_STDERRORCHECK(rc)) return
field = ESMF_FieldCreate(name=trim(LIS_FieldList(fIndex)%stateName), &
grid=is%wrap%grids(nIndex), array=array, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return
call NUOPC_Realize(is%wrap%NStateImp(nIndex), field=field,rc=rc)
if (ESMF_STDERRORCHECK(rc)) return
LIS_FieldList(fIndex)%realizedImport = .TRUE.
elseif (realizeImp .AND. realizeExp) then
field = ESMF_FieldCreate(name=trim(LIS_FieldList(fIndex)%stateName), &
grid=is%wrap%grids(nIndex), typekind=ESMF_TYPEKIND_FIELD, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
call NUOPC_Realize(is%wrap%NStateExp(nIndex), field=field,rc=rc)
if (ESMF_STDERRORCHECK(rc)) return
LIS_FieldList(fIndex)%realizedExport = .TRUE.
field = ESMF_FieldCreate(name=trim(LIS_FieldList(fIndex)%stateName), &
grid=is%wrap%grids(nIndex), typekind=ESMF_TYPEKIND_FIELD, rc=rc)
if(ESMF_STDERRORCHECK(rc)) return
call NUOPC_Realize(is%wrap%NStateImp(nIndex), field=field,rc=rc)
if (ESMF_STDERRORCHECK(rc)) return
LIS_FieldList(fIndex)%realizedImport = .TRUE.
elseif (realizeExp) then
field = ESMF_FieldCreate(name=trim(LIS_FieldList(fIndex)%stateName), &
grid=is%wrap%grids(nIndex), typekind=ESMF_TYPEKIND_FIELD, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
call NUOPC_Realize(is%wrap%NStateExp(nIndex), field=field,rc=rc)
if (ESMF_STDERRORCHECK(rc)) return
LIS_FieldList(fIndex)%realizedExport = .TRUE.
call ESMF_StateRemove(is%wrap%NStateImp(nIndex),(/trim(LIS_FieldList(fIndex)%stateName)/), &
relaxedflag=.true.,rc=rc)
if (ESMF_STDERRORCHECK(rc)) return
elseif (realizeImp) then
call ESMF_StateRemove(is%wrap%NStateExp(nIndex),(/trim(LIS_FieldList(fIndex)%stateName)/), &
relaxedflag=.true.,rc=rc)
if (ESMF_STDERRORCHECK(rc)) return
field = ESMF_FieldCreate(name=trim(LIS_FieldList(fIndex)%stateName), &
grid=is%wrap%grids(nIndex), typekind=ESMF_TYPEKIND_FIELD, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
call NUOPC_Realize(is%wrap%NStateImp(nIndex), field=field,rc=rc)
if (ESMF_STDERRORCHECK(rc)) return
LIS_FieldList(fIndex)%realizedImport = .TRUE.
else
call ESMF_StateRemove(is%wrap%NStateExp(nIndex),(/trim(LIS_FieldList(fIndex)%stateName)/), &
relaxedflag=.true.,rc=rc)
if (ESMF_STDERRORCHECK(rc)) return
call ESMF_StateRemove(is%wrap%NStateImp(nIndex),(/trim(LIS_FieldList(fIndex)%stateName)/), &
relaxedflag=.true.,rc=rc)
if (ESMF_STDERRORCHECK(rc)) return
endif
enddo
call LIS_ESMF_FillState(is%wrap%NStateImp(nIndex),value=MISSINGVALUE,rc=rc)
if (ESMF_STDERRORCHECK(rc)) return
call LIS_ESMF_FillState(is%wrap%NStateExp(nIndex),value=MISSINGVALUE,rc=rc)
if (ESMF_STDERRORCHECK(rc)) return
is%wrap%modes(nIndex) = LIS_RunModeGet(LIS_FieldList,is%wrap%NStateImp(nIndex),rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
enddo
if (is%wrap%verbosity >= VERBOSITY_LV1) &
call LogRealized(trim(cname))
if (is%wrap%verbosity >= VERBOSITY_LV1) &
call LogModes(trim(cname),gcomp)
#ifdef DEBUG
call ESMF_LogWrite(MODNAME//": leaving "//METHOD, ESMF_LOGMSG_INFO)
#endif
end subroutine
!-----------------------------------------------------------------------------
#undef METHOD
#define METHOD "DataInitialize"
subroutine DataInitialize(gcomp, rc)
type(ESMF_GridComp) :: gcomp
integer, intent(out) :: rc
! local variables
character(32) :: cname
type(type_InternalState) :: is
type(ESMF_Clock) :: modelClock
integer :: nIndex
character(len=9) :: nStr
integer :: iIndex
integer :: itemCount
character(len=64),allocatable :: itemNameList(:)
type(ESMF_StateItem_Flag), allocatable :: itemTypeList(:)
type(ESMF_Field) :: field
integer :: stat
rc = ESMF_SUCCESS
#ifdef DEBUG
call ESMF_LogWrite(MODNAME//": entered "//METHOD, ESMF_LOGMSG_INFO)
#endif
! Query component for name
call ESMF_GridCompGet(gcomp, name=cname, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
! query Component for its internal State
nullify(is%wrap)
call ESMF_UserCompGetInternalState(gcomp, label_InternalState, is, rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
is%wrap%timeSlice = is%wrap%timeSlice + 1
! query the Component for its clock
call NUOPC_ModelGet(gcomp, modelClock=modelClock, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
do nIndex=1,is%wrap%nnests
write (nStr,"(I0)") nIndex
! Initialize import and export fields
call LIS_NUOPC_DataInit(nest=nIndex, &
importState=is%wrap%NStateImp(nIndex), &
exportState=is%wrap%NStateExp(nIndex),rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
! Fill import fields with test data
if (is%wrap%ltestfill_imp) then
call LIS_TestFillImport(nest=nIndex, &
importState=is%wrap%NStateImp(nIndex), &
step=is%wrap%timeSlice, &
label=trim(cname)//": ImportFieldsFill",rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
endif
! Fill export fields with test data
if (is%wrap%ltestfill_exp) then
call LIS_TestFillExport(nest=nIndex, &
exportState=is%wrap%NStateExp(nIndex), &
step=is%wrap%timeSlice, &
label=trim(cname)//": ExportFieldsFill",rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
endif
if (is%wrap%verbosity >= VERBOSITY_LV2) then
call LIS_ESMF_LogState(is%wrap%NStateImp(nIndex), &
label=trim(cname)//": ImportState Init Nest="//trim(nStr), &
fvalues=.TRUE.,rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
call LIS_ESMF_LogState(is%wrap%NStateExp(nIndex), &
label=trim(cname)//": ExportState Init Nest="//trim(nStr), &
fvalues=.TRUE.,rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
endif
call ESMF_StateGet(is%wrap%NStateExp(nIndex),itemCount=itemCount, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
allocate( &
itemNameList(itemCount), &
itemTypeList(itemCount), &
stat=stat)
if (ESMF_LogFoundAllocError(statusToCheck=stat, &
msg="Allocation of state item list memory failed.", &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_StateGet(is%wrap%NStateExp(nIndex),itemNameList=itemNameList, &
itemTypeList=itemTypeList,rc=rc)
if (ESMF_STDERRORCHECK(rc)) return
do iIndex=1, itemCount
if ( itemTypeList(iIndex) == ESMF_STATEITEM_FIELD) then
call ESMF_StateGet(is%wrap%NStateExp(nIndex),field=field, &
itemName=itemNameList(iIndex),rc=rc)
if (ESMF_STDERRORCHECK(rc)) return
call NUOPC_SetAttribute(field, name="Updated", value="true", rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
endif
enddo
deallocate(itemNameList, itemTypeList, stat=stat)
if (ESMF_LogFoundDeallocError(statusToCheck=stat, &
msg="Deallocation of state item list memory failed.", &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
enddo
! Write init files if lwrite_debug is on
if (is%wrap%lwrite_debug) then
do nIndex=1,is%wrap%nnests
write (nStr,"(I0)") nIndex
call NUOPC_Write(is%wrap%NStateImp(nIndex), &
fileNamePrefix="field_"//trim(cname)//"_imp_D"//trim(nStr)//'_', &
overwrite=.false., timeslice=is%wrap%debugImpSlice, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
call NUOPC_Write(is%wrap%NStateExp(nIndex), &
fileNamePrefix="field_"//trim(cname)//"_exp_D"//trim(nStr)//'_', &
overwrite=.false., timeslice=is%wrap%debugExpSlice, rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
enddo
is%wrap%debugImpSlice = is%wrap%debugImpSlice + 1
is%wrap%debugExpSlice = is%wrap%debugExpSlice + 1
endif
! set InitializeDataComplete Attribute to "true", indicating to the
! generic code that all inter-model data dependencies are satisfied
call NUOPC_CompAttributeSet(gcomp, name="InitializeDataComplete", value="true", rc=rc)
if (ESMF_STDERRORCHECK(rc)) return ! bail out
#ifdef DEBUG
call ESMF_LogWrite(MODNAME//": leaving "//METHOD, ESMF_LOGMSG_INFO)
#endif
end subroutine
!-----------------------------------------------------------------------------
#undef METHOD