Index: /palm/trunk/SOURCE/land_surface_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/land_surface_model_mod.f90	(revision 3270)
+++ /palm/trunk/SOURCE/land_surface_model_mod.f90	(revision 3271)
@@ -25,4 +25,11 @@
 ! -----------------
 ! $Id$
+! Several bugfixes:
+! - Initialization of pt_surface array with soil temperature in the uppermost
+!   soil layer, else heat fluxes at the very first time step become quite large
+! - Default initialization of vertical surface elements in special case terrain
+!   height changes are larger than adjacent building heights. 
+! 
+! 3256 2018-09-17 12:20:07Z suehring
 ! Enable initialization of z0q for vegetation, pavement and water surfaces via
 ! namelist input. 
@@ -1809,5 +1816,5 @@
     j_off = surf%joff
     i_off = surf%ioff
-
+    
 !
 !-- Calculate the exner function for the current time step
@@ -2313,5 +2320,5 @@
 !-- Calculate new roughness lengths (for water surfaces only)
     IF ( horizontal  .AND.  .NOT. constant_roughness )  CALL calc_z0_water_surface
-
+    
     CONTAINS
 !------------------------------------------------------------------------------!
@@ -2724,30 +2731,73 @@
                 i = surf_lsm_h%i(m)
                 j = surf_lsm_h%j(m)
-                IF ( vegetation_type_f%var(j,i) /= vegetation_type_f%fill )        &
+                IF ( vegetation_type_f%var(j,i) /= vegetation_type_f%fill )    &
                    surf_lsm_h%vegetation_surface(m) = .TRUE.
-                IF ( pavement_type_f%var(j,i)   /= pavement_type_f%fill )          &
+                IF ( pavement_type_f%var(j,i)   /= pavement_type_f%fill )      &
                    surf_lsm_h%pavement_surface(m) = .TRUE.
-                IF ( water_type_f%var(j,i)      /= water_type_f%fill )             &
+                IF ( water_type_f%var(j,i)      /= water_type_f%fill )         &
                    surf_lsm_h%water_surface(m) = .TRUE.
              ENDDO
+!
+!--          For vertical surfaces some special checks and treatment are
+!--          required for correct initialization. 
              DO  l = 0, 3
                 DO  m = 1, surf_lsm_v(l)%ns
 !
-!--                Only for vertical surfaces. Check if natural walls at reference
-!--                grid point are covered by any building. This case, problems 
-!--                with initialization will aris if index offsets are used. 
-!--                In order to deal with this, set special flag. 
+!--                Only for vertical surfaces. Check if at the grid point where 
+!--                the wall is defined (i+ioff, j+joff) is any building. 
+!--                This case, no natural surfaces properties will be defined at
+!--                at this grid point, leading to problems in the initialization.
+!--                To overcome this, define a special flag which
+!--                indicates that a building is defined at the wall grid point  
+!--                and take the surface properties from the adjoining grid 
+!--                point, i.e. without offset values.
+!--                Further, there can occur a special case where elevation
+!--                changes are larger than building heights. This case, (j,i)
+!--                and (j+joff,i+ioff) grid points may be both covered by 
+!--                buildings, but vertical, but vertically natural walls may 
+!--                be located between the buildings. This case, it is not 
+!--                guaranteed that information about natural surface types is 
+!--                given, neither at (j,i) nor at (j+joff,i+ioff), again leading 
+!--                to non-initialized surface properties. 
                    surf_lsm_v(l)%building_covered(m) = .FALSE.
+!
+!--                      Wall grid point is building-covered. This case, set 
+!--                      flag indicating that surface properties are initialized 
+!--                      from neighboring reference grid point, which is not 
+!--                      building_covered. 
                    IF ( building_type_f%from_file )  THEN
-                      i = surf_lsm_v(l)%i(m) + surf_lsm_v(l)%ioff
-                      j = surf_lsm_v(l)%j(m) + surf_lsm_v(l)%joff
-                      IF ( building_type_f%var(j,i) /= 0 )                     &
+                      i = surf_lsm_v(l)%i(m)
+                      j = surf_lsm_v(l)%j(m)
+                      IF ( building_type_f%var(j+surf_lsm_v(l)%joff,           &
+                                               i+surf_lsm_v(l)%ioff) /=        &
+                           building_type_f%fill )                              &
                          surf_lsm_v(l)%building_covered(m) = .TRUE.
+!
+!--                   Wall grid point as well as neighboring reference grid
+!--                   point are both building-covered. This case, surface
+!--                   properties are not necessarily defined (not covered by
+!--                   checks for static input file) at this surface. Hence, 
+!--                   initialize surface properties by simply setting 
+!--                   vegetation_type_f to bare-soil bulk parametrization. 
+!--                   soil_type_f as well as surface_fractions_f will be set 
+!--                   also.                      
+                      IF ( building_type_f%var(j+surf_lsm_v(l)%joff,           &
+                                               i+surf_lsm_v(l)%ioff) /=        &
+                           building_type_f%fill  .AND.                         &
+                           building_type_f%var(j,i) /= building_type_f%fill )  &
+                      THEN
+                         vegetation_type_f%var(j,i)                 = 1 ! bare soil
+                         soil_type_f%var_2d(j,i)                    = 1 
+                         surface_fraction_f%frac(ind_veg_wall,j,i)  = 1
+                         surface_fraction_f%frac(ind_pav_green,j,i) = 0
+                         surface_fraction_f%frac(ind_wat_win,j,i)   = 0
+                      ENDIF
+                      
                    ENDIF
 !
 !--                Normally proceed with setting surface types.
-                   i = surf_lsm_v(l)%i(m) + MERGE( 0, surf_lsm_v(l)%ioff,     &
+                   i = surf_lsm_v(l)%i(m) + MERGE( 0, surf_lsm_v(l)%ioff,      &
                                             surf_lsm_v(l)%building_covered(m) )
-                   j = surf_lsm_v(l)%j(m) + MERGE( 0, surf_lsm_v(l)%joff,     &
+                   j = surf_lsm_v(l)%j(m) + MERGE( 0, surf_lsm_v(l)%joff,      &
                                             surf_lsm_v(l)%building_covered(m) )
                    IF ( vegetation_type_f%var(j,i) /= vegetation_type_f%fill ) &
@@ -2757,4 +2807,7 @@
                    IF ( water_type_f%var(j,i)      /= water_type_f%fill )      &
                       surf_lsm_v(l)%water_surface(m) = .TRUE.
+!
+!--                Check if surface element has the flag %building_covered_all,
+!--                this case, set vegetation_type appropriate
                 ENDDO
              ENDDO
@@ -3268,8 +3321,8 @@
           DO  l = 0, 3
              DO  m = 1, surf_lsm_v(l)%ns
-                i = surf_lsm_v(l)%i(m) + MERGE( 0, surf_lsm_v(l)%ioff,      &
+                i = surf_lsm_v(l)%i(m) + MERGE( 0, surf_lsm_v(l)%ioff,         &
                                                 surf_lsm_v(l)%building_covered(m) ) 
                 j = surf_lsm_v(l)%j(m) + MERGE( 0, surf_lsm_v(l)%joff,      &
-                                                   surf_lsm_v(l)%building_covered(m) ) 
+                                                surf_lsm_v(l)%building_covered(m) ) 
              
                 st = vegetation_type_f%var(j,i)
@@ -3488,5 +3541,5 @@
           IF ( surf_lsm_h%water_surface(m) )  THEN
              IF ( TRIM( initializing_actions ) /= 'read_restart_data' )        &
-                t_soil_h%var_2d(:,m)           = water_temperature
+                t_soil_h%var_2d(:,m)        = water_temperature
              surf_lsm_h%z0(m)               = z0_water
              surf_lsm_h%z0h(m)              = z0h_water
@@ -3642,5 +3695,5 @@
                      water_pars_f%fill )                                       &
                    surf_lsm_h%emissivity(ind_wat_win,m) =                      &
-                   water_pars_f%pars_xy(ind_w_emis,j,i)  
+                                          water_pars_f%pars_xy(ind_w_emis,j,i)  
              ENDIF
           ENDDO
@@ -4395,14 +4448,8 @@
              k   = surf_lsm_h%k(m)
 !
-!--          Calculate surface temperature. In case of bare soil, the surface 
-!--          temperature must be reset to the soil temperature in the first soil 
-!--          layer
-             IF ( surf_lsm_h%lambda_surface_s(m) == 0.0_wp )  THEN
-                t_surface_h%var_1d(m)    = t_soil_h%var_2d(nzb_soil,m)
-                surf_lsm_h%pt_surface(m) = t_soil_h%var_2d(nzb_soil,m) / exn
-             ELSE
-                t_surface_h%var_1d(m)    = pt(k-1,j,i) * exn
-                surf_lsm_h%pt_surface(m) = pt(k-1,j,i)  
-             ENDIF
+!--          Initialize surface temperature with soil temperature in the uppermost
+!--          uppermost layer
+             t_surface_h%var_1d(m)    = t_soil_h%var_2d(nzb_soil,m)
+             surf_lsm_h%pt_surface(m) = t_soil_h%var_2d(nzb_soil,m) / exn
              
              IF ( cloud_physics  .OR. cloud_droplets ) THEN
@@ -4411,6 +4458,4 @@
                 surf_lsm_h%pt1(m) = pt(k,j,i)
              ENDIF 
-
-
 !
 !--          Assure that r_a cannot be zero at model start
@@ -4432,18 +4477,8 @@
                 k   = surf_lsm_v(l)%k(m)         
 !
-!--             Calculate surface temperature. In case of bare soil, the surface 
-!--             temperature must be reset to the soil temperature in the first soil 
-!--             layer
-                IF ( surf_lsm_v(l)%lambda_surface_s(m) == 0.0_wp )  THEN
-                   t_surface_v(l)%var_1d(m)      = t_soil_v(l)%var_2d(nzb_soil,m)
-                   surf_lsm_v(l)%pt_surface(m)   = t_soil_v(l)%var_2d(nzb_soil,m) / exn
-                ELSE
-                   j_off = surf_lsm_v(l)%joff
-                   i_off = surf_lsm_v(l)%ioff
-
-                   t_surface_v(l)%var_1d(m)      = pt(k,j+j_off,i+i_off) * exn
-                   surf_lsm_v(l)%pt_surface(m)   = pt(k,j+j_off,i+i_off)           
-                ENDIF
-
+!--             Initialize surface temperature with soil temperature in the uppermost
+!--             uppermost layer
+                t_surface_v(l)%var_1d(m)      = t_soil_v(l)%var_2d(nzb_soil,m)
+                surf_lsm_v(l)%pt_surface(m)   = t_soil_v(l)%var_2d(nzb_soil,m) / exn
 
                 IF ( cloud_physics  .OR. cloud_droplets ) THEN
Index: /palm/trunk/SOURCE/surface_layer_fluxes_mod.f90
===================================================================
--- /palm/trunk/SOURCE/surface_layer_fluxes_mod.f90	(revision 3270)
+++ /palm/trunk/SOURCE/surface_layer_fluxes_mod.f90	(revision 3271)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! Comment revised
+! 
+! 3157 2018-07-19 21:08:49Z maronga
 ! Added local free convection velocity scale w_lfc in calculation of uvw_abs.
 ! This can be switche on/off by the user via the flag namelist parameter 
@@ -1580,5 +1583,4 @@
 !-- Calculate potential temperature, specific humidity, and virtual potential
 !-- temperature at first grid level
-!-- ( only for upward-facing surfs )
     SUBROUTINE calc_pt_q
 
