Index: /palm/trunk/SOURCE/diffusion_s.f90
===================================================================
--- /palm/trunk/SOURCE/diffusion_s.f90	(revision 2758)
+++ /palm/trunk/SOURCE/diffusion_s.f90	(revision 2759)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Major bugfix, horizontal diffusion at vertical surfaces corrected.
+! 
+! 2718 2018-01-02 08:49:38Z maronga
 ! Corrected "Former revisions" section
 ! 
@@ -136,5 +139,5 @@
        
        USE grid_variables,                                                     &
-           ONLY:  ddx2, ddy2
+           ONLY:  ddx, ddx2, ddy, ddy2
        
        USE indices,                                                            &
@@ -231,5 +234,5 @@
              DO  m = surf_s, surf_e
                 k           = surf_def_v(0)%k(m)
-                tend(k,j,i) = tend(k,j,i) + s_flux_def_v_north(m) * ddy2
+                tend(k,j,i) = tend(k,j,i) + s_flux_def_v_north(m) * ddy
              ENDDO
 !
@@ -239,5 +242,5 @@
              DO  m = surf_s, surf_e
                 k           = surf_def_v(1)%k(m)
-                tend(k,j,i) = tend(k,j,i) + s_flux_def_v_south(m) * ddy2
+                tend(k,j,i) = tend(k,j,i) + s_flux_def_v_south(m) * ddy
              ENDDO
 !
@@ -247,5 +250,5 @@
              DO  m = surf_s, surf_e
                 k           = surf_def_v(2)%k(m)
-                tend(k,j,i) = tend(k,j,i) + s_flux_def_v_east(m) * ddx2
+                tend(k,j,i) = tend(k,j,i) + s_flux_def_v_east(m) * ddx
              ENDDO
 !
@@ -255,5 +258,5 @@
              DO  m = surf_s, surf_e
                 k           = surf_def_v(3)%k(m)
-                tend(k,j,i) = tend(k,j,i) + s_flux_def_v_west(m) * ddx2
+                tend(k,j,i) = tend(k,j,i) + s_flux_def_v_west(m) * ddx
              ENDDO
 !
@@ -264,5 +267,5 @@
              DO  m = surf_s, surf_e
                 k           = surf_lsm_v(0)%k(m)
-                tend(k,j,i) = tend(k,j,i) + s_flux_lsm_v_north(m) * ddy2
+                tend(k,j,i) = tend(k,j,i) + s_flux_lsm_v_north(m) * ddy
              ENDDO
 !
@@ -272,5 +275,5 @@
              DO  m = surf_s, surf_e
                 k           = surf_lsm_v(1)%k(m)
-                tend(k,j,i) = tend(k,j,i) + s_flux_lsm_v_south(m) * ddy2
+                tend(k,j,i) = tend(k,j,i) + s_flux_lsm_v_south(m) * ddy
              ENDDO
 !
@@ -280,5 +283,5 @@
              DO  m = surf_s, surf_e
                 k           = surf_lsm_v(2)%k(m)
-                tend(k,j,i) = tend(k,j,i) + s_flux_lsm_v_east(m) * ddx2
+                tend(k,j,i) = tend(k,j,i) + s_flux_lsm_v_east(m) * ddx
              ENDDO
 !
@@ -288,5 +291,5 @@
              DO  m = surf_s, surf_e
                 k           = surf_lsm_v(3)%k(m)
-                tend(k,j,i) = tend(k,j,i) + s_flux_lsm_v_west(m) * ddx2
+                tend(k,j,i) = tend(k,j,i) + s_flux_lsm_v_west(m) * ddx
              ENDDO
 !
@@ -297,5 +300,5 @@
              DO  m = surf_s, surf_e
                 k           = surf_usm_v(0)%k(m)
-                tend(k,j,i) = tend(k,j,i) + s_flux_usm_v_north(m) * ddy2
+                tend(k,j,i) = tend(k,j,i) + s_flux_usm_v_north(m) * ddy
              ENDDO
 !
@@ -305,5 +308,5 @@
              DO  m = surf_s, surf_e
                 k           = surf_usm_v(1)%k(m)
-                tend(k,j,i) = tend(k,j,i) + s_flux_usm_v_south(m) * ddy2
+                tend(k,j,i) = tend(k,j,i) + s_flux_usm_v_south(m) * ddy
              ENDDO
 !
@@ -313,5 +316,5 @@
              DO  m = surf_s, surf_e
                 k           = surf_usm_v(2)%k(m)
-                tend(k,j,i) = tend(k,j,i) + s_flux_usm_v_east(m) * ddx2
+                tend(k,j,i) = tend(k,j,i) + s_flux_usm_v_east(m) * ddx
              ENDDO
 !
@@ -321,5 +324,5 @@
              DO  m = surf_s, surf_e
                 k           = surf_usm_v(3)%k(m)
-                tend(k,j,i) = tend(k,j,i) + s_flux_usm_v_west(m) * ddx2
+                tend(k,j,i) = tend(k,j,i) + s_flux_usm_v_west(m) * ddx
              ENDDO
 
@@ -448,5 +451,5 @@
        
        USE grid_variables,                                                     &
-           ONLY:  ddx2, ddy2
+           ONLY:  ddx, ddx2, ddy, ddy2
        
        USE indices,                                                            &
@@ -543,5 +546,5 @@
        DO  m = surf_s, surf_e
           k           = surf_def_v(0)%k(m)
-          tend(k,j,i) = tend(k,j,i) + s_flux_def_v_north(m) * ddy2
+          tend(k,j,i) = tend(k,j,i) + s_flux_def_v_north(m) * ddy
        ENDDO
 !
@@ -551,5 +554,5 @@
        DO  m = surf_s, surf_e
           k           = surf_def_v(1)%k(m)
-          tend(k,j,i) = tend(k,j,i) + s_flux_def_v_south(m) * ddy2
+          tend(k,j,i) = tend(k,j,i) + s_flux_def_v_south(m) * ddy
        ENDDO
 !
@@ -559,5 +562,5 @@
        DO  m = surf_s, surf_e
           k           = surf_def_v(2)%k(m)
-          tend(k,j,i) = tend(k,j,i) + s_flux_def_v_east(m) * ddx2
+          tend(k,j,i) = tend(k,j,i) + s_flux_def_v_east(m) * ddx
        ENDDO
 !
@@ -567,5 +570,5 @@
        DO  m = surf_s, surf_e
           k           = surf_def_v(3)%k(m)
-          tend(k,j,i) = tend(k,j,i) + s_flux_def_v_west(m) * ddx2
+          tend(k,j,i) = tend(k,j,i) + s_flux_def_v_west(m) * ddx
        ENDDO
 !
@@ -576,5 +579,5 @@
        DO  m = surf_s, surf_e
           k           = surf_lsm_v(0)%k(m)
-          tend(k,j,i) = tend(k,j,i) + s_flux_lsm_v_north(m) * ddy2
+          tend(k,j,i) = tend(k,j,i) + s_flux_lsm_v_north(m) * ddy
        ENDDO
 !
@@ -584,5 +587,5 @@
        DO  m = surf_s, surf_e
           k           = surf_lsm_v(1)%k(m)
-          tend(k,j,i) = tend(k,j,i) + s_flux_lsm_v_south(m) * ddy2
+          tend(k,j,i) = tend(k,j,i) + s_flux_lsm_v_south(m) * ddy
        ENDDO
 !
@@ -592,5 +595,5 @@
        DO  m = surf_s, surf_e
           k           = surf_lsm_v(2)%k(m)
-          tend(k,j,i) = tend(k,j,i) + s_flux_lsm_v_east(m) * ddx2
+          tend(k,j,i) = tend(k,j,i) + s_flux_lsm_v_east(m) * ddx
        ENDDO
 !
@@ -600,5 +603,5 @@
        DO  m = surf_s, surf_e
           k           = surf_lsm_v(3)%k(m)
-          tend(k,j,i) = tend(k,j,i) + s_flux_lsm_v_west(m) * ddx2
+          tend(k,j,i) = tend(k,j,i) + s_flux_lsm_v_west(m) * ddx
        ENDDO
 !
@@ -609,5 +612,5 @@
        DO  m = surf_s, surf_e
           k           = surf_usm_v(0)%k(m)
-          tend(k,j,i) = tend(k,j,i) + s_flux_usm_v_north(m) * ddy2
+          tend(k,j,i) = tend(k,j,i) + s_flux_usm_v_north(m) * ddy
        ENDDO
 !
@@ -617,5 +620,5 @@
        DO  m = surf_s, surf_e
           k           = surf_usm_v(1)%k(m)
-          tend(k,j,i) = tend(k,j,i) + s_flux_usm_v_south(m) * ddy2
+          tend(k,j,i) = tend(k,j,i) + s_flux_usm_v_south(m) * ddy
        ENDDO
 !
@@ -625,5 +628,5 @@
        DO  m = surf_s, surf_e
           k           = surf_usm_v(2)%k(m)
-          tend(k,j,i) = tend(k,j,i) + s_flux_usm_v_east(m) * ddx2
+          tend(k,j,i) = tend(k,j,i) + s_flux_usm_v_east(m) * ddx
        ENDDO
 !
@@ -633,5 +636,5 @@
        DO  m = surf_s, surf_e
           k           = surf_usm_v(3)%k(m)
-          tend(k,j,i) = tend(k,j,i) + s_flux_usm_v_west(m) * ddx2
+          tend(k,j,i) = tend(k,j,i) + s_flux_usm_v_west(m) * ddx
        ENDDO
 
Index: /palm/trunk/SOURCE/surface_mod.f90
===================================================================
--- /palm/trunk/SOURCE/surface_mod.f90	(revision 2758)
+++ /palm/trunk/SOURCE/surface_mod.f90	(revision 2759)
@@ -26,4 +26,8 @@
 ! -----------------
 ! $Id$
+! Bugfix, consider density in vertical fluxes of passive scalar as well as 
+! chemical species.
+! 
+! 2753 2018-01-16 14:16:49Z suehring
 ! +r_a_green, r_a_window
 ! 
@@ -116,6 +120,6 @@
 
     USE arrays_3d,                                                             &
-        ONLY:  zu, zw, heatflux_input_conversion, waterflux_input_conversion,  &
-               momentumflux_input_conversion
+        ONLY:  heatflux_input_conversion, momentumflux_input_conversion,       &
+               rho_air, rho_air_zw, zu, zw, waterflux_input_conversion 
 
 #if defined( __chem )
@@ -1753,5 +1757,5 @@
                       IF ( .NOT. random_heatflux )  THEN
                          surf%shf(num_h) = surface_heatflux *                  &
-                                                 heatflux_input_conversion(nzb)
+                                                 heatflux_input_conversion(k-1)
 !
 !--                      Check if surface heat flux might be replaced by 
@@ -1784,5 +1788,5 @@
                       IF ( constant_waterflux )  THEN
                          surf%qsws(num_h) = surface_waterflux *                &
-                                                 waterflux_input_conversion(nzb)
+                                                 waterflux_input_conversion(k-1)
                          IF ( k-1 /= 0 )  THEN
                             surf%qsws(num_h) = wall_humidityflux(0) *          &
@@ -1801,8 +1805,9 @@
                    IF ( upward_facing )  THEN
                       IF ( constant_scalarflux )  THEN
-                         surf%ssws(num_h) = surface_scalarflux
+                         surf%ssws(num_h) = surface_scalarflux * rho_air_zw(k-1)
 
                          IF ( k-1 /= 0 )                                       &
-                            surf%ssws(num_h) = wall_scalarflux(0)
+                            surf%ssws(num_h) = wall_scalarflux(0) *            &
+                                               rho_air_zw(k-1)
 
                       ELSE
@@ -1810,5 +1815,5 @@
                       ENDIF
                    ELSE
-                      surf%ssws(num_h) = wall_scalarflux(5)
+                      surf%ssws(num_h) = wall_scalarflux(5) * rho_air_zw(k)
                    ENDIF
                 ENDIF
@@ -1824,13 +1829,18 @@
                             IF ( upward_facing )  THEN
                                IF ( constant_csflux(lsp_pr) )  THEN
-                                  surf%cssws(lsp,num_h) = surface_csflux(lsp_pr)
-
-                                  IF ( k-1 /= 0 )                                    &
-                                     surf%cssws(lsp,num_h) = wall_csflux(lsp,0)
+                                  surf%cssws(lsp,num_h) =                      &
+                                                       surface_csflux(lsp_pr) *&
+                                                       rho_air_zw(k-1)
+
+                                  IF ( k-1 /= 0 )                              &
+                                     surf%cssws(lsp,num_h) =                   &
+                                                       wall_csflux(lsp,0) *    &
+                                                       rho_air_zw(k-1) 
                                ELSE
                                   surf%cssws(lsp,num_h) = 0.0_wp
                                ENDIF
                             ELSE
-                               surf%cssws(lsp,num_h) = wall_csflux(lsp,5)
+                               surf%cssws(lsp,num_h) = wall_csflux(lsp,5) *    &
+                                                       rho_air_zw(k)
                             ENDIF
                          ENDIF
@@ -1843,5 +1853,5 @@
                 IF ( ocean )  THEN
                    IF ( upward_facing )  THEN 
-                      surf%sasws(num_h) = bottom_salinityflux
+                      surf%sasws(num_h) = bottom_salinityflux * rho_air_zw(k-1)
                    ELSE
                       surf%sasws(num_h) = 0.0_wp
@@ -1907,5 +1917,5 @@
 !--          Prescribe top scalar flux
              IF ( passive_scalar .AND. constant_top_scalarflux )               &
-                surf%ssws(num_h) = top_scalarflux
+                surf%ssws(num_h) = top_scalarflux * rho_air_zw(nzt+1)
 !
 !--          Prescribe top chemical species' flux
@@ -1913,5 +1923,5 @@
              DO  lsp = 1, nvar
                 IF ( air_chemistry  .AND.  constant_top_csflux(lsp) )  THEN 
-                   surf%cssws(lsp,num_h) = top_csflux(lsp)
+                   surf%cssws(lsp,num_h) = top_csflux(lsp) * rho_air_zw(nzt+1)
                 ENDIF
              ENDDO
@@ -1920,5 +1930,5 @@
 !--          Prescribe top salinity flux
              IF ( ocean .AND. constant_top_salinityflux)                       &
-                surf%sasws(num_h) = top_salinityflux
+                surf%sasws(num_h) = top_salinityflux * rho_air_zw(nzt+1)
 !
 !--          Top momentum fluxes
