forked from schism-dev/schism-esmf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schism_nuopc_cap.F90
1100 lines (847 loc) · 41.4 KB
/
schism_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
! This code is part of the SCHISM-ESMF interface. It defines
! the schism component for a NUOPC coupled system
!
! @copyright (C) 2021-2023 Helmholtz-Zentrum Hereon
! @copyright (C) 2022-2023 Virginia Institute of Marine Science
! @copyright (C) 2020-2021 Helmholtz-Zentrum Geesthacht
!
! @author Carsten Lemmen <[email protected]>
! @author Joseph Y. Zhang >[email protected]>
!
! @license Apache License, Version 2.0 (the "License");
! you may not use this file except in compliance with the License.
! You may obtain a copy of the License at
!
! http://www.apache.org/licenses/LICENSE-2.0
!
! Unless required by applicable law or agreed to in writing, software
! distributed under the License is distributed on an "AS IS" BASIS,
! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
! See the License for the specific language governing permissions and
! limitations under the License.
!
#define ESMF_CONTEXT line=__LINE__,file=ESMF_FILENAME,method=ESMF_METHOD
#define ESMF_ERR_PASSTHRU msg="SCHISM subroutine call returned error"
#undef ESMF_FILENAME
#define ESMF_FILENAME "schism_nuopc_cap.F90"
#define _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(X) if (ESMF_LogFoundError(rcToCheck=localrc, ESMF_ERR_PASSTHRU, ESMF_CONTEXT, rcToReturn=X)) call ESMF_Finalize(rc=localrc, endflag=ESMF_END_ABORT)
#define _SCHISM_LOG_AND_FINALIZE_ON_ERRORS_(X) if (ESMF_LogFoundError(rcToCheck=localRc, ESMF_ERR_PASSTHRU, ESMF_CONTEXT, rcToReturn=X) .or. ESMF_LogFoundError(rcToCheck=userRc, ESMF_ERR_PASSTHRU, ESMF_CONTEXT, rcToReturn=X)) call ESMF_Finalize(rc=localrc, endflag=ESMF_END_ABORT)
module schism_nuopc_cap
use esmf
use nuopc
use NUOPC_Model, &
model_routine_SS => SetServices, &
model_label_DataInitialize => label_DataInitialize, &
model_label_SetClock => label_SetClock, &
model_label_Advance => label_Advance
use schism_bmi
use schism_esmf_util
use schism_nuopc_util
implicit none
private
public SetServices
contains
#undef ESMF_METHOD
#define ESMF_METHOD "SetServices"
subroutine SetServices(comp, rc)
type(ESMF_GridComp) :: comp
integer, intent(out) :: rc
integer(ESMF_KIND_I4) :: localrc
character(len=ESMF_MAXSTR), parameter :: label_InternalState = 'InternalState'
type(type_InternalStateWrapper) :: internalState
type(type_InternalState), pointer :: isDataPtr => null()
rc = ESMF_SUCCESS
call NUOPC_CompDerive(comp, model_routine_SS, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
allocate(internalState%wrap, stat=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call ESMF_UserCompSetInternalState(comp, label_InternalState, &
internalState, localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
! NUOPC automatically has an entry point for InitializeP0, so do not?
call NUOPC_CompSetEntryPoint(comp, ESMF_METHOD_INITIALIZE, &
phaseLabelList=(/"IPDv00p0"/), userRoutine=InitializeP0, rc=localrc)
call NUOPC_CompSetEntryPoint(comp, ESMF_METHOD_INITIALIZE, &
phaseLabelList=(/"IPDv00p1"/), userRoutine=InitializeAdvertise, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_CompSetEntryPoint(comp, ESMF_METHOD_INITIALIZE, &
phaseLabelList=(/"IPDv00p2"/), userRoutine=InitializeRealize, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_CompSpecialize(comp, specLabel=model_label_SetClock, &
specRoutine=SetClock, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_CompSpecialize(comp, specLabel=model_label_DataInitialize, &
specRoutine=DataInitialize, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_CompSpecialize(comp, specLabel=model_label_Advance, &
specRoutine=ModelAdvance, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> Do we need a specialization of Finalize, by adding a label?
!call NUOPC_CompSpecialize(comp, specLabel=model_label_Finalize, &
! specRoutine=Finalize, rc=localrc)
! Yes, we should release the haloHandle
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
end subroutine SetServices
#undef ESMF_METHOD
#define ESMF_METHOD "InitializeP0"
subroutine InitializeP0(comp, importState, exportState, parentClock, rc)
! phase 0: Set Initialize Phase Definition Version (REQUIRED, NUOPC PROVIDED)
! – Initialize the InitializePhaseMap Attribute according to the NUOPC Initialize Phase Definition (IPD) version 00
! ∗ IPDv00p1 = 1: (REQUIRED, IMPLEMENTOR PROVIDED) · Advertise Fields in import and export States.
! ∗ IPDv00p2 = 2: (REQUIRED, IMPLEMENTOR PROVIDED)
! · Realize the advertised Fields in import and export States.
! ∗ IPDv00p3 = 3: (REQUIRED, NUOPC PROVIDED)
! · Check compatibility of the Fields’ Connected status.
! ∗ IPDv00p4 = 4: (REQUIRED, NUOPC PROVIDED)
! · Handle Field data initialization. Time stamp the export Fields.
type(ESMF_GridComp) :: comp
type(ESMF_State) :: importState
type(ESMF_State) :: exportState
type(ESMF_Clock) :: parentClock
integer, intent(out) :: rc
character(len=10) :: InitializePhaseMap(4)
integer :: localrc
logical :: isPresent
character(len=ESMF_MAXSTR) :: configFileName, compName
character(len=ESMF_MAXSTR) :: message
type(ESMF_Config) :: config
type(ESMF_Info) :: info
rc=ESMF_SUCCESS
call NUOPC_CompGet(comp, name=compName, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_CompSetClock(comp, externalClock=parentClock, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
write(message, '(A)') trim(compName)//' initializing (p=0) component ...'
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
!> @todo add other IPD versions mappings, i.e. IPDv00p1, IPDv01p1, IPDv02p1,
!> IPDv03p1, IPDv04p1, IPDv05p1; all map to 1 ?
InitializePhaseMap = (/"IPDv00p1=1","IPDv00p2=2", &
"IPDv00p3=3","IPDv00p4=4"/)
!call ESMF_AttributeAdd(comp, convention="NUOPC", &
! purpose="General", &
! attrList=(/"InitializePhaseMap"/), rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call ESMF_InfoGetFromHost(comp, info=info, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call ESMF_InfoSet(info, key="NUOPC/General/InitializePhaseMap", &
values=InitializePhaseMap, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
! Read the configuration for this component from file if not
! already present in the component
call ESMF_GridCompGet(comp, configIsPresent=isPresent, name=compName, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
if (isPresent) then
call ESMF_GridCompGet(comp, config=config, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
write(message, '(A)') trim(compName)//' uses internal configuration'
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
else
configfilename=trim(compName)//'.cfg'
inquire(file=trim(configfilename), exist=isPresent)
config = ESMF_ConfigCreate(rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
if (isPresent) then
call ESMF_ConfigLoadFile(config, trim(configfilename), rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
write(message,'(A)') trim(compName)//' read configuration from '// trim(configFileName)
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
else
write(message,'(A)') trim(compName)//' has no configuration; use global config'
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
endif
call ESMF_GridCompSet(comp, config=config, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
endif
end subroutine InitializeP0
#undef ESMF_METHOD
#define ESMF_METHOD "InitializeAdvertise"
!> @description The purpose of this phase is for your model to advertise its import and export
!> fields. This means that your model announces which model variables it is capable of exporting
!> (e.g., an atmosphere might export air pressure at sea level) and which model variables it
!> requires (e.g., an atmosphere might require sea surface temperature as a boundary condition).
!> The reason there is an explicit advertise phase is because NUOPC dynamically matches fields
!> among all the models participating in a coupled simulation during runtime. So, we need to
!> collect the list of possible input and output fields from all the models during their initialization.
!> Note that NUOPC does not allocate memory for fields during the advertise phase or when
!> NUOPC_Advertise is called. Instead, this is simply a way for models to communicate the standard
!> names of fields. During a later phase, only those fields that are connected (e.g., a field
!> exported from one model that is imported by another) need to have memory allocated. Also, since
!> ESMF will accept pointers to pre-allocated memory, it is usually not necessary to change
!> how memory is allocated for your model’s variables.
!> Should be mapped to IPDv00p1, IPDv01p1, IPDv02p1, IPDv03p1, IPDv04p1, IPDv05p1;
!> its implementation is required
subroutine InitializeAdvertise(comp, importState, exportState, clock, rc)
implicit none
type(ESMF_GridComp) :: comp
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc
integer(ESMF_KIND_I4) :: localrc, mpiCommunicator, mpiCommDuplicate
integer(ESMF_KIND_I4) :: ntime=0, iths=0, i
character(len=ESMF_MAXSTR) :: message, compName, cvalue
character(len=ESMF_MAXSTR), allocatable :: itemNameList(:)
logical :: isPresent, isSet
type(ESMF_VM) :: vm
type(type_InternalStateWrapper) :: internalState
type(type_InternalState), pointer :: isDataPtr => null()
rc = ESMF_SUCCESS
localrc = ESMF_SUCCESS
!> more possikeywordds lities for interface: verbosity, profiling, diagnostic
call NUOPC_CompGet(comp, name=compName, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
write(message, '(A)') trim(compName)//' initialize (p=1) component ...'
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
allocate(internalState%wrap, stat=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call ESMF_GridCompSetInternalState(comp, internalState, localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call ESMF_GridCompGetInternalState(comp, internalState, localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
isDataPtr => internalState%wrap
isDataPtr%numOwnedNodes = 0
isDataPtr%numForeignNodes = 0
call SCHISM_InitializePtrMap(comp, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
if (.not.ESMF_StateIsCreated(importState)) then
importState=ESMF_StateCreate(name=trim(compName)//'Import', stateintent= &
ESMF_STATEINTENT_IMPORT, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
write(message,'(A)') trim(compName)//' created state "'//trim(compName)// &
'Import" for import'
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
endif
if (.not.ESMF_StateIsCreated(exportState)) then
exportState=ESMF_StateCreate(name=trim(compName)//'Export', stateintent= &
ESMF_STATEINTENT_EXPORT, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
write(message,'(A)') trim(compName)//' created state "'//trim(compName)// &
'Export" for export'
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
endif
! Get VM for this component
call ESMF_GridCompGet(comp, vm=vm, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call ESMF_VMGet(vm, mpiCommunicator=mpiCommunicator, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
#ifndef ESMF_MPIUNI
call MPI_Comm_dup(mpiCommunicator, mpiCommDuplicate, rc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
write(message, '(A)') trim(compName)//' initializing parallel environment ...'
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
call schism_parallel_init(communicator=mpiCommDuplicate)
write(message, '(A)') trim(compName)//' initialized parallel environment.'
#endif
call ESMF_UtilIOMkDir ('./outputs', relaxedFlag=.true., rc=localrc)
write(message, '(A)') trim(compName)//' writes results to directory "./outputs".'
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
write(message, '(A)') trim(compName)//' initializing science model ...'
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
inquire(file='param.nml', exist=isPresent)
if (.not.isPresent) then
write(message, '(A)') trim(compName)//' cannot start without required file "param.nml".'
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_ERROR)
localrc = ESMF_RC_FILE_OPEN
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
endif
! query attributes
call NUOPC_CompAttributeGet(comp, name='meshloc', value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
if (isPresent .and. isSet) then
if (trim(cvalue) == 'node') then
meshloc = ESMF_MESHLOC_NODE
else
meshloc = ESMF_MESHLOC_ELEMENT
end if
else
cvalue = 'node'
meshloc = ESMF_MESHLOC_NODE
end if
write(message, '(A)') trim(compName)//' meshloc is set to '//trim(cvalue)
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
! debug option
call NUOPC_CompAttributeGet(comp, name='debug_level', value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
debug_level = 0
if (isPresent .and. isSet) then
read(cvalue,*) debug_level
end if
write(message, '(A,I1)') trim(compName)//' debug_level is set to ', debug_level
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
! init schism
call schism_init(0, './', iths, ntime)
write(message, '(A)') trim(compName)//' initialized science model'
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
! Deal with setting up the Field dictionary here and advertising the
! variables.
! @todo this should be customized by a field dictionary-like configuration
! file
call NUOPC_FieldDictionaryAddIfNeeded("air_pressure_at_sea_level", "N m-2", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_FieldDictionaryAddIfNeeded("surface_downwelling_photosynthetic_radiative_flux", "W m-2 s-1", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_FieldDictionaryAddIfNeeded("sea_surface_temperature", "K", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_FieldDictionaryAddIfNeeded("inst_temp_height2m", "K", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_FieldDictionaryAddIfNeeded("sea_surface_salinity", "PSU", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_FieldDictionaryAddIfNeeded("inst_merid_wind_height10m", "m s-1", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_FieldDictionaryAddIfNeeded("inst_zonal_wind_height10m", "m s-1", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_FieldDictionaryAddIfNeeded("eastward_wave_radiation_stress", "N m-1", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_FieldDictionaryAddIfNeeded("eastward_northward_wave_radiation_stress", "N m-1", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_FieldDictionaryAddIfNeeded("northward_wave_radiation_stress", "N m-1", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_FieldDictionaryAddIfNeeded("depth-averaged_x-velocity", "m s-1", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_FieldDictionaryAddIfNeeded("depth-averaged_y-velocity", "m s-1", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_FieldDictionaryAddIfNeeded("ocn_current_zonal", "m s-1", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_FieldDictionaryAddIfNeeded("ocn_current_merid", "m s-1", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_FieldDictionaryAddIfNeeded("ocean_mask", "1", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
! for coupling to ATM/DATM
call NUOPC_Advertise(importState, "air_pressure_at_sea_level", rc=localrc)
call NUOPC_Advertise(importState, "inst_zonal_wind_height10m", rc=localrc)
call NUOPC_Advertise(importState, "inst_merid_wind_height10m", rc=localrc)
! for coupling to WW3/WDAT
call NUOPC_Advertise(importState, "eastward_wave_radiation_stress", rc=localrc)
call NUOPC_Advertise(importState, "eastward_northward_wave_radiation_stress", rc=localrc)
call NUOPC_Advertise(importState, "northward_wave_radiation_stress", rc=localrc)
!> The mesh information is usually not in CF standard and therefore needs
!> to be added to the FieldDictionary before advertising
allocate(itemNameList(4))
itemNameList=(/ 'mesh_topology ', &
'mesh_global_node_id ', &
'mesh_global_element_id ', &
'mesh_element_node_connectivity'/)
do i=1,4
call NUOPC_FieldDictionaryAddIfNeeded(trim(itemNameList(i)), "1", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_Advertise(exportState, StandardName=trim(itemNameList(i)), &
SharePolicyField='share', SharePolicyGeomObject='share', &
TransferOfferGeomObject='will provide', rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
enddo
! for coupling to WW3
call NUOPC_FieldAdvertise(exportState, "ocn_current_zonal", "m s-1", localrc)
call NUOPC_FieldAdvertise(exportState, "ocn_current_merid", "m s-1", localrc)
call NUOPC_FieldAdvertise(exportState, "sea_surface_temperature", "K", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_FieldAdvertise(exportState, "temperature", "K", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_FieldAdvertise(exportState, "sea_surface_salinity", "PSU", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_FieldAdvertise(exportState, "depth-averaged_x-velocity", "m s-1", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call NUOPC_FieldAdvertise(exportState, "depth-averaged_y-velocity", "m s-1", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
! required for coupling through CMEPS mediator
call NUOPC_FieldAdvertise(exportState, "ocean_mask", "1", localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
end subroutine
#undef ESMF_METHOD
#define ESMF_METHOD "InitializeRealize"
!> @description During this phase, fields that were previously advertised should now be realized. Realizing a field means that an ESMF_Field object is created and it is added to the appropriate ESMF_State, either import or export. In order to create an ESMF_Field, you’ll first need to create one of the ESMF geometric types, ESMF_Grid, ESMF_Mesh, or ESMF_LocStream. For 2D and 3D logically rectangular grids (such as a lat-lon grid), the typical choice is ESMF_Grid. For unstructured grids, use an ESMF_Mesh. Fields are put into import or export States by calling NUOPC_Realize.
!> Should be mapped to IPDv00p2, IPDv01p3, IPDv02p3, IPDv03p3, IPDv04p3, IPDv05p4;
!> Required if providing any geometry. For higher phases IPDv03p5, IPDv04p5, IPDv05p6
!> a separate routine should be provided for accepting fields.
subroutine InitializeRealize(comp, importState, exportState, clock, rc)
use schism_esmf_util, only : SCHISM_MeshCreateNode
use schism_esmf_util, only : SCHISM_MeshCreateElement
!> @todo move all use statements of schism into schism_bmi
use schism_glbl, only: np, pr2, windx2, windy2, srad, nws, rkind
use schism_esmf_util, only: SCHISM_StateFieldCreateRealize
implicit none
type(ESMF_GridComp) :: comp
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc
type(ESMF_TimeInterval) :: stabilityTimeStep
type(ESMF_Field) :: field
integer(ESMF_KIND_I4) :: localrc, i
type(ESMF_CoordSys_Flag) :: coordsys
type(ESMF_Mesh) :: mesh2d
character(len=ESMF_MAXSTR) :: message, compName
character(len=ESMF_MAXSTR), allocatable :: itemNameList(:)
type(ESMF_StateItem_Flag), allocatable :: itemTypeList(:)
integer(ESMF_KIND_I4) :: itemCount
type(type_InternalStateWrapper) :: internalState
type(type_InternalState), pointer :: isDataPtr => null()
type(ESMF_DistGrid) :: nodalDistgrid
type(ESMF_Array) :: array
real(ESMF_KIND_R8), pointer :: farrayPtr1(:) => null()
!> @todo move to internal state
!> Maybe think more generally about how to handle these intermediate varialbes,
!> best of course dealt with in a mediator
real(ESMF_KIND_R8), target, allocatable :: eastward_wave_radiation_stress(:)
real(ESMF_KIND_R8), target, allocatable :: eastward_northward_wave_radiation_stress(:)
real(ESMF_KIND_R8), target, allocatable :: northward_wave_radiation_stress(:)
rc = ESMF_SUCCESS
localrc= ESMF_SUCCESS
!<<<<<<< HEAD
!=======
!> @todo move addSchismMesh back to schism_esmf_util to share with ESMF cap
!> call addSchismMesh(comp, ownedNodes=ownedNodes, foreignNodes=foreignNodes, rc=localrc)
!call addSchismMesh(comp, localrc)
!>>>>>>> a9a0ce0 (Use MeshCreate instead off add Mesh)
if (meshloc == ESMF_MESHLOC_NODE) then
call SCHISM_MeshCreateNode(comp, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
else
call SCHISM_MeshCreateElement(comp, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
end if
call ESMF_GridCompGet(comp, mesh=mesh2d, name=compName, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call ESMF_MeshGet(mesh2d, nodalDistgrid=nodalDistgrid, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call SCHISM_StateFieldCreateRealize(comp, state=importState, &
name="inst_zonal_wind_height10m", field=field, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call SCHISM_StateFieldCreateRealize(comp, state=importState, &
name="inst_merid_wind_height10m", field=field, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call SCHISM_StateFieldCreateRealize(comp, state=importState, &
name="air_pressure_at_sea_level", field=field, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call SCHISM_StateFieldCreateRealize(comp, state=importState, &
name="downwelling_short_photosynthetic_radiation_at_water_surface", field=field, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> @todo add more atmospheric fields (like humidity)
!> Wave parameters, for now we only have those from the WW3DATA cap in
!> NOAA's CoastalApp.
call SCHISM_StateFieldCreateRealize(comp, state=importState, &
name="eastward_wave_radiation_stress", field=field, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call SCHISM_StateFieldCreateRealize(comp, state=importState, &
name="eastward_northward_wave_radiation_stress", field=field, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call SCHISM_StateFieldCreateRealize(comp, state=importState, &
name="northward_wave_radiation_stress", field=field, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> The list of export states is declared in InitializeAdvertise
call ESMF_StateGet(exportState, itemCount=itemCount, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
allocate(itemNameList(itemCount), itemTypeList(itemCount), stat=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call ESMF_StateGet(exportState, itemTypeList=itemTypeList, &
itemNameList=itemNameList, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
do i=1, itemCount
if (itemTypeList(i) /= ESMF_STATEITEM_FIELD) cycle
call SCHISM_FieldRealize(exportState, itemNameList(i), &
mesh=mesh2d, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
write(message,'(A)') trim(compName)//' realized field '//trim(itemNameList(i))// &
' in its export state'
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
enddo
if (allocated(itemNameList)) deallocate(itemNameList)
if (allocated(itemTypeList)) deallocate(itemTypeList)
call ESMF_StateGet(importState, itemCount=itemCount, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
if (itemCount > 0) then
allocate(itemNameList(itemCount), itemTypeList(itemCount), stat=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call ESMF_StateGet(importState, itemTypeList=itemTypeList, &
itemNameList=itemNameList, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
endif
do i=1, itemCount
if (itemTypeList(i) /= ESMF_STATEITEM_FIELD) cycle
write(message,'(A)') trim(compName)//' realized field '//trim(itemNameList(i))// &
' in its import state'
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
enddo
!> As IPDv01p3 (NUOPC Provided) fails when fields are not connected, we here
!> remove all unconnected fields from the import and export stabilityTimeStep
call SCHISM_RemoveUnconnectedFields(importState, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call SCHISM_RemoveUnconnectedFields(exportState, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!@TODO: should we destroy field & array vars?
end subroutine
#undef ESMF_METHOD
#define ESMF_METHOD "SetClock"
!> @description A model's clock copies start/stop time and timestep from its
!> parent's clock. If a model has a timestep that is different (smaller) than
!> the parent's it needs to be set here.
subroutine SetClock(comp, rc)
use schism_glbl, only : start_year, start_month, start_day, start_hour, rnday
use schism_glbl, only : wtiminc
type(ESMF_GridComp) :: comp
integer, intent(out) :: rc
type(ESMF_Clock) :: driverClock, modelClock
type(ESMF_TimeInterval) :: runDur, timeStep
type(ESMF_Time) :: startTime, stopTime
integer :: localrc, d, h, m
real(ESMF_KIND_R8) :: seconds
character(len=ESMF_MAXSTR) :: message
rc = ESMF_SUCCESS
call NUOPC_ModelGet(comp, driverClock=driverClock, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> Set start time
call ESMF_TimeSet(startTime, yy=start_year, mm=start_month, dd=start_day, h=int(start_hour), rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> Set stop time
d = int(rnday)
h = int((rnday-d)*24)
m = int((rnday-d)*24*60-h*60)
call ESMF_TimeIntervalSet(runDur, d=d, h=h, m=m, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
stopTime = startTime+runDur
!> Time step must be same with the driver
call ESMF_ClockGet(driverClock, timeStep=timeStep, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> Create component clock
modelClock = ESMF_ClockCreate(timeStep, startTime, stopTime=stopTime, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> Update component clock
call ESMF_GridCompSet(comp, clock=modelClock, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> Check that wtiminc, i.e. the time between two new atmospheric inputs
!> corresponds to the parent (coupling) time step
call ESMF_TimeIntervalGet(timeStep, s_r8=seconds, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
if (abs(wtiminc - seconds) > 1e-6) then
write(message, '(A,I7,A,I7)') 'Check setting of wtiminc = ', int(wtiminc), &
' in param.nml! Auto-resetting to wtiminc = ', int(seconds)
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_WARNING)
endif
wtiminc = seconds
end subroutine
#undef ESMF_METHOD
#define ESMF_METHOD "SetRunClock"
!> @description If the timestep of the parent is dynamic, then there might
!> be mismatches between intergral timesteps of a model and the parent
!> timestep. This is reported as an error unless dealt with in this label
!> @todo (not registered and fully implemented yet, so not used)
subroutine SetRunClock(comp, rc)
type(ESMF_GridComp) :: comp
integer, intent(out) :: rc
type(ESMF_Clock) :: driverClock, modelClock
type(ESMF_Time) :: driverCurrTime
integer :: localrc
rc = ESMF_SUCCESS
!> query driver and the component clocks
call NUOPC_ModelGet(comp, driverClock=driverClock, modelClock=modelClock, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call ESMF_ClockGet(driverClock, currTime=driverCurrTime, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> set model clock to have the current start time as the driver clock
call ESMF_ClockSet(modelClock, currTime=driverCurrTime, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> check the component clock against the driver clock
call NUOPC_CompCheckSetClock(comp, driverClock, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
end subroutine
#undef ESMF_METHOD
#define ESMF_METHOD "DataInitialize"
subroutine DataInitialize(comp, rc)
type(ESMF_GridComp) :: comp
integer, intent(out) :: rc
! local variables
type(ESMF_Time) :: currTime
type(ESMF_Clock) :: clock
type(ESMF_State) :: exportState
integer(ESMF_KIND_I4) :: localrc
character(len=*), parameter :: subname = '(DataInitialize): '
!--------------------------------
rc = ESMF_SUCCESS
call ESMF_LogWrite(trim(subname)//' called', ESMF_LOGMSG_INFO)
!> Query component for its clock, import and export states
call NUOPC_ModelGet(comp, modelClock=clock, exportState=exportState, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> Update fields on export state
call SCHISM_Export(comp, exportState, clock, localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call ESMF_LogWrite(trim(subname)//' done', ESMF_LOGMSG_INFO)
end subroutine DataInitialize
#undef ESMF_METHOD
#define ESMF_METHOD "ModelAdvance"
!> @description As described in the section 4.2, the subroutine ModelAdvance (shown below) has been registered to the special- ization point with the label model_label_Advance in the SetServices subroutine. This specialization point subroutine is called within the generic NUOPC_Model run phase in order to request that your model take a timestep forward. The code to do this is model dependent, so it does not appear in the subroutine below. Each NUOPC component maintains its own clock (an ESMF_Clock object). The clock is used to indicate the current model time and the timestep size. When the subroutine finishes, your model should be moved ahead in time from the current time by one timestep. NUOPC will automatically advance the clock for you, so there is no explicit call to do that here.
!> Because the import/export states and the clock do not come in through the parameter list, they must be accessed via a call to NUOPC_ModelGet
subroutine ModelAdvance(comp, rc)
use schism_glbl, only: dt
implicit none
!> Input/output variables
type(ESMF_GridComp) :: comp
integer, intent(out) :: rc
!> Local variables
type(ESMF_Clock) :: clock
type(ESMF_State) :: importState, exportState
type(ESMF_Time) :: currTime
type(ESMF_TimeInterval) :: timeStep
character(len=160) :: message
integer(ESMF_KIND_I4) :: localrc
integer, save :: it = 1
integer :: i, num_schism_steps
real(ESMF_KIND_R8) :: seconds
character(len=*), parameter :: subname = '(ModelAdvance): '
!--------------------------------
rc = ESMF_SUCCESS
call ESMF_LogWrite(trim(subname)//' called', ESMF_LOGMSG_INFO)
!> Query component for its clock, import and export states
call NUOPC_ModelGet(comp, modelClock=clock, importState=importState, &
exportState=exportState, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> Update fields on import state
call SCHISM_Import(comp, importState, clock, rc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> Write log about advance
call ESMF_ClockPrint(clock, options="currTime", &
preString="--- advancing schism from ", unit=message, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call ESMF_ClockGet(clock, currTime=currTime, timeStep=timeStep, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call ESMF_TimePrint(currTime + timeStep, &
preString=trim(message)//" to ", unit=message, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call ESMF_LogWrite(message, ESMF_LOGMSG_INFO, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> Run SCHISM
call ESMF_TimeIntervalGet(timeStep, s_r8=seconds, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
num_schism_steps=int(seconds/dt)
do i = it, it+num_schism_steps-1
call schism_step(i)
it = it + 1
end do
!> Update fields on export state
call SCHISM_Export(comp, exportState, clock, localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call ESMF_LogWrite(trim(subname)//' done', ESMF_LOGMSG_INFO)
end subroutine ModelAdvance
#undef ESMF_METHOD
#define ESMF_METHOD "SCHISM_RemoveUnconnectedFields"
subroutine SCHISM_RemoveUnconnectedFields(state, rc)
implicit none
type(ESMF_State), intent(inout) :: state
integer(kind=ESMF_KIND_I4), optional :: rc
integer(kind=ESMF_KIND_I4) :: rc_, localrc, itemCount, i
type(ESMF_StateItem_Flag), allocatable :: itemTypeList(:)
character(len=ESMF_MAXSTR), allocatable :: itemNameList(:)
character(len=ESMF_MAXSTR) :: message
type(ESMF_Field) :: field
logical :: isPresent
if (present(rc)) rc = ESMF_SUCCESS
call ESMF_StateGet(state, itemCount=itemCount, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc_)
allocate(itemTypeList(itemCount))
allocate(itemNameList(itemCount))
call ESMF_StateGet(state, itemTypeList=itemTypeList, &
itemNameList=itemNameList, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc_)
do i=1, itemCount
if (itemTypeList(i) /= ESMF_STATEITEM_FIELD) cycle
call ESMF_StateGet(state, trim(itemNameList(i)), field=field, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc_)
isPresent=.true.
! call ESMF_AttributeGet(field, name='Connected', isPresent=isPresent, rc=localrc)
! _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc_)
write(message,'(A)') '--- checking connection state of '//trim(itemNameList(i))
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
!if (isPresent) isPresent = NUOPC_IsConnected(state,trim(itemNameList(i)), rc=localrc)
if (isPresent) isPresent = NUOPC_IsConnected(field, rc=localrc)
if(localrc/=ESMF_SUCCESS) then
isPresent=.false.
localrc=ESMF_SUCCESS
endif
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc_)
if (.not.isPresent) then
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc_)
call ESMF_StateRemove(state, itemNameList(i:i), rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc_)
write(message,'(A)') '--- removed unconnected field '//trim(itemNameList(i))
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
endif
enddo
end subroutine SCHISM_RemoveUnconnectedFields
#undef ESMF_METHOD
#define ESMF_METHOD "SCHISM_Export"
subroutine SCHISM_Export(comp, exportState, clock, rc)
use schism_glbl, only: nvrt, eta2, dav, uu2, vv2, tr_nd, idry_e
use schism_esmf_util, only: SCHISM_StateUpdate
implicit none
!> Input/output variables
type(ESMF_GridComp), intent(in) :: comp
type(ESMF_State) , intent(inout) :: exportState
type(ESMF_Clock) , intent(in) :: clock
integer , intent(inout) :: rc
!> Local variables
type(ESMF_Time) :: currTime
type(type_InternalStateWrapper) :: internalState
type(type_InternalState), pointer :: isDataPtr => null()
integer(ESMF_KIND_I4) :: localrc
real(ESMF_KIND_R8), allocatable, save, target :: idry_r8(:)
character(len=ESMF_MAXSTR) :: timeStr
character(len=*), parameter :: subname = '(SCHISM_Export): '
!--------------------------------
rc = ESMF_SUCCESS
call ESMF_LogWrite(trim(subname)//' called', ESMF_LOGMSG_INFO)
!> Query internal state
call ESMF_GridCompGetInternalState(comp, internalState, localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
isDataPtr => internalState%wrap
if(.not.associated(isDataPtr)) localrc = ESMF_RC_PTR_NULL
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> Update fields on export state
!> sea surface height
call SCHISM_StateUpdate(exportState, 'sea_surface_height_above_sea_level', eta2, &
isPtr=isDataPtr, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> depth average current in x direction
call SCHISM_StateUpdate(exportState, 'depth-averaged_x-velocity', dav(1,:), &
isPtr=isDataPtr, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> depth average current in y direction
call SCHISM_StateUpdate(exportState, 'depth-averaged_y-velocity', dav(2,:), &
isPtr=isDataPtr, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> surface current in x direction
call SCHISM_StateUpdate(exportState, 'ocn_current_zonal', uu2(nvrt,:), &
isPtr=isDataPtr, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> surface current in y direction
call SCHISM_StateUpdate(exportState, 'ocn_current_merid', vv2(nvrt,:), &
isPtr=isDataPtr, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> surface temperature
call SCHISM_StateUpdate(exportState, 'sea_surface_temperature', tr_nd(1,:,:), &
isPtr=isDataPtr, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> surface salinity
call SCHISM_StateUpdate(exportState, 'sea_surface_salinity', tr_nd(2,:,:), &
isPtr=isDataPtr, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> ocean mask
!> mediator expects ocean mask in double rather then integer
if (.not. allocated(idry_r8)) then
allocate(idry_r8(size(idry_e)))
idry_r8(:) =0.0d0
end if
idry_r8(:) = dble(idry_e(:))
call SCHISM_StateUpdate(exportState, 'ocean_mask', idry_r8, &
isPtr=isDataPtr, onElement=.true., rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
!> Write fields on export state for debugging
if (debug_level > 0) then
call ESMF_ClockGet(clock, currTime=currTime, rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call ESMF_TimeGet(currTime, timeStringISOFrac=timeStr , rc=localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
call SCHISM_StateWriteVTK(exportState, 'export_'//trim(timeStr), rc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
end if
call ESMF_LogWrite(trim(subname)//' done', ESMF_LOGMSG_INFO)
end subroutine SCHISM_Export
#undef ESMF_METHOD
#define ESMF_METHOD "SCHISM_Import"
subroutine SCHISM_Import(comp, importState, clock, rc)
use schism_glbl , only: windx2, windy2, pr2
use schism_esmf_util, only: SCHISM_StateImportWaveTensor
use schism_esmf_util, only: SCHISM_StateUpdate
implicit none
!> Input/output variables
type(ESMF_GridComp), intent(in) :: comp
type(ESMF_State) , intent(inout) :: importState
type(ESMF_Clock) , intent(in) :: clock
integer , intent(inout) :: rc
!> Local variables
type(ESMF_Time) :: currTime
type(type_InternalStateWrapper) :: internalState
type(type_InternalState), pointer :: isDataPtr => null()
integer(ESMF_KIND_I4) :: localrc
character(len=ESMF_MAXSTR) :: timeStr
character(len=*), parameter :: subname = '(SCHISM_Import): '
!--------------------------------
rc = ESMF_SUCCESS
call ESMF_LogWrite(trim(subname)//' called', ESMF_LOGMSG_INFO)
!> Query internal state
call ESMF_GridCompGetInternalState(comp, internalState, localrc)
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
isDataPtr => internalState%wrap
if(.not.associated(isDataPtr)) localrc = ESMF_RC_PTR_NULL