Skip to content

Commit

Permalink
Added stub mediator
Browse files Browse the repository at this point in the history
  • Loading branch information
rsdunlapiv committed Jan 9, 2018
1 parent 0cbb3c1 commit 6e1c3e0
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 2 deletions.
1 change: 1 addition & 0 deletions compset/lishydro.runconfig.irene.nldas2
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# optionally turn off a component (options are "yes" and "no")
lnd: yes
hyd: no
med: no

# PET lists - if not set, use all PETs
#pets_lnd: 0 23
Expand Down
3 changes: 2 additions & 1 deletion src/driver/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ DEP_SHRD_LIBS := $(DEP_SHRD_LIBS) $(addprefix -l, $(ESMF_DEP_SHRD_LIBS))


# -----------------------------------------------------------------------------
LISHydroApp: app.o driver.o
LISHydroApp: app.o driver.o mediator.o
$(ESMF_F90LINKER) $(ESMF_F90LINKOPTS) $(ESMF_F90LINKPATHS) $(ESMF_F90LINKRPATHS) -o $@ $^ $(ESMF_F90ESMFLINKLIBS) $(DEP_LINK_OBJS) $(DEP_SHRD_PATH) $(DEP_SHRD_LIBS)

# module dependencies:
app.o: driver.o
driver.o: mediator.o

# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
Expand Down
10 changes: 9 additions & 1 deletion src/driver/driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module ESM

use LIS_NUOPC, only: lndSS => SetServices
use WRFHydro_NUOPC, only: hydSS => SetServices
!use MED, only: medSS => SetServices
use Mediator, only: medSS => SetServices

use NUOPC_Connector, only: cplSS => SetServices

Expand Down Expand Up @@ -242,6 +242,14 @@ subroutine SetModelServices(driver, rc)

endif !enabledHyd

! add Mediator component
call NUOPC_DriverAddComp(driver, "MED", medSS, comp=child, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out


! read clock set up from config
call getTimeFromConfig(config, "start_time:", startTime, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
Expand Down
134 changes: 134 additions & 0 deletions src/driver/mediator.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
module Mediator

!-----------------------------------------------------------------------------
! Mediator Component.
!-----------------------------------------------------------------------------

use ESMF
use NUOPC
use NUOPC_Mediator, only: &
model_routine_SS => SetServices, &
model_label_Advance => label_Advance

implicit none

private

public SetServices

!-----------------------------------------------------------------------------
contains
!-----------------------------------------------------------------------------

subroutine SetServices(mediator, rc)
type(ESMF_GridComp) :: mediator
integer, intent(out) :: rc

rc = ESMF_SUCCESS

! the NUOPC model component will register the generic methods
call NUOPC_CompDerive(mediator, model_routine_SS, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out

! set entry point for methods that require specific implementation
call NUOPC_CompSetEntryPoint(mediator, ESMF_METHOD_INITIALIZE, &
phaseLabelList=(/"IPDv00p1"/), userRoutine=InitializeP1, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call NUOPC_CompSetEntryPoint(mediator, ESMF_METHOD_INITIALIZE, &
phaseLabelList=(/"IPDv00p2"/), userRoutine=InitializeP2, 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(mediator, specLabel=model_label_Advance, &
specRoutine=MediatorAdvance, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out

end subroutine

!-----------------------------------------------------------------------------

subroutine InitializeP1(mediator, importState, exportState, clock, rc)
type(ESMF_GridComp) :: mediator
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc

rc = ESMF_SUCCESS

end subroutine

!-----------------------------------------------------------------------------

subroutine InitializeP2(mediator, importState, exportState, clock, rc)
type(ESMF_GridComp) :: mediator
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc

rc = ESMF_SUCCESS

end subroutine

!-----------------------------------------------------------------------------

subroutine MediatorAdvance(mediator, rc)
type(ESMF_GridComp) :: mediator
integer, intent(out) :: rc

! local variables
type(ESMF_Clock) :: clock
type(ESMF_State) :: importState, exportState

rc = ESMF_SUCCESS

! query the Component for its clock, importState and exportState
call ESMF_GridCompGet(mediator, clock=clock, importState=importState, &
exportState=exportState, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out

! HERE THE MEDIATOR does the mediation of Fields that come in on the
! importState with a timestamp consistent to the currTime of the
! mediators Clock.

! The Mediator uses the data on the import Fields to update the data
! held by Fields in the exportState.

! After this routine returns the generic Mediator will correctly
! timestamp the export Fields and update the Mediator Clock to:
!
! currTime -> currTime + timeStep
!
! Where the timeStep is equal to the parent timeStep.

call ESMF_ClockPrint(clock, options="currTime", &
preString="-------->MED Advance() mediating for: ", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out

call ESMF_ClockPrint(clock, options="stopTime", &
preString="----------------> model time step to: ", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out

end subroutine

end module Mediator

0 comments on commit 6e1c3e0

Please sign in to comment.