! $Id: CoupledFlowApp.F90,v 1.27 2011/07/20 18:56:19 theurich Exp $ ! !------------------------------------------------------------------------------ !BOE ! ! \subsection{Main program source file for demo xdunexbeachapp.F90} ! ! !DESCRIPTION: ! ESMF Application Wrapper for Xdune-Xbeach. This file contains the ! main program, and creates a top level ESMF Gridded Component to contain ! all other Components. ! ! !EOE program ESMF_XduneXbeach ! ESMF Uses CamelCase notation, so let's stick to that for all coupler code.... ! ESMF module, defines all ESMF data types and methods use ESMF ! XDuneXbeach Component registration routines use XduneXbeachMod, only : XduneXbeach_register implicit none ! Configuration character(ESMF_MAXSTR) :: fname ! config file name type(ESMF_Config) :: cf ! the Config itself ! Component, and State type(ESMF_GridComp) :: XduneXbeachComp ! the coupled Component type(ESMF_State) :: XduneXbeachState ! the coupled State ! Clock, TimeInterval, and Times type(ESMF_Clock) :: clock type(ESMF_TimeInterval) :: timeStep type(ESMF_Time) :: startTime type(ESMF_Time) :: stopTime ! Grid and related variables ! We'll regrid to some common grid with constant dx,dy type(ESMF_Grid) :: grid integer :: i, j, imin_t, imax_t, jmin_t, jmax_t real(ESMF_KIND_R8) :: dx, dy real(ESMF_KIND_R8), pointer :: CoordX(:), CoordY(:) #define WRITECOORD__disable #ifdef WRITECOORD type(ESMF_Array) :: coordXa, coordYa #endif ! I wonder what this is for..... ! Namelist and related variables integer :: fileunit integer :: i_max, j_max real(ESMF_KIND_R8) :: x_min, x_max, y_min, y_max integer :: s_month, s_day, s_hour, s_min integer :: e_month, e_day, e_hour, e_min integer :: step_min ! Return codes for error checks integer :: rc, urc !------------------------------------------------------------------------------ !------------------------------------------------------------------------------ ! ESMF_Initialize !------------------------------------------------------------------------------ !------------------------------------------------------------------------------ ! !BOE ! ! !DESCRIPTION: ! \subsubsection{Example of Initializing the Framework} ! ! The first call to ESMF must be the initialize method. As part of ! initialization the default Calendar can be specified and options ! for logging can be set. ! Here we are setting the default Calendar to be Gregorian, and ! request default logging into seperate files for each PET: !EOE ! We need some kind of time loop for the combination of both models. ! This is it.... !BOC ! Initialize ESMF, set the default calendar and log type. call ESMF_Initialize(defaultCalKind=ESMF_CALKIND_GREGORIAN, rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & line=__LINE__, & file=__FILE__)) & call ESMF_Finalize(endflag=ESMF_END_ABORT) !EOC !------------------------------------------------------------------------------ !------------------------------------------------------------------------------ ! print *, "XDune XBeach Application Start" ! Read configuration cf = ESMF_ConfigCreate(rc=rc) ! Create the empty Config fname = "xdunexbeach.ini" ! Name the Resource File call ESMF_ConfigLoadFile(cf, fname, rc=rc) ! Load the Resource File if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & line=__LINE__, & file=__FILE__)) & call ESMF_Finalize(endflag=ESMF_END_ABORT) !------------------------------------------------------------------------------ !------------------------------------------------------------------------------ ! Create section !------------------------------------------------------------------------------ !------------------------------------------------------------------------------ ! !BOE ! Clreate the top level Gridded Component called "XDune-XBeachcoupler" !EOE !BOC ! Create the top level Gridded Component. XduneXbeachComp = ESMF_GridCompCreate(name="XDune-XBeach coupler", rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & line=__LINE__, & file=__FILE__)) & call ESMF_Finalize(endflag=ESMF_END_ABORT) !EOC ! print *, "Components created" !------------------------------------------------------------------------------ !------------------------------------------------------------------------------ ! Register section !------------------------------------------------------------------------------ !------------------------------------------------------------------------------ call ESMF_GridCompSetServices(XduneXbeachComp, XduneXbeach_register, & userRc=urc, rc=rc) ! print *, "XBeach-XDune Component SetServices finished, rc =", rc, urc if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & line=__LINE__, & file=__FILE__)) & call ESMF_Finalize(endflag=ESMF_END_ABORT) !------------------------------------------------------------------------------ !------------------------------------------------------------------------------ ! Create and initialize a clock, and a grid. !------------------------------------------------------------------------------ !------------------------------------------------------------------------------ !BOE ! ! !DESCRIPTION: ! \subsubsection{Example of Calendar and Clock Creation and Usage} ! ! The following piece of code provides an example of Clock creation used in ! the Demo. Note that the Gregorian calendar was set as the default in ! the ESMF\_Initialize() call above. As shown in this example, we first ! initialize a time interval (timestep) to 2 seconds: !EOE !BOC call ESMF_ConfigGetAttribute(cf, step_min, label='timestep [minutes]:', & default=1, rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & line=__LINE__, & file=__FILE__)) & call ESMF_Finalize(endflag=ESMF_END_ABORT) call ESMF_TimeIntervalSet(timeStep, m=step_min, rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & line=__LINE__, & file=__FILE__)) & call ESMF_Finalize(endflag=ESMF_END_ABORT) write(*,*) '[config] timestep [minutes]:', step_min !And then we set the start time and stop time to input values for the month, !day, and hour (assuming the year to be 1970): s_month = 1 s_day = 1 s_hour = 0 s_min = 0 call ESMF_TimeSet(startTime, yy=1970, mm=s_month, dd=s_day, & h=s_hour, m=s_min, s=0, rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & line=__LINE__, & file=__FILE__)) & call ESMF_Finalize(endflag=ESMF_END_ABORT) write(*,*) 'Start time set' e_month = 1 e_day = 1 e_hour = 0 ! Run for 2 minutes (for testing) call ESMF_ConfigGetAttribute(cf, e_min, label='stop time [minutes]:', & default=1, rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & line=__LINE__, & file=__FILE__)) & call ESMF_Finalize(endflag=ESMF_END_ABORT) write(*,*) '[config] stop time [minutes]:', e_min call ESMF_TimeSet(stopTime, yy=1970, mm=e_month, dd=e_day, & h=e_hour, m=e_min, s=0, rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & line=__LINE__, & file=__FILE__)) & call ESMF_Finalize(endflag=ESMF_END_ABORT) !With the time interval, start time, and stop time set above, the Clock can !now be created: clock = ESMF_ClockCreate(timeStep=timeStep, startTime=startTime, & stopTime=stopTime, rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & line=__LINE__, & file=__FILE__)) & call ESMF_Finalize(endflag=ESMF_END_ABORT) !Subsequent calls to ESMF_ClockAdvance with this clock will increment the !current time from the start time by the timestep. !EOC ! ! Create the Grid and attach it to the Component: ! !BOE ! ! !DESCRIPTION: ! \subsubsection{Example of Grid Creation} ! ! The following piece of code provides an example of Grid creation used in ! the Demo. The extents of the Grid were previously read in from an input ! file, but the rest of the Grid parameters are set here by default. The ! Grid spans the Application's PET list, while the type of the Grid is ! assumed to be horizontal and Cartesian x-y with an Arakawa C staggering. ! The Grid name is set to "demo grid": !EOE ! For now make an empty grid.... grid = ESMF_GridEmptyCreate(rc=urc) if (ESMF_LogFoundError(rcToCheck=urc, msg=ESMF_LOGERR_PASSTHRU, & line=__LINE__, & file=__FILE__)) & call ESMF_Finalize(endflag=ESMF_END_ABORT) !BOE ! Set the Combined Grid in the DuneBeach Component !BOC call ESMF_GridCompSet(XduneXbeachComp, grid=grid, rc=urc) if (ESMF_LogFoundError(rcToCheck=urc, msg=ESMF_LOGERR_PASSTHRU, & line=__LINE__, & file=__FILE__, & rcToReturn=rc)) return ! bail out !EOC !BOC !EOC !------------------------------------------------------------------------------ !------------------------------------------------------------------------------ !BOE ! ! !DESCRIPTION: ! \subsubsection{XduneXbeach State Creation} ! ! Create and initialize a dummy State to use for both import and export. ! This is where the combined information should resisde !EOE !------------------------------------------------------------------------------ !------------------------------------------------------------------------------ !BOC XduneXbeachState = ESMF_StateCreate(Name="XduneXbeach State", rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & line=__LINE__, & file=__FILE__)) & call ESMF_Finalize(endflag=ESMF_END_ABORT) !EOC !------------------------------------------------------------------------------ !------------------------------------------------------------------------------ !BOE ! ! !DESCRIPTION: ! \subsubsection{Example of Initialize, Run, and Finalize} ! ! Init, Run, and Finalize sections of the XDuneXBeach component !EOE !------------------------------------------------------------------------------ !------------------------------------------------------------------------------ !BOC ! print *, "Initialize Grid component" call ESMF_GridCompInitialize(XduneXbeachComp, & importState=XduneXbeachState, exportState=XduneXbeachState, & clock=clock, userRc=urc, rc=rc) ! print *, "XBeach-XDune Component Initialize finished, rc =", rc, urc if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & line=__LINE__, & file=__FILE__)) & call ESMF_Finalize(endflag=ESMF_END_ABORT) call ESMF_GridCompRun(XduneXbeachComp, & importState=XduneXbeachState, exportState=XduneXbeachState, & clock=clock, userRc=urc, rc=rc) ! print *, "XBeach-XDune Component Run finished, rc =", rc, urc if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & line=__LINE__, & file=__FILE__)) & call ESMF_Finalize(endflag=ESMF_END_ABORT) call ESMF_GridCompFinalize(XduneXbeachComp, & importState=XduneXbeachState, exportState=XduneXbeachState, & clock=clock, userRc=urc, rc=rc) ! print *, "XBeach-XDune Component Finalize finished, rc =", rc, urc if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & line=__LINE__, & file=__FILE__)) & call ESMF_Finalize(endflag=ESMF_END_ABORT) !EOC !------------------------------------------------------------------------------ !------------------------------------------------------------------------------ !BOE ! ! !DESCRIPTION: ! \subsubsection{Object Destruction} ! ! Near the end of the application, call object destroy methods to ! clean up the objects previously created: !EOE !------------------------------------------------------------------------------ !------------------------------------------------------------------------------ !BOC call ESMF_StateDestroy(XduneXbeachState, rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & line=__LINE__, & file=__FILE__)) & call ESMF_Finalize(endflag=ESMF_END_ABORT) call ESMF_GridCompDestroy(XduneXbeachComp, rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & line=__LINE__, & file=__FILE__)) & call ESMF_Finalize(endflag=ESMF_END_ABORT) call ESMF_GridDestroy(grid, rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & line=__LINE__, & file=__FILE__)) & call ESMF_Finalize(endflag=ESMF_END_ABORT) call ESMF_ClockDestroy(clock, rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & line=__LINE__, & file=__FILE__)) & call ESMF_Finalize(endflag=ESMF_END_ABORT) !EOC !------------------------------------------------------------------------------ !------------------------------------------------------------------------------ ! This output goes to stdout print *, "**********************************************************" print *, "SUCCESS! The XDuneXBeach ", & "ran to completion!" print *, "See the output files in the source directory for ", & "the generated data." print *, "**********************************************************" !BOE ! ! !DESCRIPTION: ! \subsubsection{Example of ESMF Finalize} ! !EOE !BOC !Call ESMF_Finalize at the end of an ESMF application: call ESMF_Finalize() !EOC end program ESMF_XduneXbeach