Index: /palm/trunk/SOURCE/nesting_offl_mod.f90
===================================================================
--- /palm/trunk/SOURCE/nesting_offl_mod.f90	(revision 3890)
+++ /palm/trunk/SOURCE/nesting_offl_mod.f90	(revision 3891)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! Bugfix, do not overwrite lateral and top boundary data in case of restart 
+! runs. 
+! 
+! 3885 2019-04-11 11:29:34Z kanani
 ! Changes related to global restructuring of location messages and introduction 
 ! of additional debug messages
@@ -73,6 +77,5 @@
         ONLY:  air_chemistry, bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r,  &
                bc_dirichlet_s, dt_3d, dz, constant_diffusion,                  &
-               debug_output, debug_string,                                     &
-               humidity,                                                       &
+               debug_output, debug_string, humidity, initializing_actions,     &
                message_string, nesting_offline, neutral, passive_scalar,       &
                rans_mode, rans_tke_e, time_since_reference_point, volume_flow
@@ -1209,92 +1212,90 @@
        CALL netcdf_data_input_offline_nesting
 !
-!--    Initialize boundary data.
-       IF ( bc_dirichlet_l )  THEN
-          u(nzb+1:nzt,nys:nyn,0)    = nest_offl%u_left(0,nzb+1:nzt,nys:nyn)
-          v(nzb+1:nzt,nysv:nyn,-1)  = nest_offl%v_left(0,nzb+1:nzt,nysv:nyn) 
-          w(nzb+1:nzt-1,nys:nyn,-1) = nest_offl%w_left(0,nzb+1:nzt-1,nys:nyn)
-          IF ( .NOT. neutral )  pt(nzb+1:nzt,nys:nyn,-1) =                     &
-                                   nest_offl%pt_left(0,nzb+1:nzt,nys:nyn)
-          IF ( humidity      )  q(nzb+1:nzt,nys:nyn,-1)  =                     &
-                                   nest_offl%q_left(0,nzb+1:nzt,nys:nyn)
-          IF ( air_chemistry )  THEN
-             DO  n = 1, UBOUND( chem_species, 1 )
-                IF( nest_offl%chem_from_file_l(n) )  THEN
-                   chem_species(n)%conc(nzb+1:nzt,nys:nyn,-1) =                &
-                                   nest_offl%chem_left(0,nzb+1:nzt,nys:nyn,n)
-                ENDIF
-             ENDDO
-          ENDIF
-       ENDIF
-       IF ( bc_dirichlet_r )  THEN
-          u(nzb+1:nzt,nys:nyn,nxr+1)   = nest_offl%u_right(0,nzb+1:nzt,nys:nyn) 
-          v(nzb+1:nzt,nysv:nyn,nxr+1)  = nest_offl%v_right(0,nzb+1:nzt,nysv:nyn)
-          w(nzb+1:nzt-1,nys:nyn,nxr+1) = nest_offl%w_right(0,nzb+1:nzt-1,nys:nyn)
-          IF ( .NOT. neutral )  pt(nzb+1:nzt,nys:nyn,nxr+1) =                  &
-                                   nest_offl%pt_right(0,nzb+1:nzt,nys:nyn)
-          IF ( humidity      )  q(nzb+1:nzt,nys:nyn,nxr+1)  =                  &
-                                   nest_offl%q_right(0,nzb+1:nzt,nys:nyn)
-          IF ( air_chemistry )  THEN
-             DO  n = 1, UBOUND( chem_species, 1 )
-                IF( nest_offl%chem_from_file_r(n) )  THEN
-                   chem_species(n)%conc(nzb+1:nzt,nys:nyn,nxr+1) =             &
-                                   nest_offl%chem_right(0,nzb+1:nzt,nys:nyn,n)
-                ENDIF
-             ENDDO
-          ENDIF
-       ENDIF
-       IF ( bc_dirichlet_s )  THEN
-          u(nzb+1:nzt,-1,nxlu:nxr)  = nest_offl%u_south(0,nzb+1:nzt,nxlu:nxr)
-          v(nzb+1:nzt,0,nxl:nxr)    = nest_offl%v_south(0,nzb+1:nzt,nxl:nxr) 
-          w(nzb+1:nzt-1,-1,nxl:nxr) = nest_offl%w_south(0,nzb+1:nzt-1,nxl:nxr) 
-          IF ( .NOT. neutral )  pt(nzb+1:nzt,-1,nxl:nxr) =                     &
-                                   nest_offl%pt_south(0,nzb+1:nzt,nxl:nxr)
-          IF ( humidity      )  q(nzb+1:nzt,-1,nxl:nxr)  =                     &
-                                   nest_offl%q_south(0,nzb+1:nzt,nxl:nxr) 
-          IF ( air_chemistry )  THEN
-             DO  n = 1, UBOUND( chem_species, 1 )
-                IF( nest_offl%chem_from_file_s(n) )  THEN
-                   chem_species(n)%conc(nzb+1:nzt,-1,nxl:nxr) =                &
-                                   nest_offl%chem_south(0,nzb+1:nzt,nxl:nxr,n)
-                ENDIF
-             ENDDO
-          ENDIF
-       ENDIF
-       IF ( bc_dirichlet_n )  THEN
-          u(nzb+1:nzt,nyn+1,nxlu:nxr)  = nest_offl%u_north(0,nzb+1:nzt,nxlu:nxr)
-          v(nzb+1:nzt,nyn+1,nxl:nxr)   = nest_offl%v_north(0,nzb+1:nzt,nxl:nxr) 
-          w(nzb+1:nzt-1,nyn+1,nxl:nxr) = nest_offl%w_north(0,nzb+1:nzt-1,nxl:nxr)
-          IF ( .NOT. neutral )  pt(nzb+1:nzt,nyn+1,nxl:nxr) =                  &
-                                   nest_offl%pt_north(0,nzb+1:nzt,nxl:nxr) 
-          IF ( humidity      )  q(nzb+1:nzt,nyn+1,nxl:nxr)  =                  &
-                                   nest_offl%q_north(0,nzb+1:nzt,nxl:nxr)
-          IF ( air_chemistry )  THEN
-             DO  n = 1, UBOUND( chem_species, 1 )
-                IF( nest_offl%chem_from_file_n(n) )  THEN
-                   chem_species(n)%conc(nzb+1:nzt,nyn+1,nxl:nxr) =             &
-                                   nest_offl%chem_north(0,nzb+1:nzt,nxl:nxr,n)
-                ENDIF
-             ENDDO
-          ENDIF
-       ENDIF
-!
-!--    Initialize geostrophic wind components. Actually this is already done in
-!--    init_3d_model when initializing_action = 'inifor', however, in speical 
-!--    case of user-defined initialization this will be done here again, in 
-!--    order to have a consistent initialization. 
-       ug(nzb+1:nzt) = nest_offl%ug(0,nzb+1:nzt)
-       vg(nzb+1:nzt) = nest_offl%vg(0,nzb+1:nzt)
-!
-!--    Set bottom and top boundary condition for geostrophic wind components
-       ug(nzt+1) = ug(nzt)
-       vg(nzt+1) = vg(nzt)
-       ug(nzb)   = ug(nzb+1)
-       vg(nzb)   = vg(nzb+1)
-!
-!--    Initial calculation of the boundary layer depth from the prescribed 
-!--    boundary data. This is requiered for initialize the synthetic turbulence
-!--    generator correctly. 
-       CALL calc_zi
-       
+!--    Initialize boundary data. Please note, do not initialize boundaries in 
+!--    case of restart runs. This case the boundaries are already initialized
+!--    and the boundary data from file would be on the wrong time level.  
+       IF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
+          IF ( bc_dirichlet_l )  THEN
+             u(nzb+1:nzt,nys:nyn,0)    = nest_offl%u_left(0,nzb+1:nzt,nys:nyn)
+             v(nzb+1:nzt,nysv:nyn,-1)  = nest_offl%v_left(0,nzb+1:nzt,nysv:nyn) 
+             w(nzb+1:nzt-1,nys:nyn,-1) = nest_offl%w_left(0,nzb+1:nzt-1,nys:nyn)
+             IF ( .NOT. neutral )  pt(nzb+1:nzt,nys:nyn,-1) =                  &
+                                      nest_offl%pt_left(0,nzb+1:nzt,nys:nyn)
+             IF ( humidity      )  q(nzb+1:nzt,nys:nyn,-1)  =                  &
+                                      nest_offl%q_left(0,nzb+1:nzt,nys:nyn)
+             IF ( air_chemistry )  THEN
+                DO  n = 1, UBOUND( chem_species, 1 )
+                   IF( nest_offl%chem_from_file_l(n) )  THEN
+                      chem_species(n)%conc(nzb+1:nzt,nys:nyn,-1) =             &
+                                      nest_offl%chem_left(0,nzb+1:nzt,nys:nyn,n)
+                   ENDIF
+                ENDDO
+             ENDIF
+          ENDIF
+          IF ( bc_dirichlet_r )  THEN
+             u(nzb+1:nzt,nys:nyn,nxr+1)   = nest_offl%u_right(0,nzb+1:nzt,nys:nyn) 
+             v(nzb+1:nzt,nysv:nyn,nxr+1)  = nest_offl%v_right(0,nzb+1:nzt,nysv:nyn)
+             w(nzb+1:nzt-1,nys:nyn,nxr+1) = nest_offl%w_right(0,nzb+1:nzt-1,nys:nyn)
+             IF ( .NOT. neutral )  pt(nzb+1:nzt,nys:nyn,nxr+1) =               &
+                                      nest_offl%pt_right(0,nzb+1:nzt,nys:nyn)
+             IF ( humidity      )  q(nzb+1:nzt,nys:nyn,nxr+1)  =               &
+                                      nest_offl%q_right(0,nzb+1:nzt,nys:nyn)
+             IF ( air_chemistry )  THEN
+                DO  n = 1, UBOUND( chem_species, 1 )
+                   IF( nest_offl%chem_from_file_r(n) )  THEN
+                      chem_species(n)%conc(nzb+1:nzt,nys:nyn,nxr+1) =          &
+                                      nest_offl%chem_right(0,nzb+1:nzt,nys:nyn,n)
+                   ENDIF
+                ENDDO
+             ENDIF
+          ENDIF
+          IF ( bc_dirichlet_s )  THEN
+             u(nzb+1:nzt,-1,nxlu:nxr)  = nest_offl%u_south(0,nzb+1:nzt,nxlu:nxr)
+             v(nzb+1:nzt,0,nxl:nxr)    = nest_offl%v_south(0,nzb+1:nzt,nxl:nxr) 
+             w(nzb+1:nzt-1,-1,nxl:nxr) = nest_offl%w_south(0,nzb+1:nzt-1,nxl:nxr) 
+             IF ( .NOT. neutral )  pt(nzb+1:nzt,-1,nxl:nxr) =                  &
+                                      nest_offl%pt_south(0,nzb+1:nzt,nxl:nxr)
+             IF ( humidity      )  q(nzb+1:nzt,-1,nxl:nxr)  =                  &
+                                      nest_offl%q_south(0,nzb+1:nzt,nxl:nxr) 
+             IF ( air_chemistry )  THEN
+                DO  n = 1, UBOUND( chem_species, 1 )
+                   IF( nest_offl%chem_from_file_s(n) )  THEN
+                      chem_species(n)%conc(nzb+1:nzt,-1,nxl:nxr) =             &
+                                      nest_offl%chem_south(0,nzb+1:nzt,nxl:nxr,n)
+                   ENDIF
+                ENDDO
+             ENDIF
+          ENDIF
+          IF ( bc_dirichlet_n )  THEN
+             u(nzb+1:nzt,nyn+1,nxlu:nxr)  = nest_offl%u_north(0,nzb+1:nzt,nxlu:nxr)
+             v(nzb+1:nzt,nyn+1,nxl:nxr)   = nest_offl%v_north(0,nzb+1:nzt,nxl:nxr) 
+             w(nzb+1:nzt-1,nyn+1,nxl:nxr) = nest_offl%w_north(0,nzb+1:nzt-1,nxl:nxr)
+             IF ( .NOT. neutral )  pt(nzb+1:nzt,nyn+1,nxl:nxr) =               &
+                                      nest_offl%pt_north(0,nzb+1:nzt,nxl:nxr) 
+             IF ( humidity      )  q(nzb+1:nzt,nyn+1,nxl:nxr)  =               &
+                                      nest_offl%q_north(0,nzb+1:nzt,nxl:nxr)
+             IF ( air_chemistry )  THEN
+                DO  n = 1, UBOUND( chem_species, 1 )
+                   IF( nest_offl%chem_from_file_n(n) )  THEN
+                      chem_species(n)%conc(nzb+1:nzt,nyn+1,nxl:nxr) =          &
+                                      nest_offl%chem_north(0,nzb+1:nzt,nxl:nxr,n)
+                   ENDIF
+                ENDDO
+             ENDIF
+          ENDIF
+!         
+!--       Initialize geostrophic wind components. Actually this is already done in
+!--       init_3d_model when initializing_action = 'inifor', however, in speical 
+!--       case of user-defined initialization this will be done here again, in 
+!--       order to have a consistent initialization. 
+          ug(nzb+1:nzt) = nest_offl%ug(0,nzb+1:nzt)
+          vg(nzb+1:nzt) = nest_offl%vg(0,nzb+1:nzt)
+!         
+!--       Set bottom and top boundary condition for geostrophic wind components
+          ug(nzt+1) = ug(nzt)
+          vg(nzt+1) = vg(nzt)
+          ug(nzb)   = ug(nzb+1)
+          vg(nzb)   = vg(nzb+1)
+       ENDIF      
 !
 !--    After boundary data is initialized, mask topography at the 
@@ -1303,10 +1304,16 @@
        v = MERGE( v, 0.0_wp, BTEST( wall_flags_0, 2 ) )
        w = MERGE( w, 0.0_wp, BTEST( wall_flags_0, 3 ) )
-       
+!
+!--    Initial calculation of the boundary layer depth from the prescribed 
+!--    boundary data. This is requiered for initialize the synthetic turbulence
+!--    generator correctly. 
        CALL calc_zi
        
 !
-!--    After boundary data is initialized, ensure mass conservation
-       CALL nesting_offl_mass_conservation
+!--    After boundary data is initialized, ensure mass conservation. Not 
+!--    necessary in restart runs.
+       IF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
+          CALL nesting_offl_mass_conservation
+       ENDIF
 
     END SUBROUTINE nesting_offl_init
Index: /palm/trunk/SOURCE/synthetic_turbulence_generator_mod.f90
===================================================================
--- /palm/trunk/SOURCE/synthetic_turbulence_generator_mod.f90	(revision 3890)
+++ /palm/trunk/SOURCE/synthetic_turbulence_generator_mod.f90	(revision 3891)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Bugfix in initialization in case of restart runs. 
+! 
+! 3885 2019-04-11 11:29:34Z kanani
 ! Changes related to global restructuring of location messages and introduction 
 ! of additional debug messages
@@ -773,4 +776,14 @@
 !--    to initialize the filter functions.
        CALL calc_length_and_time_scale
+!
+!--    Parametrize Reynolds-stress tensor, diagonal elements as well
+!--    as r21 (v'u'), r31 (w'u'), r32 (w'v'). Parametrization follows
+!--    Rotach et al. (1996) and is based on boundary-layer depth, 
+!--    friction velocity and velocity scale. 
+       CALL parametrize_reynolds_stress
+!      
+!--    Calculate coefficient matrix from Reynolds stress tensor  
+!--    (Lund rotation)
+       CALL calc_coeff_matrix
             
     ENDIF
