! $Id$ ! ! Template code for a child Grid Component, which has no subcomponents ! below it. This is where the bulk of the computation is expected to be ! placed. There are three phases where code is run: Initialization, ! the Run routine, and Finalization. Init and Finalize are expected to ! be called only once. Run may be called once or many times from the ! higher level components in the application. Data which is needed from ! other components or is produced here for other components must be ! placed in an ESMF State object. !------------------------------------------------------------------------- !------------------------------------------------------------------------- !BOP ! ! !DESCRIPTION: ! A Template for a User-Written Gridded Component. ! ! !\begin{verbatim} module xbeachgridcomponent_module ! ESMF Framework module use esmf use libxbeach_module implicit none private public UserGrid_SetServices contains subroutine UserGrid_SetServices(gcomp, rc) type(ESMF_GridComp) :: gcomp integer :: rc call ESMF_GridCompSetEntryPoint(gcomp, ESMF_SETINIT, my_init, rc=rc) call ESMF_GridCompSetEntryPoint(gcomp, ESMF_SETRUN, my_run, rc=rc) call ESMF_GridCompSetEntryPoint(gcomp, ESMF_SETFINAL, my_final, rc=rc) end subroutine UserGrid_SetServices subroutine my_init(gcomp, importState, exportState, externalclock, rc) type(ESMF_GridComp) :: gcomp type(ESMF_State) :: importState type(ESMF_State) :: exportState type(ESMF_Clock) :: externalclock integer :: rc character(ESMF_MAXSTR) :: statename, bundlename type(ESMF_Grid) :: grid type(ESMF_FieldBundle) :: bundle type(ESMF_Field) :: field(1) type(ESMF_ArraySpec) :: arrayspec type(ESMF_Array) :: array type(ESMF_DistGrid) :: distgrid real*8, dimension(:,:), pointer :: farray2d integer :: nx, ny rc = init() call ESMF_GridCompPrint(gcomp, rc=rc) ! Create the grid rc = getintparameter("nx", nx, 2) rc = getintparameter("ny", ny, 2) grid = ESMF_GridCreateShapeTile(minIndex=(/1,1/), maxIndex=(/nx,ny/), name="xbeachgrid", rc=rc) ! Set the coordinates ! get the distgrid (required to store arrays) call ESMF_GridGet(grid=grid, distgrid=distgrid, rc=rc) statename = "Coast" exportState = ESMF_StateCreate(statename, statetype=ESMF_STATE_EXPORT, rc=rc) bundlename = "Bathymetry" bundle = ESMF_FieldBundleCreate(name=bundlename, rc=rc) call ESMF_ArraySpecSet(arrayspec, 2, ESMF_TYPEKIND_R8, rc=rc) array = ESMF_ArrayCreate(s%zb, distgrid=distgrid) field(1) = ESMF_FieldCreate(grid, array=array, name="zb", rc=rc) call ESMF_FieldBundleAdd(bundle, field(1), rc) call ESMF_StateAdd(exportState, bundle, rc) call ESMF_StatePrint(exportstate, rc=rc) call ESMF_LogWrite("XBeach initialize routine called", ESMF_LOG_INFO) if (rc .eq. 0) then rc = ESMF_SUCCESS else rc = ESMF_FAILURE end if end subroutine my_init subroutine my_run(gcomp, importState, exportState, externalclock, rc) type(ESMF_GridComp) :: gcomp type(ESMF_State) :: importState type(ESMF_State) :: exportState type(ESMF_Clock) :: externalclock integer :: rc type(ESMF_TimeInterval) :: timeStep type(ESMF_TimeInterval) :: currSimTime integer :: tint, t real*8 :: part ! Assume 0 == tstart ! Calculate until clock current + step call ESMF_ClockGet(externalclock, timeStep=timeStep, currSimTime=currSimTime, rc=rc) call ESMF_TimeIntervalGet(timeStep, s=tint, rc=rc) call ESMF_TimeIntervalGet(currSimTime, s=t, rc=rc) ! Setting tnext to external tnext so it stops on tnext rc = setdoubleparameter("tnext", real(t+tint,8), 5) ! explicit scheme, so loop until t reaches tnext rc = getdoubleparameter('t', part, 1) do while(part .lt. tint+t) rc = executestep() rc = getdoubleparameter("t", part, 1) end do ! Current t shouls now be equal to t+tint (not true if outputs are not a multiple of external tstep.... ! write(*,*) 'These should be equal', par%t, t+tint call ESMF_LogWrite("XBeach run routine called", ESMF_LOG_INFO) if (rc .eq. 0) then rc = ESMF_SUCCESS else rc = ESMF_FAILURE end if end subroutine my_run subroutine my_final(gcomp, importState, exportState, externalclock, rc) type(ESMF_GridComp) :: gcomp type(ESMF_State) :: importState type(ESMF_State) :: exportState type(ESMF_Clock) :: externalclock integer :: rc rc = finalize() call ESMF_LogWrite("XBeach finalize routine called", ESMF_LOG_INFO) if (rc .eq. 0) then rc = ESMF_SUCCESS else rc = ESMF_FAILURE end if end subroutine my_final end module Xbeachgridcomponent_module !\end{verbatim}