forked from geoschem/FVdycoreCubed_GridComp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StandAlone_DynAdvCore_GridCompMod.F90
executable file
·367 lines (294 loc) · 11.3 KB
/
StandAlone_DynAdvCore_GridCompMod.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
#include "MAPL_Generic.h"
!-------------------------------------------------------------------------
! NASA/GSFC, Global Modeling and Assimilation Office, Code 910.1 !
!-------------------------------------------------------------------------
!BOP
!
! !MODULE: StandAlone_DynAdvCore_GridCompMod
!
! !INTERFACE:
module StandAlone_DynAdvCore_GridCompMod
!
! !USES:
use ESMF
use MAPL
use AdvCore_GridCompMod, only : AdvCoreSetServices => SetServices
use FVdycoreCubed_GridComp, only : DynCoreSetServices => SetServices
implicit none
private
! !PUBLIC MEMBER FUNCTIONS:
public SetServices
!
integer :: DynCore = -1
integer :: AdvCore = -1
! !DESCRIPTION:
!
! {\tt StandAlone\_DynAdvCore\_GridCompMod} is an ESMF gridded component implementing
! DynCore and AdvCore.
!
! !REVISION HISTORY:
! 18March2014 Kouatchou First crack.
!
!EOP
!------------------------------------------------------------------------------
contains
!------------------------------------------------------------------------------
!BOP
! !IROUTINE: SetServices - Externally visible registration routine
!
! !INTERFACE:
!
subroutine SetServices(GC, rc)
!
! !ARGUMENTS:
type(ESMF_GridComp), intent(inout) :: GC
integer, optional, intent( out) :: RC
!
! !DESCRIPTION:
!
! User-supplied setservices routine.
! The register routine sets the subroutines to be called
! as the init, run, and finalize routines. Note that those are
! private to the module.
!
!EOP
character(len=ESMF_MAXSTR) :: IAm
integer :: STATUS
character(len=ESMF_MAXSTR) :: COMP_NAME
!=============================================================================
! Begin...
! Get my name and set-up traceback handle
! ---------------------------------------
call ESMF_GridCompGet( GC, NAME=COMP_NAME, RC=STATUS )
VERIFY_(STATUS)
Iam = trim(COMP_NAME) // 'SetServices'
! Register methods with MAPL
! --------------------------
call MAPL_GridCompSetEntryPoint ( GC, ESMF_METHOD_INITIALIZE, Initialize, RC=status )
VERIFY_(STATUS)
call MAPL_GridCompSetEntryPoint ( GC, ESMF_METHOD_RUN, Run, RC=status )
VERIFY_(STATUS)
call MAPL_GridCompSetEntryPoint ( GC, ESMF_METHOD_FINALIZE, Finalize, RC=status )
VERIFY_(STATUS)
! Creat childrens gridded components and invoke their SetServices
!-----------------------------------------------------------------
DynCore = MAPL_AddChild(GC, NAME='DYN', SS=DynCoreSetServices, RC=status)
VERIFY_(STATUS)
AdvCore = MAPL_AddChild(GC, NAME='ADV', SS=AdvCoreSetServices, RC=status)
VERIFY_(STATUS)
call MAPL_TimerAdd(GC, name="INITIALIZE" ,RC=STATUS)
VERIFY_(STATUS)
call MAPL_TimerAdd(GC, name="RUN" ,RC=STATUS)
VERIFY_(STATUS)
call MAPL_TimerAdd(GC, name="TOTAL" ,RC=STATUS)
VERIFY_(STATUS)
! AdvCore Imports
! ---------------
CALL MAPL_AddConnectivity ( GC, &
SHORT_NAME = (/'MFX ', 'MFY ', 'CX ' , 'CY ', 'PLE0', 'PLE1'/), &
DST_ID = AdvCore, &
SRC_ID = DynCore, &
RC=STATUS )
VERIFY_(STATUS)
! Ending with a Generic SetServices call is a MAPL requirement
!-------------------------------------------------------------
call MAPL_GenericSetServices ( GC, rc=STATUS)
VERIFY_(STATUS)
! All done
! --------
!if ( MAPL_AM_I_ROOT() ) print *, trim(Iam) // ': done!'
RETURN_(ESMF_SUCCESS)
end subroutine SetServices
!EOC
!------------------------------------------------------------------------------
! NASA/GSFC, Global Modeling and Assimilation Office, Code 610.1 !
!-------------------------------------------------------------------------
!BOP
!
! !IROUTINE: Initialize_ --- Initialize Example
!
! !INTERFACE:
!
SUBROUTINE Initialize ( GC, IMPORT, EXPORT, CLOCK, rc )
! !USES:
implicit NONE
! !INPUT PARAMETERS:
type(ESMF_Clock), intent(inout) :: CLOCK ! The clock
! !OUTPUT PARAMETERS:
type(ESMF_GridComp), intent(inout) :: GC ! Grid Component
type(ESMF_State), intent(inout) :: IMPORT ! Import State
type(ESMF_State), intent(inout) :: EXPORT ! Export State
integer, intent(out) :: rc ! Error return code:
! 0 - all is well
! 1 -
! !DESCRIPTION: This is a simple ESMF wrapper.
!EOP
!
! !LOCAL VARIABLES:
character(len=ESMF_MAXSTR) :: IAm
integer :: STATUS
type(ESMF_Grid) :: GRID ! Grid
type(ESMF_Config) :: CF ! Universal Config
integer :: im, jm, lm ! 3D Dimensions
real(ESMF_KIND_R4), pointer :: lons(:,:) ! Longitudes
real(ESMF_KIND_R4), pointer :: lats(:,:) ! Latitudes
integer :: nymd, nhms ! date, time
real :: cdt ! time step in secs
character(len=ESMF_MAXSTR) :: comp_name
type (MAPL_MetaComp), pointer :: MAPL
!-------------------------------------------------------------------------
!BOC
Iam = 'Initialize'
! Get my name and set-up traceback handle
! ---------------------------------------
call ESMF_GridCompGet( GC, name=COMP_NAME, RC=status )
VERIFY_(STATUS)
Iam = trim(comp_name) // trim(Iam)
if ( MAPL_AM_I_ROOT() ) print *, trim(Iam) // ': Generic Init...'
! Create grid for this GC
! ------------------------
call MAPL_GridCreate (GC, RC=status )
VERIFY_(STATUS)
call MAPL_GetObjectFromGC ( GC, MAPL, RC=STATUS)
VERIFY_(STATUS)
! Initialize MAPL Generic
! -----------------------
call MAPL_GenericInitialize ( gc, IMPORT, EXPORT, clock, RC=status )
VERIFY_(STATUS)
! All done
! --------
!if ( MAPL_AM_I_ROOT() ) print *, trim(Iam) // ': done!'
RETURN_(ESMF_SUCCESS)
END SUBROUTINE Initialize
!EOC
!------------------------------------------------------------------------------
!BOP
!
! !IROUTINE: Run - run routine
!
! !INTERFACE:
!
subroutine Run(GC, IMPORT, EXPORT, CLOCK, RC)
!
! !INPUT/OUTPUT PARAMETERS:
type(ESMF_GridComp), intent(inout) :: GC ! Gridded component
type(ESMF_State), intent(inout) :: IMPORT ! Import state
type(ESMF_State), intent(inout) :: EXPORT ! Export state
type(ESMF_Clock), intent(inout) :: CLOCK ! The clock
!
! !OUTPUT PARAMETERS:
integer, optional, intent( out) :: RC ! Error code
!
! !DESCRIPTION:
!
! The Run method advanced the advection one long time step, as
! specified in the configuration. This may be broken down int a
! number of internal, small steps, also configurable.
!
!EOP
!=============================================================================
!BOC
! !LOCAL VARIABLES:
character(len=ESMF_MAXSTR) :: IAm
integer :: STATUS
character(len=ESMF_MAXSTR) :: COMP_NAME
type(ESMF_Grid) :: GRID ! Grid
type(ESMF_Config) :: CF ! Universal Config
type (MAPL_MetaComp), pointer :: MAPL
integer :: im, jm, lm ! 3D Dimensions
real(ESMF_KIND_R4), pointer :: lons(:,:) ! Longitudes
real(ESMF_KIND_R4), pointer :: lats(:,:) ! Latitudes
integer :: nymd, nhms ! date, time
real :: cdt ! time step in secs
type (ESMF_GridComp), pointer :: GCS(:)
type (ESMF_State), pointer :: GIM(:)
type (ESMF_State), pointer :: GEX(:)
type (ESMF_State) :: INTERNAL
character(len=ESMF_MAXSTR),pointer :: GCNames(:)
INTEGER :: I
! Get my name and set-up traceback handle
! ---------------------------------------
Iam = 'Run'
call ESMF_GridCompGet( GC, NAME=COMP_NAME, RC=STATUS )
VERIFY_(STATUS)
Iam = trim(COMP_NAME) // trim(Iam)
!if ( MAPL_AM_I_ROOT() ) print *, trim(Iam) // ': Generic Run...'
! Get my internal MAPL_Generic state
!-----------------------------------
call MAPL_GetObjectFromGC ( GC, MAPL, RC=STATUS)
VERIFY_(STATUS)
call MAPL_TimerOn(MAPL, "TOTAL")
call MAPL_TimerOn(MAPL, "RUN")
! Get the children`s states from the generic state
!-------------------------------------------------
call MAPL_Get ( MAPL, &
GCS=GCS, GIM=GIM, GEX=GEX, &
GCNames = GCNames, &
INTERNAL_ESMF_STATE = INTERNAL, &
RC=STATUS )
VERIFY_(STATUS)
! Call Run Method for Children
I = DynCore
call ESMF_GridCompRun(GCS(I), &
importState = GIM(I), &
exportState = GEX(I), &
clock = CLOCK, &
userRC=STATUS)
VERIFY_(STATUS)
I = AdvCore
call ESMF_GridCompRun(GCS(I), &
importState = GIM(I), &
exportState = GEX(I), &
clock = CLOCK, &
userRC=STATUS)
VERIFY_(STATUS)
call MAPL_TimerOff(MAPL, "TOTAL")
call MAPL_TimerOff(MAPL, "RUN")
!IF ( MAPL_AM_I_ROOT() ) PRINT*, TRIM(Iam) // ': done!'
RETURN_(ESMF_SUCCESS)
end subroutine Run
!EOC
!------------------------------------------------------------------------------
!BOP
!
! !IROUTINE: Finalize - user supplied finalize routine
!
! !INTERFACE:
!
subroutine Finalize(GC, IMPORT, EXPORT, CLOCK, RC)
!
! !INPUT/OUTPUT PARAMETERS:
type(ESMF_GridComp), intent(inout) :: GC ! Gridded component
type(ESMF_State), intent(inout) :: IMPORT ! Import state
type(ESMF_State), intent(inout) :: EXPORT ! Export state
type(ESMF_Clock), intent(inout) :: CLOCK ! The clock
!
! !OUTPUT PARAMETERS:
integer, optional, intent( out) :: RC ! Error code
!
! !DESCRIPTION:
! Finalize merely destroys the FVadv object that was created in Initialize
! and releases the space for the persistent data .
!
!EOP
!=============================================================================
!BOC
! !LOCAL VARIABLES:
character(len=ESMF_MAXSTR) :: IAm
integer :: STATUS
character(len=ESMF_MAXSTR) :: COMP_NAME
! Get my name and set-up traceback handle
! ---------------------------------------
Iam = 'Finalize'
call ESMF_GridCompGet( GC, NAME=COMP_NAME, RC=STATUS )
VERIFY_(STATUS)
Iam = trim(COMP_NAME) // TRIM(Iam)
!if ( MAPL_AM_I_ROOT() ) print *, trim(Iam) // ': Generic Fin...'
call MAPL_GenericFinalize(GC, IMPORT, EXPORT, CLOCK, RC)
VERIFY_(STATUS)
!IF ( MAPL_AM_I_ROOT() ) PRINT*, TRIM(Iam) // ': done!'
RETURN_(ESMF_SUCCESS)
end subroutine Finalize
!EOC
!------------------------------------------------------------------------------
end module StandAlone_DynAdvCore_GridCompMod