-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdriverParentComp.F90
194 lines (163 loc) · 6.83 KB
/
driverParentComp.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
!==============================================================================
! Earth System Modeling Framework
! Copyright (c) 2002-2025, 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 driverParentComp
!-----------------------------------------------------------------------------
! Code that specializes generic NUOPC_Driver
!-----------------------------------------------------------------------------
use ESMF
use NUOPC
use NUOPC_Driver, &
driverSS => SetServices
use driverChildComp, only: driver_SS => SetServices
use OCN, only: ocnSS => SetServices
use NUOPC_Connector, only: cplSS => SetServices
implicit none
private
! private module data --> ONLY PARAMETERS
integer, parameter :: stepCount = 5
real(ESMF_KIND_R8), parameter :: stepTime = 30.D0 ! step time [s]
! should be parent step
public SetServices
!-----------------------------------------------------------------------------
contains
!-----------------------------------------------------------------------------
subroutine SetServices(driver, rc)
type(ESMF_GridComp) :: driver
integer, intent(out) :: rc
rc = ESMF_SUCCESS
! derive from NUOPC_Driver
call NUOPC_CompDerive(driver, driverSS, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
! specialize driver
call NUOPC_CompSpecialize(driver, specLabel=label_SetModelServices, &
specRoutine=SetModelServices, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
! set driver verbosity
call NUOPC_CompAttributeSet(driver, name="Verbosity", value="high", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
end subroutine
!-----------------------------------------------------------------------------
subroutine SetModelServices(driver, rc)
type(ESMF_GridComp) :: driver
integer, intent(out) :: rc
! local variables
type(ESMF_GridComp) :: child
type(ESMF_CplComp) :: connector
type(ESMF_Time) :: startTime
type(ESMF_Time) :: stopTime
type(ESMF_TimeInterval) :: timeStep
type(ESMF_Clock) :: internalClock
integer :: petCount, i
integer, allocatable :: petList(:)
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
! SetServices for the child driver, acting as ATM, on custom petList
allocate(petList(petCount/2))
do i=1, petCount/2
petList(i) = i-1 ! PET labeling goes from 0 to petCount-1
enddo
call NUOPC_DriverAddComp(driver, "driverChild", driver_SS, &
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 the OCN
call NUOPC_DriverAddComp(driver, "OCN", ocnSS, 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
#if 1
! turning this connector off will trigger an error in the driverChild
! InternalInitializeRealize() routine, detecting that there is no producer
! for this field.
! SetServices for OCN2ATM
call NUOPC_DriverAddComp(driver, srcCompLabel="OCN", &
dstCompLabel="driverChild", &
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
#endif
! SetServices for ATM2OCN
call NUOPC_DriverAddComp(driver, srcCompLabel="driverChild", &
dstCompLabel="OCN", &
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
! set the model clock
call ESMF_TimeSet(startTime, s = 0, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
call ESMF_Finalize(endflag=ESMF_END_ABORT)
call ESMF_TimeSet(stopTime, s_r8 = stepTime * stepCount, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
call ESMF_Finalize(endflag=ESMF_END_ABORT)
call ESMF_TimeIntervalSet(timeStep, s_r8 = stepTime, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
call ESMF_Finalize(endflag=ESMF_END_ABORT)
internalClock = ESMF_ClockCreate(name="Driver Clock", &
timeStep=timeStep, startTime=startTime, stopTime=stopTime, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
call ESMF_Finalize(endflag=ESMF_END_ABORT)
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