@@ -204,6 +204,140 @@ subroutine SetServices ( GC, RC )
204204 RESTART = MAPL_RestartRequired ,&
205205 _RC )
206206
207+ ! !!!!!!!!!!!!!!!
208+ ! parameters in restart, for rivers
209+ ! !!!!!!!!!!!!!
210+
211+ call MAPL_AddInternalSpec(GC ,&
212+ LONG_NAME = ' K_parameter_for_local_streams' ,&
213+ UNITS = ' 1' ,&
214+ SHORT_NAME = ' KSTR' ,&
215+ DIMS = MAPL_DimsTileOnly ,&
216+ VLOCATION = MAPL_VLocationNone ,&
217+ RESTART = MAPL_RestartRequired ,&
218+ _RC )
219+
220+ call MAPL_AddInternalSpec(GC ,&
221+ LONG_NAME = ' K_parameter_for_main_rivers' ,&
222+ UNITS = ' 1' ,&
223+ SHORT_NAME = ' K' ,&
224+ DIMS = MAPL_DimsTileOnly ,&
225+ VLOCATION = MAPL_VLocationNone ,&
226+ RESTART = MAPL_RestartRequired ,&
227+ _RC )
228+
229+ call MAPL_AddInternalSpec(GC ,&
230+ LONG_NAME = ' main_river_length_scale' ,&
231+ UNITS = ' m' ,&
232+ SHORT_NAME = ' LENGSC' ,&
233+ DIMS = MAPL_DimsTileOnly ,&
234+ VLOCATION = MAPL_VLocationNone ,&
235+ RESTART = MAPL_RestartRequired ,&
236+ _RC )
237+
238+ call MAPL_AddInternalSpec(GC ,&
239+ LONG_NAME = ' local_streams_length_scale' ,&
240+ UNITS = ' m' ,&
241+ SHORT_NAME = ' LSTR' ,&
242+ DIMS = MAPL_DimsTileOnly ,&
243+ VLOCATION = MAPL_VLocationNone ,&
244+ RESTART = MAPL_RestartRequired ,&
245+ _RC )
246+
247+ call MAPL_AddInternalSpec(GC ,&
248+ LONG_NAME = ' climatology_of_catchment_inflow' ,&
249+ UNITS = ' m+3 s-1' ,&
250+ SHORT_NAME = ' QIN_CLMT' ,&
251+ DIMS = MAPL_DimsTileOnly ,&
252+ VLOCATION = MAPL_VLocationNone ,&
253+ RESTART = MAPL_RestartRequired ,&
254+ _RC )
255+
256+ call MAPL_AddInternalSpec(GC ,&
257+ LONG_NAME = ' climatology_of_catchment_outflow' ,&
258+ UNITS = ' m+3 s-1' ,&
259+ SHORT_NAME = ' QRI_CLMT' ,&
260+ DIMS = MAPL_DimsTileOnly ,&
261+ VLOCATION = MAPL_VLocationNone ,&
262+ RESTART = MAPL_RestartRequired ,&
263+ _RC )
264+
265+ call MAPL_AddInternalSpec(GC ,&
266+ LONG_NAME = ' climatology_of_catchment_stream_flow' ,&
267+ UNITS = ' m+3 s-1' ,&
268+ SHORT_NAME = ' QSTR_CLMT' ,&
269+ DIMS = MAPL_DimsTileOnly ,&
270+ VLOCATION = MAPL_VLocationNone ,&
271+ RESTART = MAPL_RestartRequired ,&
272+ _RC )
273+
274+ call MAPL_AddInternalSpec(GC ,&
275+ LONG_NAME = ' downstream_catchment_id' ,&
276+ UNITS = ' 1' ,&
277+ SHORT_NAME = ' DOWNID' ,&
278+ DIMS = MAPL_DimsTileOnly ,&
279+ VLOCATION = MAPL_VLocationNone ,&
280+ RESTART = MAPL_RestartRequired ,&
281+ _RC )
282+
283+ call MAPL_AddInternalSpec(GC ,&
284+ LONG_NAME = ' catchment_area' ,&
285+ UNITS = ' m+2' ,&
286+ SHORT_NAME = ' AREA_CATCH' ,&
287+ DIMS = MAPL_DimsTileOnly ,&
288+ VLOCATION = MAPL_VLocationNone ,&
289+ RESTART = MAPL_RestartRequired ,&
290+ _RC )
291+
292+ ! !!!!!!!!!!!!!!!
293+ ! parameters in restart, for reservoirs
294+ ! !!!!!!!!!!!!!
295+
296+ call MAPL_AddInternalSpec(GC ,&
297+ LONG_NAME = ' active_reservoirs' ,&
298+ UNITS = ' 1' ,&
299+ SHORT_NAME = ' ACTIVE_RES' ,&
300+ DIMS = MAPL_DimsTileOnly ,&
301+ VLOCATION = MAPL_VLocationNone ,&
302+ RESTART = MAPL_RestartRequired ,&
303+ _RC )
304+
305+ call MAPL_AddInternalSpec(GC ,&
306+ LONG_NAME = ' type_of_reservoirs' ,&
307+ UNITS = ' 1' ,&
308+ SHORT_NAME = ' TYPE_RES' ,&
309+ DIMS = MAPL_DimsTileOnly ,&
310+ VLOCATION = MAPL_VLocationNone ,&
311+ RESTART = MAPL_RestartRequired ,&
312+ _RC )
313+
314+ call MAPL_AddInternalSpec(GC ,&
315+ LONG_NAME = ' max_capacity_of_reservoirs' ,&
316+ UNITS = ' m+3' ,&
317+ SHORT_NAME = ' CAP_RES' ,&
318+ DIMS = MAPL_DimsTileOnly ,&
319+ VLOCATION = MAPL_VLocationNone ,&
320+ RESTART = MAPL_RestartRequired ,&
321+ _RC )
322+
323+ call MAPL_AddInternalSpec(GC ,&
324+ LONG_NAME = ' length_scale_of_reservoirs' ,&
325+ UNITS = ' m' ,&
326+ SHORT_NAME = ' WID_RES' ,&
327+ DIMS = MAPL_DimsTileOnly ,&
328+ VLOCATION = MAPL_VLocationNone ,&
329+ RESTART = MAPL_RestartRequired ,&
330+ _RC )
331+
332+ call MAPL_AddInternalSpec(GC ,&
333+ LONG_NAME = ' flood_control_flag_of_reservoirs' ,&
334+ UNITS = ' 1' ,&
335+ SHORT_NAME = ' FLD_RES' ,&
336+ DIMS = MAPL_DimsTileOnly ,&
337+ VLOCATION = MAPL_VLocationNone ,&
338+ RESTART = MAPL_RestartRequired ,&
339+ _RC )
340+
207341! !!!!!!!!!!!!!!!
208342! Export
209343! !!!!!!!!!!!!!!
@@ -316,7 +450,7 @@ subroutine INITIALIZE (GC,IMPORT, EXPORT, CLOCK, RC )
316450 type (ESMF_Grid) :: tileGrid
317451 type (ESMF_Grid) :: pfaf_tilegrid, pfaf_grid
318452 character (len= ESMF_MAXSTR) :: SURFRC
319- type (ESMF_Config) :: SCF
453+ type (ESMF_Config) :: SCF, CF
320454
321455 type (MAPL_MetaComp), pointer :: MAPL
322456 type (MAPL_LocStream) :: locstream, pfaf_LocStream
@@ -327,6 +461,16 @@ subroutine INITIALIZE (GC,IMPORT, EXPORT, CLOCK, RC )
327461 type (ESMF_Grid) :: agrid
328462 type (ESMF_DELayout) :: layout
329463 type (ESMF_DistGrid) :: dist_grid
464+ type (ESMF_State ) :: INTERNAL
465+ real , dimension (:), pointer :: KSTR_RS
466+ real , dimension (:), pointer :: K_RS
467+ real , dimension (:), pointer :: LENGSC_RS
468+ real , dimension (:), pointer :: LSTR_RS
469+ real , dimension (:), pointer :: QIN_CLMT_RS
470+ real , dimension (:), pointer :: QRI_CLMT_RS
471+ real , dimension (:), pointer :: QSTR_CLMT_RS
472+ real , dimension (:), pointer :: DOWNID_RS
473+ real , dimension (:), pointer :: AREA_CATCH_RS
330474
331475 integer , pointer :: ims(:) = > NULL ()
332476
@@ -345,6 +489,9 @@ subroutine INITIALIZE (GC,IMPORT, EXPORT, CLOCK, RC )
345489 integer :: j,nt_local, mpierr
346490 logical :: use_res
347491
492+ real ,dimension (:), pointer :: cap_res_glob(:),wid_res_glob(:)
493+ integer ,dimension (:), pointer :: active_res_glob(:),type_res_glob(:),fld_res_glob(:)
494+
348495 ! ------------------
349496 ! begin
350497
@@ -410,113 +557,17 @@ subroutine INITIALIZE (GC,IMPORT, EXPORT, CLOCK, RC )
410557 call MAPL_GetResource (SCF, ROUTE_DT, label= ' RRM_DT:' , DEFAULT= 3600 , RC= STATUS )
411558 route% route_dt = ROUTE_DT
412559
413- call MAPL_GetResource (MAPL, RIVER_INPUT_FILE, label = ' RIVER_INPUT_FILE:' , default = ' ../input/river_input.nc' , RC= STATUS )
414- if (MAPL_AM_I_Root()) then
415- call formatter% open (RIVER_INPUT_FILE, PFIO_READ, _RC)
416- endif
417- allocate (tmp_real(n_pfaf_g))
418- allocate (tmp_int(n_pfaf_g))
419-
420- ! read areacat
421- if (MAPL_AM_I_Root()) then
422- call formatter% get_var(' area_catch' , tmp_real(:), _RC)
423- endif
424- call MAPL_CommsBcast(layout, tmp_real, n_pfaf_g, MAPL_Root, status)
425- allocate (areacat_glob(n_pfaf_g))
426- tmp_real= tmp_real* 1.e6
427- areacat_glob = tmp_real
428- allocate (route% areacat(n_pfaf_local), source = tmp_real(minCatch:maxCatch))
429-
430- ! read lengsc
431- if (MAPL_AM_I_Root()) then
432- call formatter% get_var(' lengsc' , tmp_real(:), _RC)
433- endif
434- call MAPL_CommsBcast(layout, tmp_real, n_pfaf_g, MAPL_Root, status)
435- allocate (route% lengsc(n_pfaf_local), source = tmp_real(minCatch:maxCatch))
436- route% lengsc= route% lengsc* 1.e3
437-
438- ! read downid
439- if (MAPL_AM_I_Root()) then
440- call formatter% get_var(' downid' , tmp_int(:), _RC)
441- endif
442- call MAPL_CommsBcast(layout, tmp_int, n_pfaf_g, MAPL_Root, status)
443- allocate (route% downid(n_pfaf_local), source = tmp_int(minCatch:maxCatch))
444-
445- ! read lstr
446- if (MAPL_AM_I_Root()) then
447- call formatter% get_var(' lstr' , tmp_real(:), _RC)
448- endif
449- call MAPL_CommsBcast(layout, tmp_real, n_pfaf_g, MAPL_Root, status)
450- allocate (route% lstr(n_pfaf_local), source = tmp_real(minCatch:maxCatch))
451- route% lstr = route% lstr* 1.e3
452-
453- ! read K
454- if (MAPL_AM_I_Root()) then
455- call formatter% get_var(' K' , tmp_real(:), _RC)
456- endif
457- call MAPL_CommsBcast(layout, tmp_real, n_pfaf_g, MAPL_Root, status)
458- allocate (route% K(n_pfaf_local), source = tmp_real(minCatch:maxCatch))
459-
460- ! read Kstr
461- if (MAPL_AM_I_Root()) then
462- call formatter% get_var(' Kstr' , tmp_real(:), _RC)
463- endif
464- call MAPL_CommsBcast(layout, tmp_real, n_pfaf_g, MAPL_Root, status)
465- allocate (route% Kstr(n_pfaf_local), source = tmp_real(minCatch:maxCatch))
466-
467- ! read qri_clmt
468- if (MAPL_AM_I_Root()) then
469- call formatter% get_var(' qri_clmt' , tmp_real(:), _RC)
470- endif
471- call MAPL_CommsBcast(layout, tmp_real, n_pfaf_g, MAPL_Root, status)
472- allocate (route% qri_clmt(n_pfaf_local), source = tmp_real(minCatch:maxCatch))
473-
474- ! read qin_clmt
475- if (MAPL_AM_I_Root()) then
476- call formatter% get_var(' qin_clmt' , tmp_real(:), _RC)
477- endif
478- call MAPL_CommsBcast(layout, tmp_real, n_pfaf_g, MAPL_Root, status)
479- allocate (route% qin_clmt(n_pfaf_local), source = tmp_real(minCatch:maxCatch))
480-
481- ! read qstr_clmt
482- if (MAPL_AM_I_Root()) then
483- call formatter% get_var(' qstr_clmt' , tmp_real(:), _RC)
484- endif
485- call MAPL_CommsBcast(layout, tmp_real, n_pfaf_g, MAPL_Root, status)
486- allocate (route% qstr_clmt(n_pfaf_local), source = tmp_real(minCatch:maxCatch))
487-
488- deallocate (tmp_real, tmp_int)
489-
490- if (MAPL_AM_I_Root()) then
491- call formatter% close ()
492- endif
493-
494560 allocate (route% runoff_acc(nt_local), source = 0 .)
495561
496-
497- ! Initial reservoir module
498- route% reservoir = Reservoir(layout, trim (RIVER_INPUT_FILE), N_pfaf_g,n_pfaf_local, minCatch,maxCatch,use_res, _RC)
499-
500- if (mapl_am_I_root()) print * ," reservoir init success"
501-
502562 pfaf_grid = create_pfaf_grid(_RC)
503563 call MAPL_LocstreamCreate(pfaf_Locstream, pfaf_Grid, _RC)
504564 call MAPL_LocStreamGet(pfaf_LocStream, TILEGRID= pfaf_tilegrid, _RC)
505-
506- call MAPL_GetResource (MAPL, TILE_PFAF_File, label = ' TILE_PFAF_FILE:' , default = ' ../input/tile_pfaf.nc4' , RC= STATUS )
507-
508- call create_mapping_handler(trim (TILE_PFAF_File), tilegrid, pfaf_tilegrid, _RC)
509-
510565 call MAPL% grid% set(pfaf_grid, _RC)
511-
512566 call ESMF_GridCompSet(gc, grid= pfaf_grid, RC= status)
513567 VERIFY_(STATUS)
514-
515568 call MAPL_set(MAPL, locstream = pfaf_locstream, rc= status)
516569 VERIFY_(STATUS)
517570
518- call setup_exchange_water(pfaf_tilegrid, _RC)
519-
520571 call ESMF_TimeIntervalSet(CollectWater_DT, s= ROUTE_DT, rc= status)
521572 VERIFY_(status)
522573 call ESMF_ClockGet(clock, currTime= CurrentTime, timeStep= ModelTimeStep, rc= status)
@@ -531,10 +582,47 @@ subroutine INITIALIZE (GC,IMPORT, EXPORT, CLOCK, RC )
531582 )
532583 VERIFY_(status)
533584
534- deallocate (areacat_glob)
535585 deallocate (ims)
536586 call MAPL_GenericInitialize ( GC, import, export, clock, rc= status )
537587 VERIFY_(STATUS)
588+
589+ call ESMF_UserCompGetInternalState ( GC, ' RiverRoute_state' ,wrap,status )
590+ VERIFY_(STATUS)
591+ call ESMF_GridCompGet(GC, name= COMP_NAME, CONFIG= CF, RC= STATUS )
592+ VERIFY_(STATUS)
593+ call MAPL_GetObjectFromGC(GC, MAPL, STATUS)
594+ VERIFY_(STATUS)
595+ call MAPL_Get(MAPL, INTERNAL_ESMF_STATE= INTERNAL, _RC)
596+ call MAPL_GetPointer(INTERNAL, KSTR_RS, ' KSTR' , _RC )
597+ call MAPL_GetPointer(INTERNAL, K_RS, ' K' , _RC )
598+ call MAPL_GetPointer(INTERNAL, LENGSC_RS, ' LENGSC' , _RC )
599+ call MAPL_GetPointer(INTERNAL, LSTR_RS, ' LSTR' , _RC )
600+ call MAPL_GetPointer(INTERNAL, QIN_CLMT_RS, ' QIN_CLMT' , _RC )
601+ call MAPL_GetPointer(INTERNAL, QRI_CLMT_RS, ' QRI_CLMT' , _RC )
602+ call MAPL_GetPointer(INTERNAL, QSTR_CLMT_RS, ' QSTR_CLMT' , _RC )
603+ call MAPL_GetPointer(INTERNAL, DOWNID_RS, ' DOWNID' , _RC )
604+ call MAPL_GetPointer(INTERNAL, AREA_CATCH_RS, ' AREA_CATCH' , _RC )
605+
606+ allocate (route% areacat(n_pfaf_local), source = AREA_CATCH_RS)
607+ allocate (route% lengsc(n_pfaf_local), source = LENGSC_RS)
608+ allocate (route% downid(n_pfaf_local), source = int (DOWNID_RS))
609+ allocate (route% lstr(n_pfaf_local), source = LSTR_RS)
610+ allocate (route% K(n_pfaf_local), source = K_RS)
611+ allocate (route% Kstr(n_pfaf_local), source = KSTR_RS)
612+ allocate (route% qri_clmt(n_pfaf_local), source = QRI_CLMT_RS)
613+ allocate (route% qin_clmt(n_pfaf_local), source = QIN_CLMT_RS)
614+ allocate (route% qstr_clmt(n_pfaf_local), source = QSTR_CLMT_RS)
615+ ! Initial reservoir module
616+ route% reservoir = Reservoir(GC, use_res, _RC)
617+ if (mapl_am_I_root()) print * ," reservoir init success"
618+
619+ allocate (areacat_glob(n_pfaf_g))
620+ call ESMFL_FCollect(pfaf_tilegrid, areacat_glob, AREA_CATCH_RS, RC= STATUS)
621+ call MAPL_GetResource (MAPL, TILE_PFAF_File, label = ' TILE_PFAF_FILE:' , default = ' ../input/tile_pfaf.nc4' , RC= STATUS )
622+ call create_mapping_handler(trim (TILE_PFAF_File), tilegrid, pfaf_tilegrid, _RC)
623+ call setup_exchange_water(pfaf_tilegrid, _RC)
624+ deallocate (areacat_glob)
625+
538626 RETURN_(ESMF_SUCCESS)
539627
540628 contains
@@ -824,6 +912,7 @@ subroutine RUN (GC,IMPORT, EXPORT, CLOCK, RC )
824912 real , dimension (:), pointer :: WSTREAM
825913 real , dimension (:), pointer :: WRIVER
826914 real , dimension (:), pointer :: WRES
915+
827916 real , dimension (:), pointer :: LRIVERMOUTH
828917 real , dimension (:), pointer :: ORIVERMOUTH
829918
@@ -902,7 +991,7 @@ subroutine RUN (GC,IMPORT, EXPORT, CLOCK, RC )
902991 call MAPL_GetPointer(INTERNAL, WRIVER, ' WRIVER' , _RC )
903992 call MAPL_GetPointer(INTERNAL, WSTREAM,' WSTREAM' , _RC)
904993 call MAPL_GetPointer(INTERNAL, WRES, ' WRES' , _RC)
905-
994+
906995! export
907996 call MAPL_GetPointer(EXPORT, QSFLOW, ' QSFLOW' , _RC)
908997 call MAPL_GetPointer(EXPORT, QINFLOW, ' QINFLOW' , _RC)
0 commit comments