Index: palm/trunk/SOURCE/time_integration_spinup.f90
===================================================================
--- palm/trunk/SOURCE/time_integration_spinup.f90	(revision 2726)
+++ palm/trunk/SOURCE/time_integration_spinup.f90	(revision 2728)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Set velocity componenets to homogeneous values during spinup
+! 
+! 2724 2018-01-05 12:12:38Z maronga
 ! Use dt_spinup for all active components during spinup
 ! 
@@ -65,5 +68,5 @@
  
     USE arrays_3d,                                                             &
-        ONLY:  pt, pt_p
+        ONLY:  pt, pt_p, u, v
 
     USE control_parameters,                                                    &
@@ -71,12 +74,14 @@
                coupling_start_time, current_timestep_number,                   &
                data_output_during_spinup, disturbance_created, dopr_n, do_sum, &
-               dt_averaging_input_pr, dt_dopr, dt_dots, dt_do2d_xy, dt_do3d, dt_run_control,        &
-               dt_spinup, dt_3d, humidity, intermediate_timestep_count,               &
+               dt_averaging_input_pr, dt_dopr, dt_dots, dt_do2d_xy, dt_do3d,   &
+               dt_run_control, dt_spinup, dt_3d, humidity,                     &
+               intermediate_timestep_count,                                    &
                intermediate_timestep_count_max, land_surface,                  &
                simulated_time, simulated_time_chr,                             &
-               skip_time_dopr, skip_time_do2d_xy, skip_time_do3d, spinup, spinup_pt_amplitude, &
-               spinup_pt_mean, spinup_time, timestep_count, timestep_scheme,   &
-               time_dopr, time_dopr_av, time_dots, time_do2d_xy, time_do3d, time_run_control,           &
-               time_since_reference_point, urban_surface
+               skip_time_dopr, skip_time_do2d_xy, skip_time_do3d, spinup,      &
+               spinup_pt_amplitude, spinup_pt_mean, spinup_time,               &
+               timestep_count, timestep_scheme, time_dopr, time_dopr_av,       &
+               time_dots, time_do2d_xy, time_do3d, time_run_control,           &
+               time_since_reference_point, ug_surface, vg_surface, urban_surface
 
     USE constants,                                                             &
@@ -141,10 +146,30 @@
     REAL(wp) ::  dt_save     !< temporary storage for time step
                   
-    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pt_save   !< temporary storage of temperature
-
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pt_save  !< temporary storage of temperature
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u_save   !< temporary storage of u wind component
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  v_save   !< temporary storage of v wind component
+
+
+!
+!-- Save 3D arrays because they are to be changed for spinup purpose
     ALLOCATE( pt_save(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+    ALLOCATE( u_save(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+    ALLOCATE( v_save(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
 
     CALL exchange_horiz( pt, nbgp )   
+    CALL exchange_horiz( u,  nbgp )  
+    CALL exchange_horiz( v,  nbgp )  
+ 
     pt_save = pt
+    u_save  = u
+    v_save  = v
+
+!
+!-- Set the same wall-adjacent velocity to all grid points. The sign of the 
+!-- original velocity field must be preserved because the surface schemes crash 
+!-- otherwise. The precise reason is still unknown. A minimum velocity of 0.1
+!-- m/s is used to maintain turbulent transfer at the surface.
+    u = SIGN(1.0_wp,u) * MAX(ug_surface,0.1_wp)
+    v = SIGN(1.0_wp,v) * MAX(vg_surface,0.1_wp)
 
     dt_save = dt_3d
@@ -453,7 +478,9 @@
 
 !
-!-- Write back saved temperature to the 3D arrays
-    pt(:,:,:)   = pt_save
-    pt_p(:,:,:) = pt_save
+!-- Write back saved arrays to the 3D arrays
+    pt   = pt_save
+    pt_p = pt_save
+    u    = u_save
+    v    = v_save
 
 !
@@ -462,4 +489,6 @@
 
     DEALLOCATE(pt_save)
+    DEALLOCATE(u_save)
+    DEALLOCATE(v_save)
 
     CALL location_message( 'finished spinup-sequence', .TRUE. )
