FV3-JEDI
esm.F90
Go to the documentation of this file.
1 module esm
2 
3  !-----------------------------------------------------------------------------
4  ! Code that specializes generic ESM Component code.
5  !-----------------------------------------------------------------------------
6 
7  use esmf
8  use nuopc
9  use nuopc_driver, &
10  driver_routine_ss => setservices, &
11  driver_label_setmodelservices => label_setmodelservices, &
12  driver_label_setrunsequence => label_setrunsequence
13 
14  use atm, only: atmss => setservices
15  use ocn, only: ocnss => setservices
16  use med, only: medss => setservices
17 
18  use nuopc_connector, only: cplss => setservices
19 
20  implicit none
21 
22  private
23 
24  public setservices
25 
26  !-----------------------------------------------------------------------------
27  contains
28  !-----------------------------------------------------------------------------
29 
30  subroutine setservices(driver, rc)
31  type(esmf_gridcomp) :: driver
32  integer, intent(out) :: rc
33 
34  rc = esmf_success
35 
36  ! NUOPC_Driver registers the generic methods
37  call nuopc_compderive(driver, driver_routine_ss, rc=rc)
38  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
39  line=__line__, &
40  file=__file__)) &
41  return ! bail out
42 
43  ! attach specializing method(s)
44  call nuopc_compspecialize(driver, speclabel=driver_label_setmodelservices, &
45  specroutine=setmodelservices, rc=rc)
46  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
47  line=__line__, &
48  file=__file__)) &
49  return ! bail out
50  call nuopc_compspecialize(driver, speclabel=driver_label_setrunsequence, &
51  specroutine=setrunsequence, rc=rc)
52  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
53  line=__line__, &
54  file=__file__)) &
55  return ! bail out
56 
57  end subroutine
58 
59  !-----------------------------------------------------------------------------
60 
61  subroutine setmodelservices(driver, rc)
62  type(esmf_gridcomp) :: driver
63  integer, intent(out) :: rc
64 
65  ! local variables
66  integer :: localrc
67  type(esmf_time) :: startTime
68  type(esmf_time) :: stopTime
69  type(esmf_timeinterval) :: timeStep
70  type(esmf_clock) :: internalClock
71  integer :: petCount, i
72  integer, allocatable :: petList(:)
73  type(esmf_gridcomp) :: child
74  type(esmf_cplcomp) :: connector
75 
76  rc = esmf_success
77 
78  ! get the petCount
79  call esmf_gridcompget(driver, petcount=petcount, rc=rc)
80  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
81  line=__line__, &
82  file=__file__)) &
83  return ! bail out
84 
85  ! SetServices for ATM
86  allocate(petlist(petcount))
87  do i=1, petcount
88  petlist(i) = i-1 ! PET labeling goes from 0 to petCount-1
89  enddo !0,1,2
90  call nuopc_driveraddcomp(driver, "ATM", atmss, petlist=petlist, &
91  comp=child, rc=rc)
92  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
93  line=__line__, &
94  file=__file__)) &
95  return ! bail out
96  deallocate(petlist)
97  call nuopc_compattributeset(child, name="Verbosity", value="high", rc=rc)
98  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
99  line=__line__, &
100  file=__file__)) &
101  return ! bail out
102 
103  ! SetServices for OCN
104  allocate(petlist(petcount))
105  do i=1, petcount
106  petlist(i) = i-1 ! PET labeling goes from 0 to petCount-1
107  enddo !3,4,5
108  call nuopc_driveraddcomp(driver, "OCN", ocnss, petlist=petlist, &
109  comp=child, rc=rc)
110  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
111  line=__line__, &
112  file=__file__)) &
113  return ! bail out
114  deallocate(petlist)
115  call nuopc_compattributeset(child, name="Verbosity", value="high", rc=rc)
116  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
117  line=__line__, &
118  file=__file__)) &
119  return ! bail out
120 
121  ! SetServices for MED
122  ! set petList for MED
123  ! There are no restrictions that NUOPC places on the mediator petList,
124  ! neither in size, nor the PETs that are included.
125  ! In this example the petList for MED is set to some crazy combination,
126  ! just to show that it can basically be set to anything:
127  ! -> first PET of each ATM and OCN and the two missed PETs
128  ! -> kind of strange, but hey this is just a feature demo
129  allocate(petlist(petcount)) ! makes 4 total PETs in the petList
130  do i=1, petcount
131  petlist(i) = i-1 ! PET labeling goes from 0 to petCount-1
132  enddo !0,1,2,3,4,5
133  call nuopc_driveraddcomp(driver, "MED", medss, petlist=petlist, &
134  comp=child, rc=rc)
135  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
136  line=__line__, &
137  file=__file__)) &
138  return ! bail out
139  deallocate(petlist)
140  call nuopc_compattributeset(child, name="Verbosity", value="high", rc=rc)
141  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
142  line=__line__, &
143  file=__file__)) &
144  return ! bail out
145 
146  ! SetServices for atm2med
147  call nuopc_driveraddcomp(driver, srccomplabel="ATM", dstcomplabel="MED", &
148  compsetservicesroutine=cplss, comp=connector, rc=rc)
149  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
150  line=__line__, &
151  file=__file__)) &
152  return ! bail out
153  call nuopc_compattributeset(connector, name="Verbosity", value="high", rc=rc)
154  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
155  line=__line__, &
156  file=__file__)) &
157  return ! bail out
158 
159  ! SetServices for ocn2med
160  call nuopc_driveraddcomp(driver, srccomplabel="OCN", dstcomplabel="MED", &
161  compsetservicesroutine=cplss, comp=connector, rc=rc)
162  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
163  line=__line__, &
164  file=__file__)) &
165  return ! bail out
166  call nuopc_compattributeset(connector, name="Verbosity", value="high", rc=rc)
167  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
168  line=__line__, &
169  file=__file__)) &
170  return ! bail out
171 
172  ! SetServices for med2atm
173  call nuopc_driveraddcomp(driver, srccomplabel="MED", dstcomplabel="ATM", &
174  compsetservicesroutine=cplss, comp=connector, rc=rc)
175  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
176  line=__line__, &
177  file=__file__)) &
178  return ! bail out
179  call nuopc_compattributeset(connector, name="Verbosity", value="high", rc=rc)
180  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
181  line=__line__, &
182  file=__file__)) &
183  return ! bail out
184 
185  ! SetServices for med2ocn
186  call nuopc_driveraddcomp(driver, srccomplabel="MED", dstcomplabel="OCN", &
187  compsetservicesroutine=cplss, comp=connector, rc=rc)
188  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
189  line=__line__, &
190  file=__file__)) &
191  return ! bail out
192  call nuopc_compattributeset(connector, name="Verbosity", value="high", rc=rc)
193  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
194  line=__line__, &
195  file=__file__)) &
196  return ! bail out
197 
198  ! set the driver clock
199  call esmf_timeintervalset(timestep, m=15, rc=rc) ! 15 minute steps
200  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
201  line=__line__, &
202  file=__file__)) &
203  return ! bail out
204 
205  call esmf_timeset(starttime, yy=2018, mm=4, dd=14, h=21, m=0, rc=rc)
206  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
207  line=__line__, &
208  file=__file__)) &
209  return ! bail out
210 
211  call esmf_timeset(stoptime, yy=2018, mm=4, dd=14, h=21, m=15, rc=rc)
212  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
213  line=__line__, &
214  file=__file__)) &
215  return ! bail out
216 
217  internalclock = esmf_clockcreate(name="Application Clock", &
218  timestep=timestep, starttime=starttime, stoptime=stoptime, rc=rc)
219  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
220  line=__line__, &
221  file=__file__)) &
222  return ! bail out
223 
224  call esmf_gridcompset(driver, clock=internalclock, rc=rc)
225  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
226  line=__line__, &
227  file=__file__)) &
228  return ! bail out
229 
230  end subroutine
231 
232  !-----------------------------------------------------------------------------
233 
234  subroutine setrunsequence(driver, rc)
235  type(esmf_gridcomp) :: driver
236  integer, intent(out) :: rc
237 
238  ! local variables
239  integer :: localrc
240 
241  rc = esmf_success
242 
243 !ATM->MED
244 !OCN->MED
245 !MED
246 !MED->ATM
247 !MED->OCN
248 !ATM
249 !OCN
250 
251  ! Replace the default RunSequence with a customized sequence, one time slot
252  call nuopc_drivernewrunsequence(driver, slotcount=1, rc=rc)
253  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
254  line=__line__, &
255  file=__file__)) &
256  return ! bail out
257  call nuopc_driveraddrunelement(driver, slot=1, &
258  srccomplabel="ATM", dstcomplabel="MED", rc=rc)
259  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
260  line=__line__, &
261  file=__file__)) &
262  return ! bail out
263  call nuopc_driveraddrunelement(driver, slot=1, &
264  srccomplabel="OCN", dstcomplabel="MED", rc=rc)
265  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
266  line=__line__, &
267  file=__file__)) &
268  return ! bail out
269  call nuopc_driveraddrunelement(driver, slot=1, complabel="MED", rc=rc)
270  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
271  line=__line__, &
272  file=__file__)) &
273  return ! bail out
274  call nuopc_driveraddrunelement(driver, slot=1, &
275  srccomplabel="MED", dstcomplabel="ATM", rc=rc)
276  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
277  line=__line__, &
278  file=__file__)) &
279  return ! bail out
280  call nuopc_driveraddrunelement(driver, slot=1, &
281  srccomplabel="MED", dstcomplabel="OCN", rc=rc)
282  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
283  line=__line__, &
284  file=__file__)) &
285  return ! bail out
286  call nuopc_driveraddrunelement(driver, slot=1, complabel="ATM", rc=rc)
287  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
288  line=__line__, &
289  file=__file__)) &
290  return ! bail out
291  call nuopc_driveraddrunelement(driver, slot=1, complabel="OCN", rc=rc)
292  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
293  line=__line__, &
294  file=__file__)) &
295  return ! bail out
296 
297  end subroutine
298 
299  !-----------------------------------------------------------------------------
300 
301 end module
esm::setservices
subroutine, public setservices(driver, rc)
Definition: esm.F90:31
atm
Definition: atm.F90:1
esm::setrunsequence
subroutine setrunsequence(driver, rc)
Definition: esm.F90:235
esm::setmodelservices
subroutine setmodelservices(driver, rc)
Definition: esm.F90:62
med
Definition: med.F90:1
ocn
Definition: ocn.F90:1
esm
Definition: esm.F90:1
atm::setservices
subroutine, public setservices(model, rc)
Definition: atm.F90:24