-
Notifications
You must be signed in to change notification settings - Fork 1
/
esm.F90
202 lines (170 loc) · 7.12 KB
/
esm.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
!==============================================================================
! Earth System Modeling Framework
! Copyright 2002-2018, University Corporation for Atmospheric Research,
! Massachusetts Institute of Technology, Geophysical Fluid Dynamics
! Laboratory, University of Michigan, National Centers for Environmental
! Prediction, Los Alamos National Laboratory, Argonne National Laboratory,
! NASA Goddard Space Flight Center.
! Licensed under the University of Illinois-NCSA License.
!==============================================================================
module ESM
!-----------------------------------------------------------------------------
! Code that specializes generic ESM Component code.
!-----------------------------------------------------------------------------
use ESMF
use NUOPC
use NUOPC_Driver, &
driver_routine_SS => SetServices, &
driver_label_SetModelServices => label_SetModelServices
use hycom_cap, only: ocnSS => SetServices
use cice_cap, only: iceSS => SetServices
use CON, only: cplSS => SetServices
implicit none
private
public SetServices
!-----------------------------------------------------------------------------
contains
!-----------------------------------------------------------------------------
subroutine SetServices(driver, rc)
type(ESMF_GridComp) :: driver
integer, intent(out) :: rc
rc = ESMF_SUCCESS
! NUOPC_Driver registers the generic methods
call NUOPC_CompDerive(driver, driver_routine_SS, 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(driver, specLabel=driver_label_SetModelServices, &
specRoutine=SetModelServices, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
! set verbosity on driver
call NUOPC_CompAttributeSet(driver, name="Verbosity", value="max", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
end subroutine
!-----------------------------------------------------------------------------
subroutine SetModelServices(driver, rc)
use mod_nuopc_options, only: &
tstart, tend, nuopc_tinterval, nuopc_opt, &
ice_petCount, ocn_petCount
type(ESMF_GridComp) :: driver
integer, intent(out) :: rc
! local variables
integer :: localrc
type(ESMF_Grid) :: grid
type(ESMF_Field) :: field
type(ESMF_Time) :: startTime
type(ESMF_Time) :: stopTime
type(ESMF_TimeInterval) :: timeStep
type(ESMF_Clock) :: internalClock
type(ESMF_GridComp) :: child
integer :: petCount, i
integer :: petCountATM, petCountOCN
integer, allocatable :: petList(:)
type(ESMF_CplComp) :: connector
rc = ESMF_SUCCESS
! get the petCount
call ESMF_GridCompGet(driver, petCount=petCount, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
! call namelist coupled
call nuopc_opt()
! SetServices for OCN with petList on first half of PETs
allocate(petList(ocn_petCount))
do i=1,ocn_petCount
petList(i)=i-1
enddo
call NUOPC_DriverAddComp(driver, "HYCOM", ocnSS, petList=petList, &
comp=child, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call NUOPC_CompAttributeSet(child, name="Verbosity", value="high", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
deallocate(petList)
! SetServices for CICE with petList on second half of PETs
allocate(petList(ice_petCount))
do i=1,ice_petCount
petList(i)=ocn_petCount+i-1
enddo
call NUOPC_DriverAddComp(driver, "CICE", iceSS,petList=petList, &
comp=child, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call NUOPC_CompAttributeSet(child, name="Verbosity", value="high", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
deallocate(petList)
! SetServices for cice2ocn
call NUOPC_DriverAddComp(driver, srcCompLabel="CICE", dstCompLabel="HYCOM", &
compSetServicesRoutine=cplSS, comp=connector, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call NUOPC_CompAttributeSet(connector, name="Verbosity", value="high", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
! SetServices for ocn2ice
call NUOPC_DriverAddComp(driver, srcCompLabel="HYCOM", dstCompLabel="CICE", &
compSetServicesRoutine=cplSS, comp=connector, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call NUOPC_CompAttributeSet(connector, name="Verbosity", value="max", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
! set the driver clock
call ESMF_TimeIntervalSet(timeStep, s=nuopc_tinterval, rc=rc) ! 3 minute steps
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_TimeSet(startTime, yy=tstart(1), mm=tstart(2), dd=tstart(3), h=tstart(4), m=0, &
calkindflag=ESMF_CALKIND_GREGORIAN, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_TimeSet(stopTime, yy=tend(1), mm=tend(2), dd=tend(3), h=tend(4), m=0, &
calkindflag=ESMF_CALKIND_GREGORIAN, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
internalClock = ESMF_ClockCreate(name="HYCOM CICE NUOPC", &
timeStep=timeStep, startTime=startTime, stopTime=stopTime, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_GridCompSet(driver, clock=internalClock, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
end subroutine
!-----------------------------------------------------------------------------
end module