<p><b>duda</b> 2010-03-16 18:54:38 -0600 (Tue, 16 Mar 2010)</p><p>BRANCH COMMIT<br>
<br>
Add directory for CAM-MPAS interface implementation, which will<br>
be used in place of the normal driver and sub-driver when MPAS<br>
is driven by CAM.<br>
<br>
test_driver.F contains a stand-alone driver program for testing<br>
that the calls to CAM-MPAS interface routines work.<br>
<br>
module_mpas_cam_interface.F will contain the implementation of<br>
the interface routines. Currently, all interface routines are<br>
defined in module_mpas_cam_interface.F, though some remain to be<br>
implemented (namely, CAM_TO_MPAS, MPAS_TO_CAM, CAM_INIDAT_TO_MPAS,<br>
and CAM_RESTART_TO_MPAS).<br>
<br>
<br>
A    driver_cam_interface<br>
A    driver_cam_interface/module_mpas_cam_interface.F<br>
A    driver_cam_interface/Makefile<br>
A    driver_cam_interface/module_subdriver.F<br>
A    driver_cam_interface/test_driver.F<br>
</p><hr noshade><pre><font color="gray">Added: branches/mpas_cam_coupling/src/driver_cam_interface/Makefile
===================================================================
--- branches/mpas_cam_coupling/src/driver_cam_interface/Makefile                                (rev 0)
+++ branches/mpas_cam_coupling/src/driver_cam_interface/Makefile        2010-03-17 00:54:38 UTC (rev 142)
@@ -0,0 +1,22 @@
+.SUFFIXES: .F .o
+
+OBJS = module_subdriver.F \
+       module_mpas_cam_interface.o \
+       test_driver.o
+
+all: $(OBJS)
+
+module_subdriver.o: 
+
+module_mpas_cam_interface.o: module_subdriver.o
+
+test_driver.o: module_mpas_cam_interface.o
+
+clean:
+        $(RM) *.o *.mod
+
+.F.o:
+        $(RM) $@ $*.mod
+        $(CPP) $(CPPFLAGS) $(CPPINCLUDES) $&lt; &gt; $*.f90
+        $(FC) $(FFLAGS) -c $*.f90 $(FCINCLUDES) -I../framework -I../core_$(CORE)
+        $(RM) $*.f90

Added: branches/mpas_cam_coupling/src/driver_cam_interface/module_mpas_cam_interface.F
===================================================================
--- branches/mpas_cam_coupling/src/driver_cam_interface/module_mpas_cam_interface.F                                (rev 0)
+++ branches/mpas_cam_coupling/src/driver_cam_interface/module_mpas_cam_interface.F        2010-03-17 00:54:38 UTC (rev 142)
@@ -0,0 +1,227 @@
+module mpas_cam_interface
+
+   use grid_types
+   use configure
+   use io_input
+   use dmpar
+   use subdriver
+
+
+   type (dm_info), pointer :: dminfo
+   type (domain_type), pointer :: domain
+   real (kind=RKIND) :: dt
+   integer :: itimestep
+
+   interface mpas_setup_test_case
+      subroutine mpas_setup_test_case(domain)
+         use grid_types
+         type (domain_type), intent(inout) :: domain
+      end subroutine mpas_setup_test_case
+   end interface mpas_setup_test_case
+
+
+   contains
+
+
+   subroutine mpas_init1(mpi_comm)
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! SUBROUTINE MPAS_INIT1
+   !
+   ! Initializes the MPAS software infrastructure, reads run-time configuration
+   !    information, reads grid information from an MPAS grid file, and allocates
+   !    storage for fields to be provided by CAM through either 
+   !    cam_inidat_to_mpas() or cam_restart_to_mpas().
+   !
+   ! Input: mpi_comm - an MPI communicator supplied by CAM to be used by MPAS
+   !
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   
+      implicit none
+
+      integer, intent(in) :: mpi_comm
+   
+      write(0,*) 'Called MPAS_INIT1'
+
+      allocate(dminfo)
+      call dmpar_init(dminfo, mpi_comm)
+
+      call read_namelist(dminfo)
+
+      call allocate_domain(domain, dminfo)
+
+! NOTE: Really, we only want to read in the grid information, since any state 
+! variables will be overwritten by cam_inidat_to_mpas() or cam_restart_to_mpas()
+      call input_state_for_domain(domain)
+   
+   end subroutine mpas_init1
+   
+   
+   subroutine cam_inidat_to_mpas()
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! SUBROUTINE MPAS_INIDAT_TO_MPAS
+   !
+   ! Input: Numcols - number of columns/cells
+   !        MaxEdges - maximum number of edges per cell
+   !        Plev - number of vertical levels
+   !        Pcnst - number of tracers
+   !        Pref - reference surface pressure (Pa)
+   !        Ptop - pressure at top of model (Pa)
+   !        Ae, Be - A and B arrays at vertical edges
+   !        Ac, Bc - A and B arrays at vertical centers
+   !        Psd - dry surface pressure (Pa)
+   !        Phis - surface geopotential (m^2/s^2)
+   !        T - temperature (K)
+   !        U - normal velocity at edges (m/s)
+   !        Tracer - tracer mixing ratios (kg/kg)
+   !
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   
+      implicit none
+   
+      write(0,*) 'Called CAM_INIDAT_TO_MPAS'
+
+! TEMPORARY: until we are actually given fields, just call one of the test case
+! setup routines to initialize the MPAS prognostic fields
+      call mpas_setup_test_case(domain)
+   
+   end subroutine cam_inidat_to_mpas
+   
+   
+   subroutine cam_restart_to_mpas()
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! SUBROUTINE MPAS_RESTART_TO_MPAS
+   !
+   ! Input: Numcols - number of columns/cells
+   !        MaxEdges - maximum number of edges per cell
+   !        Plev - number of vertical levels
+   !        Pcnst - number of tracers
+   !        Psd - dry surface pressure (Pa)
+   !        Phis - surface geopotential (m^2/s^2)
+   !        T - temperature (K)
+   !        U - normal velocity at edges (m/s)
+   !        W - vertical velocity (Pa/s)
+   !        Tracer - tracer mixing ratios (kg/kg)
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   
+      implicit none
+   
+      write(0,*) 'Called CAM_RESTART_TO_MPAS'
+
+! TEMPORARY: until we are actually given fields, just call one of the test case
+! setup routines to initialize the MPAS prognostic fields
+      call mpas_setup_test_case(domain)
+   
+   end subroutine cam_restart_to_mpas
+   
+   
+   subroutine mpas_init2()
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! SUBROUTINE MPAS_INIT2
+   !
+   ! Calls the core-specific (most likely the hydrostatic atmosphere core) 
+   !    initialization routine mpas_init() after initial fields have been provided
+   !    through a call to either cam_inidat_to_mpas() or cam_restart_to_mpas().
+   !
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   
+      implicit none
+
+      type (block_type), pointer :: block_ptr
+
+      dt = config_dt
+
+      ! Compute diagnostic fields needed in solve loop, and initialize
+      !    simulation time to 0 for all blocks
+      block_ptr =&gt; domain % blocklist
+      do while (associated(block_ptr))
+         call mpas_init(block_ptr, block_ptr % mesh, dt)
+         block_ptr =&gt; block_ptr % next
+      end do
+   
+   end subroutine mpas_init2
+   
+   
+   subroutine mpas_to_cam()
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! SUBROUTINE MPAS_TO_CAM
+   !
+   ! Input: Numcols - number of columns/cells
+   !        Plev - number of vertical levels
+   !        Pcnst - number of tracers
+   !
+   ! Output: Psd - dry surface pressure (Pa)
+   !         Phis - surface geopotential (m^2/s^2)
+   !         T - temperature (K)
+   !         Ux - longitudinal velocity at cell centers (m/s)
+   !         Uy - latitudinal velocity at cell centers (m/s)
+   !         Omega - omega (Pa/s)
+   !         Tracer - tracer mixing ratios (kg/kg)
+   !
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   
+      implicit none
+
+      write(0,*) 'Called MPAS_TO_CAM'
+   
+   end subroutine mpas_to_cam
+   
+   
+   subroutine cam_to_mpas()
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! SUBROUTINE CAM_TO_MPAS
+   !
+   ! Input: Numcols - number of columns/cells
+   !        Plev - number of vertical levels
+   !        Pcnst - number of tracers
+   !        T_tend - temperature tendency (K/s)
+   !        Ux_tend - longitudinal velocity tendency at cell centers (m/s^2)
+   !        Uy_tend - latitudinal velocity tendency at cell centers (m/s^2)
+   !        Tracer - tracer mixing ratios (kg/kg)
+   !
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   
+      implicit none
+
+      write(0,*) 'Called CAM_TO_MPAS'
+   
+   end subroutine cam_to_mpas
+   
+   
+   subroutine mpas_dyn_run()
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! SUBROUTINE MPAS_DYN_RUN
+   !
+   ! Advance MPAS dynamics by one timestep.
+   !
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   
+      implicit none
+   
+      write(0,*) 'Called MPAS_DYN_RUN'
+
+      itimestep = 1
+      call mpas_timestep(domain, itimestep, dt)
+   
+   end subroutine mpas_dyn_run
+   
+   
+   subroutine mpas_final()
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! SUBROUTINE MPAS_FINAL
+   !
+   ! Deallocates storage allocated by MPAS and shuts down the MPAS software
+   !    infrastructure.
+   !
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   
+      implicit none
+   
+      write(0,*) 'Called MPAS_FINAL'
+
+      call deallocate_domain(domain)
+
+      call dmpar_finalize(dminfo)
+   
+   end subroutine mpas_final
+
+end module mpas_cam_interface

Added: branches/mpas_cam_coupling/src/driver_cam_interface/module_subdriver.F
===================================================================
--- branches/mpas_cam_coupling/src/driver_cam_interface/module_subdriver.F                                (rev 0)
+++ branches/mpas_cam_coupling/src/driver_cam_interface/module_subdriver.F        2010-03-17 00:54:38 UTC (rev 142)
@@ -0,0 +1,150 @@
+module subdriver
+
+   use grid_types
+   use io_output
+   use configure
+   use dmpar
+   use timer
+
+   integer :: output_frame
+   integer :: restart_frame
+
+   interface
+      subroutine mpas_init(block, mesh, dt)
+         use grid_types
+         type (block_type), intent(inout) :: block
+         type (grid_meta), intent(inout) :: mesh
+         real (kind=RKIND), intent(in) :: dt
+      end subroutine mpas_init
+
+      subroutine mpas_timestep(domain, itimestep, dt)
+         use grid_types
+         type (domain_type), intent(inout) :: domain
+         integer, intent(in) :: itimestep
+         real (kind=RKIND), intent(in) :: dt
+      end subroutine mpas_timestep
+   end interface
+
+
+   contains
+
+
+   subroutine solve(domain)
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! Solve 2d shallow water equations over the time range specified in the 
+   !   namelist, writing model state to an output file periodically
+   !
+   ! Input/Output: domain - grid metadata and model state, to be advanced forward 
+   !                       in time
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+      implicit none
+
+      type (domain_type), intent(inout) :: domain
+     
+      integer :: ntimesteps, itimestep
+      real (kind=RKIND) :: dt
+      type (block_type), pointer :: block_ptr
+      type (io_output_object) :: output_obj
+      type (io_output_object) :: restart_obj
+
+
+      ! Eventually, dt should be domain specific
+      dt = config_dt
+      ntimesteps = config_ntimesteps
+
+
+      ! Compute diagnostic fields needed in solve loop, and initialize 
+      !    simulation time to 0 for all blocks
+      block_ptr =&gt; domain % blocklist
+      do while (associated(block_ptr))
+         call mpas_init(block_ptr, block_ptr % mesh, dt)
+         if (.not. config_do_restart) block_ptr % time_levs(1) % state % xtime % scalar = 0.0
+         block_ptr =&gt; block_ptr % next
+      end do
+
+      ! Before integrating, write out the initial state
+      output_frame = 1
+      restart_frame = 1
+      call output_state_init(output_obj, domain, &quot;OUTPUT&quot;)
+      call write_output_frame(output_obj, domain)
+
+
+      ! During integration, time level 1 stores the model state at the beginning of the 
+      !   time step, and time level 2 stores the state advanced dt in time by timestep(...)
+      do itimestep = 1,ntimesteps     
+         write(0,*) 'Doing timestep ', itimestep
+         call timer_start(&quot;time integration&quot;)
+         call mpas_timestep(domain, itimestep, dt) 
+         call timer_stop(&quot;time integration&quot;)
+
+         ! Move time level 2 fields back into time level 1 for next time step
+         call shift_time_levels(domain)
+
+         if (mod(itimestep, config_output_interval) == 0) then 
+            call write_output_frame(output_obj, domain)
+         end if
+         if (mod(itimestep, config_restart_interval) == 0 .and. config_restart_interval &gt; 0) then 
+            if (restart_frame == 1) call output_state_init(restart_obj, domain, &quot;RESTART&quot;)
+            call output_state_for_domain(restart_obj, domain, restart_frame)
+            restart_frame = restart_frame + 1
+         end if
+      end do
+
+      call output_state_finalize(output_obj, domain % dminfo)
+      if (restart_frame &gt; 1) call output_state_finalize(restart_obj, domain % dminfo)
+
+   end subroutine solve
+
+
+   subroutine write_output_frame(output_obj, domain)
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! Compute diagnostic fields for a domain and write model state to output file
+   !
+   ! Input/Output: domain - contains model state; diagnostic field are computed 
+   !                        before returning
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+      implicit none
+
+      type (domain_type), intent(inout) :: domain
+      type (io_output_object), intent(inout) :: output_obj
+
+      integer :: i, j, k
+      integer :: eoe
+      type (block_type), pointer :: block_ptr
+
+      block_ptr =&gt; domain % blocklist
+      do while (associated(block_ptr))
+         call compute_output_diagnostics(block_ptr % time_levs(1) % state, block_ptr % mesh)
+         block_ptr =&gt; block_ptr % next
+      end do
+
+      call output_state_for_domain(output_obj, domain, output_frame)
+      output_frame = output_frame + 1
+
+   end subroutine write_output_frame
+
+
+   subroutine compute_output_diagnostics(state, grid)
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! Compute diagnostic fields for a domain
+   !
+   ! Input: state - contains model prognostic fields
+   !        grid  - contains grid metadata
+   ! 
+   ! Output: state - upon returning, diagnostic fields will have be computed
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+      implicit none
+
+      type (grid_state), intent(inout) :: state
+      type (grid_meta), intent(in) :: grid
+
+      integer :: i, eoe
+      integer :: iEdge, k
+
+   end subroutine compute_output_diagnostics
+
+
+end module subdriver

Added: branches/mpas_cam_coupling/src/driver_cam_interface/test_driver.F
===================================================================
--- branches/mpas_cam_coupling/src/driver_cam_interface/test_driver.F                                (rev 0)
+++ branches/mpas_cam_coupling/src/driver_cam_interface/test_driver.F        2010-03-17 00:54:38 UTC (rev 142)
@@ -0,0 +1,37 @@
+program test_driver
+
+   use mpas_cam_interface
+
+   implicit none
+
+   integer :: mpi_ierr
+
+   call MPI_Init(mpi_ierr)
+
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! Begin calling CAM-MAS interface routines
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+   call mpas_init1(MPI_COMM_WORLD)
+
+   call cam_inidat_to_mpas()
+
+   call mpas_init2()
+
+   call mpas_dyn_run()
+
+   call mpas_to_cam()
+
+   call cam_to_mpas()
+
+   call mpas_final()
+
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! Finish calling CAM-MAS interface routines
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+   call MPI_Finalize(mpi_ierr)
+
+   stop
+
+end program test_driver

</font>
</pre>