<p><b>dwj07@fsu.edu</b> 2012-01-06 13:47:25 -0700 (Fri, 06 Jan 2012)</p><p><br>
        -- BRANCH COMMIT --<br>
<br>
        Merging trunk to performance branch.<br>
</p><hr noshade><pre><font color="gray">
Property changes on: branches/ocean_projects/performance/src
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/ocean_projects/imp_vert_mix_mrp/src:754-986
/branches/ocean_projects/split_explicit_timestepping/src:1044-1097
/branches/ocean_projects/vert_adv_mrp/src:704-745
/branches/source_renaming/src:1082-1113
/branches/time_manager/src:924-962
/trunk/mpas/src:1109-1190
   + /branches/ocean_projects/imp_vert_mix_mrp/src:754-986
/branches/ocean_projects/rayleigh/src:1298-1311
/branches/ocean_projects/split_explicit_mrp/src:1133-1175
/branches/ocean_projects/split_explicit_timestepping/src:1044-1097
/branches/ocean_projects/vert_adv_mrp/src:704-745
/branches/source_renaming/src:1082-1113
/branches/time_manager/src:924-962
/trunk/mpas/src:1109-1313


Property changes on: branches/ocean_projects/performance/src/core_ocean
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean:754-986
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean:1044-1097
/branches/ocean_projects/vert_adv_mrp/src/core_ocean:704-745
/branches/source_renaming/src/core_ocean:1082-1113
/branches/time_manager/src/core_ocean:924-962
/trunk/mpas/src/core_ocean:1109-1199
   + /branches/cam_mpas_nh/src/core_ocean:1260-1270
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean:754-986
/branches/ocean_projects/rayleigh/src/core_ocean:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean:1133-1175
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean:704-745
/branches/source_renaming/src/core_ocean:1082-1113
/branches/time_manager/src/core_ocean:924-962
/trunk/mpas/src/core_ocean:1109-1313

Modified: branches/ocean_projects/performance/src/core_ocean/Makefile
===================================================================
--- branches/ocean_projects/performance/src/core_ocean/Makefile        2012-01-06 20:05:35 UTC (rev 1314)
+++ branches/ocean_projects/performance/src/core_ocean/Makefile        2012-01-06 20:47:25 UTC (rev 1315)
@@ -13,6 +13,7 @@
            mpas_ocn_vel_forcing.o \
            mpas_ocn_vel_forcing_windstress.o \
            mpas_ocn_vel_forcing_bottomdrag.o \
+           mpas_ocn_vel_forcing_rayleigh.o \
            mpas_ocn_vel_pressure_grad.o \
            mpas_ocn_tracer_vadv.o \
            mpas_ocn_tracer_vadv_spline.o \
@@ -41,9 +42,9 @@
            mpas_ocn_equation_of_state.o \
            mpas_ocn_equation_of_state_jm.o \
            mpas_ocn_equation_of_state_linear.o \
-       mpas_ocn_global_diagnostics.o
+       mpas_ocn_global_diagnostics.o \
+           mpas_ocn_time_average.o
 
-
 all: core_hyd
 
 core_hyd: $(OBJS)
@@ -59,10 +60,12 @@
 
 mpas_ocn_time_integration_split.o:
 
-mpas_ocn_tendency.o:
+mpas_ocn_tendency.o: mpas_ocn_time_average.o
 
 mpas_ocn_global_diagnostics.o: 
 
+mpas_ocn_time_average.o:
+
 mpas_ocn_thick_hadv.o:
 
 mpas_ocn_thick_vadv.o:
@@ -77,12 +80,14 @@
 
 mpas_ocn_vel_hmix_del4.o:
 
-mpas_ocn_vel_forcing.o: mpas_ocn_vel_forcing_windstress.o mpas_ocn_vel_forcing_bottomdrag.o
+mpas_ocn_vel_forcing.o: mpas_ocn_vel_forcing_windstress.o mpas_ocn_vel_forcing_bottomdrag.o mpas_ocn_vel_forcing_rayleigh.o
 
 mpas_ocn_vel_forcing_windstress.o:
 
-mpas_ocn_velforcing_bottomdrag.o:
+mpas_ocn_vel_forcing_bottomdrag.o:
 
+mpas_ocn_vel_forcing_rayleigh.o:
+
 mpas_ocn_vel_coriolis.o:
 
 mpas_ocn_tracer_hadv.o:  mpas_ocn_tracer_hadv2.o  mpas_ocn_tracer_hadv3.o  mpas_ocn_tracer_hadv4.o
@@ -172,7 +177,8 @@
                                           mpas_ocn_equation_of_state.o \
                                           mpas_ocn_equation_of_state_jm.o \
                                           mpas_ocn_equation_of_state_linear.o \
-                                          mpas_ocn_global_diagnostics.o
+                                          mpas_ocn_global_diagnostics.o \
+                                          mpas_ocn_time_average.o
 
 clean:
         $(RM) *.o *.mod *.f90 libdycore.a

Modified: branches/ocean_projects/performance/src/core_ocean/Registry
===================================================================
--- branches/ocean_projects/performance/src/core_ocean/Registry        2012-01-06 20:05:35 UTC (rev 1314)
+++ branches/ocean_projects/performance/src/core_ocean/Registry        2012-01-06 20:47:25 UTC (rev 1315)
@@ -1,6 +1,6 @@
-#
-# namelist  type  namelist_record  name  default_value
-#
+%
+% namelist  type  namelist_record  name  default_value
+%
 namelist integer   sw_model config_test_case           5
 namelist character sw_model config_time_integration    RK4
 namelist logical   sw_model config_rk_filter_btr_mode  false
@@ -36,7 +36,7 @@
 namelist real      split_explicit_ts config_btr_gam2_SSHWt1  1.0
 namelist real      split_explicit_ts config_btr_gam3_uWt2    1.0
 namelist logical   split_explicit_ts config_btr_solve_SSH2   false
-namelist logical   sw_model config_h_ScaleWithMesh     false
+namelist logical   hmix     config_h_ScaleWithMesh     false
 namelist real      hmix     config_h_mom_eddy_visc2     0.0
 namelist real      hmix     config_h_mom_eddy_visc4     0.0
 namelist logical   hmix     config_visc_vorticity_term true
@@ -46,8 +46,8 @@
 namelist real      hmix     config_h_tracer_eddy_diff2  0.0
 namelist real      hmix     config_h_tracer_eddy_diff4  0.0
 namelist real      hmix     config_apvm_upwinding       0.5
-namelist logical   hmix     config_mom_decay            false 
-namelist real      hmix     config_mom_decay_time       3600.0
+namelist logical   hmix     config_rayleigh_friction    false
+namelist real      hmix     config_rayleigh_damping_coeff 0.0
 namelist character vmix     config_vert_visc_type       const
 namelist character vmix     config_vert_diff_type       const
 namelist logical   vmix     config_implicit_vertical_mix  .true.
@@ -76,9 +76,9 @@
 namelist real      restore   config_restoreT_timescale  90.0
 namelist real      restore   config_restoreS_timescale  90.0
 
-#
-# dim  type  name_in_file  name_in_code
-#
+%
+% dim  type  name_in_file  name_in_code
+%
 dim nCells nCells
 dim nEdges nEdges
 dim maxEdges maxEdges
@@ -92,9 +92,9 @@
 dim nVertLevels nVertLevels
 dim nVertLevelsP1 nVertLevels+1
 
-#
-# var persistence type  name_in_file  ( dims )  time_levs iro-  name_in_code struct super-array array_class
-#
+%
+% var persistence type  name_in_file  ( dims )  time_levs iro-  name_in_code struct super-array array_class
+%
 var persistent text    xtime ( Time ) 2 ro xtime state - -
 
 var persistent real    latCell ( nCells ) 0 iro latCell mesh - -
@@ -149,21 +149,21 @@
 var persistent real    fVertex ( nVertices ) 0 iro fVertex mesh - -
 var persistent real    h_s ( nCells ) 0 iro h_s mesh - -
 
-# Space needed for advection
+% Space needed for advection
 var persistent real    deriv_two ( FIFTEEN TWO nEdges ) 0 - deriv_two mesh - -
 var persistent integer advCells ( TWENTYONE nCells ) 0 - advCells mesh - -
 
-# !! NOTE: the following arrays are needed to allow the use
-# !! of the module_advection.F w/o alteration
-# Space needed for deformation calculation weights
+% !! NOTE: the following arrays are needed to allow the use
+% !! of the module_advection.F w/o alteration
+% Space needed for deformation calculation weights
 var persistent real    defc_a ( maxEdges nCells ) 0 - defc_a mesh - -
 var persistent real    defc_b ( maxEdges nCells ) 0 - defc_b mesh - -
 var persistent real    kdiff ( nVertLevels nCells Time ) 0 - kdiff mesh - -
 
-# Arrays required for reconstruction of velocity field
+% Arrays required for reconstruction of velocity field
 var persistent real    coeffs_reconstruct ( R3 maxEdges nCells ) 0 - coeffs_reconstruct mesh - -
 
-# Arrays for z-level version of mpas-ocean
+% Arrays for z-level version of mpas-ocean
 var persistent integer maxLevelCell ( nCells ) 0 iro maxLevelCell mesh - -
 var persistent integer maxLevelEdgeTop ( nEdges ) 0 - maxLevelEdgeTop mesh - -
 var persistent integer maxLevelEdgeBot ( nEdges ) 0 - maxLevelEdgeBot mesh - -
@@ -176,7 +176,7 @@
 var persistent real hRatioZLevelK ( nVertLevels ) 0 - hRatioZLevelK mesh - -
 var persistent real hRatioZLevelKm1 ( nVertLevels ) 0 - hRatioZLevelKm1 mesh - -
 
-# Boundary conditions: read from input, saved in restart and written to output
+% Boundary conditions: read from input, saved in restart and written to output
 var persistent integer boundaryEdge ( nVertLevels nEdges ) 0 iro boundaryEdge mesh - -
 var persistent integer boundaryVertex ( nVertLevels nVertices ) 0 iro boundaryVertex mesh - -
 var persistent integer boundaryCell ( nVertLevels nCells ) 0 iro boundaryCell mesh - -
@@ -187,7 +187,7 @@
 var persistent real    temperatureRestore ( nCells ) 0 ir temperatureRestore mesh - -
 var persistent real    salinityRestore ( nCells ) 0 ir salinityRestore mesh - -
 
-# Prognostic variables: read from input, saved in restart, and written to output
+% Prognostic variables: read from input, saved in restart, and written to output
 var persistent real    u ( nVertLevels nEdges Time ) 2 ir u state - -
 var persistent real    h ( nVertLevels nCells Time ) 2 ir h state - -
 var persistent real    rho ( nVertLevels nCells Time ) 2 iro rho state - -
@@ -195,7 +195,7 @@
 var persistent real    salinity ( nVertLevels nCells Time ) 2 iro salinity state tracers dynamics
 var persistent real    tracer1 ( nVertLevels nCells Time ) 2 iro tracer1 state tracers testing
 
-# Tendency variables: neither read nor written to any files
+% Tendency variables: neither read nor written to any files
 var persistent real    tend_u ( nVertLevels nEdges Time ) 1 - u tend - -
 var persistent real    tend_h ( nVertLevels nCells Time ) 1 - h tend - -
 var persistent real    tend_ssh ( nCells Time ) 1 - ssh tend - -
@@ -203,7 +203,7 @@
 var persistent real    tend_salinity ( nVertLevels nCells Time ) 1 - salinity tend tracers dynamics
 var persistent real    tend_tracer1 ( nVertLevels nCells Time ) 1 - tracer1 tend tracers testing
 
-# state variables for Split Explicit timesplitting
+% state variables for Split Explicit timesplitting
 var persistent real   uBtr ( nEdges Time )         2 -  uBtr state - -
 var persistent real   ssh ( nCells Time )          2 o  ssh state - - 
 var persistent real   uBtrSubcycle ( nEdges Time ) 2 -  uBtrSubcycle state - -
@@ -216,7 +216,7 @@
 var persistent real   vorticityBtr ( nVertices Time ) 1 - vorticityBtr state - -
 var persistent real   u_diffusionBtr ( nEdges Time ) 1 - u_diffusionBtr state - -
 
-# Diagnostic fields: only written to output
+% Diagnostic fields: only written to output
 var persistent real    v ( nVertLevels nEdges Time ) 2 - v state - -
 var persistent real    divergence ( nVertLevels nCells Time ) 2 o divergence state - -
 var persistent real    vorticity ( nVertLevels nVertices Time ) 2 o vorticity state - -
@@ -239,13 +239,13 @@
 var persistent real    wTop ( nVertLevelsP1 nCells Time ) 2 - wTop state - -
 var persistent real    rhoDisplaced ( nVertLevels nCells Time ) 2 - rhoDisplaced state - -
 
-# Other diagnostic variables: neither read nor written to any files
+% Other diagnostic variables: neither read nor written to any files
 var persistent real    vh ( nVertLevels nEdges Time ) 2 - vh state - -
 var persistent real    circulation ( nVertLevels nVertices Time ) 2 - circulation state - -
 var persistent real    gradPVt ( nVertLevels nEdges Time ) 2 - gradPVt state - -
 var persistent real    gradPVn ( nVertLevels nEdges Time ) 2 - gradPVn state - -
 
-# Globally reduced diagnostic variables: only written to output
+% Globally reduced diagnostic variables: only written to output
 var persistent real    areaCellGlobal ( Time ) 2 o areaCellGlobal state - -
 var persistent real    areaEdgeGlobal ( Time ) 2 o areaEdgeGlobal state - -
 var persistent real    areaTriangleGlobal ( Time ) 2 o areaTriangleGlobal state - -
@@ -254,8 +254,18 @@
 var persistent real    volumeEdgeGlobal ( Time ) 2 o volumeEdgeGlobal state - -
 var persistent real    CFLNumberGlobal ( Time ) 2 o CFLNumberGlobal state - -
 
-# Diagnostics fields, only one time level required
+% Diagnostics fields, only one time level required
 var persistent real    RiTopOfCell ( nVertLevelsP1 nCells Time ) 1 - RiTopOfCell diagnostics - -
 var persistent real    RiTopOfEdge ( nVertLevelsP1 nEdges Time ) 1 - RiTopOfEdge diagnostics - -
 var persistent real    vertViscTopOfEdge ( nVertLevelsP1 nEdges Time ) 1 - vertViscTopOfEdge diagnostics - -
 var persistent real    vertDiffTopOfCell ( nVertLevelsP1 nCells Time ) 1 - vertDiffTopOfCell diagnostics - -
+
+var persistent real    nAccumulate ( Time ) 1 o nAccumulate state - -
+var persistent real    acc_ssh ( nCells Time ) 1 o acc_ssh state - -
+var persistent real    acc_sshVar ( nCells Time ) 1 o acc_sshVar state - -
+var persistent real    acc_uReconstructZonal ( nVertLevels nCells Time ) 1 o acc_uReconstructZonal state - -
+var persistent real    acc_uReconstructMeridional ( nVertLevels nCells Time ) 1 o acc_uReconstructMeridional state - -
+var persistent real    acc_uReconstructZonalVar ( nVertLevels nCells Time ) 1 o acc_uReconstructZonalVar state - -
+var persistent real    acc_uReconstructMeridionalVar ( nVertLevels nCells Time ) 1 o acc_uReconstructMeridionalVar state - -
+var persistent real           acc_u ( nVertLevels nEdges Time ) 1 o acc_u state - -
+var persistent real           acc_uVar ( nVertLevels nEdges Time ) 1 o acc_uVar state - -

Modified: branches/ocean_projects/performance/src/core_ocean/mpas_ocn_advection.F
===================================================================
--- branches/ocean_projects/performance/src/core_ocean/mpas_ocn_advection.F        2012-01-06 20:05:35 UTC (rev 1314)
+++ branches/ocean_projects/performance/src/core_ocean/mpas_ocn_advection.F        2012-01-06 20:47:25 UTC (rev 1315)
@@ -1,5 +1,6 @@
 module ocn_advection
 
+   use mpas_kind_types
    use mpas_grid_types
    use mpas_configure
    use mpas_constants
@@ -117,7 +118,7 @@
 
             theta_abs(iCell) =  pii/2. - sphere_angle( xc(1), yc(1), zc(1),  &amp;
                                                        xc(2), yc(2), zc(2),  &amp;
-                                                       0.,    0.,    1.      ) 
+                                                       0.0_RKIND, 0.0_RKIND, 1.0_RKIND ) 
 
 ! angles from cell center to neighbor centers (thetav)
 
@@ -390,7 +391,7 @@
    ! Computes the angle between arcs AB and AC, given points A, B, and C
    ! Equation numbers w.r.t. http://mathworld.wolfram.com/SphericalTrigonometry.html
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-   real function sphere_angle(ax, ay, az, bx, by, bz, cx, cy, cz)!{{{
+   real (kind=RKIND) function sphere_angle(ax, ay, az, bx, by, bz, cx, cy, cz)!{{{
    
       implicit none
    
@@ -410,9 +411,9 @@
       real (kind=RKIND) :: s                ! Semiperimeter of the triangle
       real (kind=RKIND) :: sin_angle
    
-      a = acos(max(min(bx*cx + by*cy + bz*cz,1.0),-1.0))      ! Eqn. (3)
-      b = acos(max(min(ax*cx + ay*cy + az*cz,1.0),-1.0))      ! Eqn. (2)
-      c = acos(max(min(ax*bx + ay*by + az*bz,1.0),-1.0))      ! Eqn. (1)
+      a = acos(max(min(bx*cx + by*cy + bz*cz,1.0_RKIND),-1.0_RKIND))      ! Eqn. (3)
+      b = acos(max(min(ax*cx + ay*cy + az*cz,1.0_RKIND),-1.0_RKIND))      ! Eqn. (2)
+      c = acos(max(min(ax*bx + ay*by + az*bz,1.0_RKIND),-1.0_RKIND))      ! Eqn. (1)
    
       ABx = bx - ax
       ABy = by - ay
@@ -428,12 +429,12 @@
    
       s = 0.5*(a + b + c)
 !      sin_angle = sqrt((sin(s-b)*sin(s-c))/(sin(b)*sin(c)))   ! Eqn. (28)
-      sin_angle = sqrt(min(1.,max(0.,(sin(s-b)*sin(s-c))/(sin(b)*sin(c)))))   ! Eqn. (28)
+      sin_angle = sqrt(min(1.0_RKIND,max(0.0_RKIND,(sin(s-b)*sin(s-c))/(sin(b)*sin(c)))))   ! Eqn. (28)
    
       if ((Dx*ax + Dy*ay + Dz*az) &gt;= 0.0) then
-         sphere_angle =  2.0 * asin(max(min(sin_angle,1.0),-1.0))
+         sphere_angle =  2.0 * asin(max(min(sin_angle,1.0_RKIND),-1.0_RKIND))
       else
-         sphere_angle = -2.0 * asin(max(min(sin_angle,1.0),-1.0))
+         sphere_angle = -2.0 * asin(max(min(sin_angle,1.0_RKIND),-1.0_RKIND))
       end if
    
    end function sphere_angle!}}}
@@ -445,7 +446,7 @@
    ! Computes the angle between vectors AB and AC, given points A, B, and C, and
    !   a vector (u,v,w) normal to the plane.
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-   real function plane_angle(ax, ay, az, bx, by, bz, cx, cy, cz, u, v, w)!{{{
+   real (kind=RKIND) function plane_angle(ax, ay, az, bx, by, bz, cx, cy, cz, u, v, w)!{{{
    
       implicit none
    
@@ -480,9 +481,9 @@
       cos_angle = (ABx*ACx + ABy*ACy + ABz*ACz) / (mAB * mAC)
    
       if ((Dx*u + Dy*v + Dz*w) &gt;= 0.0) then
-         plane_angle =  acos(max(min(cos_angle,1.0),-1.0))
+         plane_angle =  acos(max(min(cos_angle,1.0_RKIND),-1.0_RKIND))
       else
-         plane_angle = -acos(max(min(cos_angle,1.0),-1.0))
+         plane_angle = -acos(max(min(cos_angle,1.0_RKIND),-1.0_RKIND))
       end if
    
    end function plane_angle!}}}
@@ -495,7 +496,7 @@
    !    B=(bx, by, bz). It is assumed that both A and B lie on the surface of the
    !    same sphere centered at the origin.
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-   real function arc_length(ax, ay, az, bx, by, bz)!{{{
+   real (kind=RKIND) function arc_length(ax, ay, az, bx, by, bz)!{{{
    
       implicit none
    
@@ -839,7 +840,7 @@
 
             theta_abs(iCell) =  pii/2. - sphere_angle( xc(1), yc(1), zc(1),  &amp;
                                                        xc(2), yc(2), zc(2),  &amp;
-                                                       0.,    0.,    1.      ) 
+                                                       0.0_RKIND, 0.0_RKIND, 1.0_RKIND ) 
 
 ! angles from cell center to neighbor centers (thetav)
 
@@ -891,10 +892,10 @@
          do i=2,n-1
             ip1 = i+1
             if (ip1 == n) ip1 = 1
-            thetat(i) = plane_angle( 0.,0.,0.,  &amp;
-                                     xp(i)-xp(i-1), yp(i)-yp(i-1), 0.,  &amp;
-                                     xp(ip1)-xp(i), yp(ip1)-yp(i), 0.,  &amp;
-                                     0., 0., 1.)
+            thetat(i) = plane_angle( 0.0_RKIND, 0.0_RKIND, 0.0_RKIND,  &amp;
+                                     xp(i)-xp(i-1), yp(i)-yp(i-1), 0.0_RKIND,  &amp;
+                                     xp(ip1)-xp(i), yp(ip1)-yp(i), 0.0_RKIND,  &amp;
+                                     0.0_RKIND, 0.0_RKIND, 1.0_RKIND)
             thetat(i) = thetat(i) + thetat(i-1)
          end do
 

Modified: branches/ocean_projects/performance/src/core_ocean/mpas_ocn_mpas_core.F
===================================================================
--- branches/ocean_projects/performance/src/core_ocean/mpas_ocn_mpas_core.F        2012-01-06 20:05:35 UTC (rev 1314)
+++ branches/ocean_projects/performance/src/core_ocean/mpas_ocn_mpas_core.F        2012-01-06 20:47:25 UTC (rev 1315)
@@ -26,6 +26,8 @@
 
    use ocn_vmix
 
+   use ocn_time_average
+
    type (io_output_object) :: restart_obj
 
    integer :: current_outfile_frames
@@ -218,6 +220,7 @@
       real (kind=RKIND), intent(in) :: dt
       integer :: i, iEdge, iCell, k
    
+      call ocn_time_average_init(block % state % time_levs(1) % state)
    
       call mpas_timer_start(&quot;diagnostic solve&quot;, .false., initDiagSolveTimer)
       call ocn_diagnostic_solve(dt, block % state % time_levs(1) % state, mesh)
@@ -312,7 +315,13 @@
       write(0,*) 'Initial time ', timeStamp
 
       call ocn_write_output_frame(output_obj, output_frame, domain)
+      block_ptr =&gt; domain % blocklist
 
+      do while(associated(block_ptr))
+        call ocn_time_average_init(block_ptr % state % time_levs(1) % state)
+        block_ptr =&gt; block_ptr % next
+      end do
+
       ! 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(...)
       itimestep = 0
@@ -339,7 +348,21 @@
                call mpas_output_state_finalize(output_obj, domain % dminfo)
                call mpas_output_state_init(output_obj, domain, &quot;OUTPUT&quot;, trim(timeStamp))
             end if
-            call ocn_write_output_frame(output_obj, output_frame, domain)
+
+            block_ptr =&gt; domain % blocklist
+            do while (associated(block_ptr))
+                call ocn_time_average_normalize(block_ptr % state % time_levs(1) % state)
+                block_ptr =&gt; block_ptr % next
+            end do
+
+            call write_output_frame(output_obj, output_frame, domain)
+
+            block_ptr =&gt; domain % blocklist
+            do while (associated(block_ptr))
+                call ocn_time_average_init(block_ptr % state % time_levs(1) % state)
+                block_ptr =&gt; block_ptr % next
+            end do
+
          end if
 
          if (mpas_is_alarm_ringing(clock, restartAlarmID, ierr=ierr)) then

Modified: branches/ocean_projects/performance/src/core_ocean/mpas_ocn_tendency.F
===================================================================
--- branches/ocean_projects/performance/src/core_ocean/mpas_ocn_tendency.F        2012-01-06 20:05:35 UTC (rev 1314)
+++ branches/ocean_projects/performance/src/core_ocean/mpas_ocn_tendency.F        2012-01-06 20:47:25 UTC (rev 1315)
@@ -38,6 +38,8 @@
    use ocn_equation_of_state
    use ocn_vmix
 
+   use ocn_time_average
+
    implicit none
    private
    save

Copied: branches/ocean_projects/performance/src/core_ocean/mpas_ocn_time_average.F (from rev 1313, trunk/mpas/src/core_ocean/mpas_ocn_time_average.F)
===================================================================
--- branches/ocean_projects/performance/src/core_ocean/mpas_ocn_time_average.F                                (rev 0)
+++ branches/ocean_projects/performance/src/core_ocean/mpas_ocn_time_average.F        2012-01-06 20:47:25 UTC (rev 1315)
@@ -0,0 +1,129 @@
+module ocn_time_average
+
+    use mpas_grid_types
+
+    implicit none
+    save
+    public
+
+    contains 
+
+    subroutine ocn_time_average_init(state)!{{{
+        type (state_type), intent(inout) :: state
+
+        real, pointer :: nAccumulate
+
+        real (kind=RKIND), dimension(:), pointer :: acc_ssh, acc_sshVar
+        real (kind=RKIND), dimension(:,:), pointer :: acc_uReconstructZonal, acc_uReconstructMeridional, acc_uReconstructZonalVar, acc_uReconstructMeridionalVar
+        real (kind=RKIND), dimension(:,:), pointer :: acc_u, acc_uVar
+
+        nAccumulate =&gt; state % nAccumulate % scalar
+
+        acc_ssh =&gt; state % acc_ssh % array
+        acc_sshVar =&gt; state % acc_sshVar % array
+        acc_uReconstructZonal =&gt; state % acc_uReconstructZonal % array
+        acc_uReconstructMeridional =&gt; state % acc_uReconstructMeridional % array
+        acc_uReconstructZonalVar =&gt; state % acc_uReconstructZonalVar % array
+        acc_uReconstructMeridionalVar =&gt; state % acc_uReconstructMeridionalVar % array
+        acc_u =&gt; state % acc_u % array
+        acc_uVar =&gt; state % acc_uVar % array
+
+        nAccumulate = 0
+
+        acc_ssh = 0.0
+        acc_sshVar = 0.0
+        acc_uReconstructZonal = 0.0
+        acc_uReconstructMeridional = 0.0
+        acc_uReconstructZonalVar = 0.0
+        acc_uReconstructMeridionalVar = 0.0
+        acc_u = 0.0
+        acc_uVar = 0.0
+
+    end subroutine ocn_time_average_init!}}}
+
+    subroutine ocn_time_average_accumulate(state, old_state)!{{{
+        type (state_type), intent(inout) :: state
+        type (state_type), intent(in) :: old_state
+
+        real, pointer :: nAccumulate, old_nAccumulate
+
+        real (kind=RKIND), dimension(:), pointer :: ssh
+        real (kind=RKIND), dimension(:,:), pointer :: uReconstructZonal, uReconstructMeridional, u
+
+        real (kind=RKIND), dimension(:,:), pointer :: acc_u, acc_uVar
+        real (kind=RKIND), dimension(:,:), pointer :: acc_uReconstructZonal, acc_uReconstructMeridional, acc_uReconstructZonalVar, acc_uReconstructMeridionalVar
+        real (kind=RKIND), dimension(:), pointer :: acc_ssh, acc_sshVar
+
+        real (kind=RKIND), dimension(:,:), pointer :: old_acc_u, old_acc_uVar
+        real (kind=RKIND), dimension(:,:), pointer :: old_acc_uReconstructZonal, old_acc_uReconstructMeridional, old_acc_uReconstructZonalVar, old_acc_uReconstructMeridionalVar
+        real (kind=RKIND), dimension(:), pointer :: old_acc_ssh, old_acc_sshVar
+
+        old_nAccumulate =&gt; old_state % nAccumulate  % scalar
+        nAccumulate =&gt; state % nAccumulate  % scalar
+
+        ssh =&gt; state % ssh % array
+        uReconstructZonal =&gt; state % uReconstructZonal % array
+        uReconstructMeridional =&gt; state % uReconstructMeridional % array
+        u =&gt; state % u % array
+
+        acc_ssh =&gt; state % acc_ssh % array
+        acc_sshVar =&gt; state % acc_sshVar % array
+        acc_uReconstructZonal =&gt; state % acc_uReconstructZonal % array
+        acc_uReconstructMeridional =&gt; state % acc_uReconstructMeridional % array
+        acc_uReconstructZonalVar =&gt; state % acc_uReconstructZonalVar % array
+        acc_uReconstructMeridionalVar =&gt; state % acc_uReconstructMeridionalVar % array
+        acc_u =&gt; state % acc_u % array
+        acc_uVar =&gt; state % acc_uVar % array
+
+        old_acc_ssh =&gt; old_state % acc_ssh % array
+        old_acc_sshVar =&gt; old_state % acc_sshVar % array
+        old_acc_uReconstructZonal =&gt; old_state % acc_uReconstructZonal % array
+        old_acc_uReconstructMeridional =&gt; old_state % acc_uReconstructMeridional % array
+        old_acc_uReconstructZonalVar =&gt; old_state % acc_uReconstructZonalVar % array
+        old_acc_uReconstructMeridionalVar =&gt; old_state % acc_uReconstructMeridionalVar % array
+        old_acc_u =&gt; old_state % acc_u % array
+        old_acc_uVar =&gt; old_state % acc_uVar % array
+
+        acc_ssh = old_acc_ssh + ssh
+        acc_sshVar = old_acc_sshVar + ssh**2
+        acc_uReconstructZonal = old_acc_uReconstructZonal + uReconstructZonal
+        acc_uReconstructMeridional = old_acc_uReconstructMeridional + uReconstructMeridional
+        acc_uReconstructZonalVar = old_acc_uReconstructZonalVar + uReconstructZonal**2
+        acc_uReconstructMeridionalVar = old_acc_uReconstructMeridionalVar + uReconstructMeridional**2
+        acc_u = old_acc_u + u
+        acc_uVar = old_acc_uVar + u**2
+
+        nAccumulate = old_nAccumulate + 1
+    end subroutine ocn_time_average_accumulate!}}}
+
+    subroutine ocn_time_average_normalize(state)!{{{
+        type (state_type), intent(inout) :: state
+
+        real, pointer :: nAccumulate
+
+        real (kind=RKIND), dimension(:), pointer :: acc_ssh, acc_sshVar
+        real (kind=RKIND), dimension(:,:), pointer :: acc_uReconstructZonal, acc_uReconstructMeridional, acc_uReconstructZonalVar, acc_uReconstructMeridionalVar
+        real (kind=RKIND), dimension(:,:), pointer :: acc_u, acc_uVar
+
+        nAccumulate =&gt; state % nAccumulate  % scalar
+
+        acc_ssh =&gt; state % acc_ssh % array
+        acc_sshVar =&gt; state % acc_sshVar % array
+        acc_uReconstructZonal =&gt; state % acc_uReconstructZonal % array
+        acc_uReconstructMeridional =&gt; state % acc_uReconstructMeridional % array
+        acc_uReconstructZonalVar =&gt; state % acc_uReconstructZonalVar % array
+        acc_uReconstructMeridionalVar =&gt; state % acc_uReconstructMeridionalVar % array
+        acc_u =&gt; state % acc_u % array
+        acc_uVar =&gt; state % acc_uVar % array
+
+        acc_ssh = acc_ssh / nAccumulate
+        acc_sshVar = acc_sshVar / nAccumulate
+        acc_uReconstructZonal = acc_uReconstructZonal / nAccumulate
+        acc_uReconstructMeridional = acc_uReconstructMeridional / nAccumulate
+        acc_uReconstructZonalVar = acc_uReconstructZonalVar / nAccumulate
+        acc_uReconstructMeridionalVar = acc_uReconstructMeridionalVar / nAccumulate
+        acc_u = acc_u / nAccumulate
+        acc_uVar = acc_uVar / nAccumulate
+    end subroutine ocn_time_average_normalize!}}}
+
+end module ocn_time_average

Modified: branches/ocean_projects/performance/src/core_ocean/mpas_ocn_time_integration_rk4.F
===================================================================
--- branches/ocean_projects/performance/src/core_ocean/mpas_ocn_time_integration_rk4.F        2012-01-06 20:05:35 UTC (rev 1314)
+++ branches/ocean_projects/performance/src/core_ocean/mpas_ocn_time_integration_rk4.F        2012-01-06 20:47:25 UTC (rev 1315)
@@ -25,6 +25,7 @@
 
    use ocn_equation_of_state
    use ocn_vmix
+   use ocn_time_average
 
    implicit none
    private
@@ -316,29 +317,6 @@
             call mpas_timer_stop(&quot;RK4-implicit vert mix&quot;)
          end if
 
-         ! mrp 110725 momentum decay term
-         if (config_mom_decay) then
-             call mpas_timer_start(&quot;RK4-momentum decay&quot;)
-
-            !
-            !  Implicit solve for momentum decay
-            !
-            !  Add term to RHS of momentum equation: -1/gamma u
-            !
-            !  This changes the solve to:
-            !  u^{n+1} = u_provis^{n+1}/(1+dt/gamma)
-            !
-            coef = 1.0/(1.0 + dt/config_mom_decay_time)
-            do iEdge=1,block % mesh % nEdges
-               do k=1,maxLevelEdgeTop(iEdge)
-                  u(k,iEdge) = coef*u(k,iEdge) 
-               end do
-            end do
-
-            call mpas_timer_stop(&quot;RK4-momentum decay&quot;)
-         end if
-
-
          if (config_test_case == 1) then    ! For case 1, wind field should be fixed
             block % state % time_levs(2) % state % u % array(:,:) = block % state % time_levs(1) % state % u % array(:,:)
          end if
@@ -353,6 +331,8 @@
                           block % state % time_levs(2) % state % uReconstructMeridional % array    &amp;
                          )
 
+         call ocn_time_average_accumulate(block % state % time_levs(2) % state, block % state % time_levs(1) % state)
+
          block =&gt; block % next
       end do
       call mpas_timer_stop(&quot;RK4-cleaup phase&quot;)

Modified: branches/ocean_projects/performance/src/core_ocean/mpas_ocn_time_integration_split.F
===================================================================
--- branches/ocean_projects/performance/src/core_ocean/mpas_ocn_time_integration_split.F        2012-01-06 20:05:35 UTC (rev 1314)
+++ branches/ocean_projects/performance/src/core_ocean/mpas_ocn_time_integration_split.F        2012-01-06 20:47:25 UTC (rev 1315)
@@ -27,8 +27,8 @@
 
    use ocn_equation_of_state
    use ocn_vmix
+   use ocn_time_average
 
-
    implicit none
    private
    save
@@ -1009,25 +1009,7 @@
           call ocn_tracer_vmix_tend_implicit(block % mesh, dt, vertdifftopofcell, h, tracers, err)
         end if
 
-        ! mrp 110725 adding momentum decay term
-        if (config_mom_decay) then
 
-          !
-          !  Implicit solve for momentum decay
-          !
-          !  Add term to RHS of momentum equation: -1/gamma u
-          !
-          !  This changes the solve to:
-          !  u^{n+1} = u_provis^{n+1}/(1+dt/gamma)
-          !
-          coef = 1.0/(1.0 + dt/config_mom_decay_time)
-          do iEdge=1,block % mesh % nEdges
-            do k=1,maxLevelEdgeTop(iEdge)
-              u(k,iEdge) = coef*u(k,iEdge) 
-            end do
-          end do
-        end if
-
         if (config_test_case == 1) then    ! For case 1, wind field should be fixed
           block % state % time_levs(2) % state % u % array(:,:) = block % state % time_levs(1) % state % u % array(:,:)
         end if
@@ -1041,6 +1023,8 @@
             block % state % time_levs(2) % state % uReconstructZonal % array,        &amp;
             block % state % time_levs(2) % state % uReconstructMeridional % array)
 
+        call ocn_time_average_accumulate(block % state % time_levs(2) % state, block % state % time_levs(1) % state)
+
         block =&gt; block % next
       end do
       call mpas_timer_stop(&quot;se timestep&quot;, timer_main)

Modified: branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vel_forcing.F
===================================================================
--- branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vel_forcing.F        2012-01-06 20:05:35 UTC (rev 1314)
+++ branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vel_forcing.F        2012-01-06 20:47:25 UTC (rev 1315)
@@ -19,6 +19,7 @@
 
    use ocn_vel_forcing_windstress
    use ocn_vel_forcing_bottomdrag
+   use ocn_vel_forcing_rayleigh
 
    implicit none
    private
@@ -114,7 +115,7 @@
       !
       !-----------------------------------------------------------------
 
-      integer :: err1, err2
+      integer :: err1, err2, err3
 
       !-----------------------------------------------------------------
       !
@@ -126,8 +127,10 @@
 
       call ocn_vel_forcing_windstress_tend(grid, u_src, h_edge, tend, err1)
       call ocn_vel_forcing_bottomdrag_tend(grid, u, ke_edge, h_edge, tend, err2)
+      call ocn_vel_forcing_rayleigh_tend(grid, u, tend, err3)
 
       err = ior(err1, err2)
+      err = ior(err, err3)
 
    !--------------------------------------------------------------------
 
@@ -161,12 +164,14 @@
 
       integer, intent(out) :: err !&lt; Output: error flag
 
-      integer :: err1, err2
+      integer :: err1, err2, err3
 
       call ocn_vel_forcing_windstress_init(err1)
       call ocn_vel_forcing_bottomdrag_init(err2)
+      call ocn_vel_forcing_rayleigh_init(err3)
 
       err = ior(err1, err2)
+      err = ior(err, err3)
 
    !--------------------------------------------------------------------
 

Copied: branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vel_forcing_rayleigh.F (from rev 1313, trunk/mpas/src/core_ocean/mpas_ocn_vel_forcing_rayleigh.F)
===================================================================
--- branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vel_forcing_rayleigh.F                                (rev 0)
+++ branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vel_forcing_rayleigh.F        2012-01-06 20:47:25 UTC (rev 1315)
@@ -0,0 +1,180 @@
+!|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+!
+!  ocn_vel_forcing_rayleigh
+!
+!&gt; \brief MPAS ocean Rayleigh Friction (to be used to smooth &quot;shocks&quot; from cold starts)
+!&gt; \author Todd Ringler
+!&gt; \date   5 January 2012
+!&gt; \version SVN:$Id:$
+!&gt; \details
+!&gt;  This module contains the routine for computing 
+!&gt;  tendencies based on linear Rayleigh friction.
+!
+!-----------------------------------------------------------------------
+
+module ocn_vel_forcing_rayleigh
+
+   use mpas_grid_types
+   use mpas_configure
+
+   implicit none
+   private
+   save
+
+   !--------------------------------------------------------------------
+   !
+   ! Public parameters
+   !
+   !--------------------------------------------------------------------
+
+   !--------------------------------------------------------------------
+   !
+   ! Public member functions
+   !
+   !--------------------------------------------------------------------
+
+   public :: ocn_vel_forcing_rayleigh_tend, &amp;
+             ocn_vel_forcing_rayleigh_init
+
+   !--------------------------------------------------------------------
+   !
+   ! Private module variables
+   !
+   !--------------------------------------------------------------------
+
+   logical :: rayleighFrictionOn
+   real (kind=RKIND) :: rayleighDampingCoef
+
+
+!***********************************************************************
+
+contains
+
+!***********************************************************************
+!
+!  ocn_vel_forcing_rayleigh_tend
+!
+!&gt; \brief   Computes tendency term from Rayleigh friction
+!&gt; \author  Todd Ringler
+!&gt; \date    5 January 2012
+!&gt; \version SVN:$Id$
+!&gt; \details 
+!&gt;  This routine computes the Rayleigh friction tendency for momentum
+!&gt;  based on current state.
+!
+!-----------------------------------------------------------------------
+
+   subroutine ocn_vel_forcing_rayleigh_tend(grid, u, tend, err)!{{{
+
+      !-----------------------------------------------------------------
+      !
+      ! input variables
+      !
+      !-----------------------------------------------------------------
+
+      real (kind=RKIND), dimension(:,:), intent(in) :: &amp;
+         u    !&lt; Input: velocity 
+
+      type (mesh_type), intent(in) :: &amp;
+         grid          !&lt; Input: grid information
+
+      !-----------------------------------------------------------------
+      !
+      ! input/output variables
+      !
+      !-----------------------------------------------------------------
+
+      real (kind=RKIND), dimension(:,:), intent(inout) :: &amp;
+         tend          !&lt; Input/Output: velocity tendency
+
+      !-----------------------------------------------------------------
+      !
+      ! output variables
+      !
+      !-----------------------------------------------------------------
+
+      integer, intent(out) :: err !&lt; Output: error flag
+
+      !-----------------------------------------------------------------
+      !
+      ! local variables
+      !
+      !-----------------------------------------------------------------
+
+      integer :: iEdge, nEdgesSolve, k
+      integer, dimension(:), pointer :: maxLevelEdgeTop
+
+      !-----------------------------------------------------------------
+      !
+      ! call relevant routines for computing tendencies
+      ! note that the user can choose multiple options and the 
+      !   tendencies will be added together
+      !
+      !-----------------------------------------------------------------
+
+      err = 0
+
+      if(.not.rayleighFrictionOn) return
+
+      nEdgesSolve = grid % nEdgesSolve
+      maxLevelEdgeTop =&gt; grid % maxLevelEdgeTop % array
+
+      do iEdge=1,nEdgesSolve
+        do k=1,maxLevelEdgeTop(iEdge)
+
+           tend(k,iEdge) = tend(k,iEdge) - rayleighDampingCoef * u(k,iEdge)
+
+        enddo
+      enddo
+
+
+   !--------------------------------------------------------------------
+
+   end subroutine ocn_vel_forcing_rayleigh_tend!}}}
+
+!***********************************************************************
+!
+!  ocn_vel_forcing_rayleigh_init
+!
+!&gt; \brief   Initializes ocean Rayleigh friction
+!&gt; \author  Todd Ringler
+!&gt; \date    5 January 2012
+!&gt; \version SVN:$Id$
+!&gt; \details 
+!&gt;  This routine initializes quantities related to 
+!&gt;  in the ocean. 
+!
+!-----------------------------------------------------------------------
+
+   subroutine ocn_vel_forcing_rayleigh_init(err)!{{{
+
+   !--------------------------------------------------------------------
+
+      !-----------------------------------------------------------------
+      !
+      ! call individual init routines for each parameterization
+      !
+      !-----------------------------------------------------------------
+
+      integer, intent(out) :: err !&lt; Output: error flag
+
+
+      err = 0
+
+      rayleighDampingCoef = 0.0
+
+      if (config_rayleigh_friction) then
+          rayleighFrictionOn = .true.
+          rayleighDampingCoef = config_rayleigh_damping_coeff
+      endif
+
+   !--------------------------------------------------------------------
+
+   end subroutine ocn_vel_forcing_rayleigh_init!}}}
+
+!***********************************************************************
+
+end module ocn_vel_forcing_rayleigh
+
+!|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+! vim: foldmethod=marker

Modified: branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vel_vadv.F
===================================================================
--- branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vel_vadv.F        2012-01-06 20:05:35 UTC (rev 1314)
+++ branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vel_vadv.F        2012-01-06 20:47:25 UTC (rev 1315)
@@ -108,9 +108,9 @@
       integer, dimension(:), pointer :: maxLevelEdgeTop
       integer, dimension(:,:), pointer :: cellsOnEdge, edgeMask
 
-      real :: wTopEdge
-      real, dimension(:), allocatable :: w_dudzTopEdge
-      real, dimension(:), pointer :: zMidZLevel
+      real (kind=RKIND) :: wTopEdge
+      real (kind=RKIND), dimension(:), allocatable :: w_dudzTopEdge
+      real (kind=RKIND), dimension(:), pointer :: zMidZLevel
 
       if(velVadvOn == 0) return
 

</font>
</pre>